Attached Files |
Implement-additional-UserBan-rules-CORE.patch [^] (6,022 bytes) 2011-01-03 13:31
[Show Content]
Index: install/english.lang
===================================================================
--- install/english.lang (revision 14094)
+++ install/english.lang (working copy)
@@ -792,6 +792,7 @@
<PHRASE Label="la_opt_Deny" Module="Core" Type="1">RGVueQ==</PHRASE>
<PHRASE Label="la_opt_Description" Module="Core" Type="1">RGVzY3JpcHRpb24=</PHRASE>
<PHRASE Label="la_opt_Disabled" Module="Core" Type="1">RGlzYWJsZWQ=</PHRASE>
+ <PHRASE Label="la_opt_DoesntMatch" Module="Core" Type="1">RG9lc24ndCBtYXRjaA==</PHRASE>
<PHRASE Label="la_opt_EditorsPick" Module="Core" Type="1">RWRpdG9yJ3MgUGljaw==</PHRASE>
<PHRASE Label="la_opt_Email" Module="Core" Type="1">RS1tYWls</PHRASE>
<PHRASE Label="la_opt_EmailBody" Module="Core" Type="1">RS1tYWlsIEJvZHk=</PHRASE>
@@ -807,12 +808,15 @@
<PHRASE Label="la_opt_hour" Module="Core" Type="1">aG91cihzKQ==</PHRASE>
<PHRASE Label="la_opt_InheritFromParent" Module="Core" Type="1">SW5oZXJpdCBmcm9tIFBhcmVudA==</PHRASE>
<PHRASE Label="la_opt_IP_Address" Module="Core" Type="1">SVAgQWRkcmVzcw==</PHRASE>
+ <PHRASE Label="la_opt_IsUnique" Module="Core" Type="1">SXMgdW5pcXVl</PHRASE>
<PHRASE Label="la_opt_LastName" Module="Core" Type="1">TGFzdCBOYW1l</PHRASE>
<PHRASE Label="la_opt_LoggedOut" Module="Core" Type="1">TG9nZ2VkIE91dA==</PHRASE>
<PHRASE Label="la_opt_min" Module="Core" Type="1">bWludXRlKHMp</PHRASE>
<PHRASE Label="la_opt_ModalWindow" Module="Core" Type="1">TW9kYWwgV2luZG93</PHRASE>
<PHRASE Label="la_opt_month" Module="Core" Type="1">bW9udGgocyk=</PHRASE>
<PHRASE Label="la_opt_NewEmail" Module="Core" Type="1">TmV3IEUtbWFpbA==</PHRASE>
+ <PHRASE Label="la_opt_NotEmpty" Module="Core" Type="1">Tm90IGVtcHR5</PHRASE>
+ <PHRASE Label="la_opt_NotLike" Module="Core" Type="1">Tm90IGxpa2U=</PHRASE>
<PHRASE Label="la_opt_NotProcessed" Module="Core" Type="1">Tm90IFByb2Nlc3NlZA==</PHRASE>
<PHRASE Label="la_opt_NotReplied" Module="Core" Type="1">Tm90IFJlcGxpZWQ=</PHRASE>
<PHRASE Label="la_opt_PartiallyProcessed" Module="Core" Type="1">UGFydGlhbGx5IFByb2Nlc3NlZA==</PHRASE>
Index: units/ban_rules/ban_rules_config.php
===================================================================
--- units/ban_rules/ban_rules_config.php (revision 14094)
+++ units/ban_rules/ban_rules_config.php (working copy)
@@ -83,7 +83,7 @@
'RuleId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'RuleType' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options'=>Array(
0 => 'la_opt_Deny',
-// 1 => 'la_opt_Allow'
+ 1 => 'la_opt_Allow',
)
),
'ItemField' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options' => Array(
@@ -101,7 +101,11 @@
),
'ItemVerb' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options'=>Array(
1 => 'la_opt_Exact',
- 3 => 'la_opt_Sub-match'
+ 2 => 'la_opt_DoesntMatch',
+ 3 => 'la_opt_Sub-match',
+ 4 => 'la_opt_NotLike',
+ 7 => 'la_opt_NotEmpty',
+ 8 => 'la_opt_IsUnique',
)
),
'ItemValue' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'required' => 1, 'default' => ''),
Index: units/helpers/user_helper.php
===================================================================
--- units/helpers/user_helper.php (revision 14094)
+++ units/helpers/user_helper.php (working copy)
@@ -357,10 +357,9 @@
return true;
}
- $sql = 'SELECT *
- FROM '.$table.'
- WHERE ItemType = 6 AND Status = ' . STATUS_ACTIVE . '
- ORDER BY Priority DESC';
+ $sql = 'SELECT * FROM ' . $table . '
+ WHERE ItemType = 6 AND Status = ' . STATUS_ACTIVE . '
+ ORDER BY Priority DESC';
$rules = $this->Conn->Query($sql);
$found = false;
@@ -369,23 +368,20 @@
$this_value = strtolower( $object->GetDBField($field) );
$test_value = strtolower( $rule['ItemValue'] );
-
+
switch ($rule['ItemVerb']) {
- /*case 0: // any
- $found = true;
- break;*/
-
+
case 1: // is
if ($this_value == $test_value) {
$found = true;
}
break;
- /*case 2: // is not
+ case 2: // is not
if ($this_value != $test_value) {
$found = true;
}
- break;*/
+ break;
case 3: // contains
if (strstr($this_value, $test_value)) {
@@ -393,25 +389,12 @@
}
break;
-
- /*case 4: // not contains
+ case 4: // not contains
if (!strstr($this_value, $test_value)) {
$found = true;
}
- break;
+ break;
- case 5: // Greater Than
- if ($test_value > $this_value) {
- $found = true;
- }
- break;
-
- case 6: // Less Than
- if ($test_value < $this_value) {
- $found = true;
- }
- break;
-
case 7: // exists
if (strlen($this_value) > 0) {
$found = true;
@@ -419,17 +402,33 @@
break;
case 8: // unique
- if ($this->ValueExists($field, $this_value)) {
+ if ($this->_checkValueExist($field, $this_value)) {
$found = true;
}
- break;*/
+ break;
}
- if ($found) {
+ if ( $found ) {
+ if ( $rule['RuleType'] ) { // 0 - deny; 1 - allow
+ $found = false;
+ }
break;
}
}
return !$found;
}
+
+ /**
+ * Checks if value is unique in Users table against the specified field
+ * @param string $field
+ * @param string $value
+ */
+ function _checkValueExist($field, $value)
+ {
+ $table = $this->Application->getUnitOption('u', 'TableName');
+ $sql = 'SELECT * FROM ' . $table . '
+ WHERE '. $field .' = ' . $this->Conn->qstr($value);
+ return $this->Conn->GetOne($sql);
+ }
}
Implement-additional-UserBan-rules-CORE_v2.patch [^] (11,239 bytes) 2011-01-05 04:14
[Show Content]
Index: admin_templates/ban_rules/ban_rule_edit.tpl
===================================================================
--- admin_templates/ban_rules/ban_rule_edit.tpl (revision 14103)
+++ admin_templates/ban_rules/ban_rule_edit.tpl (working copy)
@@ -66,9 +66,9 @@
<inp2:m_RenderElement name="inp_edit_hidden" prefix="ban-rule" field="ItemType"/>
<inp2:m_RenderElement name="inp_id_label" prefix="ban-rule" field="RuleId" title="la_fld_Id"/>
- <inp2:m_RenderElement name="inp_edit_options" prefix="ban-rule" field="RuleType" title="la_fld_RuleType"/>
- <inp2:m_RenderElement name="inp_edit_options" prefix="ban-rule" field="ItemField" title="la_fld_ItemField"/>
- <inp2:m_RenderElement name="inp_edit_options" prefix="ban-rule" field="ItemVerb" title="la_fld_FieldComparision"/>
+ <inp2:m_RenderElement name="inp_edit_radio" prefix="ban-rule" field="RuleType" title="la_fld_RuleType"/>
+ <inp2:m_RenderElement name="inp_edit_options" prefix="ban-rule" field="ItemField" title="la_fld_ItemField" has_empty="1"/>
+ <inp2:m_RenderElement name="inp_edit_options" prefix="ban-rule" field="ItemVerb" title="la_fld_FieldComparision" has_empty="1"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="ban-rule" field="ItemValue" title="la_fld_FieldValue"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="ban-rule" field="ErrorTag" title="la_fld_ErrorTag"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="ban-rule" field="Priority" title="la_fld_Priority"/>
Index: install/english.lang
===================================================================
--- install/english.lang (revision 14105)
+++ install/english.lang (working copy)
@@ -334,6 +334,7 @@
<PHRASE Label="la_error_unique" Module="Core" Type="1">UmVjb3JkIGlzIG5vdCB1bmlxdWU=</PHRASE>
<PHRASE Label="la_error_unique_category_field" Module="Core" Type="1">U2VjdGlvbiBmaWVsZCBub3QgdW5pcXVl</PHRASE>
<PHRASE Label="la_error_unknown_category" Module="Core" Type="1">VW5rbm93biBzZWN0aW9u</PHRASE>
+ <PHRASE Label="la_error_UserBanned" Module="Core" Type="1">VXNlciBCYW5uZWQ=</PHRASE>
<PHRASE Label="LA_ERROR_USERNOTFOUND" Module="Core" Type="1">dXNlciBub3QgZm91bmQ=</PHRASE>
<PHRASE Label="la_err_bad_date_format" Module="Core" Type="1">SW5jb3JyZWN0IGRhdGUgZm9ybWF0LCBwbGVhc2UgdXNlICglcykgZXguICglcyk=</PHRASE>
<PHRASE Label="la_err_bad_type" Module="Core" Type="1">SW5jb3JyZWN0IGRhdGEgZm9ybWF0LCBwbGVhc2UgdXNlICVz</PHRASE>
@@ -793,6 +794,7 @@
<PHRASE Label="la_opt_Deny" Module="Core" Type="1">RGVueQ==</PHRASE>
<PHRASE Label="la_opt_Description" Module="Core" Type="1">RGVzY3JpcHRpb24=</PHRASE>
<PHRASE Label="la_opt_Disabled" Module="Core" Type="1">RGlzYWJsZWQ=</PHRASE>
+ <PHRASE Label="la_opt_DoesntMatch" Module="Core" Type="1">RG9lc24ndCBtYXRjaA==</PHRASE>
<PHRASE Label="la_opt_EditorsPick" Module="Core" Type="1">RWRpdG9yJ3MgUGljaw==</PHRASE>
<PHRASE Label="la_opt_Email" Module="Core" Type="1">RS1tYWls</PHRASE>
<PHRASE Label="la_opt_EmailBody" Module="Core" Type="1">RS1tYWlsIEJvZHk=</PHRASE>
@@ -808,12 +810,15 @@
<PHRASE Label="la_opt_hour" Module="Core" Type="1">aG91cihzKQ==</PHRASE>
<PHRASE Label="la_opt_InheritFromParent" Module="Core" Type="1">SW5oZXJpdCBmcm9tIFBhcmVudA==</PHRASE>
<PHRASE Label="la_opt_IP_Address" Module="Core" Type="1">SVAgQWRkcmVzcw==</PHRASE>
+ <PHRASE Label="la_opt_IsUnique" Module="Core" Type="1">SXMgdW5pcXVl</PHRASE>
<PHRASE Label="la_opt_LastName" Module="Core" Type="1">TGFzdCBOYW1l</PHRASE>
<PHRASE Label="la_opt_LoggedOut" Module="Core" Type="1">TG9nZ2VkIE91dA==</PHRASE>
<PHRASE Label="la_opt_min" Module="Core" Type="1">bWludXRlKHMp</PHRASE>
<PHRASE Label="la_opt_ModalWindow" Module="Core" Type="1">TW9kYWwgV2luZG93</PHRASE>
<PHRASE Label="la_opt_month" Module="Core" Type="1">bW9udGgocyk=</PHRASE>
<PHRASE Label="la_opt_NewEmail" Module="Core" Type="1">TmV3IEUtbWFpbA==</PHRASE>
+ <PHRASE Label="la_opt_NotEmpty" Module="Core" Type="1">Tm90IGVtcHR5</PHRASE>
+ <PHRASE Label="la_opt_NotLike" Module="Core" Type="1">Tm90IGxpa2U=</PHRASE>
<PHRASE Label="la_opt_NotProcessed" Module="Core" Type="1">Tm90IFByb2Nlc3NlZA==</PHRASE>
<PHRASE Label="la_opt_NotReplied" Module="Core" Type="1">Tm90IFJlcGxpZWQ=</PHRASE>
<PHRASE Label="la_opt_PartiallyProcessed" Module="Core" Type="1">UGFydGlhbGx5IFByb2Nlc3NlZA==</PHRASE>
Index: units/ban_rules/ban_rules_config.php
===================================================================
--- units/ban_rules/ban_rules_config.php (revision 14103)
+++ units/ban_rules/ban_rules_config.php (working copy)
@@ -81,12 +81,14 @@
'Fields' => Array (
'RuleId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'RuleType' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options'=>Array(
- 0 => 'la_opt_Deny',
-// 1 => 'la_opt_Allow'
- )
+ 'RuleType' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array(0 => 'la_opt_Deny', 1 => 'la_opt_Allow'), 'use_phrases' => 1,
+ 'not_null' => 1, 'required' => 1, 'default' => 0
),
- 'ItemField' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options' => Array(
+ 'ItemField' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter'=>'kOptionsFormatter', 'options' => Array(
'ip' => 'la_opt_IP_Address',
'Login' => 'la_opt_Username',
'Email' => 'la_opt_Email',
@@ -97,12 +99,21 @@
'State' => 'la_opt_State',
'Zip' => 'la_opt_Zip',
'Phone' => 'la_opt_Phone',
- )
+ ), 'use_phrases' => 1,
+ 'required' => 1,
+ 'default' => NULL,
),
- 'ItemVerb' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0, 'use_phrases' => 1, 'formatter'=>'kOptionsFormatter', 'options'=>Array(
+ 'ItemVerb' => Array (
+ 'type' => 'int',
+ 'formatter'=>'kOptionsFormatter', 'options'=>Array(
1 => 'la_opt_Exact',
- 3 => 'la_opt_Sub-match'
- )
+ 2 => 'la_opt_DoesntMatch',
+ 3 => 'la_opt_Sub-match',
+ 4 => 'la_opt_NotLike',
+ 7 => 'la_opt_NotEmpty',
+ 8 => 'la_opt_IsUnique',
+ ), 'use_phrases' => 1,
+ 'not_null' => 1, 'required' => 1, 'default' => 0,
),
'ItemValue' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'required' => 1, 'default' => ''),
'ItemType' => Array ('type' => 'int', 'not_null' => 1, 'default' => 6),
Index: units/helpers/user_helper.php
===================================================================
--- units/helpers/user_helper.php (revision 14103)
+++ units/helpers/user_helper.php (working copy)
@@ -352,84 +352,91 @@
function checkBanRules(&$object)
{
$table = $this->Application->getUnitOption('ban-rule', 'TableName');
+
if (!$this->Conn->TableFound($table)) {
// when ban table not found -> assume user is ok by default
return true;
}
$sql = 'SELECT *
- FROM '.$table.'
+ FROM ' . $table . '
WHERE ItemType = 6 AND Status = ' . STATUS_ACTIVE . '
ORDER BY Priority DESC';
$rules = $this->Conn->Query($sql);
$found = false;
+
foreach ($rules as $rule) {
$field = $rule['ItemField'];
+ $this_value = mb_strtolower( $object->GetDBField($field) );
+ $test_value = mb_strtolower( $rule['ItemValue'] );
- $this_value = strtolower( $object->GetDBField($field) );
- $test_value = strtolower( $rule['ItemValue'] );
-
- switch ($rule['ItemVerb']) {
- /*case 0: // any
- $found = true;
- break;*/
-
+ switch ( $rule['ItemVerb'] ) {
case 1: // is
if ($this_value == $test_value) {
$found = true;
}
break;
- /*case 2: // is not
+ case 2: // is not
if ($this_value != $test_value) {
$found = true;
}
- break;*/
+ break;
case 3: // contains
- if (strstr($this_value, $test_value)) {
+ if ( strstr($this_value, $test_value) ) {
$found = true;
}
break;
-
- /*case 4: // not contains
- if (!strstr($this_value, $test_value)) {
+ case 4: // not contains
+ if ( !strstr($this_value, $test_value) ) {
$found = true;
}
break;
- case 5: // Greater Than
- if ($test_value > $this_value) {
- $found = true;
- }
- break;
-
- case 6: // Less Than
- if ($test_value < $this_value) {
- $found = true;
- }
- break;
-
case 7: // exists
- if (strlen($this_value) > 0) {
+ if ( strlen($this_value) > 0 ) {
$found = true;
}
break;
case 8: // unique
- if ($this->ValueExists($field, $this_value)) {
+ if ( $this->_checkValueExist($field, $this_value) ) {
$found = true;
}
- break;*/
+ break;
}
- if ($found) {
+ if ( $found ) {
+ // check ban rules, until one of them matches
+
+ if ( $rule['RuleType'] ) {
+ // invert rule type
+ $found = false;
+ }
+
break;
}
}
return !$found;
}
+
+ /**
+ * Checks if value is unique in Users table against the specified field
+ *
+ * @param string $field
+ * @param string $value
+ * @return string
+ */
+ function _checkValueExist($field, $value)
+ {
+ $sql = 'SELECT *
+ FROM ' . $this->Application->getUnitOption('u', 'TableName') . '
+ WHERE '. $field .' = ' . $this->Conn->qstr($value);
+
+ return $this->Conn->GetOne($sql);
+ }
}
Index: units/users/users_config.php
===================================================================
--- units/users/users_config.php (revision 14103)
+++ units/users/users_config.php (working copy)
@@ -337,7 +337,7 @@
'Fields' => Array
(
'PortalUserId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'Login' => Array ('type' => 'string', 'unique'=>Array('Login'), 'default' => null,'required'=>1, 'error_msgs' => Array('unique'=>'!lu_user_already_exist!')),
+ 'Login' => Array ('type' => 'string', 'unique'=>Array('Login'), 'default' => null,'required'=>1, 'error_msgs' => Array('unique'=>'!lu_user_already_exist!', 'banned' => '!la_error_UserBanned!')),
'Password' => Array ('type' => 'string', 'formatter' => 'kPasswordFormatter', 'encryption_method' => 'md5', 'verify_field' => 'VerifyPassword', 'skip_empty' => 1, 'default' => md5('')),
'FirstName' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
'LastName' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
Index: units/users/users_event_handler.php
===================================================================
--- units/users/users_event_handler.php (revision 14103)
+++ units/users/users_event_handler.php (working copy)
@@ -534,8 +534,7 @@
/* @var $user_helper UserHelper */
if (!$user_helper->checkBanRules($object)) {
- $event->status = erFAIL;
- return ;
+ $object->SetError('Login', 'banned');
}
}
|