Completed
Push — master ( 00f01c...c33608 )
by Martijn van
02:27
created
code/model/IpAccess.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      */
78 78
     public function matchRange()
79 79
     {
80
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
80
+        if ($ranges = array_filter($this->allowedIps, function($ip) {
81 81
             return strstr($ip, '-');
82 82
         })
83 83
         ) {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function matchCIDR()
102 102
     {
103
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
103
+        if ($ranges = array_filter($this->allowedIps, function($ip) {
104 104
             return strstr($ip, '/');
105 105
         })
106 106
         ) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function matchWildCard()
122 122
     {
123
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
123
+        if ($ranges = array_filter($this->allowedIps, function($ip) {
124 124
             return substr($ip, -1) === '*';
125 125
         })
126 126
         ) {
Please login to merge, or discard this patch.
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -13,123 +13,123 @@
 block discarded – undo
13 13
  */
14 14
 class IpAccess
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    public $allowedIps = array();
16
+	/**
17
+	 * @var array
18
+	 */
19
+	public $allowedIps = array();
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    private $ip = '';
21
+	/**
22
+	 * @var string
23
+	 */
24
+	private $ip = '';
25 25
 
26
-    /**
27
-     * IpAccess constructor.
28
-     *
29
-     * @param string $ip
30
-     * @param array $allowedIps
31
-     */
32
-    public function __construct($ip = '', $allowedIps = array())
33
-    {
34
-        $this->ip         = $ip;
35
-        $this->allowedIps = $allowedIps;
36
-    }
26
+	/**
27
+	 * IpAccess constructor.
28
+	 *
29
+	 * @param string $ip
30
+	 * @param array $allowedIps
31
+	 */
32
+	public function __construct($ip = '', $allowedIps = array())
33
+	{
34
+		$this->ip         = $ip;
35
+		$this->allowedIps = $allowedIps;
36
+	}
37 37
 
38
-    /**
39
-     * @param $ip
40
-     */
41
-    public function setIp($ip)
42
-    {
43
-        $this->ip = $ip;
44
-    }
38
+	/**
39
+	 * @param $ip
40
+	 */
41
+	public function setIp($ip)
42
+	{
43
+		$this->ip = $ip;
44
+	}
45 45
 
46
-    /**
47
-     * @return string
48
-     */
49
-    public function hasAccess()
50
-    {
51
-        if (empty($this->allowedIps)) {
52
-            return 'allowed';
53
-        } elseif ($match = $this->matchExact()) {
54
-            return $match;
55
-        } elseif ($match = $this->matchRange()) {
56
-            return $match;
57
-        } elseif ($match = $this->matchCIDR()) {
58
-            return $match;
59
-        } elseif ($match = $this->matchWildCard()) {
60
-            return $match;
61
-        }
62
-    }
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function hasAccess()
50
+	{
51
+		if (empty($this->allowedIps)) {
52
+			return 'allowed';
53
+		} elseif ($match = $this->matchExact()) {
54
+			return $match;
55
+		} elseif ($match = $this->matchRange()) {
56
+			return $match;
57
+		} elseif ($match = $this->matchCIDR()) {
58
+			return $match;
59
+		} elseif ($match = $this->matchWildCard()) {
60
+			return $match;
61
+		}
62
+	}
63 63
 
64
-    /**
65
-     * @return string
66
-     */
67
-    public function matchExact()
68
-    {
69
-        if (in_array($this->ip, $this->allowedIps)) {
70
-            return $this->ip;
71
-        }
72
-    }
64
+	/**
65
+	 * @return string
66
+	 */
67
+	public function matchExact()
68
+	{
69
+		if (in_array($this->ip, $this->allowedIps)) {
70
+			return $this->ip;
71
+		}
72
+	}
73 73
 
74
-    /**
75
-     * try to match against a ip range
76
-     * Example : 192.168.1.50-100
77
-     */
78
-    public function matchRange()
79
-    {
80
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
81
-            return strstr($ip, '-');
82
-        })
83
-        ) {
84
-            foreach ($ranges as $range) {
85
-                $first = substr($range, 0, strrpos($range, '.') + 1);
86
-                $last  = substr(strrchr($range, '.'), 1);
87
-                list ($start, $end) = explode('-', $last);
88
-                for ($i = $start; $i <= $end; $i++) {
89
-                    if ($this->ip === $first . $i) {
90
-                        return $range;
91
-                    }
92
-                }
93
-            }
94
-        }
95
-    }
74
+	/**
75
+	 * try to match against a ip range
76
+	 * Example : 192.168.1.50-100
77
+	 */
78
+	public function matchRange()
79
+	{
80
+		if ($ranges = array_filter($this->allowedIps, function ($ip) {
81
+			return strstr($ip, '-');
82
+		})
83
+		) {
84
+			foreach ($ranges as $range) {
85
+				$first = substr($range, 0, strrpos($range, '.') + 1);
86
+				$last  = substr(strrchr($range, '.'), 1);
87
+				list ($start, $end) = explode('-', $last);
88
+				for ($i = $start; $i <= $end; $i++) {
89
+					if ($this->ip === $first . $i) {
90
+						return $range;
91
+					}
92
+				}
93
+			}
94
+		}
95
+	}
96 96
 
97
-    /**
98
-     * try to match cidr range
99
-     * Example : 192.168.1.0/24
100
-     */
101
-    public function matchCIDR()
102
-    {
103
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
104
-            return strstr($ip, '/');
105
-        })
106
-        ) {
107
-            foreach ($ranges as $cidr) {
108
-                list ($net, $mask) = explode('/', $cidr);
109
-                if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
110
-                    return $cidr;
111
-                }
112
-            }
113
-        }
114
-    }
97
+	/**
98
+	 * try to match cidr range
99
+	 * Example : 192.168.1.0/24
100
+	 */
101
+	public function matchCIDR()
102
+	{
103
+		if ($ranges = array_filter($this->allowedIps, function ($ip) {
104
+			return strstr($ip, '/');
105
+		})
106
+		) {
107
+			foreach ($ranges as $cidr) {
108
+				list ($net, $mask) = explode('/', $cidr);
109
+				if ((ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($net)) {
110
+					return $cidr;
111
+				}
112
+			}
113
+		}
114
+	}
115 115
 
116
-    /**
117
-     * try to match against a range that ends with a wildcard *
118
-     * Example : 192.168.1.*
119
-     * Example : 192.168.*
120
-     */
121
-    public function matchWildCard()
122
-    {
123
-        if ($ranges = array_filter($this->allowedIps, function ($ip) {
124
-            return substr($ip, -1) === '*';
125
-        })
126
-        ) {
127
-            foreach ($ranges as $range) {
128
-                if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
129
-                    return $range;
130
-                }
131
-            }
132
-        }
133
-    }
116
+	/**
117
+	 * try to match against a range that ends with a wildcard *
118
+	 * Example : 192.168.1.*
119
+	 * Example : 192.168.*
120
+	 */
121
+	public function matchWildCard()
122
+	{
123
+		if ($ranges = array_filter($this->allowedIps, function ($ip) {
124
+			return substr($ip, -1) === '*';
125
+		})
126
+		) {
127
+			foreach ($ranges as $range) {
128
+				if (substr($this->ip, 0, strlen(substr($range, 0, -1))) === substr($range, 0, -1)) {
129
+					return $range;
130
+				}
131
+			}
132
+		}
133
+	}
134 134
 
135 135
 }
Please login to merge, or discard this patch.
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/LimitAdminAccessExtension.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@
 block discarded – undo
5 5
  */
6 6
 class LimitAdminAccessExtension extends Extension
7 7
 {
8
-    /**
9
-     * @return mixed
10
-     */
11
-    public function onBeforeInit()
12
-    {
13
-        if (Config::inst()->get('IpAccess', 'enabled')) {
14
-            $ipAccess = new IpAccess($this->owner->getRequest()->getIP(),
15
-                Config::inst()->get('IpAccess', 'allowed_ips'));
8
+	/**
9
+	 * @return mixed
10
+	 */
11
+	public function onBeforeInit()
12
+	{
13
+		if (Config::inst()->get('IpAccess', 'enabled')) {
14
+			$ipAccess = new IpAccess($this->owner->getRequest()->getIP(),
15
+				Config::inst()->get('IpAccess', 'allowed_ips'));
16 16
 
17
-            if (!$ipAccess->hasAccess()) {
18
-                $response = null;
19
-                if (class_exists('ErrorPage', true)) {
20
-                    $response = ErrorPage::response_for(403);
21
-                }
17
+			if (!$ipAccess->hasAccess()) {
18
+				$response = null;
19
+				if (class_exists('ErrorPage', true)) {
20
+					$response = ErrorPage::response_for(403);
21
+				}
22 22
 
23
-                $response = ($response) ? $response : 'The requested page could not be found.';
23
+				$response = ($response) ? $response : 'The requested page could not be found.';
24 24
 
25
-                return $this->owner->httpError(403, $response);
26
-            }
27
-        }
28
-    }
25
+				return $this->owner->httpError(403, $response);
26
+			}
27
+		}
28
+	}
29 29
 }
Please login to merge, or discard this patch.
code/AdminLoginForm.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -3,63 +3,63 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
code/AdminSecurity.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -6,109 +6,109 @@
 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
-        if (Config::inst()->get('IpAccess', 'enabled')) {
33
-            $ipAccess = new IpAccess($this->getRequest()->getIP(),
34
-                Config::inst()->get('IpAccess', 'allowed_ips'));
35
-            if (!$ipAccess->hasAccess()) {
36
-                $response = null;
37
-                if (class_exists('ErrorPage', true)) {
38
-                    $response = ErrorPage::response_for(404);
39
-                }
40
-                $this->httpError(404, $response ? $response : 'The requested page could not be found.');
41
-                return;
42
-            }
43
-        }
32
+		if (Config::inst()->get('IpAccess', 'enabled')) {
33
+			$ipAccess = new IpAccess($this->getRequest()->getIP(),
34
+				Config::inst()->get('IpAccess', 'allowed_ips'));
35
+			if (!$ipAccess->hasAccess()) {
36
+				$response = null;
37
+				if (class_exists('ErrorPage', true)) {
38
+					$response = ErrorPage::response_for(404);
39
+				}
40
+				$this->httpError(404, $response ? $response : 'The requested page could not be found.');
41
+				return;
42
+			}
43
+		}
44 44
 
45
-        if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
46
-            // this prevents loading frontend css and javscript files
47
-            Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
48
-            Requirements::css('adminlogin/css/style.css');
49
-        }
45
+		if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
46
+			// this prevents loading frontend css and javscript files
47
+			Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
48
+			Requirements::css('adminlogin/css/style.css');
49
+		}
50 50
 
51
-        Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
52
-    }
51
+		Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
52
+	}
53 53
 
54
-    /**
55
-     * @param null $action
56
-     * @return string
57
-     */
58
-    public function Link($action = null)
59
-    {
60
-        return "AdminSecurity/$action";
61
-    }
54
+	/**
55
+	 * @param null $action
56
+	 * @return string
57
+	 */
58
+	public function Link($action = null)
59
+	{
60
+		return "AdminSecurity/$action";
61
+	}
62 62
 
63
-    /**
64
-     * @return string
65
-     */
66
-    public static function isAdminLogin()
67
-    {
68
-        return strstr(self::getBackUrl(), '/admin/');
69
-    }
63
+	/**
64
+	 * @return string
65
+	 */
66
+	public static function isAdminLogin()
67
+	{
68
+		return strstr(self::getBackUrl(), '/admin/');
69
+	}
70 70
 
71
-    /**
72
-     * @return string
73
-     */
74
-    public static function getBackUrl()
75
-    {
76
-        $request = Controller::curr()->getRequest();
77
-        if ($url = $request->requestVar('BackURL')) {
78
-            return $url;
79
-        }
80
-        return '';
81
-    }
71
+	/**
72
+	 * @return string
73
+	 */
74
+	public static function getBackUrl()
75
+	{
76
+		$request = Controller::curr()->getRequest();
77
+		if ($url = $request->requestVar('BackURL')) {
78
+			return $url;
79
+		}
80
+		return '';
81
+	}
82 82
 
83
-    /**
84
-     * @param SS_HTTPRequest $request
85
-     * @return string
86
-     */
87
-    public function passwordsent($request)
88
-    {
89
-        return parent::passwordsent($request);
90
-    }
83
+	/**
84
+	 * @param SS_HTTPRequest $request
85
+	 * @return string
86
+	 */
87
+	public function passwordsent($request)
88
+	{
89
+		return parent::passwordsent($request);
90
+	}
91 91
 
92
-    /**
93
-     * @see Security::getPasswordResetLink()
94
-     * We overload this, so we can add the BackURL to the password resetlink
95
-     * @param Member $member
96
-     * @param string $autologinToken
97
-     * @return string
98
-     */
99
-    public static function getPasswordResetLink($member, $autologinToken)
100
-    {
101
-        $autologinToken      = urldecode($autologinToken);
102
-        $selfControllerClass = __CLASS__;
103
-        $selfController      = new $selfControllerClass();
104
-        return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
105
-    }
92
+	/**
93
+	 * @see Security::getPasswordResetLink()
94
+	 * We overload this, so we can add the BackURL to the password resetlink
95
+	 * @param Member $member
96
+	 * @param string $autologinToken
97
+	 * @return string
98
+	 */
99
+	public static function getPasswordResetLink($member, $autologinToken)
100
+	{
101
+		$autologinToken      = urldecode($autologinToken);
102
+		$selfControllerClass = __CLASS__;
103
+		$selfController      = new $selfControllerClass();
104
+		return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
105
+	}
106 106
 
107
-    /**
108
-     * @return ChangePasswordForm
109
-     */
110
-    public function ChangePasswordForm()
111
-    {
112
-        return new ChangePasswordForm($this, 'ChangePasswordForm');
113
-    }
107
+	/**
108
+	 * @return ChangePasswordForm
109
+	 */
110
+	public function ChangePasswordForm()
111
+	{
112
+		return new ChangePasswordForm($this, 'ChangePasswordForm');
113
+	}
114 114
 }
Please login to merge, or discard this patch.