Files
coolify/app/Support/RootSetupWindow.php
T
Andras BacsaiandClaude Opus 5.5 aa016e685d fix(cache): accept numbers that Redis returns as strings
The root setup window and the scanner disk usage checked is_int() on
cached values, but the Redis store returns numbers as strings. The
setup window was closed right after each start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 17:52:03 +01:00

46 lines
1.2 KiB
PHP

<?php
namespace App\Support;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
/**
* The first registration creates the root user. It is allowed only for a short time after
* Coolify starts, so a bot cannot claim a fresh install. A restart opens the window again.
*/
class RootSetupWindow
{
public const MINUTES = 10;
private const CACHE_KEY = 'root-setup-window-closes-at';
/**
* The key has no TTL: app:init clears the cache before it calls this, so a missing key
* means that Coolify has not finished starting, not that the window is closed.
*/
public static function openIfNoUserExists(): void
{
if (User::query()->exists()) {
return;
}
Cache::forever(self::CACHE_KEY, now()->addMinutes(self::MINUTES)->getTimestamp());
}
/**
* The Redis store returns numbers as strings, so the value is not always an int.
*/
public static function isOpen(): bool
{
$closesAt = Cache::get(self::CACHE_KEY);
return is_numeric($closesAt) && now()->getTimestamp() < (int) $closesAt;
}
public static function isPending(): bool
{
return ! Cache::has(self::CACHE_KEY);
}
}