Просмотр исходного кода

#40
- some fixes & enhancements
- links in studio
- tests for DNSBL

Alex Trofimov 12 лет назад
Родитель
Сommit
adf728fa34

+ 1 - 1
inc/classes/BxDolDb.php

@@ -734,7 +734,7 @@ EOJ;
             elseif (is_numeric($mixedArg))
                 $s = $mixedArg;
             else
-                $s = "'" . mysql_real_escape_string($mixedArg, $this->link) . "'";
+                $s = "'" . mysql_real_escape_string($mixedArg) . "'";
 
             $i = bx_mb_strpos($sQuery, '?', $iPos);
             $sQuery = bx_mb_substr_replace($sQuery, $s, $i, 1);

+ 2 - 1
modules/boonex/antispam/classes/BxAntispamDNSBlacklists.php

@@ -89,9 +89,10 @@ class BxAntispamDNSBlacklists extends BxDol
 
     public function getRules ($aChains)
     {
+        bx_import('BxDolLanguages');
         $oDb = BxDolDb::getInstance();
         $sChains = $oDb->implode_escape($aChains);
-        $a = $oDb->getAll("SELECT * FROM `bx_antispam_dnsbl_rules` WHERE `chain` IN($sChains) ORDER BY `chain`, `added`");
+        $a = $oDb->getAll("SELECT * FROM `bx_antispam_dnsbl_rules` WHERE `chain` IN($sChains) AND `active` = 1 ORDER BY `chain`, `added`");
         foreach ($a as $k => $r) {
             $a[$k]['chain_title'] = _t('_bx_antispam_chain_' . $a[$k]['chain']);
         }

+ 4 - 0
modules/boonex/antispam/classes/BxAntispamStudioPage.php

@@ -22,8 +22,12 @@ class BxAntispamStudioPage extends BxTemplStudioModule
         bx_import('BxDolModule');
         $this->oModule = BxDolModule::getInstance('bx_antispam');
 
+        bx_import('BxDolPermalinks');
+
         $this->aMenuItems = array(
     	    array('name' => 'general', 'icon' => 'cogs', 'title' => '_adm_lmi_cpt_settings'),
+    	    array('name' => 'ip_table', 'icon' => 'align-justify', 'title' => '_bx_antispam_ip_table', 'link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=antispam-ip-table')),
+    	    array('name' => 'dnsbl_list', 'icon' => 'align-justify', 'title' => '_bx_antispam_dnsbl_list', 'link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=antispam-dnsbl-list')),
         );
     }
 

+ 3 - 1
modules/boonex/antispam/install/langs/en.xml

@@ -20,6 +20,8 @@ This antispam method scan submitted content for the URLs and check them if any o
     <string name="_bx_antispam_submit_false_positive_report"><![CDATA[If you believe that this is a mistake, please submit a false positive report here: {0}]]></string>
 	<string name="_bx_antispam_ip_allow"><![CDATA[Allow]]></string>
 	<string name="_bx_antispam_ip_deny"><![CDATA[Deny]]></string>
+	<string name="_bx_antispam_ip_table"><![CDATA[IP table]]></string>
+	<string name="_bx_antispam_dnsbl_list"><![CDATA[DNSBL list]]></string>
 	<string name="_bx_antispam_chain_whitelist"><![CDATA[IP whitelist]]></string>
 	<string name="_bx_antispam_chain_spammers"><![CDATA[IP blacklist]]></string>
 	<string name="_bx_antispam_chain_uridns"><![CDATA[Spam text]]></string>
@@ -27,7 +29,7 @@ This antispam method scan submitted content for the URLs and check them if any o
 	<string name="_bx_antispam_rule_note_spamhaus_org"><![CDATA[Detect spammer IPs]]></string>
 	<string name="_bx_antispam_rule_note_zomgbl_spameatingmonkey_net"><![CDATA[Everything is blacklisted, <u>use it only if something is whitelisted!</u>]]></string>
 	<string name="_bx_antispam_rule_note_surbl_org"><![CDATA[Detect spammer URLs from SURBLs (lists of web sites that have appeared in unsolicited messages)]]></string>
-	<string name="_bx_antispam_rule_note_opm_tornevall_org"><![CDATA[Detect anonymous/elite proxies and abuse IPs]]></string>
+	<string name="_bx_antispam_rule_note_dnsbl_tornevall_org"><![CDATA[Detect anonymous/elite proxies and abuse IPs]]></string>
 	<string name="_bx_antispam_dnsbl"><![CDATA[DNSBL]]></string>
 	<string name="_bx_antispam_uri_dnsbl"><![CDATA[URI DNSBL]]></string>
 	<string name="_bx_antispam_type_dnsbl"><![CDATA[DNSBL]]></string>

+ 1 - 1
modules/boonex/antispam/install/sql/enable.sql

@@ -44,7 +44,7 @@ INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbo
 -- grid: DNSBL
 
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
-('bx_antispam_grid_dnsbl', 'Sql', 'SELECT `id`, `chain`, `zonedomain`, `postvresp`, `url`, `recheck`, `comment`, `added`, `active` FROM `bx_antispam_dnsbl_rules`', 'bx_antispam_dnsbl_rules', 'id', 'added', 'active', '', 16, NULL, 'start', '', 'chain,zonedomain,url,recheck', 'comment', 'auto', 'chain', 'comment', 64, 'BxAntispamGridDNSBL', 'modules/boonex/antispam/classes/BxAntispamGridDNSBL.php');
+('bx_antispam_grid_dnsbl', 'Sql', 'SELECT `id`, `chain`, `zonedomain`, `postvresp`, `url`, `recheck`, `comment`, `added`, `active` FROM `bx_antispam_dnsbl_rules`', 'bx_antispam_dnsbl_rules', 'id', 'added', 'active', '', 16, NULL, 'start', '', 'chain,zonedomain,url,recheck', 'comment', 'auto', 'chain,zonedomain', 'comment', 64, 'BxAntispamGridDNSBL', 'modules/boonex/antispam/classes/BxAntispamGridDNSBL.php');
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable`, `chars_limit`, `params`, `order`) VALUES
 ('bx_antispam_grid_dnsbl', 'switcher', '_sys_active', '10%', 0, 0, '', 1),

+ 1 - 1
modules/boonex/antispam/install/sql/install.sql

@@ -27,7 +27,7 @@ CREATE TABLE `bx_antispam_dnsbl_rules` (
 
 INSERT INTO `bx_antispam_dnsbl_rules` (`chain`, `zonedomain`, `postvresp`, `url`, `recheck`, `comment`, `added`, `active`) VALUES
 ('spammers', 'sbl.spamhaus.org.', 'any', 'http://www.spamhaus.org/sbl/', 'http://www.spamhaus.org/query/bl?ip=%s', '_bx_antispam_rule_note_spamhaus_org', 0, 1),
-('spammers', 'opm.tornevall.org.', '230', 'http://dnsbl.tornevall.org/', '', '_bx_antispam_rule_note_opm_tornevall_org', 0, 0),
+('spammers', 'dnsbl.tornevall.org.', '230', 'http://dnsbl.tornevall.org/', '', '_bx_antispam_rule_note_dnsbl_tornevall_org', 0, 0),
 ('uridns', 'multi.surbl.org.', 'any', 'http://www.surbl.org/', 'http://george.surbl.org/lookup.html', '_bx_antispam_rule_note_surbl_org', 0, 1),
 ('spammers', 'zomgbl.spameatingmonkey.net.', 'any', 'http://spameatingmonkey.com/index.html', '', '_bx_antispam_rule_note_zomgbl_spameatingmonkey_net', 0, 0);
 

+ 1 - 1
studio/template/scripts/BxBaseStudioModule.php

@@ -57,7 +57,7 @@ class BxBaseStudioModule extends BxDolStudioModule {
             $aMenu[] = array(
                 'name' => $aItem['name'],
                 'icon' => $aItem['icon'],
-            	'link' => BX_DOL_URL_STUDIO . 'module.php?name=' . $this->sModule . '&page=' . $aItem['name'],
+            	'link' => isset($aItem['link'])  ? $aItem['link'] : BX_DOL_URL_STUDIO . 'module.php?name=' . $this->sModule . '&page=' . $aItem['name'],
             	'title' => _t($aItem['title']),
             	'selected' => $aItem['name'] == $this->sPage
             );

+ 54 - 0
tests/units/modules/boonex/antispam/classes/BxAntispamDNSBlacklistsTest.php

@@ -0,0 +1,54 @@
+<?php
+
+bx_import('BxDolModule');
+$oModule = BxDolModule::getInstance('bx_antispam');
+bx_import('DNSBlacklists', $oModule->_aModule);
+
+/**
+ * Test DNSURI black lists in Antispam module
+ */
+class BxAntispamDNSBlacklistsTest extends BxDolTestCase
+{
+    protected $_oDNSBlacklists;
+
+    protected function setUp()
+    {
+        $oModule = BxDolModule::getInstance('bx_antispam');
+        $this->_oDNSBlacklists = bx_instance('BxAntispamDNSBlacklists', array(), $oModule->_aModule);
+    }
+
+    protected function tearDown()
+    {
+        unset($this->_oDNSBlacklists);
+    }
+
+    public function providerForIsSpam()
+    {
+        // it is assumed that sbl.spamhaus.org. rule is enabled
+        return array(
+            array(BX_DOL_DNSBL_CHAIN_SPAMMERS, '127.0.0.1', BX_DOL_DNSBL_NEGATIVE), // 127.0.0.1 is always NOT listed 
+            array(BX_DOL_DNSBL_CHAIN_SPAMMERS, '127.0.0.2', BX_DOL_DNSBL_POSITIVE), // 127.0.0.2 is always listed 
+        );
+    }
+
+    /**
+     * @dataProvider providerForIsSpam
+     */
+    public function test_dnsbl_lookup_ip($mixedChain, $sIp, $bRes)
+    {
+        if (!$this->isSpamhaus())
+            $this->markTestSkipped('sbl.spamhaus.org is not enabled.');
+        else        
+            $this->assertEquals($bRes, $this->_oDNSBlacklists->dnsbl_lookup_ip($mixedChain, $sIp));
+    }
+
+    protected function isSpamhaus() 
+    {
+        $aRules = $this->_oDNSBlacklists->getRules(array(BX_DOL_DNSBL_CHAIN_SPAMMERS));
+        foreach ($aRules as $aRule)
+            if ('sbl.spamhaus.org.' == $aRule['zonedomain'])
+                return true;
+        return false;
+    }
+}
+

+ 17 - 3
tests/units/modules/boonex/antispam/classes/BxAntispamDNSURIBlacklistsTest.php

@@ -5,24 +5,27 @@
  */
 class BxAntispamDNSURIBlacklistsTest extends BxDolTestCase
 {
+    protected $_oDNSBlacklists;
     protected $_oDNSURIBlacklists;
-    
 
     protected function setUp()
     {
         bx_import('BxDolModule');
         $oModule = BxDolModule::getInstance('bx_antispam');
 
+        $this->_oDNSBlacklists = bx_instance('BxAntispamDNSBlacklists', array(), $oModule->_aModule);
         $this->_oDNSURIBlacklists = bx_instance('BxAntispamDNSURIBlacklists', array(), $oModule->_aModule);
     }
 
     protected function tearDown()
     {
+        unset($this->_oDNSBlacklists);
         unset($this->_oDNSURIBlacklists);
     }
 
     public function providerForIsSpam()
     {
+        // it is assumed that multi.surbl.org. rule is enabled
         return array(
             array("some text without urls", false), // no spam detection in text without urls
             array("Hello. \nDolphin lives on http://www.boonex.com site", false), // no spam for good urls
@@ -41,8 +44,19 @@ class BxAntispamDNSURIBlacklistsTest extends BxDolTestCase
      */
     public function testIsSpam($sText, $bRes)
     {
-        // check result boolean value
-        $this->assertEquals($bRes, $this->_oDNSURIBlacklists->isSpam($sText));
+        if (!$this->isSurbl())
+            $this->markTestSkipped('multi.surbl.org is not enabled.');
+        else        
+            $this->assertEquals($bRes, $this->_oDNSURIBlacklists->isSpam($sText));
+    }
+
+    protected function isSurbl() 
+    {
+        $aRules = $this->_oDNSBlacklists->getRules(array(BX_DOL_DNSBL_CHAIN_URIDNS));
+        foreach ($aRules as $aRule)
+            if ('multi.surbl.org.' == $aRule['zonedomain'])
+                return true;
+        return false;
     }
 }