Merge branch 'develop' into dane/restore-backups

This commit is contained in:
Dane Everitt 2021-01-25 19:16:40 -08:00
commit 663143de0b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
575 changed files with 6080 additions and 6864 deletions

View file

@ -15,7 +15,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class BackupRemoteUploadController extends Controller
{
const PART_SIZE = 5 * 1024 * 1024 * 1024;
public const PART_SIZE = 5 * 1024 * 1024 * 1024;
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
@ -29,9 +29,6 @@ class BackupRemoteUploadController extends Controller
/**
* BackupRemoteUploadController constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
*/
public function __construct(BackupRepository $repository, BackupManager $backupManager)
{
@ -42,9 +39,6 @@ class BackupRemoteUploadController extends Controller
/**
* Returns the required presigned urls to upload a backup to S3 cloud storage.
*
* @param \Illuminate\Http\Request $request
* @param string $backup
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception
@ -64,13 +58,13 @@ class BackupRemoteUploadController extends Controller
// Prevent backups that have already been completed from trying to
// be uploaded again.
if (! is_null($backup->completed_at)) {
if (!is_null($backup->completed_at)) {
throw new ConflictHttpException('This backup is already in a completed state.');
}
// Ensure we are using the S3 adapter.
$adapter = $this->backupManager->adapter();
if (! $adapter instanceof AwsS3Adapter) {
if (!$adapter instanceof AwsS3Adapter) {
throw new BadRequestHttpException('The configured backup adapter is not an S3 compatible adapter.');
}
@ -97,9 +91,10 @@ class BackupRemoteUploadController extends Controller
// Create as many UploadPart presigned urls as needed
$parts = [];
for ($i = 0; $i < ($size / self::PART_SIZE); $i++) {
for ($i = 0; $i < ($size / self::PART_SIZE); ++$i) {
$parts[] = $client->createPresignedRequest(
$client->getCommand('UploadPart', array_merge($params, ['PartNumber' => $i + 1])), $expires
$client->getCommand('UploadPart', array_merge($params, ['PartNumber' => $i + 1])),
$expires
)->getUri()->__toString();
}

View file

@ -9,8 +9,8 @@ use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Repositories\Eloquent\BackupRepository;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@ -30,9 +30,6 @@ class BackupStatusController extends Controller
/**
* BackupStatusController constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
*/
public function __construct(BackupRepository $repository, BackupManager $backupManager)
{
@ -43,8 +40,6 @@ class BackupStatusController extends Controller
/**
* Handles updating the state of a backup.
*
* @param \Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest $request
* @param string $backup
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -54,10 +49,8 @@ class BackupStatusController extends Controller
/** @var \Pterodactyl\Models\Backup $model */
$model = Backup::query()->where('uuid', $backup)->firstOrFail();
if (! is_null($model->completed_at)) {
throw new BadRequestHttpException(
'Cannot update the status of a backup that is already marked as completed.'
);
if (!is_null($model->completed_at)) {
throw new BadRequestHttpException('Cannot update the status of a backup that is already marked as completed.');
}
$action = $request->input('successful')
@ -124,10 +117,6 @@ class BackupStatusController extends Controller
* Marks a multipart upload in a given S3-compatiable instance as failed or successful for
* the given backup.
*
* @param \Pterodactyl\Models\Backup $backup
* @param \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter
* @param bool $successful
*
* @throws \Exception
* @throws \Pterodactyl\Exceptions\DisplayException
*/
@ -139,7 +128,7 @@ class BackupStatusController extends Controller
// A failed backup doesn't need to error here, this can happen if the backup encouters
// an error before we even start the upload. AWS gives you tooling to clear these failed
// multipart uploads as needed too.
if (! $successful) {
if (!$successful) {
return;
}
throw new DisplayException('Cannot complete backup request: no upload_id present on model.');
@ -152,7 +141,7 @@ class BackupStatusController extends Controller
];
$client = $adapter->getClient();
if (! $successful) {
if (!$successful) {
$client->execute($client->getCommand('AbortMultipartUpload', $params));
return;

View file

@ -22,9 +22,6 @@ class EggInstallController extends Controller
/**
* EggInstallController constructor.
*
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(EnvironmentService $environment, ServerRepositoryInterface $repository)
{
@ -36,10 +33,6 @@ class EggInstallController extends Controller
* Handle request to get script and installation information for a server
* that is being created on the node.
*
* @param \Illuminate\Http\Request $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function index(Request $request, string $uuid): JsonResponse
@ -57,7 +50,7 @@ class EggInstallController extends Controller
return response()->json([
'scripts' => [
'install' => ! $egg->copy_script_install ? null : str_replace(["\r\n", "\n", "\r"], "\n", $egg->copy_script_install),
'install' => !$egg->copy_script_install ? null : str_replace(["\r\n", "\n", "\r"], "\n", $egg->copy_script_install),
'privileged' => $egg->script_is_privileged,
],
'config' => [

View file

@ -31,11 +31,6 @@ class ServerDetailsController extends Controller
/**
* ServerConfigurationController constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $eggConfigurationService
* @param \Pterodactyl\Repositories\Eloquent\NodeRepository $nodeRepository
*/
public function __construct(
ServerRepository $repository,
@ -52,8 +47,8 @@ class ServerDetailsController extends Controller
* Returns details about the server that allows Wings to self-recover and ensure
* that the state of the server matches the Panel at all times.
*
* @param \Illuminate\Http\Request $request
* @param string $uuid
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -71,7 +66,6 @@ class ServerDetailsController extends Controller
/**
* Lists all servers with their configurations that are assigned to the requesting node.
*
* @param \Illuminate\Http\Request $request
* @return \Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection
*/
public function list(Request $request)
@ -85,7 +79,7 @@ class ServerDetailsController extends Controller
->where('node_id', $node->id)
// If you don't cast this to a string you'll end up with a stringified per_page returned in
// the metadata, and then Wings will panic crash as a result.
->paginate((int)$request->input('per_page', 50));
->paginate((int) $request->input('per_page', 50));
return new ServerConfigurationCollection($servers);
}

View file

@ -19,8 +19,6 @@ class ServerInstallController extends Controller
/**
* ServerInstallController constructor.
*
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
*/
public function __construct(ServerRepository $repository)
{
@ -30,8 +28,6 @@ class ServerInstallController extends Controller
/**
* Returns installation information for a server.
*
* @param \Illuminate\Http\Request $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -51,8 +47,6 @@ class ServerInstallController extends Controller
/**
* Updates the installation state of a server.
*
* @param \Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException

View file

@ -2,7 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Cake\Chronos\Chronos;
use Carbon\CarbonImmutable;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@ -53,13 +53,6 @@ class ServerTransferController extends Controller
/**
* ServerTransferController constructor.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
* @param \Pterodactyl\Repositories\Wings\DaemonTransferRepository $daemonTransferRepository
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
* @param \Pterodactyl\Services\Nodes\NodeJWTService $jwtService
*/
public function __construct(
ConnectionInterface $connection,
@ -80,8 +73,6 @@ class ServerTransferController extends Controller
/**
* The daemon notifies us about the archive status.
*
* @param \Illuminate\Http\Request $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -92,7 +83,7 @@ class ServerTransferController extends Controller
$server = $this->repository->getByUuid($uuid);
// Unsuspend the server and don't continue the transfer.
if (! $request->input('successful')) {
if (!$request->input('successful')) {
return $this->processFailedTransfer($server->transfer);
}
@ -110,11 +101,11 @@ class ServerTransferController extends Controller
Arr::set($data, 'suspended', false);
$this->connection->transaction(function () use ($data, $server) {
// This token is used by the new node the server is being transfered to. It allows
// This token is used by the new node the server is being transferred to. It allows
// that node to communicate with the old node during the process to initiate the
// actual file transfer.
$token = $this->jwtService
->setExpiresAt(Chronos::now()->addMinutes(15))
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setSubject($server->uuid)
->handle($server->node, $server->uuid, 'sha256');
@ -128,7 +119,7 @@ class ServerTransferController extends Controller
$this->daemonTransferRepository
->setServer($server)
->setNode($server->transfer->newNode)
->notify($server, $data, $server->node, $token->__toString());
->notify($server, $data, $server->node, $token->toString());
});
return new JsonResponse([], Response::HTTP_NO_CONTENT);
@ -137,7 +128,6 @@ class ServerTransferController extends Controller
/**
* The daemon notifies us about a transfer failure.
*
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -152,7 +142,6 @@ class ServerTransferController extends Controller
/**
* The daemon notifies us about a transfer success.
*
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -165,7 +154,7 @@ class ServerTransferController extends Controller
/** @var \Pterodactyl\Models\Server $server */
$server = $this->connection->transaction(function () use ($server, $transfer) {
$allocations = [$transfer->old_allocation];
if (! empty($transfer->old_additional_allocations)) {
if (!empty($transfer->old_additional_allocations)) {
array_push($allocations, $transfer->old_additional_allocations);
}
@ -201,7 +190,6 @@ class ServerTransferController extends Controller
* Release all of the reserved allocations for this transfer and mark it as failed in
* the database.
*
* @param \Pterodactyl\Models\ServerTransfer $transfer
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -212,7 +200,7 @@ class ServerTransferController extends Controller
$transfer->forceFill(['successful' => false])->saveOrFail();
$allocations = [$transfer->new_allocation];
if (! empty($transfer->new_additional_allocations)) {
if (!empty($transfer->new_additional_allocations)) {
array_push($allocations, $transfer->new_additional_allocations);
}

View file

@ -38,10 +38,6 @@ class SftpAuthenticationController extends Controller
/**
* SftpController constructor.
*
* @param \Pterodactyl\Services\Servers\GetUserPermissionsService $permissionsService
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $userRepository
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
*/
public function __construct(
GetUserPermissionsService $permissionsService,
@ -57,9 +53,6 @@ class SftpAuthenticationController extends Controller
* Authenticate a set of credentials and return the associated server details
* for a SFTP connection on the daemon.
*
* @param \Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest $request
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
@ -76,15 +69,13 @@ class SftpAuthenticationController extends Controller
if ($this->hasTooManyLoginAttempts($request)) {
$seconds = $this->limiter()->availableIn($this->throttleKey($request));
throw new TooManyRequestsHttpException(
$seconds, "Too many login attempts for this account, please try again in {$seconds} seconds."
);
throw new TooManyRequestsHttpException($seconds, "Too many login attempts for this account, please try again in {$seconds} seconds.");
}
/** @var \Pterodactyl\Models\Node $node */
$node = $request->attributes->get('node');
if (empty($connection['server'])) {
throw new NotFoundHttpException;
throw new NotFoundHttpException();
}
/** @var \Pterodactyl\Models\User $user */
@ -93,27 +84,23 @@ class SftpAuthenticationController extends Controller
]);
$server = $this->serverRepository->getByUuid($connection['server'] ?? '');
if (! password_verify($request->input('password'), $user->password) || $server->node_id !== $node->id) {
if (!password_verify($request->input('password'), $user->password) || $server->node_id !== $node->id) {
$this->incrementLoginAttempts($request);
throw new HttpForbiddenException(
'Authorization credentials were not correct, please try again.'
);
throw new HttpForbiddenException('Authorization credentials were not correct, please try again.');
}
if (! $user->root_admin && $server->owner_id !== $user->id) {
if (!$user->root_admin && $server->owner_id !== $user->id) {
$permissions = $this->permissionsService->handle($server, $user);
if (! in_array(Permission::ACTION_FILE_SFTP, $permissions)) {
throw new HttpForbiddenException(
'You do not have permission to access SFTP for this server.'
);
if (!in_array(Permission::ACTION_FILE_SFTP, $permissions)) {
throw new HttpForbiddenException('You do not have permission to access SFTP for this server.');
}
}
// Prevent SFTP access to servers that are being transferred.
if (! is_null($server->transfer)) {
throw new ServerTransferringException;
if (!is_null($server->transfer)) {
throw new ServerTransferringException();
}
// Remember, for security purposes, only reveal the existence of the server to people that
@ -132,9 +119,6 @@ class SftpAuthenticationController extends Controller
/**
* Get the throttle key for the given request.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function throttleKey(Request $request): string
{