香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mini_xzey/app/Http/Middleware/IntranetAccess.php

40 lines
798 B

<?php
declare(strict_types = 1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class IntranetAccess
{
/**
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next): mixed
{
$forwarded = $request->server("HTTP_X_REAL_IP");
if(!empty($forwarded)){
$ip = $forwarded;
}else{
$ip = $request->ip();
}
if(
$ip != '::1' &&
$ip != '127.0.0.1' &&
!str_starts_with($ip, "10.") &&
!str_starts_with($ip, "172.") &&
!str_starts_with($ip, "192.")
) {
return response('Not Found.', 404);
}
return $next($request);
}
}