Here is a better commented version of the Perl service program. The old
comments were just for me.
#!C:\Perl\bin\perl
#this program reads a string sent by the post method
#and makes an xml file from it. This xml file is
#displayed in HTML as a blog.
$LengthOfArray=51;
print "Content-type:text/html\n\n";
#read input string sent by post method
$input =$ENV{'QUERY_STRING'};
#get rid of hex packing and other chars
$input =~ s/%(..)/pack("c",hex($1))/eg;
$input =~ tr|;|.|;
$input =~ tr|'| |;
$input =~ tr|"| |;
#split the incoming string string
($name,$password, $comment, $select) = split(/&/,$input);
#split data again at equal sign relationship
($dummey,$name) = split(/=/,$name);
#replace a + with a space
$name =~ tr|+| |;
if(!$name)
{$name ="no_data";}
#security replace all control characters with a underbar
$name =~ tr/\000-\047/_/;
#split data again at equal sign relationship
($dummey,$comment) = split(/=/,$comment);
#replace a + with a space
$comment =~ tr|+| |;
if(!$comment)
{$comment ="no_data";}
#security replace all control characters with a space
$comment =~ tr/\000-\047/ /;
#split data again at equal sign relationship
($dummey,$password) = split(/=/,$password);
#replace a + with a space
$name =~ tr|+| |;
if(!$passowrd)
{$passowrd ="no_data";}
#security replace all control characters with a underbar
$password =~ tr/\000-\047/_/;
#split data again at equal sign relationship
($dummey,$select) = split(/=/,$select);
#replace a + with a space
$select =~ tr|+| |;
if(!$select)
{$select ="no_data";}
#security replace all control characters with a underbar
$select =~ tr/\000-\047/_/;
# check to see if password entered
if($password ne "Turners")
{$name ="Blocked!";
$comment ="Comment blocked, Wrong Password!";
$select ="Blocked!";}
# open the relational.txt file for input
..........................................................
open(RELDATA, "<BlogRelData.txt");
flock(RELDATA, 2);
@array = <RELDATA>;
flock(RELDATA, 8);
close (RELDATA);
($count, $xname, $xcomment, $date, $xselect)=split(/;/,$array[0]);
#count test and reset
if($count eq "")
{$count ="0";}
else
{$count = $count+1;}
if($count > 1000)
{$count ="0";}
# get the server time
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
gmtime(time);
#convert hour and month to eastern standard time
if($hour <= 5)
{
$hour=$hour+19;
$mday=$mday-2;
}
else
{$hour=$hour-5;
$mday=$mday-1;
}
#compost the date variable
$date = "Month-"."$mon"." Day-"."$mday"." Hour-"."$hour";
# compose a period delimited composite variable
$data = "$count".";"."$name".";"."$comment".";"."$date".";"."$select";
#determine the array length
$alength = @array;
#limit the length of the array
if($alength >= $LengthOfArray)
{pop(@array);}
#unshift new comosite array value into array
unshift(@array, $data);
#output the array to a text file-----------------------------------------
if($count >= 0 && $count < 100000)
{
open(RESULT, ">BlogRelData.txt");
flock(RESULT, 2);
foreach $array(@array)
{
$array =~ s/\n//g;
print RESULT $array;
print RESULT "\n";
}
flock(RESULT, 8);
close (RESULT);
}
#print array to an XML file____________________
#open the xml file for
output..........................................................
open(XML, ">BlogData.xml");
flock(XML, 2);
print XML "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
print XML "<Namefile>\n";
# xml output sequence...........................
for( $i=0; $i < $alength; $i=$i+1 )
{
$packet = $array[$i];
($count, $xname, $xcomment, $xdate, $xselect)=split(/;/, $packet);
if($xpages eq "")
{$xpages ="no data";}
#security replace all control characters with an underbar
$xname =~ s/<(([^>]|\n)*)>/_/g;
$xcomment =~ s/<(([^>]|\n)*)>/_/g;
$xdate =~ s/<(([^>]|\n)*)>/_/g;
$xselect =~ s/<(([^>]|\n)*)>/_/g;
# xml output sequence...........................
print XML "<cd>\n";
print XML "<visitor>";
print XML $count;
print XML "</visitor>\n";
print XML "<date>";
print XML "$xdate";
print XML "</date>\n";
print XML "<name>";
print XML "$xname";
print XML "</name>\n";
print XML "<comment>";
print XML "$xcomment";
print XML "</comment>\n";
print XML "<select>";
print XML "$xselect";
print XML "</select>\n";
print XML "</cd>\n";
}
print XML "</Namefile>";
flock(XML, 8);
close (XML);
#sleep for seconds
sleep(1);
# REDIRECT TO BACK TO THE HTML TABLE ..............
print "<html>\n";
print "<script>\n";
print
"window.location.replace(\"http://www.angelfire.com/scifi2/zpt/blog.html\")";
print "</script>\n";
print "</html>";
#END OF XML FILE