App-Chronicle

 view release on metacpan or  search on metacpan

cgi-bin/comments.cgi  view on Meta::CPAN

#!/usr/bin/perl -w
#
#  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
# --
#



use strict;
use warnings;

use CGI;
use Encode 'decode_utf8';
use POSIX qw(strftime);


#
#  The directory to store comments in
#
#  In this case ~/comments/
#
my $COMMENT = $ENV{ 'DOCUMENT_ROOT' } . "../comments/";

#my $COMMENT = (getpwuid $>)[7]  . "/comments";


#
#  The notification addresses - leave blank to disable
#
my $TO   = 'weblog@steve.org.uk';
my $FROM = 'weblog@steve.org.uk';


#
# Get the parameters from the request - decoding them because UTF-8
# is the way of the future.  Yeah, I laughed too.
#
my $cgi = new CGI();

my $name = $cgi->param('name') || undef;
$name = decode_utf8($name) if ($name);

my $mail = $cgi->param('mail') || undef;
$mail = decode_utf8($mail) if ($mail);

my $body = $cgi->param('body') || undef;
$body = decode_utf8($body) if ($body);

my $id = $cgi->param('id') || undef;
$id = decode_utf8($id) if ($id);

my $link = $cgi->param('link') || undef;
$link = decode_utf8($link) if ($link);

my $cap  = $cgi->param('robot') || undef;
my $ajax = $cgi->param('ajax')  || 0;


#
# Strip newlins
#
$link =~ s/[\r\n]//g if ($link);
$id   =~ s/[\r\n]//g if ($id);
$name =~ s/[\r\n]//g if ($name);
$mail =~ s/[\r\n]//g if ($mail);


#
#  If any are missing just redirect back to the blog homepage.
#
if ( !defined($name) ||
     !length($name) ||
     !defined($mail) ||
     !length($mail) ||
     !defined($body) ||
     !length($body) ||
     !defined($id) ||
     !length($id) )
{
    if ($ajax)
    {
        print "Content-type: text/html\n\n";
        print "Missing fields.\n";
    }



( run in 0.558 second using v1.01-cache-2.11-cpan-6aa56a78535 )