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>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user