#!/usr/bin/perl -wT ############################################################################### use strict; $ENV{PATH}='/bin:/usr/bin:/sbin:/usr/local/bin:/usr/local/etc:/usr/sbin:/usr/local/sbin';#For untainting ########################## Testing ############################################## # For testing from command line you need to set some environment variables, # e.g. assuming you are using the tcsh shell # setenv REQUEST_URI /cgi-wrap/traceroute.pl # setenv QUERY_STRING 'target=www.slac.stanford.edu&function=ping' #For IPv4 # setenv QUERY_STRING www.cern.ch; setenv REMOTE_HOST www.google.com # setenv REMOTE_ADDR 72.14.204.105; setenv SERVER_NAME www.slac.stanford.edu #For IPv6 # setenv QUERY_STRING 'target=ipv6.google.com'; setenv REMOTE_HOST ipv6.google.com # setenv REMOTE_ADDR 2a00:1450:8007::6a; setenv SERVER_NAME ui2-4.dir.garr.it # #To find the IPv6 address of a host use # #dig ipv6.google.com -t AAAA # You will also need to include the -T option in the command line if you want to # use the perl -d debug facility, i.e. you need to use: # perl -d -T traceroute.pl # REMOTE_HOST, REMOTE_ADDR are the name and IP address of the client/browser # SERVER_NAME is the name of the web server, # QUERY_STRING is the name or IP address of the host to be probed. ################################################################################ # Put out header right at start to ensure it precedes any errors or bug reports. # To enable line-buffered output (more interactive output), change the name # of this script to nph-traceroute.pl or use a Unix logical link. select(STDOUT); $| = 1; # Flush output after each print my $msg=""; if ($0 =~ /nph-/) { $msg="$ENV{SERVER_PROTOCOL} 200 OK\nServer: $ENV{SERVER_SOFTWARE}\n"; } #Get this out first so can get out error messages print $msg."Content-type: text/html\n\n"; my $version="5.8, 5/12/2012, Les Cottrell"; # Added option to force IPv6, made fix to private proxy address ################################################################################ #Understand the local environment use Cwd; my $AF_INET=2; my $debug=0; (my $progname = $0) =~ s'^.*/''; my $uid=scalar(getpwuid($<)); #Get fully qualified IP address of the local host use Net::Domain qw(hostname hostfqdn hostdomain); my $hostname = hostfqdn(); my $ipv="4";#set default used by gethostbyname6 to decide if to force IPv6 my $ipaddr=gethostbyname6($hostname); my $site="";#Allows us to special case SLAC's configuration if($hostname=~/\.slac\.stanford\.edu/) {$site="slac";} my $archname=$^O; ########################## Get the form action field ######################### #$form allows one to use a different form action field, e.g. #REQUEST_URI is of the form: /cgi-bin/traceroute.pl?choice=yes my ($temp, $bin_dir); ($temp,$bin_dir,$temp)=split /\//,$ENV{'REQUEST_URI'}; my $form="