# HG changeset patch # User Steve Kemp # Date 1197547903 0 # Node ID a25099606ec525ae0cda1a95d594e297a7e4b9e6 # Parent 46db55d5fa50482ca13488816015848f7e33c371 Updated. diff -r 46db55d5fa50 -r a25099606ec5 cgi-bin/comments.cgi --- a/cgi-bin/comments.cgi Thu Dec 13 10:00:12 2007 +0000 +++ b/cgi-bin/comments.cgi Thu Dec 13 12:11:43 2007 +0000 @@ -1,11 +1,25 @@ #!/usr/bin/perl -w # -# This is a simple script which is designed to accept POST request, -# of comments to a series of text files. +# This is a simple script which is designed to accept comment requests, +# and save the details to local text files upon the localhost. # # This code is very simple and should be easy to extend with anti-spam # at a later point. # +# +### +# +# NOTE: If you wish to use this you must edit three things at the +# top of the script. +# +# 1. The directory to save the comment data to. +# +# 2. The email address to notify. +# +# 3. The email address to use as the sender. +# +#### +# # Steve # -- # @@ -23,8 +37,22 @@ # # The directory to store comments in # +# my $COMMENT = "/home/www/comments/"; +# my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/"; +# +# The notification addresses - leave blank to disable +# +# my $TO = 'weblog@steve.org.uk'; +# my $FROM = 'weblog@steve.org.uk'; +# +my $TO = ''; +my $FROM = ''; + + + + # # Get the parameters from the request. @@ -34,6 +62,7 @@ my $mail = $cgi->param('mail') || undef; my $body = $cgi->param('body') || undef; my $id = $cgi->param('id') || undef; +my $cap = $cgi->param('captcha') || undef; # @@ -48,6 +77,15 @@ exit; } +# +# Does the captcha value contain text? If so spam. +# +if ( defined( $cap ) && length( $cap ) ) +{ + print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; + exit; +} + # # Otherwise save them away. @@ -61,10 +99,17 @@ # +# Show the header +# +print "Content-type: text/html\n\n"; + + +# # get the current time # my $timestr = strftime "%e-%B-%Y-%H:%M:%S", gmtime; + # # Open the file. # @@ -78,10 +123,26 @@ print FILE $body; close( FILE ); + +# +# Send a mail. +# +if ( length($TO) && length($FROM) ) +{ + open ( SENDMAIL, "|/usr/lib/sendmail -t"); + print SENDMAIL "To: $TO\n"; + print SENDMAIL "From: $FROM\n"; + print SENDMAIL "Subject: New Comment [$id]\n"; + print SENDMAIL "\n\n"; + print ( SENDMAIL `cat $file` ); + close ( SENDMAIL ); +} + + # # Now show the user the thanks message.. # -print "Content-type: text/html\n\n"; + print <