« Blog Spam | Main | TIA2: The MATRIX »

October 30, 2003

Spam Comments part 2

My initial intention was to throw together a quick and dirty hack that would see if my concept would even work, that is piping an MT comment through SA or DCC. The failure in this process has proven to be my lack of understanding in Perl and/or the MT plugin architecture, and resulted in a 30 minute hack to a 5 hour exploratory adventure.

There have already been a few revisions on this idea. Originally I had planned to make a MTSpamComment tag that would wrap around the current MTComment tags. While an interesting idea, I realized this isn't really flexible enough so I moved towards implementing a global filter. This way you can change the <MTCommentText> to include the optional variable spam_compare=1 > and you could potentially include it anywhere else (maybe Trackbacks). This would work all fine and dandy, but I seem to have hit a snag where my knowledge of the MT plugin system, and the mechanics of Perl have broken down to sheer chaos.

First question becomes, is anyone aware of a means with which to debug what might be wrong? Maybe I've been spoiled by my recent dive into GDB, but for some reason I have to believe that there is a more descriptive error message than:

[Thu Oct 30 09:08:34 2003] [error] [client 151.196.45.74] malformed header from script. Bad header=Possible unintended interpolat: /usr/local/www/cgi-bin/cgiwrap that exists for the MT Plugin system. You can see the simplistic Perl code in the extended entry (thats about all that's there). This is almost enough to convince me to move to Serendipity.

[EDIT: corrected HTML tags]

I figure I may as well share what I've been doing code wise too, since it will probably help make things a bit easier to understand. You'll find better Perl code in this world, I've never claimed to be a Perl hacker (C and PHP do everything else I need).

package MT::Plugin::CommentSpam;

use MT::Template::Context;
use MT::Comment;
use dccifd/dccif.pl

my $fuz1 = 10;
my $fuz2 = 10;

MT::Template::Context->add_global_filter(check_spam => { &spamc } );
MT::Template::Context->add_tag(

sub spamc {
my $text = shift;
my $curr_tmpl = shift;
my $arg_value = shift;

switch ($arg_value) {
case 1 {
@proc_args = ("dccproc", "-Q", "-H", "-i", $text);
system(@args) == 0 or die "system @args failed: $?"

/* now check for the resulting changes in $text */
if (($text =~ /\bFuz1=many/) ||
($text =~ /\bFuz2=many/))
$text = "This comment has been deemed to be spam";
if (($text =~ /\bFuz1=$fuz1/) ||
($text =~ /\bFuz2=$fuz2/))
$text = "This comment has been deemed to be spam";
last }
case 2 {
// future work for Spam Assassin usage
last }
};

return $text;
}
1;

Posted by Dan at October 30, 2003 06:36 AM

Comments