diff --git a/app/Exceptions/DisplayException.php b/app/Exceptions/DisplayException.php index 884df9a89..26e662cc6 100644 --- a/app/Exceptions/DisplayException.php +++ b/app/Exceptions/DisplayException.php @@ -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()); } diff --git a/app/Models/Server.php b/app/Models/Server.php index 7411a2a9c..0773823d4 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -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. * diff --git a/app/Services/Servers/ReinstallServerService.php b/app/Services/Servers/ReinstallServerService.php index 182223828..d18a76d41 100644 --- a/app/Services/Servers/ReinstallServerService.php +++ b/app/Services/Servers/ReinstallServerService.php @@ -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(); diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index e5db01fb2..e7caee392 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -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), diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index 747d2f2d8..6cddc112d 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -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, ]; } diff --git a/resources/lang/en/admin/server.php b/resources/lang/en/admin/server.php index 29cb72d18..ff7747eef 100644 --- a/resources/lang/en/admin/server.php +++ b/resources/lang/en/admin/server.php @@ -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.', diff --git a/resources/scripts/api/server/getServer.ts b/resources/scripts/api/server/getServer.ts index 16743ef87..d24194447 100644 --- a/resources/scripts/api/server/getServer.ts +++ b/resources/scripts/api/server/getServer.ts @@ -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 ), diff --git a/resources/scripts/components/server/settings/ReinstallServerBox.tsx b/resources/scripts/components/server/settings/ReinstallServerBox.tsx index 3a5a8dad5..42f7a4a0e 100644 --- a/resources/scripts/components/server/settings/ReinstallServerBox.tsx +++ b/resources/scripts/components/server/settings/ReinstallServerBox.tsx @@ -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) => actions.flashes); @@ -36,6 +37,17 @@ export default () => { clearFlashes(); }, []); + if (skipScripts) { + return ( + +

+ Reinstalling this server has been disabled because it is configured to skip its egg's install + script. If you would like to reinstall this server, contact a server administrator. +

+
+ ); + } + return ( This will reinstall the server with the assigned service scripts. Danger! This could overwrite server data.