Reeformat with new rules post merge

This commit is contained in:
Dane Everitt 2021-01-25 19:20:51 -08:00
parent 663143de0b
commit 0a2c89e9f4
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 104 additions and 159 deletions

View file

@ -50,7 +50,7 @@ class DaemonConnectionException extends DisplayException
// a 500 level error. // a 500 level error.
if ($this->statusCode < 500 && !is_null($response)) { if ($this->statusCode < 500 && !is_null($response)) {
$body = json_decode($response->getBody()->__toString(), true); $body = json_decode($response->getBody()->__toString(), true);
$message = sprintf("An error occurred on the remote host: %s. (request id: %s)", $body['error'] ?? $message, $this->requestId ?? '<nil>'); $message = sprintf('An error occurred on the remote host: %s. (request id: %s)', $body['error'] ?? $message, $this->requestId ?? '<nil>');
} }
$level = $this->statusCode >= 500 && $this->statusCode !== 504 $level = $this->statusCode >= 500 && $this->statusCode !== 504

View file

@ -185,9 +185,7 @@ class ServerViewController extends Controller
public function manage(Request $request, Server $server) public function manage(Request $request, Server $server)
{ {
if ($server->status === Server::STATUS_INSTALL_FAILED) { if ($server->status === Server::STATUS_INSTALL_FAILED) {
throw new DisplayException( throw new DisplayException('This server is in a failed install state and cannot be recovered. Please delete and re-create the server.');
'This server is in a failed install state and cannot be recovered. Please delete and re-create the server.'
);
} }
// Check if the panel doesn't have at least 2 nodes configured. // Check if the panel doesn't have at least 2 nodes configured.

View file

@ -12,8 +12,8 @@ use Illuminate\Validation\UnauthorizedException;
use Pterodactyl\Services\Backups\DeleteBackupService; use Pterodactyl\Services\Backups\DeleteBackupService;
use Pterodactyl\Services\Backups\DownloadLinkService; use Pterodactyl\Services\Backups\DownloadLinkService;
use Pterodactyl\Services\Backups\InitiateBackupService; use Pterodactyl\Services\Backups\InitiateBackupService;
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository; use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
@ -42,11 +42,6 @@ class BackupController extends ClientApiController
/** /**
* BackupController constructor. * BackupController constructor.
*
* @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $repository
* @param \Pterodactyl\Services\Backups\DeleteBackupService $deleteBackupService
* @param \Pterodactyl\Services\Backups\InitiateBackupService $initiateBackupService
* @param \Pterodactyl\Services\Backups\DownloadLinkService $downloadLinkService
*/ */
public function __construct( public function __construct(
DaemonBackupRepository $repository, DaemonBackupRepository $repository,
@ -66,14 +61,12 @@ class BackupController extends ClientApiController
* Returns all of the backups for a given server instance in a paginated * Returns all of the backups for a given server instance in a paginated
* result set. * result set.
* *
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @return array * @return array
*/ */
public function index(Request $request, Server $server) public function index(Request $request, Server $server)
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException; throw new UnauthorizedException();
} }
$limit = min($request->query('per_page') ?? 20, 50); $limit = min($request->query('per_page') ?? 20, 50);
@ -113,15 +106,12 @@ class BackupController extends ClientApiController
/** /**
* Returns information about a single backup. * Returns information about a single backup.
* *
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return array * @return array
*/ */
public function view(Request $request, Server $server, Backup $backup) public function view(Request $request, Server $server, Backup $backup)
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException; throw new UnauthorizedException();
} }
return $this->fractal->item($backup) return $this->fractal->item($backup)
@ -133,9 +123,6 @@ class BackupController extends ClientApiController
* Deletes a backup from the panel as well as the remote source where it is currently * Deletes a backup from the panel as well as the remote source where it is currently
* being stored. * being stored.
* *
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* *
* @throws \Throwable * @throws \Throwable
@ -143,7 +130,7 @@ class BackupController extends ClientApiController
public function delete(Request $request, Server $server, Backup $backup) public function delete(Request $request, Server $server, Backup $backup)
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) {
throw new UnauthorizedException; throw new UnauthorizedException();
} }
$server->audit(AuditLog::SERVER__BACKUP_DELETED, function (AuditLog $audit) use ($backup) { $server->audit(AuditLog::SERVER__BACKUP_DELETED, function (AuditLog $audit) use ($backup) {
@ -160,15 +147,12 @@ class BackupController extends ClientApiController
* will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated * will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated
* which the user is redirected to. * which the user is redirected to.
* *
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function download(Request $request, Server $server, Backup $backup) public function download(Request $request, Server $server, Backup $backup)
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_DOWNLOAD, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_DOWNLOAD, $server)) {
throw new UnauthorizedException; throw new UnauthorizedException();
} }
switch ($backup->disk) { switch ($backup->disk) {
@ -179,7 +163,7 @@ class BackupController extends ClientApiController
'attributes' => ['url' => ''], 'attributes' => ['url' => ''],
]); ]);
default: default:
throw new BadRequestHttpException; throw new BadRequestHttpException();
} }
} }
@ -192,9 +176,6 @@ class BackupController extends ClientApiController
* files that currently exist on the server will be deleted before restoring. * files that currently exist on the server will be deleted before restoring.
* Otherwise the archive will simply be unpacked over the existing files. * Otherwise the archive will simply be unpacked over the existing files.
* *
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* *
* @throws \Throwable * @throws \Throwable
@ -202,7 +183,7 @@ class BackupController extends ClientApiController
public function restore(Request $request, Server $server, Backup $backup) public function restore(Request $request, Server $server, Backup $backup)
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) {
throw new UnauthorizedException; throw new UnauthorizedException();
} }
// Cannot restore a backup unless a server is fully installed and not currently // Cannot restore a backup unless a server is fully installed and not currently

View file

@ -75,16 +75,13 @@ class FileController extends ClientApiController
/** /**
* Return the contents of a specified file for the user. * Return the contents of a specified file for the user.
* *
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\GetFileContentsRequest $request
* @param \Pterodactyl\Models\Server $server
* @return \Illuminate\Http\Response
*
* @throws \Throwable * @throws \Throwable
*/ */
public function contents(GetFileContentsRequest $request, Server $server): Response public function contents(GetFileContentsRequest $request, Server $server): Response
{ {
$response = $this->fileRepository->setServer($server)->getContent( $response = $this->fileRepository->setServer($server)->getContent(
$request->get('file'), config('pterodactyl.files.max_edit_size') $request->get('file'),
config('pterodactyl.files.max_edit_size')
); );
return new Response($response, Response::HTTP_OK, ['Content-Type' => 'text/plain']); return new Response($response, Response::HTTP_OK, ['Content-Type' => 'text/plain']);
@ -146,10 +143,6 @@ class FileController extends ClientApiController
/** /**
* Creates a new folder on the server. * Creates a new folder on the server.
* *
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\CreateFolderRequest $request
* @param \Pterodactyl\Models\Server $server
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function create(CreateFolderRequest $request, Server $server): JsonResponse public function create(CreateFolderRequest $request, Server $server): JsonResponse
@ -169,10 +162,6 @@ class FileController extends ClientApiController
/** /**
* Renames a file on the remote machine. * Renames a file on the remote machine.
* *
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest $request
* @param \Pterodactyl\Models\Server $server
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function rename(RenameFileRequest $request, Server $server): JsonResponse public function rename(RenameFileRequest $request, Server $server): JsonResponse
@ -220,7 +209,8 @@ class FileController extends ClientApiController
return $this->fileRepository->setServer($server) return $this->fileRepository->setServer($server)
->compressFiles( ->compressFiles(
$request->input('root'), $request->input('files') $request->input('root'),
$request->input('files')
); );
}); });
@ -259,7 +249,8 @@ class FileController extends ClientApiController
$this->fileRepository->setServer($server) $this->fileRepository->setServer($server)
->deleteFiles( ->deleteFiles(
$request->input('root'), $request->input('files') $request->input('root'),
$request->input('files')
); );
}); });

View file

@ -88,8 +88,6 @@ class BackupStatusController extends Controller
* The only thing the successful field does is update the entry value for the audit logs * The only thing the successful field does is update the entry value for the audit logs
* table tracking for this restoration. * table tracking for this restoration.
* *
* @param \Illuminate\Http\Request $request
* @param string $backup
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* *
* @throws \Throwable * @throws \Throwable
@ -104,7 +102,7 @@ class BackupStatusController extends Controller
// Just create a new audit entry for this event and update the server state // Just create a new audit entry for this event and update the server state
// so that power actions, file management, and backups can resume as normal. // so that power actions, file management, and backups can resume as normal.
$model->server->audit($action, function (AuditLog $audit, Server $server) use ($backup, $request) { $model->server->audit($action, function (AuditLog $audit, Server $server) use ($backup) {
$audit->is_system = true; $audit->is_system = true;
$audit->metadata = ['backup_uuid' => $backup]; $audit->metadata = ['backup_uuid' => $backup];
$server->update(['status' => null]); $server->update(['status' => null]);

View file

@ -26,9 +26,7 @@ class ServerInstalled
} }
if (!$server->isInstalled()) { if (!$server->isInstalled()) {
throw new HttpException( throw new HttpException(Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.');
Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.'
);
} }
return $next($request); return $next($request);

View file

@ -17,28 +17,27 @@ use Illuminate\Container\Container;
* @property array $device * @property array $device
* @property array $metadata * @property array $metadata
* @property \Carbon\CarbonImmutable $created_at * @property \Carbon\CarbonImmutable $created_at
*
* @property \Pterodactyl\Models\User|null $user * @property \Pterodactyl\Models\User|null $user
* @property \Pterodactyl\Models\Server|null $server * @property \Pterodactyl\Models\Server|null $server
*/ */
class AuditLog extends Model class AuditLog extends Model
{ {
const UPDATED_AT = null; public const UPDATED_AT = null;
const SERVER__FILESYSTEM_DOWNLOAD = 'server:filesystem.download'; public const SERVER__FILESYSTEM_DOWNLOAD = 'server:filesystem.download';
const SERVER__FILESYSTEM_WRITE = 'server:filesystem.write'; public const SERVER__FILESYSTEM_WRITE = 'server:filesystem.write';
const SERVER__FILESYSTEM_DELETE = 'server:filesystem.delete'; public const SERVER__FILESYSTEM_DELETE = 'server:filesystem.delete';
const SERVER__FILESYSTEM_RENAME = 'server:filesystem.rename'; public const SERVER__FILESYSTEM_RENAME = 'server:filesystem.rename';
const SERVER__FILESYSTEM_COMPRESS = 'server:filesystem.compress'; public const SERVER__FILESYSTEM_COMPRESS = 'server:filesystem.compress';
const SERVER__FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress'; public const SERVER__FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress';
const SERVER__FILESYSTEM_PULL = 'server:filesystem.pull'; public const SERVER__FILESYSTEM_PULL = 'server:filesystem.pull';
const SERVER__BACKUP_STARTED = 'server:backup.started'; public const SERVER__BACKUP_STARTED = 'server:backup.started';
const SERVER__BACKUP_FAILED = 'server:backup.failed'; public const SERVER__BACKUP_FAILED = 'server:backup.failed';
const SERVER__BACKUP_COMPELTED = 'server:backup.completed'; public const SERVER__BACKUP_COMPELTED = 'server:backup.completed';
const SERVER__BACKUP_DELETED = 'server:backup.deleted'; public const SERVER__BACKUP_DELETED = 'server:backup.deleted';
const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started'; public const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started';
const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed'; public const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed';
const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed'; public const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed';
/** /**
* @var string[] * @var string[]
@ -100,9 +99,6 @@ class AuditLog extends Model
* currently authenticated user if available. This model is not saved at this point, so * currently authenticated user if available. This model is not saved at this point, so
* you can always make modifications to it as needed before saving. * you can always make modifications to it as needed before saving.
* *
* @param string $action
* @param array $metadata
* @param bool $isSystem
* @return $this * @return $this
*/ */
public static function factory(string $action, array $metadata, bool $isSystem = false) public static function factory(string $action, array $metadata, bool $isSystem = false)

View file

@ -157,7 +157,7 @@ class Permission extends Model
'read' => 'Allows a user to view all backups that exist for this server.', 'read' => 'Allows a user to view all backups that exist for this server.',
'delete' => 'Allows a user to remove backups from the system.', 'delete' => 'Allows a user to remove backups from the system.',
'download' => 'Allows a user to download a backup for the server. Danger: this allows a user to access all files for the server in the backup.', 'download' => 'Allows a user to download a backup for the server. Danger: this allows a user to access all files for the server in the backup.',
'restore' => 'Allows a user to restore a backup for the server. Danger: this allows the user to delete all of the server files in the process.' 'restore' => 'Allows a user to restore a backup for the server. Danger: this allows the user to delete all of the server files in the process.',
], ],
], ],

View file

@ -35,7 +35,6 @@ use Znck\Eloquent\Traits\BelongsToThrough;
* @property int $backup_limit * @property int $backup_limit
* @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $updated_at
*
* @property \Pterodactyl\Models\User $user * @property \Pterodactyl\Models\User $user
* @property \Pterodactyl\Models\Subuser[]|\Illuminate\Database\Eloquent\Collection $subusers * @property \Pterodactyl\Models\Subuser[]|\Illuminate\Database\Eloquent\Collection $subusers
* @property \Pterodactyl\Models\Allocation $allocation * @property \Pterodactyl\Models\Allocation $allocation
@ -63,10 +62,10 @@ class Server extends Model
*/ */
public const RESOURCE_NAME = 'server'; public const RESOURCE_NAME = 'server';
const STATUS_INSTALLING = 'installing'; public const STATUS_INSTALLING = 'installing';
const STATUS_INSTALL_FAILED = 'install_failed'; public const STATUS_INSTALL_FAILED = 'install_failed';
const STATUS_SUSPENDED = 'suspended'; public const STATUS_SUSPENDED = 'suspended';
const STATUS_RESTORING_BACKUP = 'restoring_backup'; public const STATUS_RESTORING_BACKUP = 'restoring_backup';
/** /**
* The table associated with the model. * The table associated with the model.
@ -332,8 +331,6 @@ class Server extends Model
* Returns a fresh AuditLog model for the server. This model is not saved to the * Returns a fresh AuditLog model for the server. This model is not saved to the
* database when created, so it is up to the caller to correctly store it as needed. * database when created, so it is up to the caller to correctly store it as needed.
* *
* @param string $action
* @param array $metadata
* @return \Pterodactyl\Models\AuditLog * @return \Pterodactyl\Models\AuditLog
*/ */
public function newAuditEvent(string $action, array $metadata = []): AuditLog public function newAuditEvent(string $action, array $metadata = []): AuditLog
@ -352,9 +349,8 @@ class Server extends Model
* *
* The response from the callback is returned to the caller. * The response from the callback is returned to the caller.
* *
* @param string $action
* @param \Closure $callback
* @return mixed * @return mixed
*
* @throws \Throwable * @throws \Throwable
*/ */
public function audit(string $action, Closure $callback) public function audit(string $action, Closure $callback)

View file

@ -56,11 +56,6 @@ class DaemonBackupRepository extends DaemonRepository
/** /**
* Sends a request to Wings to begin restoring a backup for a server. * Sends a request to Wings to begin restoring a backup for a server.
* *
* @param \Pterodactyl\Models\Backup $backup
* @param string|null $url
* @param bool $truncate
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function restore(Backup $backup, string $url = null, bool $truncate = false): ResponseInterface public function restore(Backup $backup, string $url = null, bool $truncate = false): ResponseInterface

View file

@ -22,9 +22,6 @@ class DownloadLinkService
/** /**
* DownloadLinkService constructor. * DownloadLinkService constructor.
*
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
* @param \Pterodactyl\Services\Nodes\NodeJWTService $jwtService
*/ */
public function __construct(BackupManager $backupManager, NodeJWTService $jwtService) public function __construct(BackupManager $backupManager, NodeJWTService $jwtService)
{ {
@ -35,10 +32,6 @@ class DownloadLinkService
/** /**
* Returns the URL that allows for a backup to be downloaded by an individual * Returns the URL that allows for a backup to be downloaded by an individual
* user, or by the Wings control software. * user, or by the Wings control software.
*
* @param \Pterodactyl\Models\Backup $backup
* @param \Pterodactyl\Models\User $user
* @return string
*/ */
public function handle(Backup $backup, User $user): string public function handle(Backup $backup, User $user): string
{ {
@ -61,7 +54,6 @@ class DownloadLinkService
* Returns a signed URL that allows us to download a file directly out of a non-public * Returns a signed URL that allows us to download a file directly out of a non-public
* S3 bucket by using a signed URL. * S3 bucket by using a signed URL.
* *
* @param \Pterodactyl\Models\Backup $backup
* @return string * @return string
*/ */
protected function getS3BackupUrl(Backup $backup) protected function getS3BackupUrl(Backup $backup)

View file

@ -1,9 +1,9 @@
<?php <?php
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddGenericServerStatusColumn extends Migration class AddGenericServerStatusColumn extends Migration
{ {