#!/usr/local/bin/perl $thisdir="/www/faculty/copper/2003/INPUT"; $mainpageURL="/faculty/copper/2003/"; $workingdir=$thisdir; $mesgdir="$thisdir/messages"; $readmesgfile = 'readmesg2003.cgi'; @VarNames=(); %VarValues=(); #### when we start to keep messages: $startyear = 2002; $startmonth = 9; chdir($workingdir); $bodystmt = 'bgcolor="#009ebe"'; $title = 'Bulletin Board for Copper Mountain Conference'; if ($ENV{"REQUEST_METHOD"} eq "POST") { read(STDIN,$buffer,$ENV{"CONTENT_LENGTH"}); } else { $buffer=$ENV{"QUERY_STRING"}; } # now we have $VarNames, $VarValues &DecodeUrl($buffer); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year += 1900; $mesgfilehtml = sprintf("%s/mesg%d.%02d.html",$mesgdir,$year,$mon+1); $mesgfilecount = sprintf("%s/mesg%d.%02d.count",$mesgdir,$year,$mon+1); print "Content-type: text/html\n\n"; # if the file doesn't exist yet, create it and put in the header if ( ! -f $mesgfilehtml ) { &fileerror($mesgfilehtml) if (!open(MESG,">$mesgfilehtml")); printf MESG "",$year,$mon+1; print MESG "",$mon+1,"/",$year,"\n"; close(MESG); system("chmod 666 $mesgfilehtml"); } &fileerror($mesgfilehtml) if (!open(MESG,$mesgfilehtml)); # get the count $count=0; if (( ! -f $mesgfilecount)||(!open(COUNT,$mesgfilecount))) { while () { chop; if (//) { $count=$1; } } } else { $_ = ; chop; if (/^(\d+)$/) { $count=$1; } close(COUNT); system("chmod 666 $mesgfilecount"); } $count++; # remove all <>'s from VarValues foreach $i ("name","email","subject","message","homepage") { $VarValues{$i} =~ s//>/g; } &fileerror($mesgfilehtml) if (!open(MESG,">>$mesgfilehtml")); printf MESG "\n",$count; print MESG "\n"; printf MESG "\n",$mday; print MESG "\n" if ($VarValues{"homepage"} ne ""); print MESG "\n"; $VarValues{"name"}="Anonymous" if !$VarValues{"name"}; $VarValues{"email"}="None" if !$VarValues{"email"}; $VarValues{"subject"}="None" if !$VarValues{"subject"}; print MESG "Name:",$VarValues{"name"},"
\n"; print MESG "Email:",$VarValues{"email"},"
\n"; print MESG "Subject:",$VarValues{"subject"},"
\n"; print MESG "\n"; $VarValues{"message"} =~ s/\n/
\n/g; print MESG $VarValues{"message"},"
\n"; print MESG "\n"; close(MESG); if (open(COUNT,">$mesgfilecount")) { printf COUNT "%d\n",$count; close(COUNT); system("chmod 666 $mesgfilecount"); } print "\n"; print "$title\n"; print "\n"; print ""; print "

Your message was posted

\n"; printf "You were message #%d of the month.

\n",$count; print "Here's what you wrote, as I saw it:

\n

    \n"; print "
  • Name: ",$VarValues{"name"},"\n"; print "
  • Email: ",$VarValues{"email"},"\n"; print "
  • Homepage: ",$VarValues{"homepage"},"\n" if ($VarValue{"homepage"} ne ""); print "
  • Subject: ",$VarValues{"subject"},"\n"; print "
  • Message:
    \n
    \n
    \n"; print $VarValues{"message"},"
    \n"; print "
\n"; print "


\n"; print "Scan the messages.


\n"; print "Return to main page\n"; print "\n\n"; exit 0; sub fileerror { local($name)=$_[0]; print "Error\n"; print "\n"; print "Couldn't open $name.\n"; exit 1; } sub DecodeUrl { local($str) = $_[0]; # don't modify original string local(@entries,$val); %VarValues=(); @VarNames=(); # clear any old values @entries = split("&",$str); # split into entries #print STDOUT "Num = ",$#entries,"\n"; # go through each entry, split into varname and value, remove # +'s and hex codes for (local($i)=0;$i<=$#entries;$i++) { #print STDOUT 'entry=',$entries[$i],"\n"; # split into name and value ($VarNames[$i],$val) = split("=",$entries[$i]); #print STDOUT "name=",$names[$i]," val=",$val,"\n"; $val =~ s/\+/ /g; # replace +'s with spaces # this is why we love perl--replace hex codes w/ ascii char # there's probably a better way to do this, but this seems to # work pretty well. 1 while $val =~ s/(.*)%([\da-fA-F]{2})(.*)/$val=sprintf("%s%c%s",$1,hex($2),$3)/eg; # get rid of ^M's $val =~ s/\r//g; $VarValues{$VarNames[$i]} = $val; #print STDOUT "-----------\n"; } $i; # return the number of entries (not the highest index) } # $number = &GetNumVars($string); sub GetNumVars { local($str) = $_[0]; # don't modify original string local(@temp); @temp = split("&",$str); # split around &'s, into entries $#temp + 1; # returns the number elements in $temp }