#!/usr/bin/perl
# Simple Network Tools CGI using common unix executables with a simple perl wrapper. Nothing Fancy.
# Written by David Flanigan (dave@flanigan.net)
# No warrenty, blah blah blah...
#
#Load Libs
use CGI qw(:param);
#init varables
my $cdate = `/bin/date`;
chomp $cdate;
# get url params
my $tool = param('tool');
my $dest = param('dest');
#Watch for baddies trying to pass params to the tools
#Strip white-space
$dest =~ tr/ //d;
#Look for entries starting with a "-"
if ($dest =~ /^\-/)
{
print "Content-Type: text/html\n\n";
print "Attetmp to pass params to network tools detected and logged\n";
exit;
}
#Set executables by tool
if ($tool eq "ping") { $exe = "/bin/ping -c 5"; }
elsif ($tool eq "trace") { $exe = "/bin/traceroute"; }
elsif ($tool eq "whois") { $exe = "/usr/bin/whois"; }
elsif ($tool eq "lookup") { $exe = "/usr/bin/host"; }
#Or we don't know this tool
else
{
print "Content-Type: text/html\n\n";
print "Unknwown tool\n";
print "\
\
";
print "Tool = $tool, $Destination = $dest\n";
exit;
}
# Do it
print "Content-Type: text/html\n\n";
print "Tool = $tool \t Target = $dest\n";
print "\
\n";
system ("$exe $dest");
print "\<\/PRE\>\n";
print "Task Completed on $cdate";
print "\
\
";
print "Click \here\<\/a\> to return to flanigan.net";
exit(0);