Приглашаем посетить
Кржижановский (krzhizhanovskiy.lit-info.ru)

WebBBS

############################################
##                                        ##
##                 WebBBS                 ##
##           by Darryl Burgdorf           ##
##       (e-mail burgdorf@awsd.com)       ##
##                                        ##
##         last modified: 5/28/97         ##
##           copyright (c) 1997           ##
##                                        ##
##    latest version is available from    ##
##        http://awsd.com/scripts/        ##
##                                        ##
############################################

# COPYRIGHT NOTICE:
#
# Copyright 1997 Darryl C. Burgdorf.  All Rights Reserved.
#
# This program may be used and modified free of charge by anyone, so
# long as this copyright notice and the header above remain intact.  By
# using this program you agree to indemnify Darryl C. Burgdorf from any
# liability.
#
# Selling the code for this program without prior written consent is
# expressly forbidden.  Obtain permission before redistributing this
# program over the Internet or in any other medium.  In all cases
# copyright and header must remain intact.

# VERSION HISTORY:
#
# 2.14  05/28/97  Allowed for parsing, display or purging of HTML
#                 Added support for WebAdverts banner displays
#                 Added optional headers & footers on message pages
#                 Allowed easy disabling of all e-mail functions
#                 Simplified word-wrap of quoted message text
#                 Added word-wrap to e-mail notifications
#                 Corrected style of password input boxes
#                 Finally fixed message sorting so it's numeric
#                 Fixed bug in message deletion with admin password
#                 Fixed bug in display of author search results
#                 A lot of minor "tweaks" and format alterations
# 2.13  04/06/97  Added $HourOffset
#                 Added $InputColumns and $InputRows
#                 Set $DefaultTime="archive" to index all posts
#                 Incorporated formerly-separate admin script
#                 Added passwords to allow deletions by authors
#                 Added "reversed threaded" listing option
#                 Added timestamp to avoid "constant" cookie updates
#                 Added number of new messages to welcome blurb
#                 Added "X of Y Messages Displayed" to index page
#                 Added "return to index" links to error messages
#                 "Optionalized" e-mail notification of responses
#                 Closed security hole allowing SSI in messages
#                 Fixed minor bug in file locking
#                 Miscellaneous minor "clean-up" revisions
# 2.12  02/26/97  Added "previous" and "next" message links
#                 Added file locking to prevent dup message IDs
#                 Added configurable default settings
#                 Corrected bug in "archive only" display options
# 2.11  02/14/97  Temporary fix for cookie domain bug
# 2.10  02/11/97  Added optional support for cookies
#                 Eliminated need for initial "setup" page
#                 Added "archive only" option
#                 Added "single line breaks" option
#                 Added ability to search by author's name
#                 Finally tracked down and squashed "new post" bug
#                   (Many thanks to Perry Paolantonio!)
# 2.01  02/02/97  Name changed from "WebBoard" to "WebBBS"
#                 Added automatic quoting of previous message
#                 Removed sometimes-problematic "location" call
#                 Eliminated redundant e-mail notifications
#                 Corrected bug with $name variable
# 2.00  01/19/97  Complete "from the ground up" rewrite
#                   (Major change: Use of dynamic page generation)
# 1.01  01/04/97  Added option to allow embedded HTML in messages
#                 Minor bug fixes and format alterations
# 1.00  12/22/96  Initial "public" release
#                   (Had been in use privately for months)

sub WebBBS {
	$version = "2.14";
	$UseLocking = 1;
	%MonthToNumber=
	  ('Jan','00','Feb','01','Mar','02',
	  'Apr','03','May','04','Jun','05',
	  'Jul','06','Aug','07','Sep','08',
	  'Oct','09','Nov','10','Dec','11');
	require "timelocal.pl";
	if ($UseCookies) {
		$Cookie_Exp_Date = "Fri, 31-Dec-1999 00:00:00 GMT";
		if ($cgiurl =~ m#^http://([\w-\.]+):?(\d*)/(.+)/#o) {
			$Cookie_Path = "/$3/";
		}
		&GetCompressedCookies($boardname);
	}
	unless ($InputColumns) { $InputColumns = 80; }
	if ($InputColumns < 25) { $InputColumns = 25; }
	unless ($InputRows) { $InputRows = 15; }
	if ($InputRows < 5) { $InputRows = 5; }
	$InputLength = int($InputColumns/2);
	&Parse_Form;
	&Get_Date;
	print "Content-type: text/html\n";
	if ($ENV{'QUERY_STRING'} =~ /read=(\d+)/i) {
		&DisplayMessage($1);
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /post/i) {
		&PostMessage;
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /addresslist/i) {
		&UpdateAddressList;
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /reconfigure/i) {
		&Reconfigure;
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /delete/i) {
		&Delete;
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /admin/i) {
		if ($passwordfile) {
			$AdminDisplay=1;
		}
		&DisplayIndex;
		exit;
	}
	elsif ($ENV{'QUERY_STRING'} =~ /newpass/i) {
		&newpass;
		exit;
	}
	else {
		&DisplayIndex;
		exit;
	}
}

sub Parse_Form {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs){
		($val1, $val2) = split(/=/, $pair);
		$val1 =~ tr/+/ /;
		$val1 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$val2 =~ tr/+/ /;
		$val2 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		unless (($AllowHTML > 1) && ($val1 eq "body")) {
			$val2 =~ s/<!--([^>]|\n)*-->/ /g;
		}
		if (($AllowHTML < 1) || ($val1 ne "body")) {
			$val2 =~ s/<([^>]|\n)*>/ /g;
		}
		unless (($AllowHTML eq "1") && ($val1 eq "body")) {
			$val2 =~ s/\&/\&\;/g;
			$val2 =~ s/"/\"\;/g;
			$val2 =~ s/</\<\;/g;
			$val2 =~ s/>/\>\;/g;
		}
		$val2 =~ s/\cM\n/<BR>/g;
		$val2 =~ s/\n\cM/<BR>/g;
		$val2 =~ s/\cM/<BR>/g;
		$val2 =~ s/\n/<BR>/g;
		$val2 =~ s/<BR>\s\s\s+/<BR><BR>/g;
		$val2 =~ s/<BR>\t/<BR><BR>/g;
		$val2 =~ s/\s+/ /g;
		$val2 =~ s/<BR>\s/<BR>/g;
		$val2 =~ s/\s<BR>/<BR>/g;
		$val2 =~ s/<BR><BR>/<P>/g;
		$val2 =~ s/<P><BR>/<P>/g;
		$val2 =~ s/<P>>/<P>>/g;
		$val2 =~ s/<BR>>/<BR>>/g;
		unless ($SingleLineBreaks) {
			$val2 =~ s/<BR>>/<BRR>/g;
			$val2 =~ s/<BR>/ /g;
			$val2 =~ s/<BRR>/<BR>>/g;
		}
		$val2 =~ s/<P>/\n<P>/g;
		$val2 =~ s/<BR>/\n<BR>/g;
		$val2 =~ s/<P>\n/\n/g;
		$val2 =~ s/<BR>\n/\n/g;
		if ($FORM{$val1}) {
			$FORM{$val1} = "$FORM{$val1}, $val2";
		}
		else {
			$FORM{$val1} = $val2;
		}
	}
}

sub DisplayMessage {
	opendir(MESSAGES,$dir) || &Error_File($dir);
	@messages = readdir(MESSAGES);
	@sortedmessages = sort {$a<=>$b} @messages;
	closedir(MESSAGES);
	foreach $message (@sortedmessages) {
		if (($message < $1) && ($message > 0)) {
			$prevmessage = $message;
		}
		elsif ($message > $1) {
			$nextmessage = $message;
			last;
		}
	}
	$messagenumber = $1;
	open(FILE,"$dir/$messagenumber") || &Error_NoMessage;
	@message = <FILE>;
	close(FILE);
	print "\n";
	foreach $line (@message) {
		if ($line =~ /^SUBJECT>(.*)/i) { $subject = $1; }
		elsif ($line =~ /^POSTER>(.*)/i) { $poster = $1; }
		elsif ($line =~ /^EMAIL>(.*)/i) { $email = $1; }
		elsif ($line =~ /^DATE>(.*)/i) { $date = $1; }
		elsif ($line =~ /^EMAILNOTICES>/i) { next; }
		elsif ($line =~ /^PASSWORD>(.*)/i) { $oldpassword = $1; }
		elsif ($line =~ /^PREVIOUS>(.*)/i) { $previous = $1; }
		elsif ($line =~ /^NEXT>(.*)/i) { $next = $1; }
		elsif ($line =~ /^LINKNAME>(.*)/i) { $linkname = $1; }
		elsif ($line =~ /^LINKURL>(.*)/i) { $linkurl = $1; }
		elsif (!$startup) {
			$startup = 1;
			print "<HTML><HEAD><TITLE>$subject</TITLE></HEAD>\n";
			print "<BODY $bodyspec>\n";
			if ($MessageHeaderFile) {
				open (HEADER,"$MessageHeaderFile");
				@header = <HEADER>;
				close (HEADER);
				foreach $line (@header) { print "$line"; }
			}
			print "<P ALIGN=CENTER>[ <A HREF=\"#Responses\">";
			print "Read Responses</A> | ";
			unless ($ArchiveOnly) {
				print "<A HREF=\"#PostResponse\">";
				print "Post a New Response</A> | ";
			}
			print "<A HREF=\"$cgiurl\">";
			print "Return to the Index</A> ]</P>\n";
			print "<P ALIGN=CENTER><STRONG>[ ";
			if ($prevmessage > 0) {
				$tracker = 1;
				print "<A HREF=\"$cgiurl?read=$prevmessage\">";
				print "Previous</A>";
			}
			if ($previous > 0) {
				if (-e "$dir/$previous") {
					if ($tracker > 0) { print " | "; }
					$tracker = 1;
					print "<A HREF=\"$cgiurl?";
					print "read=$previous\">";
					print "Previous in Thread</A>";
				}
			}
			if ($next) {
				@responses = split(/ /,$next);
				foreach $response (@responses) {
					if ((-e "$dir/$response")
					  && ($response >0)) {
						if ($tracker > 0) { print " | "; }
						$tracker = 1;
						print "<A HREF=\"$cgiurl?";
						print "read=$response\">";
						print "Next in Thread</A>";
						last;
					}
				}
			}
			if ($nextmessage > 0) {
				if ($tracker > 0) { print " | "; }
				print "<A HREF=\"$cgiurl?read=$nextmessage\">";
				print "Next</A>";
			}
			print " ]</STRONG></P><HR>\n";
			print "<H2 ALIGN=CENTER>$boardname</H2>\n";
			print "<H1 ALIGN=CENTER>$subject</H1>\n";
			print "<P ALIGN=CENTER><EM>Posted by <STRONG>";
			if ($email) {
				print "<A HREF=\"mailto:$email\">$poster</A>";
			}
			else { print "$poster"; }
			print "</STRONG> on <STRONG>$date</STRONG>";
			if (length($previous) > 25) {
				print ", in response to $previous.";
			}
			elsif ($previous > 0) {
				&GetMessageDesc($previous);
				if ($subject{$previous}) {
					print ", in response to ";
					print "<A HREF=\"$cgiurl?";
					print "read=$previous\">";
					print "$subject{$previous}</A>, ";
					print "posted by ";
					print "$poster{$previous} on ";
					print "$date{$previous}";
				}
			}
			print "</EM></P>\n";
			print $line;
		}
		else { print $line; }
	}
	print "</P>\n";
	if ($linkurl) {
		print "<P ALIGN=CENTER>";
		print "<EM><A HREF=\"$linkurl\">";
		print "$linkname</A></EM></P>\n";
	}
	print "<A NAME=\"Responses\"><HR></A>";
	print "<H2 ALIGN=CENTER>Responses</H2>\n";
	print "<P><UL>";
	@responses = split(/ /,$next);
	$responsecount = 0;
	foreach $response (@responses) {
		&GetMessageDesc($response);
		if ($subject{$response}) {
			&PrintMessageDesc($response);
			$responsecount ++;
		}
	}
	if ($responsecount eq 0) {
		print "(No responses to this message have been posted.)";
	}
	print "</UL></P>\n";
	unless ($ArchiveOnly) {
		print "<A NAME=\"PostResponse\"><HR></A>";
		print "<H2 ALIGN=CENTER>Post a New Response</H2>\n";
		&Print_Form($1);
	}
	print "<HR><P><CENTER>\n",
	  "<FORM METHOD=POST ACTION=\"$cgiurl?delete\">\n",
	  "<INPUT TYPE=HIDDEN NAME=\"password\" ",
	  "VALUE=\"$oldpassword\">\n",
	  "<INPUT TYPE=HIDDEN NAME=\"message\" ",
	  "VALUE=\"$messagenumber\">\n",
	  "<INPUT TYPE=SUBMIT VALUE=\"Delete Message\"> ",
	  "Password: <INPUT TYPE=PASSWORD NAME=\"newpassword\" ",
	  "SIZE=15>\n</FORM></CENTER></P>\n",
	  "<HR><P ALIGN=CENTER><SMALL>The $boardname is maintained ",
	  "with <STRONG><A HREF=\"http://awsd.com/scripts/webbbs/\">",
	  "WebBBS $version</A></STRONG>.</SMALL></P>\n";
	if ($MessageFooterFile) {
		open (FOOTER,"$MessageFooterFile");
		@footer = <FOOTER>;
		close (FOOTER);
		foreach $line (@footer) { print "$line"; }
	}
	print "</BODY></HTML>\n";
}

sub Delete {
	$PassCheck = 0;
	unless ($FORM{'newpassword'}) { &Error_Password; }
	$newpassword = crypt($FORM{'newpassword'},aa);
	if ($FORM{'password'}) {
		if ($newpassword eq $FORM{'password'}) {
			$PassCheck = 1;
		}
	}
	unless ($PassCheck == 1) {
		if (!$passwordfile) {
			&Error_Password;
		}
		open (PASSWORD, "$dir/$passwordfile");
		$password = <PASSWORD>;
		close (PASSWORD);
		chop ($password) if ($password =~ /\n$/);
		if (!$password) { &newpass; }
		unless ($newpassword eq $password) { &Error_Password; }
	}
	@messages = split(/, /,$FORM{'message'});
	foreach $message (@messages) { unlink "$dir/$message"; }
	print "\n",
	  "<HTML><HEAD><TITLE>Message(s) Deleted!</TITLE></HEAD>\n",
	  "<BODY $bodyspec><H1 ALIGN=CENTER>Your Message(s) ",
	  "Have Been Deleted!</H1>\n",
	  "<P>The designated message(s) are no longer on the board. ",
	  "If you have any questions, please send a note to ",
	  "<A HREF=\"mailto:$maillist_address\">",
	  "$maillist_address</A>. ",
	  "Thanks!\n";
	&Footer;
	exit;
}

sub Error_Password {
	&Error_Header;
	print "<H1 ALIGN=CENTER>Invalid Password!</H1>\n";
	print "<P>The message(s) were not deleted, ";
	print "as either the password was incorrect ";
	print "or no password was entered!\n";
	&Footer;
	exit;
}

sub GetMessageDesc {
	open(FILE,"$dir/$_[0]");
	@lines = <FILE>;
	close(FILE);
	foreach $line (@lines) {
		if ($line =~ /^SUBJECT>(.*)/i) {
			$subject{$_[0]} = $1;
		}
		elsif ($line =~ /^POSTER>(.*)/i) {
			$poster{$_[0]} = $1;
		}
		elsif ($line =~ /^DATE>(.*)/i) {
			$date{$_[0]} = $1;
		}
		elsif ($line =~ /^PREVIOUS>(.*)/i) {
			$previous{$_[0]} = $1;
		}
		elsif ($line =~ /^NEXT>(.*)/i) {
			$next{$_[0]} = $1; last;
		}
	}
}

sub PrintMessageDesc {
	print "<LI>";
	if ($AdminDisplay) {
		print "<INPUT TYPE=CHECKBOX ";
		print "NAME=\"message\" VALUE=\"$_[0]\"> ";
	}
	print "<STRONG>";
	if ($Cookies{'lastmessage'}
	  && ($Cookies{'lastmessage'} < $_[0])) {
		print "<EM>NEW:</EM> ";
	}
	print "<A HREF=\"$cgiurl?read=$_[0]\">";
	print "$subject{$_[0]}</A></STRONG><BR>";
	print "$poster{$_[0]} -- <EM>$date{$_[0]}</EM>\n";
}

sub Print_Form {
	print "<P><FORM METHOD=POST ACTION=\"$cgiurl?post\">\n";
	if ($_[0]) {
		print "<INPUT TYPE=HIDDEN NAME=\"followup\" ";
		print "VALUE=\"$_[0]\">\n";
	}
	print "<P><CENTER><TABLE><TR>\n";
	print "<TD ALIGN=RIGHT><P><STRONG>Your Name:</STRONG>";
	print "</TD><TD><INPUT TYPE=TEXT NAME=\"name\" SIZE=$InputLength";
	if ($Cookies{'name'}) {
		print " VALUE=\"$Cookies{'name'}\"";
	}
	print "></TD></TR><TR>\n";
	print "<TD ALIGN=RIGHT><P><STRONG>E-Mail Address:</STRONG>";
	print "</TD><TD><INPUT TYPE=TEXT NAME=\"email\" ";
	print "SIZE=$InputLength";
	if ($Cookies{'email'}) {
		print " VALUE=\"$Cookies{'email'}\"";
	}
	print "></TD></TR><TR>\n";
	print "<TD ALIGN=RIGHT><P><STRONG>Subject:</STRONG>";
	print "</TD><TD><INPUT TYPE=TEXT NAME=\"subject\" ";
	print "SIZE=$InputLength";
	if ($_[0]) {
		print " VALUE=\"";
		unless ($subject =~ /^Re:/) { print "Re: "; }
		print "$subject\"";
	}
	print "></TD></TR><TR>\n";
	print "<TD COLSPAN=2 ALIGN=CENTER>";
	print "<P><STRONG>Message:</STRONG>";
	print "<BR><TEXTAREA COLS=$InputColumns ROWS=$InputRows ";
	print "NAME=\"body\" WRAP=VIRTUAL>\n";
	if ($_[0] && $AutoQuote) {
		$quotedtext = "";
		foreach $line (@message) {
			unless (($line =~ /^SUBJECT>/i)
			  || ($line =~ /^POSTER>/i)
			  || ($line =~ /^EMAIL>/i)
			  || ($line =~ /^DATE>/i)
			  || ($line =~ /^EMAILNOTICES>/i)
			  || ($line =~ /^PASSWORD>/i)
			  || ($line =~ /^PREVIOUS>/i)
			  || ($line =~ /^NEXT>/i)
			  || ($line =~ /^LINKNAME>/i)
			  || ($line =~ /^LINKURL>/i)
			  || ($line =~ /^<([^>])*>>/i)
			  || ($line =~ /^<([^>])*>>/i)
			  || (length($line) < 2)) {
				$quotedtext = $quotedtext.$line;
			}
		}
		$quotedtext =~ s/\n/ /g;
		$quotedtext =~ s/<P>/\n\n\>\; /g;
		$quotedtext =~ s/<BR>/\n\>\; /g;
		$quotedtext =~ s/<([^>]|\n)*>/ /g;
		$quotedtext =~ s/\& /\&\; /g;
		$quotedtext =~ s/"/\"\;/g;
		$quotedtext =~ s/</\<\;/g;
		$quotedtext =~ s/>/\>\;/g;
		$length = length($quotedtext)-1;
		$wrapcount = 0;
		foreach $key (0..$length) {
			$char = substr($quotedtext,$key,1);
			$wrapcount++;
			if (($wrapcount > ($InputColumns-15))
			  && ($char eq " ")) {
				$char = "\n> ";
			}
			print "$char";
			if ($char =~ /\n/) {
				$wrapcount = 0;
			}
		}
		print "\n";
	}
	print "</TEXTAREA></TD></TR><TR>\n",
	  "<TD COLSPAN=2 ALIGN=CENTER><HR WIDTH=50%>",
	  "<P><SMALL>If you'd like to include ",
	  "a link to another page with your message,",
	  "<BR>please provide both the URL address ",
	  "and the title of the page:</SMALL>",
	  "</TD></TR><TR>\n",
	  "<TD ALIGN=RIGHT><P><STRONG>Optional Link ",
	  "URL:</STRONG></TD><TD><INPUT TYPE=TEXT ",
	  "NAME=\"url\" SIZE=$InputLength VALUE=\"http://\">",
	  "</TD></TR><TR>\n",
	  "<TD ALIGN=RIGHT><P><STRONG>Optional Link ",
	  "Title:</STRONG></TD><TD><INPUT TYPE=TEXT ",
	  "NAME=\"url_title\" SIZE=$InputLength></TD></TR><TR>\n",
	  "<TD COLSPAN=2 ALIGN=CENTER><HR WIDTH=50%>",
	  "<P><SMALL>If you'd like to have the option ",
	  "of deleting your post later,",
	  "<BR>please provide a password (CASE SENSITIVE!):</SMALL>",
	  "</TD></TR><TR>\n",
	  "<TD ALIGN=RIGHT><P><STRONG>Password:</STRONG>",
	  "</TD><TD><INPUT TYPE=PASSWORD NAME=\"password\" ",
	  "SIZE=$InputLength></TD></TR><TR>\n",
	  "<TD COLSPAN=2 ALIGN=CENTER><HR WIDTH=50%>";
	if ($mailprog) {
		print "<P><SMALL>If you'd like e-mail notification ";
		print "of responses, please check this box:</SMALL> ";
		print "<INPUT TYPE=CHECKBOX NAME=\"wantnotice\"";
		unless ($Cookies{'wantnotice'} eq "no") {
			print " CHECKED";
		}
		print " VALUE=\"yes\"></TD></TR><TR>\n";
		print "<TH COLSPAN=2><HR WIDTH=50%><P>";
	}
	print "<INPUT TYPE=SUBMIT VALUE=\"Post Message\"></TH>";
	print "</TR></TABLE></CENTER></P></FORM>\n";
}

sub newpass {
	if (!$passwordfile) {
		&DisplayIndex;
		exit;
	}
	$newpassword = crypt($FORM{'newpassword'},aa);
	open (PASSWORD, "$dir/$passwordfile");
	$password = <PASSWORD>;
	close (PASSWORD);
	chop ($password) if ($password =~ /\n$/);
	if (!$password) {
		unless ($FORM{'changeto'}) {
			$FORM{'changeto'} = $FORM{'newpassword'};
		}
	}
	else {
		unless ($newpassword eq $password) { &Error_Password; }
	}
	print "\n";
	$newpassword = crypt($FORM{'changeto'},aa);
	open (PASSWORD, ">$dir/$passwordfile")
	  || &Error_File($dir/$passwordfile);
	$lockerror = &LockFile(PASSWORD);
	if ($lockerror) {
		print "[ File Lock Error! ]";
		exit;
	}
	print PASSWORD "$newpassword";
	&UnlockFile(PASSWORD);
	close (PASSWORD);
	print "<HTML><HEAD><TITLE>Password Changed";
	print "</TITLE></HEAD><BODY $bodyspec>\n";
	print "<P>The new administrative password is ";
	print "<STRONG>$FORM{'changeto'}</STRONG>.\n";
	&Footer;
	exit;
}

sub DisplayIndex {
	opendir(MESSAGES,$dir) || &Error_File($dir);
	@messages = readdir(MESSAGES);
	closedir(MESSAGES);
	@sortedmessages = sort {$a<=>$b} @messages;
	$TotalMessages = @sortedmessages;
	$DisplayedMessages = 0;
	$lastmessage = 0;
	foreach $message (@sortedmessages) {
		if ($message == 0) { $TotalMessages --; }
		else {
			if ($message > $lastmessage) {
				$lastmessage = $message;
			}
		}
	}
	if ($UseCookies) {
		if (($FORM{'ListCriteria'} eq "Recent")
		  && ($FORM{'KeySearch'} eq "No")) {
			$listtype = $FORM{'ListType'};
			$listtime = $FORM{'ListTime'};
		}
		if (!($FORM{'ListType'})) {
			$FORM{'ListType'} = $Cookies{'listtype'};
		}
		if (!($FORM{'ListTime'})) {
			$FORM{'ListTime'} = $Cookies{'listtime'};
		}
		&Send_Cookie;
	}
	if (!($FORM{'ListType'})) { $FORM{'ListType'} = $DefaultType; }
	if (!($FORM{'ListTime'})) { $FORM{'ListTime'} = $DefaultTime; }
	print "\n";
	print "<HTML><HEAD><TITLE>$boardname ";
	print "Message Index</TITLE></HEAD>\n";
	print "<BODY $bodyspec>\n";
	if ($HeaderFile) {
		open (HEADER,"$HeaderFile");
		@header = <HEADER>;
		close (HEADER);
		foreach $line (@header) { print "$line"; }
	}
	if ($showbanners) { &insertadvert; }
	print "<P ALIGN=CENTER>[ ";
	unless ($ArchiveOnly) {
		print "<A HREF=\"#PostMessage\">Post ";
		print "a New Message</A> | ";
		if ($mailprog && $address_list) {
			print "<A HREF=\"#Subscribe\">Subscribe</A> | ";
		}
	}
	print "<A HREF=\"$cgiurl?reconfigure\">Search / ";
	print "Personalize Display</A> ]</P>\n";
	if ($Cookies{'lastvisit'}) {
		print "<P ALIGN=CENTER><STRONG>Welcome back";
		if ($Cookies{'name'}) { print ", $Cookies{'name'}"; }
		print "!<EM><BR>Your last visit began ";
		print "on $Cookies{'lastvisit'}</EM>\n";
		if ($Cookies{'lastmessage'} < $lastmessage) {
			$NewCount = $lastmessage - $Cookies{'lastmessage'};
			print "<BR>Since then, $NewCount new message";
			if ($NewCount > 1) { print "s have"; }
			else { print " has"; }
		}
		else {
			print "<BR>Since then, no new messages have";
		}
		print " been posted!</STRONG></P>\n";
	}
	elsif ($Cookies{'lastmessage'}) {
		print "<P ALIGN=CENTER><STRONG>Welcome";
		if ($Cookies{'name'}) { print ", $Cookies{'name'}"; }
		print "!\n";
		if ($Cookies{'lastmessage'} < $lastmessage) {
			$NewCount = $lastmessage - $Cookies{'lastmessage'};
			print "<BR>$NewCount new message";
			if ($NewCount > 1) { print "s have"; }
			else { print " has"; }
			print " been posted!";
		}
		print "</STRONG></P>\n";
	}
	else { print "<P ALIGN=CENTER><STRONG>Welcome!</STRONG></P>\n"; }
	print "<HR>\n";
	print "<H2 ALIGN=CENTER>$boardname</H2>\n";
	print "<H1 ALIGN=CENTER>Message Index</H1>\n";
	if ($AdminDisplay) {
		print "<H2 ALIGN=CENTER><EM>Administrative ",
		  "Display</EM></H2>\n",
		  "<P><BLOCKQUOTE><EM>From this display, ",
		  "you have the option to delete any or all ",
		  "messages. Simply select those you wish to delete, ",
		  "then press the "Delete Messages" button.",
		  "</EM></BLOCKQUOTE>\n",
		  "<FORM METHOD=POST ACTION=\"$cgiurl?delete\">\n",
		  "<P ALIGN=CENTER><STRONG>Password:</STRONG> ",
		  "<INPUT TYPE=PASSWORD NAME=\"newpassword\" ",
		  "SIZE=30>\n";
		$FORM{'ListTime'} = "Archive";
	}
	if ($FORM{'ListCriteria'} eq "Archive") {
		print "<P ALIGN=CENTER>Messages Posted or Last Modified ";
		$starttime =
		  $FORM{'StartYear'}.$MonthToNumber{$FORM{'StartMonth'}};
		$endtime =
		  $FORM{'EndYear'}.$MonthToNumber{$FORM{'EndMonth'}};
		if ($endtime < $starttime) {
			print "Between $FORM{'EndMonth'} $FORM{'EndYear'} ";
			print "and $FORM{'StartMonth'} $FORM{'StartYear'}\n";
			$StartYear = $FORM{'EndYear'}-1900;
			$EndYear = $FORM{'StartYear'}-1900;
			$StartMonth = $MonthToNumber{$FORM{'EndMonth'}};
			$EndMonth = $MonthToNumber{$FORM{'StartMonth'}}+1;
		}
		else {
			if ($starttime eq $endtime) {
				print "During $FORM{'StartMonth'} ";
				print "$FORM{'StartYear'}\n";
			}
			else {
				print "Between $FORM{'StartMonth'} ";
				print "$FORM{'StartYear'} ";
				print "and $FORM{'EndMonth'} ";
				print "$FORM{'EndYear'}\n";
			}
			$StartYear = $FORM{'StartYear'}-1900;
			$EndYear = $FORM{'EndYear'}-1900;
			$StartMonth = $MonthToNumber{$FORM{'StartMonth'}};
			$EndMonth = $MonthToNumber{$FORM{'EndMonth'}}+1;
		}
		if ($EndMonth > 11) {
			$EndMonth = 0; $EndYear = $EndYear+1;
		}
		$startday = &timelocal(0,0,0,1,$StartMonth,$StartYear);
		$endday = &timelocal(0,0,0,1,$EndMonth,$EndYear);
		$startday = (($time-$startday)/86400);
		$endday = (($time-$endday)/86400);
	}
	else {
		$endday = -1;
		unless ($FORM{'ListTime'}) { $FORM{'ListTime'} = "Week"; }
		if ($FORM{'ListTime'} eq "Day") { $startday = 1; }
		elsif ($FORM{'ListTime'} eq "Two Days") { $startday = 2; }
		elsif ($FORM{'ListTime'} eq "Week") { $startday = 7; }
		elsif ($FORM{'ListTime'} eq "Two Weeks") { $startday = 14; }
		elsif ($FORM{'ListTime'} eq "Month") { $startday = 30; }
		else { $startday = 10000; }
		if ($ArchiveOnly || ($startday eq 10000)) {
			print "<P ALIGN=CENTER>All Messages</P>\n";
		}
		else {
			print "<P ALIGN=CENTER>Messages Posted or Modified ";
			print "Within the Last $FORM{'ListTime'}\n";
		}
	}
	if ($FORM{'KeySearch'} eq "Yes") {
		$FORM{'Keywords'} =~ s/\W/ /g;
		@keywords = split(/\s+/, $FORM{'Keywords'});
		print "<P ALIGN=CENTER>Messages Containing ";
		print "<STRONG>$FORM{'Boolean'}</STRONG> ";
		print "of the Keywords:<BR>";
		foreach $keyword (@keywords) {
			print "<STRONG>$keyword</STRONG>";
			$i++;
			if (length($keyword) < 3) { print " (ignored)"; }
			if (!($i == @keywords)) { print ", "; }
			else { print "\n"; }
		}
		foreach $message (@sortedmessages) {
			open (FILE,"$dir/$message");
			@LINES = <FILE>;
			close (FILE);
			$string = join(' ',@LINES);
			$string =~ s/\n//g;
			$value = 0;
			if ($FORM{'Boolean'} eq 'All') {
				foreach $term (@keywords) {
					unless (length($term) < 3) {
						$test = ($string =~ s/$term//ig);
						if ($test < 1) {
							$value = 0;
							last;
						}
						else {
							$value = $value+$test;
						}
					}
				}
			}
			elsif ($FORM{'Boolean'} eq 'Any') {
				foreach $term (@keywords) {
					unless (length($term) < 3) {
						$test = ($string =~ s/$term//ig);
						$value = $value+$test;
					}
				}
			}
			if ($value > 0) {
				push (@keywordmatches, $message);
			}
		}
		@sortedmessages = @keywordmatches;
	}
	elsif ($FORM{'KeySearch'} eq "Author") {
		print "<P ALIGN=CENTER>Messages Posted By ";
		print "<STRONG>"$FORM{'Author'}"</STRONG>\n";
		foreach $message (@sortedmessages) {
			$value = 0;
			&GetMessageDesc($message);
			$subject{$message} = "";
			if ($poster{$message} =~ /$FORM{'Author'}/i) {
				$value = 1;
			}
			if ($value > 0) {
				push (@keywordmatches, $message);
			}
		}
		@sortedmessages = @keywordmatches;
	}
	foreach $message (@sortedmessages) {
		if (((-M "$dir/$message") <= $startday)
		  && ((-M "$dir/$message") > $endday)) {
			&GetMessageDesc($message);
			if ($subject{$message}) {
				$DisplayedMessages ++;
			}
		}
	}
	print "<P ALIGN=CENTER><EM>$DisplayedMessages of ";
	print "$TotalMessages Messages Displayed<BR>";
	unless ($FORM{'ListType'}) {
		$FORM{'ListType'} = "Chronologically";
	}
	if ($FORM{'ListType'} eq "Chronologically") {
		print "(Chronological Listing)";
	}
	elsif ($FORM{'ListType'} eq "By Threads, Reversed") {
		print "(Reversed Threaded Listing)";
	}
	else { print "(Threaded Listing)"; }
	print "</EM></P>\n";
	$messagecount = 0;
	print "<P><UL>\n";
	if ($FORM{'ListType'} eq "Chronologically") {
		@messages = reverse(@sortedmessages);
		foreach $message (@messages) {
			if ($subject{$message}) {
				&PrintMessageDesc($message);
				$messagecount ++;
			}
		}
	}
	elsif ($FORM{'ListType'} eq "By Threads, Reversed") {
		@reversedmessages = reverse(@sortedmessages);
		foreach $message (@reversedmessages) {
			if (($subject{$message}) && !($already{$message})) {
				unless ($subject{$previous{$message}}) {
					&ThreadList($message);
					$messagecount ++;
				}
			}
		}
	}
	else {
		foreach $message (@sortedmessages) {
			if (($subject{$message}) && !($already{$message})) {
				&ThreadList($message);
				$messagecount ++;
			}
		}
	}
	print "</UL></P>\n";
	if ($messagecount < 1) {
		print "<P ALIGN=CENTER><STRONG>No messages ";
		print "matched your search criteria! ";
		print "Please try again....</STRONG></P>\n";
	}
	if ($AdminDisplay) {
		print "<P><CENTER><INPUT TYPE=SUBMIT VALUE=\"Delete ",
		  "Messages\"></CENTER></P></FORM>\n",
		  "<HR><FORM METHOD=POST ACTION=\"$cgiurl?newpass\">\n",
		  "<P ALIGN=CENTER><STRONG>Old Password:</STRONG> ",
		  "<INPUT TYPE=TEXT NAME=\"newpassword\" SIZE=30>\n",
		  "<BR><STRONG>New Password:</STRONG> ",
		  "<INPUT TYPE=TEXT NAME=\"changeto\" SIZE=30>\n",
		  "<P><CENTER><INPUT TYPE=SUBMIT VALUE=\"Change ",
		  "Administrative Password\"></CENTER></P></FORM>\n";
	}
	unless ($ArchiveOnly) {
		print "<A NAME=\"PostMessage\"><HR></A>";
		print "<H2 ALIGN=CENTER>Post a New Message</H2>\n";
		&Print_Form;
		if ($mailprog && $address_list) {
			print "<A NAME=\"Subscribe\"><HR></A>",
			  "<H2 ALIGN=CENTER>Subscribe</H2>\n",
			  "<P ALIGN=CENTER><EM>If you'd like to, you ",
			  "can receive automatic e-mail notification ",
			  "of new posts!\n",
			  "<BR>Simply provide your ",
			  "e-mail address below!</EM>\n",
			  "<FORM METHOD=POST ",
			  "ACTION=\"$cgiurl?addresslist\">\n",
			  "<P><CENTER>Your E-Mail Address: ",
			  "<INPUT TYPE=TEXT ",
			  "NAME=\"email\" SIZE=30";
			if ($Cookies{'email'}) {
				print " VALUE=\"$Cookies{'email'}\"";
			}
			print "> <INPUT TYPE=SUBMIT ",
			  "VALUE=\"Send Address\">\n",
			  "<BR><INPUT TYPE=RADIO NAME=\"action\" ",
			  "VALUE=\"add\" CHECKED> Add Address ",
			  "to List <INPUT TYPE=RADIO ",
			  "NAME=\"action\" VALUE=\"delete\"> ",
			  "Delete Address from List",
			  "</CENTER></P></FORM>\n";
		}
	}
	print "<HR><P ALIGN=CENTER><SMALL>The $boardname is maintained ";
	print "with <STRONG><A HREF=\"http://awsd.com/scripts/webbbs/\">";
	print "WebBBS $version</A></STRONG>.</SMALL></P>\n";
	if ($FooterFile) {
		open (FOOTER,"$FooterFile");
		@footer = <FOOTER>;
		close (FOOTER);
		foreach $line (@footer) { print "$line"; }
	}
	print "</BODY></HTML>\n";
}

sub ThreadList {
	local(@responses);
	&PrintMessageDesc($_[0]);
	print "<UL>\n";
	@responses = split(/ /,$next{$_[0]});
	foreach $response (@responses) {
		if ($subject{$response}) {
			&ThreadList($response);
		}
	}
	print "</UL>\n";
	$already{$_[0]} = 1;
}

sub PostMessage {
	$FORM{'email'} =~ s/ |;|,|\*//g;
	if ($FORM{'email'} =~ /.*\@.*\..*/) { $email = "$FORM{'email'}"; }
	$FORM{'url'} =~ s/ |;|,|\*//g;
	if ($FORM{'url'} =~ /.*\:\/\/.*\..*/ && $FORM{'url_title'}) {
		$message_url = "$FORM{'url'}";
		$message_url_title = "$FORM{'url_title'}";
	}
	if ($FORM{'followup'}) { $followup = "$FORM{'followup'}"; }
	if ($FORM{'name'}) { $name = "$FORM{'name'}"; }
	if ($FORM{'subject'}) { $subject = "$FORM{'subject'}"; }
	if ($FORM{'body'}) { $body = "$FORM{'body'}"; }
	unless ($name && $subject && $body) { &Error_Incomplete; }
	$new_body = $body;
	$new_body =~ s/\n/ /g;
	unless (-w "$dir/$dupecheck_file") {
		&Error_File("$dir/$dupecheck_file");
	}
	open (DUPEDATA,"$dir/$dupecheck_file");
	$last_body = <DUPEDATA>;
	close (DUPEDATA);
	if ($last_body eq $new_body) { &Error_Duplicate; }
	else {
		open (DUPEDATA,">$dir/$dupecheck_file");
		print DUPEDATA "$new_body";
		close (DUPEDATA);
	}
	unless (-w "$dir/$datafile") { &Error_File("$dir/$datafile"); }
	open (NUMBER,"+<$dir/$datafile");
	$lockerror = &LockFile(NUMBER);
	if ($lockerror) {
		print "\n",
		  "<HTML><HEAD><TITLE>Message ",
		  "Not Posted</TITLE></HEAD>\n",
		  "<BODY $bodyspec>\n",
		  "<H3 ALIGN=CENTER>Your Message ",
		  "Was Not Posted!</H3>\n",
		  "<P>Apparently, someone else also decided to post a ",
		  "message, and managed to get in just ahead of you, ",
		  "as the the data file is momentarily locked. Please ",
		  "use the "Back" button on your browser to ",
		  "return and try again!\n";
		&Footer;
		exit;
	}
	$num = <NUMBER>;
	$num++;
	seek(NUMBER, 0, 0);
	print NUMBER "$num";
	&UnlockFile(NUMBER);
	close (NUMBER);
	open (MESSAGE,">$dir/$num") || &Error_File("$dir/$num");
	print MESSAGE "SUBJECT>$subject\n";
	print MESSAGE "POSTER>$name\n";
	print MESSAGE "EMAIL>$email\n";
	print MESSAGE "DATE>$todaydate\n";
	if (!$FORM{'wantnotice'}) {
		print MESSAGE "EMAILNOTICES>no\n";
		$Cookies{'wantnotice'} = "no";
	}
	else { $Cookies{'wantnotice'} = ""; }
	if ($FORM{'password'}) {
		$password = crypt($FORM{'password'},aa);
		print MESSAGE "PASSWORD>$password\n";
	}
	if ($FORM{'source_title'} && $FORM{'source_url'}) {
		print MESSAGE "PREVIOUS><A HREF=\"$FORM{'source_url'}\">";
		print MESSAGE "$FORM{'source_title'}</A>\n";
	}
	else { print MESSAGE "PREVIOUS>$followup\n"; }
	print MESSAGE "NEXT>\n";
	print MESSAGE "LINKNAME>$message_url_title\n";
	print MESSAGE "LINKURL>$message_url\n";
	print MESSAGE "<P>$body\n";
	close (MESSAGE);
	if ($followup) {
		open (FOLLOWUP,"$dir/$followup");
		@followup_lines = <FOLLOWUP>;
		close (FOLLOWUP);
		open (FOLLOWUP,">$dir/$followup");
		foreach $line (@followup_lines) {
			if ($line =~ /^SUBJECT>(.*)/i) {
				$subject{$followup} = $1;
			}
			elsif ($line =~ /^POSTER>(.*)/i) {
				$poster{$followup} = $1;
			}
			elsif ($line =~ /^DATE>(.*)/i) {
				$date{$followup} = $1;
			}
			elsif ($line =~ /^EMAIL>(.*)/i) {
				$email{$followup} = $1;
			}
			elsif ($line =~ /^EMAILNOTICES>/i) {
				$wantnotice{$followup} = "no";
			}
			if ($line =~ /^NEXT>/) {
				$line =~ s/\n//g;
				print FOLLOWUP "$line $num\n";
			}
			else {
				print FOLLOWUP "$line";
			}
		}
		close(FOLLOWUP);
	}
	if ($mailprog) {
		$FORM{'subject'} = &UnWebify($FORM{'subject'});
		$FORM{'name'} = &UnWebify($FORM{'name'});
		$FORM{'body'} = &UnWebify($FORM{'body'});
		$subject{$followup} = &UnWebify($subject{$followup});
		$poster{$followup} = &UnWebify($poster{$followup});
		$open1 = "A new message, \"$FORM{'subject'},\" ";
		$open1 = $open1."was posted on the $boardname";
		$open1 = $open1." <$cgiurl> by $FORM{'name'} on $todaydate";
		$open2 = $open1;
		if ($subject{$followup}) {
			$open1 = $open1."  It is a response to ";
			$open1 = $open1."\"$subject{$followup},\" posted by";
			$open1 = $open1." $poster{$followup} on ";
			$open1 = $open1."$date{$followup}";
			$open2 = $open2."  It is a response to your post, ";
			$open2 = $open2."\"$subject{$followup},\"";
			$open2 = $open2." of $date{$followup}";
		}
		$open1 = $open1."\n\n";
		$open2 = $open2."\n\n";
		$body = "The message reads as follows:\n\n";
		$body = $body."                      ";
		$body = $body."-------------------------\n\n";
		$body = $body.$FORM{'body'}."\n\n";
		$body = $body."                      ";
		$body = $body."-------------------------\n\n";
		$close1 = "This is an automatically-generated notice.  ";
		$close1 = $close1."If you'd like to be removed from the ";
		$close1 = $close1."mailing list, please visit the ";
		$close1 = $close1."$boardname at <$cgiurl>, or send your ";
		$close1 = $close1."request to $maillist_address.  If ";
		$close1 = $close1."you wish to respond to this message, ";
		$close1 = $close1."please post your response directly ";
		$close1 = $close1."directly to the board.  Thank you!\n\n";
		$close2 = "This is an automatically-generated notice.  ";
		$close2 = $close2."If you wish to respond to this ";
		$close2 = $close2."message, please post your response ";
		$close2 = $close2."directly to the $boardname at ";
		$close2 = $close2."<$cgiurl>.  Thank you!\n\n";
	}
	if ($mailprog && $address_list) {
		open (ADDRESSES,"$dir/$address_list")
		  || &Error_File("$dir/$address_list");
		@addresses = <ADDRESSES>;
		close (ADDRESSES);
		foreach $address (@addresses) {
			unless ((length($address) < 5)
			  || ($email && ($address =~ /$email/i))
			  || ($email{$followup}
			  && ($address =~ /$email{$followup}/i))) {
				open (MAIL, "|$mailprog -t")
				  || &Error_File($mailprog);
				print MAIL "To: $address",
				  "From: maillist\@SEE.MESSAGE.FOR.ADDRESS\n",
				  "Subject: New $boardname Post\n\n";
				&WordWrap($open1);
				&WordWrap($body);
				&WordWrap($close1);
				close (MAIL);
			}
			if ($email{$followup}
			  && ($address =~ /$email{$followup}/i)) {
				$onrecipientlist = 1;
			}
		}
	}
	if ($mailprog && $email{$followup}) {
		unless ((($wantnotice{$followup} eq "no")
		  && !$onrecipientlist)
		  || ($email{$followup} eq $email)) {
			open (MAIL, "|$mailprog -t")
			  || &Error_File($mailprog);
			print MAIL "To: $email{$followup}\n",
			  "From: maillist\@SEE.MESSAGE.FOR.ADDRESS\n",
			  "Subject: Response to Your $boardname Post\n\n";
			&WordWrap($open2);
			&WordWrap($body);
			&WordWrap($close2);
			close (MAIL);
		}
	}
	if ($UseCookies) {
		&Send_Cookie;
	}
	print "\n";
	print "<HTML><HEAD><TITLE>Message Posted</TITLE></HEAD>\n";
	print "<BODY $bodyspec>\n";
	print "<P ALIGN=CENTER>[ <A HREF=\"$cgiurl?read=$num\">";
	print "Review Your Message</A> | <A HREF=\"$cgiurl\">Return to ";
	print "the Index</A> ]</P><HR>\n";
	print "<H2 ALIGN=CENTER>$boardname</H2>\n";
	print "<H1 ALIGN=CENTER>Your Message Has Been Posted</H1>\n";
	print "<P ALIGN=CENTER>Thanks for contributing!\n";
	&Footer;
}

sub UnWebify {
	$texttoconvert = $_[0];
	$texttoconvert =~ s/<P>/\n\n/g;
	$texttoconvert =~ s/<([^>]|\n)*>//g;
	$texttoconvert =~ s/\"\;/"/g;
	$texttoconvert =~ s/\<\;/</g;
	$texttoconvert =~ s/\>\;/>/g;
	$texttoconvert =~ s/\&\;/\&/g;
	$texttoconvert =~ s/\n(\n)+/\n\n/g;
	return $texttoconvert;
}

sub WordWrap {
	$quotedtext = $_[0];
	$length = length($quotedtext)-1;
	$wrapcount = 0;
	foreach $key (0..$length) {
		$char = substr($quotedtext,$key,1);
		$wrapcount++;
		if (($wrapcount > 65) && ($char eq " ")) {
			$char = "\n";
		}
		print MAIL "$char";
		if ($char =~ /\n/) {
			$wrapcount = 0;
		}
	}
}

sub Get_Date {
	@days =
	  (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
	@months =
	  (January,February,March,April,May,June,
	  July,August,September,October,November,December);
	$time = time;
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
	  localtime($time+($HourOffset*3600));
	$ampm = "a.m.";
	if ($hour eq 12) { $ampm = "p.m."; }
	if ($hour eq 0) { $hour = "12"; }
	if ($hour > 12) {
		$hour = ($hour - 12);
		$ampm = "p.m.";
	}
	if ($min < 10) { $min = "0$min"; }
	$todaydate = "$days[$wday], $mday $months[$mon] 19$year, ";
	$todaydate = $todaydate."at $hour\:$min $ampm";
}

sub Send_Cookie {
	if (!$name) { $name = $Cookies{'name'}; }
	if (!$email) { $email = $Cookies{'email'}; }
	if (!$listtype) { $listtype = $Cookies{'listtype'}; }
	if (!$listtime) { $listtime = $Cookies{'listtime'}; }
	if (!$Cookies{'thisvisit'}) {
		$Cookies{'thisvisit'} = $Cookies{'lastvisit'};
	}
	if (!$Cookies{'thismessage'}) {
		$Cookies{'thismessage'} = $Cookies{'lastmessage'};
	}
	if (($time - $Cookies{'timestamp'}) < 1800) {
		$lastvisit = $Cookies{'lastvisit'};
		$lastseen = $Cookies{'lastmessage'};
		$thisvisit = $Cookies{'thisvisit'};
		$thisseen = $Cookies{'thismessage'};
	}
	else {
		$lastvisit = $Cookies{'thisvisit'};
		$lastseen = $Cookies{'thismessage'};
		$Cookies{'lastvisit'} = $Cookies{'thisvisit'};
		$Cookies{'lastmessage'} = $Cookies{'thismessage'};
		$thisvisit = $todaydate;
		$thisseen = $lastmessage;
	}
	if (!$Cookies{'lastmessage'}) {
		$Cookies{'lastmessage'} = $lastmessage;
	}
	&SetCompressedCookies($boardname,'name',$name,'email',$email,
	  'listtype',$listtype,'listtime',$listtime,
	  'lastmessage',$lastseen,'lastvisit',$lastvisit,
	  'thismessage',$thisseen,'thisvisit',$thisvisit,
	  'timestamp',$time,'wantnotice',$Cookies{'wantnotice'});
}

sub Reconfigure {
	print "\n";
	print "<HTML><HEAD>";
	print "<TITLE>$boardname Configuration</TITLE></HEAD>\n";
	print "<BODY $bodyspec>\n";
	if ($MessageHeaderFile) {
		open (HEADER,"$MessageHeaderFile");
		@header = <HEADER>;
		close (HEADER);
		foreach $line (@header) { print "$line"; }
	}
	print "<P ALIGN=CENTER>[ <A HREF=\"$cgiurl\">Return ";
	print "to the Index</A> ]</P><HR>\n";
	print "<H2 ALIGN=CENTER>$boardname</H2>\n";
	print "<H1 ALIGN=CENTER>Message Index ";
	print "Display Configuration</H1>\n";
	$ListType = $Cookies{'listtype'};
	$ListTime = $Cookies{'listtime'};
	if (!$ListType) { $ListType = $DefaultType; }
	if (!$ListTime) { $ListTime = $DefaultTime; }
	if ($ListTime eq "Archive") { $ListTime = "Several Eons"; }
	print "<P>Use the form below to search for messages ",
	  "which include certain keywords or which were posted ",
	  "at a particular time or by a particular individual, ",
	  "and/or to select the manner in which you wish the ",
	  "messages in the index to be displayed.\n";
	if ($UseCookies) {
		print "<P>(If your browser supports and is set to accept ";
		print ""cookies," your preferences will be ";
		print "remembered the next time you visit!)</P>\n";
	}
	else {
		print "<P>(Note that since this board is not set to ";
		print "utilize "cookies," your preferences ";
		print "will not be remembered the next time you ";
		print "visit.)</P>\n";
	}
	print "<HR WIDTH=50%>\n";
	print "<FORM METHOD=POST ACTION=\"$cgiurl\">\n";
	print "<P>List messages <SELECT NAME=\"ListType\"><OPTION";
	if (($ListType eq "Chronologically") || !$ListType) {
		print " SELECTED";
	}
	print ">Chronologically<OPTION";
	if ($ListType eq "By Threads") { print " SELECTED"; }
	print ">By Threads<OPTION";
	if ($ListType eq "By Threads, Reversed") { print " SELECTED"; }
	print ">By Threads, Reversed</SELECT>\n",
	  "<P><EM>(A chronological display will put the newest ",
	  "messages at the top of the list. A standard threaded ",
	  "display will put the newest messages at the bottom. A ",
	  "reversed threaded display will show messages in a mixed ",
	  "order: 'First' messages will be arranged with the newest ",
	  "at the top, but responses will be arranged with the ",
	  "newest at the bottom. Though awkward, this is the ",
	  "default index style of many Web-based bulletin boards, ",
	  "and is the style with which many users are most ",
	  "familiar.)</EM>\n",
	  "<P>List only those messages:</P><P><DL>\n";
	unless ($ArchiveOnly) {
		print "<DD><INPUT TYPE=RADIO NAME=\"ListCriteria\" ";
		print "VALUE=\"Recent\" CHECKED> ";
		print "Posted within the last <SELECT ";
		print "NAME=\"ListTime\"><OPTION";
		if ($ListTime eq "Day") { print " SELECTED"; }
		print ">Day <OPTION";
		if ($ListTime eq "Two Days") { print " SELECTED"; }
		print ">Two Days<OPTION";
		if (($ListTime eq "Week") || !($ListTime)) {
			print " SELECTED";
		}
		print ">Week<OPTION";
		if ($ListTime eq "Two Weeks") { print " SELECTED"; }
		print ">Two Weeks<OPTION";
		if ($ListTime eq "Month") { print " SELECTED"; }
		print ">Month<OPTION";
		if ($ListTime eq "Several Eons") { print " SELECTED"; }
		print ">Several Eons</SELECT>\n";
	}
	print "<P><DD><INPUT TYPE=RADIO ";
	print "NAME=\"ListCriteria\" VALUE=\"Archive\"";
	if ($ArchiveOnly) { print " CHECKED"; }
	print "> Posted between <SELECT ",
	  "NAME=\"StartMonth\"><OPTION ",
	  "SELECTED>Jan<OPTION>Feb<OPTION>Mar<OPTION>Apr",
	  "<OPTION>May<OPTION>Jun<OPTION>Jul<OPTION>Aug",
	  "<OPTION>Sep<OPTION>Oct<OPTION>Nov<OPTION>Dec</SELECT> ",
	  "<SELECT NAME=\"StartYear\">",
	  "<OPTION>1996<OPTION SELECTED>1997<OPTION>1998",
	  "</SELECT> and <SELECT NAME=\"EndMonth\"><OPTION>Jan",
	  "<OPTION>Feb<OPTION>Mar<OPTION>Apr",
	  "<OPTION>May<OPTION>Jun<OPTION>Jul",
	  "<OPTION>Aug<OPTION>Sep<OPTION>Oct<OPTION>Nov",
	  "<OPTION SELECTED>Dec</SELECT> <SELECT ",
	  "NAME=\"EndYear\"><OPTION>1996<OPTION ",
	  "SELECTED>1997<OPTION>1998</SELECT></DL></P>\n",
	  "<P>List:</P>\n",
	  "<P><DL><DD><INPUT TYPE=RADIO NAME=\"KeySearch\" ",
	  "VALUE=\"No\" CHECKED> All messages within the specified ",
	  "date range<P><DD><INPUT TYPE=RADIO NAME=\"KeySearch\" ",
	  "VALUE=\"Yes\"> Only messages containing <SELECT ",
	  "NAME=\"Boolean\"><OPTION SELECTED>Any",
	  "<OPTION>All</SELECT> of the following keywords:",
	  "<DD><INPUT TYPE=TEXT NAME=\"Keywords\" ",
	  "SIZE=50><P><DD><INPUT TYPE=RADIO NAME=\"KeySearch\" ",
	  "VALUE=\"Author\"> Only messages posted by:",
	  "<DD><INPUT TYPE=TEXT ",
	  "NAME=\"Author\" SIZE=50></DL></P>\n",
	  "<P><CENTER><INPUT TYPE=SUBMIT VALUE=\"View Message ",
	  "Index\"></CENTER></P></FORM>\n",
	  "<HR><P ALIGN=CENTER><SMALL>The $boardname is maintained ",
	  "with <STRONG><A HREF=\"http://awsd.com/scripts/webbbs/\">",
	  "WebBBS $version</A></STRONG>.</SMALL></P>\n";
	if ($MessageFooterFile) {
		open (FOOTER,"$MessageFooterFile");
		@footer = <FOOTER>;
		close (FOOTER);
		foreach $line (@footer) { print "$line"; }
	}
	print "</BODY></HTML>\n";
}

sub UpdateAddressList {
	$FORM{'email'} =~ s/ |;|,|\*//g;
	unless ($FORM{'email'} =~ /.*\@.*\..*/) { &Error_Email; }
	unless (-w "$dir/$address_list") {
		&Error_File("$dir/$address_list");
	}
	open (LIST,"$dir/$address_list");
	@list = <LIST>;
	close (LIST);
	$listcheck = 0;
	open (LIST,">$dir/$address_list");
	foreach $address (@list) {
		if ($address =~ /$FORM{'email'}/i) {
			if ($FORM{'action'} eq "delete") {
				&Off_The_List;
				$listcheck = 1;
			}
			else {
				&Error_List_Yes;
				print LIST "$address";
				$listcheck = 1;
			}
		}
		else {
			print LIST "$address";
		}
	}
	if ($listcheck < 1) {
		if ($FORM{'action'} eq "delete") {
			&Error_List_No;
		}
		else {
			&On_The_List;
			print LIST "$FORM{'email'}\n";
		}
	}
	close (LIST);
}

sub On_The_List {
	print "\n";
	print "<HTML><HEAD><TITLE>You're On The List!</TITLE></HEAD>\n";
	print "<BODY $bodyspec>";
	print "<H1 ALIGN=CENTER>Thanks For Your Interest!</H1>\n";
	print "<P>Your e-mail address (<STRONG>$FORM{'email'}</STRONG>) ";
	print "has been added to the $boardname e-mail notification ";
	print "list. Whenever a new message is posted, you'll know ";
	print "about it! If you have any questions, please send a note ";
	print "to <A HREF=\"mailto:$maillist_address\">";
	print "$maillist_address</A>. ";
	print "Thanks!\n";
	&Footer;
}

sub Off_The_List {
	print "\n";
	print "<HTML><HEAD><TITLE>You're Off The List!</TITLE></HEAD>\n";
	print "<BODY $bodyspec>";
	print "<H1 ALIGN=CENTER>We're Sorry to See You Go!</H1>\n";
	print "<P>Your e-mail address (<STRONG>$FORM{'email'}</STRONG>) ";
	print "has been removed from the $boardname e-mail notification ";
	print "list. If you have any questions, please send a note to ";
	print "<A HREF=\"mailto:$maillist_address\">";
	print "$maillist_address</A>.\n";
	&Footer;
}

sub Error_List_Yes {
	&Error_Header;
	print "<H1 ALIGN=CENTER>Duplicate Submission!</H1>\n";
	print "<P>Thanks for your interest, but your e-mail address ";
	print "(<STRONG>$FORM{'email'}</STRONG>) is <EM>already</EM> ";
	print "on the $boardname e-mail notification list! You don't ";
	print "need <EM>two</EM> notices of each new post, do you?\n";
	&Footer;
}

sub Error_List_No {
	&Error_Header;
	print "<H1 ALIGN=CENTER>You're Not On The List!</H1>\n";
	print "<P>Your e-mail address (<STRONG>$FORM{'email'}</STRONG>) ";
	print "can't be removed from the $boardname e-mail notification ";
	print "list, since it is not currently <EM>on</EM> the list! ";
	print "If you have any questions, please send a note to ";
	print "<A HREF=\"mailto:$maillist_address\">";
	print "$maillist_address</A>.\n";
	&Footer;
}

sub Error_Email {
	&Error_Header;
	print "<H1 ALIGN=CENTER>Invalid Address!</H1>\n";
	print "<P>Thanks for your interest, ";
	print "but the e-mail address you entered seems ";
	print "to be invalid. Please use the "Back" button ";
	print "on your browser to return and re-enter it.\n";
	&Footer;
	exit;
}

sub Error_File {
	&Error_Header;
	print "<H1 ALIGN=CENTER>File Error!</H1>\n";
	print "<P>The server encountered an error while trying to ";
	print "access <STRONG>$_[0]</STRONG>! Either the directory or ";
	print "file doesn't exist, or its permissions are set ";
	print "incorrectly.\n";
	&Footer;
	exit;
}

sub Error_NoMessage {
	&Error_Header;
	print "<H1 ALIGN=CENTER>No Message!</H1>\n";
	print "<P>Sorry, but the message you just tried to load ";
	print "doesn't exist! You may have followed an obsolete ";
	print "hard-coded link, or it may be that you just tried ";
	print "to enter the address manually, and mis-typed it. ";
	print "Please return to the <A HREF=\"$cgiurl\">";
	print "message index</A> and try again!\n";
	&Footer;
	exit;
}

sub Error_Incomplete {
	&Error_Header;
	print "<H1 ALIGN=CENTER>Incomplete Submission!</H1>\n";
	print "<P>Your message is incomplete! Your enthusiasm is ";
	print "appreciated, but you need to make sure that you include ";
	print "<EM>your name</EM>, <EM>a subject line</EM> and (of ";
	print "course) <EM>a message</EM>! Please return to the <A ";
	print "HREF=\"$ENV{'HTTP_REFERER'}\">entry ";
	print "form</A> and try again! Thanks!\n";
	print "<P>(If you use the "Back" button on your ";
	print "browser, any information you've already input should be ";
	print "retained.)\n";
	&Footer;
	exit;
}

sub Error_Duplicate {
	&Error_Header;
	print "<H1 ALIGN=CENTER>Duplicate Submission!</H1>\n";
	print "<P>This error usually means that you have pressed the ";
	print ""Post Message" button more than once ";
	print "for the same message. Please return to the ";
	print "<A HREF=\"$cgiurl\">message index</A> ";
	print "(and reload it if necessary) to confirm that ";
	print "your message was, in fact, posted!\n";
	&Footer;
	exit;
}

sub Error_Header {
	print "\n";
	print "<HTML><HEAD><TITLE>Oops!</TITLE></HEAD>\n";
	print "<BODY $bodyspec>\n";
}

sub Footer {
	print "</P><HR WIDTH=50%>\n";
	print "<P ALIGN=CENTER>[ <STRONG><A HREF=\"$cgiurl\">";
	print "Return to the Message Index</A></STRONG> ]</P>\n";
	print "</BODY></HTML>\n";
}

sub LockFile {
	local(*FILE) = @_;
	local($TrysLeft) = 10;
	if ($UseLocking) {
		while ($TrysLeft--) {
			$lockresult = eval("flock(FILE,6)");
			if ($@) {
				$UseLocking = 0;
				last;
			}
			if (!$lockresult) {
				select(undef,undef,undef,0.1);
			}
			else {
				last;
			}
		}
	}
	if ($TrysLeft >= 0) {
		return 0;
	}
	else {
		return -1;
	}
}

sub UnlockFile {
	local(*FILE) = @_;
	if ($UseLocking) {
		flock(FILE,8);
	}
}

1;