Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\ServerTransfer;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Http\Controllers\Controller;
Expand All @@ -14,6 +16,7 @@
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
use Webmozart\Assert\Assert;

class ServerTransferController extends Controller
{
Expand All @@ -32,17 +35,20 @@ public function __construct(
*
* @throws \Throwable
*/
public function failure(string $uuid): JsonResponse
public function failure(Request $reqest, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$transfer = $server->transfer;
if (is_null($transfer)) {
throw new ConflictHttpException('Server is not being transferred.');
}

/** @var Node $node */
Assert::isInstanceOf($node = $request->attributes->get('node'), Node::class);

// Either node can tell the panel that the transfer has failed. Only the new node
// can tell the panel that it was successful.
if (! $server->node->is($transfer->newNode) && ! $server->node->is($transfer->oldNode)) {
if (! $node->is($transfer->newNode) && ! $node->is($transfer->oldNode)) {
throw new HttpForbiddenException('Requesting node does not have permission to access this server.');
}

Expand All @@ -54,17 +60,20 @@ public function failure(string $uuid): JsonResponse
*
* @throws \Throwable
*/
public function success(string $uuid): JsonResponse
public function success(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$transfer = $server->transfer;
if (is_null($transfer)) {
throw new ConflictHttpException('Server is not being transferred.');
}

/** @var Node $node */
Assert::isInstanceOf($node = $request->attributes->get('node'), Node::class);

// Only the new node communicates a successful state to the panel, so we should
// not allow the old node to hit this endpoint.
if (! $server->node->is($transfer->newNode)) {
if (! $node->is($transfer->newNode)) {
throw new HttpForbiddenException('Requesting node does not have permission to access this server.');
}

Expand Down