Skip to content

Commit 63eefaa

Browse files
committed
Merge branch 'develop' of https://github.com/Pterodactyl/Panel into develop
2 parents 1fcffc7 + fcff908 commit 63eefaa

File tree

7 files changed

+70
-16
lines changed

7 files changed

+70
-16
lines changed

app/Extensions/Backups/BackupManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Webmozart\Assert\Assert;
1010
use InvalidArgumentException;
1111
use League\Flysystem\AdapterInterface;
12+
use Illuminate\Foundation\Application;
1213
use League\Flysystem\AwsS3v3\AwsS3Adapter;
1314
use League\Flysystem\Memory\MemoryAdapter;
1415
use Illuminate\Contracts\Config\Repository;
@@ -44,7 +45,7 @@ class BackupManager
4445
*
4546
* @param \Illuminate\Foundation\Application $app
4647
*/
47-
public function __construct($app)
48+
public function __construct(Application $app)
4849
{
4950
$this->app = $app;
5051
$this->config = $app->make(Repository::class);

app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ public function __invoke(Request $request, string $backup)
6969
// Ensure we are using the S3 adapter.
7070
$adapter = $this->backupManager->adapter();
7171
if (! $adapter instanceof AwsS3Adapter) {
72-
throw new BadRequestHttpException('The configured backup adapter is not an S3 compatiable adapter.');
72+
throw new BadRequestHttpException('The configured backup adapter is not an S3 compatible adapter.');
7373
}
7474

7575
// The path where backup will be uploaded to
7676
$path = sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid);
7777

7878
// Get the S3 client
7979
$client = $adapter->getClient();
80-
$expires = CarbonImmutable::now()->addMinutes(30);
80+
$expires = CarbonImmutable::now()->addMinutes(config('backups.presigned_url_lifespan', 60));
8181

8282
// Params for generating the presigned urls
8383
$params = [
@@ -102,14 +102,9 @@ public function __invoke(Request $request, string $backup)
102102
}
103103

104104
return new JsonResponse([
105+
'upload_id' => $params['UploadId'],
105106
'parts' => $parts,
106107
'part_size' => self::PART_SIZE,
107-
'complete_multipart_upload' => $client->createPresignedRequest(
108-
$client->getCommand('CompleteMultipartUpload', $params), $expires
109-
)->getUri()->__toString(),
110-
'abort_multipart_upload' => $client->createPresignedRequest(
111-
$client->getCommand('AbortMultipartUpload', $params), $expires->addMinutes(15)
112-
)->getUri()->__toString(),
113108
]);
114109
}
115110
}

app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
44

55
use Carbon\CarbonImmutable;
6+
use Pterodactyl\Models\Backup;
67
use Illuminate\Http\JsonResponse;
8+
use League\Flysystem\AwsS3v3\AwsS3Adapter;
79
use Pterodactyl\Http\Controllers\Controller;
10+
use Pterodactyl\Extensions\Backups\BackupManager;
811
use Pterodactyl\Repositories\Eloquent\BackupRepository;
912
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1013
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
@@ -16,24 +19,33 @@ class BackupStatusController extends Controller
1619
*/
1720
private $repository;
1821

22+
/**
23+
* @var \Pterodactyl\Extensions\Backups\BackupManager
24+
*/
25+
private $backupManager;
26+
1927
/**
2028
* BackupStatusController constructor.
2129
*
2230
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
31+
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
2332
*/
24-
public function __construct(BackupRepository $repository)
33+
public function __construct(BackupRepository $repository, BackupManager $backupManager)
2534
{
2635
$this->repository = $repository;
36+
$this->backupManager = $backupManager;
2737
}
2838

2939
/**
3040
* Handles updating the state of a backup.
3141
*
3242
* @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request
3343
* @param string $backup
44+
*
3445
* @return \Illuminate\Http\JsonResponse
3546
*
3647
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
48+
* @throws \Exception
3749
*/
3850
public function __invoke(ReportBackupCompleteRequest $request, string $backup)
3951
{
@@ -47,13 +59,40 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
4759
}
4860

4961
$successful = $request->input('successful') ? true : false;
62+
5063
$model->forceFill([
5164
'is_successful' => $successful,
5265
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
5366
'bytes' => $successful ? $request->input('size') : 0,
5467
'completed_at' => CarbonImmutable::now(),
5568
])->save();
5669

70+
// Check if we are using the s3 backup adapter.
71+
$adapter = $this->backupManager->adapter();
72+
if ($adapter instanceof AwsS3Adapter) {
73+
/** @var \Pterodactyl\Models\Backup $backup */
74+
$backup = Backup::query()->where('uuid', $backup)->firstOrFail();
75+
76+
$client = $adapter->getClient();
77+
78+
$params = [
79+
'Bucket' => $adapter->getBucket(),
80+
'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid),
81+
'UploadId' => $request->input('upload_id'),
82+
];
83+
84+
// If the backup was not successful, send an AbortMultipartUpload request.
85+
if (! $successful) {
86+
$client->execute($client->getCommand('AbortMultipartUpload', $params));
87+
} else {
88+
// Otherwise send a CompleteMultipartUpload request.
89+
$params['MultipartUpload'] = [
90+
'Parts' => $client->execute($client->getCommand('ListParts', $params))['Parts'],
91+
];
92+
$client->execute($client->getCommand('CompleteMultipartUpload', $params));
93+
}
94+
}
95+
5796
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
5897
}
5998
}

app/Http/Requests/Api/Client/Servers/Network/NewAllocationRequest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Network;
44

5-
use Illuminate\Support\Collection;
6-
use Pterodactyl\Models\Allocation;
75
use Pterodactyl\Models\Permission;
86
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
97

@@ -16,5 +14,4 @@ public function permission(): string
1614
{
1715
return Permission::ACTION_ALLOCATION_CREATE;
1816
}
19-
2017
}

app/Services/Backups/InitiateBackupService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function setIgnoredFiles(?array $ignored)
9999
*
100100
* @param \Pterodactyl\Models\Server $server
101101
* @param string|null $name
102+
* @param bool $override
103+
*
102104
* @return \Pterodactyl\Models\Backup
103105
*
104106
* @throws \Throwable

config/backups.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// have been made, without losing data.
99
'default' => env('APP_BACKUP_DRIVER', Backup::ADAPTER_WINGS),
1010

11+
// This value is used to determine the lifespan of UploadPart presigned urls that wings
12+
// uses to upload backups to S3 storage. Value is in minutes, so this would default to an hour.
13+
'presigned_url_lifespan' => env('BACKUP_PRESIGNED_URL_LIFESPAN', 60),
14+
1115
'disks' => [
1216
// There is no configuration for the local disk for Wings. That configuration
1317
// is determined by the Daemon configuration, and not the Panel.

resources/scripts/components/server/ServerDetailsBlock.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import tw from 'twin.macro';
2+
import tw, { TwStyle } from 'twin.macro';
33
import { faCircle, faEthernet, faHdd, faMemory, faMicrochip, faServer } from '@fortawesome/free-solid-svg-icons';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import { bytesToHuman, megabytesToHuman } from '@/helpers';
@@ -13,6 +13,21 @@ interface Stats {
1313
disk: number;
1414
}
1515

16+
function statusToColor (status: string|null, installing: boolean): TwStyle {
17+
if (installing) {
18+
status = '';
19+
}
20+
21+
switch (status) {
22+
case 'offline':
23+
return tw`text-red-500`;
24+
case 'running':
25+
return tw`text-green-500`;
26+
default:
27+
return tw`text-yellow-500`;
28+
}
29+
}
30+
1631
const ServerDetailsBlock = () => {
1732
const [ stats, setStats ] = useState<Stats>({ memory: 0, cpu: 0, disk: 0 });
1833

@@ -49,6 +64,7 @@ const ServerDetailsBlock = () => {
4964
}, [ instance, connected ]);
5065

5166
const name = ServerContext.useStoreState(state => state.server.data!.name);
67+
const isInstalling = ServerContext.useStoreState(state => state.server.data!.isInstalling);
5268
const limits = ServerContext.useStoreState(state => state.server.data!.limits);
5369
const primaryAllocation = ServerContext.useStoreState(state => state.server.data!.allocations.filter(alloc => alloc.isDefault).map(
5470
allocation => (allocation.alias || allocation.ip) + ':' + allocation.port
@@ -65,10 +81,10 @@ const ServerDetailsBlock = () => {
6581
fixedWidth
6682
css={[
6783
tw`mr-1`,
68-
status === 'offline' ? tw`text-red-500` : (status === 'running' ? tw`text-green-500` : tw`text-yellow-500`),
84+
statusToColor(status, isInstalling),
6985
]}
7086
/>
71-
&nbsp;{!status ? 'Connecting...' : status}
87+
&nbsp;{!status ? 'Connecting...' : (isInstalling ? 'Installing' : status)}
7288
</p>
7389
<CopyOnClick text={primaryAllocation}>
7490
<p css={tw`text-xs mt-2`}>

0 commit comments

Comments
 (0)