@@ -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); |
@@ -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 | |
@@ -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 | |
@@ -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 | |
@@ -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 | |
@@ -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 | |
@@ -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 |
@@ -5,53 +5,53 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Lockout extends Core { |
| 7 | 7 | |
| 8 | - public function unlock($username){ |
|
| 9 | - if(is_array($username)){ |
|
| 10 | - foreach($username as $key){ |
|
| 11 | - $this->_unlock($key); |
|
| 12 | - } |
|
| 13 | - } else{ |
|
| 14 | - $this->_unlock($username); |
|
| 15 | - } |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 8 | + public function unlock($username){ |
|
| 9 | + if(is_array($username)){ |
|
| 10 | + foreach($username as $key){ |
|
| 11 | + $this->_unlock($key); |
|
| 12 | + } |
|
| 13 | + } else{ |
|
| 14 | + $this->_unlock($username); |
|
| 15 | + } |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function lock($username){ |
|
| 20 | - if(is_array($username)){ |
|
| 21 | - foreach($username as $key){ |
|
| 22 | - $this->_lock($key); |
|
| 23 | - } |
|
| 24 | - } else{ |
|
| 25 | - $this->_lock($username); |
|
| 26 | - } |
|
| 27 | - return true; |
|
| 28 | - } |
|
| 29 | - public function check($username) { |
|
| 30 | - $ret = null; |
|
| 31 | - if(is_array($username)){ |
|
| 32 | - foreach($username as $key){ |
|
| 33 | - $get = $this->_check($key); |
|
| 34 | - if(!empty($get)){ |
|
| 35 | - $ret[] = $get; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } else{ |
|
| 39 | - $ret = $this->_check($username); |
|
| 40 | - } |
|
| 41 | - $ret = json_encode($ret); |
|
| 42 | - return json_decode($ret); |
|
| 43 | - } |
|
| 44 | - public function clearLocked(){ |
|
| 45 | - return $this->clear_all(); |
|
| 46 | - } |
|
| 19 | + public function lock($username){ |
|
| 20 | + if(is_array($username)){ |
|
| 21 | + foreach($username as $key){ |
|
| 22 | + $this->_lock($key); |
|
| 23 | + } |
|
| 24 | + } else{ |
|
| 25 | + $this->_lock($username); |
|
| 26 | + } |
|
| 27 | + return true; |
|
| 28 | + } |
|
| 29 | + public function check($username) { |
|
| 30 | + $ret = null; |
|
| 31 | + if(is_array($username)){ |
|
| 32 | + foreach($username as $key){ |
|
| 33 | + $get = $this->_check($key); |
|
| 34 | + if(!empty($get)){ |
|
| 35 | + $ret[] = $get; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } else{ |
|
| 39 | + $ret = $this->_check($username); |
|
| 40 | + } |
|
| 41 | + $ret = json_encode($ret); |
|
| 42 | + return json_decode($ret); |
|
| 43 | + } |
|
| 44 | + public function clearLocked(){ |
|
| 45 | + return $this->clear_all(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - private function _unlock($username){ |
|
| 49 | - $this->unlock_account($username); |
|
| 50 | - } |
|
| 51 | - private function _lock($username){ |
|
| 52 | - $this->lock_account($username); |
|
| 53 | - } |
|
| 54 | - private function _check($username){ |
|
| 55 | - return json_decode($this->check_account($username),true); |
|
| 56 | - } |
|
| 48 | + private function _unlock($username){ |
|
| 49 | + $this->unlock_account($username); |
|
| 50 | + } |
|
| 51 | + private function _lock($username){ |
|
| 52 | + $this->lock_account($username); |
|
| 53 | + } |
|
| 54 | + private function _check($username){ |
|
| 55 | + return json_decode($this->check_account($username),true); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -2,10 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - 'locked' => 'This account has been locked.', |
|
| 6 | - 'user_unlock_success' => 'Account Unlocked', |
|
| 7 | - 'user_lock_success' => 'Account locked', |
|
| 8 | - 'user_lock_fail' => 'Account fail', |
|
| 9 | - 'user_lock_404' => "Can't unlock account, because this account not locked", |
|
| 5 | + 'locked' => 'This account has been locked.', |
|
| 6 | + 'user_unlock_success' => 'Account Unlocked', |
|
| 7 | + 'user_lock_success' => 'Account locked', |
|
| 8 | + 'user_lock_fail' => 'Account fail', |
|
| 9 | + 'user_lock_404' => "Can't unlock account, because this account not locked", |
|
| 10 | 10 | |
| 11 | 11 | ]; |
| 12 | 12 | \ No newline at end of file |