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
|
|
|
|
27
|
|
|
} else{ |
28
|
|
|
$this->ret['err'] +=1; |
29
|
|
|
$this->ret['file'] = "<fg=yellow> Could't find config file. Try to run <fg=cyan>php artisan vendor:publish --tag=lockout-account"; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this->ret; |
33
|
|
|
} |
34
|
|
|
public function testWriteEventFailedLogin($username){ |
35
|
|
|
|
36
|
|
|
$this->eventFailedLogin($username); |
37
|
|
|
|
38
|
|
|
$input = $username; |
39
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
40
|
|
|
$path = $dir.md5($input); |
41
|
|
|
|
42
|
|
|
if(File::exists($path)) |
43
|
|
|
{ |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
public function testWritable($username){ |
49
|
|
|
$input = $username; |
50
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
51
|
|
|
$path = $dir.md5($input); |
52
|
|
|
|
53
|
|
|
if(is_writable($path)) |
54
|
|
|
{ |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testManualLocking($username){ |
61
|
|
|
$input = $username; |
62
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
63
|
|
|
$path = $dir.md5($input); |
|
|
|
|
64
|
|
|
|
65
|
|
|
if($this->lock_account($username)) |
66
|
|
|
{ |
67
|
|
|
return true; |
68
|
|
|
} |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
public function testUnlocking($username){ |
72
|
|
|
$input = $username; |
73
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
74
|
|
|
$path = $dir.md5($input); |
|
|
|
|
75
|
|
|
$unlock = $this->test_unlock_account($username); |
76
|
|
|
if($unlock) |
77
|
|
|
{ |
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
public function testLockLogin($username){ |
83
|
|
|
$input = $username; |
84
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
85
|
|
|
$path = $dir.md5($input); |
|
|
|
|
86
|
|
|
$unlock = $this->lockLogin($username); |
87
|
|
|
if($unlock) |
88
|
|
|
{ |
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
//////Config |
94
|
|
|
private function confLoginAttemps(){ |
95
|
|
|
if(is_numeric(config('irfa.lockout.login_attemps'))){ |
96
|
|
|
$this->ret['login_attemps'] = '<fg=green>OK'; |
97
|
|
|
} else{ |
98
|
|
|
|
99
|
|
|
$this->ret['err'] +=1; |
100
|
|
|
$this->ret['login_attemps'] ='<fg=yellow>Must be a number'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private function confLogging(){ |
105
|
|
|
if(is_bool(config('irfa.lockout.logging'))){ |
106
|
|
|
$this->ret['logging'] = '<fg=green>OK'; |
107
|
|
|
} else{ |
108
|
|
|
|
109
|
|
|
$this->ret['err'] +=1; |
110
|
|
|
$this->ret['logging'] = '<fg=yellow>Must be a Boolean'; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
private function confInput(){ |
114
|
|
|
|
115
|
|
|
if(is_string(config('irfa.lockout.input_name'))){ |
116
|
|
|
$this->ret['input_name'] = '<fg=green>OK'; |
117
|
|
|
} else{ |
118
|
|
|
|
119
|
|
|
$this->ret['err'] +=1; |
120
|
|
|
$this->ret['input_name'] = '<fg=yellow>Must be a String'; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
private function confFilePath(){ |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
if(is_writable(config('irfa.lockout.lockout_file_path'))){ |
127
|
|
|
$this->ret['lockout_file_path'] = '<fg=green>OK'; |
128
|
|
|
} else{ |
129
|
|
|
$this->ret['lockout_file_path'] = '<fg=yellow>Write Permission Denied in '.config('irfa.lockout.lockout_file_path'); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
private function confRedirectUrl(){ |
133
|
|
|
if(!empty(config('irfa.lockout.redirect_url'))){ |
134
|
|
|
$this->ret['redirect_url'] = '<fg=green>OK'; |
135
|
|
|
} else{ |
136
|
|
|
|
137
|
|
|
$this->ret['err'] +=1; |
138
|
|
|
$this->ret['redirect_url'] = '<fg=yellow>Must be provided'; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
private function confProtectActionPath(){ |
142
|
|
|
if(is_array(config('irfa.lockout.protected_action_path'))){ |
143
|
|
|
$this->ret['protected_action_path'] = '<fg=green>OK'; |
144
|
|
|
} else{ |
145
|
|
|
|
146
|
|
|
$this->ret['err'] +=1; |
147
|
|
|
$this->ret['protected_action_path'] = '<fg=yellow>Must be array'; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
private function confProtectMiddleware(){ |
152
|
|
|
if(is_array(config('irfa.lockout.protected_middleware_group'))){ |
153
|
|
|
if(!empty(config('irfa.lockout.protected_middleware_group'))){ |
154
|
|
|
$this->ret['protected_middleware_group'] = '<fg=green>OK'; |
155
|
|
|
} else{ |
156
|
|
|
$this->ret['err'] +=1; |
157
|
|
|
$this->ret['protected_middleware_group'] = '<fg=yellow>Must be provided'; |
158
|
|
|
} |
159
|
|
|
} else{ |
160
|
|
|
|
161
|
|
|
$this->ret['err'] +=1; |
162
|
|
|
$this->ret['protected_middleware_group'] = '<fg=yellow>Must be array'; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
private function confMessage(){ |
167
|
|
|
if(is_string(config('irfa.lockout.message_name'))){ |
168
|
|
|
$this->ret['message_name'] = '<fg=green>OK'; |
169
|
|
|
} else{ |
170
|
|
|
|
171
|
|
|
$this->ret['err'] +=1; |
172
|
|
|
$this->ret['message_name'] = '<fg=yellow>Must be a String'; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|