2020-04-05 02:54:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
use Pterodactyl\Models\Backup;
|
|
|
|
use Pterodactyl\Models\Server;
|
2020-04-07 03:28:14 +00:00
|
|
|
use Pterodactyl\Services\Nodes\NodeJWTService;
|
2020-04-05 02:54:59 +00:00
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
|
|
|
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\DownloadBackupRequest;
|
|
|
|
|
|
|
|
class DownloadBackupController extends ClientApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
|
|
|
|
*/
|
|
|
|
private $daemonBackupRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Routing\ResponseFactory
|
|
|
|
*/
|
|
|
|
private $responseFactory;
|
|
|
|
|
2020-04-07 03:28:14 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Nodes\NodeJWTService
|
|
|
|
*/
|
|
|
|
private $jwtService;
|
|
|
|
|
2020-04-05 02:54:59 +00:00
|
|
|
/**
|
|
|
|
* DownloadBackupController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $daemonBackupRepository
|
2020-04-07 03:28:14 +00:00
|
|
|
* @param \Pterodactyl\Services\Nodes\NodeJWTService $jwtService
|
2020-04-05 02:54:59 +00:00
|
|
|
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
DaemonBackupRepository $daemonBackupRepository,
|
2020-04-07 03:28:14 +00:00
|
|
|
NodeJWTService $jwtService,
|
2020-04-05 02:54:59 +00:00
|
|
|
ResponseFactory $responseFactory
|
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->daemonBackupRepository = $daemonBackupRepository;
|
|
|
|
$this->responseFactory = $responseFactory;
|
2020-04-07 03:28:14 +00:00
|
|
|
$this->jwtService = $jwtService;
|
2020-04-05 02:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download the backup for a given server instance. For daemon local files, the file
|
|
|
|
* will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated
|
|
|
|
* which the user is redirected to.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Backups\DownloadBackupRequest $request
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @param \Pterodactyl\Models\Backup $backup
|
2020-04-07 03:28:14 +00:00
|
|
|
* @return array
|
2020-04-05 02:54:59 +00:00
|
|
|
*/
|
|
|
|
public function __invoke(DownloadBackupRequest $request, Server $server, Backup $backup)
|
|
|
|
{
|
2020-04-07 03:28:14 +00:00
|
|
|
$token = $this->jwtService
|
|
|
|
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
|
|
|
->setClaims([
|
|
|
|
'backup_uuid' => $backup->uuid,
|
|
|
|
'server_uuid' => $server->uuid,
|
|
|
|
])
|
|
|
|
->handle($server->node, $request->user()->id . $server->uuid);
|
2020-04-05 02:54:59 +00:00
|
|
|
|
2020-04-07 03:28:14 +00:00
|
|
|
return [
|
|
|
|
'object' => 'signed_url',
|
|
|
|
'attributes' => [
|
|
|
|
'url' => sprintf(
|
|
|
|
'%s/download/backup?token=%s',
|
|
|
|
$server->node->getConnectionAddress(),
|
|
|
|
$token->__toString()
|
|
|
|
),
|
|
|
|
],
|
|
|
|
];
|
2020-04-05 02:54:59 +00:00
|
|
|
}
|
|
|
|
}
|