1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Irfa\Lockout\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Irfa\Lockout\Func\Testing; |
7
|
|
|
use Symfony\Component\Console\Helper\Table; |
8
|
|
|
use URL; |
9
|
|
|
use Str; |
|
|
|
|
10
|
|
|
|
11
|
|
|
class TestingCommands extends Command |
12
|
|
|
{ |
13
|
|
|
private $error = 0; |
14
|
|
|
private $success = 0; |
15
|
|
|
/** |
16
|
|
|
* The name and signature of the console command. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'lockout:diagnose'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Lock Account'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create a new command instance. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
parent::__construct(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the console command. |
41
|
|
|
* |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function handle() |
45
|
|
|
{ |
46
|
|
|
$curTime = microtime(true); |
47
|
|
|
$domain = 'locktest-'.md5(strtolower(config("app.name"))).'@'.strtolower(config("app.name")).".com"; |
48
|
|
|
$this->line('<fg=default>--------------------------------------------'); |
49
|
|
|
$this->testConfigurations(); |
50
|
|
|
$this->line('<fg=default>Testing Mail : <fg=cyan>'.$domain); |
51
|
|
|
$this->testWrite($domain); |
52
|
|
|
$this->testManualLock($domain); |
53
|
|
|
$this->testLocked($domain); |
54
|
|
|
$this->testUnlock($domain); |
55
|
|
|
$end=time(); |
|
|
|
|
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"); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
private function testWrite($domain){ |
62
|
|
|
$test = new Testing(); |
63
|
|
|
if( $test->testWriteEventFailedLogin($domain) AND $test->testWritable($domain)){ |
64
|
|
|
$this->line('<fg=default>Auto Lock : <fg=green>OK'); |
65
|
|
|
} elseif(!$test->testWritable($domain)){ |
66
|
|
|
$this->success += 1; |
67
|
|
|
$this->line('<fg=default>Auto Lock : <fg=yellow>Warning (Permission denied)'); |
68
|
|
|
} else{ |
69
|
|
|
$this->error += 1; |
70
|
|
|
$this->line('<fg=default>Auto Lock : <fg=red>Failed'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
private function testManualLock($domain){ |
74
|
|
|
$test = new Testing(); |
75
|
|
|
if( $test->testManualLocking($domain)){ |
76
|
|
|
$this->success += 1; |
77
|
|
|
$this->line('<fg=default>Manual Lock : <fg=green>OK'); |
78
|
|
|
} else{ |
79
|
|
|
$this->error += 1; |
80
|
|
|
$this->line('<fg=default>Manual Lock : <fg=red>Failed'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
private function testUnlock($domain){ |
84
|
|
|
$test = new Testing(); |
85
|
|
|
if( $test->testUnlocking($domain)){ |
86
|
|
|
$this->success += 1; |
87
|
|
|
$this->line('<fg=default>Unlock Account : <fg=green>OK'); |
88
|
|
|
} else{ |
89
|
|
|
$this->error += 1; |
90
|
|
|
$this->line('<fg=default>Unlock Account : <fg=red>Failed'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function testLocked($domain){ |
95
|
|
|
$test = new Testing(); |
96
|
|
|
if( $test->testLockLogin($domain)){ |
97
|
|
|
$this->success += 1; |
98
|
|
|
$this->line('<fg=default>Try Login with locked account : <fg=green>Account is Locked'); |
99
|
|
|
} else{ |
100
|
|
|
$this->error += 1; |
101
|
|
|
$this->line('<fg=default>Try Login with locked account : <fg=red>Account logged in'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
private function testConfigurations(){ |
106
|
|
|
$test = new Testing(); |
107
|
|
|
$res = $test->testConfig(); |
108
|
|
|
|
109
|
|
|
$table = new Table($this->output); |
110
|
|
|
$this->line('<fg=cyan>Testing Config:'); |
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"], |
121
|
|
|
|
122
|
|
|
]); |
123
|
|
|
$table->render(); |
124
|
|
|
$this->errorCheck($res); |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
private function errorCheck($res){ |
129
|
|
|
$this->configExists($res); |
130
|
|
|
$this->configCheck($res); |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
private function configCheck($res){ |
135
|
|
|
if($res['err'] > 0){ |
136
|
|
|
$this->line('<fg=red>Config invalid, testing is canceled.'); |
137
|
|
|
$this->line('<fg=default>--------------------------------------------'); |
138
|
|
|
$this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s',time())); |
139
|
|
|
exit(); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
private function configExists($res){ |
144
|
|
|
if($res['err'] > 0 AND !empty($res['file'])){ |
145
|
|
|
$this->line('<fg=red>Testing config failed, testing is canceled.'); |
146
|
|
|
$this->line($res['file']); |
147
|
|
|
$this->line('<fg=default>--------------------------------------------'); |
148
|
|
|
$this->line('<fg=default>Tested at: '.date('Y-m-d H:m:s',time())); |
149
|
|
|
exit(); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths