Mark A. Hershberger (hexmode) wrote in lj_dev,
Mark A. Hershberger
hexmode
lj_dev

lj + Akismet

Since I run a tiny LJ instance for myself and a few other people, I'd like to use Akismet to help filter spam. (If someone has pointers on using LJ's own spam-fighting techiniques on a small site, I'd love to hear them!)

Anyway, last night, I turned anonymous comments back on after installing Akismet checks for anonymous posts (a small change to talkpost_do.bml).

This morning, I found that 40 spam comments had been blocked (yay!) but a couple still got through, and I wanted to feed those back into Akismet. A modification to talklib.pl did the job.

Hope this helps someone else out there.


--- cvs/livejournal/cgi-bin/talklib.pl	2007-07-05 15:44:25.186758848 -0400
+++ cgi-bin/talklib.pl	2007-07-16 11:08:52.073345947 -0400
@@ -1764,6 +1764,25 @@
         return 1 unless $ip;
     }
 
+    if($LJ::DO_AKISMET) {
+      my $akismet = Net::Akismet->new(KEY => $LJ::AKISMET_KEY,
+                                      URL => 'http://www.openweblog.com/',
+                                     ) or die('Key verification failure!');
+
+      my $verdict = $akismet->spam(USER_IP                 => $ip,
+                                   COMMENT_CONTENT         => $body,
+#                                   REFERRER                => $referer,
+                                  ) or die('Is the server here?');
+
+      if ($verdict) {
+        warn "Akismet accepted spam report: $ip, $subject\n";
+        return LJ::server_down_html();
+      }
+      else {
+        warn "Akismet failed on spam report: $ip, $subject\n";
+      }
+    }
+
     # step 3: insert into spamreports
     $dbh->do('INSERT INTO spamreports (reporttime, posttime, ip, journalid, posterid, subject, body) ' .
              'VALUES (UNIX_TIMESTAMP(), UNIX_TIMESTAMP(?), ?, ?, ?, ?, ?)',

--- cvs/livejournal/htdocs/talkpost_do.bml	2007-02-10 13:49:08.543614258 -0500
+++ htdocs/talkpost_do.bml	2007-07-16 11:04:11.060038865 -0400
@@ -31,6 +31,31 @@
 
     return LJ::server_down_html() if $LJ::SERVER_DOWN;
 
+    if($LJ::DO_AKISMET && $POST{'usertype'} eq 'anonymous') { # akismet check
+      my $ip = $ENV{'REMOTE_ADDR'};
+      my $body = $POST{'body'};
+      my $referer = $ENV{'HTTP_REFERER'};
+      my $subject = $POST{subject};
+
+      my $akismet = Net::Akismet->new(KEY => $LJ::AKISMET_KEY,
+                                      URL => 'http://www.openweblog.com/',
+                                     ) or die('Key verification failure!');
+
+      my $verdict = $akismet->check(
+                        USER_IP                 => $ip,
+                        COMMENT_CONTENT         => $body,
+                        REFERRER                => $referer,
+                ) or die('Is the server here?');
+
+      if ('true' eq $verdict) {
+        warn "Akismet reports spam: $ip, $referer, $subject\n";
+        return LJ::server_down_html();
+      }
+      else {
+        warn "Akismet reports no spam: $ip, $referer, $subject\n";
+      }
+    }
+
     LJ::need_res('stc/display_none.css');
 
     # Set the title to be for an error, it will be changed later
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments