<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bit Matrix &#187; spam</title>
	<atom:link href="http://blog.bit-matrix.com/tag/spam/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bit-matrix.com</link>
	<description>Tech. Code. Linux. MySQL. Ones. Zeroes.</description>
	<lastBuildDate>Tue, 31 Aug 2010 01:10:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress spam killing script</title>
		<link>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/</link>
		<comments>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 08:55:35 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=58</guid>
		<description><![CDATA[Blog comment spam is an unfortunate reality of having a blog. See the chart to get a sense of how much spam comes in on a daily basis to one of my blogs that receives a moderate amount of traffic. The red line shows the 30-day moving average for the number of spam comments daily.



Weeding [...]]]></description>
			<content:encoded><![CDATA[<p>Blog comment spam is an unfortunate reality of having a blog. See the chart to get a sense of how much spam comes in on a daily basis to one of my blogs that receives a moderate amount of traffic. The red line shows the 30-day moving average for the number of spam comments daily.</p>
<div class="mceTemp">
<a href="http://blog.bit-matrix.com/wp-content/uploads/2009/12/spam_comments.jpg"><img class="size-full wp-image-85" title="Number of daily spam comments on the typical blog" src="http://blog.bit-matrix.com/wp-content/uploads/2009/12/spam_comments.jpg" alt="Number of daily spam comments on the typical blog" /></a>
</div>
<p><span id="more-58"></span></p>
<p>Weeding out comments daily can be a real nuisance and, if you&#8217;ve missed a few days, the spam can pile up until it becomes a real time waster. Using the Akismet plugin for Wordpress goes a long way to rid you of spam and I would recommend that everyone use it. If, for some reason, you are looking for a standalone solution, I have hacked up a quick script to mark Wordpress Comments as spam based on the number of links in the comment. It is quite crude but if you have thousands of spam messages pilled up, you will appreciate it.</p>
<p>You will need Perl and the DBI module (if you don&#8217;t know what this is you should probably get the Akismet plugin <img src='http://blog.bit-matrix.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ).</p>
<pre>#!/usr/bin/perl
#
# wp_spam_kill.pl - brute force spam killing script
#
# Kill spam comments in WordPress based on the number of links in the comment
#
# date   : 2009.01.31
# http://bit-matrix.com
# license: GPL

use strict;
use DBI;

$| = 1;

# Configure your blog database
my $db = "DATABASE_NAME";
my $host = "DATABASE_HOST";
my $username = "DATABASE_USERNAME";
my $password = "DATABASE_PASSWORD";
my $comments_table = 'comments';
my $port = "3306";

# If a comment has more than this many links, mark it as spam
my $spam_level = 4;

sub query($$){
    my $dbh = shift;
    my $pre_bind = shift;

    my $sql = $dbh-&gt;prepare($pre_bind);
    return $sql-&gt;execute() ? $sql : undef;
};

# Connect to database
print "Connecting to $db...\n";
my $dsn = sprintf "DBI:mysql:database=%s;host=%s;port=%s;",$db,$host,$port;
my $dbh = DBI-&gt;connect($dsn,$username,$password);

# Fetch all unapproved comments
print "Getting comments...\n";
my $query = 'SELECT * FROM '.$comments_table.' WHERE comment_approved="0";';
my $c_sql = query($dbh,$query);
printf "%d Comments not approved yet\n",$c_sql-&gt;rows();

# Check each comment for number of links and mark it as spam if it has more links
my $spam_killed = 0;
while(my $c = $c_sql-&gt;fetchrow_hashref()){
    my @links = $c-&gt;{comment_content} =~ /(http:\/\/)/gs;
    if( $#links+1 &gt;= $spam_level ){
        printf "SPAM - %d links in comment\n",$#links+1;
        query($dbh,'UPDATE '.$comments_table.' SET comment_approved="spam" WHERE comment_ID="'.$c-&gt;{comment_ID}.'" LIMIT 1;');
        $spam_killed++;
    };
};

printf "Marked %d messages as spam\n",$spam_killed;

0;

__END__</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
