Merge branch 'develop' of https://github.com/Pterodactyl/Panel into develop
This commit is contained in:
commit
63eefaa695
7 changed files with 70 additions and 16 deletions
|
@ -9,6 +9,7 @@ use Illuminate\Support\Str;
|
|||
use Webmozart\Assert\Assert;
|
||||
use InvalidArgumentException;
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use Illuminate\Foundation\Application;
|
||||
use League\Flysystem\AwsS3v3\AwsS3Adapter;
|
||||
use League\Flysystem\Memory\MemoryAdapter;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
@ -44,7 +45,7 @@ class BackupManager
|
|||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*/
|
||||
public function __construct($app)
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = $app->make(Repository::class);
|
||||
|
|
|
@ -69,7 +69,7 @@ class BackupRemoteUploadController extends Controller
|
|||
// Ensure we are using the S3 adapter.
|
||||
$adapter = $this->backupManager->adapter();
|
||||
if (! $adapter instanceof AwsS3Adapter) {
|
||||
throw new BadRequestHttpException('The configured backup adapter is not an S3 compatiable adapter.');
|
||||
throw new BadRequestHttpException('The configured backup adapter is not an S3 compatible adapter.');
|
||||
}
|
||||
|
||||
// The path where backup will be uploaded to
|
||||
|
@ -77,7 +77,7 @@ class BackupRemoteUploadController extends Controller
|
|||
|
||||
// Get the S3 client
|
||||
$client = $adapter->getClient();
|
||||
$expires = CarbonImmutable::now()->addMinutes(30);
|
||||
$expires = CarbonImmutable::now()->addMinutes(config('backups.presigned_url_lifespan', 60));
|
||||
|
||||
// Params for generating the presigned urls
|
||||
$params = [
|
||||
|
@ -102,14 +102,9 @@ class BackupRemoteUploadController extends Controller
|
|||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'upload_id' => $params['UploadId'],
|
||||
'parts' => $parts,
|
||||
'part_size' => self::PART_SIZE,
|
||||
'complete_multipart_upload' => $client->createPresignedRequest(
|
||||
$client->getCommand('CompleteMultipartUpload', $params), $expires
|
||||
)->getUri()->__toString(),
|
||||
'abort_multipart_upload' => $client->createPresignedRequest(
|
||||
$client->getCommand('AbortMultipartUpload', $params), $expires->addMinutes(15)
|
||||
)->getUri()->__toString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use League\Flysystem\AwsS3v3\AwsS3Adapter;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Extensions\Backups\BackupManager;
|
||||
use Pterodactyl\Repositories\Eloquent\BackupRepository;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
|
||||
|
@ -16,14 +19,21 @@ class BackupStatusController extends Controller
|
|||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Extensions\Backups\BackupManager
|
||||
*/
|
||||
private $backupManager;
|
||||
|
||||
/**
|
||||
* BackupStatusController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
|
||||
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
|
||||
*/
|
||||
public function __construct(BackupRepository $repository)
|
||||
public function __construct(BackupRepository $repository, BackupManager $backupManager)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->backupManager = $backupManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,9 +41,11 @@ class BackupStatusController extends Controller
|
|||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request
|
||||
* @param string $backup
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(ReportBackupCompleteRequest $request, string $backup)
|
||||
{
|
||||
|
@ -47,6 +59,7 @@ class BackupStatusController extends Controller
|
|||
}
|
||||
|
||||
$successful = $request->input('successful') ? true : false;
|
||||
|
||||
$model->forceFill([
|
||||
'is_successful' => $successful,
|
||||
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
|
||||
|
@ -54,6 +67,32 @@ class BackupStatusController extends Controller
|
|||
'completed_at' => CarbonImmutable::now(),
|
||||
])->save();
|
||||
|
||||
// Check if we are using the s3 backup adapter.
|
||||
$adapter = $this->backupManager->adapter();
|
||||
if ($adapter instanceof AwsS3Adapter) {
|
||||
/** @var \Pterodactyl\Models\Backup $backup */
|
||||
$backup = Backup::query()->where('uuid', $backup)->firstOrFail();
|
||||
|
||||
$client = $adapter->getClient();
|
||||
|
||||
$params = [
|
||||
'Bucket' => $adapter->getBucket(),
|
||||
'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid),
|
||||
'UploadId' => $request->input('upload_id'),
|
||||
];
|
||||
|
||||
// If the backup was not successful, send an AbortMultipartUpload request.
|
||||
if (! $successful) {
|
||||
$client->execute($client->getCommand('AbortMultipartUpload', $params));
|
||||
} else {
|
||||
// Otherwise send a CompleteMultipartUpload request.
|
||||
$params['MultipartUpload'] = [
|
||||
'Parts' => $client->execute($client->getCommand('ListParts', $params))['Parts'],
|
||||
];
|
||||
$client->execute($client->getCommand('CompleteMultipartUpload', $params));
|
||||
}
|
||||
}
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Network;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
|
||||
|
@ -16,5 +14,4 @@ class NewAllocationRequest extends ClientApiRequest
|
|||
{
|
||||
return Permission::ACTION_ALLOCATION_CREATE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -99,6 +99,8 @@ class InitiateBackupService
|
|||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param string|null $name
|
||||
* @param bool $override
|
||||
*
|
||||
* @return \Pterodactyl\Models\Backup
|
||||
*
|
||||
* @throws \Throwable
|
||||
|
|
|
@ -8,6 +8,10 @@ return [
|
|||
// have been made, without losing data.
|
||||
'default' => env('APP_BACKUP_DRIVER', Backup::ADAPTER_WINGS),
|
||||
|
||||
// This value is used to determine the lifespan of UploadPart presigned urls that wings
|
||||
// uses to upload backups to S3 storage. Value is in minutes, so this would default to an hour.
|
||||
'presigned_url_lifespan' => env('BACKUP_PRESIGNED_URL_LIFESPAN', 60),
|
||||
|
||||
'disks' => [
|
||||
// There is no configuration for the local disk for Wings. That configuration
|
||||
// is determined by the Daemon configuration, and not the Panel.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import tw from 'twin.macro';
|
||||
import tw, { TwStyle } from 'twin.macro';
|
||||
import { faCircle, faEthernet, faHdd, faMemory, faMicrochip, faServer } from '@fortawesome/free-solid-svg-icons';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { bytesToHuman, megabytesToHuman } from '@/helpers';
|
||||
|
@ -13,6 +13,21 @@ interface Stats {
|
|||
disk: number;
|
||||
}
|
||||
|
||||
function statusToColor (status: string|null, installing: boolean): TwStyle {
|
||||
if (installing) {
|
||||
status = '';
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 'offline':
|
||||
return tw`text-red-500`;
|
||||
case 'running':
|
||||
return tw`text-green-500`;
|
||||
default:
|
||||
return tw`text-yellow-500`;
|
||||
}
|
||||
}
|
||||
|
||||
const ServerDetailsBlock = () => {
|
||||
const [ stats, setStats ] = useState<Stats>({ memory: 0, cpu: 0, disk: 0 });
|
||||
|
||||
|
@ -49,6 +64,7 @@ const ServerDetailsBlock = () => {
|
|||
}, [ instance, connected ]);
|
||||
|
||||
const name = ServerContext.useStoreState(state => state.server.data!.name);
|
||||
const isInstalling = ServerContext.useStoreState(state => state.server.data!.isInstalling);
|
||||
const limits = ServerContext.useStoreState(state => state.server.data!.limits);
|
||||
const primaryAllocation = ServerContext.useStoreState(state => state.server.data!.allocations.filter(alloc => alloc.isDefault).map(
|
||||
allocation => (allocation.alias || allocation.ip) + ':' + allocation.port
|
||||
|
@ -65,10 +81,10 @@ const ServerDetailsBlock = () => {
|
|||
fixedWidth
|
||||
css={[
|
||||
tw`mr-1`,
|
||||
status === 'offline' ? tw`text-red-500` : (status === 'running' ? tw`text-green-500` : tw`text-yellow-500`),
|
||||
statusToColor(status, isInstalling),
|
||||
]}
|
||||
/>
|
||||
{!status ? 'Connecting...' : status}
|
||||
{!status ? 'Connecting...' : (isInstalling ? 'Installing' : status)}
|
||||
</p>
|
||||
<CopyOnClick text={primaryAllocation}>
|
||||
<p css={tw`text-xs mt-2`}>
|
||||
|
|
Loading…
Reference in a new issue