Countering Comment Spam

It appears that my comment spammers have departed for greener pastures. Meaning that I can defer implementation of any spam counter measures. But if you’re using my Standalone Trackback and Comments, then here’s my defense strategy:

  1. Enable the comment RSS file. This will alert you to any new comments and allow you to remove them promptly. They target old posts in hopes of escaping notice.
  2. Eliminate outbound links from comments. Which is not as easy as I’d like it to be.
    1. Eliminate links from the comment body by setting ALLOWED_TAGS.
    2. Modify the comment entry form to reflect the new allowed tags by setting FORM.
    3. Modify the comment display to unlink the author’s website by setting BODY_FUNCTION.
  3. Modify the package to add comment moderation. I was thinking about eliminating outbound links in unapproved comments and allowing them in approved comments. This would call for the addition of UNAPPROVED_TAGS and UNAPPROVED_BODY_FUNCTION member variables.

After steps 1 and 2, you should end up with a comment script something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl

use lib '../cgi-lib';
use comment::service;

sub my_comment_display {
my ($data) = @_;

my $tmpl = <<TEMPLATE;
<div class="%s">
<div class="comment">%s</div>
<div class="nameDate">%s &#0149; %s</div>
</div>
TEMPLATE

my $i = 0;
for my $item (@$data) {
my $ts = POSIX::strftime("%d %b %Y, %I:%M %p %Z", localtime($item->{timestamp}) );
my $name = $item->{blog_name} || "Anonymous Coward";
my $nameUrl = $item->{url}
? "$name [$item->{url}]"
: $name;
printf $tmpl, ($i % 2 ? "odd" : "even"), $item->{excerpt}, $nameUrl, $ts;

$i++;
}
print "<hr>n";
}

$input_form = <<FORM_END;
<form method="POST" target="_self">
<input type="hidden" name="%s" value="%s">
<input type="hidden" name="link" value="%s">
<input type="hidden" name="%s" value="ping">
<table>
<tr><td colspan="2"><b>Add your comment (b, i, em, p tags allowed):</b></td></tr>
<tr><td valign="top" width="1%">Name:</td>
<td valign="top" width="99%"><input type="text" name="blog_name" size="50"
maxlength="255" />
</td>
</tr>
<tr><td valign="top">Web site:</td>
<td valign="top"><input type="text" name="url" size="50" maxlength="255" /></td>
</tr>
<tr><td colspan="2">Due to a rash of comment spam, links are not allowed in comments</td>
</tr>
<tr><td valign="top" width="1%">Comment:</td>

<td valign="top">
<textarea name="excerpt" rows="7" cols="80" style="width:100%"></textarea>
</td>
</tr>
<tr><td> </td>
<td><input type="submit" name="submitComment"
value="&nbsp;Submit&nbsp;" />&nbsp;&nbsp;<input type="button" name="cancelComment"
value="&nbsp;Cancel&nbsp;" onclick="window.close()" />
</td>
</table>
</form>
FORM_END

$tb = new comment::service(
BODY_FUNCTION=>\&my_comment_display,
ALLOWED_TAGS=>"b,i,em,p",
FORM=>$input_form,
DATA_DIRECTORY=>"/Path/to/comments/directory",
RSS_FILE=>"/Path/to/comments.xml",
BLOG_NAME=>"Take the First Step",
BLOG_URL=>"http://www.ideoplex.com/blog/"
);
$tb->handle();

exit(0);