#!/usr/bin/perl $thisdir="/www/faculty/copper/2002/INPUT"; $mainpageURL="/faculty/copper/2002/"; $addmesgfile = "addmesg.html"; $readmesgfile = "readmesg.cgi"; $workingdir=$thisdir; $mesgdir="$thisdir/messages"; @VarNames=(); %VarValues=(); # the month and year you started the bulletin board $startyear = 2000; # <------ update $startmonth = 9; # <------ update chdir($workingdir); # how the background and colors should look $bodystmt = 'bgcolor="#009ebe"'; # the title of all outputted pages $title="Bulletin Board for Copper Mountain Conference"; @months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); @months=("January","February","March","April","May","June", "July","August","September","October","November","December"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year += 1900; print "Content-type: text/html\n\n"; print "\n"; print "\n\n$title\n"; # create a form -- this is the case where the program was linked directly # (i.e. ). in this case, create a nice looking # form which lets the user specify how to scan for messages if (($ENV{"REQUEST_METHOD"} eq "GET") && ($ENV{"QUERY_STRING"} eq "")) { # when we'll start looking from $m = $startmonth; $y = $startyear; # a little html code print "\n"; print "

Select what you want

\n"; print "

Please fill out the form below to choose which messages\n"; print "you would like to scan.

\n"; print "

\n"; print "Which Month:\n"; print " All
  • Names
  • Email address
  • Subjects
  • Numbers Please enter the string to seach over here.
    Seach String:
               

  • Post a message to the bulletin board.


    Return to main page EOR exit 0; } # this will get the url-encoded data string (all the stuff the # user-entered into netscape) and put it in variable called $buffer if ($ENV{"REQUEST_METHOD"} eq "POST") { read (STDIN,$buffer,$ENV{"CONTENT_LENGTH"}); } else { $buffer=$ENV{"QUERY_STRING"}; } # decode it and put stuff in array VarValues and hashtable VarValues &DecodeUrl($buffer); # give 'em easier to type names @names = @VarNames; %values = %VarValues; # we don't need all that memory anymore @VarNames=(); %VarValues=(); # get the month and year from the url-encoded string ($m,$y)= split(/:/,$values{"month"}); # start the html code print "\n"; # bad month # 1. $m is not "all" and it's not a number # 2. $m is a number but the year is not a number # 3. $m is a number but it's larger than 12 or less than 1 if ( (($m !~ /^all$/) && ($m !~ /^\d+$/)) || (($m =~ /^\d+/) && ($y !~ /^\d+/)) || (($m =~ /^\d+$/) &&($m > 12 || $m < 1)) ) { print "

    Bad Format

    \n"; print "The month field isn't in the correct format, which means\n"; print "that you're doing something you shouldn't be.\n"; print "

    \n"; print "Try using the offical search page\n"; print "


    \n"; print "Post a message to the bulletin\n"; print "board\n
    \n"; print "Return to main page\n"; print "\n"; exit 1; } # so now month should be either number (1-12) or "all" and year should be good # if we are not supposed to looking through all months, and the url-encoded # string contained a "number=..." field if (($m !~ /^all$/) && ($values{"number"} =~ /^\d+$/)) { # this is the mesgno we want to look for $number=$values{"number"}; # the name of the message file $filename=sprintf("%s/mesg%d.%02d.html",$mesgdir,$y,$m); # if that file's unavailible, give a message &unavail($number,$m,$y) if (!open(MESG,$filename)); $_ = ; # get header # go through each line of the file while () { chop; # found a new message in the file if (//) { next if ($1 != $number); # not our message number } # if not new message line, get next line else { next; } # if we get here, it means we found the appropiate message in # the file # html code print "

    Message #$number

    \n"; # read in the whole message ($date,$homepage,$name,$email,$subject,$message) = &readmessage(MESG); # print out date, header, and message print "Date Posted: ",$months[$m-1]," $date, ",$y,"
    \n"; &printheader($homepage,$name,$email,$subject); print "\nMessage:
    $message

    \n"; print "Post a message to the\n"; print "bulleting board.\n


    \n"; print "Return to main page\n"; print "\n"; # don't do anything more exit 0; } # searching through file # if we get here, we didn't find the message we were looking for &unavail($number,$m,$y); exit 0; } # if we get here, that means we have to search # make sure we have a type of search $values{"searchon"}="all" if ($values{"searchon"} !~ /(name|email|subject|all|number)/); # if they didn't give a search string, then show them everything $values{"searchon"}="all" if (($values{"searchon"} ne "all")&&(!$values{"searchstring"})); # the string to search for (save me a little typing) $str = $values{"searchstring"}; # do all the months if ($m eq "all") { $thismonth=$startmonth; $thisyear=$startyear; } # otherwise, start on the month user requested else { $thismonth=$m; $thisyear=$y; } # a little html code print "

    Messages

    \n"; print "The following messages matched your pattern for "; if ($m eq "all") { print "all months"; } else { print $months[$m-1]," ",$y; } print ".

    \nClick on the number to view the message body


    \n"; #print "

    Parameters:

    \n"; # this loop will be exited depending on whether we're looking at all months # or just one month in particular while (1) { # the name of the current message file to look at $filename=sprintf("%s/mesg%d.%02d.html",$mesgdir,$thisyear,$thismonth); $printedit=0; # if we can get into the file if ((-f $filename)&&(open(MESG,$filename))) { $_ = ; # file header # them print "

    ",$months[$thismonth-1]," ",$thisyear,"

    \n
    "; $printedit=1; # go thru every line in the file while () { chop; # ok, this means the start of a message if (//) { # the message number $number=$1; # read in the message ($date,$homepage,$name,$email,$subject,$message) = &readmessage(MESG); # if we're searching on the name field, and we get a # match (which will also surround the match with # ...) if (($values{"searchon"} eq "name")&&($name =~ s/($str)/$1<\/strong>/ig)) { print "
    \n"; print "Message $number\n"; print "
    "; &printheader($homepage,$name,$email,$subject); } # if we're searching on email field and get a match # (don't highlight match because that will throw off # the "mailto:" thingy) elsif (($values{"searchon"} eq "email")&&($email =~ /$str/i)) { print "
    \n"; print "Message $number\n"; print "
    "; &printheader($homepage,$name,$email,$subject); } # searching on subject with match elsif (($values{"searchon"} eq "subject")&&($subject =~ s/($str)/$1<\/strong>/ig)) { print "
    \n"; print "Message $number\n"; print "
    "; &printheader($homepage,$name,$email,$subject); } # searching on the number and found a match elsif (($values{"searchon"} eq "number")&&($number =~ /^($str)$/)) { print "
    \n"; print "Message $number"; print "\n"; print "
    "; &printheader($homepage,$name,$email,$subject); } # if we're searching all of the messages elsif ($values{"searchon"} eq "all") { print "
    \n"; print "Message $number\n"; print "
    "; &printheader($homepage,$name,$email,$subject); } } # one message in file } # the whole file } # it's a good file # at this point, we're done with that month/year file # give some html print "

    \n" if $printedit; # if we had a specific month, we're done here so leave the outside while last if ($m ne "all"); # otherwise, increment the month and year accordingly if (++$thismonth > 12) { $thismonth=1; $thisyear++; } # exit the loop after we do today's month/year file #last if (($thisyear>=$year)&&($thismonth>$mon+1)); last if (($thisyear>$year)||(($thisyear==$year)&&($thismonth>$mon+1))); } # all the files print "

    Post a message on\n"; print "the bulletin board\n


    \n"; print "Return to main page\n"; print "\n"; # give a little dealy if that particular message isn't there sub unavail { local($number,$m,$y)=@_; print "

    Message Unavailable

    \n"; print "Sorry, but that message # $number of ",$months[$m-1]," ",$y; print "\nappears to be unavailable.

    \n"; print "


    \n"; print "\n"; exit 1; } # reads one whole message assuming the file pointer is in the right place # (the line after ) sub readmessage { local($file)=$_[0]; local($date,$homepage,$name,$email,$subject,$message,$header); $header=0; while (<$file>) { chop; if (//) { $date=$1; } elsif (//) { $homepage=$1; } elsif (//) { $header=1; } elsif ($header && /Name:(.*)
    /) { $name=$1; } elsif ($header && /Email:(.*)
    /) { $email=$1; } elsif ($header && /Subject:(.*)
    /) { $subject=$1; } elsif (//) { while (<$file>) { last if (//); $message.=$_; } return ($date,$homepage,$name,$email,$subject,$message); } } return ($date,$homepage,$name,$email,$subject,$message); } sub printheader { local($homepage,$name,$email,$subject) = @_; print "Name: "; print "" if $homepage; $name = "Anonymous" if (!$name); print $name if ($name); print "" if $homepage; print "
    \nEmail address: "; $email = "None" if (!$email); print "" if ($email ne "None"); print $email; print "" if ($email ne "None"); $subject = "None" if (!$subject); print "
    \nSubject: $subject
    \n"; } 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 }