package MT::Plugin::BanNonJapaneseTBPing; # mt-ban-nonja-tb.pl # - Deny or moderate Non Japanese trackback ping using MT3 CommentFilter API # # Author: Yasuhiro Horiuchi # License: same as Perl # use strict; our $VERSION = "0.2"; # charcter repetation our $CharRep = 3; # number of match our $NofMatch = 1; use MT; use MT::Plugin; use MT::I18N; my $plugin = MT::Plugin->new({ name => "BanNonJapaneseTBPing v$VERSION", description => "Deny Non japanese trackback ping", }); MT->add_plugin($plugin); MT->add_callback('TBPingFilter', 2, $plugin, \&handler); sub handler { my($eh, $app, $ping) = @_; my $charset = MT::ConfigMgr->instance->PublishCharset; my $excerpt = MT::I18N::encode_text($ping->excerpt, $charset, 'euc'); my @match = $excerpt =~ /((?:\xA4[\xA1-\xF3]|\xA1[\xAB\xAC\xB5\xB6])|(?:\xA5[\xA1-\xF6]|\xA1[\xA6\xBC\xB3\xB4])){$CharRep,}/g; if ( @match < $NofMatch ) { my $remote_ip = $ENV{'HTTP_X_FORWARDED_FOR'} || $app->remote_ip; $app->log("Non Japanese trackback ping from $remote_ip"); return 0; } return 1; } 1;