1
|
|
|
<?php |
2
|
|
|
namespace Irfa\Lockout\Func; |
3
|
|
|
|
4
|
|
|
use Irfa\Lockout\Func\Core; |
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use View; |
7
|
|
|
use File; |
8
|
|
|
|
9
|
|
|
class Testing extends Core { |
10
|
|
|
private $ret = []; |
11
|
|
|
|
12
|
|
|
public function testConfig(){ |
13
|
|
|
$this->ret=[]; |
14
|
|
|
$this->ret['err'] = 0; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
if(!empty(config('irfa.lockout'))){ |
18
|
|
|
$this->confLoginAttemps(); |
19
|
|
|
$this->confLogging(); |
20
|
|
|
$this->confInput(); |
21
|
|
|
$this->confFilePath(); |
22
|
|
|
$this->confRedirectUrl(); |
23
|
|
|
$this->confProtectActionPath(); |
24
|
|
|
$this->confProtectMiddleware(); |
25
|
|
|
$this->confMessage(); |
26
|
|
|
$this->confExceptEnabled(); |
27
|
|
|
$this->confExceptAccount(); |
28
|
|
|
|
29
|
|
|
} else{ |
30
|
|
|
$this->ret['err'] +=1; |
31
|
|
|
$this->ret['file'] = "<fg=yellow> Could't find config file. Try to run <fg=cyan>php artisan vendor:publish --tag=lockout-account"; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $this->ret; |
35
|
|
|
} |
36
|
|
|
public function testWriteEventFailedLogin($username){ |
37
|
|
|
|
38
|
|
|
$this->eventFailedLogin($username); |
39
|
|
|
|
40
|
|
|
$input = $username; |
41
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
42
|
|
|
$path = $dir.md5($input); |
43
|
|
|
|
44
|
|
|
if(File::exists($path)) |
45
|
|
|
{ |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
return false; |
49
|
|
|
} |
50
|
|
|
public function testWritable($username){ |
51
|
|
|
$input = $username; |
52
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
53
|
|
|
$path = $dir.md5($input); |
54
|
|
|
|
55
|
|
|
if(is_writable($path)) |
56
|
|
|
{ |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testManualLocking($username){ |
63
|
|
|
$input = $username; |
64
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
65
|
|
|
$path = $dir.md5($input); |
|
|
|
|
66
|
|
|
|
67
|
|
|
if($this->lock_account($username)) |
68
|
|
|
{ |
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
public function testUnlocking($username){ |
74
|
|
|
$input = $username; |
75
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
76
|
|
|
$path = $dir.md5($input); |
|
|
|
|
77
|
|
|
$unlock = $this->test_unlock_account($username); |
78
|
|
|
if($unlock) |
79
|
|
|
{ |
80
|
|
|
return true; |
81
|
|
|
} |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
public function testLockLogin($username){ |
85
|
|
|
$input = $username; |
86
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
87
|
|
|
$path = $dir.md5($input); |
|
|
|
|
88
|
|
|
$unlock = $this->lockLogin($username); |
89
|
|
|
if($unlock) |
90
|
|
|
{ |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
//////Config |
96
|
|
|
private function confLoginAttemps(){ |
97
|
|
|
if(is_numeric(config('irfa.lockout.login_attemps'))){ |
98
|
|
|
$this->ret['login_attemps'] = '<fg=green>OK'; |
99
|
|
|
} else{ |
100
|
|
|
|
101
|
|
|
$this->ret['err'] +=1; |
102
|
|
|
$this->ret['login_attemps'] ='<fg=red>Must be a number'; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function confLogging(){ |
107
|
|
|
if(is_bool(config('irfa.lockout.logging'))){ |
108
|
|
|
$this->ret['logging'] = '<fg=green>OK'; |
109
|
|
|
} else{ |
110
|
|
|
|
111
|
|
|
$this->ret['err'] +=1; |
112
|
|
|
$this->ret['logging'] = '<fg=red>Must be a Boolean'; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
private function confInput(){ |
116
|
|
|
|
117
|
|
|
if(is_string(config('irfa.lockout.input_name'))){ |
118
|
|
|
$this->ret['input_name'] = '<fg=green>OK'; |
119
|
|
|
} else{ |
120
|
|
|
|
121
|
|
|
$this->ret['err'] +=1; |
122
|
|
|
$this->ret['input_name'] = '<fg=red>Must be a String'; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
private function confFilePath(){ |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
if(is_writable(config('irfa.lockout.lockout_file_path'))){ |
129
|
|
|
$this->ret['lockout_file_path'] = '<fg=green>OK'; |
130
|
|
|
} else{ |
131
|
|
|
$this->ret['lockout_file_path'] = '<fg=yellow>Write Permission Denied in '.config('irfa.lockout.lockout_file_path'); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
private function confRedirectUrl(){ |
135
|
|
|
if(!empty(config('irfa.lockout.redirect_url'))){ |
136
|
|
|
$this->ret['redirect_url'] = '<fg=green>OK'; |
137
|
|
|
} else{ |
138
|
|
|
|
139
|
|
|
$this->ret['err'] +=1; |
140
|
|
|
$this->ret['redirect_url'] = '<fg=red>Must be provided'; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
private function confProtectActionPath(){ |
144
|
|
|
if(is_array(config('irfa.lockout.protected_action_path'))){ |
145
|
|
|
$this->ret['protected_action_path'] = '<fg=green>OK'; |
146
|
|
|
if(!empty(config('irfa.lockout.protected_action_path'))){ |
147
|
|
|
$this->ret['protected_action_path'] = '<fg=green>OK'; |
148
|
|
|
} else{ |
149
|
|
|
$this->ret['err'] +=1; |
150
|
|
|
$this->ret['protected_action_path'] = '<fg=red>Must be provided'; |
151
|
|
|
} |
152
|
|
|
} else{ |
153
|
|
|
|
154
|
|
|
$this->ret['err'] +=1; |
155
|
|
|
$this->ret['protected_action_path'] = '<fg=red>Must be array'; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
} |
159
|
|
|
private function confProtectMiddleware(){ |
160
|
|
|
if(is_array(config('irfa.lockout.protected_middleware_group'))){ |
161
|
|
|
if(!empty(config('irfa.lockout.protected_middleware_group'))){ |
162
|
|
|
$this->ret['protected_middleware_group'] = '<fg=green>OK'; |
163
|
|
|
} else{ |
164
|
|
|
$this->ret['err'] +=1; |
165
|
|
|
$this->ret['protected_middleware_group'] = '<fg=red>Must be provided'; |
166
|
|
|
} |
167
|
|
|
} else{ |
168
|
|
|
|
169
|
|
|
$this->ret['err'] +=1; |
170
|
|
|
$this->ret['protected_middleware_group'] = '<fg=red>Must be array'; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
private function confMessage(){ |
175
|
|
|
if(is_string(config('irfa.lockout.message_name'))){ |
176
|
|
|
$this->ret['message_name'] = '<fg=green>OK'; |
177
|
|
|
} else{ |
178
|
|
|
|
179
|
|
|
$this->ret['err'] +=1; |
180
|
|
|
$this->ret['message_name'] = '<fg=red>Must be a String'; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
} |
184
|
|
|
private function confExceptEnabled(){ |
185
|
|
|
if(is_bool(config('irfa.lockout.enable_except_account'))){ |
186
|
|
|
$this->ret['enable_except_account'] = '<fg=green>OK'; |
187
|
|
|
} else{ |
188
|
|
|
|
189
|
|
|
$this->ret['err'] +=1; |
190
|
|
|
$this->ret['enable_except_account'] = '<fg=red>Must be a String'; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
private function confExceptAccount(){ |
195
|
|
|
if(is_array(config('irfa.lockout.except_account'))){ |
196
|
|
|
if(!empty(config('irfa.lockout.except_account'))){ |
197
|
|
|
$this->ret['except_account'] = '<fg=green>OK'; |
198
|
|
|
} else{ |
199
|
|
|
if(config('irfa.lockout.enable_except_account')){ |
200
|
|
|
|
201
|
|
|
$this->ret['except_account'] = '<fg=yellow>NOT SET'; |
202
|
|
|
} else{ |
203
|
|
|
|
204
|
|
|
$this->ret['except_account'] = '<fg=green>OK'; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
} else{ |
208
|
|
|
|
209
|
|
|
$this->ret['err'] +=1; |
210
|
|
|
$this->ret['except_account'] = '<fg=red>Must be a array'; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|