Completed
Push — master ( 968ba1...24c107 )
by Martijn van
02:33
created
code/AdminSecurity.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
      * We overload this, so we can add the BackURL to the password resetlink
96 96
      *
97 97
      * @param Member $member
98
-     * @param $autologinToken
98
+     * @param string $autologinToken
99 99
      * @return string
100 100
      */
101 101
     public static function getPasswordResetLink($member, $autologinToken)
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@
 block discarded – undo
7 7
  */
8 8
 class AdminSecurity extends Security
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    private static $allowed_actions = array(
14
-        'passwordsent',
15
-        'ChangePasswordForm'
16
-    );
10
+	/**
11
+	 * @var array
12
+	 */
13
+	private static $allowed_actions = array(
14
+		'passwordsent',
15
+		'ChangePasswordForm'
16
+	);
17 17
 
18
-    /**
19
-     * Template thats used to render the pages.
20
-     *
21
-     * @config
22
-     * @var string
23
-     */
24
-    private static $template_main = 'AdminLogin';
18
+	/**
19
+	 * Template thats used to render the pages.
20
+	 *
21
+	 * @config
22
+	 * @var string
23
+	 */
24
+	private static $template_main = 'AdminLogin';
25 25
 
26
-    /**
27
-     * @return void
28
-     */
29
-    public function init()
30
-    {
31
-        parent::init();
26
+	/**
27
+	 * @return void
28
+	 */
29
+	public function init()
30
+	{
31
+		parent::init();
32 32
 
33
-        if (Config::inst()->get('IpAccess', 'enabled')) {
34
-            $ipAccess = new IpAccess($this->getRequest()->getIP(),
35
-                Config::inst()->get('IpAccess', 'allowed_ips'));
36
-            if (!$ipAccess->hasAccess()) {
37
-                $response = null;
38
-                if (class_exists('ErrorPage', true)) {
39
-                    $response = ErrorPage::response_for(404);
40
-                }
41
-                $this->httpError(404, $response ? $response : 'The requested page could not be found.');
42
-                return;
43
-            }
44
-        }
33
+		if (Config::inst()->get('IpAccess', 'enabled')) {
34
+			$ipAccess = new IpAccess($this->getRequest()->getIP(),
35
+				Config::inst()->get('IpAccess', 'allowed_ips'));
36
+			if (!$ipAccess->hasAccess()) {
37
+				$response = null;
38
+				if (class_exists('ErrorPage', true)) {
39
+					$response = ErrorPage::response_for(404);
40
+				}
41
+				$this->httpError(404, $response ? $response : 'The requested page could not be found.');
42
+				return;
43
+			}
44
+		}
45 45
 
46
-        if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
47
-            // this prevents loading frontend css and javscript files
48
-            Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
49
-            Requirements::css('adminlogin/css/style.css');
50
-        }
46
+		if (Config::inst()->get('AdminLogin', 'UseTheme') !== true) {
47
+			// this prevents loading frontend css and javscript files
48
+			Object::useCustomClass('Page_Controller', 'AdminLoginPage_Controller');
49
+			Requirements::css('adminlogin/css/style.css');
50
+		}
51 51
 
52
-        Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
53
-    }
52
+		Object::useCustomClass('MemberLoginForm', 'AdminLoginForm');
53
+	}
54 54
 
55
-    /**
56
-     * @param null $action
57
-     * @return string
58
-     */
59
-    public function Link($action = null)
60
-    {
61
-        return "AdminSecurity/$action";
62
-    }
55
+	/**
56
+	 * @param null $action
57
+	 * @return string
58
+	 */
59
+	public function Link($action = null)
60
+	{
61
+		return "AdminSecurity/$action";
62
+	}
63 63
 
64
-    /**
65
-     * @return string
66
-     */
67
-    public static function isAdminLogin()
68
-    {
69
-        return strstr(self::getBackUrl(), '/admin/');
70
-    }
64
+	/**
65
+	 * @return string
66
+	 */
67
+	public static function isAdminLogin()
68
+	{
69
+		return strstr(self::getBackUrl(), '/admin/');
70
+	}
71 71
 
72
-    /**
73
-     * @return string
74
-     */
75
-    public static function getBackUrl()
76
-    {
77
-        $request = Controller::curr()->getRequest();
78
-        if($url = $request->requestVar('BackURL')) {
79
-            return $url;
80
-        }
81
-        return '';
82
-    }
72
+	/**
73
+	 * @return string
74
+	 */
75
+	public static function getBackUrl()
76
+	{
77
+		$request = Controller::curr()->getRequest();
78
+		if($url = $request->requestVar('BackURL')) {
79
+			return $url;
80
+		}
81
+		return '';
82
+	}
83 83
 
84
-    /**
85
-     * @param SS_HTTPRequest $request
86
-     * @return string
87
-     */
88
-    public function passwordsent($request)
89
-    {
90
-        return parent::passwordsent($request);
91
-    }
84
+	/**
85
+	 * @param SS_HTTPRequest $request
86
+	 * @return string
87
+	 */
88
+	public function passwordsent($request)
89
+	{
90
+		return parent::passwordsent($request);
91
+	}
92 92
 
93
-    /**
94
-     * @see Security::getPasswordResetLink()
95
-     * We overload this, so we can add the BackURL to the password resetlink
96
-     *
97
-     * @param Member $member
98
-     * @param $autologinToken
99
-     * @return string
100
-     */
101
-    public static function getPasswordResetLink($member, $autologinToken)
102
-    {
103
-        $autologinToken      = urldecode($autologinToken);
104
-        $selfControllerClass = __CLASS__;
105
-        $selfController      = new $selfControllerClass();
106
-        return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
107
-    }
93
+	/**
94
+	 * @see Security::getPasswordResetLink()
95
+	 * We overload this, so we can add the BackURL to the password resetlink
96
+	 *
97
+	 * @param Member $member
98
+	 * @param $autologinToken
99
+	 * @return string
100
+	 */
101
+	public static function getPasswordResetLink($member, $autologinToken)
102
+	{
103
+		$autologinToken      = urldecode($autologinToken);
104
+		$selfControllerClass = __CLASS__;
105
+		$selfController      = new $selfControllerClass();
106
+		return $selfController->Link('changepassword') . "?m={$member->ID}&t=$autologinToken";
107
+	}
108 108
 
109
-    /**
110
-     * @return ChangePasswordForm
111
-     */
112
-    public function ChangePasswordForm()
113
-    {
114
-        return new ChangePasswordForm($this, 'ChangePasswordForm');
115
-    }
109
+	/**
110
+	 * @return ChangePasswordForm
111
+	 */
112
+	public function ChangePasswordForm()
113
+	{
114
+		return new ChangePasswordForm($this, 'ChangePasswordForm');
115
+	}
116 116
 }
Please login to merge, or discard this patch.
code/model/IpAccess.php 1 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.