http:BL spam filtering and tagging module for sNews 1.7

http:BL spam filtering and tagging module for sNews 1.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.

Spam tagging mod

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

mod.spam1.0.0.zip

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.

Tags

 

You might like

Comments


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


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

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?


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.


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.


Thanks jesth, I appreciate the feedback!


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!


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


Hello hello Matt
It's been a long time.

I hope you're well.

I just installed it since an american blackhat SEO bee is annoying my brand new website.

I gonna tell ya later if I caught it. :-D


Where do these &iuml;&iquest;&frac12; come from?
Is it me?

Oh! I got another question: are you going to publish your Mod for subscribing by email to new comments.


I'm not sure where they're coming from Sven, but they are most likely being entered by hand, as I'm getting the same ones, and they're using the contact form only.

I don't get them enough to really care, my email filter is dumping them into spam now anyways.

I won't be releasing this comment subscription thingie I wrote, as it's too elaborate and changed so many things. I also run a separate PHP script via CRON hourly so if a comment thread is busy people won't get constant emails.


It is my apostrophe. The french apostroph is rather different.
Kinda a comma like this , but up...
it is weird that it is being displayed here as on most of american websites or forum my apostrophs are printed well.

C�est ça.


Matt, when I must do
// around line 1620, find this following block of code and REMOVE it

and change it to your code my adminpanel looks like this:
http://www.shrani.si/f/1l/3d/2cBcoAjR/cras...

I really dont know what goes wrong here :)


Hi Matt,
unfortunately the download of the mod no longer works. Any chance of fixing it? Thanks and greetings
tina


Hi seven,

Fixed now, sorry about that, thanks for letting me know.

--Matt


(optional, not publicly displayed) (optional)

Copyleft 2002 - 2014 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top