Permalink
Browse files

Made thresholds configurable

1 parent 570c449 commit 414cac700c9f6c7be42fe1fddfc1169ac7fcb7dd @splitbrain committed Jun 2, 2011
Showing with 123 additions and 7 deletions.
  1. +1 −1 README
  2. +24 −0 stopforumspam.en.php
  3. +98 −6 stopforumspam.php
View
2 README
@@ -7,7 +7,7 @@ by http://www.stopforumspam.com
If a match was found, the user registration will be denied. Denials are
logged in the standard UNB log.
-To install copy the stopforumspam.php into your unb_lib/plugins folder.
+To install copy the stopforumspam.* files into your unb_lib/plugins folder.
----
View
@@ -0,0 +1,24 @@
+<?php
+// Language : English (en)
+// Encoding : UTF-8 (without BOM) (auto-detect: A°A°A°A°A°)
+// Author : Andreas Gohr <andi@splitbrain.org>
+// Reference: none (primary translation)
+//
+// See this web page for information on how to edit this file:
+// http://newsboard.unclassified.de/devel/docs/translating
+
+$UNB_T['stopforumspam config email days label'] = 'Maximum age for email checks';
+$UNB_T['stopforumspam config email days desc'] = 'Set to the number of days within the checked email has to be been last reported to be blocked as a spammer. Set 0 to disable email checks.';
+$UNB_T['stopforumspam config email freq label'] = 'Minimum frequency for email checks';
+$UNB_T['stopforumspam config email freq desc'] = 'Set the minimum number of times an email has to be been reported to be blocked as a spammer.';
+
+$UNB_T['stopforumspam config ip days label'] = 'Maximum age for IP checks';
+$UNB_T['stopforumspam config ip days desc'] = 'Set to the number of days within the checked IP address has to be been last reported to be blocked as a spammer. Set 0 to disable IP checks.';
+$UNB_T['stopforumspam config ip freq label'] = 'Minimum frequency for IP checks';
+$UNB_T['stopforumspam config ip freq desc'] = 'Set the minimum number of times an IP Address has to be been reported to be blocked as a spammer.';
+
+$UNB_T['stopforumspam config user days label'] = 'Maximum age for username checks';
+$UNB_T['stopforumspam config user days desc'] = 'Set to the number of days within the checked username has to be been last reported to be blocked as a spammer. Set 0 to disable username checks.';
+$UNB_T['stopforumspam config user freq label'] = 'Minimum frequency for username checks';
+$UNB_T['stopforumspam config user freq desc'] = 'Set the minimum number of times an username has to be been reported to be blocked as a spammer.';
+
View
@@ -12,9 +12,96 @@
UnbPluginMeta('Andreas Gohr <andi@splitbrain.org>', 'author');
UnbPluginMeta('en', 'lang');
UnbPluginMeta('unb.devel.20110527', 'version');
+UnbPluginMeta('plugin_stopforumspam_config', 'config');
if (!UnbPluginEnabled()) return;
+
+function plugin_stopforumspam_rc($opt,$default=null){
+ $val = rc($opt);
+ if($val !== false && $val !== null) return $val;
+ return $default;
+}
+
+function plugin_stopforumspam_config(&$data) {
+ global $UNB;
+
+ // setup config fields
+ if ($data['request'] == 'fields') {
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_email_days',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_email_days',30),
+ 'fieldlabel' => 'stopforumspam config email days label',
+ 'fielddesc' => 'stopforumspam config email days desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_email_freq',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_email_freq',1),
+ 'fieldlabel' => 'stopforumspam config email freq label',
+ 'fielddesc' => 'stopforumspam config email freq desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_ip_days',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_ip_days',30),
+ 'fieldlabel' => 'stopforumspam config ip days label',
+ 'fielddesc' => 'stopforumspam config ip days desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_ip_freq',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_ip_freq',1),
+ 'fieldlabel' => 'stopforumspam config ip freq label',
+ 'fielddesc' => 'stopforumspam config ip freq desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_user_days',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_user_days',30),
+ 'fieldlabel' => 'stopforumspam config user days label',
+ 'fielddesc' => 'stopforumspam config user days desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+ $data['fields'][] = array(
+ 'fieldtype' => 'text',
+ 'fieldname' => 'sfs_user_freq',
+ 'fieldvalue' => plugin_stopforumspam_rc('sfs_user_freq',1),
+ 'fieldlabel' => 'stopforumspam config user freq label',
+ 'fielddesc' => 'stopforumspam config user freq desc',
+ 'fieldsize' => 3,
+ 'fieldlength' => 3,
+ );
+
+ }
+
+ // save config data
+ if ($data['request'] == 'handleform') {
+ $UNB['ConfigFile']['sfs_email_days'] = (int) $_POST['sfs_email_days'];
+ $UNB['ConfigFile']['sfs_email_freq'] = (int) $_POST['sfs_email_freq'];
+ $UNB['ConfigFile']['sfs_ip_days'] = (int) $_POST['sfs_ip_days'];
+ $UNB['ConfigFile']['sfs_ip_freq'] = (int) $_POST['sfs_ip_freq'];
+ $UNB['ConfigFile']['sfs_user_days'] = (int) $_POST['sfs_user_days'];
+ $UNB['ConfigFile']['sfs_user_freq'] = (int) $_POST['sfs_user_freq'];
+
+ $data['result'] = true;
+ }
+
+ return true;
+}
+
function plugin_stopforumspam_hook(&$data) {
global $UNB;
@@ -34,23 +121,28 @@ function plugin_stopforumspam_hook(&$data) {
}
if(!$resp['success']) return;
- // only consider data of last 30 days
- $tresh = time() - 60*60*24*30;
-
+ // check email
+ if($resp['email']['lastseen'] >= (time()-(60*60*24*plugin_stopforumspam_rc('sfs_email_days',30))) &&
+ $resp['email']['frequency'] >= plugin_stopforumspam_rc('sfs_email_freq',1) ){
- if($resp['email']['lastseen'] > $tresh){
UnbAddLog('stopforumspam: user registration blocked by email: '.$data['email']);
$data['error'] = 'Sorry, you seem to be a spammer.';
return;
}
- if($resp['username']['lastseen'] > $tresh){
+ // check username
+ if($resp['username']['lastseen'] >= (time()-(60*60*24*plugin_stopforumspam_rc('sfs_user_days',30))) &&
+ $resp['username']['frequency'] >= plugin_stopforumspam_rc('sfs_user_freq',1) ){
+
UnbAddLog('stopforumspam: user registration blocked by username: '.$data['username']);
$data['error'] = 'Sorry, you seem to be a spammer.';
return;
}
- if($resp['ip']['lastseen'] > $tresh){
+ // check ip address
+ if($resp['ip']['lastseen'] >= (time()-(60*60*24*plugin_stopforumspam_rc('sfs_ip_days',30))) &&
+ $resp['ip']['frequency'] >= plugin_stopforumspam_rc('sfs_ip_freq',1) ){
+
UnbAddLog('stopforumspam: user registration blocked by ip: '.$_SERVER['REMOTE_ADDR']);
$data['error'] = 'Sorry, you seem to be a spammer.';
return;

0 comments on commit 414cac7

Please sign in to comment.