diff --git a/app/Exceptions/Http/Server/ServerTransferringException.php b/app/Exceptions/Http/Server/ServerTransferringException.php new file mode 100644 index 000000000..91c3f39bd --- /dev/null +++ b/app/Exceptions/Http/Server/ServerTransferringException.php @@ -0,0 +1,14 @@ +permissionsService->handle($server, $user); $node = null; - if ($server->transfer !== null) { + if (! is_null($server->transfer)) { // Check if the user has permissions to receive transfer logs. if (! in_array('admin.websocket.transfer', $permissions)) { throw new HttpException(Response::HTTP_FORBIDDEN, 'You do not have permission to view transfer logs'); diff --git a/app/Http/Controllers/Api/Remote/SftpAuthenticationController.php b/app/Http/Controllers/Api/Remote/SftpAuthenticationController.php index 7fb5625f4..31862a567 100644 --- a/app/Http/Controllers/Api/Remote/SftpAuthenticationController.php +++ b/app/Http/Controllers/Api/Remote/SftpAuthenticationController.php @@ -12,6 +12,7 @@ use Pterodactyl\Exceptions\Http\HttpForbiddenException; use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Services\Servers\GetUserPermissionsService; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Pterodactyl\Exceptions\Http\Server\ServerTransferringException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; @@ -110,9 +111,14 @@ class SftpAuthenticationController extends Controller } } - // Remeber, for security purposes, only reveal the existence of the server to people that + // Prevent SFTP access to servers that are being transferred. + if (! is_null($server->transfer)) { + throw new ServerTransferringException(); + } + + // Remember, for security purposes, only reveal the existence of the server to people that // have provided valid credentials, and have permissions to know about it. - if ($server->installed !== 1 || $server->suspended || $server->transfer !== null) { + if ($server->installed !== 1 || $server->suspended) { throw new BadRequestHttpException( 'Server is not installed or is currently suspended.' ); @@ -132,7 +138,7 @@ class SftpAuthenticationController extends Controller * @param \Illuminate\Http\Request $request * @return string */ - protected function throttleKey(Request $request) + protected function throttleKey(Request $request): string { $username = explode('.', strrev($request->input('username', ''))); diff --git a/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php b/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php index eee798198..2a08a1cb4 100644 --- a/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php +++ b/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php @@ -79,7 +79,7 @@ class AuthenticateServerAccess } } - if ($server->transfer !== null) { + if (! is_null($server->transfer)) { if (! $user->root_admin || ($user->root_admin && ! $request->routeIs($this->except))) { throw new ConflictHttpException('Server is currently being transferred.'); } diff --git a/app/Http/Middleware/Server/AccessingValidServer.php b/app/Http/Middleware/Server/AccessingValidServer.php index 1bed5f556..9c73112dc 100644 --- a/app/Http/Middleware/Server/AccessingValidServer.php +++ b/app/Http/Middleware/Server/AccessingValidServer.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Contracts\Config\Repository as ConfigRepository; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; use Symfony\Component\HttpKernel\Exception\ConflictHttpException; +use Pterodactyl\Exceptions\Http\Server\ServerTransferringException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class AccessingValidServer @@ -80,9 +81,9 @@ class AccessingValidServer return $this->response->view('errors.installing', [], 409); } - if ($server->transfer !== null) { + if (! is_null($server->transfer)) { if ($isApiRequest) { - throw new ConflictHttpException('Server is currently being transferred.'); + throw new ServerTransferringException(); } return $this->response->view('errors.transferring', [], 409); diff --git a/app/Services/Servers/SuspensionService.php b/app/Services/Servers/SuspensionService.php index e1a0a805a..83de0ad08 100644 --- a/app/Services/Servers/SuspensionService.php +++ b/app/Services/Servers/SuspensionService.php @@ -7,6 +7,7 @@ use Pterodactyl\Models\Server; use Illuminate\Database\ConnectionInterface; use Pterodactyl\Repositories\Wings\DaemonServerRepository; use Symfony\Component\HttpKernel\Exception\ConflictHttpException; +use Pterodactyl\Exceptions\Http\Server\ServerTransferringException; class SuspensionService { @@ -58,8 +59,8 @@ class SuspensionService } // Check if the server is currently being transferred. - if ($server->transfer !== null) { - throw new ConflictHttpException('Server is currently being transferred'); + if (! is_null($server->transfer)) { + throw new ServerTransferringException(); } $this->connection->transaction(function () use ($action, $server) { @@ -68,7 +69,7 @@ class SuspensionService ]); // Only send the suspension request to wings if the server is not currently being transferred. - if ($server->transfer === null) { + if (is_null($server->transfer)) { $this->daemonServerRepository->setServer($server)->suspend($action === self::ACTION_UNSUSPEND); } }); diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index 766b3b726..0673f9b57 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -72,7 +72,7 @@ class ServerTransformer extends BaseClientTransformer ], 'is_suspended' => $server->suspended, 'is_installing' => $server->installed !== 1, - 'is_transferring' => $server->transfer !== null, + 'is_transferring' => ! is_null($server->transfer), ]; } diff --git a/resources/scripts/routers/ServerRouter.tsx b/resources/scripts/routers/ServerRouter.tsx index d01f76fcd..533491db6 100644 --- a/resources/scripts/routers/ServerRouter.tsx +++ b/resources/scripts/routers/ServerRouter.tsx @@ -66,7 +66,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) getServer(match.params.id) .catch(error => { if (error.response?.status === 409) { - if (error.response.data?.errors[0]?.detail?.includes('transfer')) { + if (error.response.data?.errors[0]?.code === 'ServerTransferringException') { setTransferring(true); } else { setInstalling(true); diff --git a/resources/views/admin/servers/view/manage.blade.php b/resources/views/admin/servers/view/manage.blade.php index af4e93e1b..9962cfddf 100644 --- a/resources/views/admin/servers/view/manage.blade.php +++ b/resources/views/admin/servers/view/manage.blade.php @@ -72,7 +72,7 @@
@@ -97,7 +97,7 @@ @endif - @if($server->transfer === null) + @if(is_null($server->transfer))