@@ -20,11 +20,11 @@ |
||
20 | 20 | */ |
21 | 21 | public function handle($request, Closure $next) |
22 | 22 | { |
23 | - if($request->method() == "POST"){ |
|
24 | - if(in_array($request->path(), config('irfa.lockout.protected_action_path'))) { |
|
25 | - if($this->lockLogin()){ |
|
23 | + if ($request->method() == "POST") { |
|
24 | + if (in_array($request->path(), config('irfa.lockout.protected_action_path'))) { |
|
25 | + if ($this->lockLogin()) { |
|
26 | 26 | $message['code'] = 403; |
27 | - $message[config('irfa.lockout.message_name')] =Lang::get('lockoutMessage.locked'); |
|
27 | + $message[config('irfa.lockout.message_name')] = Lang::get('lockoutMessage.locked'); |
|
28 | 28 | return response()->json($message); |
29 | 29 | } |
30 | 30 | } |
@@ -22,13 +22,13 @@ |
||
22 | 22 | */ |
23 | 23 | public function handle($request, Closure $next) |
24 | 24 | { |
25 | - if($request->method() == "POST"){ |
|
26 | - if(in_array($request->path(), config('irfa.lockout.protected_action_path'))) { |
|
27 | - if($this->lockLogin()){ |
|
25 | + if ($request->method() == "POST") { |
|
26 | + if (in_array($request->path(), config('irfa.lockout.protected_action_path'))) { |
|
27 | + if ($this->lockLogin()) { |
|
28 | 28 | $this->eventFailedLogin(); |
29 | 29 | $this->logging(); |
30 | - Session::flash(config('irfa.lockout.message_name'),Lang::get('lockoutMessage.locked')); |
|
31 | - return redirect(empty(config('irfa.lockout.redirect_url'))?"/":URL::to(config('irfa.lockout.redirect_url'))); |
|
30 | + Session::flash(config('irfa.lockout.message_name'), Lang::get('lockoutMessage.locked')); |
|
31 | + return redirect(empty(config('irfa.lockout.redirect_url')) ? "/" : URL::to(config('irfa.lockout.redirect_url'))); |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * @return void |
16 | 16 | */ |
17 | 17 | protected $commands = [ |
18 | - 'Irfa\Lockout\Console\Commands\LockCommands', |
|
19 | - 'Irfa\Lockout\Console\Commands\UnlockCommands', |
|
20 | - 'Irfa\Lockout\Console\Commands\AttempsCommands', |
|
21 | - 'Irfa\Lockout\Console\Commands\LockInfoPackage', |
|
22 | - 'Irfa\Lockout\Console\Commands\ClearLockCommands', |
|
18 | + 'Irfa\Lockout\Console\Commands\LockCommands', |
|
19 | + 'Irfa\Lockout\Console\Commands\UnlockCommands', |
|
20 | + 'Irfa\Lockout\Console\Commands\AttempsCommands', |
|
21 | + 'Irfa\Lockout\Console\Commands\LockInfoPackage', |
|
22 | + 'Irfa\Lockout\Console\Commands\ClearLockCommands', |
|
23 | 23 | ]; |
24 | 24 | |
25 | 25 | public function register() |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | $router = $this->app['router']; |
28 | 28 | $this->commands($this->commands); |
29 | 29 | \Illuminate\Support\Facades\Event::listen( |
30 | - \Illuminate\Auth\Events\Failed::class, |
|
30 | + \Illuminate\Auth\Events\Failed::class, |
|
31 | 31 | LockoutAccount::class |
32 | 32 | ); |
33 | 33 | \Illuminate\Support\Facades\Event::listen( |
34 | - \Illuminate\Auth\Events\Authenticated::class, |
|
34 | + \Illuminate\Auth\Events\Authenticated::class, |
|
35 | 35 | CleanLockoutAccount::class |
36 | 36 | ); |
37 | 37 | $router->pushMiddlewareToGroup('web',\Irfa\Lockout\Middleware\LockAccount::class); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | \Illuminate\Auth\Events\Authenticated::class, |
35 | 35 | CleanLockoutAccount::class |
36 | 36 | ); |
37 | - $router->pushMiddlewareToGroup('web',\Irfa\Lockout\Middleware\LockAccount::class); |
|
37 | + $router->pushMiddlewareToGroup('web', \Irfa\Lockout\Middleware\LockAccount::class); |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | $this->publishes([ |
49 | 49 | __DIR__.'/../resource/config/irfa/lockout.php' => config_path('irfa/lockout.php'), |
50 | - __DIR__.'/../resource/lang' => resource_path('lang'),], 'lockout-account'); |
|
50 | + __DIR__.'/../resource/lang' => resource_path('lang'), ], 'lockout-account'); |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | } |
@@ -39,18 +39,18 @@ |
||
39 | 39 | */ |
40 | 40 | public function handle(Core $core) |
41 | 41 | { |
42 | - $ret = $core->check_account($this->argument('username')); |
|
42 | + $ret = $core->check_account($this->argument('username')); |
|
43 | 43 | $table = new Table($this->output); |
44 | - $read_enc = json_decode( $ret); |
|
45 | - $time = $read_enc->last_attemps; |
|
46 | - $attemps = $read_enc->attemps; |
|
47 | - $ip = $read_enc->ip; |
|
48 | - $table->setRows([ |
|
44 | + $read_enc = json_decode( $ret); |
|
45 | + $time = $read_enc->last_attemps; |
|
46 | + $attemps = $read_enc->attemps; |
|
47 | + $ip = $read_enc->ip; |
|
48 | + $table->setRows([ |
|
49 | 49 | ['<fg=yellow>Login attemps', $attemps], |
50 | 50 | ['<fg=yellow>Last login attemps',$time], |
51 | 51 | ['<fg=yellow>Last IP Address',empty(end($ip))? "unknown":end($ip)],]); |
52 | - $table->render(); |
|
53 | - // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
|
52 | + $table->render(); |
|
53 | + // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 |
@@ -41,14 +41,14 @@ |
||
41 | 41 | { |
42 | 42 | $ret = $core->check_account($this->argument('username')); |
43 | 43 | $table = new Table($this->output); |
44 | - $read_enc = json_decode( $ret); |
|
44 | + $read_enc = json_decode($ret); |
|
45 | 45 | $time = $read_enc->last_attemps; |
46 | 46 | $attemps = $read_enc->attemps; |
47 | 47 | $ip = $read_enc->ip; |
48 | 48 | $table->setRows([ |
49 | - ['<fg=yellow>Login attemps', $attemps], |
|
50 | - ['<fg=yellow>Last login attemps',$time], |
|
51 | - ['<fg=yellow>Last IP Address',empty(end($ip))? "unknown":end($ip)],]); |
|
49 | + ['<fg=yellow>Login attemps', $attemps], |
|
50 | + ['<fg=yellow>Last login attemps', $time], |
|
51 | + ['<fg=yellow>Last IP Address', empty(end($ip)) ? "unknown" : end($ip)], ]); |
|
52 | 52 | $table->render(); |
53 | 53 | // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
54 | 54 |
@@ -46,9 +46,9 @@ |
||
46 | 46 | ['<fg=green>'.$this->argument('username').' successfully locked.'], |
47 | 47 | |
48 | 48 | ]); |
49 | - $table->render(); |
|
49 | + $table->render(); |
|
50 | 50 | } else{ |
51 | - $this->line('<fg=red> Locking failed.'); |
|
51 | + $this->line('<fg=red> Locking failed.'); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 |
@@ -40,14 +40,14 @@ |
||
40 | 40 | public function handle(Core $core) |
41 | 41 | { |
42 | 42 | $this->line('Locking '.$this->argument('username').'...'); |
43 | - if($core->lock_account($this->argument('username'))!="error"){ |
|
43 | + if ($core->lock_account($this->argument('username')) != "error") { |
|
44 | 44 | $table = new Table($this->output); |
45 | 45 | $table->setRows([ |
46 | 46 | ['<fg=green>'.$this->argument('username').' successfully locked.'], |
47 | 47 | |
48 | 48 | ]); |
49 | 49 | $table->render(); |
50 | - } else{ |
|
50 | + } else { |
|
51 | 51 | $this->line('<fg=red> Locking failed.'); |
52 | 52 | } |
53 | 53 | } |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function handle() |
39 | 39 | { |
40 | - $this->informasi(); |
|
40 | + $this->informasi(); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | private function informasi(){ |
44 | - $this->line(" _____ __ _ _ _ |
|
44 | + $this->line(" _____ __ _ _ _ |
|
45 | 45 | |_ _| / _| | | | | | | |
46 | 46 | | | _ __| |_ __ _ ______| | ___ ___| | _____ _ _| |_ |
47 | 47 | | || '__| _/ _` |______| | / _ \ / __| |/ / _ \| | | | __| |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | $this->line('Version 1.0.0 (2020)'); |
54 | 54 | $this->line('<fg=cyan>https://github.com/irfaardy/lockout-account'); |
55 | 55 | $conf = config('irfa.lockout'); |
56 | - $this->line('<fg=default>-------------------------------------------------------------------------------'); |
|
57 | - $this->line('<fg=yellow>Configuration'); |
|
56 | + $this->line('<fg=default>-------------------------------------------------------------------------------'); |
|
57 | + $this->line('<fg=yellow>Configuration'); |
|
58 | 58 | foreach($conf as $key => $val){ |
59 | 59 | if(is_array($val)){ |
60 | 60 | foreach($val as $v){ |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $vl = $val; |
65 | 65 | } |
66 | 66 | |
67 | - $this->line('<fg=default>'.$key.' = <fg=cyan>'.$vl); |
|
67 | + $this->line('<fg=default>'.$key.' = <fg=cyan>'.$vl); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $this->informasi(); |
41 | 41 | } |
42 | 42 | |
43 | - private function informasi(){ |
|
43 | + private function informasi() { |
|
44 | 44 | $this->line(" _____ __ _ _ _ |
45 | 45 | |_ _| / _| | | | | | | |
46 | 46 | | | _ __| |_ __ _ ______| | ___ ___| | _____ _ _| |_ |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | $conf = config('irfa.lockout'); |
56 | 56 | $this->line('<fg=default>-------------------------------------------------------------------------------'); |
57 | 57 | $this->line('<fg=yellow>Configuration'); |
58 | - foreach($conf as $key => $val){ |
|
59 | - if(is_array($val)){ |
|
60 | - foreach($val as $v){ |
|
58 | + foreach ($conf as $key => $val) { |
|
59 | + if (is_array($val)) { |
|
60 | + foreach ($val as $v) { |
|
61 | 61 | $vl .= $v.", "; |
62 | 62 | } |
63 | - } else{ |
|
63 | + } else { |
|
64 | 64 | $vl = $val; |
65 | 65 | } |
66 | 66 |
@@ -39,20 +39,20 @@ |
||
39 | 39 | */ |
40 | 40 | public function handle(Core $core) |
41 | 41 | { |
42 | - $ret = $core->unlock_account($this->argument('username')); |
|
42 | + $ret = $core->unlock_account($this->argument('username')); |
|
43 | 43 | $table = new Table($this->output); |
44 | - $read_enc = json_decode( $ret); |
|
45 | - $time = $read_enc->last_attemps; |
|
46 | - $attemps = $read_enc->attemps; |
|
47 | - $ip = $read_enc->ip; |
|
48 | - $table->setRows([ |
|
44 | + $read_enc = json_decode( $ret); |
|
45 | + $time = $read_enc->last_attemps; |
|
46 | + $attemps = $read_enc->attemps; |
|
47 | + $ip = $read_enc->ip; |
|
48 | + $table->setRows([ |
|
49 | 49 | ['<fg=cyan>Login attemps', $attemps], |
50 | 50 | ['<fg=cyan>Last login attemps',$time], |
51 | 51 | ['<fg=cyan>Last IP Address',empty(end($ip))? "unknown":end($ip)], |
52 | 52 | ['<fg=cyan>Unlocked at',date('Y-m-d H:i:s', time())], |
53 | 53 | ]); |
54 | - $table->render(); |
|
55 | - // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
|
54 | + $table->render(); |
|
55 | + // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 |
@@ -41,15 +41,15 @@ |
||
41 | 41 | { |
42 | 42 | $ret = $core->unlock_account($this->argument('username')); |
43 | 43 | $table = new Table($this->output); |
44 | - $read_enc = json_decode( $ret); |
|
44 | + $read_enc = json_decode($ret); |
|
45 | 45 | $time = $read_enc->last_attemps; |
46 | 46 | $attemps = $read_enc->attemps; |
47 | 47 | $ip = $read_enc->ip; |
48 | 48 | $table->setRows([ |
49 | - ['<fg=cyan>Login attemps', $attemps], |
|
50 | - ['<fg=cyan>Last login attemps',$time], |
|
51 | - ['<fg=cyan>Last IP Address',empty(end($ip))? "unknown":end($ip)], |
|
52 | - ['<fg=cyan>Unlocked at',date('Y-m-d H:i:s', time())], |
|
49 | + ['<fg=cyan>Login attemps', $attemps], |
|
50 | + ['<fg=cyan>Last login attemps', $time], |
|
51 | + ['<fg=cyan>Last IP Address', empty(end($ip)) ? "unknown" : end($ip)], |
|
52 | + ['<fg=cyan>Unlocked at', date('Y-m-d H:i:s', time())], |
|
53 | 53 | ]); |
54 | 54 | $table->render(); |
55 | 55 | // $this->line('<fg=yellow>Valid input is lock, unlock, and attemps.'); |
@@ -46,9 +46,9 @@ |
||
46 | 46 | ['<fg=green>Locked Account(s) Cleared.'], |
47 | 47 | |
48 | 48 | ]); |
49 | - $table->render(); |
|
49 | + $table->render(); |
|
50 | 50 | } else{ |
51 | - $this->line('<fg=red> Clearing failed.'); |
|
51 | + $this->line('<fg=red> Clearing failed.'); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 |
@@ -40,14 +40,14 @@ |
||
40 | 40 | public function handle(Core $core) |
41 | 41 | { |
42 | 42 | $this->line('Cleaning locked user...'); |
43 | - if($core->clear_all()){ |
|
43 | + if ($core->clear_all()) { |
|
44 | 44 | $table = new Table($this->output); |
45 | 45 | $table->setRows([ |
46 | 46 | ['<fg=green>Locked Account(s) Cleared.'], |
47 | 47 | |
48 | 48 | ]); |
49 | 49 | $table->render(); |
50 | - } else{ |
|
50 | + } else { |
|
51 | 51 | $this->line('<fg=red> Clearing failed.'); |
52 | 52 | } |
53 | 53 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | $path = $dir.md5($input); |
17 | 17 | |
18 | 18 | if(!File::exists($dir)){ |
19 | - File::makeDirectory($dir, 0750, true); |
|
19 | + File::makeDirectory($dir, 0750, true); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if(!File::exists($path)) |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | array_push($ip_list,$ip); |
31 | 31 | } |
32 | 32 | if($get->attemps == "lock"){ |
33 | - $login_fail = "lock"; |
|
33 | + $login_fail = "lock"; |
|
34 | 34 | } else{ |
35 | - $login_fail = $get->attemps+1; |
|
35 | + $login_fail = $get->attemps+1; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | File::put($path,json_encode($content)); |
41 | 41 | |
42 | 42 | } |
43 | - protected function eventCleanLockoutAccount(){ |
|
44 | - $input = Request::input(config('irfa.lockout.input_name')); |
|
45 | - $this->unlock_account($input); |
|
43 | + protected function eventCleanLockoutAccount(){ |
|
44 | + $input = Request::input(config('irfa.lockout.input_name')); |
|
45 | + $this->unlock_account($input); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | protected function logging(){ |
49 | - if(config('irfa.lockout.logging')){ |
|
50 | - Log::notice("Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL); |
|
49 | + if(config('irfa.lockout.logging')){ |
|
50 | + Log::notice("Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | $path = $dir.md5(Request::input('email')); |
60 | 60 | if(File::exists($path)) |
61 | 61 | { |
62 | - $get = json_decode(File::get($path)); |
|
63 | - // dd($get->attemps.">".$attemps); |
|
64 | - if($get->attemps == "lock"){ |
|
62 | + $get = json_decode(File::get($path)); |
|
63 | + // dd($get->attemps.">".$attemps); |
|
64 | + if($get->attemps == "lock"){ |
|
65 | 65 | return true; |
66 | - } |
|
67 | - if($get->attemps > $attemps){ |
|
68 | - if($matchip){ |
|
66 | + } |
|
67 | + if($get->attemps > $attemps){ |
|
68 | + if($matchip){ |
|
69 | 69 | if($this->checkIp($ip_list,$ip)){ |
70 | 70 | return true; |
71 | 71 | } else{ |
72 | 72 | return false; |
73 | 73 | } |
74 | - } else{ |
|
74 | + } else{ |
|
75 | 75 | return true; |
76 | - } |
|
77 | - } else{ |
|
76 | + } |
|
77 | + } else{ |
|
78 | 78 | return false; |
79 | - } |
|
79 | + } |
|
80 | 80 | } else{ |
81 | 81 | return false; |
82 | 82 | } |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | |
91 | 91 | } |
92 | 92 | public function clear_all(){ |
93 | - $file = new Filesystem(); |
|
94 | - if($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))){ |
|
93 | + $file = new Filesystem(); |
|
94 | + if($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))){ |
|
95 | 95 | return true; |
96 | - } else{ |
|
96 | + } else{ |
|
97 | 97 | return false; |
98 | - } |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | public function unlock_account($username){ |
101 | 101 | $ip = Request::ip(); |
@@ -105,48 +105,48 @@ discard block |
||
105 | 105 | $path = $dir.md5($username); |
106 | 106 | |
107 | 107 | if(File::exists($path)){ |
108 | - $readf = File::get($path); |
|
109 | - File::delete($path); |
|
108 | + $readf = File::get($path); |
|
109 | + File::delete($path); |
|
110 | 110 | if(php_sapi_name() == "cli"){ |
111 | - echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
|
112 | - return $readf; |
|
111 | + echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
|
112 | + return $readf; |
|
113 | 113 | |
114 | 114 | } else{ |
115 | - return true; |
|
115 | + return true; |
|
116 | 116 | } |
117 | 117 | } else{ |
118 | - if(php_sapi_name() == "cli"){ |
|
119 | - echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
118 | + if(php_sapi_name() == "cli"){ |
|
119 | + echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
120 | 120 | exit(); |
121 | - } else{ |
|
122 | - return false; |
|
123 | - } |
|
121 | + } else{ |
|
122 | + return false; |
|
123 | + } |
|
124 | + } |
|
124 | 125 | } |
125 | - } |
|
126 | - public function check_account($username){ |
|
126 | + public function check_account($username){ |
|
127 | 127 | $dir = config('irfa.lockout.lockout_file_path'); |
128 | 128 | $path = $dir.md5($username); |
129 | 129 | |
130 | 130 | if(File::exists($path)){ |
131 | - $readf = File::get($path); |
|
131 | + $readf = File::get($path); |
|
132 | 132 | if(php_sapi_name() == "cli"){ |
133 | 133 | |
134 | - return $readf; |
|
134 | + return $readf; |
|
135 | 135 | |
136 | 136 | } else{ |
137 | - return $readf; |
|
137 | + return $readf; |
|
138 | 138 | } |
139 | 139 | } else{ |
140 | - if(php_sapi_name() == "cli"){ |
|
141 | - echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
140 | + if(php_sapi_name() == "cli"){ |
|
141 | + echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
142 | 142 | exit(); |
143 | - } else{ |
|
144 | - return false; |
|
145 | - } |
|
143 | + } else{ |
|
144 | + return false; |
|
145 | + } |
|
146 | + } |
|
146 | 147 | } |
147 | - } |
|
148 | 148 | |
149 | - public function lock_account($username){ |
|
149 | + public function lock_account($username){ |
|
150 | 150 | $ip = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; |
151 | 151 | $input = $username; |
152 | 152 | $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
@@ -154,26 +154,26 @@ discard block |
||
154 | 154 | $attemps = config('irfa.lockout.login_attemps'); |
155 | 155 | $path = $dir.md5($username); |
156 | 156 | try{ |
157 | - if(!File::exists($dir)){ |
|
158 | - File::makeDirectory($dir, 0750, true); |
|
159 | - } |
|
160 | - $login_fail = "lock"; |
|
157 | + if(!File::exists($dir)){ |
|
158 | + File::makeDirectory($dir, 0750, true); |
|
159 | + } |
|
160 | + $login_fail = "lock"; |
|
161 | 161 | |
162 | - $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
163 | - File::put($path,json_encode($content)); |
|
164 | - if(php_sapi_name() == "cli"){ |
|
162 | + $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
163 | + File::put($path,json_encode($content)); |
|
164 | + if(php_sapi_name() == "cli"){ |
|
165 | 165 | return Lang::get('lockoutMessage.user_lock_success')."\n"; |
166 | 166 | |
167 | - } else{ |
|
167 | + } else{ |
|
168 | 168 | return true; |
169 | 169 | } |
170 | 170 | } catch(Exception $e){ |
171 | - if(php_sapi_name() == "cli"){ |
|
171 | + if(php_sapi_name() == "cli"){ |
|
172 | 172 | return "error"; |
173 | 173 | |
174 | - } else{ |
|
174 | + } else{ |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | } |
178 | - } |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | \ No newline at end of file |
@@ -2,176 +2,176 @@ |
||
2 | 2 | namespace Irfa\Lockout\Func; |
3 | 3 | |
4 | 4 | use Log; |
5 | -use Illuminate\Support\Facades\Request,File,Lang; |
|
5 | +use Illuminate\Support\Facades\Request, File, Lang; |
|
6 | 6 | use Illuminate\Filesystem\Filesystem; |
7 | 7 | use Symfony\Component\Console\Helper\Table; |
8 | 8 | |
9 | 9 | class Core |
10 | 10 | { |
11 | - protected function eventFailedLogin(){ |
|
11 | + protected function eventFailedLogin() { |
|
12 | 12 | $ip = Request::ip(); |
13 | 13 | $input = Request::input(config('irfa.lockout.input_name')); |
14 | - $matchip= config('irfa.lockout.match_ip') == true ? $ip :null; |
|
14 | + $matchip = config('irfa.lockout.match_ip') == true ? $ip : null; |
|
15 | 15 | $dir = config('irfa.lockout.lockout_file_path'); |
16 | 16 | $path = $dir.md5($input); |
17 | 17 | |
18 | - if(!File::exists($dir)){ |
|
18 | + if (!File::exists($dir)) { |
|
19 | 19 | File::makeDirectory($dir, 0750, true); |
20 | 20 | } |
21 | 21 | |
22 | - if(!File::exists($path)) |
|
22 | + if (!File::exists($path)) |
|
23 | 23 | { |
24 | 24 | $login_fail = 1; |
25 | - } else{ |
|
25 | + } else { |
|
26 | 26 | |
27 | 27 | $get = json_decode(File::get($path)); |
28 | 28 | $ip_list = $get->ip; |
29 | - if(!$this->checkIp($ip_list,$ip)){ |
|
30 | - array_push($ip_list,$ip); |
|
29 | + if (!$this->checkIp($ip_list, $ip)) { |
|
30 | + array_push($ip_list, $ip); |
|
31 | 31 | } |
32 | - if($get->attemps == "lock"){ |
|
32 | + if ($get->attemps == "lock") { |
|
33 | 33 | $login_fail = "lock"; |
34 | - } else{ |
|
34 | + } else { |
|
35 | 35 | $login_fail = $get->attemps+1; |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | - $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
40 | - File::put($path,json_encode($content)); |
|
39 | + $content = ['username' => $input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$ip], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
40 | + File::put($path, json_encode($content)); |
|
41 | 41 | |
42 | 42 | } |
43 | - protected function eventCleanLockoutAccount(){ |
|
43 | + protected function eventCleanLockoutAccount() { |
|
44 | 44 | $input = Request::input(config('irfa.lockout.input_name')); |
45 | 45 | $this->unlock_account($input); |
46 | 46 | |
47 | 47 | } |
48 | - protected function logging(){ |
|
49 | - if(config('irfa.lockout.logging')){ |
|
48 | + protected function logging() { |
|
49 | + if (config('irfa.lockout.logging')) { |
|
50 | 50 | Log::notice("Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - protected function lockLogin(){ |
|
54 | + protected function lockLogin() { |
|
55 | 55 | $ip = Request::ip(); |
56 | - $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
|
56 | + $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip'); |
|
57 | 57 | $dir = config('irfa.lockout.lockout_file_path'); |
58 | 58 | $attemps = config('irfa.lockout.login_attemps'); |
59 | 59 | $path = $dir.md5(Request::input('email')); |
60 | - if(File::exists($path)) |
|
60 | + if (File::exists($path)) |
|
61 | 61 | { |
62 | 62 | $get = json_decode(File::get($path)); |
63 | 63 | // dd($get->attemps.">".$attemps); |
64 | - if($get->attemps == "lock"){ |
|
64 | + if ($get->attemps == "lock") { |
|
65 | 65 | return true; |
66 | 66 | } |
67 | - if($get->attemps > $attemps){ |
|
68 | - if($matchip){ |
|
69 | - if($this->checkIp($ip_list,$ip)){ |
|
67 | + if ($get->attemps > $attemps) { |
|
68 | + if ($matchip) { |
|
69 | + if ($this->checkIp($ip_list, $ip)) { |
|
70 | 70 | return true; |
71 | - } else{ |
|
71 | + } else { |
|
72 | 72 | return false; |
73 | 73 | } |
74 | - } else{ |
|
74 | + } else { |
|
75 | 75 | return true; |
76 | 76 | } |
77 | - } else{ |
|
77 | + } else { |
|
78 | 78 | return false; |
79 | 79 | } |
80 | - } else{ |
|
80 | + } else { |
|
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | } |
84 | - private function checkIp($ip_list,$ip){ |
|
85 | - if(collect($ip_list)->contains($ip)){ |
|
84 | + private function checkIp($ip_list, $ip) { |
|
85 | + if (collect($ip_list)->contains($ip)) { |
|
86 | 86 | return true; |
87 | - } else{ |
|
87 | + } else { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | |
91 | 91 | } |
92 | - public function clear_all(){ |
|
92 | + public function clear_all() { |
|
93 | 93 | $file = new Filesystem(); |
94 | - if($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))){ |
|
94 | + if ($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))) { |
|
95 | 95 | return true; |
96 | - } else{ |
|
96 | + } else { |
|
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | } |
100 | - public function unlock_account($username){ |
|
100 | + public function unlock_account($username) { |
|
101 | 101 | $ip = Request::ip(); |
102 | - $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
|
102 | + $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip'); |
|
103 | 103 | $dir = config('irfa.lockout.lockout_file_path'); |
104 | 104 | $attemps = config('irfa.lockout.attemps'); |
105 | 105 | $path = $dir.md5($username); |
106 | 106 | |
107 | - if(File::exists($path)){ |
|
107 | + if (File::exists($path)) { |
|
108 | 108 | $readf = File::get($path); |
109 | 109 | File::delete($path); |
110 | - if(php_sapi_name() == "cli"){ |
|
110 | + if (php_sapi_name() == "cli") { |
|
111 | 111 | echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
112 | 112 | return $readf; |
113 | 113 | |
114 | - } else{ |
|
114 | + } else { |
|
115 | 115 | return true; |
116 | 116 | } |
117 | - } else{ |
|
118 | - if(php_sapi_name() == "cli"){ |
|
117 | + } else { |
|
118 | + if (php_sapi_name() == "cli") { |
|
119 | 119 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
120 | 120 | exit(); |
121 | - } else{ |
|
121 | + } else { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
126 | - public function check_account($username){ |
|
126 | + public function check_account($username) { |
|
127 | 127 | $dir = config('irfa.lockout.lockout_file_path'); |
128 | 128 | $path = $dir.md5($username); |
129 | 129 | |
130 | - if(File::exists($path)){ |
|
130 | + if (File::exists($path)) { |
|
131 | 131 | $readf = File::get($path); |
132 | - if(php_sapi_name() == "cli"){ |
|
132 | + if (php_sapi_name() == "cli") { |
|
133 | 133 | |
134 | 134 | return $readf; |
135 | 135 | |
136 | - } else{ |
|
136 | + } else { |
|
137 | 137 | return $readf; |
138 | 138 | } |
139 | - } else{ |
|
140 | - if(php_sapi_name() == "cli"){ |
|
139 | + } else { |
|
140 | + if (php_sapi_name() == "cli") { |
|
141 | 141 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
142 | 142 | exit(); |
143 | - } else{ |
|
143 | + } else { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - public function lock_account($username){ |
|
150 | - $ip = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; |
|
149 | + public function lock_account($username) { |
|
150 | + $ip = php_sapi_name() == "cli" ? "lock-via-cli" : "lock-via-web"; |
|
151 | 151 | $input = $username; |
152 | - $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
|
152 | + $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip'); |
|
153 | 153 | $dir = config('irfa.lockout.lockout_file_path'); |
154 | 154 | $attemps = config('irfa.lockout.login_attemps'); |
155 | 155 | $path = $dir.md5($username); |
156 | - try{ |
|
157 | - if(!File::exists($dir)){ |
|
156 | + try { |
|
157 | + if (!File::exists($dir)) { |
|
158 | 158 | File::makeDirectory($dir, 0750, true); |
159 | 159 | } |
160 | 160 | $login_fail = "lock"; |
161 | 161 | |
162 | - $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
163 | - File::put($path,json_encode($content)); |
|
164 | - if(php_sapi_name() == "cli"){ |
|
162 | + $content = ['username' => $input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$ip], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
163 | + File::put($path, json_encode($content)); |
|
164 | + if (php_sapi_name() == "cli") { |
|
165 | 165 | return Lang::get('lockoutMessage.user_lock_success')."\n"; |
166 | 166 | |
167 | - } else{ |
|
167 | + } else { |
|
168 | 168 | return true; |
169 | 169 | } |
170 | - } catch(Exception $e){ |
|
171 | - if(php_sapi_name() == "cli"){ |
|
170 | + } catch (Exception $e) { |
|
171 | + if (php_sapi_name() == "cli") { |
|
172 | 172 | return "error"; |
173 | 173 | |
174 | - } else{ |
|
174 | + } else { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | } |