http:BL spam filtering and tagging module for sNews 1.7

Comments (7)

Today I'm happy to release the initial version of my sNews SPAM module. This module should help assist you in filtering and managing much of the junk comments in your sNews installation. As of this writing, the module has properly tagged 96.1% of SPAM comments on my site, and tagged 0 false positives.

How does it work? It does this by checking the comment poster's IP address against the extensive (70 Million+) database from Project Honey Pot. You need a http:BL Access Key to utilize this mod, so sign up, and install a honeypot or quicklink if you can. An overview of Project HoneyPot can be found here.

A quick demo of the end product admin interface can be seen in this video here.

Here is what the email tagging feature looks like in an email client.

Now for the fun part, installing the module. First download the module package;

VERSION history
[1.0.0] - initial release

OK, now extract the zip file and have a look at the contents.

Upload the stylesheet and spam module

Now upload the css folder and the mod.spam.php module file into the same directory as your snews.php file.

SQL code

Next you want to add the settings to your database, that file is in the sql folder, mod.spam.sql;

INSERT INTO settings (name, value) VALUES
('spam_email_tag', 'on'),
('spam_auto_delete', '21'),
('spam_api_key', 'abcdefghijkl'),
('spam_enable', 'on');

Modify the language file

Next we need to add the language variables to our language file, EN.php in my case, copy those from the lang/EN.php to your language file;

    // Spam Manager
    $l['snews_spam'] = 'Spam Management System';
    $l['spam_manager'] = 'Spam settings';
    $l['spam_enable'] = 'Enable Spam detection.';
    $l['spam_update_check'] = 'Check for updates';
    $l['spam_api_key'] = 'Project Honey Pot <a href="http://www.projecthoneypot.org/httpbl_configure.php" title="Http:BL API Key">Http:BL API Key</a>';
    $l['spam_api_js_error'] = 'The API key contains illegal characters or is the wrong length. All Access Keys are 12-characters in length, lower case, and contain only alpha characters (no numbers).';
    $l['spam_auto_delete'] = 'Delete Spam comments after how many days. (0 = never)';
    $l['spam_email_tag'] = 'Prepend tag to emails when the comment is flagged. <br />
        <i>Note: If you\'re using the  \'Approve comments before publishing\' or \'Send posted comments to your e-mail\' comment settings, this will prepend the tag [SPAM] to the email subject when the message is suspected spam.</i>';
    $l['spam_save'] = 'Save settings';
    $l['spam_comments'] = 'Comments tagged as spam';
    $l['spam_tagged'] = 'total comments currently tagged as spam';
    $l['spam_no_spam'] = '0 comments currently tagged as spam.';
    $l['spam_delete'] = 'Delete all spam comments';
    $l['spam_delete_msg'] = 'This will delete all comments tagged as SPAM from the database, are you sure?';
    $l['spam_deleted'] = 'spam comments deleted.';
    $l['spam_preview_posted_in'] = 'Posted in:';
    $l['spam_preview_name'] = 'Name:';
    $l['spam_preview_date'] = 'Date:';
    $l['spam_preview_preview'] = 'Preview:';

Modify the index template file

Now let's work on a copy of index.php, add the following include just below the snews.php include;

include('mod.spam.php'); 

and then within the head somewhere;

<?php 
if (_ADMIN) {
    echo '<link rel="stylesheet" type="text/css" href="css/mod.spam.css" />';
}
?>

Modify the core snews.php file

Now I've included a snews.patch file as well, to simplify patching your snews.php file. Patching is easy, drop the patch into the same directory and issue the command;

patch < snews.patch

If that worked, then skip to the end now.

Now if you don't have CLI access or can't patch for whatever reason, we'll do the modifications by hand here. Let's work on a copy of snews.php, take your time and make the following changes (highlighted);

// around line 100

if (_ADMIN) {$l['cat_listSEF'] .= ',snews_spam,administration,admin_category,admin_article

// around line 570

case 'snews_files':
    files(); return; break;
case 'snews_spam':
    manageSpam(); return; break;
case 'process':
    processing(); return; break;

// around line 840

$approved = s('approve_comments') != 'on'|| _ADMIN ? 'True' : '';
    if (s('spam_enable') == 'on') {
        if (spamQuery() == 'true') {
            $approved = 'SPAM';
            if (s('spam_email_tag') == 'on') {
                $append = '[SPAM] - ';
            }
        }
    }
$query = 'INSERT INTO '._PRE.'comments'.'(articleid, name, url, comment, time, approved) VALUES'.

// around line 845

$commentStatus = (s('approve_comments') == 'on' || $approved == 'SPAM') && !_ADMIN ? l('comment_sent_approve') : l('comment_sent');

// around line 850

if (s('approve_comments') == 'on' || $approved == 'SPAM') {

// around line 854

$subject = $append.l('subject_a');

// around line 1605, change the line, change the != \'True\' part like below

$query_comm = 'SELECT id,articleid,name FROM '._PRE.'comments'.' WHERE approved NOT IN (\'True\',\'SPAM\') ORDER BY id DESC';

// around line 1620, find this following block of code and REMOVE it

if ($unapproved > 0) {
	echo '<div class="adminpanel">';
	echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('comments'));
	echo '<p><a onclick="toggle(\'sub1\')" style="cursor: pointer;" title="'.l('unapproved').'">
	'.$unapproved.' '.l('wait_approval').'</a></p>';
	echo '<div id="sub1" style="display: none;">';
	while ($r = mysql_fetch_array($result_comm)) {
		$articleTITLE = retrieve('title', 'articles', 'id', $r['articleid']);
		echo '<p>'.$r['name'].' (<strong>'.$articleTITLE.'</strong>) '.l('divider').'
			<a href="'._SITE.'?action=editcomment&amp;commentid='.$r['id'].'">'.l('edit').'</a></p>';
	}
    echo '</div></fieldset></div>';
}

// now ADD this entire block in it's place

    echo '<div class="adminpanel">';
    echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('comments'));
    echo '<p>'.displaySpamLink().'<br /><a onclick="toggle(\'sub1\')" style="cursor: pointer;" title="'.l('unapproved').'">
    '.$unapproved.' '.l('wait_approval').'</a></p>';
    echo '<div id="sub1" style="display: none;">';
    while ($r = mysql_fetch_array($result_comm)) {
        $articleTITLE = retrieve('title', 'articles', 'id', $r['articleid']);
        echo '<p>'.$r['name'].' (<strong>'.$articleTITLE.'</strong>) '.l('divider').'
        <a href="'._SITE.'?action=editcomment&amp;commentid='.$r['id'].'">'.l('edit').'</a></p>';
    }
    echo '</div></fieldset></div>';
 

// finally, around line 1625, add the following

    echo '<p><a href="snews_settings/">'.l('settings').'</a></p>
    <p><a href="snews_spam/">'.l('spam_manager').'</a></p>
    <p><a href="snews_files/">'.l('files').'</a></p>

Upload the modified files

That should be it, now upload your modified snews.php, index.php, and language files and you should be in business.

bookmark / share this: Bookmark and Share
rated 4.25/5 (4 votes)


7 comments

Add a new comment »

toolman toolman said:
Mar 1st, 2010 at 4:24 am

I am glad that I can install this modification. Good work Matt!
The installation instructions should further highlight the first round bracket in the line with $commentStatus, because the bracket should be added.

I still had a problem with displaying "comments waiting approval" in the administration panel, but I remembered that I installed LightView (similar to Lightbox), there is a conflict toggle function. So the problem is solved.
So, we proceed to the fight against spam :D


toolman toolman said:
Mar 1st, 2010 at 5:07 am

I forgot one thing. It would be nice to see a link to this page on http://www.projecthoneypot.org/httpbl_implementations.php :)

Whether there would be possibility to send a comment about a specific IP directly from the snews? For example, 195.xx.xx.xx is comment spammer?


Matt Matt said:
Mar 1st, 2010 at 7:43 am

Thanks toolman, I highlighted the added opening parenthesis for that line.

I sent a note to the Project Honey Pot folks about the implementation page, we'll see if they respond. :)

As for the IP reporting, it would be nice, but Project Honey Pot only takes data collected from the honeypots generated by them, to keep the data legitimate.

Otherwise someone could just forward bogus IPs if they wanted and that would dilute the data, or worse, get someone blacklisted unfairly, so it makes sense for them to control the data tightly.


jesth jesth said:
Mar 4th, 2010 at 5:50 pm

Hi.

Friend of slemborg and asundrus here, just wanted to thank you, as i've used your site alot for help etc. and this one is also looking good.


Matt Matt said:
Mar 4th, 2010 at 6:34 pm

Thanks jesth, I appreciate the feedback!


konga konga said:
Aug 27th, 2010 at 10:25 am

Hi Matt, if you plan to update it, please have a look into function displaySpamLink() in mod.spam.php. Replace the english text with l('spam_tagged') and l('spam_no_spam'), so other languages will work immediately ;)

Again THANKS for all your Mods and Hacks!


Tina Tina said:
Aug 29th, 2010 at 3:32 pm

Installed this today and working like a charm :) Thanks!



Write a comment

* = required field

:

:

:

:

You may insert urls in plain text, urls will be automatically linkified for trusted users and on seasoned posts only. All first comments are moderated, so use your email if you want to be remembered.


Back to top