[geeklog-hg] geeklog: Updated SFS module of SPAM-X to check IP of post. Added...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sat Feb 1 17:19:03 EST 2014
changeset 9462:a1d813d30d1b
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/a1d813d30d1b
user: Tom <websitemaster at cogeco.net>
date: Sat Feb 01 17:18:18 2014 -0500
description:
Updated SFS module of SPAM-X to check IP of post. Added the ability to delete old spam-x records based on date last updated. Added SFS confidence score.
diffstat:
plugins/spamx/BaseAdmin.class.php | 3 +-
plugins/spamx/SFS.Examine.class.php | 57 +++++++++++++
plugins/spamx/SFS.Misc.class.php | 52 +++++++----
plugins/spamx/SFSbase.class.php | 124 +++++++++++++++++++++++++++++
plugins/spamx/SFSreport.Action.class.php | 62 ++++++++++++++
plugins/spamx/configuration_validation.php | 2 +
plugins/spamx/functions.inc | 18 +++-
plugins/spamx/install_defaults.php | 15 +++-
plugins/spamx/install_updates.php | 20 ++++
plugins/spamx/language/english.php | 2 +
plugins/spamx/language/english_utf-8.php | 4 +-
public_html/docs/english/spamx.html | 16 +++-
public_html/docs/japanese/spamx.html | 16 +++-
13 files changed, 361 insertions(+), 30 deletions(-)
diffs (truncated from 611 to 300 lines):
diff -r 76d966a028f5 -r a1d813d30d1b plugins/spamx/BaseAdmin.class.php
--- a/plugins/spamx/BaseAdmin.class.php Sat Feb 01 11:00:12 2014 +0900
+++ b/plugins/spamx/BaseAdmin.class.php Sat Feb 01 17:18:18 2014 -0500
@@ -123,7 +123,8 @@
if (!empty($entry)) {
$entry = str_replace(' ', '', $entry);
$entry = DB_escapeString($entry);
- $retval = DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('{$this->moduleName}', '{$entry}', 0, '0000-00-00 00:00:00')");
+ $timestamp = DB_escapeString(date('Y-m-d H:i:s'));
+ $retval = DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('{$this->moduleName}', '{$entry}', 0, '$timestamp')");
}
return $retval;
diff -r 76d966a028f5 -r a1d813d30d1b plugins/spamx/SFS.Examine.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/spamx/SFS.Examine.class.php Sat Feb 01 17:18:18 2014 -0500
@@ -0,0 +1,57 @@
+<?php
+
+/**
+* File: SFS.Examine.class.php
+* This is the Stop Forum Spam Examine class for the Geeklog Spam-X plugin
+*
+* Copyright (C) 2014 Tom Homer - WebSiteMaster AT cogeco DOT com
+*
+* Licensed under the GNU General Public License
+*
+*
+*/
+
+if (strpos ($_SERVER['PHP_SELF'], 'SFS.Examine.class.php') !== false) {
+ die ('This file can not be used on its own!');
+}
+
+/**
+* Include Base Classes
+*/
+require_once ($_CONF['path'] . 'plugins/spamx/' . 'BaseCommand.class.php');
+require_once ($_CONF['path'] . 'plugins/spamx/' . 'SFSbase.class.php');
+
+/**
+* Checks number of links in post.
+*
+* based in large part on the works of Dirk Haun, Tom Willet (Spam-X) and Russ Jones (SLV)
+*/
+
+class SFS extends BaseCommand
+{
+ /**
+ * Here we do the work
+ */
+ public function execute($comment)
+ {
+ global $LANG_SX00;
+
+ $ans = PLG_SPAM_NOT_FOUND;
+ $uid = $this->getUid();
+
+ $SFS = new SFSbase();
+ if ($SFS->CheckForSpam($comment)) {
+ $ans = PLG_SPAM_FOUND;
+ SPAMX_log($LANG_SX00['foundspam'] . 'Stop Forum Spam (SFS)'.
+ $LANG_SX00['foundspam2'] . $uid .
+ $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
+ }
+
+ // tell the Action module that we've already been triggered
+ $GLOBALS['SFS_triggered'] = true;
+
+ return $ans;
+ }
+}
+
+?>
diff -r 76d966a028f5 -r a1d813d30d1b plugins/spamx/SFS.Misc.class.php
--- a/plugins/spamx/SFS.Misc.class.php Sat Feb 01 11:00:12 2014 +0900
+++ b/plugins/spamx/SFS.Misc.class.php Sat Feb 01 17:18:18 2014 -0500
@@ -64,6 +64,14 @@
if (!$_SPX_CONF['sfs_enabled']) {
return PLG_SPAM_NOT_FOUND; // invalid data, assume ok
}
+
+ if (!$_SPX_CONF['sfs_confidence']) {
+ $_SPX_CONF['sfs_enabled'] = 25;
+ }
+
+ if (!isset($_SPX_CONF['timeout'])) {
+ $_SPX_CONF['timeout'] = 5; // seconds
+ }
$db_email = DB_escapeString($email);
$db_ip = DB_escapeString($ip);
@@ -74,20 +82,17 @@
OR name='email' AND value='$db_email'", 1);
if (DB_numRows($result) > 0) {
list ($name, $value) = DB_fetchArray($result);
- DB_query("UPDATE {$_TABLES['spamx']} SET counter = counter + 1 WHERE name='" . DB_escapeString($name) . "' AND value='" . DB_escapeString($value) . "'", 1);
+ $timestamp = DB_escapeString(date('Y-m-d H:i:s'));
+ DB_query("UPDATE {$_TABLES['spamx']} SET counter = counter + 1, regdate = '$timestamp' WHERE name='" . DB_escapeString($name) . "' AND value='" . DB_escapeString($value) . "'", 1);
return PLG_SPAM_FOUND;
}
-
+
$em = urlencode($email);
$query = "http://www.stopforumspam.com/api?f=serial&email=$em";
if (!empty($ip)) {
$query .= "&ip=$ip";
}
- if (!isset($_SPX_CONF['timeout'])) {
- $_SPX_CONF['timeout'] = 5; // seconds
- }
-
require_once 'HTTP/Request.php';
$req = new HTTP_Request(
@@ -119,28 +124,37 @@
}
} else {
return PLG_SPAM_NOT_FOUND; // PEAR Error, assume ok
- }
+ }
- if ($result['email']['appears'] == 1) {
- $value_arr[] = "('email', '$db_email')";
- }
-
- if ($result['ip']['appears'] == 1) {
- $value_arr[] = "('IP', '$db_ip')";
- }
-
- if (!empty($value_arr)) {
+ if (!$result) return PLG_SPAM_NOT_FOUND; // invalid data, assume ok
+
+ if (
+ (isset($result['email']) && $result['email']['appears'] == 1 && $result['email']['confidence'] > (float) $_SPX_CONF['sfs_confidence'] ) ||
+ ($result['ip']['appears'] == 1 && $result['ip']['confidence'] > (float) $_SPX_CONF['sfs_confidence'] )
+ ) {
+ $timestamp = DB_escapeString(date('Y-m-d H:i:s'));
+ if (isset($result['email']) && $result['email']['appears'] == 1 && $result['email']['confidence'] > (float) $_SPX_CONF['sfs_confidence'] ) {
+ $value_arr[] = "('email', '$db_email', '$timestamp')";
+ }
+ if ($result['ip']['appears'] == 1 && $result['ip']['confidence'] > (float) $_SPX_CONF['sfs_confidence'] ) {
+ $value_arr[] = "('IP', '$db_ip', '$timestamp')";
+ }
$values = implode(',', $value_arr);
- $sql = "INSERT INTO {$_TABLES['spamx']} (name, value)
+ $sql = "INSERT INTO {$_TABLES['spamx']} (name, value, regdate)
VALUES $values";
DB_query($sql);
$log_msg = sprintf($LANG_SX00['email_ip_spam'], $email, $ip);
SPAMX_log($log_msg);
-
+
return PLG_SPAM_FOUND;
+ } else {
+ if ($this->_verbose) {
+ SPAMX_log ("SFS: spammer IP not detected: " . $ip . " Spammer email not detected: " . $email);
+ }
}
-
+
+ // Passed the checks
return PLG_SPAM_NOT_FOUND;
}
}
diff -r 76d966a028f5 -r a1d813d30d1b plugins/spamx/SFSbase.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/spamx/SFSbase.class.php Sat Feb 01 17:18:18 2014 -0500
@@ -0,0 +1,124 @@
+<?php
+
+/**
+* File: SFSbase.class.php
+* Stop Forum Spam (SFS) Base Class
+*
+* Copyright (C) 2014 Tom Homer - WebSiteMaster AT cogeco DOT com
+*
+* Licensed under the GNU General Public License
+*
+*
+*/
+
+if (strpos ($_SERVER['PHP_SELF'], 'SFSbase.class.php') !== false) {
+ die ('This file can not be used on its own!');
+}
+
+/**
+* Checks number of links in post.
+*
+* based in large part on the works of Dirk Haun, Tom Willet (Spam-X) and Russ Jones (SLV)
+*/
+
+class SFSbase
+{
+ private $_debug = false;
+ private $_verbose = false;
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->_debug = false;
+ $this->_verbose = false;
+ }
+
+ /**
+ * Check if spam IP
+ *
+ * @param string $post post to check for spam
+ * @return boolean true = spam found, false = no spam
+ *
+ * Note: Also returns 'false' in case of problems communicating with SFS.
+ * Error messages are logged in Geeklog's error.log
+ *
+ */
+ function CheckForSpam ($post)
+ {
+ global $_SPX_CONF, $REMOTE_ADDR;
+
+ if (!isset($_SPX_CONF['sfs_enabled'])) {
+ $_SPX_CONF['sfs_enabled'] = false;
+ }
+
+ if (!$_SPX_CONF['sfs_enabled']) {
+ return PLG_SPAM_NOT_FOUND; // invalid data, assume ok
+ }
+
+ if (!$_SPX_CONF['sfs_confidence']) {
+ $_SPX_CONF['sfs_enabled'] = 25;
+ }
+
+ if (!isset($_SPX_CONF['timeout'])) {
+ $_SPX_CONF['timeout'] = 5; // seconds
+ }
+
+
+ $ip = $REMOTE_ADDR;
+ $query = "http://www.stopforumspam.com/api?f=serial&ip=$ip";
+
+ require_once 'HTTP/Request.php';
+
+ $req = new HTTP_Request(
+ $query,
+ array(
+ 'timeout' => $_SPX_CONF['timeout'],
+ )
+ );
+
+ if ($this->_verbose) {
+ SPAMX_log('Sending to SFS: ' . $query);
+ }
+
+ if ($req->sendRequest() === TRUE) {
+ $result = $req->getResponseBody();
+
+ if ($result === FALSE) {
+ return PLG_SPAM_NOT_FOUND; // Response body is not set, assume ok
+ }
+
+ $result = unserialize($result);
+
+ if (!$result) {
+ if ($this->_verbose) {
+ SPAMX_log ("SFS: no spam detected");
+ }
+
+ return PLG_SPAM_NOT_FOUND; // Invalid data, assume ok
+ }
+ } else {
+ return PLG_SPAM_NOT_FOUND; // PEAR Error, assume ok
+ }
+
+ if (!$result) return PLG_SPAM_NOT_FOUND; // invalid data, assume ok
+
+ if ($result['ip']['appears'] == 1 && $result['ip']['confidence'] > (float) $_SPX_CONF['sfs_confidence'] ) {
+ $retval = PLG_SPAM_FOUND;
+ SPAMX_log ("SFS: spammer IP detected: " . $ip);
+
+ // Add IP to SFS IP list... assuming sfs runs after ip check so no dups
+ $db_ip = DB_escapeString($ip);
+ $sql = "INSERT INTO {$_TABLES['spamx']} (name, value, regdate)
+ VALUES ('IP', '$db_ip', '$timestamp')";
+ DB_query($sql);
+ } else if ($this->_verbose) {
+ SPAMX_log ("SFS: spammer IP not detected: " . $ip);
+ }
+
+ return $retval;
+ }
+}
+
+?>
diff -r 76d966a028f5 -r a1d813d30d1b plugins/spamx/SFSreport.Action.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/spamx/SFSreport.Action.class.php Sat Feb 01 17:18:18 2014 -0500
@@ -0,0 +1,62 @@
+<?php
More information about the geeklog-cvs
mailing list