İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class IpFirewall
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
// İzin verilen IP listesi (Env veya Config'den alınabilir)
|
||||
// Boş bırakılırsa herkese açık olur.
|
||||
$allowedIpsString = config('app.allowed_api_ips', '');
|
||||
|
||||
if (empty($allowedIpsString)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$allowedIps = explode(',', $allowedIpsString);
|
||||
$clientIp = $request->ip();
|
||||
|
||||
if (!in_array($clientIp, $allowedIps)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Access denied. IP not allowed.',
|
||||
'ip' => $clientIp
|
||||
], 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user