typed config

This commit is contained in:
robert dennis
2026-10-12 05:18:57 -04:00
parent 8810ae5a78
commit bb0e915fde
35 changed files with 94 additions and 91 deletions
@@ -5,13 +5,13 @@ declare(strict_types=1);
namespace Pterodactyl\Http\Controllers\Api\Admin\Settings;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Fluent;
use Knuckles\Scribe\Attributes\Endpoint;
use Knuckles\Scribe\Attributes\Group;
use Knuckles\Scribe\Attributes\Response as ScribeResponse;
use Knuckles\Scribe\Attributes\Subgroup;
use Pterodactyl\Http\Controllers\Api\Admin\AdminApiController;
use Pterodactyl\Http\Requests\Api\Admin\Settings\GetSettingsRequest;
use Pterodactyl\Support\JsonValueGuard;
#[Group('Admin API', 'Root administrator endpoints for managing panel configuration and resources.')]
#[Subgroup('Settings', 'View and update global panel settings.')]
@@ -56,16 +56,19 @@ class SettingsController extends AdminApiController
#[ScribeResponse(self::SETTINGS_EXAMPLE, description: 'Settings returned.')]
public function index(GetSettingsRequest $request): JsonResponse
{
// Settings saved from the panel come back from the database as strings, so numbers are cast on read.
$settings = Fluent::make(config()->all());
return new JsonResponse([
'general' => [
'app:name' => config('app.name'),
'pterodactyl:auth:2fa_required' => JsonValueGuard::integer(config('pterodactyl.auth.2fa_required')),
'pterodactyl:auth:2fa_required' => $settings->integer('pterodactyl.auth.2fa_required'),
'app:locale' => config('app.locale'),
],
'mail' => [
'mail:default' => config('mail.default'),
'mail:mailers:smtp:host' => config('mail.mailers.smtp.host'),
'mail:mailers:smtp:port' => JsonValueGuard::integer(config('mail.mailers.smtp.port')),
'mail:mailers:smtp:port' => $settings->integer('mail.mailers.smtp.port'),
'mail:mailers:smtp:encryption' => config('mail.mailers.smtp.encryption'),
'mail:mailers:smtp:username' => config('mail.mailers.smtp.username'),
// Never return the SMTP password to the client.
@@ -74,17 +77,17 @@ class SettingsController extends AdminApiController
'mail:from:name' => config('mail.from.name'),
],
'advanced' => [
'recaptcha:enabled' => JsonValueGuard::boolean(config('recaptcha.enabled')),
'recaptcha:enabled' => config()->boolean('recaptcha.enabled'),
'recaptcha:secret_key' => '',
'recaptcha:website_key' => config('recaptcha.website_key'),
'pterodactyl:guzzle:timeout' => JsonValueGuard::integer(config('pterodactyl.guzzle.timeout')),
'pterodactyl:guzzle:connect_timeout' => JsonValueGuard::integer(config('pterodactyl.guzzle.connect_timeout')),
'pterodactyl:client_features:allocations:enabled' => JsonValueGuard::boolean(config('pterodactyl.client_features.allocations.enabled')),
'pterodactyl:guzzle:timeout' => $settings->integer('pterodactyl.guzzle.timeout'),
'pterodactyl:guzzle:connect_timeout' => $settings->integer('pterodactyl.guzzle.connect_timeout'),
'pterodactyl:client_features:allocations:enabled' => config()->boolean('pterodactyl.client_features.allocations.enabled'),
'pterodactyl:client_features:allocations:range_start' => config('pterodactyl.client_features.allocations.range_start'),
'pterodactyl:client_features:allocations:range_end' => config('pterodactyl.client_features.allocations.range_end'),
],
'meta' => [
'load_environment_only' => JsonValueGuard::boolean(config('pterodactyl.load_environment_only', false)),
'load_environment_only' => config()->boolean('pterodactyl.load_environment_only', false),
'show_recaptcha_warning' => config('recaptcha._shipped_secret_key') === config('recaptcha.secret_key')
|| config('recaptcha._shipped_website_key') === config('recaptcha.website_key'),
],
@@ -10,6 +10,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Fluent;
use Illuminate\Validation\ValidationException;
use Knuckles\Scribe\Attributes\BodyParam;
use Knuckles\Scribe\Attributes\Endpoint;
@@ -124,7 +125,7 @@ class LoginCheckpointController extends AbstractLoginController
$decrypted,
JsonValueGuard::nullableString($request->validated('authentication_code')) ?? '',
$oldTimestamp,
JsonValueGuard::integer(config('pterodactyl.auth.2fa.window', 1))
Fluent::make(config()->array('pterodactyl.auth.2fa'))->integer('window', 1)
);
if ($verified !== false) {