Skip to content

Commit a1b3443

Browse files
authored
Added allowed IPs (alexjustesen#2160)
1 parent 512a855 commit a1b3443

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class AllowedIpAddressesMiddleware
10+
{
11+
/**
12+
* Handle an incoming request.
13+
*
14+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
15+
*/
16+
public function handle(Request $request, Closure $next): Response
17+
{
18+
if (blank(config('speedtest.allowed_ips'))) {
19+
return $next($request);
20+
}
21+
22+
$allowedIps = explode(',', config('speedtest.allowed_ips'));
23+
24+
return in_array($request->ip(), $allowedIps)
25+
? $next($request)
26+
: abort(403);
27+
}
28+
}

bootstrap/app.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
'public-dashboard' => App\Http\Middleware\PublicDashboard::class,
2020
]);
2121

22+
$middleware->prependToGroup('api', [
23+
App\Http\Middleware\AllowedIpAddressesMiddleware::class,
24+
]);
25+
26+
$middleware->prependToGroup('web', [
27+
App\Http\Middleware\AllowedIpAddressesMiddleware::class,
28+
]);
29+
2230
$middleware->redirectGuestsTo(fn () => route('filament.admin.auth.login'));
2331
$middleware->redirectUsersTo(AppServiceProvider::HOME);
2432

config/speedtest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/**
1212
* General settings.
1313
*/
14+
'allowed_ips' => env('ALLOWED_IPS'),
15+
1416
'content_width' => env('CONTENT_WIDTH', '7xl'),
1517

1618
'prune_results_older_than' => (int) env('PRUNE_RESULTS_OLDER_THAN', 0),

0 commit comments

Comments
 (0)