Passed
Push — master ( f82025...71b901 )
by Martijn van
02:54
created
code/AdminLoginExtension.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
code/AdminSecurity.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -6,101 +6,101 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
code/LimitAdminAccessExtension.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
code/AdminLoginForm.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
      */
32 32
     public function forgotPassword($data)
33 33
     {
34
-        if($data['Email']) {
34
+        if ($data['Email']) {
35 35
             /* @var $member Member */
36
-            if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
36
+            if ($member = Member::get()->where("Email = '" . Convert::raw2sql($data['Email']) . "'")->first()) {
37 37
                 $token = $member->generateAutologinTokenAndStoreHash();
38 38
                 $this->sendPasswordResetLinkEmail($member, $token);
39 39
             }
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -6,67 +6,67 @@
 block discarded – undo
6 6
 class AdminLoginForm extends MemberLoginForm
7 7
 {
8 8
 
9
-    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
10
-    {
11
-        parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
9
+	public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
10
+	{
11
+		parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
12 12
 
13
-        if ($this->Actions()->fieldByName('forgotPassword')) {
14
-            // replaceField won't work, since it's a dataless field
15
-            $this->Actions()->removeByName('forgotPassword');
16
-            $this->Actions()->push(new LiteralField(
17
-                'forgotPassword',
18
-                '<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">'
19
-                . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
20
-            ));
21
-        }
13
+		if ($this->Actions()->fieldByName('forgotPassword')) {
14
+			// replaceField won't work, since it's a dataless field
15
+			$this->Actions()->removeByName('forgotPassword');
16
+			$this->Actions()->push(new LiteralField(
17
+				'forgotPassword',
18
+				'<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">'
19
+				. _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
20
+			));
21
+		}
22 22
 
23
-        Requirements::customScript(<<<JS
23
+		Requirements::customScript(<<<JS
24 24
 			(function() {
25 25
 				var el = document.getElementById("AdminLoginForm_LoginForm_Email");
26 26
 				if(el && el.focus) el.focus();
27 27
 			})();
28 28
 JS
29
-        );
30
-    }
29
+		);
30
+	}
31 31
 
32
-    /**
33
-     * @param array $data
34
-     * @return SS_HTTPResponse
35
-     */
36
-    public function forgotPassword($data)
37
-    {
38
-        if($data['Email']) {
39
-            /* @var $member Member */
40
-            if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
41
-                $token = $member->generateAutologinTokenAndStoreHash();
42
-                $this->sendPasswordResetLinkEmail($member, $token);
43
-            }
32
+	/**
33
+	 * @param array $data
34
+	 * @return SS_HTTPResponse
35
+	 */
36
+	public function forgotPassword($data)
37
+	{
38
+		if($data['Email']) {
39
+			/* @var $member Member */
40
+			if ($member = Member::get()->where("Email = '".Convert::raw2sql($data['Email'])."'")->first()) {
41
+				$token = $member->generateAutologinTokenAndStoreHash();
42
+				$this->sendPasswordResetLinkEmail($member, $token);
43
+			}
44 44
 
45
-            return $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email']));
46
-        }
45
+			return $this->controller->redirect('AdminSecurity/passwordsent/' . urlencode($data['Email']));
46
+		}
47 47
 
48
-        $this->sessionMessage(
49
-            _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'),
50
-            'bad'
51
-        );
48
+		$this->sessionMessage(
49
+			_t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'),
50
+			'bad'
51
+		);
52 52
 
53
-        return $this->controller->redirect('AdminSecurity/lostpassword');
54
-    }
53
+		return $this->controller->redirect('AdminSecurity/lostpassword');
54
+	}
55 55
 
56
-    /**
57
-     * @param Member $member
58
-     * @param string $token
59
-     */
60
-    protected function sendPasswordResetLinkEmail($member, $token)
61
-    {
62
-        /* @var $email Member_ForgotPasswordEmail */
63
-        $email = Member_ForgotPasswordEmail::create();
64
-        $email->populateTemplate($member);
65
-        $email->populateTemplate(array(
66
-            'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token)
67
-        ));
68
-        $email->setTo($member->Email);
69
-        $email->send();
70
-    }
56
+	/**
57
+	 * @param Member $member
58
+	 * @param string $token
59
+	 */
60
+	protected function sendPasswordResetLinkEmail($member, $token)
61
+	{
62
+		/* @var $email Member_ForgotPasswordEmail */
63
+		$email = Member_ForgotPasswordEmail::create();
64
+		$email->populateTemplate($member);
65
+		$email->populateTemplate(array(
66
+			'PasswordResetLink' => AdminSecurity::getPasswordResetLink($member, $token)
67
+		));
68
+		$email->setTo($member->Email);
69
+		$email->send();
70
+	}
71 71
 
72 72
 }
Please login to merge, or discard this patch.
code/model/IpAccess.php 3 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -13,172 +13,172 @@
 block discarded – undo
13 13
  */
14 14
 class IpAccess extends Object
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    public $allowedIps = array();
20
-
21
-    /**
22
-     * @config
23
-     * @var array
24
-     */
25
-    private static $allowed_ips = array();
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    private $ip = '';
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;
42
-
43
-        self::config()->allowed_ips = $allowedIps;
44
-    }
45
-
46
-    /**
47
-     * @param $ip
48
-     */
49
-    public function setIp($ip)
50
-    {
51
-        $this->ip = $ip;
52
-    }
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 self::$allowed_ips ? self::$allowed_ips : (array)self::config()->allowed_ips;
64
-    }
65
-
66
-    /**
67
-     * @return bool
68
-     */
69
-    public function isEnabled()
70
-    {
71
-        return (bool)Config::inst()->get('IpAccess', 'enabled');
72
-    }
73
-
74
-    /**
75
-     * @return bool
76
-     */
77
-    public function hasAccess()
78
-    {
79
-        if (!$this->isEnabled() || !(bool)$this->getAllowedIps()) {
80
-            return true;
81
-        }
82
-
83
-        return $this->matchIp();
84
-    }
85
-
86
-    /**
87
-     * @return bool
88
-     */
89
-    public function matchIp()
90
-    {
91
-        return ($this->matchExact() || $this->matchRange() || $this->matchCIDR() || $this->matchWildCard());
92
-    }
93
-
94
-    /**
95
-     * @param Controller $controller
96
-     * @throws SS_HTTPResponse_Exception
97
-     */
98
-    public function respondNoAccess(Controller $controller)
99
-    {
100
-        $response = null;
101
-        if (class_exists('ErrorPage', true)) {
102
-            $response = ErrorPage::response_for(403);
103
-        }
104
-        $controller->httpError(403, $response ? $response : 'The requested page could not be found.');
105
-    }
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function matchExact()
111
-    {
112
-        return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : '';
113
-    }
114
-
115
-    /**
116
-     * Try to match against a ip range
117
-     * Example : 192.168.1.50-100
118
-     *
119
-     * @return string
120
-     */
121
-    public function matchRange()
122
-    {
123
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
124
-            return strstr($ip, '-');
125
-        });
126
-
127
-        $ip = $this->ip;
128
-
129
-        $matches = array_filter($ranges, function ($range) use ($ip) {
130
-            $ipFirstPart    = substr($ip, 0, strrpos($ip, '.') + 1);
131
-            $ipLastPart     = substr(strrchr($ip, '.'), 1);
132
-            $rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
133
-
134
-            list ($start, $end) = explode('-', substr(strrchr($range, '.'), 1));
135
-
136
-            return $ipFirstPart === $rangeFirstPart && $ipLastPart >= $start && $ipLastPart <= $end;
137
-        });
138
-
139
-        return array_shift($matches);
140
-    }
141
-
142
-    /**
143
-     * Try to match cidr range
144
-     * Example : 192.168.1.0/24
145
-     *
146
-     * @return string
147
-     */
148
-    public function matchCIDR()
149
-    {
150
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
151
-            return strstr($ip, '/');
152
-        });
153
-
154
-        if (!empty($ranges)) foreach ($ranges as $range) {
155
-            list ($net, $mask) = explode('/', $range);
156
-            if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
157
-                return $range;
158
-            }
159
-        }
160
-        return '';
161
-    }
162
-
163
-    /**
164
-     * Try to match against a range that ends with a wildcard *
165
-     * Example : 192.168.1.*
166
-     * Example : 192.168.*
167
-     *
168
-     * @return string
169
-     */
170
-    public function matchWildCard()
171
-    {
172
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
173
-            return substr($ip, -1) === '*';
174
-        });
175
-
176
-        if (!empty($ranges)) foreach ($ranges as $range) {
177
-            if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
178
-                return $range;
179
-            }
180
-        }
181
-        return '';
182
-    }
16
+	/**
17
+	 * @var array
18
+	 */
19
+	public $allowedIps = array();
20
+
21
+	/**
22
+	 * @config
23
+	 * @var array
24
+	 */
25
+	private static $allowed_ips = array();
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	private $ip = '';
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;
42
+
43
+		self::config()->allowed_ips = $allowedIps;
44
+	}
45
+
46
+	/**
47
+	 * @param $ip
48
+	 */
49
+	public function setIp($ip)
50
+	{
51
+		$this->ip = $ip;
52
+	}
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 self::$allowed_ips ? self::$allowed_ips : (array)self::config()->allowed_ips;
64
+	}
65
+
66
+	/**
67
+	 * @return bool
68
+	 */
69
+	public function isEnabled()
70
+	{
71
+		return (bool)Config::inst()->get('IpAccess', 'enabled');
72
+	}
73
+
74
+	/**
75
+	 * @return bool
76
+	 */
77
+	public function hasAccess()
78
+	{
79
+		if (!$this->isEnabled() || !(bool)$this->getAllowedIps()) {
80
+			return true;
81
+		}
82
+
83
+		return $this->matchIp();
84
+	}
85
+
86
+	/**
87
+	 * @return bool
88
+	 */
89
+	public function matchIp()
90
+	{
91
+		return ($this->matchExact() || $this->matchRange() || $this->matchCIDR() || $this->matchWildCard());
92
+	}
93
+
94
+	/**
95
+	 * @param Controller $controller
96
+	 * @throws SS_HTTPResponse_Exception
97
+	 */
98
+	public function respondNoAccess(Controller $controller)
99
+	{
100
+		$response = null;
101
+		if (class_exists('ErrorPage', true)) {
102
+			$response = ErrorPage::response_for(403);
103
+		}
104
+		$controller->httpError(403, $response ? $response : 'The requested page could not be found.');
105
+	}
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function matchExact()
111
+	{
112
+		return in_array($this->ip, $this->getAllowedIps()) ? $this->ip : '';
113
+	}
114
+
115
+	/**
116
+	 * Try to match against a ip range
117
+	 * Example : 192.168.1.50-100
118
+	 *
119
+	 * @return string
120
+	 */
121
+	public function matchRange()
122
+	{
123
+		$ranges = array_filter($this->getAllowedIps(), function ($ip) {
124
+			return strstr($ip, '-');
125
+		});
126
+
127
+		$ip = $this->ip;
128
+
129
+		$matches = array_filter($ranges, function ($range) use ($ip) {
130
+			$ipFirstPart    = substr($ip, 0, strrpos($ip, '.') + 1);
131
+			$ipLastPart     = substr(strrchr($ip, '.'), 1);
132
+			$rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
133
+
134
+			list ($start, $end) = explode('-', substr(strrchr($range, '.'), 1));
135
+
136
+			return $ipFirstPart === $rangeFirstPart && $ipLastPart >= $start && $ipLastPart <= $end;
137
+		});
138
+
139
+		return array_shift($matches);
140
+	}
141
+
142
+	/**
143
+	 * Try to match cidr range
144
+	 * Example : 192.168.1.0/24
145
+	 *
146
+	 * @return string
147
+	 */
148
+	public function matchCIDR()
149
+	{
150
+		$ranges = array_filter($this->getAllowedIps(), function ($ip) {
151
+			return strstr($ip, '/');
152
+		});
153
+
154
+		if (!empty($ranges)) foreach ($ranges as $range) {
155
+			list ($net, $mask) = explode('/', $range);
156
+			if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
157
+				return $range;
158
+			}
159
+		}
160
+		return '';
161
+	}
162
+
163
+	/**
164
+	 * Try to match against a range that ends with a wildcard *
165
+	 * Example : 192.168.1.*
166
+	 * Example : 192.168.*
167
+	 *
168
+	 * @return string
169
+	 */
170
+	public function matchWildCard()
171
+	{
172
+		$ranges = array_filter($this->getAllowedIps(), function ($ip) {
173
+			return substr($ip, -1) === '*';
174
+		});
175
+
176
+		if (!empty($ranges)) foreach ($ranges as $range) {
177
+			if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
178
+				return $range;
179
+			}
180
+		}
181
+		return '';
182
+	}
183 183
 
184 184
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
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 self::$allowed_ips ? self::$allowed_ips : (array)self::config()->allowed_ips;
63
+        return self::$allowed_ips ? self::$allowed_ips : (array) self::config()->allowed_ips;
64 64
     }
65 65
 
66 66
     /**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      */
69 69
     public function isEnabled()
70 70
     {
71
-        return (bool)Config::inst()->get('IpAccess', 'enabled');
71
+        return (bool) Config::inst()->get('IpAccess', 'enabled');
72 72
     }
73 73
 
74 74
     /**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function hasAccess()
78 78
     {
79
-        if (!$this->isEnabled() || !(bool)$this->getAllowedIps()) {
79
+        if (!$this->isEnabled() || !(bool) $this->getAllowedIps()) {
80 80
             return true;
81 81
         }
82 82
 
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function matchRange()
122 122
     {
123
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
123
+        $ranges = array_filter($this->getAllowedIps(), function($ip) {
124 124
             return strstr($ip, '-');
125 125
         });
126 126
 
127 127
         $ip = $this->ip;
128 128
 
129
-        $matches = array_filter($ranges, function ($range) use ($ip) {
129
+        $matches = array_filter($ranges, function($range) use ($ip) {
130 130
             $ipFirstPart    = substr($ip, 0, strrpos($ip, '.') + 1);
131 131
             $ipLastPart     = substr(strrchr($ip, '.'), 1);
132 132
             $rangeFirstPart = substr($range, 0, strrpos($range, '.') + 1);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public function matchCIDR()
149 149
     {
150
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
150
+        $ranges = array_filter($this->getAllowedIps(), function($ip) {
151 151
             return strstr($ip, '/');
152 152
         });
153 153
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public function matchWildCard()
171 171
     {
172
-        $ranges = array_filter($this->getAllowedIps(), function ($ip) {
172
+        $ranges = array_filter($this->getAllowedIps(), function($ip) {
173 173
             return substr($ip, -1) === '*';
174 174
         });
175 175
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -151,8 +151,10 @@  discard block
 block discarded – undo
151 151
             return strstr($ip, '/');
152 152
         });
153 153
 
154
-        if (!empty($ranges)) foreach ($ranges as $range) {
154
+        if (!empty($ranges)) {
155
+        	foreach ($ranges as $range) {
155 156
             list ($net, $mask) = explode('/', $range);
157
+        }
156 158
             if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
157 159
                 return $range;
158 160
             }
@@ -173,9 +175,11 @@  discard block
 block discarded – undo
173 175
             return substr($ip, -1) === '*';
174 176
         });
175 177
 
176
-        if (!empty($ranges)) foreach ($ranges as $range) {
178
+        if (!empty($ranges)) {
179
+        	foreach ($ranges as $range) {
177 180
             if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
178 181
                 return $range;
182
+        }
179 183
             }
180 184
         }
181 185
         return '';
Please login to merge, or discard this patch.