Reeformat with new rules post merge
This commit is contained in:
parent
663143de0b
commit
0a2c89e9f4
14 changed files with 104 additions and 159 deletions
|
@ -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.
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue