#!/usr/bin/perl $| = 0; # declare the variables $boarddir = '/home/httpd/vhosts/fengshui.com.sg/httpdocs/forum'; $boardurl = 'http://www.fengshui.com.sg/forum'; $cgi = 'http://www.fengshui.com.sg/Xcgi-bin/forum.pl'; $indexcgi = 'http://www.fengshui.com.sg/Xcgi-bin/index.pl'; $queryswitch = '?'; $style = 1; $threaded = 1; $maximum = 0; $maxdisplay = 50; $fontface = 'arial'; $fontsize = 2; $tablecolor1 = 'orange'; $tablecolor2 = 'orange'; $tablecolor3 = 'orange'; $fontcolor1 = 'black'; $fontcolor2 = 'black'; $fontcolor3 = 'black'; ######################################################################### # Don't change anything below here unless you know what you're doing :) # ######################################################################### $datadir = "$boarddir/data"; $datafile = "$boarddir/data.txt"; $index_t = "$boarddir/index_t.html"; $page_t = "$boarddir/page_t.html"; $use_cgi = 1; $LOCK_EX = 2; $LOCK_UN = 8; &readform; print "Content-type: text/html\n\n"; open (FILE, "$datafile") || &fatal_error("Unable to open $datafile"); &lock(FILE); @messages = ; &unlock(FILE); close(FILE); $messagecount = 0; $threadcount = 0; for ($a = 0; $a < @messages; $a++) { ($mnum[$a],$msub[$a],$mfollow[$a],$mname[$a],$memail[$a],$mdate[$a],$mip[$a],$mbrowser[$a],$chop) = split(/``/,$messages[$a]); $messagecount++; if ($mfollow[$a] == 1) { $threadcount++; } } open (FILE, "$index_t") || &fatal_error("Unable to open $index_t"); &lock(FILE); @template = ; &unlock(FILE); close(FILE); for ($a = 0; $a < @template; $a++) { $_ = $template[$a]; if (//) { if ($style == 1) { $displaycounter = 0; $itzapizza = 0; $remember = $mnum[0]; print "\n"; for ($b = 0; $b < @messages; $b++) { if ($mfollow[$b] > 1) { $itzapizza++; } else { unless ($b == 0 || $threaded == 0) { print "\n"; if ($itzapizza == 0) { print "\n"; $remember = $mnum[$b]; } $displaycounter++; open (FILE, "$datadir/$mnum[$b]\.txt") || &fatal_error("Unable to open $mnum[$b]\.txt"); &lock(FILE); @body = ; &unlock(FILE); close(FILE); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } if ($displaycounter >= $maxdisplay && $maximum == 1 && $action ne 'showall') { $b = @messages; } } unless (@messages == 0 || $threaded == 0) { print "\n"; if ($itzapizza == 0) { print "\n"; } print "
Thread Info:No more messages in this thread.\n"; } else { print "$itzapizza more message(s) in this thread.\n"; $itzapizza = 0; } print "Post / View this thread.
$mdate[$b]
Posted By:$mname[$b]
Subject:$msub[$b]
Message:@body
No more messages in this thread.\n"; } else { print "$itzapizza more message(s) in this thread.\n"; } print "Post / View this thread.
\n"; } else { $last = 1; print "\n"; } } } elsif (//) { print "
\n"; print "\n"; print "\n"; print "\n\n"; print "\n"; print "\n\n"; print "\n"; print "\n\n"; print "\n"; print "\n\n"; print "\n"; print "
Name:
E-Mail:
Subject:
Message:
"; print " "; print "
\n\n"; } elsif (//) { print "$messagecount\n"; } elsif (//) { print "$threadcount\n"; } elsif (//) { if ($maximum == 1 && $action ne 'showall' && @messages > $maxdisplay) { print "$maxdisplay\n"; } else { print "all\n"; } } elsif (//) { if ($maximum == 1 && $action ne 'showall' && @messages > $maxdisplay) { print "Show All Messages\n"; } } else { print "$_"; } } sub fatal_error { local($e) = @_; print "\n"; print "Forum Fatal Error \n"; print "\n"; print "
\n"; print "

Forum Fatal Error

\n"; print "
\n"; print "Forum experienced an unrecoverable error. The error seems\n"; print "to be:

\n"; print "$e

\n\n"; print "If this error continues, you should contact the administrator.

\n"; print "Forum Main\n"; print "

\n"; print "
"; print "
\n"; exit; } sub readform { read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; $FORM{$name} = $value; } $what = $FORM{'what'}; @vars = split(/&/, $ENV{QUERY_STRING}); foreach $var (@vars) { ($v,$i) = split(/=/, $var); $v =~ tr/+/ /; $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ tr/+/ /; $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ s///g; $INFO{$v} = $i; } $action = $INFO{'action'}; $startat = $INFO{'startat'}; } sub lock { local($file)=@_; flock($file, $LOCK_EX); } sub unlock { local($file)=@_; flock($file, $LOCK_UN); }