#!/usr/bin/perl require 'utility2.pl'; &form_handler; $textdir = "../../data/text"; $docfile = "../../htdocs/cowboys/$FORM{'3'}"; for ($count = 1; $count < 5; $count++) { if ($FORM{'$count'} =~ /\//g || $FORM{'$count'} =~ /\.\./) { error(); exit; } } use POSIX; $date = strftime("%H:%M %m/%d/%Y",localtime); open (OLDCHAT, "$textdir/$FORM{'1'}") || die "text file doesn't exist"; @old = ; ##get copy of old comments open (ADDCHAT, ">$textdir/$FORM{'1'}"); #empty old comments $FORM{'name'} =~ s/\<+.+\>*//g; $FORM{'location'} =~ s/\<+.+\>*//g; $FORM{'comments'} =~ s/\<+.+\>*//g; $FORM{'comments'} =~ s/\n+//g; open (BAD, "$textdir/bad.txt") || die "can't open bad"; @bad=; foreach $bad(@bad) { chop ($bad); if ($FORM{'comments'} =~ /$bad/ig) { $FORM{'comments'} =~ s/$bad/\%\$\#\&\!\%/gi; next;} } print ADDCHAT ("

$FORM{'name'} from $FORM{'location'} said:

$FORM{'comments'}
$date


\n"); #print new comment on top for (@old) { s/\s+/ /g; s/\n+//g; s/
/
\n/g; } if (scalar @old>200) { pop(@old) until scalar @old < 200; } print ADDCHAT @old; #add old comments close ADDCHAT; open (TOP, "$textdir/$FORM{'2'}"); @top = ; open (CHAT, "$textdir/$FORM{'1'}"); @new = ;#get copy of updated comments open (NEWCHAT, ">$docfile") or &debug($FORM{'3'}); select(NEWCHAT); &html_header("$FORM{'4'}"); print "@top"; print "@new"; &html_footer; close NEWCHAT; select(STDOUT); print "Location: http://www.example.com/cowboys/$FORM{'3'}\n\n"; exit(0); sub error { print "Content-type: text/html\n\n"; &html_header("Error"); print<<"GOOF"; A system error occrred. Perhaps you tried to use an illegal character. GOOF &html_footer; 0; } sub debug { my $debugpage = shift(@_); print "Content-type: text/html\n\n"; &html_header("Error"); print<<"GOOF"; Could not open $debugpage for writing! GOOF &html_footer; 0; }