Fight Comment Spam: Secret Tag Implementation for Movable Type

So, after [wetting your mouth][st], here is my implementation. If you expect something BIG, glamorous, I really must disappoint you ;) This implementation is known to work this MT 2.6x and MT Blacklist 1.6.4. It should work with later versions, but may need some changes. Please report any problems — and feel free to send me working implementations for later versions of MT and [MT Blacklist][bl].

[st]: http://www.itst.org/web/313-secret_tags_at_work.shtml
[bl]: http://www.jayallen.org/projects/mt-blacklist/

First, go to your comment template and insert a hidden field like this:

or alike. **Change the name to a random value of your choice.**

**Secret Tags without MT Blacklist**
Now you must tell MT about this new tag. Search Comments.pm (/lib/MT/App/) for the following code:

sub post {
my $app = shift;
my $q = $app->{query};

if (my $state = $q->param(‘comment_state’)) {

and replace it by

sub post {
my $app = shift;
my $q = $app->{query};

// Secret Tag. Don’t tell your mummy ;)
if (!$q->param(‘stag’)) {
$app->log(‘Blocked comment because of missing Secret Tag’);
return $app->error($app->translate(“Invalid entry ID “));
}

if (my $state = $q->param(‘comment_state’)) {

Then save Comments.pm and upload it to your MT installation. Don’t forget to backup a working, unmodfied copy of Comments.pm before overwriting it.

From now on, all comment submissions that do not include this form field will be rejected with an error message telling the entry code was invalid. We are polite people, so we don’t curse ;) Beside, all blocked attempts will be written to your Activity Log.

**Secret Tags with MT Blacklist**
At this point a quick break to thank Jay for this great plugin — ok, let’s continue.

MT Blacklists replaces the comment and trackback posting routines of MT, so we need to implement our Secret Tag in MT Blacklist’s new code.

Find MTBlPost.pm (/extlib/jayallen) and search for:

sub comment_post_hdlr_26 {

require jayallen::Blacklist;

use MT::Util qw( remove_html );
my $app = shift;
my $q = $app->{query};
if (my $state = $q->param(‘comment_state’)) {
require MT::Serialize;
my $ser = MT::Serialize->new($app->{cfg}->Serializer);
$state = $ser->unserialize(pack ‘H*’, $state);
$state = $$state;
for my $f (keys %$state) {
$q->param($f, $state->{$f});
}
}

and append:

// Secret Tag. Don’t tell your mummy ;)
if (!$q->param(‘stag’)) {
$app->log(‘Blocked comment because of missing Secret Tag’);
return $app->error($app->translate(“Invalid entry ID “));
}

Now find

sub comment_post_hdlr_266 {

require jayallen::Blacklist;

use MT::Util qw( remove_html encode_html );
my $app = shift;
my $q = $app->{query};

and append our five lines again:

// Secret Tag. Don’t tell your mummy ;)
if (!$q->param(‘stag’)) {
$app->log(‘Blocked comment because of missing Secret Tag’);
return $app->error($app->translate(“Invalid entry ID “));
}

That’s all folks. As already mentioned, this works with MT 2.6x and MT Blacklist 1.6.x. Since I do not have any working installations of current versions, I can not tell what you have to do to make it work there. It should work accordingly, though ;)

One comment

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert