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
|
|
|
|
11
|
|
|
public function testConfig(){ |
12
|
|
|
$ret=[]; |
13
|
|
|
$ret['err'] = 0; |
14
|
|
|
if(!empty(config('irfa.lockout'))){ |
15
|
|
|
if(is_numeric(config('irfa.lockout.login_attemps'))){ |
16
|
|
|
$ret['login_attemps'] = '<fg=green>OK'; |
17
|
|
|
} else{ |
18
|
|
|
|
19
|
|
|
$ret['err'] +=1; |
20
|
|
|
$ret['login_attemps'] ='<fg=yellow>Must be a number'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if(is_bool(config('irfa.lockout.logging'))){ |
24
|
|
|
$ret['logging'] = '<fg=green>OK'; |
25
|
|
|
} else{ |
26
|
|
|
|
27
|
|
|
$ret['err'] +=1; |
28
|
|
|
$ret['logging'] = '<fg=yellow>Must be a Boolean'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if(is_string(config('irfa.lockout.input_name'))){ |
32
|
|
|
$ret['input_name'] = '<fg=green>OK'; |
33
|
|
|
} else{ |
34
|
|
|
|
35
|
|
|
$ret['err'] +=1; |
36
|
|
|
$ret['input_name'] = '<fg=yellow>Must be a String'; |
37
|
|
|
} |
38
|
|
|
if(is_writable(config('irfa.lockout.lockout_file_path'))){ |
39
|
|
|
$ret['lockout_file_path'] = '<fg=green>OK'; |
40
|
|
|
} else{ |
41
|
|
|
$ret['lockout_file_path'] = '<fg=yellow>Write Permission Denied in '.config('irfa.lockout.lockout_file_path'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if(!empty(config('irfa.lockout.redirect_url'))){ |
45
|
|
|
$ret['redirect_url'] = '<fg=green>OK'; |
46
|
|
|
} else{ |
47
|
|
|
|
48
|
|
|
$ret['err'] +=1; |
49
|
|
|
$ret['redirect_url'] = '<fg=yellow>Must be provided'; |
50
|
|
|
} |
51
|
|
|
if(is_array(config('irfa.lockout.protected_action_path'))){ |
52
|
|
|
$ret['protected_action_path'] = '<fg=green>OK'; |
53
|
|
|
} else{ |
54
|
|
|
|
55
|
|
|
$ret['err'] +=1; |
56
|
|
|
$ret['protected_action_path'] = '<fg=yellow>Must be array'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if(is_array(config('irfa.lockout.protected_middleware_group'))){ |
60
|
|
|
if(!empty(config('irfa.lockout.protected_middleware_group'))){ |
61
|
|
|
$ret['protected_middleware_group'] = '<fg=green>OK'; |
62
|
|
|
} else{ |
63
|
|
|
$ret['err'] +=1; |
64
|
|
|
$ret['protected_middleware_group'] = '<fg=yellow>Must be provided'; |
65
|
|
|
} |
66
|
|
|
} else{ |
67
|
|
|
|
68
|
|
|
$ret['err'] +=1; |
69
|
|
|
$ret['protected_middleware_group'] = '<fg=yellow>Must be array'; |
70
|
|
|
} |
71
|
|
|
if(is_string(config('irfa.lockout.message_name'))){ |
72
|
|
|
$ret['message_name'] = '<fg=green>OK'; |
73
|
|
|
} else{ |
74
|
|
|
|
75
|
|
|
$ret['err'] +=1; |
76
|
|
|
$ret['message_name'] = '<fg=yellow>Must be a String'; |
77
|
|
|
} |
78
|
|
|
} else{ |
79
|
|
|
$ret['err'] +=1; |
80
|
|
|
$ret['file'] = "<fg=yellow> Could't find config file. Try to run <fg=cyan>php artisan vendor:publish --tag=lockout-account"; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $ret; |
84
|
|
|
} |
85
|
|
|
public function testWriteEventFailedLogin($username){ |
86
|
|
|
|
87
|
|
|
$this->eventFailedLogin($username); |
88
|
|
|
|
89
|
|
|
$input = $username; |
90
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
91
|
|
|
$path = $dir.md5($input); |
92
|
|
|
|
93
|
|
|
if(File::exists($path)) |
94
|
|
|
{ |
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
public function testWritable($username){ |
100
|
|
|
$input = $username; |
101
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
102
|
|
|
$path = $dir.md5($input); |
103
|
|
|
|
104
|
|
|
if(is_writable($path)) |
105
|
|
|
{ |
106
|
|
|
return true; |
107
|
|
|
} |
108
|
|
|
return false; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testManualLocking($username){ |
112
|
|
|
$input = $username; |
113
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
114
|
|
|
$path = $dir.md5($input); |
|
|
|
|
115
|
|
|
|
116
|
|
|
if($this->lock_account($username)) |
117
|
|
|
{ |
118
|
|
|
return true; |
119
|
|
|
} |
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testUnlocking($username){ |
124
|
|
|
$input = $username; |
125
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
126
|
|
|
$path = $dir.md5($input); |
|
|
|
|
127
|
|
|
$unlock = $this->test_unlock_account($username); |
128
|
|
|
if($unlock) |
129
|
|
|
{ |
130
|
|
|
return true; |
131
|
|
|
} |
132
|
|
|
return false; |
133
|
|
|
} |
134
|
|
|
public function testLockLogin($username){ |
135
|
|
|
$input = $username; |
136
|
|
|
$dir = config('irfa.lockout.lockout_file_path'); |
137
|
|
|
$path = $dir.md5($input); |
|
|
|
|
138
|
|
|
$unlock = $this->lockLogin($username); |
139
|
|
|
if($unlock) |
140
|
|
|
{ |
141
|
|
|
return true; |
142
|
|
|
} |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|