|
#!/usr/bin/perl -w # # showmepostenv.cgi v0.2 --crb3 26sep01/08jun03 # # display all the args provided to a CGI program by the http server. # $genpage="$0: GET/POST Parameters Display"; # # # # $isarg=0; if(defined($ENV{'CONTENT_LENGTH'})){ # POST params read(STDIN, $postquery, $ENV{'CONTENT_LENGTH'}); $POST{'isarg'} = $isarg |= 2; &cgi_args(\%POST,$postquery); } if(defined($ENV{'QUERY_STRING'})){ # GET params $getquery=$ENV{'QUERY_STRING'}; $GET{'isarg'} = $isarg |= 1 unless length($getquery)<1; &cgi_args(\%GET,$getquery); } $whoami=`whoami`; print "Content-type: text/html\n\n"; print <<EOF; <html><head> <title>$genpage :: $whoami</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <center> <h2> $genpage :: $whoami </h2> </center><hr> EOF if($isarg & 2){ # have POST params? print "CONTENT_LENGTH: ",$ENV{'CONTENT_LENGTH'},"\n<br />\n"; print "<p>POST params:</p><p><pre>$postquery</pre></p><br />\n"; &show_keypairs(\%POST); }else{ print "\$ENV{\'CONTENT_LENGTH\'}"," doesn't exist (no POST params).\n"; } print "<hr>"; if($isarg & 1){ # have GET params? print "QUERY_STRING: ",$ENV{'QUERY_STRING'},"\n<br />\n"; # print "<p>GET params:</p><p><pre>$getquery</pre></p><hr>\n"; &show_keypairs(\%GET); }else{ print "\$ENV{\'QUERY_STRING\'}"," doesn't exist or empty (no GET params).\n"; } print "<hr><h3>Contents of ENV:</h3>\n"; &show_keypairs(\%ENV); print "<hr></body></html>\n"; # #----------------------------------------------- # # cgi_args. # convert a CGI args-string into a hash. # sub cgi_args { my($CGI,$query)=(@_); my(@cmds,$cmd,$key,$arg); @cmds=split('&',$query); # textbook slice 'n' dice stuff rather foreach $cmd (@cmds) { # than pull in a heaping helping of CPAN. ($key,$arg)=split('=',$cmd); $arg =~ tr/+/ /; $arg =~ s/\%([a-fA-F0-9]{2})/pack("C",hex($1))/eg; if(exists($CGI->{$key})){ $CGI->{$key} .= ",$arg"; }else{ $CGI->{$key} = $arg; } } } # # show_keypairs. # factored-out HTML conversion and display of a hash's contents. # sub show_keypairs { my($REF) = shift(@_); my($key,$arg); while( ($key,$arg)=each %$REF){ # escape-out any HTML in key # $key =~ s/\&/&/gi; $key =~ s/\</</gi; $key =~ s/\>/>/gi; $key =~ s/\"/"/gi; # # escape-out any HTML in $arg # $arg =~ s/\&/&/gi; $arg =~ s/\</</gi; $arg =~ s/\>/>/gi; $arg =~ s/\"/"/gi; print "'$key' => '$arg'<BR>\n"; } } |
Grab a gzipped copy here |
| Syntax highlighting using Syntax::Highlight::Engine::Kate |