Index: branches/5.2.x/core/admin_templates/groups/groups_edit.tpl =================================================================== diff -u -N -r14244 -r14630 --- branches/5.2.x/core/admin_templates/groups/groups_edit.tpl (.../groups_edit.tpl) (revision 14244) +++ branches/5.2.x/core/admin_templates/groups/groups_edit.tpl (.../groups_edit.tpl) (revision 14630) @@ -74,12 +74,14 @@
- + + + Index: branches/5.2.x/core/units/users/users_event_handler.php =================================================================== diff -u -N -r14617 -r14630 --- branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 14617) +++ branches/5.2.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 14630) @@ -1,6 +1,6 @@ SetFieldsFromHash( $this->getSubmittedFields($event) ); $username = $object->GetDBField('UserLogin'); $password = $object->GetDBField('UserPassword'); - $rember_login = $object->GetDBField('UserRememberLogin') == 1; + $remember_login = $object->GetDBField('UserRememberLogin') == 1; $user_helper =& $this->Application->recallObject('UserHelper'); /* @var $user_helper UserHelper */ $user_helper->event =& $event; - $result = $user_helper->loginUser($username, $password, false, $rember_login); + $result = $user_helper->loginUser($username, $password, false, $remember_login); if ($result != LoginResult::OK) { $event->status = kEvent::erFAIL; @@ -460,6 +460,8 @@ if ( !$user_helper->checkBanRules($object) ) { $object->SetError('Login', 'banned'); } + + $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); } /** @@ -696,7 +698,6 @@ } $object->SetDBField('Status', STATUS_ACTIVE); // make user subscriber Active by default - $object->SetDBField('ip', $_SERVER['REMOTE_ADDR']); if ( $object->Create() ) { $this->AddSubscriberGroup($object); @@ -1181,11 +1182,14 @@ function checkItemStatus(&$event) { $object =& $event->getObject(); - if (!$object->isLoaded()) { + /* @var $object kDBItem */ + + if ( !$object->isLoaded() ) { return true; } $virtual_users = Array (USER_ROOT, USER_GUEST); + return ($object->GetDBField('Status') == STATUS_ACTIVE) || in_array($object->GetID(), $virtual_users); } Index: branches/5.2.x/core/units/helpers/user_helper.php =================================================================== diff -u -N -r14628 -r14630 --- branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14628) +++ branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14630) @@ -1,6 +1,6 @@ getUserObject(); + $ip_restrictions = $object->GetDBField('IPRestrictions'); + if ( $ip_restrictions && !$this->Application->isDebugMode() && !kUtil::ipMatch($ip_restrictions, "\n") ) { + return false; + } + $groups = $object->getMembershipGroups(true); - if (!$groups) { - $groups = Array(); + if ( !$groups ) { + $groups = Array (); } if ( $object->GetDBField('UserType') == UserType::USER ) { - array_push($groups, $this->Application->ConfigValue('User_NewGroup') ); + array_push($groups, $this->Application->ConfigValue('User_NewGroup')); } elseif ( $object->GetDBField('UserType') == UserType::ADMIN ) { - array_push($groups, $this->Application->ConfigValue('User_AdminGroup') ); + array_push($groups, $this->Application->ConfigValue('User_AdminGroup')); } // store groups, because kApplication::CheckPermission will use them! - array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') ); - $this->Application->StoreVar( 'UserGroups', implode(',', $groups), true ); // true for optional + array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup')); + $groups = array_unique($groups); + $this->Application->StoreVar('UserGroups', implode(',', $groups), true); // true for optional return $this->Application->CheckPermission($this->Application->isAdmin ? 'ADMIN' : 'LOGIN', 1); } @@ -295,7 +301,7 @@ // synchronize login $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); /* @var $sync_manager UsersSyncronizeManager */ - + $sync_manager->performAction('LoginUser', $username, $password); } @@ -360,10 +366,10 @@ public function &getUserObject() { $prefix_special = $this->Application->isAdmin ? 'u.current' : 'u'; // "u" used on front not to change theme - + $object =& $this->Application->recallObject($prefix_special, null, Array('skip_autoload' => true)); /* @var $object UsersItem */ - + return $object; } Index: branches/5.2.x/admin/system_presets/simple/users_u.php =================================================================== diff -u -N -r14599 -r14630 --- branches/5.2.x/admin/system_presets/simple/users_u.php (.../users_u.php) (revision 14599) +++ branches/5.2.x/admin/system_presets/simple/users_u.php (.../users_u.php) (revision 14630) @@ -71,7 +71,7 @@ $hidden_fields = Array ( /* 'PortalUserId', 'Login', 'Password', 'FirstName','LastName', 'Company', 'Email', 'CreatedOn', 'Phone', 'Fax', 'Street', 'Street2', 'City', 'State' , 'Zip', 'Country', 'ResourceId', 'Status', - 'Modified', 'dob', 'tz', 'ip', 'IsBanned', 'PwResetConfirm', 'PwRequestTime',*/ + 'Modified', 'dob', 'tz',*/ 'IPAddress', /*'IsBanned', 'PwResetConfirm', 'PwRequestTime',*/ 'IPRestrictions', ); // virtual fields to hide @@ -83,7 +83,7 @@ $required_fields = Array ( /*'PortalUserId',*/ 'Login', /*'Password', 'FirstName', 'LastName', 'Company', */'Email', /*'CreatedOn', 'Phone', 'Fax', 'Street', 'Street2', 'City', 'State' , 'Zip', 'Country', 'ResourceId', 'Status', - 'Modified', 'dob', 'tz', 'ip', 'IsBanned', 'PwResetConfirm', 'PwRequestTime',*/ + 'Modified', 'dob', 'tz', 'IPAddress', 'IsBanned', 'PwResetConfirm', 'PwRequestTime',*/ ); // virtual fields to make required @@ -115,5 +115,5 @@ // 'Admins' => Array ('PortalUserId', 'Login', 'FirstName', 'LastName', 'Email'), // users list; section: Users Management -> Users - 'RegularUsers' => Array (/*'PortalUserId', 'Login', 'FirstName', 'LastName', 'Email',*/ 'PrimaryGroup', 'CreatedOn', 'Modified', /* 'Status'*/), + 'RegularUsers' => Array (/*'PortalUserId', 'Login', 'FirstName', 'LastName', 'Email',*/ 'PrimaryGroup', 'CreatedOn', 'Modified', /* 'Status',*/ 'IPAddress'), ); Index: branches/5.2.x/core/install/install_schema.sql =================================================================== diff -u -N -r14629 -r14630 --- branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 14629) +++ branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 14630) @@ -232,6 +232,7 @@ Personal tinyint(4) NOT NULL DEFAULT '0', Enabled tinyint(4) NOT NULL DEFAULT '1', FrontRegistration tinyint(3) unsigned NOT NULL DEFAULT '0', + IPRestrictions text, PRIMARY KEY (GroupId), UNIQUE KEY `Name` (`Name`), KEY Personal (Personal), @@ -261,7 +262,7 @@ Modified int(11) DEFAULT NULL, dob int(11) DEFAULT NULL, tz int(11) DEFAULT NULL, - ip varchar(20) NOT NULL DEFAULT '', + IPAddress varchar(15) NOT NULL, IsBanned tinyint(1) NOT NULL DEFAULT '0', PwResetConfirm varchar(255) NOT NULL, PwRequestTime int(11) unsigned DEFAULT NULL, @@ -270,6 +271,7 @@ UserType tinyint(4) NOT NULL, PrimaryGroupId int(11) DEFAULT NULL, OldStyleLogin tinyint(4) NOT NULL, + IPRestrictions text, PRIMARY KEY (PortalUserId), UNIQUE KEY ResourceId (ResourceId), KEY CreatedOn (CreatedOn), Index: branches/5.2.x/admin/system_presets/simple/groups_g.php =================================================================== diff -u -N -r14244 -r14630 --- branches/5.2.x/admin/system_presets/simple/groups_g.php (.../groups_g.php) (revision 14244) +++ branches/5.2.x/admin/system_presets/simple/groups_g.php (.../groups_g.php) (revision 14630) @@ -36,7 +36,7 @@ // fields to hide $hidden_fields = Array ( /*'GroupId', 'Name', 'Description', 'CreatedOn','System', 'Personal', 'Enabled', 'ResourceId',*/ - 'FrontRegistration', + 'FrontRegistration', 'IPRestrictions', ); // virtual fields to hide Index: branches/5.2.x/core/units/users/users_config.php =================================================================== diff -u -N -r14617 -r14630 --- branches/5.2.x/core/units/users/users_config.php (.../users_config.php) (revision 14617) +++ branches/5.2.x/core/units/users/users_config.php (.../users_config.php) (revision 14630) @@ -1,6 +1,6 @@ Array ('formatter' => 'kDateFormatter', 'default' => NULL), 'dob' => Array ('formatter' => 'kDateFormatter', 'default' => NULL), 'tz' => Array ('default' => NULL), - 'ip' => Array ('default' => ''), + 'IPAddress' => Array ('default' => ''), 'IsBanned' => Array ('default' => 0), 'PwResetConfirm' => Array ('default' => ''), 'PwRequestTime' => Array ('formatter' => 'kDateFormatter', 'default' => NULL), @@ -414,6 +414,7 @@ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1, 'default' => 0 ), + 'IPRestrictions' => Array ('default' => NULL), ), 'VirtualFields' => Array ( @@ -531,7 +532,7 @@ 'Modified' => Array ('type' => 'int'), 'dob' => Array ('type' => 'int'), 'tz' => Array ('type' => 'int'), - 'ip' => Array ('type' => 'string', 'not_null' => 1), + 'IPAddress' => Array ('type' => 'string', 'not_null' => 1), 'IsBanned' => Array ('type' => 'int', 'not_null' => 1), 'PwResetConfirm' => Array ('type' => 'string', 'not_null' => 1), 'PwRequestTime' => Array ('type' => 'int'), @@ -540,6 +541,7 @@ 'UserType' => Array ('type' => 'int', 'not_null' => 1), 'PrimaryGroupId' => Array ('type' => 'int'), 'OldStyleLogin' => Array ('type' => 'int', 'not_null' => 1), + 'IPRestrictions' => Array ('type' => 'string'), ), 'VirtualFields' => Array ( @@ -632,6 +634,7 @@ 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 100, ), 'CreatedOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 100), 'Modified' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 100), + 'IPAddress' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 100, 'hidden' => 1), ), ), ), Index: branches/5.2.x/core/units/users/users_item.php =================================================================== diff -u -N -r14596 -r14630 --- branches/5.2.x/core/units/users/users_item.php (.../users_item.php) (revision 14596) +++ branches/5.2.x/core/units/users/users_item.php (.../users_item.php) (revision 14630) @@ -1,6 +1,6 @@ Application->RecallVar('UserGroups'); - if($user_groups === false || $force_reload) - { + + if ( $user_groups === false || $force_reload ) { // primary group goes first - $sql = 'SELECT GroupId - FROM ' . TABLE_PREFIX . 'UserGroup - WHERE (PortalUserId = ' . $this->GetID() . ') AND ( (MembershipExpires IS NULL) OR ( MembershipExpires >= UNIX_TIMESTAMP() ) ) - ORDER BY IF(GroupId = ' . $this->GetDBField('PrimaryGroupId') . ', 1, 0) DESC'; + $sql = 'SELECT g.IPRestrictions, ug.GroupId + FROM ' . TABLE_PREFIX . 'UserGroup ug + JOIN ' . TABLE_PREFIX . 'PortalGroup g ON g.GroupId = ug.GroupId + WHERE (ug.PortalUserId = ' . $this->GetID() . ') AND ( (ug.MembershipExpires IS NULL) OR (ug.MembershipExpires >= ' . adodb_mktime() . ') ) + ORDER BY IF(ug.GroupId = ' . $this->GetDBField('PrimaryGroupId') . ', 1, 0) DESC'; + $groups = $this->Conn->GetCol($sql, 'GroupId'); - return $this->Conn->GetCol($sql); + if ( $this->Application->isDebugMode() ) { + return array_keys($groups); + } + else { + $user_groups = Array (); + + foreach ($groups as $group_id => $ip_restrictions) { + if ( !$ip_restrictions || kUtil::ipMatch($ip_restrictions, "\n") ) { + $user_groups[] = $group_id; + } + } + + return $user_groups; + } } - else - { - return explode(',', $user_groups); - } + + return explode(',', $user_groups); } function SendEmailEvents() @@ -142,7 +156,7 @@ if ( $ret ) { $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array (), Array ('InPortalSyncronize')); /* @var $sync_manager UsersSyncronizeManager */ - + $sync_manager->performAction('deleteUser', $this->FieldValues); } Index: branches/5.2.x/core/install/upgrades.sql =================================================================== diff -u -N -r14629 -r14630 --- branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 14629) +++ branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 14630) @@ -2130,4 +2130,10 @@ ADD UploadExtensions VARCHAR(255) NOT NULL DEFAULT '' AFTER Validation, ADD UploadMaxSize INT NULL AFTER UploadExtensions; -ALTER TABLE Language ADD SynchronizationModes VARCHAR(255) NOT NULL DEFAULT ''; \ No newline at end of file +ALTER TABLE Language ADD SynchronizationModes VARCHAR(255) NOT NULL DEFAULT ''; + +ALTER TABLE PortalUser + CHANGE ip IPAddress VARCHAR(15) NOT NULL, + ADD IPRestrictions TEXT NULL; + +ALTER TABLE PortalGroup ADD IPRestrictions TEXT NULL; \ No newline at end of file Index: branches/5.2.x/core/admin_templates/users/admins_edit.tpl =================================================================== diff -u -N -r14468 -r14630 --- branches/5.2.x/core/admin_templates/users/admins_edit.tpl (.../admins_edit.tpl) (revision 14468) +++ branches/5.2.x/core/admin_templates/users/admins_edit.tpl (.../admins_edit.tpl) (revision 14630) @@ -66,13 +66,22 @@
- - - + + + + - - - + + + + + + + + + + +
Index: branches/5.2.x/core/units/groups/groups_config.php =================================================================== diff -u -N -r14585 -r14630 --- branches/5.2.x/core/units/groups/groups_config.php (.../groups_config.php) (revision 14585) +++ branches/5.2.x/core/units/groups/groups_config.php (.../groups_config.php) (revision 14630) @@ -1,6 +1,6 @@ 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0 ), + 'IPRestrictions' => Array ('type' => 'string', 'default' => NULL), ), 'VirtualFields' => Array ( Index: branches/5.2.x/core/admin_templates/users/users_edit.tpl =================================================================== diff -u -N -r14585 -r14630 --- branches/5.2.x/core/admin_templates/users/users_edit.tpl (.../users_edit.tpl) (revision 14585) +++ branches/5.2.x/core/admin_templates/users/users_edit.tpl (.../users_edit.tpl) (revision 14630) @@ -83,11 +83,17 @@ - + + + + + + + Index: branches/5.2.x/core/install/english.lang =================================================================== diff -u -N -r14629 -r14630 --- branches/5.2.x/core/install/english.lang (.../english.lang) (revision 14629) +++ branches/5.2.x/core/install/english.lang (.../english.lang) (revision 14630) @@ -424,6 +424,7 @@ SW5zdGFsbCBNb2R1bGVz SW5zdGFsbCBQaHJhc2UgVHlwZXM= SVAgQWRkcmVzcw== + SVAgUmVzdHJpY3Rpb25z VXNlIGN1cnJlbnQgc2VjdGlvbiBhcyByb290IGZvciB0aGUgZXhwb3J0 SVNPIENvZGU= UHJpbWFyeQ== @@ -615,7 +616,7 @@ SGlkZQ== QWxsIEZpbGVz Q1NWIEZpbGVz - U2luZ2xlIElQIG9yIHJhbmdlIHJlY29yZCBwZXIgbGluZSAoZm9ybWF0czogMS4yLjMuNCBvciAxLjIuMyBvciAxLjIuMy4zMi0xLjIuMy41NCBvciAxLjIuMy4zMi8yNyBvciAxLjIuMy4zMi8yNTUuMjU1LjI1NS4yMjQp + U2luZ2xlIElQLCBJUCByYW5nZSwgU3VibmV0IG9yIGhvc3RuYW1lIHJlY29yZCBwZXIgbGluZSAoZm9ybWF0czogMS4yLjMuNCBvciAxLjIuMy4zMi0xLjIuMy41NCBvciAxLjIuMy4zMi8yNyBvciAxLjIuMy4zMi8yNTUuMjU1LjI1NS4yMjQgb3Igd3d3LmluLXBvcnRhbC5jb20p U2luZ2xlIEVtYWlsIEV2ZW50IHBlciBsaW5lIChmb3JtYXRzOiBVU0VSLkFERCwgT1JERVIuU1VCTUlUKQ== U2luZ2xlIFBocmFzZSBMYWJlbCBwZXIgbGluZSAoZm9ybWF0czogbGFfU2FtcGxlTGFiZWwsIGx1X0Zyb250RW5kTGFiZWwp VXNlciB3aWxsIGJlIGF1dG9tYXRpY2FsbHkgcmVkaXJlY3RlZCB0byB0aGUgc2VsZWN0ZWQgVXJsIEVuZGluZyBpbiBjYXNlIHdoZW4gY3VycmVudCBwYWdlIHVybCBoYXMgYSBkaWZmZXJlbnQgZW5kaW5n