[CODE] Integrating the spam filter into phpBB3

Mods for various forums/blogs for use with the SBST

Moderator: fspamlist

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

[CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Wed Nov 26, 2008 7:03 pm

I wrote this one for Tom's forum, and figured it'd be useful for others.

Unfortunately, whilst phpBB3 allows you to have new registrations and posts, checked automatically against Spamhaus/SpamCop (See ACP > Security Settings > Check IP against DNS Blackhole List:), it doesn't allow the others, and has way too many F/P's due to it's checking the CBL aswell.

Whilst this one doesn't currently allow you to have users checked before allowing their posts to go through (I'm working on that), it does allow you to check new registrations against the databases used by Check Spammers, and have an e-mail fired to you whenever a user is blocked.

File: /includes/functions_user.php

Find: (approx line #1358)

Code: Select all

   // ... fast checks first.
   if (strpos($username, '"') !== false || strpos($username, '"') !== false || empty($clean_username))
   {
      return 'INVALID_CHARS';
   }

   $mbstring = $pcre = false;


Add AFTER

Code: Select all

   /// BEGIN SPAM MOD
   $email = request_var('email', '');
   $ip = $_SERVER['REMOTE_ADDR'];
   $fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.str_replace(' ', '%20', $username).'&email='.$email.'&ip='.$ip);
   if (strpos($fspamcheck, 'TRUE') !==False) {
      // Notify admin via e-mail
      $blockedby = str_replace(' TRUE', '', $fspamcheck);
      $blockedby = str_replace(' ', ' & ', $blockedby);
      $msg = 'The following was blocked by the '.$blockedby.' filter<br><br>Username: '.$username.'<br><br>Email: '.$email.'<br><br>IP: '.$ip;
      $to = "your@email.addr";
      $from = "nobody@".$_SERVER['SERVER_NAME'];
      $subject = "Spammer blocked by hpHosts Spam filter";
      $headers =    "MIME-Versin: 1.0\r\n" .
      "Content-type: text/html; charset=ISO-8859-1; format=flowed\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n" .
      "From: " . $from . "\r\n" .
      "X-Mailer: hpHosts Spam Filter";
      mail($to, $subject, $msg, $headers);
      // Notify user
      return 'Your registration has been blocked by our <a href="http://temerc.com/Check_Spammers/">spam filter</a>. Please either try again or contact an administrator';
      die();
   }
   /// END SPAM MOD


You'll need to download the Check Spammers file, and place the files on your server.

An example of the e-mail you will receive is;

Code: Select all

The following was blocked by the fSpamlist & StopForumSpam filter

Username: embormbeteoma

Email: soovtovichsofttwtest@gmail.com

IP: 212.95.54.36
Last edited by MysteryFCM on Fri Sep 09, 2011 11:37 pm, edited 6 times in total.
Reason: Updated code (allows for spaces in usernames)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Wed Feb 11, 2009 10:35 am

If you've got existing spammers registered and want to prevent their posting until you get a chance to remove their accounts (tested on phpBB 3.0.4;

File: /posting.php

Find: (approx line #729)

Code: Select all

   // Validate username
   if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))


ADD BEFORE

Code: Select all

   // BEGIN SPAM MOD
   $sPostersIP = $_SERVER['REMOTE_ADDR'];
   $username = $user->data['username'];
   $fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.str_replace(' ', '%20', $username).'&ip='.$sPostersIP);
   if (strpos($fspamcheck, 'TRUE') !==False) {
      // Notify admin via e-mail
      $blockedby = str_replace(' TRUE', '', $fspamcheck);
      $blockedby = str_replace(' ', ' & ', $blockedby);
      $msg = 'The following user was prevented from posting by the '.$blockedby.' filter<br><br>Username: '.$username.'<br><br>IP: '.$sPostersIP;
      // Change your@email.addr to the e-mail address you want e-mail reports sent to
      $to = "your@email.addr";
      $from = "nobody@".$_SERVER['SERVER_NAME'];
      $subject = "Spammer blocked by hpHosts Spam filter";
      $headers =    "MIME-Versin: 1.0\r\n" .
      "Content-type: text/html; charset=ISO-8859-1; format=flowed\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n" .
      "From: " . $from . "\r\n" .
      "X-Mailer: hpHosts Spam Filter";
      mail($to, $subject, $msg, $headers);
      // Notify user
      $error[] = 'Your post has been blocked by our <a href="http://temerc.com/Check_Spammers/">spam filter</a>. Please either try again or contact an administrator';
   }
   // END SPAM MOD
Last edited by MysteryFCM on Fri Sep 09, 2011 11:37 pm, edited 1 time in total.
Reason: Updated code (Allows for spaces in usernames)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

RikRas
Posts: 5
Joined: Wed Feb 18, 2009 4:06 pm
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby RikRas » Wed Feb 18, 2009 5:39 pm

can you tell me if the entire "check_spammers" directory is what I need to upload to my Apache server? Should it be placed in the root of my forum? Is there anywhere I have to configure the paths to anything? I have read the docs, but they don't mention any of this. Maybe that is an indication it is simpler than I expect.
--------
Rik

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Wed Feb 18, 2009 6:04 pm

All you need to do is upload the check_spammers folder and it's contents, to your server (can be absolutely anywhere on your server).

I'd recommend changing the check_spammers folder name to something a little less obvious.

You'd then replace the path in the mod, to the copy hosted on your server, for example;

Code: Select all

$fspamcheck = file_get_contents('/somewhere/on/your/website/check_spammers_plain.php?name='.$username.'&ip='.$sPostersIP);


Where /somewhere/on/your/website/ is the path to the check_spammers folder :)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

RikRas
Posts: 5
Joined: Wed Feb 18, 2009 4:06 pm
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby RikRas » Sat Feb 21, 2009 3:30 pm

The script is working very well, thanks you for providing it.
--------
Rik

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Sat Feb 21, 2009 3:32 pm

My pleasure :)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

OKCRandy
Posts: 3
Joined: Sun May 24, 2009 9:06 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby OKCRandy » Sun May 24, 2009 11:59 am

For some strange reason no posts are being allowed to my forum.

Posting was possible when I first installed but now no posting is allowed.

The following is displayed:

Your post has been blocked by our spam filter. Please either try again or contact an administrator

What would cause this to happen?

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Sun May 24, 2009 12:14 pm

Is this occuring for all users?

Are you using the latest edition of the SBST?

Do you have mail notifications enabled, so you receive the blocked users/posts notifications? (will tell you which of the blacklists blocked it).
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

OKCRandy
Posts: 3
Joined: Sun May 24, 2009 9:06 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby OKCRandy » Sun May 24, 2009 1:19 pm

I have mail notifications enabled, I get emails when a spammer tries to register.

I am not sure what you mean by SBST.

I took out the entry to File: /posting.php

I think I have a clean user base so I do not think I need the edits for posting.php. Is that correct?

If I leave the edit out to the file posting.php, posting is allowed.

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Sun May 24, 2009 2:43 pm

OKCRandy wrote:I have mail notifications enabled, I get emails when a spammer tries to register.

I am not sure what you mean by SBST.


SBST = Spambot Search Tool :)

OKCRandy wrote:I took out the entry to File: /posting.php

I think I have a clean user base so I do not think I need the edits for posting.php. Is that correct?


That is correct, yes :)

OKCRandy wrote:If I leave the edit out to the file posting.php, posting is allowed.


If you've still got it, could you post a copy of the modified posting.php file please (the one with the SBST mod code from above). Note it will need to be zipped as .php files aren't allowed to be attached directly.
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

OKCRandy
Posts: 3
Joined: Sun May 24, 2009 9:06 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby OKCRandy » Sun May 24, 2009 5:24 pm

Here is the file. Thanks for your help.
Attachments
SBST_posting.zip
(13.16 KiB) Downloaded 435 times

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Sun May 24, 2009 5:47 pm

Sorry for taking so long. For some reason, it was not properly reading the $sPostersIP variable, and thus, not submitting it (not entirely sure why that resulted in the mod thinking true had been returned, as directly querying the URL it uses, resulted in the correct answer of FALSE).

Can you try replacing the mod code in posting.php with the following please? (just tested it on this board and it worked as expected once I asked it to detect the IP each time, instead of using a var);

Code: Select all

   // BEGIN SPAM MOD
   $sPostersIP = $_SERVER['REMOTE_ADDR'];
   $username = $user->data['username'];
   $fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$username.'&ip='.$_SERVER['REMOTE_ADDR']);
   if (strpos($fspamcheck, 'TRUE') !==False) {
      // Notify admin via e-mail
      $blockedby = str_replace(' TRUE', '', $fspamcheck);
      $blockedby = str_replace(' ', ' & ', $blockedby);
      $msg = 'The following user was prevented from posting by the '.$blockedby.' filter<br><br>Username: '.$username.'<br><br>IP: '.$sPostersIP;
      // Change your@email.addr to the e-mail address you want e-mail reports sent to
      $to = "your@email.addr";
      $from = "nobody@".$_SERVER['SERVER_NAME'];
      $subject = "Spammer blocked by hpHosts Spam filter";
      $headers =    "MIME-Versin: 1.0\r\n" .
      "Content-type: text/html; charset=ISO-8859-1; format=flowed\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n" .
      "From: " . $from . "\r\n" .
      "X-Mailer: hpHosts Spam Filter";
      mail($to, $subject, $msg, $headers);
      // Notify user
      $error[] = 'Your post has been blocked by our <a href="http://temerc.com/Check_Spammers/?name='.$username.'&ip='.$_SERVER['REMOTE_ADDR'].'">spam filter</a>. Please either try again or contact an administrator';
   }
   // END SPAM MOD


/edit

I noticed btw, that you added the code after //validate username, but it was actually meant to be added before it ;) (shouldn't have caused this though)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 10:19 am

Kindly bear with my ignorance here, but I just want to make sure I do this absolutely correctly.

For the first one in this thread ( the one that doesn't affect pre-registered members ) is there any file in which I need to edit the paths ?
Or can I really just slap it anywhere I like and install it ?
And thanks in advance for the work done on this, may it save me many headaches ;-)

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 10:26 am

No worries :)

You can place the SBST files absolutely anywhere you like :) All you need to ensure is, you change the URL in the mod, to reflect the location of the files. For example, if you place them at;

domain.com/sbst/

Then you would change;

Code: Select all

$fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$username.'&email='.$email.'&ip='.$ip);


To;

Code: Select all

$fspamcheck = file_get_contents('http://domain.com/sbst/check_spammers_plain.php?name='.$username.'&email='.$email.'&ip='.$ip);
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 10:39 am

I seem to be having a bit of a problem here..

I used UEStudio to search for that string in all files ( including sub-directories ) and it returns that the string doesn't exist in any file....

"That" string being this one

Code: Select all

$fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$username.'&email='.$email.'&ip='.$ip);


Nevermind, I'm an idiot.........
Last edited by Spewk on Tue Jul 14, 2009 10:45 am, edited 1 time in total.

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 10:42 am

That string is part of the mod in the first post, that you need to add to your forums registration file :)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 11:48 am

hmmm well that just didn't turn out well - got two errors that have my site down

Code: Select all

[phpBB Debug] PHP Notice: in file /common.php on line 228: require(./antispam/asacp.php) [function.require]: failed to open stream: No such file or directory

Fatal error: require() [function.require]: Failed opening required './antispam/asacp.php' (include_path='.;C:\php5\pear') in D:\Hosting\4574740\html\Forum\common.php on line 228


Edit : ok so that's only one error....wonder what I'm supposed to do with that path ?
Last edited by Spewk on Tue Jul 14, 2009 11:56 am, edited 1 time in total.

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 11:53 am

Does this file exist? >>> antispam/asacp.php

If so, it's likely due to the error_reporting variable being turned on. Go to the folder containing the SBST files, and open config.php.

Locate the following in config.php;

Code: Select all

error_reporting(E_ALL ^ E_NOTICE);


.. and replace it with;

Code: Select all

//error_reporting(E_ALL ^ E_NOTICE);
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 11:59 am

Spewk wrote:Edit : ok so that's only one error....wonder what I'm supposed to do with that path ?


Interestingly, that file is not part of the SBST, so why it's suddenly sprung up is baffling. However, can you attach a copy of the file you modified so I can take a look please?
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 12:12 pm

holy crap, what a mess I seem to have made of this - now my homepage is a spambot acp.....

Ack - that's what I need, just any old surfer coming along using my control panels

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 12:16 pm

MysteryFCM wrote:
Spewk wrote:Edit : ok so that's only one error....wonder what I'm supposed to do with that path ?


Interestingly, that file is not part of the SBST, so why it's suddenly sprung up is baffling. However, can you attach a copy of the file you modified so I can take a look please?


At this point my brain is kind of frying, sitting here looking at the front page of my site turned into a spambot control panel...ccould you please specify exactly which file you need me to upload and to where ?

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 12:19 pm

Where did you upload the SBST files to? (From what you've described, you've uploaded the SBST files to the root of your site?)

The only file that should've been modified is (this is the file mentioned in the first post, and is the one you needed to add the mod code to);

forum/includes/functions_user.php
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 12:22 pm

MysteryFCM wrote:Where did you upload the SBST files to? (From what you've described, you've uploaded the SBST files to the root of your site?)

The only file that should've been modified is (this is the file mentioned in the first post, and is the one you needed to add the mod code to);

forum/includes/functions_user.php



Well, no nothing is directly on root - but when I went to the install.xml page in the folder I created, it had a long list of edits you have to do to install the mod, so I did all of those....

and this is the hierarchy "../forum/spammerhammer/"

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 12:27 pm

There is no install.xml file in the SBST????

SBST files = http://temerc.com/Check_Spammers/check_spammers.zip
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 12:45 pm

Ahhh hell my site is dorked, going to have to restore database

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 12:48 pm

Aslong as you're comfortable undoing the instructions you followed, you should be able to put your site back to normal.

I'm a little curious about which file you downloaded, that contained the install.xml file though?
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 1:01 pm

Well I deleted all the altered files from the server and restored the originals, but for some reason it didn't work.
I don't actually even know for sure if restoring the db is going to work.

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 1:25 pm

Did you remember to clear the cache folder after restoring the original files?

Restoring the DB will only fix it if you actually modified the DB itself.

If it's the same error message you're getting;

1. Clear the cache folder (forum/cache)
2. open common.php and go to line 228 (as mentioned in the error), and remove the reference to the file in the error message (I presume the file it is mentioning, is part of the mod you used as it's not part of the SBST and it's not part of the phpBB3 installation)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

Spewk
Posts: 27
Joined: Tue Jul 14, 2009 5:56 am
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby Spewk » Tue Jul 14, 2009 1:36 pm

It's screwed - there is no common.php file in the cache folder, and the one one level up stops at line #227

I guess I'll just have to upload the entire forum all over again

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into phpBB3

Postby MysteryFCM » Tue Jul 14, 2009 1:40 pm

You can try uploading a copy of the original common.php file, but you still need to delete ALL of the files in the cache folder for phpBB to update itself with the original files (otherwise it will continue to use the cached versions, regardless of how many times you restore the originals)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!


Return to “Mods”

Who is online

Users browsing this forum: No registered users and 2 guests