Alex Trofimov 12 anni fa
parent
commit
004f596e29

+ 6 - 1
inc/classes/BxDolAcl.php

@@ -133,17 +133,22 @@ class BxDolAcl extends BxDol implements iBxDolSingleton {
     /**
      * Check if member has one of the provided membership levels
      * @param $iPermissions - integer value to check permissions for, every bit is matched with some membership id
-     * @param $iProfileId - profile if to check, if it isn't provided or is false then currently loggen in profile is used.
+     * @param $iProfileId - profile to check, if it isn't provided or is false then currently logged in profile is used.
      * @return true if member has privided membership levels, or false if member hasn't.
      */
     public function isMemberLevelInSet($iPermissions, $iProfileId = false) {
         if (!$iPermissions)
             return false;
+
+        if (false === $iProfileId && ($iPermissions&(pow(2, MEMBERSHIP_ID_ADMINISTRATOR - 1))) && isAdmin())
+            return true;
+
         if (false === $iProfileId) {
             bx_import('BxDolProfile');
             $oProfile = BxDolProfile::getInstance();
             $iProfileId = $oProfile ? $oProfile->id() : 0;
         }
+
         $aACL = $this->getMemberMembershipInfo($iProfileId);
         return ($iPermissions & pow(2, $aACL['id'] - 1));
     }

+ 2 - 0
inc/js/classes/BxDolGrid.js

@@ -378,6 +378,8 @@ BxDolGrid.prototype._onDataReloaded = function (isSkipSearchInput) {
 
     jQuery('#' + this._sIdTable + ' tbody tr:odd').addClass('bx-def-color-bg-hl');
     
+    jQuery('#' + this._sIdTable).bxTime();
+
     if (this._oOptions.sorting)
         this.orderable();
 

+ 182 - 0
modules/boonex/antispam/classes/BxAntispamGridIpTable.php

@@ -0,0 +1,182 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ * 
+ * @defgroup    Antispam Antispam
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+bx_import('BxTemplGrid');
+
+class BxAntispamGridIpTable extends BxTemplGrid 
+{
+    public function __construct ($aOptions, $oTemplate = false) 
+    {
+        parent::__construct ($aOptions, $oTemplate);
+    }
+
+    /**
+     * add js file for AJAX form submission
+     */
+    protected function _addJsCss() 
+    {
+        parent::_addJsCss();
+        $this->_oTemplate->addJs('jquery.form.js');
+
+        bx_import('BxTemplFormView');
+        $oForm = new BxTemplFormView(array());
+        $oForm->addCssJs();
+    }
+
+    /**
+     * 'add' action handler
+     */
+    public function performActionAdd() 
+    {
+        $sAction = 'add';
+
+        $aForm = array(
+            'form_attrs' => array(
+                'id' => 'sample-add-form',    
+                'action' => 'grid.php?o=' . $this->_sObject . '&a=' . $sAction, // grid.php is usiversal actions handler file, we need to pass object and action names to it at least
+                'method' => 'post',
+            ),
+            'params' => array (
+                'db' => array(
+                    'table' => 'sample_grid_data', 
+                    'key' => 'ID', 
+                    'submit_name' => 'do_submit',
+                ),
+            ),
+            'inputs' => array(
+                'NickName' => array(
+                    'type' => 'text',
+                    'name' => 'NickName',
+                    'caption' => _t('Username'),
+                    'required' => true,
+                    'checker' => array(
+                        'func' => 'length',
+                        'params' => array(1, 150),
+                        'error' => _t( 'Username is required' )
+                    ),                    
+                    'db' => array (
+                        'pass' => 'Xss',  
+                    ),
+                ),
+                'Email' => array(
+                    'type' => 'text',
+                    'name' => 'Email',
+                    'caption' => _t('Email'),
+                    'required' => true,
+                    'checker' => array(
+                        'func' => 'email',
+                        'error' => _t( '_Incorrect Email' )
+                    ),
+                    'db' => array (
+                        'pass' => 'Xss',  
+                    ),
+                ),
+                'City' => array(
+                    'type' => 'text',
+                    'name' => 'City',
+                    'caption' => _t('City'),
+                    'required' => true,
+                    'checker' => array(
+                        'func' => 'length',
+                        'params' => array(1, 150),
+                        'error' => _t( 'City is required' )
+                    ),
+                    'db' => array (
+                        'pass' => 'Xss',  
+                    ),
+                ),
+
+                'submit' => array(
+                    'type' => 'input_set',
+                    0 => array (
+                        'type' => 'submit',
+                        'name' => 'do_submit',
+                        'value' => _t('_Submit'),
+                    ),
+                    1 => array (
+                        'type' => 'reset',
+                        'name' => 'close',
+                        'value' => _t('Close'),
+                        'attrs' => array(
+                            'onclick' => "$('.dolPopup:visible').dolPopupHide()",
+                            'class' => 'bx-def-margin-sec-left',
+                        ),
+                    ),
+                ),
+
+            ),
+        );
+
+        bx_import('BxTemplFormView');
+        $oForm = new BxTemplFormView($aForm);
+        $oForm->initChecker();
+
+        if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
+
+            $iNewId = $oForm->insert (array(), true); // insert record to database
+            if ($iNewId)
+                $aRes = array('grid' => $this->getCode(true), 'blink' => $iNewId); // if record is successfully added, reload grid and highlight added row
+            else
+                $aRes = array('msg' => "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');
+            // we need to use 'transBox' function to properly display 'popup'
+            $s = BxTemplFunctions::getInstance()->transBox('', '
+                <div class="bx-def-padding-top bx-def-padding-left bx-def-padding-right bx-def-color-bg-block" style="width:300px;">' . $oForm->getCode() . '</div>
+                <script>
+                    $(document).ready(function () {
+                        $("#sample-add-form").ajaxForm({ 
+                            dataType: "json",
+                            beforeSubmit: function (formData, jqForm, options) {
+                                bx_loading($("#' . $aForm['form_attrs']['id'] . '"), true);
+                            },
+                            success: function (data) {
+                                $(".dolPopup:visible").dolPopupHide();
+                                glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
+                            }
+                        });
+                    });
+                </script>');
+
+            $this->_echoResultJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))), true);
+
+        }
+    }
+
+
+    protected function _getCellType ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        return parent::_getCellDefault ('allow' == $mixedValue ? _t('_bx_antispam_ip_allow') : _t('_bx_antispam_ip_deny'), $sKey, $aField, $aRow);
+    }
+    protected function _getCellLastDT ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        return parent::_getCellDefault (bx_time_js($mixedValue, BX_FORMAT_DATE), $sKey, $aField, $aRow);
+    }
+
+    protected function _getCellFrom ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        return parent::_getCellDefault (long2ip($mixedValue), $sKey, $aField, $aRow);
+    }
+
+    protected function _getCellTo ($mixedValue, $sKey, $aField, $aRow) 
+    {
+        return parent::_getCellDefault (long2ip($mixedValue), $sKey, $aField, $aRow);
+    }
+
+}
+
+/** @} */

+ 7 - 0
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -20,6 +20,13 @@ class BxAntispamModule extends BxDolModule
         parent::__construct($aModule);
     }
 
+    function serviceIpTable () 
+    {
+        bx_import('BxDolGrid');
+        $oGrid = BxDolGrid::getObjectInstance('bx_antispam_grid_ip_table'); // it automatically creates instance of default or custom class by object name
+        return $oGrid ? $oGrid->getCode() : '';
+    }
+
     /**
      * Check text for spam.
      * First it check if IP is whitelisted(or under cron execution or user is admin) - for whitelisted IPs check for spam isn't performed,

+ 25 - 0
modules/boonex/antispam/classes/BxAntispamPage.php

@@ -0,0 +1,25 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Antispam Antispam
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxTemplPage');
+
+/**
+ * Antispam module pages.
+ */
+class BxAntispamPage extends BxTemplPage {
+
+    public function __construct($aObject, $oTemplate = false) {
+        parent::__construct($aObject, $oTemplate);
+    }
+
+}
+
+/** @} */

+ 18 - 0
modules/boonex/antispam/install/langs/en.xml

@@ -9,6 +9,24 @@
     <string name="_bx_antispam_ip_blocked"><![CDATA[IP address is blocked. {0}]]></string>
     <string name="_bx_antispam_spam_detected"><![CDATA[Spam detected. {0}]]></string>
     <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_page_title_sys_ip_table"><![CDATA[IP table]]></string>
+	<string name="_bx_antispam_page_title_ip_table"><![CDATA[IP table]]></string>
+
+	<string name="_bx_antispam_page_block_title_ip_table"><![CDATA[IP table]]></string>
+
+	<string name="_bx_antispam_grid_field_select"><![CDATA[Select]]></string>
+	<string name="_bx_antispam_grid_field_ip_from"><![CDATA[IP from]]></string>
+	<string name="_bx_antispam_grid_field_ip_to"><![CDATA[IP to]]></string>
+	<string name="_bx_antispam_grid_title_action"><![CDATA[Action]]></string>
+	<string name="_bx_antispam_grid_title_expiration"><![CDATA[Expiration]]></string>
+	<string name="_bx_antispam_grid_title_note"><![CDATA[Note]]></string>
+	<string name="_bx_antispam_grid_title_actions"><![CDATA[Actions]]></string>
+
+	<string name="_bx_antispam_grid_action_delete"><![CDATA[Delete]]></string>
+	<string name="_bx_antispam_grid_action_add"><![CDATA[Add]]></string>
 
 	<string name="_bx_antispam_option_block"><![CDATA[Total block all spam content]]></string>
 	<string name="_bx_antispam_option_report"><![CDATA[Send report to admin if spam content discovered]]></string>

+ 14 - 0
modules/boonex/antispam/install/sql/disable.sql

@@ -1,2 +1,16 @@
+
 -- settings
+
 DELETE FROM `top`, `toc`, `to` USING `sys_options_types` AS `top` LEFT JOIN `sys_options_categories` AS `toc` ON `top`.`id`=`toc`.`type_id` LEFT JOIN `sys_options` AS `to` ON `toc`.`id`=`to`.`category_id` WHERE `top`.`name`='bx_antispam';
+
+-- page: ip table
+
+DELETE FROM `sys_objects_page` WHERE `object`='bx_antispam_ip_table';
+DELETE FROM `sys_pages_blocks` WHERE `object`='bx_antispam_ip_table';
+
+-- grid: ip table
+
+DELETE FROM `sys_objects_grid` WHERE `object` = 'bx_antispam_grid_ip_table';
+DELETE FROM `sys_grid_fields` WHERE `object` = 'bx_antispam_grid_ip_table';
+DELETE FROM `sys_grid_actions` WHERE `object` = 'bx_antispam_grid_ip_table';
+

+ 30 - 0
modules/boonex/antispam/install/sql/enable.sql

@@ -1,4 +1,6 @@
+
 -- settings
+
 SET @iTypeOrder = (SELECT MAX(`order`) FROM `sys_options_types` WHERE `group` = 'modules');
 INSERT INTO `sys_options_types` (`group`, `name`, `caption`, `icon`, `order`) VALUES 
 ('modules', 'bx_antispam', '_bx_antispam_adm_stg_cpt_type', 'bx_antispam@modules/boonex/antispam/|std-mi.png', IF(NOT ISNULL(@iTypeOrder), @iTypeOrder + 1, 1));
@@ -23,3 +25,31 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'bx_antispam_stopforumspam_enable', '_bx_antispam_option_stopforumspam_enable', 'on', 'checkbox', '', '', '', 60),
 (@iCategoryId, 'bx_antispam_stopforumspam_api_key', '_bx_antispam_option_stopforumspam_api_key', '', 'digit', '', '', '', 61);
 
+-- page: ip table
+
+INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
+('bx_antispam_ip_table', 'antispam-ip-table', '_bx_antispam_page_title_sys_ip_table', '_bx_antispam_page_title_ip_table', 'bx_antispam', 5, 64, 1, 'page.php?i=antispam-ip-table', '', '', '', 0, 1, 0, 'BxAntispamPage', 'modules/boonex/antispam/classes/BxAntispamPage.php');
+
+INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES 
+('bx_antispam_ip_table', 1, 'bx_antispam', '_bx_antispam_page_block_title_ip_table', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:11:\"bx_antispam\";s:6:\"method\";s:8:\"ip_table\";}', 0, 1, 1, 1);
+
+-- grid: ip table
+
+INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_mode`, `sorting_fields`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
+('bx_antispam_grid_ip_table', 'Sql', 'SELECT `ID`, `From`, `To`, `Type`, `LastDT`, `Desc` FROM `bx_antispam_ip_table`', 'bx_antispam_ip_table', 'ID', '', '', 10, NULL, 'start', '', 'From,To,Desc', 'auto', 'From,To,Type,LastDT,Desc', 64, 'BxAntispamGridIpTable', 'modules/boonex/antispam/classes/BxAntispamGridIpTable.php');
+
+INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
+('bx_antispam_grid_ip_table', 'checkbox', '_bx_antispam_grid_field_select', '2%', '', 1),
+('bx_antispam_grid_ip_table', 'From', '_bx_antispam_grid_field_ip_from', '15%', '', 2),
+('bx_antispam_grid_ip_table', 'To', '_bx_antispam_grid_field_ip_to', '15%', '', 3),
+('bx_antispam_grid_ip_table', 'Type', '_bx_antispam_grid_title_action', '15%', '', 4),
+('bx_antispam_grid_ip_table', 'LastDT', '_bx_antispam_grid_title_expiration', '15%', '', 5),
+('bx_antispam_grid_ip_table', 'Desc', '_bx_antispam_grid_title_note', '26%', '', 6),
+('bx_antispam_grid_ip_table', 'actions', '_bx_antispam_grid_title_actions', '12%', '', 7);
+
+INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
+('bx_antispam_grid_ip_table', 'bulk', 'delete', '_bx_antispam_grid_action_delete', '', 1, 1),
+('bx_antispam_grid_ip_table', 'single', 'edit', '', 'pencil', 0, 1),
+('bx_antispam_grid_ip_table', 'single', 'delete', '', 'remove',  1, 2),
+('bx_antispam_grid_ip_table', 'independent', 'add', '_bx_antispam_grid_action_add', '', 0, 1);
+