mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-23 09:32:29 +01:00
Simplify logic in websocket control
This commit is contained in:
parent
bb559422dc
commit
6c61577699
@ -3,12 +3,11 @@
|
|||||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||||
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Http\Response;
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Pterodactyl\Models\Permission;
|
use Pterodactyl\Models\Permission;
|
||||||
use Pterodactyl\Services\Nodes\NodeJWTService;
|
use Pterodactyl\Services\Nodes\NodeJWTService;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||||
use Pterodactyl\Services\Servers\GetUserPermissionsService;
|
use Pterodactyl\Services\Servers\GetUserPermissionsService;
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
@ -55,26 +54,22 @@ class WebsocketController extends ClientApiController
|
|||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {
|
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {
|
||||||
throw new HttpException(Response::HTTP_FORBIDDEN, 'You do not have permission to connect to this server\'s websocket.');
|
throw new HttpForbiddenException('You do not have permission to connect to this server\'s websocket.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$permissions = $this->permissionsService->handle($server, $user);
|
$permissions = $this->permissionsService->handle($server, $user);
|
||||||
|
|
||||||
$node = null;
|
$node = $server->node;
|
||||||
if (! is_null($server->transfer)) {
|
if (! is_null($server->transfer)) {
|
||||||
// Check if the user has permissions to receive transfer logs.
|
// Check if the user has permissions to receive transfer logs.
|
||||||
if (! in_array('admin.websocket.transfer', $permissions)) {
|
if (! in_array('admin.websocket.transfer', $permissions)) {
|
||||||
throw new HttpException(Response::HTTP_FORBIDDEN, 'You do not have permission to view transfer logs');
|
throw new HttpForbiddenException('You do not have permission to view server transfer logs.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect the websocket request to the new node if the server has been archived.
|
// Redirect the websocket request to the new node if the server has been archived.
|
||||||
if ($server->transfer->archived) {
|
if ($server->transfer->archived) {
|
||||||
$node = $server->transfer->newNode;
|
$node = $server->transfer->newNode;
|
||||||
} else {
|
|
||||||
$node = $server->node;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$node = $server->node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $this->jwtService
|
$token = $this->jwtService
|
||||||
|
Loading…
Reference in New Issue
Block a user