Skip to content

Commit b91cf5b

Browse files
author
Karel Mareš
committed
support environments
1 parent b401816 commit b91cf5b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

config/ip-filter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
|
1313
*/
1414

15+
// Env - only use filter on listed environments
16+
'env' => ['production'],
17+
1518
// White list - List of allowed IP addresses
1619
'allowed' => [],
1720

src/FilterIp.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ public function handle($request, Closure $next)
1818
{
1919
$whiteList = config('ip-filter.allowed', []);
2020
$blackList = config('ip-filter.denied', []);
21+
$environments = config('ip-filter.env', []);
22+
$appEnvironment = config('app.env');
2123
$ip = $request->ip();
2224

2325
if (
24-
(!count($whiteList) && !count($blackList)) ||
25-
count($whiteList) > 0 && in_array($ip, $whiteList) ||
26-
count($blackList) > 0 && !in_array($ip, $blackList)
27-
) {
26+
!in_array($appEnvironment, $environments) || (
27+
(!count($whiteList) && !count($blackList)) ||
28+
count($whiteList) > 0 && in_array($ip, $whiteList) ||
29+
count($blackList) > 0 && !in_array($ip, $blackList)
30+
)) {
2831
return $next($request);
2932
}
3033
}

0 commit comments

Comments
 (0)