#!/usr/bin/perl -w #----------------------------------------------------------------------------- # echo.cgi : Echos information sent from client in an HTTP request. # * Reads in all of STDIN. # * Prints out all the HTTP Environment variables. # * Prints out to STOUT all it read in. # Parke Godfrey ©2012 Oct 9 use URI::Escape; #----------------------------------------------------------------------------- # Read in all the standard input (POST). my $buffer; open(BUFFER, ">", \$buffer) or die "Can't open buffer to write: $!"; while (<>) { print BUFFER; } close(BUFFER); #----------------------------------------------------------------------------- # Print headers. print "Content-Type: text/html\n"; # Header: Content-Type print "\n"; # Blank line ending Headers #----------------------------------------------------------------------------- # Print start of HTML document. print "\n" . "\n" . "
\n" . "\n" . "\n"; #----------------------------------------------------------------------------- # Print out HTTP ENV variables and values. print ""; foreach my $key (keys %ENV) { if ($key =~ /^HTTP_(.*)$/) { print $1, ": ", $ENV{$key}, "\n"; } } print "\n"; #----------------------------------------------------------------------------- # Print out Query String from URL (GET). (It might not exist.) print "
"; if ($ENV{"QUERY_STRING"} ne "") { print $ENV{"QUERY_STRING"}, "\n"; } print "\n"; #----------------------------------------------------------------------------- # Print out (echo) the payload that we read in. print "
\n"; open(BUFFER, "<", \$buffer) or die "Can't open buffer to read: $!"; while (\n"; #----------------------------------------------------------------------------- # Show parsed parameter key-value pairs, if any. # Remember to URI unescape! And turn +'s into spaces. if ($ENV{"QUERY_STRING"} ne "" or $buffer ne "") { print ") { print; } close(BUFFER); print "
" . "
$key: | \n" . "\"$val\" | \n" . "