Completed
Push — master ( 311eb2...4aec60 )
by Martijn van
02:28
created
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|null
66
-     */
67
-    public function matchExact()
68
-    {
69
-        if (in_array($this->ip, $this->allowedIps)) {
70
-            return $this->ip;
71
-        }
72
-    }
64
+	/**
65
+	 * @return string|null
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/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 SS_HTTPResponse|HTMLText
86
-     */
87
-    public function passwordsent($request)
88
-    {
89
-        return parent::passwordsent($request);
90
-    }
83
+	/**
84
+	 * @param SS_HTTPRequest $request
85
+	 * @return SS_HTTPResponse|HTMLText
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.