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

+ 123 - 4
modules/boonex/antispam/classes/BxAntispamGridDNSBL.php

@@ -25,6 +25,8 @@ class BxAntispamGridDNSBL extends BxTemplGrid
     {
         parent::_addJsCss();
 
+        $this->_oTemplate->addJs('jquery.form.js');
+
         bx_import('BxTemplFormView');
         $oForm = new BxTemplFormView(array());
         $oForm->addCssJs();
@@ -170,10 +172,6 @@ class BxAntispamGridDNSBL extends BxTemplGrid
 
         bx_import('BxTemplFormView');
         $oForm = new BxTemplFormView($aForm);
-        if (!$oForm) {
-            $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
-            exit;
-        }
 
         $s = $oModule->_oTemplate->parseHtmlByName('recheck.html', array (
             'form' => $oForm->getCode(),
@@ -187,12 +185,123 @@ class BxAntispamGridDNSBL extends BxTemplGrid
         $this->_echoResultJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))), true);
     }
 
+    /**
+     * 'recheck' action handler
+     */
+    public function performActionAdd() 
+    {
+        bx_import('BxTemplFormView');
+
+        $aForm = array(
+            'form_attrs' => array(
+                'id' => 'bx_antispam_form_dnsbl_add',
+                'action' => BX_DOL_URL_ROOT . 'grid.php?o=bx_antispam_grid_dnsbl&a=add',
+                'method' => 'post',
+            ),
+            'params' => array (
+                'db' => array(
+                    'table' => 'bx_antispam_dnsbl_rules',
+                    'key' => 'id',
+                    'submit_name' => 'do_submit',
+                ),
+            ),
+            'inputs' => array(
+
+                'country' => array(
+                    'type' => 'select',
+                    'name' => 'country',
+                    'caption' => _t('_bx_antispam_field_country'),
+                    'values' => BxDolForm::getDataItems('Country'),
+                ),
+
+                'chain' => array(
+                    'type' => 'radio_set',
+                    'name' => 'chain',
+                    'caption' => _t('_bx_antispam_field_action'),
+                    'values' => array ('spammers' => _t('_bx_antispam_chain_spammers'), 'whitelist' => _t('_bx_antispam_chain_whitelist')),
+                    'value' => 'spammers',
+                ),
+
+                'submit' => array(
+                    'type' => 'input_set',
+                    0 => array (
+                        'type' => 'submit',
+                        'name' => 'do_submit',
+                        'value' => _t('_sys_submit'),
+                    ),
+                    1 => array (
+                        'type' => 'reset',
+                        'name' => 'close',
+                        'value' => _t('_sys_close'),
+                        'attrs' => array('class' => 'bx-def-margin-sec-left', 'onclick' => '$(\'.bx-popup-applied:visible\').dolPopupHide();'),
+                    ),
+                ),
+
+            ),
+        );
+
+        $oForm = new BxTemplFormView($aForm);
+        $oForm->initChecker();
+
+        if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
+
+            $aCustomValues = array(
+                'chain' => $oForm->getCleanValue('chain'),
+                'zonedomain' => sprintf("%s.countries.nerd.dk.", strtolower($oForm->getCleanValue('country'))),
+                'postvresp' => '127.0.0.2',
+                'url' => 'http://countries.nerd.dk/',
+                'comment' => '_bx_antispam_rule_note_country',
+                'added' => time(),
+                'active' => 1,
+                
+            );
+
+            $iRecentId = $oForm->insert ($aCustomValues, true); // insert new record
+
+            if ($iRecentId)
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $iRecentId); // if record is successfully added, reload grid and highlight added row
+            else
+                $aRes = array('msg' => _t('_sys_txt_error_occured')); // if record adding failed, display error message
+
+            $this->_echoResultJson($aRes, true);
+
+        } else { // if form is not submitted or some fields are invalid, display popup with form
+
+            bx_import('BxTemplFunctions');
+            $s = BxTemplFunctions::getInstance()->popupBox($oForm->getId() . '_form', _t('_bx_antispam_popup_dnsbl_add'), $oForm->getCode() . '
+                <script>
+                    $(document).ready(function () {
+                        $("#' . $oForm->getId() . '").ajaxForm({ 
+                            dataType: "json",
+                            beforeSubmit: function (formData, jqForm, options) {
+                                bx_loading($("#' . $oForm->getId() . '"), true);
+                            },
+                            success: function (data) {
+                                $(".bx-popup-applied:visible").dolPopupHide();
+                                glGrids.' . $this->_sObject . '.processJson(data, "add");
+                            }
+                        });
+                    });
+                </script>');
+
+            $this->_echoResultJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))), true);
+
+        }
+    }
 
     protected function _getCellChain ($mixedValue, $sKey, $aField, $aRow) 
     {
         return parent::_getCellDefault (_t('_bx_antispam_chain_' . $mixedValue), $sKey, $aField, $aRow);
     }
 
+    protected function _getCellZonedomain ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        $s = $mixedValue;
+        if ($aRow['url'])
+            $s = '<a target="_blank" href="' . $aRow['url'] . '">' . $mixedValue . '</a>';
+        return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
+    }
+
     protected function _getCellComment ($mixedValue, $sKey, $aField, $aRow) 
     {
         $sCountry = '';
@@ -204,6 +313,16 @@ class BxAntispamGridDNSBL extends BxTemplGrid
         return parent::_getCellDefault (_t($mixedValue, $sCountry), $sKey, $aField, $aRow);
     }
 
+    protected function _getCellActions ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        if (preg_match('/^(\w{2})\.countries\.nerd\.dk\.$/', $aRow['zonedomain'], $aMatches)) {
+            $aRow['active'] = 1;
+            return parent::_getCellActions ($mixedValue, $sKey, $aField, $aRow);
+        }
+        
+        return parent::_getCellDefault ('', $sKey, $aField, $aRow);
+    }
+
 }
 
 /** @} */

+ 1 - 1
modules/boonex/antispam/classes/BxAntispamGridIpTable.php

@@ -87,7 +87,7 @@ class BxAntispamGridIpTable extends BxTemplGrid
         }
         $oForm->initChecker($aIpTableDirective);
 
-        if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid            
+        if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
 
             $aCustomValues = array(
                 'From' => sprintf("%u", ip2long($oForm->getCleanValue('From'))),

+ 6 - 2
modules/boonex/antispam/install/langs/en.xml

@@ -24,9 +24,10 @@ This antispam method scan submitted content for the URLs and check them if any o
 	<string name="_bx_antispam_chain_spammers"><![CDATA[IP blacklist]]></string>
 	<string name="_bx_antispam_chain_uridns"><![CDATA[Spam text]]></string>
 	<string name="_bx_antispam_rule_note_country"><![CDATA[Country: {0}]]></string>
-	<string name="_bx_antispam_rule_note_spamhaus_org"><![CDATA[Detect spammer IPs from sbl.spamhaus.org]]></string>
-	<string name="_bx_antispam_rule_note_zomgbl_spameatingmonkey_net"><![CDATA[Everything is blacklisted, use only if something is whitelisted]]></string>
+	<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_dnsbl"><![CDATA[DNSBL]]></string>
 	<string name="_bx_antispam_uri_dnsbl"><![CDATA[URI DNSBL]]></string>
 	<string name="_bx_antispam_type_dnsbl"><![CDATA[DNSBL]]></string>
@@ -36,6 +37,7 @@ This antispam method scan submitted content for the URLs and check them if any o
 
 	<string name="_bx_antispam_popup_help"><![CDATA[DNSBL help]]></string>
 	<string name="_bx_antispam_popup_dnsbl_recheck"><![CDATA[Recheck IP/URL in DNSBL/URIDNSBL]]></string>
+	<string name="_bx_antispam_popup_dnsbl_add"><![CDATA[Add country based rule]]></string>
 	<string name="_bx_antispam_popup_block_log"><![CDATA[Block log]]></string>
 
 	<string name="_bx_antispam_page_title_sys_ip_table"><![CDATA[IP table]]></string>
@@ -65,6 +67,8 @@ This antispam method scan submitted content for the URLs and check them if any o
 	<string name="_bx_antispam_field_member_id"><![CDATA[Member]]></string>
 	<string name="_bx_antispam_field_type"><![CDATA[Type]]></string>
 	<string name="_bx_antispam_field_when"><![CDATA[When]]></string>
+	<string name="_bx_antispam_field_country"><![CDATA[Country]]></string>
+	<string name="_bx_antispam_field_zonedomain"><![CDATA[ZONE domain]]></string>
 
     <string name="_bx_antispam_form_ip_table"><![CDATA[IP table directive]]></string>
     <string name="_bx_antispam_form_ip_table_add"><![CDATA[Add IP table directive]]></string>

+ 6 - 2
modules/boonex/antispam/install/sql/enable.sql

@@ -49,12 +49,16 @@ INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `fie
 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),
 ('bx_antispam_grid_dnsbl', 'chain', '_bx_antispam_field_chain', '15%', 0, 0, '', 2),
-('bx_antispam_grid_dnsbl', 'comment', '_bx_antispam_field_note', '75%', 0, 0, '', 3);
+('bx_antispam_grid_dnsbl', 'zonedomain', '_bx_antispam_field_zonedomain', '15%', 0, 0, '', 3),
+('bx_antispam_grid_dnsbl', 'comment', '_bx_antispam_field_note', '55%', 0, 0, '', 4),
+('bx_antispam_grid_dnsbl', 'actions', '_sys_actions', '5%', 0, 0, '', 5);
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 ('bx_antispam_grid_dnsbl', 'independent', 'log', '_bx_antispam_grid_action_log', '', 0, 1),
 ('bx_antispam_grid_dnsbl', 'independent', 'recheck', '_bx_antispam_grid_action_recheck', '', 0, 2),
-('bx_antispam_grid_dnsbl', 'independent', 'help', '_bx_antispam_grid_action_help', '', 0, 3);
+('bx_antispam_grid_dnsbl', 'independent', 'add', '_bx_antispam_grid_action_add', '', 0, 3),
+('bx_antispam_grid_dnsbl', 'independent', 'help', '_bx_antispam_grid_action_help', '', 0, 4),
+('bx_antispam_grid_dnsbl', 'single', 'delete', '', 'remove',  1, 1);
 
 -- grid: ip table
 

+ 4 - 5
modules/boonex/antispam/install/sql/install.sql

@@ -26,11 +26,10 @@ CREATE TABLE `bx_antispam_dnsbl_rules` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 INSERT INTO `bx_antispam_dnsbl_rules` (`chain`, `zonedomain`, `postvresp`, `url`, `recheck`, `comment`, `added`, `active`) VALUES
-('whitelist', 'au.countries.nerd.dk.', '127.0.0.2', 'http://countries.nerd.dk/', '', '_bx_antispam_rule_note_country', 1287642420, 0),
-('spammers', 'cn.countries.nerd.dk.', '127.0.0.2', 'http://countries.nerd.dk/', '', '_bx_antispam_rule_note_country', 1287642420, 0),
-('spammers', 'sbl.spamhaus.org.', 'any', 'http://www.spamhaus.org/sbl/', 'http://www.spamhaus.org/query/bl?ip=%s', '_bx_antispam_rule_note_spamhaus_org', 1287642420, 1),
-('spammers', 'zomgbl.spameatingmonkey.net.', 'any', 'http://spameatingmonkey.com/index.html', '', '_bx_antispam_rule_note_zomgbl_spameatingmonkey_net', 1287642420, 0),
-('uridns', 'multi.surbl.org.', 'any', 'http://www.surbl.org/', 'http://george.surbl.org/lookup.html', '_bx_antispam_rule_note_surbl_org', 1287642420, 1);
+('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),
+('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);
 
 CREATE TABLE `bx_antispam_dnsbluri_zones` (
   `level` tinyint(4) NOT NULL,