comparison cgi-bin/comments.cgi @ 108:a25099606ec5

Updated.
author Steve Kemp <steve@steve.org.uk>
date Thu, 13 Dec 2007 12:11:43 +0000
parents cd27fd555272
children 412506c2de6b
comparison
equal deleted inserted replaced
107:46db55d5fa50 108:a25099606ec5
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 # 2 #
3 # This is a simple script which is designed to accept POST request, 3 # This is a simple script which is designed to accept comment requests,
4 # of comments to a series of text files. 4 # and save the details to local text files upon the localhost.
5 # 5 #
6 # This code is very simple and should be easy to extend with anti-spam 6 # This code is very simple and should be easy to extend with anti-spam
7 # at a later point. 7 # at a later point.
8 #
9 #
10 ###
11 #
12 # NOTE: If you wish to use this you must edit three things at the
13 # top of the script.
14 #
15 # 1. The directory to save the comment data to.
16 #
17 # 2. The email address to notify.
18 #
19 # 3. The email address to use as the sender.
20 #
21 ####
8 # 22 #
9 # Steve 23 # Steve
10 # -- 24 # --
11 # 25 #
12 26
21 35
22 36
23 # 37 #
24 # The directory to store comments in 38 # The directory to store comments in
25 # 39 #
40 # my $COMMENT = "/home/www/comments/";
41 #
26 my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/"; 42 my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/";
43
44 #
45 # The notification addresses - leave blank to disable
46 #
47 # my $TO = 'weblog@steve.org.uk';
48 # my $FROM = 'weblog@steve.org.uk';
49 #
50 my $TO = '';
51 my $FROM = '';
52
53
54
27 55
28 56
29 # 57 #
30 # Get the parameters from the request. 58 # Get the parameters from the request.
31 # 59 #
32 my $cgi = new CGI(); 60 my $cgi = new CGI();
33 my $name = $cgi->param('name') || undef; 61 my $name = $cgi->param('name') || undef;
34 my $mail = $cgi->param('mail') || undef; 62 my $mail = $cgi->param('mail') || undef;
35 my $body = $cgi->param('body') || undef; 63 my $body = $cgi->param('body') || undef;
36 my $id = $cgi->param('id') || undef; 64 my $id = $cgi->param('id') || undef;
65 my $cap = $cgi->param('captcha') || undef;
37 66
38 67
39 # 68 #
40 # If any are missing just redirect back to the blog homepage. 69 # If any are missing just redirect back to the blog homepage.
41 # 70 #
42 if ( !defined( $name ) || !length( $name ) || 71 if ( !defined( $name ) || !length( $name ) ||
43 !defined( $mail ) || !length( $mail ) || 72 !defined( $mail ) || !length( $mail ) ||
44 !defined( $body ) || !length( $body ) || 73 !defined( $body ) || !length( $body ) ||
45 !defined( $id ) || !length( $id ) ) 74 !defined( $id ) || !length( $id ) )
75 {
76 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
77 exit;
78 }
79
80 #
81 # Does the captcha value contain text? If so spam.
82 #
83 if ( defined( $cap ) && length( $cap ) )
46 { 84 {
47 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; 85 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
48 exit; 86 exit;
49 } 87 }
50 88
59 $id=$2; 97 $id=$2;
60 } 98 }
61 99
62 100
63 # 101 #
102 # Show the header
103 #
104 print "Content-type: text/html\n\n";
105
106
107 #
64 # get the current time 108 # get the current time
65 # 109 #
66 my $timestr = strftime "%e-%B-%Y-%H:%M:%S", gmtime; 110 my $timestr = strftime "%e-%B-%Y-%H:%M:%S", gmtime;
111
67 112
68 # 113 #
69 # Open the file. 114 # Open the file.
70 # 115 #
71 my $file = $COMMENT . "/" . $id . "." . $timestr; 116 my $file = $COMMENT . "/" . $id . "." . $timestr;
76 print FILE "IP-Address: $ENV{'REMOTE_ADDR'}\n"; 121 print FILE "IP-Address: $ENV{'REMOTE_ADDR'}\n";
77 print FILE "\n"; 122 print FILE "\n";
78 print FILE $body; 123 print FILE $body;
79 close( FILE ); 124 close( FILE );
80 125
126
127 #
128 # Send a mail.
129 #
130 if ( length($TO) && length($FROM) )
131 {
132 open ( SENDMAIL, "|/usr/lib/sendmail -t");
133 print SENDMAIL "To: $TO\n";
134 print SENDMAIL "From: $FROM\n";
135 print SENDMAIL "Subject: New Comment [$id]\n";
136 print SENDMAIL "\n\n";
137 print ( SENDMAIL `cat $file` );
138 close ( SENDMAIL );
139 }
140
141
81 # 142 #
82 # Now show the user the thanks message.. 143 # Now show the user the thanks message..
83 # 144 #
84 print "Content-type: text/html\n\n"; 145
85 print <<EOF; 146 print <<EOF;
86 <html> 147 <html>
87 <head> 148 <head>
88 <title>Thanks For Your Comment</title> 149 <title>Thanks For Your Comment</title>
89 </head> 150 </head>