Files
MahdiandCursor e92be66e54 feat: SuperAdmin server-access kill switch gate
Add /super/settings endpoints and API middleware that returns generic 503 while keeping unlock routes whitelisted.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-11 15:51:17 +03:30

45 lines
993 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class BlockServerAccess
{
public const CACHE_KEY = 'sa_server_access_blocked';
public function handle(Request $request, Closure $next)
{
$path = trim($request->path(), '/');
if ($this->isWhitelisted($path)) {
return $next($request);
}
if (Cache::get(self::CACHE_KEY)) {
return response()->json([
'message' => 'خطا در برقراری ارتباط با سرور',
], 503);
}
return $next($request);
}
private function isWhitelisted(string $path): bool
{
$allowed = [
'super/settings',
'api/super/settings',
];
foreach ($allowed as $item) {
if ($path === $item || str_ends_with($path, '/'.$item)) {
return true;
}
}
return false;
}
}