@@ -11,6 +11,10 @@ public function check($patterns)
11
11
{
12
12
$ status = false ;
13
13
14
+ if ($ this ->isEmpty ()) {
15
+ return $ status ;
16
+ }
17
+
14
18
if (!$ location = $ this ->getLocation ()) {
15
19
return $ status ;
16
20
}
@@ -34,6 +38,29 @@ public function check($patterns)
34
38
return $ status ;
35
39
}
36
40
41
+ protected function isEmpty ()
42
+ {
43
+ $ status = true ;
44
+
45
+ $ types = ['continents ' , 'regions ' , 'countries ' , 'cities ' ];
46
+
47
+ foreach ($ types as $ type ) {
48
+ if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ type )) {
49
+ continue ;
50
+ }
51
+
52
+ if (empty ($ list ['allow ' ]) && empty ($ list ['block ' ])) {
53
+ continue ;
54
+ }
55
+
56
+ $ status = false ;
57
+
58
+ break ;
59
+ }
60
+
61
+ return $ status ;
62
+ }
63
+
37
64
protected function isFiltered ($ location , $ type )
38
65
{
39
66
if (!$ list = config ('firewall.middleware. ' . $ this ->middleware . '. ' . $ type )) {
@@ -63,17 +90,6 @@ protected function getLocation()
63
90
return $ this ->$ service ($ location );
64
91
}
65
92
66
- protected function getResponse ($ url )
67
- {
68
- try {
69
- $ response = json_decode (file_get_contents ($ url ));
70
- } catch (\ErrorException $ e ) {
71
- $ response = null ;
72
- }
73
-
74
- return $ response ;
75
- }
76
-
77
93
protected function ipapi ($ location )
78
94
{
79
95
$ response = $ this ->getResponse ('http://ip-api.com/json/ ' . $ this ->ip () . '?fields=continent,country,regionName,city ' );
@@ -152,4 +168,23 @@ protected function ipinfo($location)
152
168
153
169
return $ location ;
154
170
}
171
+
172
+ protected function getResponse ($ url )
173
+ {
174
+ try {
175
+ $ ch = curl_init ();
176
+ curl_setopt ($ ch , CURLOPT_URL , $ url );
177
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
178
+ curl_setopt ($ ch , CURLOPT_TIMEOUT , 3 );
179
+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 3 );
180
+ $ content = curl_exec ($ ch );
181
+ curl_close ($ ch );
182
+
183
+ $ response = json_decode ($ content );
184
+ } catch (\ErrorException $ e ) {
185
+ $ response = null ;
186
+ }
187
+
188
+ return $ response ;
189
+ }
155
190
}
0 commit comments