#!/usr/usc/bin/perl
# Order the lines above so that the first gives the location
# of Perl on your system. The rest become comments.
#simple Perl script to print CGI inputs
require "cgi-lib.pl";
print &PrintHeader;
#print "Content-type: text/html\n\n";
print "
\n";
print "Show CGI Inputs\n";
print "";
print "";
print "Show CGI Inputs:
\n";
print "Command Line Arguments:
\n";
$j=1;
foreach $a (@ARGV)
{
print "arg$j: $a
\n";
$j=$j+1;
}
print "
";
print "Environment Variables:
\n";
print "SERVER_SOFTWARE = $ENV{'SERVER_SOFTWARE'}
\n";
print "SERVER_NAME = $ENV{'SERVER_NAME'}
\n";
print "GATEWAY_INTERFACE = $ENV{'GATEWAY_INTERFACE'}
\n";
print "SERVER_PROTOCOL = $ENV{'SERVER_PROTOCOL'}
\n";
print "SERVER_PORT = $ENV{'SERVER_PORT'}
\n";
print "REQUEST_METHOD = $ENV{'REQUEST_METHOD'}
\n";
print "HTTP_ACCEPT = $ENV{'HTTP_ACCEPT'}
\n";
print "PATH_INFO = $ENV{'PATH_INFO'}
\n";
print "PATH_TRANSLATED = $ENV{'PATH_TRANSLATED'}
\n";
print "SCRIPT_NAME = $ENV{'SCRIPT_NAME'}
\n";
print "QUERY_STRING = $ENV{'QUERY_STRING'}
\n";
print "REMOTE_HOST = $ENV{'REMOTE_HOST'}
\n";
print "REMOTE_ADDR = $ENV{'REMOTE_ADDR'}
\n";
print "REMOTE_USER = $ENV{'REMOTE_USER'}
\n";
print "CONTENT_TYPE = $ENV{'CONTENT_TYPE'}
\n";
print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}
\n";
print "HTTP_REFERER = $ENV{'HTTP_REFERER'}
\n";
print "HTTP_USER_AGENT = $ENV{'HTTP_USER_AGENT'}
\n";
print "HTTP_COOKIE = $ENV{'HTTP_COOKIE'}
\n";
print "
\n";
print "Standard Input:
\n";
#get buffer from QUERY_STRING (GET) or STDIN (POST)
if ($ENV{'REQUEST_METHOD'} eq "GET")
{
$buffer = $ENV{'QUERY_STRING'};
print "There is no input in STDIN";
print " when using GET method.
\n";
}
else
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
print "$buffer\n";
}
print "
";
print "Name/Value pairs extracted
\n";
#check for equal signs in buffer
$e = index($buffer,"=");
if ( $e == -1 )
{
print "no name/value pairs in input\n";
}
else
{
#make an array of pairs split at the & sign
@nvpairs = split(/&/, $buffer);
#for each pair, extract name and value
foreach $pair (@nvpairs)
{
#split into name and value
($name, $value) = split(/=/, $pair);
#print name/value pair
print "$name = $value
\n";
}
}
print "
";
print "Name/Value pairs decoded
\n";
if ( $e != -1 )
{
foreach $pair (@nvpairs)
{
#convert plusses to spaces
$pair =~ s/\+/ /g;
#split into name and value
($name, $value) = split(/=/, $pair);
#decode any %XX from hex numbers to alphanumeric
$name =~ s/%(..)/pack("c",hex($1))/ge;
$value =~ s/%(..)/pack("c",hex($1))/ge;
#print name/value pair and decoded value
print "$name = $value
\n";
}
}
print "\n";