The script was written for perl 4.036, so if you have perl 5.0 you may need to make some changes. it was tested on linux running httpd 1.4. Things like the "date" command may need changed, along with a few other minor things. It's very difficult to write a completely portable perl script for things like this. If you aren't sure of what you're doing when it comes to perl or CGI scripts, you may have some problems. I've received mail from some people saying it doesnt work on their system, or they can't figure out how to use it, etc. All I can say is that I don't guarantee that it will work for you, since you don't have to pay for it unless you actually put it to use. My motto is: "If it's cool, it's probably not easy" :) #!/usr/bin/perl # # COMMENTS.CGI # by Matt Kruse (mkruse@saunix.sau.edu) # # It was written for and tested under perl 4.036 and NCSA httpd 1.4. # It may need some hacking to convert to perl 5.0 or another server type. # # Using this script is easy! Here's what you'll want to do: # 1. put the script in the directory where your comments will be # 2. name it comments.cgi # 3. make it executable (chmod 755 comments.cgi) # 4. make sure the directory is writable (chmod 777 .) # 5. Load up the comments.cgi in your browser! # # You can then create the main questions.html page from there, and it will # immediately be ready to use. you can go back and edit the questions.html # file to make it fancy if you want. # WARNING: the comments are stored on single lines to make it easier # search, delete, etc. Loading up the questions.html file in an editor like # pico will wrap the lines and possibly cause errors. Use vi or emacs. # But you shouldn't need to edit the html file anyway (that's the point!) # # NOTE: the default password to begin with is "password". Change this # immediately to a more secure password. # # HAVE FUN! :) # Some subroutines from CGI-LIB.PL were used, so here is what I am supposed # to include in my script: # (from cgi-lib.pl) # Copyright 1994 Steven E. Brenner # Unpublished work. # Permission granted to use and modify this library so long as the # copyright above is maintained, modifications are documented, and # credit is given for any use of the library. # Thanks are due to many people for reporting bugs and suggestions # especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen, # Andrew Dalke, Mark-Jason Dominus and Dave Dittrich. sub MethGet { return ($ENV{'REQUEST_METHOD'} eq "GET"); } sub ReadParse { local (*in) = @_ if @_; local ($i, $loc, $key, $val); if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; } return 1; # just for fun } sub PrintHeader { return "Content-type: text/html\n\n"; } # Owner-changeable options # ------------------------ $OWNERPASSWORD="chem106"; $PAGENAME="questions.html"; @badwords=("fuck","shit","damn","pussy","dick","cock","bitch","asshole"); &ReadParse(*input); print &PrintHeader; $DATE=`date`; $DATE=substr($DATE,0,16); # Subroutine to read comments page into @LINES # -------------------------------------------- sub ReadPage { open (INDEX,"$PAGENAME"); @LINES=; close(INDEX); } # Subroutine to print out all of comments page # -------------------------------------------- sub PrintPage { open (INDEX,"$PAGENAME"); while () {print; } close (INDEX); } # Subroutine for Bad Password Input # --------------------------------- sub BadPassword { print <Bad Password The password you have entered is incorrect. Your username, IP address, and the current time have been logged for possible review later. If this was an accident, please try again. If you are trying to break a password, please don't.


EOF exit(0); } # Subroutine to check for empty responses # --------------------------------------- sub BadResponse { print <Response Error You have left some of the entries blank which must be filled in.

Please go back and fill in all the fields correctly.


EOF exit(0); } # Subroutine to check for inappropriate responses # ----------------------------------------------- sub CheckText { $TEXTTOCHECK=$_[0]; # Check for offensive words foreach $badword (@badwords) { if ($TEXTTOCHECK=~ /$badword/i) { print <Grow Up! Your text contains a word that others may find offensive. Please re-enter your text and make it suitable for everyone.
Return to Comments Section
The unacceptable words are in bold below:

EOF foreach $badword (@badwords) { $TEXTTOCHECK =~ s/($badword)/$1<\/B>/g; } print "$TEXTTOCHECK

\n


\n"; exit(0); } } #end of foreach # Check for html markup if ( ($TEXTTOCHECK=~ //) ) { print <HTML Markup not allowed You have entered text that appeared to have HTML markup tags in it. This page is specially formatted to appear correctly, so please do not try to put markup or links in your text. In fact, any text including the characters '<' or '>' is not allowed, so please use something else. Thanks.


EOF exit(0); } } # end of sub # Start with the main program # --------------------------- $COMMAND=$input{'COMMAND'}; $PASSWORD=$input{'PASSWORD'}; $NAME=$input{'NAME'}; $COMMENTS=$input{'COMMENTS'}; $SEARCHTEXT=$input{'SEARCHTEXT'}; $EMAIL=$input{'EMAIL'}; # Utilities for Page Owner # ------------------------ if ($COMMAND eq '') { print <Page Setup and Owner's Utilities
Welcome to the utilities section of the comments page. This allows the owner of the page to start the comments page for the first time, change the parameters of the page, delete entries that are old, or delete entries that contain certain words or characters.

Select an action:

Create Index Page
Choose this option when running this script for the first time. It creates a basic comments page that is all set up and ready to run for you. You can then go back and manually change the words or layout if you want to.
Change your Password
This option allows you to change your password. To update the page from now on, you will need to enter your password, and you should choose one of your own immediatly after setting up the page.
Update the comments page
This is the option you'll be using on a regular basis. It lets you delete comments on your page that are older thn a certain date, or comments that contain a certain string. This means there is no need to edit the actual file itself - everything can be done from here.
Change the list of unusable words
There are certain words that most people find offensive, and they are not allowed to be put onto the comments page. You can edit this list of words if you want to add more, or if you don't want to have any at all.

EOF exit(0); } # Create Main Index Page (OWNER ONLY) # ----------------------------------- if ($COMMAND eq 'CREATEINDEX') { print <Create Index Page This form allows you to automatically create a correctly-formatted index page to begin with.
Several things you should keep in mind:
  1. The comments page MUST be in the same directory as this script. This script cannot be used in the /cgi-bin directory. Not all WWW sites alow users to have scripts in their own directories, but most do.
  2. The directory that this script and the comments page is in must be world-writable. This is so both this script and the page itself can be written to by you and other people leaving comments.
  3. Filling in the information below and creating the page will actually change this script itself to your specifications.
  4. If you want to start over, you can run this section again and create a new index file.
  5. This will NOT check to see if the filename you give it already exists. If you tell it to make "questions.html" and that page already exists, it will be overwritten.
Current Passwrd:
Name of comments page:
Page Title:
EOF exit(0); } # Actually Create Index (OWNER ONLY) # ---------------------------------- if ($COMMAND eq 'DOCREATEINDEX') { if ($PASSWORD ne $OWNERPASSWORD) {&BadPassword;} #update script with new info open (SCRIPT,"comments.cgi"); $PAGENAME=$input{'PAGENAME'}; @LINES=