Files
citrus-cms/app/Http/Middleware/IpFirewall.php
T
2026-04-28 21:14:25 +03:00

38 lines
942 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);
}
}