Merge branch 'develop' into feature/react-admin
This commit is contained in:
commit
a87fef37ec
77 changed files with 1082 additions and 839 deletions
75
app/Services/Backups/DownloadLinkService.php
Normal file
75
app/Services/Backups/DownloadLinkService.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Backups;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Services\Nodes\NodeJWTService;
|
||||
use Pterodactyl\Extensions\Backups\BackupManager;
|
||||
|
||||
class DownloadLinkService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Extensions\Backups\BackupManager
|
||||
*/
|
||||
private $backupManager;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nodes\NodeJWTService
|
||||
*/
|
||||
private $jwtService;
|
||||
|
||||
/**
|
||||
* DownloadLinkService constructor.
|
||||
*/
|
||||
public function __construct(BackupManager $backupManager, NodeJWTService $jwtService)
|
||||
{
|
||||
$this->backupManager = $backupManager;
|
||||
$this->jwtService = $jwtService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL that allows for a backup to be downloaded by an individual
|
||||
* user, or by the Wings control software.
|
||||
*/
|
||||
public function handle(Backup $backup, User $user): string
|
||||
{
|
||||
if ($backup->disk === Backup::ADAPTER_AWS_S3) {
|
||||
return $this->getS3BackupUrl($backup);
|
||||
}
|
||||
|
||||
$token = $this->jwtService
|
||||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
||||
->setClaims([
|
||||
'backup_uuid' => $backup->uuid,
|
||||
'server_uuid' => $backup->server->uuid,
|
||||
])
|
||||
->handle($backup->server->node, $user->id . $backup->server->uuid);
|
||||
|
||||
return sprintf('%s/download/backup?token=%s', $backup->server->node->getConnectionAddress(), $token->__toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a signed URL that allows us to download a file directly out of a non-public
|
||||
* S3 bucket by using a signed URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getS3BackupUrl(Backup $backup)
|
||||
{
|
||||
/** @var \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter */
|
||||
$adapter = $this->backupManager->adapter(Backup::ADAPTER_AWS_S3);
|
||||
|
||||
$request = $adapter->getClient()->createPresignedRequest(
|
||||
$adapter->getClient()->getCommand('GetObject', [
|
||||
'Bucket' => $adapter->getBucket(),
|
||||
'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid),
|
||||
'ContentType' => 'application/x-gzip',
|
||||
]),
|
||||
CarbonImmutable::now()->addMinutes(5)
|
||||
);
|
||||
|
||||
return $request->getUri()->__toString();
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ class ReinstallServerService
|
|||
public function handle(Server $server)
|
||||
{
|
||||
return $this->connection->transaction(function () use ($server) {
|
||||
$server->forceFill(['installed' => Server::STATUS_INSTALLING])->save();
|
||||
$server->fill(['status' => Server::STATUS_INSTALLING])->save();
|
||||
|
||||
$this->daemonServerRepository->setServer($server)->reinstall();
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class ServerConfigurationStructureService
|
|||
{
|
||||
return [
|
||||
'uuid' => $server->uuid,
|
||||
'suspended' => $server->suspended,
|
||||
'suspended' => $server->isSuspended(),
|
||||
'environment' => $this->environment->handle($server),
|
||||
'invocation' => $server->startup,
|
||||
'skip_egg_scripts' => $server->skip_scripts,
|
||||
|
@ -118,7 +118,7 @@ class ServerConfigurationStructureService
|
|||
'skip_scripts' => $server->skip_scripts,
|
||||
],
|
||||
'rebuild' => false,
|
||||
'suspended' => (int) $server->suspended,
|
||||
'suspended' => $server->isSuspended() ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,8 +211,8 @@ class ServerCreationService
|
|||
'node_id' => Arr::get($data, 'node_id'),
|
||||
'name' => Arr::get($data, 'name'),
|
||||
'description' => Arr::get($data, 'description') ?? '',
|
||||
'status' => Server::STATUS_INSTALLING,
|
||||
'skip_scripts' => Arr::get($data, 'skip_scripts') ?? isset($data['skip_scripts']),
|
||||
'suspended' => false,
|
||||
'owner_id' => Arr::get($data, 'owner_id'),
|
||||
'memory' => Arr::get($data, 'memory'),
|
||||
'swap' => Arr::get($data, 'swap'),
|
||||
|
|
|
@ -6,7 +6,7 @@ use Webmozart\Assert\Assert;
|
|||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Exceptions\Http\Server\ServerTransferringException;
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
|
||||
class SuspensionService
|
||||
{
|
||||
|
@ -49,18 +49,18 @@ class SuspensionService
|
|||
// Nothing needs to happen if we're suspending the server and it is already
|
||||
// suspended in the database. Additionally, nothing needs to happen if the server
|
||||
// is not suspended and we try to un-suspend the instance.
|
||||
if ($isSuspending === $server->suspended) {
|
||||
if ($isSuspending === $server->isSuspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the server is currently being transferred.
|
||||
if (!is_null($server->transfer)) {
|
||||
throw new ServerTransferringException();
|
||||
throw new ConflictHttpException('Cannot toggle suspension status on a server that is currently being transferred.');
|
||||
}
|
||||
|
||||
$this->connection->transaction(function () use ($action, $server) {
|
||||
$this->connection->transaction(function () use ($action, $server, $isSuspending) {
|
||||
$server->update([
|
||||
'suspended' => $action === self::ACTION_SUSPEND,
|
||||
'status' => $isSuspending ? Server::STATUS_SUSPENDED : null,
|
||||
]);
|
||||
|
||||
// Only send the suspension request to wings if the server is not currently being transferred.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue