#!/usr/bin/perl
use CGI qw/:standard -nosticky/;
#################################################################
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else
{
print "Content-type: text/html\n\n";
print "<P>Use POST or GET";
}
foreach $pair (@pairs)
{
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($formdata{$key})
{
$formdata{$key} .= ", $value";
}
else
{
$formdata{$key} = $value;
}
}
#################################################################
$|=1;
$host=$formdata{'host'};
$count=$formdata{'count'};
$count=4 if ($count eq "");
$size=$formdata{'size'};
$size=64 if ($size eq "");
print "Content-type: text/html\n\n";
print "<html>\n<head></head>\n";
print "<body>\n<br>\n<br>\n";
print "<form name=pinger action=/cgi-bin/ping.pl
method=post>";
print "host <input type=text name=host value=\"$host\">\n";
print "count <input type=text name=count value=\"$count\"
size=2>";
print "size <input type=text name=size value=\"$size\"
size=3>";
print "<input type=submit value=\"ping\">\n";
print "</form>";
if ($host ne "")
{
if (($host=~m/^\d{2,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) &&
($count=~m/^\d{1,3}$/) && ($size=~/^\d{1,5}$/))
{
select(STDOUT);
$| = 1;
open(STDERR, '>&STDOUT');
print "<pre>";
{ open(PING,"|/usr/local/sbin/fping -c$count
-b$size $host"); }
print <PING>;
close(PING);
print "</pre>\n";
}
else
{ print "<font color=red><b>bad params</b></font>";
}
}
print "</body>\n</html>";
|