Mercurial > hg > chronicle
comparison cgi-bin/comments.cgi @ 98:3d8b0e615bf3
Added.
author | Steve Kemp <steve@steve.org.uk> |
---|---|
date | Wed, 12 Dec 2007 17:28:29 +0000 |
parents | |
children | cd27fd555272 |
comparison
equal
deleted
inserted
replaced
97:69570137cb66 | 98:3d8b0e615bf3 |
---|---|
1 #!/usr/bin/perl -w | |
2 # | |
3 # This is a simple script which is designed to accept POST request, | |
4 # of comments to a series of text files. | |
5 # | |
6 # This code is very simple and should be easy to extend with anti-spam | |
7 # at a later point. | |
8 # | |
9 # Steve | |
10 # -- | |
11 # | |
12 | |
13 | |
14 | |
15 use strict; | |
16 use warnings; | |
17 use CGI; | |
18 | |
19 # | |
20 # The directory to store comments in | |
21 # | |
22 my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/"; | |
23 | |
24 | |
25 # | |
26 # Get the parameters from the request. | |
27 # | |
28 my $cgi = new CGI(); | |
29 my $name = $cgi->param('name') || undef; | |
30 my $mail = $cgi->param('mail') || undef; | |
31 my $body = $cgi->param('body') || undef; | |
32 my $id = $cgi->param('id') || undef; | |
33 | |
34 | |
35 # | |
36 # If any are missing just redirect back to the blog homepage. | |
37 # | |
38 if ( !defined( $name ) || !length( $name ) || | |
39 !defined( $mail ) || !length( $mail ) || | |
40 !defined( $body ) || !length( $body ) || | |
41 !defined( $id ) || !length( $id ) ) | |
42 { | |
43 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; | |
44 exit; | |
45 } | |
46 | |
47 | |
48 # | |
49 # Otherwise save them away. | |
50 # | |
51 # | |
52 # ID. | |
53 # | |
54 if ( $id =~ /^(.*)[\/\\](.*)$/ ){ | |
55 $id=$2; | |
56 } | |
57 | |
58 | |
59 # | |
60 # get the current time | |
61 # | |
62 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
63 localtime(time); | |
64 | |
65 # | |
66 # Open the file. | |
67 # | |
68 my $file = $COMMENT . "/" . $id . "." . "$mday-$mon-$year-$hour-$min-$sec"; | |
69 open( FILE, ">", $file ); | |
70 print FILE "Name: $name\n"; | |
71 print FILE "Mail: $mail\n"; | |
72 print FILE "User-Agent: $ENV{'HTTP_USER_AGENT'}\n"; | |
73 print FILE "IP-Address: $ENV{'REMOTE_ADDR'}\n"; | |
74 print FILE "\n"; | |
75 print FILE $body; | |
76 close( FILE ); | |
77 | |
78 # | |
79 # Now show the user the thanks message.. | |
80 # | |
81 print "Content-type: text/html\n\n"; | |
82 print <<EOF; | |
83 <html> | |
84 <head> | |
85 <title>Thanks For Your Comment</title> | |
86 </head> | |
87 <body> | |
88 <h2>Thanks!</h2> | |
89 <p>Your comment will be included the next time this blog is rebuilt.</p> | |
90 <p><a href="http://$ENV{'HTTP_HOST'}/">Return to blog</a>.</p> | |
91 </body> | |
92 </html> | |
93 EOF | |
94 |