#!/usr/bin/perl use strict; use warnings; use Cwd 'abs_path'; $| = 1; # Enable autoflush alarm(10); # Set timeout after 10 seconds # Read the request from standard input my $request = <>; alarm(0); # Disable alarm # Sanitize the request by removing any carriage return or newline characters $request =~ s/[\r\n]//g; # Change directory to /var/nex chdir("/var/nex") or exit 1; # Get the absolute path for the request my $path = abs_path("./$request"); # Ensure $path is defined and not empty if (!defined $path || $path eq "") { print "3not found\t.\t.\t.\r\n" and exit 1; } # If the path is exactly "/var/nex", ensure it's correctly formatted $path = "/var/nex/" if $path eq "/var/nex"; # Exit if the path does not start with /var/nex/ print "3cut it out\t.\t.\t.\r\n" and exit 1 if $path !~ /^\/var\/nex\//; # If the path is a directory, append "/menu" $path .= "/menu" if -d $path; # Attempt to open the file at the resolved path open my $file, '<', $path or do { print "3not found\t.\t.\t.\r\n"; exit 1; }; # Print the file contents and close the file print <$file>; close $file;