@@ -10,19 +10,19 @@ |
||
| 10 | 10 | class AdminLoginExtension extends Extension |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Redirect to AdminSecurity, when we are coming from /admin/* |
|
| 15 | - * |
|
| 16 | - * @return SS_HTTPResponse|void |
|
| 17 | - */ |
|
| 18 | - public function onBeforeSecurityLogin() |
|
| 19 | - { |
|
| 20 | - $backUrl = $this->owner->getRequest()->getVar('BackURL'); |
|
| 21 | - if (strstr($backUrl, '/admin/')) { |
|
| 22 | - if (Controller::curr()->class != 'AdminSecurity') { |
|
| 23 | - $link = 'AdminSecurity/login' . '?BackURL=' . urlencode($backUrl); |
|
| 24 | - return $this->owner->redirect($link); |
|
| 25 | - } |
|
| 26 | - } |
|
| 27 | - } |
|
| 13 | + /** |
|
| 14 | + * Redirect to AdminSecurity, when we are coming from /admin/* |
|
| 15 | + * |
|
| 16 | + * @return SS_HTTPResponse|void |
|
| 17 | + */ |
|
| 18 | + public function onBeforeSecurityLogin() |
|
| 19 | + { |
|
| 20 | + $backUrl = $this->owner->getRequest()->getVar('BackURL'); |
|
| 21 | + if (strstr($backUrl, '/admin/')) { |
|
| 22 | + if (Controller::curr()->class != 'AdminSecurity') { |
|
| 23 | + $link = 'AdminSecurity/login' . '?BackURL=' . urlencode($backUrl); |
|
| 24 | + return $this->owner->redirect($link); |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -3,63 +3,63 @@ |
||
| 3 | 3 | class AdminLoginForm extends MemberLoginForm |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) |
|
| 7 | - { |
|
| 8 | - parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser); |
|
| 6 | + public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) |
|
| 7 | + { |
|
| 8 | + parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser); |
|
| 9 | 9 | |
| 10 | - if ($this->Actions()->fieldByName('forgotPassword')) { |
|
| 11 | - // replaceField won't work, since it's a dataless field |
|
| 12 | - $this->Actions()->removeByName('forgotPassword'); |
|
| 13 | - $this->Actions()->push(new LiteralField( |
|
| 14 | - 'forgotPassword', |
|
| 15 | - '<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">' |
|
| 16 | - . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>' |
|
| 17 | - )); |
|
| 18 | - } |
|
| 10 | + if ($this->Actions()->fieldByName('forgotPassword')) { |
|
| 11 | + // replaceField won't work, since it's a dataless field |
|
| 12 | + $this->Actions()->removeByName('forgotPassword'); |
|
| 13 | + $this->Actions()->push(new LiteralField( |
|
| 14 | + 'forgotPassword', |
|
| 15 | + '<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">' |
|
| 16 | + . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>' |
|
| 17 | + )); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - Requirements::customScript(<<<JS |
|
| 20 | + Requirements::customScript(<<<JS |
|
| 21 | 21 | (function() { |
| 22 | 22 | var el = document.getElementById("AdminLoginForm_LoginForm_Email"); |
| 23 | 23 | if(el && el.focus) el.focus(); |
| 24 | 24 | })(); |
| 25 | 25 | JS |
| 26 | - ); |
|
| 27 | - } |
|
| 26 | + ); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param array $data |
|
| 31 | - */ |
|
| 32 | - public function forgotPassword($data) |
|
| 33 | - { |
|
| 34 | - $email = Convert::raw2sql($data['Email']); |
|
| 29 | + /** |
|
| 30 | + * @param array $data |
|
| 31 | + */ |
|
| 32 | + public function forgotPassword($data) |
|
| 33 | + { |
|
| 34 | + $email = Convert::raw2sql($data['Email']); |
|
| 35 | 35 | |
| 36 | - /* @var $member Member */ |
|
| 37 | - $member = Member::get()->where("Email = '{$email}'")->first(); |
|
| 36 | + /* @var $member Member */ |
|
| 37 | + $member = Member::get()->where("Email = '{$email}'")->first(); |
|
| 38 | 38 | |
| 39 | - if ($member) { |
|
| 40 | - $token = $member->generateAutologinTokenAndStoreHash(); |
|
| 39 | + if ($member) { |
|
| 40 | + $token = $member->generateAutologinTokenAndStoreHash(); |
|
| 41 | 41 | |
| 42 | - /* @var $email Member_ForgotPasswordEmail */ |
|
| 43 | - $email = Member_ForgotPasswordEmail::create(); |
|
| 44 | - $email->populateTemplate($member); |
|
| 45 | - $email->populateTemplate(array( |
|
| 46 | - 'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token) |
|
| 47 | - )); |
|
| 48 | - $email->setTo($member->Email); |
|
| 49 | - $email->send(); |
|
| 42 | + /* @var $email Member_ForgotPasswordEmail */ |
|
| 43 | + $email = Member_ForgotPasswordEmail::create(); |
|
| 44 | + $email->populateTemplate($member); |
|
| 45 | + $email->populateTemplate(array( |
|
| 46 | + 'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token) |
|
| 47 | + )); |
|
| 48 | + $email->setTo($member->Email); |
|
| 49 | + $email->send(); |
|
| 50 | 50 | |
| 51 | - $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email'])); |
|
| 52 | - } elseif ($data['Email']) { |
|
| 53 | - // Avoid information disclosure by displaying the same status, |
|
| 54 | - // regardless wether the email address actually exists |
|
| 55 | - $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email'])); |
|
| 56 | - } else { |
|
| 57 | - $this->sessionMessage( |
|
| 58 | - _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'), |
|
| 59 | - 'bad' |
|
| 60 | - ); |
|
| 51 | + $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email'])); |
|
| 52 | + } elseif ($data['Email']) { |
|
| 53 | + // Avoid information disclosure by displaying the same status, |
|
| 54 | + // regardless wether the email address actually exists |
|
| 55 | + $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email'])); |
|
| 56 | + } else { |
|
| 57 | + $this->sessionMessage( |
|
| 58 | + _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'), |
|
| 59 | + 'bad' |
|
| 60 | + ); |
|
| 61 | 61 | |
| 62 | - $this->controller->redirect('AdminSecurity/lostpassword'); |
|
| 63 | - } |
|
| 64 | - } |
|
| 62 | + $this->controller->redirect('AdminSecurity/lostpassword'); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -6,101 +6,101 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class AdminSecurity extends Security |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - private static $allowed_actions = array( |
|
| 13 | - 'passwordsent', |
|
| 14 | - 'ChangePasswordForm' |
|
| 15 | - ); |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + private static $allowed_actions = array( |
|
| 13 | + 'passwordsent', |
|
| 14 | + 'ChangePasswordForm' |
|
| 15 | + ); |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Template thats used to render the pages. |
|
| 19 | - * |
|
| 20 | - * @config |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - private static $template_main = 'AdminLogin'; |
|
| 17 | + /** |
|
| 18 | + * Template thats used to render the pages. |
|
| 19 | + * |
|
| 20 | + * @config |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + private static $template_main = 'AdminLogin'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function init() |
|
| 29 | - { |
|
| 30 | - parent::init(); |
|
| 25 | + /** |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function init() |
|
| 29 | + { |
|
| 30 | + parent::init(); |
|
| 31 | 31 | |
| 32 | - $access = new IpAccess($this->getRequest()->getIP()); |
|
| 33 | - if (!$access->hasAccess()) { |
|
| 34 | - $access->respondNoAccess($this); |
|
| 35 | - } |
|
| 32 | + $access = new IpAccess($this->getRequest()->getIP()); |
|
| 33 | + if (!$access->hasAccess()) { |
|
| 34 | + $access->respondNoAccess($this); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) { |
|
| 38 | - // this prevents loading frontend css and javscript files |
|
| 39 | - Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller'); |
|
| 40 | - Requirements::css('adminlogin/css/style.css'); |
|
| 41 | - } |
|
| 37 | + if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) { |
|
| 38 | + // this prevents loading frontend css and javscript files |
|
| 39 | + Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller'); |
|
| 40 | + Requirements::css('adminlogin/css/style.css'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - Object::useCustomClass('MemberLoginForm', 'AdminLoginForm'); |
|
| 44 | - } |
|
| 43 | + Object::useCustomClass('MemberLoginForm', 'AdminLoginForm'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param null $action |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function Link($action = null) |
|
| 51 | - { |
|
| 52 | - return "AdminSecurity/$action"; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * @param null $action |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function Link($action = null) |
|
| 51 | + { |
|
| 52 | + return "AdminSecurity/$action"; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public static function isAdminLogin() |
|
| 59 | - { |
|
| 60 | - return strstr(self::getBackUrl(), '/admin/'); |
|
| 61 | - } |
|
| 55 | + /** |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public static function isAdminLogin() |
|
| 59 | + { |
|
| 60 | + return strstr(self::getBackUrl(), '/admin/'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public static function getBackUrl() |
|
| 67 | - { |
|
| 68 | - $request = Controller::curr()->getRequest(); |
|
| 69 | - if ($url = $request->requestVar('BackURL')) { |
|
| 70 | - return $url; |
|
| 71 | - } |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 63 | + /** |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public static function getBackUrl() |
|
| 67 | + { |
|
| 68 | + $request = Controller::curr()->getRequest(); |
|
| 69 | + if ($url = $request->requestVar('BackURL')) { |
|
| 70 | + return $url; |
|
| 71 | + } |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param SS_HTTPRequest $request |
|
| 77 | - * @return SS_HTTPResponse|HTMLText |
|
| 78 | - */ |
|
| 79 | - public function passwordsent($request) |
|
| 80 | - { |
|
| 81 | - return parent::passwordsent($request); |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * @param SS_HTTPRequest $request |
|
| 77 | + * @return SS_HTTPResponse|HTMLText |
|
| 78 | + */ |
|
| 79 | + public function passwordsent($request) |
|
| 80 | + { |
|
| 81 | + return parent::passwordsent($request); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @see Security::getPasswordResetLink() |
|
| 86 | - * We overload this, so we can add the BackURL to the password resetlink |
|
| 87 | - * @param Member $member |
|
| 88 | - * @param string $autologinToken |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public static function getPasswordResetLink($member, $autologinToken) |
|
| 92 | - { |
|
| 93 | - $autologinToken = urldecode($autologinToken); |
|
| 94 | - $selfControllerClass = __CLASS__; |
|
| 95 | - $selfController = new $selfControllerClass(); |
|
| 96 | - return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken"; |
|
| 97 | - } |
|
| 84 | + /** |
|
| 85 | + * @see Security::getPasswordResetLink() |
|
| 86 | + * We overload this, so we can add the BackURL to the password resetlink |
|
| 87 | + * @param Member $member |
|
| 88 | + * @param string $autologinToken |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public static function getPasswordResetLink($member, $autologinToken) |
|
| 92 | + { |
|
| 93 | + $autologinToken = urldecode($autologinToken); |
|
| 94 | + $selfControllerClass = __CLASS__; |
|
| 95 | + $selfController = new $selfControllerClass(); |
|
| 96 | + return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken"; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return ChangePasswordForm |
|
| 101 | - */ |
|
| 102 | - public function ChangePasswordForm() |
|
| 103 | - { |
|
| 104 | - return new ChangePasswordForm($this, 'ChangePasswordForm'); |
|
| 105 | - } |
|
| 99 | + /** |
|
| 100 | + * @return ChangePasswordForm |
|
| 101 | + */ |
|
| 102 | + public function ChangePasswordForm() |
|
| 103 | + { |
|
| 104 | + return new ChangePasswordForm($this, 'ChangePasswordForm'); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -13,166 +13,166 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class IpAccess extends Object |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $allowedIps = array(); |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $allowedIps = array(); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @config |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - private static $allowed_ips = array(); |
|
| 21 | + /** |
|
| 22 | + * @config |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + private static $allowed_ips = array(); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - private $ip = ''; |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + private $ip = ''; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * IpAccess constructor. |
|
| 34 | - * |
|
| 35 | - * @param string $ip |
|
| 36 | - * @param array $allowedIps |
|
| 37 | - */ |
|
| 38 | - public function __construct($ip = '', $allowedIps = array()) |
|
| 39 | - { |
|
| 40 | - parent::__construct(); |
|
| 41 | - $this->ip = $ip; |
|
| 32 | + /** |
|
| 33 | + * IpAccess constructor. |
|
| 34 | + * |
|
| 35 | + * @param string $ip |
|
| 36 | + * @param array $allowedIps |
|
| 37 | + */ |
|
| 38 | + public function __construct($ip = '', $allowedIps = array()) |
|
| 39 | + { |
|
| 40 | + parent::__construct(); |
|
| 41 | + $this->ip = $ip; |
|
| 42 | 42 | |
| 43 | - self::config()->allowed_ips = $allowedIps; |
|
| 44 | - } |
|
| 43 | + self::config()->allowed_ips = $allowedIps; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param $ip |
|
| 48 | - */ |
|
| 49 | - public function setIp($ip) |
|
| 50 | - { |
|
| 51 | - $this->ip = $ip; |
|
| 52 | - } |
|
| 46 | + /** |
|
| 47 | + * @param $ip |
|
| 48 | + */ |
|
| 49 | + public function setIp($ip) |
|
| 50 | + { |
|
| 51 | + $this->ip = $ip; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function getAllowedIps() |
|
| 58 | - { |
|
| 59 | - if ($this->allowedIps) { |
|
| 60 | - Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead'); |
|
| 61 | - self::config()->allowed_ips = $this->allowedIps; |
|
| 62 | - } |
|
| 63 | - return (array)self::config()->allowed_ips; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function getAllowedIps() |
|
| 58 | + { |
|
| 59 | + if ($this->allowedIps) { |
|
| 60 | + Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead'); |
|
| 61 | + self::config()->allowed_ips = $this->allowedIps; |
|
| 62 | + } |
|
| 63 | + return (array)self::config()->allowed_ips; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function hasAccess() |
|
| 70 | - { |
|
| 71 | - if (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
| 72 | - || empty($this->getAllowedIps()) |
|
| 73 | - || $this->matchExact() |
|
| 74 | - || $this->matchRange() |
|
| 75 | - || $this->matchCIDR() |
|
| 76 | - || $this->matchWildCard()) |
|
| 77 | - { |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 66 | + /** |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function hasAccess() |
|
| 70 | + { |
|
| 71 | + if (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
| 72 | + || empty($this->getAllowedIps()) |
|
| 73 | + || $this->matchExact() |
|
| 74 | + || $this->matchRange() |
|
| 75 | + || $this->matchCIDR() |
|
| 76 | + || $this->matchWildCard()) |
|
| 77 | + { |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return false; |
|
| 82 | - } |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param Controller $controller |
|
| 86 | - * @throws SS_HTTPResponse_Exception |
|
| 87 | - */ |
|
| 88 | - public function respondNoAccess(Controller $controller) |
|
| 89 | - { |
|
| 90 | - $response = null; |
|
| 91 | - if (class_exists('ErrorPage', true)) { |
|
| 92 | - $response = ErrorPage::response_for(403); |
|
| 93 | - } |
|
| 94 | - $controller->httpError(403, $response ? $response : 'The requested page could not be found.'); |
|
| 95 | - } |
|
| 84 | + /** |
|
| 85 | + * @param Controller $controller |
|
| 86 | + * @throws SS_HTTPResponse_Exception |
|
| 87 | + */ |
|
| 88 | + public function respondNoAccess(Controller $controller) |
|
| 89 | + { |
|
| 90 | + $response = null; |
|
| 91 | + if (class_exists('ErrorPage', true)) { |
|
| 92 | + $response = ErrorPage::response_for(403); |
|
| 93 | + } |
|
| 94 | + $controller->httpError(403, $response ? $response : 'The requested page could not be found.'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function matchExact() |
|
| 101 | - { |
|
| 102 | - return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : ''; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function matchExact() |
|
| 101 | + { |
|
| 102 | + return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : ''; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Try to match against a ip range |
|
| 107 | - * |
|
| 108 | - * Example : 192.168.1.50-100 |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function matchRange() |
|
| 113 | - { |
|
| 114 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 115 | - return strstr($ip, '-'); |
|
| 116 | - }) |
|
| 117 | - ) { |
|
| 118 | - foreach ($ranges as $range) { |
|
| 119 | - $first = substr($range, 0, strrpos($range, '.') + 1); |
|
| 120 | - $last = substr(strrchr($range, '.'), 1); |
|
| 121 | - list ($start, $end) = explode('-', $last); |
|
| 122 | - for ($i = $start; $i <= $end; $i++) { |
|
| 123 | - if ($this->ip === $first . $i) { |
|
| 124 | - return $range; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 105 | + /** |
|
| 106 | + * Try to match against a ip range |
|
| 107 | + * |
|
| 108 | + * Example : 192.168.1.50-100 |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function matchRange() |
|
| 113 | + { |
|
| 114 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 115 | + return strstr($ip, '-'); |
|
| 116 | + }) |
|
| 117 | + ) { |
|
| 118 | + foreach ($ranges as $range) { |
|
| 119 | + $first = substr($range, 0, strrpos($range, '.') + 1); |
|
| 120 | + $last = substr(strrchr($range, '.'), 1); |
|
| 121 | + list ($start, $end) = explode('-', $last); |
|
| 122 | + for ($i = $start; $i <= $end; $i++) { |
|
| 123 | + if ($this->ip === $first . $i) { |
|
| 124 | + return $range; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Try to match cidr range |
|
| 134 | - * |
|
| 135 | - * Example : 192.168.1.0/24 |
|
| 136 | - * |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function matchCIDR() |
|
| 140 | - { |
|
| 141 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 142 | - return strstr($ip, '/'); |
|
| 143 | - }) |
|
| 144 | - ) { |
|
| 145 | - foreach ($ranges as $cidr) { |
|
| 146 | - list ($net, $mask) = explode('/', $cidr); |
|
| 147 | - if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) { |
|
| 148 | - return $cidr; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - return ''; |
|
| 153 | - } |
|
| 132 | + /** |
|
| 133 | + * Try to match cidr range |
|
| 134 | + * |
|
| 135 | + * Example : 192.168.1.0/24 |
|
| 136 | + * |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function matchCIDR() |
|
| 140 | + { |
|
| 141 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 142 | + return strstr($ip, '/'); |
|
| 143 | + }) |
|
| 144 | + ) { |
|
| 145 | + foreach ($ranges as $cidr) { |
|
| 146 | + list ($net, $mask) = explode('/', $cidr); |
|
| 147 | + if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) { |
|
| 148 | + return $cidr; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + return ''; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Try to match against a range that ends with a wildcard * |
|
| 157 | - * |
|
| 158 | - * Example : 192.168.1.* |
|
| 159 | - * Example : 192.168.* |
|
| 160 | - * |
|
| 161 | - * @return string |
|
| 162 | - */ |
|
| 163 | - public function matchWildCard() |
|
| 164 | - { |
|
| 165 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 166 | - return substr($ip, -1) === '*'; |
|
| 167 | - }) |
|
| 168 | - ) { |
|
| 169 | - foreach ($ranges as $range) { |
|
| 170 | - if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) { |
|
| 171 | - return $range; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - return ''; |
|
| 176 | - } |
|
| 155 | + /** |
|
| 156 | + * Try to match against a range that ends with a wildcard * |
|
| 157 | + * |
|
| 158 | + * Example : 192.168.1.* |
|
| 159 | + * Example : 192.168.* |
|
| 160 | + * |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 163 | + public function matchWildCard() |
|
| 164 | + { |
|
| 165 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
| 166 | + return substr($ip, -1) === '*'; |
|
| 167 | + }) |
|
| 168 | + ) { |
|
| 169 | + foreach ($ranges as $range) { |
|
| 170 | + if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) { |
|
| 171 | + return $range; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + return ''; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | } |
@@ -7,14 +7,14 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class LimitAdminAccessExtension extends Extension |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return mixed |
|
| 12 | - */ |
|
| 13 | - public function onBeforeInit() |
|
| 14 | - { |
|
| 15 | - $access = new IpAccess($this->owner->getRequest()->getIP()); |
|
| 16 | - if (!$access->hasAccess()) { |
|
| 17 | - $access->respondNoAccess($this->owner); |
|
| 18 | - } |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * @return mixed |
|
| 12 | + */ |
|
| 13 | + public function onBeforeInit() |
|
| 14 | + { |
|
| 15 | + $access = new IpAccess($this->owner->getRequest()->getIP()); |
|
| 16 | + if (!$access->hasAccess()) { |
|
| 17 | + $access->respondNoAccess($this->owner); |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | 20 | } |