@@ -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 | } |
@@ -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 | } |
@@ -13,161 +13,161 @@ |
||
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 (!empty($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 (!empty($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 | - return (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
72 | - || empty($this->getAllowedIps()) |
|
73 | - || $this->matchExact() |
|
74 | - || $this->matchRange() |
|
75 | - || $this->matchCIDR() |
|
76 | - || $this->matchWildCard()); |
|
77 | - } |
|
66 | + /** |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function hasAccess() |
|
70 | + { |
|
71 | + return (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
72 | + || empty($this->getAllowedIps()) |
|
73 | + || $this->matchExact() |
|
74 | + || $this->matchRange() |
|
75 | + || $this->matchCIDR() |
|
76 | + || $this->matchWildCard()); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param Controller $controller |
|
81 | - * @throws SS_HTTPResponse_Exception |
|
82 | - */ |
|
83 | - public function respondNoAccess(Controller $controller) |
|
84 | - { |
|
85 | - $response = null; |
|
86 | - if (class_exists('ErrorPage', true)) { |
|
87 | - $response = ErrorPage::response_for(403); |
|
88 | - } |
|
89 | - $controller->httpError(403, $response ? $response : 'The requested page could not be found.'); |
|
90 | - } |
|
79 | + /** |
|
80 | + * @param Controller $controller |
|
81 | + * @throws SS_HTTPResponse_Exception |
|
82 | + */ |
|
83 | + public function respondNoAccess(Controller $controller) |
|
84 | + { |
|
85 | + $response = null; |
|
86 | + if (class_exists('ErrorPage', true)) { |
|
87 | + $response = ErrorPage::response_for(403); |
|
88 | + } |
|
89 | + $controller->httpError(403, $response ? $response : 'The requested page could not be found.'); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function matchExact() |
|
96 | - { |
|
97 | - return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : ''; |
|
98 | - } |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function matchExact() |
|
96 | + { |
|
97 | + return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : ''; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Try to match against a ip range |
|
102 | - * |
|
103 | - * Example : 192.168.1.50-100 |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function matchRange() |
|
108 | - { |
|
109 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
110 | - return strstr($ip, '-'); |
|
111 | - }) |
|
112 | - ) { |
|
113 | - foreach ($ranges as $range) { |
|
114 | - $first = substr($range, 0, strrpos($range, '.') + 1); |
|
115 | - $last = substr(strrchr($range, '.'), 1); |
|
116 | - list ($start, $end) = explode('-', $last); |
|
117 | - for ($i = $start; $i <= $end; $i++) { |
|
118 | - if ($this->ip === $first . $i) { |
|
119 | - return $range; |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - return ''; |
|
125 | - } |
|
100 | + /** |
|
101 | + * Try to match against a ip range |
|
102 | + * |
|
103 | + * Example : 192.168.1.50-100 |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function matchRange() |
|
108 | + { |
|
109 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
110 | + return strstr($ip, '-'); |
|
111 | + }) |
|
112 | + ) { |
|
113 | + foreach ($ranges as $range) { |
|
114 | + $first = substr($range, 0, strrpos($range, '.') + 1); |
|
115 | + $last = substr(strrchr($range, '.'), 1); |
|
116 | + list ($start, $end) = explode('-', $last); |
|
117 | + for ($i = $start; $i <= $end; $i++) { |
|
118 | + if ($this->ip === $first . $i) { |
|
119 | + return $range; |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + return ''; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Try to match cidr range |
|
129 | - * |
|
130 | - * Example : 192.168.1.0/24 |
|
131 | - * |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function matchCIDR() |
|
135 | - { |
|
136 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
137 | - return strstr($ip, '/'); |
|
138 | - }) |
|
139 | - ) { |
|
140 | - foreach ($ranges as $cidr) { |
|
141 | - list ($net, $mask) = explode('/', $cidr); |
|
142 | - if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) { |
|
143 | - return $cidr; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - return ''; |
|
148 | - } |
|
127 | + /** |
|
128 | + * Try to match cidr range |
|
129 | + * |
|
130 | + * Example : 192.168.1.0/24 |
|
131 | + * |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function matchCIDR() |
|
135 | + { |
|
136 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
137 | + return strstr($ip, '/'); |
|
138 | + }) |
|
139 | + ) { |
|
140 | + foreach ($ranges as $cidr) { |
|
141 | + list ($net, $mask) = explode('/', $cidr); |
|
142 | + if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) { |
|
143 | + return $cidr; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + return ''; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Try to match against a range that ends with a wildcard * |
|
152 | - * |
|
153 | - * Example : 192.168.1.* |
|
154 | - * Example : 192.168.* |
|
155 | - * |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function matchWildCard() |
|
159 | - { |
|
160 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
161 | - return substr($ip, -1) === '*'; |
|
162 | - }) |
|
163 | - ) { |
|
164 | - foreach ($ranges as $range) { |
|
165 | - if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) { |
|
166 | - return $range; |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
170 | - return ''; |
|
171 | - } |
|
150 | + /** |
|
151 | + * Try to match against a range that ends with a wildcard * |
|
152 | + * |
|
153 | + * Example : 192.168.1.* |
|
154 | + * Example : 192.168.* |
|
155 | + * |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function matchWildCard() |
|
159 | + { |
|
160 | + if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
161 | + return substr($ip, -1) === '*'; |
|
162 | + }) |
|
163 | + ) { |
|
164 | + foreach ($ranges as $range) { |
|
165 | + if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) { |
|
166 | + return $range; |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | + return ''; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | Deprecation::notice('1.1', 'Use the "IpAccess.allowed_ips" config setting instead'); |
61 | 61 | self::config()->allowed_ips = $this->allowedIps; |
62 | 62 | } |
63 | - return (array)self::config()->allowed_ips; |
|
63 | + return (array) self::config()->allowed_ips; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function hasAccess() |
70 | 70 | { |
71 | - return (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
71 | + return (!(bool) Config::inst()->get('IpAccess', 'enabled') |
|
72 | 72 | || empty($this->getAllowedIps()) |
73 | 73 | || $this->matchExact() |
74 | 74 | || $this->matchRange() |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function matchRange() |
108 | 108 | { |
109 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
109 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
110 | 110 | return strstr($ip, '-'); |
111 | 111 | }) |
112 | 112 | ) { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function matchCIDR() |
135 | 135 | { |
136 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
136 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
137 | 137 | return strstr($ip, '/'); |
138 | 138 | }) |
139 | 139 | ) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function matchWildCard() |
159 | 159 | { |
160 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
160 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
161 | 161 | return substr($ip, -1) === '*'; |
162 | 162 | }) |
163 | 163 | ) { |