Author: dom Date: 2008-06-22 01:05:51 +0100 (Sun, 22 Jun 2008) New Revision: 1174
Added: sites/oxford.openguides.org/lib/ sites/oxford.openguides.org/lib/OpenGuides/ sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/ sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm Log: local akismet spam detector
Added: sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm =================================================================== --- sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm (rev 0) +++ sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm 2008-06-22 00:05:51 UTC (rev 1174) @@ -0,0 +1,62 @@ +# $HeadURL$ +# $LastChangedRevision$ +# $LastChangedDate$ +# $LastChangedBy$ + +package OpenGuides::SpamPlugin::Akismet; + +use strict; +use warnings; + +use Net::Akismet; +use Data::Dumper; +use Config::Tiny; +use MIME::Lite; + +sub notify_admins { + my ( $class, %args ) = @_; + my $reason = delete $args{reason}; + my $message = MIME::Lite->new( + From => $args{email}, + To => $args{email}, + Subject => "Attempted spam edit on " . $args{'url'}, + Data => "Someone just tried to edit oxford.openguides.org, and " + . "Akismet said no.\n\n" + . "Here's a dump of the details:\n" + . Dumper( %args ), + ); + $message->send; +} + +sub looks_like_spam { + my ( $class, %args ) = @_; + # http://dev.openguides.org/ticket/253 + # shouldn't have to fish this out ourselves + # hacking core OpenGuides code is for another day + my $config = Config::Tiny->read('wiki.conf'); + my $api_key = $config->{_}->{'spam_detector_akismet_key'}; + my $url = $config->{_}->{'script_url'}; + my $email = $config->{_}->{'contact_email'}; + + my $akismet = Net::Akismet->new( + KEY => $api_key, + URL => $url, + ) + or die "Could not verify API key\n"; + my %check_data = ( + USER_IP => $ENV{'REMOTE_ADDR'}, + COMMENT_USER_AGENT => $ENV{'HTTP_USER_AGENT'}, + COMMENT_CONTENT => $args{content}, + COMMENT_AUTHOR => $args{metadata}->{username}, + ); + my $result = $akismet->check( %check_data ); + + if ( $result eq 'true' ) { + $class->notify_admins( %args, url => $url, email => $email ); + return 1; + } else { + return 0; + } +} + +1;
Property changes on: sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm ___________________________________________________________________ Name: svn:keywords + HeadURL LastChangedRevision LastChangedDate LastChangedBy