@@ -5,35 +5,35 @@ |
||
5 | 5 | |
6 | 6 | class Variable { |
7 | 7 | |
8 | - protected $ip; |
|
9 | - protected $input=null; |
|
10 | - protected $dir; |
|
11 | - protected $path; |
|
12 | - protected $attemps; |
|
13 | - protected $except_enabled; |
|
14 | - protected $except_accounts; |
|
15 | - protected $permission_code; |
|
8 | + protected $ip; |
|
9 | + protected $input=null; |
|
10 | + protected $dir; |
|
11 | + protected $path; |
|
12 | + protected $attemps; |
|
13 | + protected $except_enabled; |
|
14 | + protected $except_accounts; |
|
15 | + protected $permission_code; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Initializing variable. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - */ |
|
22 | - protected function initVar(){ |
|
23 | - // if(!empty(config('irfa.lockout'))){ |
|
24 | - $this->ip = Request::ip(); |
|
25 | - $this->input = Request::input(config('irfa.lockout.input_name')); |
|
26 | - $this->dir = config('irfa.lockout.lockout_file_path'); |
|
27 | - $this->attemps = config('irfa.lockout.login_attemps'); |
|
28 | - $this->except_enabled = config('irfa.lockout.enable_except_account'); |
|
29 | - $this->except_accounts = config('irfa.lockout.except_account'); |
|
30 | - $this->path = $this->dir.md5($this->input); |
|
31 | - // } |
|
32 | - } |
|
17 | + /** |
|
18 | + * Initializing variable. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + */ |
|
22 | + protected function initVar(){ |
|
23 | + // if(!empty(config('irfa.lockout'))){ |
|
24 | + $this->ip = Request::ip(); |
|
25 | + $this->input = Request::input(config('irfa.lockout.input_name')); |
|
26 | + $this->dir = config('irfa.lockout.lockout_file_path'); |
|
27 | + $this->attemps = config('irfa.lockout.login_attemps'); |
|
28 | + $this->except_enabled = config('irfa.lockout.enable_except_account'); |
|
29 | + $this->except_accounts = config('irfa.lockout.except_account'); |
|
30 | + $this->path = $this->dir.md5($this->input); |
|
31 | + // } |
|
32 | + } |
|
33 | 33 | |
34 | - protected function setPath($username){ |
|
35 | - $this->path = $this->dir.md5($username); |
|
36 | - $this->input = $username; |
|
37 | - } |
|
34 | + protected function setPath($username){ |
|
35 | + $this->path = $this->dir.md5($username); |
|
36 | + $this->input = $username; |
|
37 | + } |
|
38 | 38 | |
39 | - } |
|
40 | 39 | \ No newline at end of file |
40 | + } |
|
41 | 41 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | class Variable { |
7 | 7 | |
8 | 8 | protected $ip; |
9 | - protected $input=null; |
|
9 | + protected $input = null; |
|
10 | 10 | protected $dir; |
11 | 11 | protected $path; |
12 | 12 | protected $attemps; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return void |
21 | 21 | */ |
22 | - protected function initVar(){ |
|
22 | + protected function initVar() { |
|
23 | 23 | // if(!empty(config('irfa.lockout'))){ |
24 | 24 | $this->ip = Request::ip(); |
25 | 25 | $this->input = Request::input(config('irfa.lockout.input_name')); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | // } |
32 | 32 | } |
33 | 33 | |
34 | - protected function setPath($username){ |
|
34 | + protected function setPath($username) { |
|
35 | 35 | $this->path = $this->dir.md5($username); |
36 | 36 | $this->input = $username; |
37 | 37 | } |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | protected function exceptAccount(){ |
18 | 18 | $this->initVar(); |
19 | 19 | if($this->except_enabled){ |
20 | - if(in_array($this->input, $this->except_accounts)){ |
|
20 | + if(in_array($this->input, $this->except_accounts)){ |
|
21 | 21 | return true; |
22 | - } else{ |
|
22 | + } else{ |
|
23 | 23 | return false; |
24 | - } |
|
24 | + } |
|
25 | 25 | } else{ |
26 | - return false; |
|
26 | + return false; |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @return void |
75 | 75 | */ |
76 | 76 | protected function eventCleanLockoutAccount() { |
77 | - $this->initVar(); |
|
77 | + $this->initVar(); |
|
78 | 78 | $this->unlock_account($this->input); |
79 | 79 | |
80 | 80 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @return boolean |
134 | 134 | */ |
135 | 135 | protected function lockLogin($username = null){ |
136 | - $this->initVar(); |
|
136 | + $this->initVar(); |
|
137 | 137 | if(php_sapi_name() == "cli" AND $username != null){ |
138 | 138 | $this->setPath($username); |
139 | 139 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @return boolean |
162 | 162 | */ |
163 | 163 | private function checkIp($ip_list,$ip){ |
164 | - $this->initVar(); |
|
164 | + $this->initVar(); |
|
165 | 165 | if(collect($ip_list)->contains($ip)){ |
166 | 166 | return true; |
167 | 167 | } else{ |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @return boolean |
177 | 177 | */ |
178 | 178 | public function clear_all(){ |
179 | - $this->initVar(); |
|
179 | + $this->initVar(); |
|
180 | 180 | $file = new Filesystem(); |
181 | 181 | if($file->cleanDirectory($this->path)){ |
182 | 182 | return true; |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return boolean |
16 | 16 | */ |
17 | - protected function exceptAccount(){ |
|
17 | + protected function exceptAccount() { |
|
18 | 18 | $this->initVar(); |
19 | - if($this->except_enabled){ |
|
20 | - if(in_array($this->input, $this->except_accounts)){ |
|
19 | + if ($this->except_enabled) { |
|
20 | + if (in_array($this->input, $this->except_accounts)) { |
|
21 | 21 | return true; |
22 | - } else{ |
|
22 | + } else { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - } else{ |
|
25 | + } else { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | } |
@@ -33,36 +33,36 @@ discard block |
||
33 | 33 | * @param string $username |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - protected function eventFailedLogin($username=null){ |
|
36 | + protected function eventFailedLogin($username = null) { |
|
37 | 37 | $this->initVar(); |
38 | - if($username !== null){ |
|
38 | + if ($username !== null) { |
|
39 | 39 | $this->setPath($username); |
40 | 40 | } |
41 | - if(!File::exists($this->dir)){ |
|
41 | + if (!File::exists($this->dir)) { |
|
42 | 42 | File::makeDirectory($this->dir, 0755, true); |
43 | 43 | } |
44 | 44 | |
45 | - if(!File::exists($this->path)) |
|
45 | + if (!File::exists($this->path)) |
|
46 | 46 | { |
47 | 47 | $login_fail = 1; |
48 | - } else{ |
|
48 | + } else { |
|
49 | 49 | |
50 | 50 | $get = json_decode(File::get($this->path)); |
51 | 51 | $ip_list = $get->ip; |
52 | - if(!$this->checkIp($ip_list,$this->ip)){ |
|
53 | - array_push($ip_list,$this->ip); |
|
52 | + if (!$this->checkIp($ip_list, $this->ip)) { |
|
53 | + array_push($ip_list, $this->ip); |
|
54 | 54 | } |
55 | - if($get->attemps == "lock"){ |
|
55 | + if ($get->attemps == "lock") { |
|
56 | 56 | $login_fail = "lock"; |
57 | - } else{ |
|
57 | + } else { |
|
58 | 58 | $login_fail = $get->attemps+1; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$this->ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
63 | - File::put($this->path,json_encode($content)); |
|
64 | - if(File::exists($this->path)){ |
|
65 | - chmod($this->path,0755); |
|
62 | + $content = ['username' => $this->input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$this->ip], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
63 | + File::put($this->path, json_encode($content)); |
|
64 | + if (File::exists($this->path)) { |
|
65 | + chmod($this->path, 0755); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -98,18 +98,18 @@ discard block |
||
98 | 98 | * @param string $username |
99 | 99 | * @return boolean |
100 | 100 | */ |
101 | - protected function is_locked($username){ |
|
101 | + protected function is_locked($username) { |
|
102 | 102 | $this->initVar(); |
103 | 103 | $this->setPath($username); |
104 | - if(File::exists($this->path)) |
|
104 | + if (File::exists($this->path)) |
|
105 | 105 | { |
106 | 106 | $get = json_decode(File::get($this->path)); |
107 | - if($get->attemps > $this->attemps || $get->attemps == "lock"){ |
|
107 | + if ($get->attemps > $this->attemps || $get->attemps == "lock") { |
|
108 | 108 | return true; |
109 | - } else{ |
|
109 | + } else { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | - } else{ |
|
112 | + } else { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | } |
@@ -132,19 +132,19 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return boolean |
134 | 134 | */ |
135 | - protected function lockLogin($username = null){ |
|
135 | + protected function lockLogin($username = null) { |
|
136 | 136 | $this->initVar(); |
137 | - if(php_sapi_name() == "cli" AND $username != null){ |
|
137 | + if (php_sapi_name() == "cli" AND $username != null) { |
|
138 | 138 | $this->setPath($username); |
139 | 139 | } |
140 | 140 | |
141 | - if(File::exists($this->path)) |
|
141 | + if (File::exists($this->path)) |
|
142 | 142 | { |
143 | 143 | $get = json_decode(File::get($this->path)); |
144 | - if($get->attemps == "lock"){ |
|
144 | + if ($get->attemps == "lock") { |
|
145 | 145 | return true; |
146 | 146 | } |
147 | - if($get->attemps > $this->attemps){ |
|
147 | + if ($get->attemps > $this->attemps) { |
|
148 | 148 | |
149 | 149 | return true; |
150 | 150 | } else { |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return boolean |
162 | 162 | */ |
163 | - private function checkIp($ip_list,$ip){ |
|
163 | + private function checkIp($ip_list, $ip) { |
|
164 | 164 | $this->initVar(); |
165 | - if(collect($ip_list)->contains($ip)){ |
|
165 | + if (collect($ip_list)->contains($ip)) { |
|
166 | 166 | return true; |
167 | - } else{ |
|
167 | + } else { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return boolean |
177 | 177 | */ |
178 | - public function clear_all(){ |
|
178 | + public function clear_all() { |
|
179 | 179 | $this->initVar(); |
180 | 180 | $file = new Filesystem(); |
181 | - if($file->cleanDirectory($this->path)){ |
|
181 | + if ($file->cleanDirectory($this->path)) { |
|
182 | 182 | return true; |
183 | - } else{ |
|
183 | + } else { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | } |
@@ -191,24 +191,24 @@ discard block |
||
191 | 191 | * @param string $username |
192 | 192 | * @return mixed |
193 | 193 | */ |
194 | - public function unlock_account($username){ |
|
194 | + public function unlock_account($username) { |
|
195 | 195 | $this->initVar(); |
196 | 196 | $this->setPath($username); |
197 | - if(File::exists($this->path)){ |
|
197 | + if (File::exists($this->path)) { |
|
198 | 198 | $readf = File::get($this->path); |
199 | 199 | File::delete($this->path); |
200 | - if(php_sapi_name() == "cli"){ |
|
200 | + if (php_sapi_name() == "cli") { |
|
201 | 201 | echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
202 | 202 | return $readf; |
203 | 203 | |
204 | - } else{ |
|
204 | + } else { |
|
205 | 205 | return true; |
206 | 206 | } |
207 | - } else{ |
|
208 | - if(php_sapi_name() == "cli"){ |
|
207 | + } else { |
|
208 | + if (php_sapi_name() == "cli") { |
|
209 | 209 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
210 | 210 | return false; |
211 | - } else{ |
|
211 | + } else { |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | } |
@@ -219,22 +219,22 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return mixed |
221 | 221 | */ |
222 | - public function test_unlock_account($username){ |
|
222 | + public function test_unlock_account($username) { |
|
223 | 223 | $this->initVar(); |
224 | 224 | $this->setPath($username); |
225 | - if(File::exists($this->path)){ |
|
225 | + if (File::exists($this->path)) { |
|
226 | 226 | $readf = File::get($this->path); |
227 | 227 | File::delete($this->path); |
228 | - if(php_sapi_name() == "cli"){ |
|
228 | + if (php_sapi_name() == "cli") { |
|
229 | 229 | return true; |
230 | 230 | |
231 | - } else{ |
|
231 | + } else { |
|
232 | 232 | return true; |
233 | 233 | } |
234 | - } else{ |
|
235 | - if(php_sapi_name() == "cli"){ |
|
234 | + } else { |
|
235 | + if (php_sapi_name() == "cli") { |
|
236 | 236 | return false; |
237 | - } else{ |
|
237 | + } else { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | } |
@@ -246,23 +246,23 @@ discard block |
||
246 | 246 | * @param string $username |
247 | 247 | * @return mixed |
248 | 248 | */ |
249 | - public function check_account($username){ |
|
249 | + public function check_account($username) { |
|
250 | 250 | $this->initVar(); |
251 | 251 | $this->setPath($username); |
252 | - if(File::exists($this->path)){ |
|
252 | + if (File::exists($this->path)) { |
|
253 | 253 | $readf = File::get($this->path); |
254 | - if(php_sapi_name() == "cli"){ |
|
254 | + if (php_sapi_name() == "cli") { |
|
255 | 255 | |
256 | 256 | return $readf; |
257 | 257 | |
258 | - } else{ |
|
258 | + } else { |
|
259 | 259 | return $readf; |
260 | 260 | } |
261 | - } else{ |
|
262 | - if(php_sapi_name() == "cli"){ |
|
261 | + } else { |
|
262 | + if (php_sapi_name() == "cli") { |
|
263 | 263 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
264 | 264 | exit(); |
265 | - } else{ |
|
265 | + } else { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | } |
@@ -274,32 +274,32 @@ discard block |
||
274 | 274 | * @param string $username |
275 | 275 | * @return mixed |
276 | 276 | */ |
277 | - public function lock_account($username){ |
|
277 | + public function lock_account($username) { |
|
278 | 278 | $this->initVar(); |
279 | - $sapi = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; |
|
279 | + $sapi = php_sapi_name() == "cli" ? "lock-via-cli" : "lock-via-web"; |
|
280 | 280 | $this->setPath($username); |
281 | - try{ |
|
282 | - if(!File::exists($this->dir)){ |
|
281 | + try { |
|
282 | + if (!File::exists($this->dir)) { |
|
283 | 283 | File::makeDirectory($this->dir, 0755, true); |
284 | 284 | } |
285 | 285 | $login_fail = "lock"; |
286 | 286 | |
287 | - $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => [$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
288 | - File::put($this->path,json_encode($content)); |
|
289 | - if(File::exists($this->path)){ |
|
290 | - chmod($this->path,0755); |
|
287 | + $content = ['username' => $this->input, 'attemps' => $login_fail, 'ip' => [$sapi], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
288 | + File::put($this->path, json_encode($content)); |
|
289 | + if (File::exists($this->path)) { |
|
290 | + chmod($this->path, 0755); |
|
291 | 291 | } |
292 | - if(php_sapi_name() == "cli"){ |
|
292 | + if (php_sapi_name() == "cli") { |
|
293 | 293 | return Lang::get('lockoutMessage.user_lock_success')."\n"; |
294 | 294 | |
295 | - } else{ |
|
295 | + } else { |
|
296 | 296 | return true; |
297 | 297 | } |
298 | - } catch(\Exception $e){ |
|
299 | - if(php_sapi_name() == "cli"){ |
|
298 | + } catch (\Exception $e) { |
|
299 | + if (php_sapi_name() == "cli") { |
|
300 | 300 | return "error"; |
301 | 301 | |
302 | - } else{ |
|
302 | + } else { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | $this->logging(); |
32 | 32 | if(!$this->exceptAccount()){ |
33 | 33 | |
34 | - $this->eventFailedLogin(); |
|
34 | + $this->eventFailedLogin(); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | public function handle(Failed $event) |
30 | 30 | { |
31 | 31 | $this->logging(); |
32 | - if(!$this->exceptAccount()){ |
|
32 | + if (!$this->exceptAccount()) { |
|
33 | 33 | |
34 | 34 | $this->eventFailedLogin(); |
35 | 35 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | public function testConfig(){ |
13 | 13 | $this->ret=[]; |
14 | - $this->ret['err'] = 0; |
|
14 | + $this->ret['err'] = 0; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | if(!empty(config('irfa.lockout'))){ |
@@ -33,30 +33,30 @@ discard block |
||
33 | 33 | |
34 | 34 | return $this->ret; |
35 | 35 | } |
36 | - public function testWriteEventFailedLogin($username){ |
|
36 | + public function testWriteEventFailedLogin($username){ |
|
37 | 37 | |
38 | - $this->eventFailedLogin($username); |
|
38 | + $this->eventFailedLogin($username); |
|
39 | 39 | |
40 | - $input = $username; |
|
41 | - $dir = config('irfa.lockout.lockout_file_path'); |
|
42 | - $path = $dir.md5($input); |
|
40 | + $input = $username; |
|
41 | + $dir = config('irfa.lockout.lockout_file_path'); |
|
42 | + $path = $dir.md5($input); |
|
43 | 43 | |
44 | - if(File::exists($path)) |
|
44 | + if(File::exists($path)) |
|
45 | 45 | { |
46 | - return true; |
|
46 | + return true; |
|
47 | 47 | } |
48 | - return false; |
|
48 | + return false; |
|
49 | 49 | } |
50 | 50 | public function testWritable($username){ |
51 | - $input = $username; |
|
52 | - $dir = config('irfa.lockout.lockout_file_path'); |
|
53 | - $path = $dir.md5($input); |
|
51 | + $input = $username; |
|
52 | + $dir = config('irfa.lockout.lockout_file_path'); |
|
53 | + $path = $dir.md5($input); |
|
54 | 54 | |
55 | - if(is_writable($path)) |
|
55 | + if(is_writable($path)) |
|
56 | 56 | { |
57 | - return true; |
|
57 | + return true; |
|
58 | 58 | } |
59 | - return false; |
|
59 | + return false; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public function testManualLocking($username){ |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | private function confLogging(){ |
107 | - if(is_bool(config('irfa.lockout.logging'))){ |
|
108 | - $this->ret['logging'] = '<fg=green>OK'; |
|
107 | + if(is_bool(config('irfa.lockout.logging'))){ |
|
108 | + $this->ret['logging'] = '<fg=green>OK'; |
|
109 | 109 | } else{ |
110 | 110 | |
111 | 111 | $this->ret['err'] +=1; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $this->ret['input_name'] = '<fg=red>Must be a String'; |
123 | 123 | } |
124 | 124 | } |
125 | - private function confFilePath(){ |
|
125 | + private function confFilePath(){ |
|
126 | 126 | |
127 | 127 | |
128 | 128 | if(is_writable(config('irfa.lockout.lockout_file_path'))){ |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | private function confProtectActionPath(){ |
144 | 144 | if(is_array(config('irfa.lockout.protected_action_path'))){ |
145 | 145 | $this->ret['protected_action_path'] = '<fg=green>OK'; |
146 | - if(!empty(config('irfa.lockout.protected_action_path'))){ |
|
146 | + if(!empty(config('irfa.lockout.protected_action_path'))){ |
|
147 | 147 | $this->ret['protected_action_path'] = '<fg=green>OK'; |
148 | 148 | } else{ |
149 | - $this->ret['err'] +=1; |
|
150 | - $this->ret['protected_action_path'] = '<fg=red>Must be provided'; |
|
149 | + $this->ret['err'] +=1; |
|
150 | + $this->ret['protected_action_path'] = '<fg=red>Must be provided'; |
|
151 | 151 | } |
152 | 152 | } else{ |
153 | 153 | |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | if(!empty(config('irfa.lockout.protected_middleware_group'))){ |
162 | 162 | $this->ret['protected_middleware_group'] = '<fg=green>OK'; |
163 | 163 | } else{ |
164 | - $this->ret['err'] +=1; |
|
165 | - $this->ret['protected_middleware_group'] = '<fg=red>Must be provided'; |
|
164 | + $this->ret['err'] +=1; |
|
165 | + $this->ret['protected_middleware_group'] = '<fg=red>Must be provided'; |
|
166 | 166 | } |
167 | 167 | } else{ |
168 | 168 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | } |
174 | 174 | private function confMessage(){ |
175 | - if(is_string(config('irfa.lockout.message_name'))){ |
|
175 | + if(is_string(config('irfa.lockout.message_name'))){ |
|
176 | 176 | $this->ret['message_name'] = '<fg=green>OK'; |
177 | 177 | } else{ |
178 | 178 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | } |
184 | - private function confExceptEnabled(){ |
|
185 | - if(is_bool(config('irfa.lockout.enable_except_account'))){ |
|
184 | + private function confExceptEnabled(){ |
|
185 | + if(is_bool(config('irfa.lockout.enable_except_account'))){ |
|
186 | 186 | $this->ret['enable_except_account'] = '<fg=green>OK'; |
187 | 187 | } else{ |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | } |
194 | 194 | private function confExceptAccount(){ |
195 | - if(is_array(config('irfa.lockout.except_account'))){ |
|
195 | + if(is_array(config('irfa.lockout.except_account'))){ |
|
196 | 196 | if(!empty(config('irfa.lockout.except_account'))){ |
197 | 197 | $this->ret['except_account'] = '<fg=green>OK'; |
198 | 198 | } else{ |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | class Testing extends Core { |
10 | 10 | private $ret = []; |
11 | 11 | |
12 | - public function testConfig(){ |
|
13 | - $this->ret=[]; |
|
12 | + public function testConfig() { |
|
13 | + $this->ret = []; |
|
14 | 14 | $this->ret['err'] = 0; |
15 | 15 | |
16 | 16 | |
17 | - if(!empty(config('irfa.lockout'))){ |
|
17 | + if (!empty(config('irfa.lockout'))) { |
|
18 | 18 | $this->confLoginAttemps(); |
19 | 19 | $this->confLogging(); |
20 | 20 | $this->confInput(); |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | $this->confExceptEnabled(); |
27 | 27 | $this->confExceptAccount(); |
28 | 28 | |
29 | - } else{ |
|
30 | - $this->ret['err'] +=1; |
|
29 | + } else { |
|
30 | + $this->ret['err'] += 1; |
|
31 | 31 | $this->ret['file'] = "<fg=yellow> Could't find config file. Try to run <fg=cyan>php artisan vendor:publish --tag=lockout-account"; |
32 | 32 | } |
33 | 33 | |
34 | 34 | return $this->ret; |
35 | 35 | } |
36 | - public function testWriteEventFailedLogin($username){ |
|
36 | + public function testWriteEventFailedLogin($username) { |
|
37 | 37 | |
38 | 38 | $this->eventFailedLogin($username); |
39 | 39 | |
@@ -41,172 +41,172 @@ discard block |
||
41 | 41 | $dir = config('irfa.lockout.lockout_file_path'); |
42 | 42 | $path = $dir.md5($input); |
43 | 43 | |
44 | - if(File::exists($path)) |
|
44 | + if (File::exists($path)) |
|
45 | 45 | { |
46 | 46 | return true; |
47 | 47 | } |
48 | 48 | return false; |
49 | 49 | } |
50 | - public function testWritable($username){ |
|
50 | + public function testWritable($username) { |
|
51 | 51 | $input = $username; |
52 | 52 | $dir = config('irfa.lockout.lockout_file_path'); |
53 | 53 | $path = $dir.md5($input); |
54 | 54 | |
55 | - if(is_writable($path)) |
|
55 | + if (is_writable($path)) |
|
56 | 56 | { |
57 | 57 | return true; |
58 | 58 | } |
59 | 59 | return false; |
60 | 60 | } |
61 | 61 | |
62 | - public function testManualLocking($username){ |
|
62 | + public function testManualLocking($username) { |
|
63 | 63 | $input = $username; |
64 | 64 | $dir = config('irfa.lockout.lockout_file_path'); |
65 | 65 | $path = $dir.md5($input); |
66 | 66 | |
67 | - if($this->lock_account($username)) |
|
67 | + if ($this->lock_account($username)) |
|
68 | 68 | { |
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | return false; |
72 | 72 | } |
73 | - public function testUnlocking($username){ |
|
73 | + public function testUnlocking($username) { |
|
74 | 74 | $input = $username; |
75 | 75 | $dir = config('irfa.lockout.lockout_file_path'); |
76 | 76 | $path = $dir.md5($input); |
77 | - $unlock = $this->test_unlock_account($username); |
|
78 | - if($unlock) |
|
77 | + $unlock = $this->test_unlock_account($username); |
|
78 | + if ($unlock) |
|
79 | 79 | { |
80 | 80 | return true; |
81 | 81 | } |
82 | 82 | return false; |
83 | 83 | } |
84 | - public function testLockLogin($username){ |
|
84 | + public function testLockLogin($username) { |
|
85 | 85 | $input = $username; |
86 | 86 | $dir = config('irfa.lockout.lockout_file_path'); |
87 | 87 | $path = $dir.md5($input); |
88 | - $unlock = $this->lockLogin($username); |
|
89 | - if($unlock) |
|
88 | + $unlock = $this->lockLogin($username); |
|
89 | + if ($unlock) |
|
90 | 90 | { |
91 | 91 | return true; |
92 | 92 | } |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | //////Config |
96 | - private function confLoginAttemps(){ |
|
97 | - if(is_numeric(config('irfa.lockout.login_attemps'))){ |
|
96 | + private function confLoginAttemps() { |
|
97 | + if (is_numeric(config('irfa.lockout.login_attemps'))) { |
|
98 | 98 | $this->ret['login_attemps'] = '<fg=green>OK'; |
99 | - } else{ |
|
99 | + } else { |
|
100 | 100 | |
101 | - $this->ret['err'] +=1; |
|
102 | - $this->ret['login_attemps'] ='<fg=red>Must be a number'; |
|
101 | + $this->ret['err'] += 1; |
|
102 | + $this->ret['login_attemps'] = '<fg=red>Must be a number'; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - private function confLogging(){ |
|
107 | - if(is_bool(config('irfa.lockout.logging'))){ |
|
106 | + private function confLogging() { |
|
107 | + if (is_bool(config('irfa.lockout.logging'))) { |
|
108 | 108 | $this->ret['logging'] = '<fg=green>OK'; |
109 | - } else{ |
|
109 | + } else { |
|
110 | 110 | |
111 | - $this->ret['err'] +=1; |
|
111 | + $this->ret['err'] += 1; |
|
112 | 112 | $this->ret['logging'] = '<fg=red>Must be a Boolean'; |
113 | 113 | } |
114 | 114 | } |
115 | - private function confInput(){ |
|
115 | + private function confInput() { |
|
116 | 116 | |
117 | - if(is_string(config('irfa.lockout.input_name'))){ |
|
117 | + if (is_string(config('irfa.lockout.input_name'))) { |
|
118 | 118 | $this->ret['input_name'] = '<fg=green>OK'; |
119 | - } else{ |
|
119 | + } else { |
|
120 | 120 | |
121 | - $this->ret['err'] +=1; |
|
121 | + $this->ret['err'] += 1; |
|
122 | 122 | $this->ret['input_name'] = '<fg=red>Must be a String'; |
123 | 123 | } |
124 | 124 | } |
125 | - private function confFilePath(){ |
|
125 | + private function confFilePath() { |
|
126 | 126 | |
127 | 127 | |
128 | - if(is_writable(config('irfa.lockout.lockout_file_path'))){ |
|
128 | + if (is_writable(config('irfa.lockout.lockout_file_path'))) { |
|
129 | 129 | $this->ret['lockout_file_path'] = '<fg=green>OK'; |
130 | - } else{ |
|
130 | + } else { |
|
131 | 131 | $this->ret['lockout_file_path'] = '<fg=yellow>Write Permission Denied in '.config('irfa.lockout.lockout_file_path'); |
132 | 132 | } |
133 | 133 | } |
134 | - private function confRedirectUrl(){ |
|
135 | - if(!empty(config('irfa.lockout.redirect_url'))){ |
|
134 | + private function confRedirectUrl() { |
|
135 | + if (!empty(config('irfa.lockout.redirect_url'))) { |
|
136 | 136 | $this->ret['redirect_url'] = '<fg=green>OK'; |
137 | - } else{ |
|
137 | + } else { |
|
138 | 138 | |
139 | - $this->ret['err'] +=1; |
|
139 | + $this->ret['err'] += 1; |
|
140 | 140 | $this->ret['redirect_url'] = '<fg=red>Must be provided'; |
141 | 141 | } |
142 | 142 | } |
143 | - private function confProtectActionPath(){ |
|
144 | - if(is_array(config('irfa.lockout.protected_action_path'))){ |
|
143 | + private function confProtectActionPath() { |
|
144 | + if (is_array(config('irfa.lockout.protected_action_path'))) { |
|
145 | 145 | $this->ret['protected_action_path'] = '<fg=green>OK'; |
146 | - if(!empty(config('irfa.lockout.protected_action_path'))){ |
|
146 | + if (!empty(config('irfa.lockout.protected_action_path'))) { |
|
147 | 147 | $this->ret['protected_action_path'] = '<fg=green>OK'; |
148 | - } else{ |
|
149 | - $this->ret['err'] +=1; |
|
148 | + } else { |
|
149 | + $this->ret['err'] += 1; |
|
150 | 150 | $this->ret['protected_action_path'] = '<fg=red>Must be provided'; |
151 | 151 | } |
152 | - } else{ |
|
152 | + } else { |
|
153 | 153 | |
154 | - $this->ret['err'] +=1; |
|
154 | + $this->ret['err'] += 1; |
|
155 | 155 | $this->ret['protected_action_path'] = '<fg=red>Must be array'; |
156 | 156 | } |
157 | 157 | |
158 | 158 | } |
159 | - private function confProtectMiddleware(){ |
|
160 | - if(is_array(config('irfa.lockout.protected_middleware_group'))){ |
|
161 | - if(!empty(config('irfa.lockout.protected_middleware_group'))){ |
|
159 | + private function confProtectMiddleware() { |
|
160 | + if (is_array(config('irfa.lockout.protected_middleware_group'))) { |
|
161 | + if (!empty(config('irfa.lockout.protected_middleware_group'))) { |
|
162 | 162 | $this->ret['protected_middleware_group'] = '<fg=green>OK'; |
163 | - } else{ |
|
164 | - $this->ret['err'] +=1; |
|
163 | + } else { |
|
164 | + $this->ret['err'] += 1; |
|
165 | 165 | $this->ret['protected_middleware_group'] = '<fg=red>Must be provided'; |
166 | 166 | } |
167 | - } else{ |
|
167 | + } else { |
|
168 | 168 | |
169 | - $this->ret['err'] +=1; |
|
169 | + $this->ret['err'] += 1; |
|
170 | 170 | $this->ret['protected_middleware_group'] = '<fg=red>Must be array'; |
171 | 171 | } |
172 | 172 | |
173 | 173 | } |
174 | - private function confMessage(){ |
|
175 | - if(is_string(config('irfa.lockout.message_name'))){ |
|
174 | + private function confMessage() { |
|
175 | + if (is_string(config('irfa.lockout.message_name'))) { |
|
176 | 176 | $this->ret['message_name'] = '<fg=green>OK'; |
177 | - } else{ |
|
177 | + } else { |
|
178 | 178 | |
179 | - $this->ret['err'] +=1; |
|
179 | + $this->ret['err'] += 1; |
|
180 | 180 | $this->ret['message_name'] = '<fg=red>Must be a String'; |
181 | 181 | } |
182 | 182 | |
183 | 183 | } |
184 | - private function confExceptEnabled(){ |
|
185 | - if(is_bool(config('irfa.lockout.enable_except_account'))){ |
|
184 | + private function confExceptEnabled() { |
|
185 | + if (is_bool(config('irfa.lockout.enable_except_account'))) { |
|
186 | 186 | $this->ret['enable_except_account'] = '<fg=green>OK'; |
187 | - } else{ |
|
187 | + } else { |
|
188 | 188 | |
189 | - $this->ret['err'] +=1; |
|
189 | + $this->ret['err'] += 1; |
|
190 | 190 | $this->ret['enable_except_account'] = '<fg=red>Must be a String'; |
191 | 191 | } |
192 | 192 | |
193 | 193 | } |
194 | - private function confExceptAccount(){ |
|
195 | - if(is_array(config('irfa.lockout.except_account'))){ |
|
196 | - if(!empty(config('irfa.lockout.except_account'))){ |
|
194 | + private function confExceptAccount() { |
|
195 | + if (is_array(config('irfa.lockout.except_account'))) { |
|
196 | + if (!empty(config('irfa.lockout.except_account'))) { |
|
197 | 197 | $this->ret['except_account'] = '<fg=green>OK'; |
198 | - } else{ |
|
199 | - if(config('irfa.lockout.enable_except_account')){ |
|
198 | + } else { |
|
199 | + if (config('irfa.lockout.enable_except_account')) { |
|
200 | 200 | |
201 | 201 | $this->ret['except_account'] = '<fg=yellow>NOT SET'; |
202 | - } else{ |
|
202 | + } else { |
|
203 | 203 | |
204 | 204 | $this->ret['except_account'] = '<fg=green>OK'; |
205 | 205 | } |
206 | 206 | } |
207 | - } else{ |
|
207 | + } else { |
|
208 | 208 | |
209 | - $this->ret['err'] +=1; |
|
209 | + $this->ret['err'] += 1; |
|
210 | 210 | $this->ret['except_account'] = '<fg=red>Must be a array'; |
211 | 211 | } |
212 | 212 |
@@ -52,72 +52,72 @@ discard block |
||
52 | 52 | $this->testManualLock($domain); |
53 | 53 | $this->testLocked($domain); |
54 | 54 | $this->testUnlock($domain); |
55 | - $end=time(); |
|
55 | + $end = time(); |
|
56 | 56 | $this->line('<fg=default>--------------------------------------------'); |
57 | - $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s',time())); |
|
58 | - $this->line('<fg=default>Test time : '.(round(microtime(true) - $curTime,3)*1000)." ms"); |
|
57 | + $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s', time())); |
|
58 | + $this->line('<fg=default>Test time : '.(round(microtime(true)-$curTime, 3) * 1000)." ms"); |
|
59 | 59 | |
60 | 60 | } |
61 | - private function testWrite($domain){ |
|
61 | + private function testWrite($domain) { |
|
62 | 62 | $test = new Testing(); |
63 | - if( $test->testWriteEventFailedLogin($domain) AND $test->testWritable($domain)){ |
|
63 | + if ($test->testWriteEventFailedLogin($domain) AND $test->testWritable($domain)) { |
|
64 | 64 | $this->line('<fg=default>Auto Lock : <fg=green>OK'); |
65 | - } elseif(!$test->testWritable($domain)){ |
|
65 | + } elseif (!$test->testWritable($domain)) { |
|
66 | 66 | $this->success += 1; |
67 | 67 | $this->line('<fg=default>Auto Lock : <fg=yellow>Warning (Permission denied)'); |
68 | - } else{ |
|
68 | + } else { |
|
69 | 69 | $this->error += 1; |
70 | 70 | $this->line('<fg=default>Auto Lock : <fg=red>Failed'); |
71 | 71 | } |
72 | 72 | } |
73 | - private function testManualLock($domain){ |
|
73 | + private function testManualLock($domain) { |
|
74 | 74 | $test = new Testing(); |
75 | - if( $test->testManualLocking($domain)){ |
|
75 | + if ($test->testManualLocking($domain)) { |
|
76 | 76 | $this->success += 1; |
77 | 77 | $this->line('<fg=default>Manual Lock : <fg=green>OK'); |
78 | - } else{ |
|
78 | + } else { |
|
79 | 79 | $this->error += 1; |
80 | 80 | $this->line('<fg=default>Manual Lock : <fg=red>Failed'); |
81 | 81 | } |
82 | 82 | } |
83 | - private function testUnlock($domain){ |
|
83 | + private function testUnlock($domain) { |
|
84 | 84 | $test = new Testing(); |
85 | - if( $test->testUnlocking($domain)){ |
|
85 | + if ($test->testUnlocking($domain)) { |
|
86 | 86 | $this->success += 1; |
87 | 87 | $this->line('<fg=default>Unlock Account : <fg=green>OK'); |
88 | - } else{ |
|
88 | + } else { |
|
89 | 89 | $this->error += 1; |
90 | 90 | $this->line('<fg=default>Unlock Account : <fg=red>Failed'); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - private function testLocked($domain){ |
|
94 | + private function testLocked($domain) { |
|
95 | 95 | $test = new Testing(); |
96 | - if( $test->testLockLogin($domain)){ |
|
96 | + if ($test->testLockLogin($domain)) { |
|
97 | 97 | $this->success += 1; |
98 | 98 | $this->line('<fg=default>Try Login with locked account : <fg=green>Account is Locked'); |
99 | - } else{ |
|
99 | + } else { |
|
100 | 100 | $this->error += 1; |
101 | 101 | $this->line('<fg=default>Try Login with locked account : <fg=red>Account logged in'); |
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - private function testConfigurations(){ |
|
105 | + private function testConfigurations() { |
|
106 | 106 | $test = new Testing(); |
107 | 107 | $res = $test->testConfig(); |
108 | 108 | |
109 | 109 | $table = new Table($this->output); |
110 | 110 | $this->line('<fg=cyan>Testing Config:'); |
111 | 111 | $table->setRows([ |
112 | - ['<fg=default>login_attemps',isset($res['login_attemps']) ? $res['login_attemps']:"<fg=red>Not Found"], |
|
113 | - ['<fg=default>logging',isset($res['logging']) ? $res['logging']:"<fg=red>Not Found"], |
|
114 | - ['<fg=default>input_name',isset($res['input_name']) ? $res['input_name']:"<fg=red>Not Found"], |
|
115 | - ['<fg=default>redirect_url',isset($res['redirect_url']) ? $res['redirect_url']:"<fg=red>Not Found"], |
|
116 | - ['<fg=default>protected_action_path',isset($res['protected_action_path']) ? $res['protected_action_path']:"<fg=red>Not Found"], |
|
117 | - ['<fg=default>protected_middleware_group',isset($res['protected_middleware_group']) ? $res['protected_middleware_group']:"<fg=red>Not Found"], |
|
118 | - ['<fg=default>message_name',isset($res['message_name']) ? $res['message_name']:"<fg=red>Not Found"], |
|
119 | - ['<fg=default>enable_except_account',isset($res['enable_except_account']) ? $res['enable_except_account']:"<fg=red>Not Found"], |
|
120 | - ['<fg=default>except_account',isset($res['except_account']) ? $res['except_account']:"<fg=red>Not Found"], |
|
112 | + ['<fg=default>login_attemps', isset($res['login_attemps']) ? $res['login_attemps'] : "<fg=red>Not Found"], |
|
113 | + ['<fg=default>logging', isset($res['logging']) ? $res['logging'] : "<fg=red>Not Found"], |
|
114 | + ['<fg=default>input_name', isset($res['input_name']) ? $res['input_name'] : "<fg=red>Not Found"], |
|
115 | + ['<fg=default>redirect_url', isset($res['redirect_url']) ? $res['redirect_url'] : "<fg=red>Not Found"], |
|
116 | + ['<fg=default>protected_action_path', isset($res['protected_action_path']) ? $res['protected_action_path'] : "<fg=red>Not Found"], |
|
117 | + ['<fg=default>protected_middleware_group', isset($res['protected_middleware_group']) ? $res['protected_middleware_group'] : "<fg=red>Not Found"], |
|
118 | + ['<fg=default>message_name', isset($res['message_name']) ? $res['message_name'] : "<fg=red>Not Found"], |
|
119 | + ['<fg=default>enable_except_account', isset($res['enable_except_account']) ? $res['enable_except_account'] : "<fg=red>Not Found"], |
|
120 | + ['<fg=default>except_account', isset($res['except_account']) ? $res['except_account'] : "<fg=red>Not Found"], |
|
121 | 121 | |
122 | 122 | ]); |
123 | 123 | $table->render(); |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - private function errorCheck($res){ |
|
128 | + private function errorCheck($res) { |
|
129 | 129 | $this->configExists($res); |
130 | 130 | $this->configCheck($res); |
131 | 131 | |
132 | 132 | } |
133 | 133 | |
134 | - private function configCheck($res){ |
|
135 | - if($res['err'] > 0){ |
|
134 | + private function configCheck($res) { |
|
135 | + if ($res['err'] > 0) { |
|
136 | 136 | $this->line('<fg=red>Config invalid, testing is canceled.'); |
137 | 137 | $this->line('<fg=default>--------------------------------------------'); |
138 | - $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s',time())); |
|
138 | + $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s', time())); |
|
139 | 139 | exit(); |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - private function configExists($res){ |
|
144 | - if($res['err'] > 0 AND !empty($res['file'])){ |
|
143 | + private function configExists($res) { |
|
144 | + if ($res['err'] > 0 AND !empty($res['file'])) { |
|
145 | 145 | $this->line('<fg=red>Testing config failed, testing is canceled.'); |
146 | 146 | $this->line($res['file']); |
147 | 147 | $this->line('<fg=default>--------------------------------------------'); |
148 | - $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s',time())); |
|
148 | + $this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s', time())); |
|
149 | 149 | exit(); |
150 | 150 | } |
151 | 151 | } |