Disable reinstall action during normal server status if "skip egg install scripts" setting is enabled (#5696)

### Description

You're able to enable a "skip egg install scripts" per server, while
still being able to reinstall a server. With this setting enabled,
reinstalling a server has no functional use, the server is locked and
shutdown, then simply unlocked immediately afterwards after a success
signal from wings. This PR disables the reinstall button when skip
install scripts is enabled for both the user and admin, with a little
component telling you why you cannot reinstall. The reinstall button is
not disabled if the server is in a status that reinstall could resolve
(eg. failed install).

### Resolved issues:
1. [x] resolves pterodactyl/panel#5306
This commit is contained in:
SkyMulley
2026-08-10 11:39:22 -04:00
committed by GitHub
parent 97ed7f2042
commit 850f2b9a4f
13 changed files with 269 additions and 2 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ class DisplayException extends PterodactylException implements HttpExceptionInte
*/
public function render(Request $request): JsonResponse|RedirectResponse
{
if ($request->expectsJson()) {
if ($request->expectsJson() || $request->is('api/*')) {
return response()->json(Handler::toArray($this), $this->getStatusCode(), $this->getHeaders());
}
+13
View File
@@ -220,6 +220,19 @@ class Server extends Model implements Identifiable
return $this->status === self::STATUS_SUSPENDED;
}
/**
* A server that skips its egg's install script gains nothing from a reinstall. The one
* exception is a server sitting in a failed state, where that report is the way back out.
*/
public function canBeReinstalled(): bool
{
return !$this->skip_scripts || in_array($this->status, [
self::STATUS_INSTALLING,
self::STATUS_INSTALL_FAILED,
self::STATUS_REINSTALL_FAILED,
], true);
}
/**
* Gets the user who owns the server.
*
@@ -4,6 +4,7 @@ namespace Pterodactyl\Services\Servers;
use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class ReinstallServerService
@@ -21,9 +22,14 @@ class ReinstallServerService
* Reinstall a server on the remote daemon.
*
* @throws \Throwable
* @throws DisplayException
*/
public function handle(Server $server): Server
{
if (!$server->canBeReinstalled()) {
throw new DisplayException(trans('admin/server.exceptions.skipping_install_script'));
}
return $this->connection->transaction(function () use ($server) {
$server->fill(['status' => Server::STATUS_INSTALLING])->save();
@@ -85,6 +85,7 @@ class ServerTransformer extends BaseTransformer
// This field is deprecated, please use "status".
'installed' => $server->isInstalled() ? 1 : 0,
'environment' => $this->environmentService->handle($server),
'skip_scripts' => $server->skip_scripts,
],
$server->getUpdatedAtColumn() => $this->formatTimestamp($server->updated_at),
$server->getCreatedAtColumn() => $this->formatTimestamp($server->created_at),
@@ -79,6 +79,7 @@ class ServerTransformer extends BaseClientTransformer
// This field is deprecated, please use "status".
'is_installing' => !$server->isInstalled(),
'is_transferring' => !is_null($server->transfer),
'skip_scripts' => $server->skip_scripts,
];
}
+1
View File
@@ -4,6 +4,7 @@ return [
'exceptions' => [
'no_new_default_allocation' => 'You are attempting to delete the default allocation for this server but there is no fallback allocation to use.',
'marked_as_failed' => 'This server was marked as having failed a previous installation. Current status cannot be toggled in this state.',
'skipping_install_script' => 'This server is configured to skip its egg\'s install script. Reinstalling is not available until that setting is disabled.',
'bad_variable' => 'There was a validation error with the :name variable.',
'daemon_exception' => 'There was an exception while attempting to communicate with the daemon resulting in a HTTP/:code response code. This exception has been logged. (request id: :request_id)',
'default_allocation_not_found' => 'The requested default allocation was not found in this server\'s allocations.',
@@ -58,6 +58,7 @@ export interface Server {
backups: number;
};
isTransferring: boolean;
skipScripts: boolean;
variables: ServerEggVariable[];
allocations: Allocation[];
}
@@ -83,6 +84,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
eggFeatures: data.egg_features || [],
featureLimits: { ...data.feature_limits },
isTransferring: data.is_transferring,
skipScripts: data.skip_scripts,
variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
rawDataToServerEggVariable
),
@@ -11,6 +11,7 @@ import { Dialog } from '@/components/elements/dialog';
export default () => {
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
const skipScripts = ServerContext.useStoreState((state) => state.server.data!.skipScripts);
const [modalVisible, setModalVisible] = useState(false);
const { addFlash, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
@@ -36,6 +37,17 @@ export default () => {
clearFlashes();
}, []);
if (skipScripts) {
return (
<TitledGreyBox title={'Reinstall Server'}>
<p css={tw`text-sm`}>
Reinstalling this server has been disabled because it is configured to skip its egg&apos;s install
script. If you would like to reinstall this server, contact a server administrator.
</p>
</TitledGreyBox>
);
}
return (
<TitledGreyBox title={'Reinstall Server'} css={tw`relative`}>
<Dialog.Confirm
@@ -26,7 +26,10 @@
<p>This will reinstall the server with the assigned service scripts. <strong>Danger!</strong> This could overwrite server data.</p>
</div>
<div class="box-footer">
@if($server->isInstalled())
@if(! $server->canBeReinstalled())
<button class="btn btn-danger disabled">Reinstall Server</button>
<p style="padding-top: 1rem;">This server is set to skip its install script. Disable "Skip Egg Install Script" on the startup page to reinstall it.</p>
@elseif($server->isInstalled())
<form action="{{ route('admin.servers.view.manage.reinstall', $server->id) }}" method="POST">
{!! csrf_field() !!}
<button type="submit" class="btn btn-danger">Reinstall Server</button>
@@ -0,0 +1,26 @@
<?php
namespace Pterodactyl\Tests\Integration\Api\Application\Servers;
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
class ServerControllerTest extends ApplicationApiIntegrationTestCase
{
/**
* Test that the "skip scripts" state is returned for a server.
*/
public function testSkipScriptsStateIsReturned()
{
$server = $this->createServerModel(['skip_scripts' => true]);
$this->getJson('/api/application/servers/' . $server->id)
->assertOk()
->assertJsonPath('attributes.container.skip_scripts', true);
$server->update(['skip_scripts' => false]);
$this->getJson('/api/application/servers/' . $server->id)
->assertOk()
->assertJsonPath('attributes.container.skip_scripts', false);
}
}
@@ -0,0 +1,103 @@
<?php
namespace Pterodactyl\Tests\Integration\Api\Application\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
class ServerManagementControllerTest extends ApplicationApiIntegrationTestCase
{
/**
* Test that a server can be reinstalled.
*/
public function testServerCanBeReinstalled()
{
$server = $this->createServerModel();
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')
->with(\Mockery::on(fn ($value) => $value->uuid === $server->uuid))
->andReturnSelf()
->getMock()
->expects('reinstall')
->andReturnUndefined();
$this->postJson('/api/application/servers/' . $server->id . '/reinstall')
->assertStatus(Response::HTTP_NO_CONTENT);
$this->assertSame(Server::STATUS_INSTALLING, $server->refresh()->status);
}
/**
* Test that a server configured to skip its egg's install script cannot be reinstalled.
*/
public function testServerConfiguredToSkipScriptsCannotBeReinstalled()
{
$server = $this->createServerModel(['skip_scripts' => true]);
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')->never();
$this->postJson('/api/application/servers/' . $server->id . '/reinstall')
->assertStatus(Response::HTTP_BAD_REQUEST)
->assertJsonPath('errors.0.detail', trans('admin/server.exceptions.skipping_install_script'));
}
/**
* Test that a client which does not explicitly ask for JSON still receives the error status
* rather than being redirected away from the API.
*/
public function testBlockedReinstallReturnsAnErrorToClientsNotRequestingJson()
{
$server = $this->createServerModel(['skip_scripts' => true]);
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')->never();
$this->post('/api/application/servers/' . $server->id . '/reinstall', [], ['Accept' => '*/*'])
->assertStatus(Response::HTTP_BAD_REQUEST)
->assertJsonPath('errors.0.detail', trans('admin/server.exceptions.skipping_install_script'));
}
/**
* Test that a server configured to skip its egg's install script can still be reinstalled
* while it is in a failed state, since that is the only way to pull it back out of one.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('recoverableStatusesDataProvider')]
public function testServerConfiguredToSkipScriptsCanBeReinstalledFromAFailedState(string $status)
{
$server = $this->createServerModel(['skip_scripts' => true, 'status' => $status]);
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')
->with(\Mockery::on(fn ($value) => $value->uuid === $server->uuid))
->andReturnSelf()
->getMock()
->expects('reinstall')
->andReturnUndefined();
$this->postJson('/api/application/servers/' . $server->id . '/reinstall')
->assertStatus(Response::HTTP_NO_CONTENT);
$this->assertSame(Server::STATUS_INSTALLING, $server->refresh()->status);
}
public static function recoverableStatusesDataProvider(): array
{
return [
[Server::STATUS_INSTALLING],
[Server::STATUS_INSTALL_FAILED],
[Server::STATUS_REINSTALL_FAILED],
];
}
}
@@ -110,6 +110,48 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
$this->assertTrue($server->isInstalled());
}
/**
* Test that a server configured to skip its egg's install script cannot be reinstalled.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('reinstallPermissionsDataProvider')]
public function testServerCannotBeReinstalledIfConfiguredToSkipScripts(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
$server->update(['skip_scripts' => true]);
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')->never();
$this->actingAs($user)
->postJson("/api/client/servers/$server->uuid/settings/reinstall")
->assertStatus(Response::HTTP_BAD_REQUEST)
->assertJsonPath('errors.0.detail', trans('admin/server.exceptions.skipping_install_script'));
$this->assertNull($server->refresh()->status);
}
/**
* Test that the "skip scripts" state is exposed to the client API.
*/
public function testSkipScriptsStateIsExposedToClient()
{
[$user, $server] = $this->generateTestAccount([Permission::ACTION_SETTINGS_REINSTALL]);
$this->actingAs($user)
->getJson("/api/client/servers/$server->uuid")
->assertOk()
->assertJsonPath('attributes.skip_scripts', false);
$server->update(['skip_scripts' => true]);
$this->actingAs($user)
->getJson("/api/client/servers/$server->uuid")
->assertOk()
->assertJsonPath('attributes.skip_scripts', true);
}
public static function renamePermissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SETTINGS_RENAME]]];
@@ -0,0 +1,57 @@
<?php
namespace Pterodactyl\Tests\Integration\Http\Controllers\Admin\ServersController;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server;
use Pterodactyl\Tests\Integration\Http\HttpTestCase;
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class ReinstallServerTest extends HttpTestCase
{
/**
* Test that a server can be reinstalled from the admin area.
*/
public function testServerCanBeReinstalled(): void
{
$server = $this->createServerModel();
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')
->with(\Mockery::on(fn ($value) => $value->uuid === $server->uuid))
->andReturnSelf()
->getMock()
->expects('reinstall')
->andReturnUndefined();
$this->actingAs(User::factory()->admin()->create())
->withHeaders(['Accept' => 'text/html'])
->post(route('admin.servers.view.manage.reinstall', ['server' => $server]))
->assertRedirect();
$this->assertSame(Server::STATUS_INSTALLING, $server->refresh()->status);
}
/**
* Test that a server configured to skip its egg's install script cannot be reinstalled from
* the admin area.
*/
public function testServerConfiguredToSkipScriptsCannotBeReinstalled(): void
{
$server = $this->createServerModel(['skip_scripts' => true]);
$service = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $service);
$service->expects('setServer')->never();
$this->actingAs(User::factory()->admin()->create())
->withHeaders(['Accept' => 'text/html'])
->post(route('admin.servers.view.manage.reinstall', ['server' => $server]))
->assertRedirect();
$this->assertNull($server->refresh()->status);
}
}