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

@ -48,9 +48,9 @@ class DaemonConnectionException extends DisplayException
// Attempt to pull the actual error message off the response and return that if it is not
// 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);
$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

View file

@ -185,9 +185,7 @@ class ServerViewController extends Controller
public function manage(Request $request, Server $server)
{
if ($server->status === Server::STATUS_INSTALL_FAILED) {
throw new DisplayException(
'This server is in a failed install state and cannot be recovered. Please delete and re-create the server.'
);
throw new DisplayException('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.

View file

@ -12,8 +12,8 @@ use Illuminate\Validation\UnauthorizedException;
use Pterodactyl\Services\Backups\DeleteBackupService;
use Pterodactyl\Services\Backups\DownloadLinkService;
use Pterodactyl\Services\Backups\InitiateBackupService;
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
use Pterodactyl\Transformers\Api\Client\BackupTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
@ -42,11 +42,6 @@ class BackupController extends ClientApiController
/**
* 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(
DaemonBackupRepository $repository,
@ -66,14 +61,12 @@ class BackupController extends ClientApiController
* Returns all of the backups for a given server instance in a paginated
* result set.
*
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function index(Request $request, Server $server)
{
if (! $request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException;
if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException();
}
$limit = min($request->query('per_page') ?? 20, 50);
@ -113,15 +106,12 @@ class BackupController extends ClientApiController
/**
* Returns information about a single backup.
*
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return array
*/
public function view(Request $request, Server $server, Backup $backup)
{
if (! $request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException;
if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) {
throw new UnauthorizedException();
}
return $this->fractal->item($backup)
@ -133,17 +123,14 @@ class BackupController extends ClientApiController
* Deletes a backup from the panel as well as the remote source where it is currently
* being stored.
*
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Models\Server $server
* @param \Pterodactyl\Models\Backup $backup
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function delete(Request $request, Server $server, Backup $backup)
{
if (! $request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) {
throw new UnauthorizedException;
if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) {
throw new UnauthorizedException();
}
$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
* 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
*/
public function download(Request $request, Server $server, Backup $backup)
{
if (! $request->user()->can(Permission::ACTION_BACKUP_DOWNLOAD, $server)) {
throw new UnauthorizedException;
if (!$request->user()->can(Permission::ACTION_BACKUP_DOWNLOAD, $server)) {
throw new UnauthorizedException();
}
switch ($backup->disk) {
@ -179,7 +163,7 @@ class BackupController extends ClientApiController
'attributes' => ['url' => ''],
]);
default:
throw new BadRequestHttpException;
throw new BadRequestHttpException();
}
}
@ -192,22 +176,19 @@ class BackupController extends ClientApiController
* files that currently exist on the server will be deleted before restoring.
* 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
*
* @throws \Throwable
*/
public function restore(Request $request, Server $server, Backup $backup)
{
if (! $request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) {
throw new UnauthorizedException;
if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) {
throw new UnauthorizedException();
}
// Cannot restore a backup unless a server is fully installed and not currently
// processing a different backup restoration request.
if (! is_null($server->status)) {
if (!is_null($server->status)) {
throw new BadRequestHttpException('This server is not currently in a state that allows for a backup to be restored.');
}

View file

@ -75,16 +75,13 @@ class FileController extends ClientApiController
/**
* 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
*/
public function contents(GetFileContentsRequest $request, Server $server): Response
{
$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']);
@ -146,10 +143,6 @@ class FileController extends ClientApiController
/**
* 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
*/
public function create(CreateFolderRequest $request, Server $server): JsonResponse
@ -169,10 +162,6 @@ class FileController extends ClientApiController
/**
* 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
*/
public function rename(RenameFileRequest $request, Server $server): JsonResponse
@ -220,7 +209,8 @@ class FileController extends ClientApiController
return $this->fileRepository->setServer($server)
->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)
->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
* table tracking for this restoration.
*
* @param \Illuminate\Http\Request $request
* @param string $backup
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
@ -104,7 +102,7 @@ class BackupStatusController extends Controller
// 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.
$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->metadata = ['backup_uuid' => $backup];
$server->update(['status' => null]);

View file

@ -25,10 +25,8 @@ class ServerInstalled
throw new NotFoundHttpException('No server resource was located in the request parameters.');
}
if (! $server->isInstalled()) {
throw new HttpException(
Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.'
);
if (!$server->isInstalled()) {
throw new HttpException(Response::HTTP_FORBIDDEN, 'Access to this resource is not allowed due to the current installation state.');
}
return $next($request);

View file

@ -67,7 +67,7 @@ class AccessingValidServer
// Servers can have install statuses other than 1 or 0, so don't check
// for a bool-type operator here.
if (! $server->isInstalled()) {
if (!$server->isInstalled()) {
if ($isApiRequest) {
throw new ConflictHttpException('Server is still completing the installation process.');
}

View file

@ -7,38 +7,37 @@ use Illuminate\Http\Request;
use Illuminate\Container\Container;
/**
* @property int $id
* @property string $uuid
* @property bool $is_system
* @property int|null $user_id
* @property int|null $server_id
* @property string $action
* @property string|null $subaction
* @property array $device
* @property array $metadata
* @property \Carbon\CarbonImmutable $created_at
*
* @property \Pterodactyl\Models\User|null $user
* @property int $id
* @property string $uuid
* @property bool $is_system
* @property int|null $user_id
* @property int|null $server_id
* @property string $action
* @property string|null $subaction
* @property array $device
* @property array $metadata
* @property \Carbon\CarbonImmutable $created_at
* @property \Pterodactyl\Models\User|null $user
* @property \Pterodactyl\Models\Server|null $server
*/
class AuditLog extends Model
{
const UPDATED_AT = null;
public const UPDATED_AT = null;
const SERVER__FILESYSTEM_DOWNLOAD = 'server:filesystem.download';
const SERVER__FILESYSTEM_WRITE = 'server:filesystem.write';
const SERVER__FILESYSTEM_DELETE = 'server:filesystem.delete';
const SERVER__FILESYSTEM_RENAME = 'server:filesystem.rename';
const SERVER__FILESYSTEM_COMPRESS = 'server:filesystem.compress';
const SERVER__FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress';
const SERVER__FILESYSTEM_PULL = 'server:filesystem.pull';
const SERVER__BACKUP_STARTED = 'server:backup.started';
const SERVER__BACKUP_FAILED = 'server:backup.failed';
const SERVER__BACKUP_COMPELTED = 'server:backup.completed';
const SERVER__BACKUP_DELETED = 'server:backup.deleted';
const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started';
const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed';
const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed';
public const SERVER__FILESYSTEM_DOWNLOAD = 'server:filesystem.download';
public const SERVER__FILESYSTEM_WRITE = 'server:filesystem.write';
public const SERVER__FILESYSTEM_DELETE = 'server:filesystem.delete';
public const SERVER__FILESYSTEM_RENAME = 'server:filesystem.rename';
public const SERVER__FILESYSTEM_COMPRESS = 'server:filesystem.compress';
public const SERVER__FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress';
public const SERVER__FILESYSTEM_PULL = 'server:filesystem.pull';
public const SERVER__BACKUP_STARTED = 'server:backup.started';
public const SERVER__BACKUP_FAILED = 'server:backup.failed';
public const SERVER__BACKUP_COMPELTED = 'server:backup.completed';
public const SERVER__BACKUP_DELETED = 'server:backup.deleted';
public const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started';
public const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed';
public const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed';
/**
* @var string[]
@ -100,16 +99,13 @@ class AuditLog extends Model
* 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.
*
* @param string $action
* @param array $metadata
* @param bool $isSystem
* @return $this
*/
public static function factory(string $action, array $metadata, bool $isSystem = false)
{
/** @var \Illuminate\Http\Request $request */
$request = Container::getInstance()->make('request');
if ($isSystem || ! $request instanceof Request) {
if ($isSystem || !$request instanceof Request) {
$request = null;
}

View file

@ -157,7 +157,7 @@ class Permission extends Model
'read' => 'Allows a user to view all backups that exist for this server.',
'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.',
'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

@ -8,49 +8,48 @@ use Illuminate\Database\Query\JoinClause;
use Znck\Eloquent\Traits\BelongsToThrough;
/**
* @property int $id
* @property string|null $external_id
* @property string $uuid
* @property string $uuidShort
* @property int $node_id
* @property string $name
* @property string $description
* @property string|null $status
* @property bool $skip_scripts
* @property int $owner_id
* @property int $memory
* @property int $swap
* @property int $disk
* @property int $io
* @property int $cpu
* @property string $threads
* @property bool $oom_disabled
* @property int $allocation_id
* @property int $nest_id
* @property int $egg_id
* @property string $startup
* @property string $image
* @property int $allocation_limit
* @property int $database_limit
* @property int $backup_limit
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*
* @property \Pterodactyl\Models\User $user
* @property \Pterodactyl\Models\Subuser[]|\Illuminate\Database\Eloquent\Collection $subusers
* @property \Pterodactyl\Models\Allocation $allocation
* @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations
* @property \Pterodactyl\Models\Node $node
* @property \Pterodactyl\Models\Nest $nest
* @property \Pterodactyl\Models\Egg $egg
* @property int $id
* @property string|null $external_id
* @property string $uuid
* @property string $uuidShort
* @property int $node_id
* @property string $name
* @property string $description
* @property string|null $status
* @property bool $skip_scripts
* @property int $owner_id
* @property int $memory
* @property int $swap
* @property int $disk
* @property int $io
* @property int $cpu
* @property string $threads
* @property bool $oom_disabled
* @property int $allocation_id
* @property int $nest_id
* @property int $egg_id
* @property string $startup
* @property string $image
* @property int $allocation_limit
* @property int $database_limit
* @property int $backup_limit
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property \Pterodactyl\Models\User $user
* @property \Pterodactyl\Models\Subuser[]|\Illuminate\Database\Eloquent\Collection $subusers
* @property \Pterodactyl\Models\Allocation $allocation
* @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations
* @property \Pterodactyl\Models\Node $node
* @property \Pterodactyl\Models\Nest $nest
* @property \Pterodactyl\Models\Egg $egg
* @property \Pterodactyl\Models\EggVariable[]|\Illuminate\Database\Eloquent\Collection $variables
* @property \Pterodactyl\Models\Schedule[]|\Illuminate\Database\Eloquent\Collection $schedule
* @property \Pterodactyl\Models\Database[]|\Illuminate\Database\Eloquent\Collection $databases
* @property \Pterodactyl\Models\Location $location
* @property \Pterodactyl\Models\ServerTransfer $transfer
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
* @property \Pterodactyl\Models\AuditLog[] $audits
* @property \Pterodactyl\Models\Schedule[]|\Illuminate\Database\Eloquent\Collection $schedule
* @property \Pterodactyl\Models\Database[]|\Illuminate\Database\Eloquent\Collection $databases
* @property \Pterodactyl\Models\Location $location
* @property \Pterodactyl\Models\ServerTransfer $transfer
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
* @property \Pterodactyl\Models\AuditLog[] $audits
*/
class Server extends Model
{
@ -63,10 +62,10 @@ class Server extends Model
*/
public const RESOURCE_NAME = 'server';
const STATUS_INSTALLING = 'installing';
const STATUS_INSTALL_FAILED = 'install_failed';
const STATUS_SUSPENDED = 'suspended';
const STATUS_RESTORING_BACKUP = 'restoring_backup';
public const STATUS_INSTALLING = 'installing';
public const STATUS_INSTALL_FAILED = 'install_failed';
public const STATUS_SUSPENDED = 'suspended';
public const STATUS_RESTORING_BACKUP = 'restoring_backup';
/**
* 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
* 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
*/
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.
*
* @param string $action
* @param \Closure $callback
* @return mixed
*
* @throws \Throwable
*/
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.
*
* @param \Pterodactyl\Models\Backup $backup
* @param string|null $url
* @param bool $truncate
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function restore(Backup $backup, string $url = null, bool $truncate = false): ResponseInterface

View file

@ -22,9 +22,6 @@ class DownloadLinkService
/**
* DownloadLinkService constructor.
*
* @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager
* @param \Pterodactyl\Services\Nodes\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
* 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
{
@ -61,7 +54,6 @@ class DownloadLinkService
* Returns a signed URL that allows us to download a file directly out of a non-public
* S3 bucket by using a signed URL.
*
* @param \Pterodactyl\Models\Backup $backup
* @return string
*/
protected function getS3BackupUrl(Backup $backup)

View file

@ -68,8 +68,8 @@ class ServerTransformer extends BaseClientTransformer
// This field is deprecated, please use "status".
'is_suspended' => $server->isSuspended(),
// This field is deprecated, please use "status".
'is_installing' => ! $server->isInstalled(),
'is_transferring' => ! is_null($server->transfer),
'is_installing' => !$server->isInstalled(),
'is_transferring' => !is_null($server->transfer),
];
}

View file

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