package MT::Plugin::BanNoReferTb; # mt-ban-norefertb.pl # - Deny TrackBack ping which doesn't have any links to your blog. # # Author: Naoya Ito # License: same as Perl # use strict; use MT; use MT::Plugin; use MT::Blog; our $VERSION = "0.02"; my $plugin = MT::Plugin->new({ name => __PACKAGE__ . " v$VERSION", description => "Deny TrackBack ping which doesn't have any links to your blog.", }); MT->add_plugin($plugin); MT->add_callback('TBPingFilter', 2, $plugin, \&handler); sub handler { my ($eh, $app, $tbping) = @_; require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent(__PACKAGE__ . "/$VERSION"); $ua->timeout(10); my $res = $ua->request(HTTP::Request->new(GET => $tbping->source_url)); return error($app, $tbping, "the server returned " . $res->status_line) unless ($res->is_success); my $url = MT::Blog->load($tbping->blog_id)->site_url; return error($app, $tbping, "there is no link to your blog") unless ($res->content =~ m/\Q$url\E/i); 1; } sub error { my ($app, $tbping, $message) = @_; $app->log(__PACKAGE__ . ": TrackBack ping from " . $tbping->source_url . " denied because " . $message); return; } 1;