@@ -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 | } |
@@ -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 | - if (!(bool)Config::inst()->get('IpAccess', 'enabled') |
|
71 | + if (!(bool) Config::inst()->get('IpAccess', 'enabled') |
|
72 | 72 | || empty($this->getAllowedIps()) |
73 | 73 | || $this->matchExact() |
74 | 74 | || $this->matchRange() |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function matchRange() |
113 | 113 | { |
114 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
114 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
115 | 115 | return strstr($ip, '-'); |
116 | 116 | }) |
117 | 117 | ) { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function matchCIDR() |
140 | 140 | { |
141 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
141 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
142 | 142 | return strstr($ip, '/'); |
143 | 143 | }) |
144 | 144 | ) { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function matchWildCard() |
164 | 164 | { |
165 | - if ($ranges = array_filter($this->getAllowedIps(), function ($ip) { |
|
165 | + if ($ranges = array_filter($this->getAllowedIps(), function($ip) { |
|
166 | 166 | return substr($ip, -1) === '*'; |
167 | 167 | }) |
168 | 168 | ) { |
@@ -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 | } |