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.
39 lines
713 B
39 lines
713 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()->header("x-forwarded-for");
|
|
if($forwarded){
|
|
$ip = explode(',',$forwarded)[0];
|
|
}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);
|
|
}
|
|
|
|
}
|
|
|