#!/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 = <OLDCHAT>; ##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=<BAD>; foreach $bad(@bad) { chop ($bad); if ($FORM{'comments'} =~ /$bad/ig) { $FORM{'comments'} =~ s/$b +ad/\%\$\#\&\!\%/gi; next;} } print ADDCHAT ("<H4>$FORM{'name'} from $FORM{'location'} said:</h4> $F +ORM{'comments'} <BR> <H6>$date</H6><P> <!--$ENV{REMOTE_HOST}--><HR>\n +"); #print new comment on top for (@old) { s/\s+/ /g; s/\n+//g; s/<HR>/<HR>\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 = <TOP>; open (CHAT, "$textdir/$FORM{'1'}"); @new = <CHAT>;#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; }
In reply to Is this code in Perl or CGI? by perl2010
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |