mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-25 10:32:31 +01:00
Add ServerTransferringException, use is_null
This commit is contained in:
parent
5668a780e2
commit
fd848985ee
14
app/Exceptions/Http/Server/ServerTransferringException.php
Normal file
14
app/Exceptions/Http/Server/ServerTransferringException.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Http\Server;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class ServerTransferringException extends HttpException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Response::HTTP_CONFLICT, 'Server is currently being transferred.');
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ class WebsocketController extends ClientApiController
|
||||
$permissions = $this->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');
|
||||
|
@ -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', '')));
|
||||
|
||||
|
@ -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.');
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -72,7 +72,7 @@
|
||||
<form action="{{ route('admin.servers.view.manage.suspension', $server->id) }}" method="POST">
|
||||
{!! csrf_field() !!}
|
||||
<input type="hidden" name="action" value="suspend" />
|
||||
<button type="submit" class="btn btn-warning @if($server->transfer !== null) disabled @endif">Suspend Server</button>
|
||||
<button type="submit" class="btn btn-warning @if(! is_null($server->transfer)) disabled @endif">Suspend Server</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@ -97,7 +97,7 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($server->transfer === null)
|
||||
@if(is_null($server->transfer))
|
||||
<div class="col-sm-4">
|
||||
<div class="box box-success">
|
||||
<div class="box-header with-border">
|
||||
|
Loading…
Reference in New Issue
Block a user