#!/usr/bin/perl
###################################################################
# SCRIPT PARAMETERS (CHANGE HERE).
###################################################################
### URL path where this script resides (+gifies for smilies).
### (can also be a relative url)
$SCRIPTDIR="/board";
### Where are the datafiles stored in ?
$DATADIR="./data";
### URL path where gif's are stored.
$GIFDIR="/board";
### background color of table headers
$BGCOLORTBLHEAD="33CCFF";
### title of all boards page
$ALLBOARDS="Michael's Message Board";
### style of fonts (is put into body tag of all generated files.
$FONTSTYLE= "style='font-family:verdana,helvetica,ariel;font-size:11pt'";
### How many subjects are listed in one page
$SUBJECTSPAGESIZE=20;
### encoding meta tag
$ENCODING="";
###################################################################
### HTTP Header string for HTML result
$HTTPHEADER = "Content-type: text/html\n\n";
$STARTTIME=time;
### read POST parameters into global $CgiParam{$name}
&parse_form;
$BOARDID = $CgiParam{"id"};
$THREADID = $CgiParam{"tid"};
$STYLE = $CgiParam{"style"};
$DO = $CgiParam{"do"};
$BOARDTITLE = "KuKu";###$CgiParam{"title"};
### show one message board
if ($DO eq "brd"){
($STYLE == 1) ? &Subjects : &TheBoard;
}
### listing of discussions for one message board.
elsif ($DO eq "subj"){
&Subjects;
}
### Show one thread
elsif ($DO eq "thrd"){
&Thread;
}
### returns static html (if in Frames mode)
### trade off speed for ease of setup
elsif ($DO eq "nothread"){
&NoThread;
}
### returns HTML with a entry form for new message
elsif ($DO eq "addmsgform"){
&AddMsgForm;
&TimeComment;
}
### add a reply for one message board
elsif ($DO eq "addmsg"){
&AddMsg($DATADIR,$BOARDID,$THREADID,$CgiParam{'message'},$CgiParam{'subj'},$CgiParam{'mail'},$CgiParam{'auth'},$CgiParam{'smile'},$CgiParam{'msg'});
}
### Display form for 'search messages'
elsif ($DO eq "searchform"){
&ShowSearchForm;
&TimeComment;
}
### perform search of messages
elsif ($DO eq "dosearch"){
&DoSearch;
}
### no parameters - show listof message boards.
else
{
&BoardList;
}
### read POST parameters into global $CgiParam{$name}
sub parse_form
{
local($name,$value,$meth,$in,$len,$got,@pairs,$pair);
$meth = $ENV{'REQUEST_METHOD'};
# Get the request data
if (!defined $meth || $meth eq '' || $meth eq 'GET' || $meth eq 'HEAD') {
$in = $ENV{'QUERY_STRING'};
}
elsif ($meth eq 'POST') {
$len = $ENV{'CONTENT_LENGTH'};
$got = read(STDIN, $in, $len);
($got==$len) || die "$HTTPHEADER Can't read POST data $got $len\n";
}
else {
die "$HTTPHEADER Unknown request method: $meth\n";
}
# Split the name-value pairs
@pairs = split(/&/, $in);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Remove any NULL characters, Server Side Includes
$value =~ s/\0//g;
$value =~ s///g;
$CgiParam{$name} = $value;
}
}
### Show subject list of a board.
sub Subjects
{
local($pos,$cnt,$line,@lines,$offset,$prevlink);
$filename="$DATADIR/board_$BOARDID.data";
if (open(BOARD,"$filename")) {
flock(BOARD,1); ## shared read lock
$offset=$CgiParam{"offs"};
$cnt=$SUBJECTSPAGESIZE;
if ($offset>0){
$pos=$offset-$SUBJECTSPAGESIZE;
$pos<0 ? $pos=0 : 1;
$prevlink=" << ";
}
$BOARDTITLE=;
chop($BOARDTITLE);
$pos=0;
while() {
if ($pos>=$offset) {
if ($cnt>0) {
push @lines, $_;
$cnt--;
}
else {
$pos = $offset+$SUBJECTSPAGESIZE;
$nextlink=" >> ";
break;
}
}
$pos++;
}
close(BOARD);
}
$dirs = "$prevlink$nextlink";
if ($dirs ne "") {
$dirs = "[$dirs] ";
}
###page + table header
print <$ENCODING$BOARDTITLE
";
&TimeComment;
}
### Show contents of one discussion thread
sub Thread
{
print "$HTTPHEADER";
$threadfile = "$DATADIR/thread_$CgiParam{'id'}_$THREADID.htm";
open(THREAD,$threadfile) || die "
No messages for this thread
";
flock(THREAD,1); ## shared read lock
while() {
print $_;
}
close(THREAD);
&TimeComment;
}
### Show one message board (with frames)
sub TheBoard
{
print <$ALLBOARDS