[geeklog-cvs] geeklog-1.3/plugins/spamx BlackList.Examine.class.php,1.7,1.8 DeleteComment.Action.class.php,1.2,1.3 IP.Examine.class.php,1.2,1.3 IPofUrl.Examine.class.php,1.2,1.3 MTBlackList.Examine.class.php,1.7,1.8 MailAdmin.Action.class.php,1.8,1.9 config.php,1.6,1.7 functions.inc,1.5,1.6

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Tue Mar 29 11:48:53 EST 2005


Update of /var/cvs/geeklog-1.3/plugins/spamx
In directory www:/tmp/cvs-serv1117/plugins/spamx

Modified Files:
	BlackList.Examine.class.php DeleteComment.Action.class.php 
	IP.Examine.class.php IPofUrl.Examine.class.php 
	MTBlackList.Examine.class.php MailAdmin.Action.class.php 
	config.php functions.inc 
Log Message:
Varios minor changes: Check blacklists case-insensitive, added simple statistics, upgrade function.


Index: IP.Examine.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/IP.Examine.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** IP.Examine.class.php	5 Feb 2005 13:13:36 -0000	1.2
--- IP.Examine.class.php	29 Mar 2005 16:48:51 -0000	1.3
***************
*** 32,48 ****
          global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
  
          /**
           * Include Blacklist Data
           */
!         $result = DB_query("SELECT * FROM {$_TABLES['spamx']} WHERE name='IP'", 1);
          $nrows = DB_numRows($result);
  
          $ans = 0;
!         for($i = 1;$i <= $nrows;$i++) {
!             $A = DB_fetchArray($result);
!             $val = $A['value'];
              if ($val = $_SERVER['REMOTE_ADDR']) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log($LANG_SX00['foundspam'] . $val . $LANG_SX00['foundspam2'] . $_USER['uid'] . $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
              }
--- 32,55 ----
          global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
  
+         if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
+             $uid = $_USER['uid'];
+         } else {
+             $uid = 1;
+         }
+ 
          /**
           * Include Blacklist Data
           */
!         $result = DB_query("SELECT value FROM {$_TABLES['spamx']} WHERE name='IP'", 1);
          $nrows = DB_numRows($result);
  
          $ans = 0;
!         for ($i = 1; $i <= $nrows; $i++) {
!             list ($val) = DB_fetchArray ($result);
              if ($val = $_SERVER['REMOTE_ADDR']) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log ($LANG_SX00['foundspam'] . $val .
!                            $LANG_SX00['foundspam2'] . $uid . 
!                            $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
              }

Index: BlackList.Examine.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/BlackList.Examine.class.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** BlackList.Examine.class.php	24 Mar 2005 13:40:44 -0000	1.7
--- BlackList.Examine.class.php	29 Mar 2005 16:48:50 -0000	1.8
***************
*** 37,43 ****
       * Here we do the work
       */
!     function execute($comment)
      {
!         global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
  
          if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
--- 37,43 ----
       * Here we do the work
       */
!     function execute ($comment)
      {
!         global $_CONF, $_TABLES, $_USER, $LANG_SX00;
  
          if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
***************
*** 50,69 ****
           * Include Blacklist Data
           */
!         $result = DB_query("SELECT * FROM {$_TABLES['spamx']} WHERE name='Personal'", 1);
!         $nrows = DB_numRows($result);
  
          $ans = 0;
!         for($i = 1;$i <= $nrows;$i++) {
!             $A = DB_fetchArray($result);
!             $val = $A['value'];
!             if (preg_match("#$val#", html_entity_decode ($comment))) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log($LANG_SX00['foundspam'] . $val . $LANG_SX00['foundspam2'] . $uid . $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
!             } 
!         } 
          return $ans;
!     } 
! } 
  
  ?>
--- 50,70 ----
           * Include Blacklist Data
           */
!         $result = DB_query ("SELECT value FROM {$_TABLES['spamx']} WHERE name='Personal'", 1);
!         $nrows = DB_numRows ($result);
  
          $ans = 0;
!         for ($i = 1; $i <= $nrows; $i++) {
!             list ($val) = DB_fetchArray ($result);
!             if (preg_match ("#$val#i", html_entity_decode ($comment))) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log ($LANG_SX00['foundspam'] . $val .
!                            $LANG_SX00['foundspam2'] . $uid .
!                            $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
!             }
!         }
          return $ans;
!     }
! }
  
  ?>

Index: functions.inc
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/functions.inc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** functions.inc	3 Oct 2004 18:40:14 -0000	1.5
--- functions.inc	29 Mar 2005 16:48:51 -0000	1.6
***************
*** 4,9 ****
   * This is the functions.inc for the Geeklog SpamX Plug-in!
   * 
!  * Copyright (C) 2004 by the following authors:
!  * Author		Tom Willett		tomw at pigstye.net
   * 
   * Licensed under GNU General Public License
--- 4,10 ----
   * This is the functions.inc for the Geeklog SpamX Plug-in!
   * 
!  * Copyright (C) 2004-2005 by the following authors:
!  * Authors      Tom Willett     tomw AT pigstye DOT net
!  *              Dirk Haun       dirk AT haun-online DOT de
   * 
   * Licensed under GNU General Public License
***************
*** 25,45 ****
  */
  require_once ($_CONF['path'] . 'plugins/spamx/config.php');
  // +---------------------------------------------------------------------------+
  // | Geeklog Plugin API Implementations                                        |
  // +---------------------------------------------------------------------------+
- /**
-  * Returns the items for this plugin that should appear on the main menu
-  * 
-  * NOTE: this MUST return the url/value pairs in the following format
-  * $<arrayname>[<label>] = <url>
-  * 
-  * Universal Plugin:  Uncomment and fill in variables;
-  * 
-  * @return array Associative array of menu items to be added to menu
-  */
- function plugin_getmenuitems_spamx()
- {
-     return array();
- } 
  
  /**
--- 26,33 ----
  */
  require_once ($_CONF['path'] . 'plugins/spamx/config.php');
+ 
  // +---------------------------------------------------------------------------+
  // | Geeklog Plugin API Implementations                                        |
  // +---------------------------------------------------------------------------+
  
  /**
***************
*** 71,77 ****
  function plugin_showstats_spamx($showsitestats)
  {
      $retval = '';
      return $retval;
! } 
  
  /**
--- 59,114 ----
  function plugin_showstats_spamx($showsitestats)
  {
+     global $_CONF, $_TABLES, $LANG_SX00;
+ 
      $retval = '';
+ 
+     if ($showsitestats == 1) {
+         // overall stats: number of deleted posts
+         $counter = DB_getItem ($_TABLES['vars'], 'value',
+                                                  "name = 'spamx.counter'");
+         $retval = '<table border="0" width="100%" cellspacing="0" cellpadding="0">';
+         $retval .= '<tr><td>' . $LANG_SX00['stats_deleted'] . '</td>';
+         $retval .= '<td align="right">' . $counter . '  </td></tr></table>';
+     } else if (SEC_hasRights('spamx.admin')) {
+         // detailed stats are only visible to SpamX admins
+         $retval .= COM_startBlock ($LANG_SX00['stats_headline']);
+ 
+         $templates = new Template ($_CONF['path_layout'] . 'stats');
+         $templates->set_file (array ('itemstats' => 'itemstatistics.thtml',
+                                      'statrow'   => 'singlestat.thtml'));
+         $templates->set_var ('item_label', $LANG_SX00['stats_page_title']);
+         $templates->set_var ('stat_name', $LANG_SX00['stats_entries']);
+ 
+         // we need a URL - link to the plugin's admin page
+         $templates->set_var ('item_url',
+                 $_CONF['site_admin_url'] . '/plugins/spamx/index.php');
+ 
+         $templates->set_var ('item_text', $LANG_SX00['stats_mtblacklist']);
+         $templates->set_var ('item_stat',
+                 DB_count ($_TABLES['spamx'], 'name', 'MTBlacklist'));
+         $templates->parse ('stat_row', 'statrow', true);
+ 
+         $templates->set_var ('item_text', $LANG_SX00['stats_pblacklist']);
+         $templates->set_var ('item_stat',
+                 DB_count ($_TABLES['spamx'], 'name', 'Personal'));
+         $templates->parse ('stat_row', 'statrow', true);
+ 
+         $templates->set_var ('item_text', $LANG_SX00['stats_ip']);
+         $templates->set_var ('item_stat',
+                 DB_count ($_TABLES['spamx'], 'name', 'IP'));
+         $templates->parse ('stat_row', 'statrow', true);
+ 
+         $templates->set_var ('item_text', $LANG_SX00['stats_ipofurl']);
+         $templates->set_var ('item_stat',
+                 DB_count ($_TABLES['spamx'], 'name', 'IPofUrl'));
+         $templates->parse ('stat_row', 'statrow', true);
+ 
+         $templates->parse ('output', 'itemstats');
+         $retval .= $templates->finish ($templates->get_var ('output'));
+         $retval .= COM_endBlock ();
+     }
+ 
      return $retval;
! }
  
  /**
***************
*** 120,129 ****
   * @return string    plugin version
   */
! function plugin_chkVersion_spamx() {
!     global $_SPX_CONF; 
      return $_SPX_CONF['version'];
  }
  
  /**
   * Actual Plugin Functions here.
   */
--- 157,202 ----
   * @return string    plugin version
   */
! function plugin_chkVersion_spamx ()
! {
!     global $_SPX_CONF;
! 
      return $_SPX_CONF['version'];
  }
  
  /**
+ * Update the SpamX plugin
+ *
+ * @return   int     Number of message to display
+ *
+ */
+ function plugin_upgrade_spamx ()
+ {
+     global $_TABLES, $_SPX_CONF;
+ 
+     $v = DB_getItem ($_TABLES['plugins'], 'pi_version', "pi_name = 'spamx'");
+ 
+     if ($v != $_SPX_CONF['version']) {
+         switch ($v) {
+             case '1.0.1':
+                 // Add the counter
+                 DB_query ("INSERT INTO {$_TABLES['vars']} VALUES ('spamx.counter', '0')");
+                 break;
+         }
+ 
+         // update version number
+         DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_SPX_CONF['version']}' WHERE pi_name = 'spamx'");
+ 
+         // check if version number was updated successfully
+         $v = DB_getItem ($_TABLES['plugins'], 'pi_version', "pi_name = 'spamx'");
+     }
+ 
+     if ($v == $_SPX_CONF['version']) {
+         return 3001;
+     }
+ 
+     return 3002;
+ }
+ 
+ /**
   * Actual Plugin Functions here.
   */

Index: IPofUrl.Examine.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/IPofUrl.Examine.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** IPofUrl.Examine.class.php	20 Feb 2005 09:51:27 -0000	1.2
--- IPofUrl.Examine.class.php	29 Mar 2005 16:48:51 -0000	1.3
***************
*** 41,44 ****
--- 41,50 ----
          global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
  
+         if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
+             $uid = $_USER['uid'];
+         } else {
+             $uid = 1;
+         }
+ 
          /**
           * Check for IP of url in blacklist
***************
*** 48,65 ****
          */
          $regx = '(ftp|http|file)://([^/\\s]+)';
!         $num = preg_match_all("#{$regx}#",html_entity_decode($comment),$urls);
  
!         $result = DB_query("SELECT * FROM {$_TABLES['spamx']} WHERE name='IPofUrl'", 1);
!         $nrows = DB_numRows($result);
  
          $ans = 0;
!         for($j = 1;$j <= $nrows;$j++) {
!             $A = DB_fetchArray($result);
!             $val = $A['value'];
!             for ($i=0;$i<$num;$i++) {
!               $ip = gethostbyname($urls[2][$i]);
                if ($val == $ip) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log($LANG_SX00['foundspam'] . $urls[2][$i] . $LANG_SX00['foundspam2'] . $_USER['uid'] . $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
                }
--- 54,72 ----
          */
          $regx = '(ftp|http|file)://([^/\\s]+)';
!         $num = preg_match_all ("#{$regx}#", html_entity_decode ($comment), $urls);
  
!         $result = DB_query ("SELECT value FROM {$_TABLES['spamx']} WHERE name='IPofUrl'", 1);
!         $nrows = DB_numRows ($result);
  
          $ans = 0;
!         for ($j = 1; $j <= $nrows; $j++) {
!             list ($val) = DB_fetchArray ($result);
!             for ($i = 0; $i < $num; $i++) {
!               $ip = gethostbyname ($urls[2][$i]);
                if ($val == $ip) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log ($LANG_SX00['foundspam'] . $urls[2][$i] .
!                            $LANG_SX00['foundspam2'] . $uid .
!                            $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']);
                  break;
                }

Index: config.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/config.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** config.php	3 Oct 2004 18:30:15 -0000	1.6
--- config.php	29 Mar 2005 16:48:51 -0000	1.7
***************
*** 10,14 ****
   */
  
! $_SPX_CONF['version'] = '1.0.1';
  // Default Spamx Action
  $_SPX_CONF['action'] = 128; // Default is ignore comment
--- 10,15 ----
   */
  
! $_SPX_CONF['version'] = '1.0.2';
! 
  // Default Spamx Action
  $_SPX_CONF['action'] = 128; // Default is ignore comment
***************
*** 16,28 ****
  // URL blacklist changes RSS feed (currently only RSS v1.0 is supported)
  $_SPX_CONF['rss_url'] = 'http://www.jayallen.org/comment_spam/feeds/blacklist-changes.rdf';
  // Entire MT-Blacklist (for inital import)
  $_SPX_CONF['mtblacklist_url'] = 'http://www.jayallen.org/comment_spam/blacklist.txt';
  // SpamX urls
  $_SPX_CONF['spamx_rss_url'] = 'http://www.pigstye.net/backend/spamx_users.rdf';
  $_SPX_CONF['spamx_submit_url'] = 'http://www.pigstye.net/gplugs/spamx/submit.php';
  // address which mail admin module will use
  $_SPX_CONF['notification_email'] = $_CONF['site_mail'];
! // This sets Ban Plugin Table Prefix the Same as Geeklog
  $_SPX_table_prefix = $_DB_table_prefix;
  // DO NOT CHANGE THE STUFF BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
  // Add SpamX Plugin table to $_TABLES array
--- 17,34 ----
  // URL blacklist changes RSS feed (currently only RSS v1.0 is supported)
  $_SPX_CONF['rss_url'] = 'http://www.jayallen.org/comment_spam/feeds/blacklist-changes.rdf';
+ 
  // Entire MT-Blacklist (for inital import)
  $_SPX_CONF['mtblacklist_url'] = 'http://www.jayallen.org/comment_spam/blacklist.txt';
+ 
  // SpamX urls
  $_SPX_CONF['spamx_rss_url'] = 'http://www.pigstye.net/backend/spamx_users.rdf';
  $_SPX_CONF['spamx_submit_url'] = 'http://www.pigstye.net/gplugs/spamx/submit.php';
+ 
  // address which mail admin module will use
  $_SPX_CONF['notification_email'] = $_CONF['site_mail'];
! 
! // This sets SpamX Plugin Table Prefix the Same as Geeklog
  $_SPX_table_prefix = $_DB_table_prefix;
+ 
  // DO NOT CHANGE THE STUFF BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
  // Add SpamX Plugin table to $_TABLES array

Index: MailAdmin.Action.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/MailAdmin.Action.class.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** MailAdmin.Action.class.php	22 Mar 2005 08:59:47 -0000	1.8
--- MailAdmin.Action.class.php	29 Mar 2005 16:48:51 -0000	1.9
***************
*** 44,48 ****
                          $_CONF['site_name'], $uid, $comment);
  
!         $msg .= "\n\nRequest headers:\n";
          if (function_exists ('getallheaders')) {
              $headers = getallheaders ();
--- 44,51 ----
                          $_CONF['site_name'], $uid, $comment);
  
!         // Add headers of the spam post to help track down the source.
!         // Function 'getallheaders' is not available when PHP is running as
!         // CGI. Print the HTTP_... headers from $_SERVER array instead then.
!         $msg .= "\n\n" . $LANG_SX00['headers'] . "\n";
          if (function_exists ('getallheaders')) {
              $headers = getallheaders ();

Index: MTBlackList.Examine.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/MTBlackList.Examine.class.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MTBlackList.Examine.class.php	24 Mar 2005 13:40:44 -0000	1.7
--- MTBlackList.Examine.class.php	29 Mar 2005 16:48:51 -0000	1.8
***************
*** 40,44 ****
       * Here we do the work
       */
!     function execute($comment)
      {
          global $_CONF, $_USER, $_TABLES, $LANG_SX00;
--- 40,44 ----
       * Here we do the work
       */
!     function execute ($comment)
      {
          global $_CONF, $_USER, $_TABLES, $LANG_SX00;
***************
*** 53,66 ****
           * Include Blacklist Data
           */
!         $result = DB_Query("SELECT * FROM {$_TABLES['spamx']} WHERE name='MTBlacklist'", 1);
!         $nrows = DB_numRows($result);
  
!         $ans = 0; //Found Flag
!         for ($i = 1;$i <= $nrows;$i++) {
!             $A = DB_fetchArray($result);
!             $val = $A['value'];
!             if (@preg_match("#$val#", html_entity_decode ($comment))) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log($LANG_SX00['fsc'] . $val . $LANG_SX00['fsc1'] . $uid . $LANG_SX00['fsc2'] . $_SERVER['REMOTE_ADDR']);
                  break;
              } 
--- 53,66 ----
           * Include Blacklist Data
           */
!         $result = DB_Query ("SELECT value FROM {$_TABLES['spamx']} WHERE name = 'MTBlacklist'", 1);
!         $nrows = DB_numRows ($result);
  
!         $ans = 0; // Found Flag
!         for ($i = 1; $i <= $nrows; $i++) {
!             list ($val) = DB_fetchArray ($result);
!             if (@preg_match ("#$val#i", html_entity_decode ($comment))) {
                  $ans = 1; // quit on first positive match
!                 SPAMX_log ($LANG_SX00['fsc'] . $val . $LANG_SX00['fsc1'] .
!                            $uid . $LANG_SX00['fsc2'] . $_SERVER['REMOTE_ADDR']);
                  break;
              } 

Index: DeleteComment.Action.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/plugins/spamx/DeleteComment.Action.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DeleteComment.Action.class.php	3 Oct 2004 18:41:18 -0000	1.2
--- DeleteComment.Action.class.php	29 Mar 2005 16:48:51 -0000	1.3
***************
*** 34,43 ****
      function execute($comment)
      {
!         global $result, $_CONF, $LANG_SX00;
          $result = 128;
          SPAMX_log($LANG_SX00['spamdeleted']);
          return 1;
      } 
  } 
  
! ?>
\ No newline at end of file
--- 34,52 ----
      function execute($comment)
      {
!         global $result, $_CONF, $_TABLES, $LANG_SX00;
          $result = 128;
+ 
+         // update count of deleted spam posts
+         // Yes, there is the possibility of a race condition here. But it's
+         // only for statistical purposes anyway, nothing important ...
+         $counter = DB_getItem ($_TABLES['vars'], 'value', "name = 'spamx.counter'");
+         $counter++;
+         DB_query ("UPDATE {$_TABLES['vars']} SET value = $counter WHERE name = 'spamx.counter'");
+ 
          SPAMX_log($LANG_SX00['spamdeleted']);
+ 
          return 1;
      } 
  } 
  
! ?>




More information about the geeklog-cvs mailing list