#!/usr/bin/perl #Get Current Date chomp($DATE = `date`); #Log Directory $dir = "/var/www/logdir"; #Log File $file = "$dir/log.txt"; #Print HTML if tested from a browser print "Content-type: text/html\n\n"; #Open Log File in appended mode open(LOG,">>$file"); #Collect HTML Post Data &getDATA; #Close Log File close(LOG); sub getDATA { # Put the posted data into variables if($ENV{'QUERY_STRING'} ne "") { $buffer = $ENV{'QUERY_STRING'}; } elsif($ENV{'CONTENT_LENGTH'} ne "") { #Read the input stream using the below line read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } elsif($#ARGV > -1) { chomp($buffer = $ARGV[0]); } #print "buffer: $buffer
\n"; #Place buffer into the array @pairs, delimited by the ";%20" #A ";" plus "%20" equals a ";" and a space @pairs = split(/;%20/, $buffer); print "----------------------------------
\n"; print LOG "----------------------------------\n"; $HTTP_REFERER = $ENV{'HTTP_REFERER'}; print "HTTP_REFERER: $HTTP_REFERER
\n"; print LOG "HTTP_REFERER: $HTTP_REFERER\n"; #Enumerate through the @pairs array foreach $pair (@pairs) { #splits each name/value pair on the equal sign delimiter ($name, $value) = split(/=/, $pair); #translates every "+" sign back to a space $value =~ tr/+/ /; #substitute every %HH hex pair back to its equivalent ASCII character, using the pack() function $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #store the values into a hash called %FORM $FORM{$name} = $value; print "DATE: $DATE; NAME: $name;VALUE: $value
\n"; print LOG "DATE: $DATE; NAME: $name; VALUE: $value\n"; } print "----------------------------------
\n"; print LOG "----------------------------------\n"; }