summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-10-29 22:09:09 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-10-29 22:09:09 +0000
commit74c0c79fe78e60f1189779dc86bbc0762bd032f4 (patch)
treebca8828c13efb6ce00d649f359811afcdf93b31a
parentc5a2c569d5fbbc13436fbad663500a38ba76704b (diff)
simplify captcha code
-rwxr-xr-xindex.cgi28
1 files changed, 13 insertions, 15 deletions
diff --git a/index.cgi b/index.cgi
index 442b3ae..4238431 100755
--- a/index.cgi
+++ b/index.cgi
@@ -83,6 +83,7 @@ sub output_article {
read_comment() if $comments_allowed;
my $articles = get_articles();
my $archives = get_archives();
+
my $tagcloud = get_tag_cloud();
my @status = ();
$template->param( archives => $archives );
@@ -256,8 +257,8 @@ sub get_archives {
my %history;
my @archives;
my @archives_compressed;
- my $current_month = $cgi->param('month') || ((localtime)[4] + 1);
my $current_year = $cgi->param('year') || ((localtime)[5] + 1900);
+ my $current_month = $cgi->param('month') || ((localtime)[4] + 1);
my %months = (
'01' => 'January',
'02' => 'February',
@@ -342,10 +343,14 @@ sub read_comment {
if ($cgi->param('recaptcha_challenge_field') && $cgi->param('recaptcha_response_field') && $cgi->param('comment') && $cgi->param('id')) {
# test our captcha
- my $result = verify_captcha( $captcha_seckey, $ENV{'REMOTE_ADDR'}, $cgi->param('recaptcha_challenge_field'), $cgi->param('recaptcha_response_field') );
+ my $result = verify_captcha(
+ privatekey => $captcha_seckey,
+ remoteip => $ENV{'REMOTE_ADDR'},
+ challenge => $cgi->param('recaptcha_challenge_field'),
+ response => $cgi->param('recaptcha_response_field')
+ );
if ($result->{'success'}) {
-
# save comment
my $stmt = "INSERT INTO comments VALUES (NULL, ?, datetime('now', 'localtime'), ?, ?, ?, ?, 0)";
my $sth = $dbh->prepare($stmt);
@@ -353,6 +358,8 @@ sub read_comment {
my $comment_email = $cgi->param('email') ? substr($cgi->param('email'), 0, 100) : undef;
my $comment_url = $cgi->param('url') ? substr($cgi->param('url'), 0, 100) : undef;
my $comment_body = substr(HTML::Entities::encode($cgi->param('comment'), "<>&"), 0, $comment_max_length);
+ my $remoteip = $ENV{'REMOTE_ADDR'};
+
$sth->execute($cgi->param('id'), $comment_name, $comment_email, $comment_url, $comment_body) || die $dbh->errstr;
$template->param( message => 'comment awaiting moderation, thank you' );
@@ -370,6 +377,7 @@ sub read_comment {
$smtp->datasend("You have received a new comment submission.\n");
$smtp->datasend("\n");
$smtp->datasend("From: $comment_name\n");
+ $smtp->datasend("IP: $remoteip\n");
$smtp->datasend("Date: $date\n");
$smtp->datasend("Comment: \"$comment_body\"\n");
$smtp->datasend("\n");
@@ -398,18 +406,9 @@ sub read_comment {
}
sub verify_captcha {
-
- my ( $privkey, $remoteip, $challenge, $response ) = @_;
-
+ my %args = @_;
my $http = HTTP::Lite->new();
- $http->prepare_post(
- {
- privatekey => $privkey,
- remoteip => $remoteip,
- challenge => $challenge,
- response => $response
- }
- );
+ $http->prepare_post( \%args );
$http->request( 'http://api-verify.recaptcha.net/verify' );
if ( $http->status eq '200' ) {
@@ -423,7 +422,6 @@ sub verify_captcha {
sub get_comments {
my %args = @_;
-
my $query = 'SELECT * FROM comments WHERE article_id=? AND enabled=? ORDER BY date ASC';
my $sth = $dbh->prepare($query);
$sth->execute($args{'article_id'}, $args{'enabled'}) || die $dbh->errstr;