api: cleanup controllers
This commit is contained in:
parent
00c42225e8
commit
f78aaea6a3
47 changed files with 323 additions and 764 deletions
|
@ -4,8 +4,8 @@ namespace Pterodactyl\Http\Controllers\Api\Client;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Auth\AuthManager;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Pterodactyl\Services\Users\UserUpdateService;
|
||||
use Pterodactyl\Transformers\Api\Client\AccountTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
|
||||
|
@ -13,27 +13,25 @@ use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
|
|||
|
||||
class AccountController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Users\UserUpdateService
|
||||
*/
|
||||
private $updateService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Auth\SessionGuard
|
||||
*/
|
||||
private $sessionGuard;
|
||||
private SessionGuard $sessionGuard;
|
||||
private UserUpdateService $updateService;
|
||||
|
||||
/**
|
||||
* AccountController constructor.
|
||||
*/
|
||||
public function __construct(AuthManager $sessionGuard, UserUpdateService $updateService)
|
||||
public function __construct(SessionGuard $sessionGuard, UserUpdateService $updateService)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->updateService = $updateService;
|
||||
$this->sessionGuard = $sessionGuard;
|
||||
$this->updateService = $updateService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's information about the currently authenticated user.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(Request $request): array
|
||||
{
|
||||
return $this->fractal->item($request->user())
|
||||
|
@ -51,7 +49,7 @@ class AccountController extends ClientApiController
|
|||
{
|
||||
$this->updateService->handle($request->user(), $request->validated());
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,6 +65,6 @@ class AccountController extends ClientApiController
|
|||
|
||||
$this->sessionGuard->logoutOtherDevices($request->input('password'));
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Services\Api\KeyCreationService;
|
||||
|
@ -15,42 +15,31 @@ use Pterodactyl\Http\Requests\Api\Client\Account\StoreApiKeyRequest;
|
|||
|
||||
class ApiKeyController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Api\KeyCreationService
|
||||
*/
|
||||
private $keyCreationService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
|
||||
*/
|
||||
private $repository;
|
||||
private Encrypter $encrypter;
|
||||
private ApiKeyRepository $repository;
|
||||
private KeyCreationService $keyCreationService;
|
||||
|
||||
/**
|
||||
* ApiKeyController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
Encrypter $encrypter,
|
||||
KeyCreationService $keyCreationService,
|
||||
ApiKeyRepository $repository
|
||||
ApiKeyRepository $repository,
|
||||
KeyCreationService $keyCreationService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->encrypter = $encrypter;
|
||||
$this->keyCreationService = $keyCreationService;
|
||||
$this->repository = $repository;
|
||||
$this->keyCreationService = $keyCreationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the API keys that exist for the given client.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(ClientApiRequest $request)
|
||||
public function index(ClientApiRequest $request): array
|
||||
{
|
||||
return $this->fractal->collection($request->user()->apiKeys)
|
||||
->transformWith($this->getTransformer(ApiKeyTransformer::class))
|
||||
|
@ -60,12 +49,11 @@ class ApiKeyController extends ClientApiController
|
|||
/**
|
||||
* Store a new API key for a user's account.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function store(StoreApiKeyRequest $request)
|
||||
public function store(StoreApiKeyRequest $request): array
|
||||
{
|
||||
if ($request->user()->apiKeys->count() >= 5) {
|
||||
throw new DisplayException('You have reached the account limit for number of API keys.');
|
||||
|
@ -87,10 +75,8 @@ class ApiKeyController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Deletes a given API key.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(ClientApiRequest $request, string $identifier)
|
||||
public function delete(ClientApiRequest $request, string $identifier): Response
|
||||
{
|
||||
$response = $this->repository->deleteWhere([
|
||||
'key_type' => ApiKey::TYPE_ACCOUNT,
|
||||
|
@ -102,6 +88,6 @@ class ApiKeyController extends ClientApiController
|
|||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ abstract class ClientApiController extends ApplicationApiController
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = [])
|
||||
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
|
||||
{
|
||||
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
|
||||
return in_array($datum, $transformer->getAvailableIncludes());
|
||||
|
@ -29,7 +29,7 @@ abstract class ClientApiController extends ApplicationApiController
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function parseIncludes()
|
||||
protected function parseIncludes(): array
|
||||
{
|
||||
$includes = $this->request->query('include') ?? [];
|
||||
|
||||
|
@ -45,9 +45,9 @@ abstract class ClientApiController extends ApplicationApiController
|
|||
/**
|
||||
* Return an instance of an application transformer.
|
||||
*
|
||||
* @return \Pterodactyl\Transformers\Api\Client\BaseClientTransformer
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getTransformer(string $abstract)
|
||||
public function getTransformer(string $abstract): BaseClientTransformer
|
||||
{
|
||||
/** @var \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer */
|
||||
$transformer = Container::getInstance()->make($abstract);
|
||||
|
|
|
@ -13,10 +13,7 @@ use Pterodactyl\Http\Requests\Api\Client\GetServersRequest;
|
|||
|
||||
class ClientController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
private ServerRepository $repository;
|
||||
|
||||
/**
|
||||
* ClientController constructor.
|
||||
|
@ -31,6 +28,8 @@ class ClientController extends ClientApiController
|
|||
/**
|
||||
* Return all of the servers available to the client making the API
|
||||
* request, including servers the user has access to as a subuser.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetServersRequest $request): array
|
||||
{
|
||||
|
@ -75,10 +74,8 @@ class ClientController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Returns all of the subuser permissions available on the system.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function permissions()
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'object' => 'system_permissions',
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\AuditLog;
|
||||
|
@ -20,25 +21,10 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
|
|||
|
||||
class BackupController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Backups\InitiateBackupService
|
||||
*/
|
||||
private $initiateBackupService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Backups\DeleteBackupService
|
||||
*/
|
||||
private $deleteBackupService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Backups\DownloadLinkService
|
||||
*/
|
||||
private $downloadLinkService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
|
||||
*/
|
||||
private $repository;
|
||||
private InitiateBackupService $initiateBackupService;
|
||||
private DeleteBackupService $deleteBackupService;
|
||||
private DownloadLinkService $downloadLinkService;
|
||||
private DaemonBackupRepository $repository;
|
||||
|
||||
/**
|
||||
* BackupController constructor.
|
||||
|
@ -61,9 +47,8 @@ class BackupController extends ClientApiController
|
|||
* Returns all of the backups for a given server instance in a paginated
|
||||
* result set.
|
||||
*
|
||||
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
|
||||
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(Request $request, Server $server): array
|
||||
{
|
||||
|
@ -81,8 +66,6 @@ class BackupController extends ClientApiController
|
|||
/**
|
||||
* Starts the backup process for a server.
|
||||
*
|
||||
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
|
||||
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function store(StoreBackupRequest $request, Server $server): array
|
||||
|
@ -108,9 +91,8 @@ class BackupController extends ClientApiController
|
|||
/**
|
||||
* Returns information about a single backup.
|
||||
*
|
||||
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
|
||||
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(Request $request, Server $server, Backup $backup): array
|
||||
{
|
||||
|
@ -129,7 +111,7 @@ class BackupController extends ClientApiController
|
|||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function delete(Request $request, Server $server, Backup $backup): JsonResponse
|
||||
public function delete(Request $request, Server $server, Backup $backup): Response
|
||||
{
|
||||
if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) {
|
||||
throw new AuthorizationException();
|
||||
|
@ -141,7 +123,7 @@ class BackupController extends ClientApiController
|
|||
$this->deleteBackupService->handle($backup);
|
||||
});
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +162,7 @@ class BackupController extends ClientApiController
|
|||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function restore(Request $request, Server $server, Backup $backup): JsonResponse
|
||||
public function restore(Request $request, Server $server, Backup $backup): Response
|
||||
{
|
||||
if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) {
|
||||
throw new AuthorizationException();
|
||||
|
@ -212,6 +194,6 @@ class BackupController extends ClientApiController
|
|||
$this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate') === 'true');
|
||||
});
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,7 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|||
|
||||
class CommandController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonCommandRepository
|
||||
*/
|
||||
private $repository;
|
||||
private DaemonCommandRepository $repository;
|
||||
|
||||
/**
|
||||
* CommandController constructor.
|
||||
|
|
|
@ -42,6 +42,8 @@ class DatabaseController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Return all of the databases that belong to the given server.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetDatabasesRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -71,11 +73,9 @@ class DatabaseController extends ClientApiController
|
|||
* Rotates the password for the given server model and returns a fresh instance to
|
||||
* the caller.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function rotatePassword(RotatePasswordRequest $request, Server $server, Database $database)
|
||||
public function rotatePassword(RotatePasswordRequest $request, Server $server, Database $database): array
|
||||
{
|
||||
$this->passwordService->handle($database);
|
||||
$database->refresh();
|
||||
|
@ -89,12 +89,12 @@ class DatabaseController extends ClientApiController
|
|||
/**
|
||||
* Removes a database from the server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(DeleteDatabaseRequest $request, Server $server, Database $database): Response
|
||||
{
|
||||
$this->managementService->delete($database);
|
||||
|
||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use Carbon\CarbonImmutable;
|
|||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\AuditLog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Services\Nodes\NodeJWTService;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
|
||||
|
@ -26,28 +25,17 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\WriteFileContentRequest;
|
|||
|
||||
class FileController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonFileRepository
|
||||
*/
|
||||
private $fileRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Routing\ResponseFactory
|
||||
*/
|
||||
private $responseFactory;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nodes\NodeJWTService
|
||||
*/
|
||||
private $jwtService;
|
||||
private DaemonFileRepository $fileRepository;
|
||||
private ResponseFactory $responseFactory;
|
||||
private NodeJWTService $jwtService;
|
||||
|
||||
/**
|
||||
* FileController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
DaemonFileRepository $fileRepository,
|
||||
ResponseFactory $responseFactory,
|
||||
NodeJWTService $jwtService,
|
||||
DaemonFileRepository $fileRepository
|
||||
NodeJWTService $jwtService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
|
@ -60,6 +48,7 @@ class FileController extends ClientApiController
|
|||
* Returns a listing of files in a given directory.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function directory(ListFilesRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -91,11 +80,9 @@ class FileController extends ClientApiController
|
|||
* Generates a one-time token with a link that the user can use to
|
||||
* download a given file.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function download(GetFileContentsRequest $request, Server $server)
|
||||
public function download(GetFileContentsRequest $request, Server $server): array
|
||||
{
|
||||
$token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->metadata = ['file' => $request->get('file')];
|
||||
|
@ -124,9 +111,9 @@ class FileController extends ClientApiController
|
|||
/**
|
||||
* Writes the contents of the specified file to the server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function write(WriteFileContentRequest $request, Server $server): JsonResponse
|
||||
public function write(WriteFileContentRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->subaction = 'write_content';
|
||||
|
@ -137,7 +124,7 @@ class FileController extends ClientApiController
|
|||
->putContent($request->get('file'), $request->getContent());
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +132,7 @@ class FileController extends ClientApiController
|
|||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function create(CreateFolderRequest $request, Server $server): JsonResponse
|
||||
public function create(CreateFolderRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->subaction = 'create_folder';
|
||||
|
@ -156,7 +143,7 @@ class FileController extends ClientApiController
|
|||
->createDirectory($request->input('name'), $request->input('root', '/'));
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,7 +151,7 @@ class FileController extends ClientApiController
|
|||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function rename(RenameFileRequest $request, Server $server): JsonResponse
|
||||
public function rename(RenameFileRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_RENAME, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
|
||||
|
@ -174,15 +161,15 @@ class FileController extends ClientApiController
|
|||
->renameFiles($request->input('root'), $request->input('files'));
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file on the server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function copy(CopyFileRequest $request, Server $server): JsonResponse
|
||||
public function copy(CopyFileRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->subaction = 'copy_file';
|
||||
|
@ -193,11 +180,11 @@ class FileController extends ClientApiController
|
|||
->copyFile($request->input('location'));
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function compress(CompressFilesRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -220,9 +207,9 @@ class FileController extends ClientApiController
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse
|
||||
public function decompress(DecompressFilesRequest $request, Server $server): Response
|
||||
{
|
||||
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) {
|
||||
// Allow up to five minutes for this request to process before timing out.
|
||||
|
@ -234,15 +221,15 @@ class FileController extends ClientApiController
|
|||
->decompressFile($request->input('root'), $request->input('file'));
|
||||
});
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes files or folders for the server in the given root directory.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function delete(DeleteFileRequest $request, Server $server): JsonResponse
|
||||
public function delete(DeleteFileRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_DELETE, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
|
||||
|
@ -254,7 +241,7 @@ class FileController extends ClientApiController
|
|||
);
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,7 +249,7 @@ class FileController extends ClientApiController
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function chmod(ChmodFilesRequest $request, Server $server): JsonResponse
|
||||
public function chmod(ChmodFilesRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository->setServer($server)
|
||||
->chmodFiles(
|
||||
|
@ -270,17 +257,15 @@ class FileController extends ClientApiController
|
|||
$request->input('files')
|
||||
);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that a file be downloaded from a remote location by Wings.
|
||||
*
|
||||
* @param $request
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function pull(PullFileRequest $request, Server $server): JsonResponse
|
||||
public function pull(PullFileRequest $request, Server $server): Response
|
||||
{
|
||||
$server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')];
|
||||
|
@ -288,6 +273,6 @@ class FileController extends ClientApiController
|
|||
$this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory'));
|
||||
});
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,17 +12,13 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest;
|
|||
|
||||
class FileUploadController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nodes\NodeJWTService
|
||||
*/
|
||||
private $jwtService;
|
||||
private NodeJWTService $jwtService;
|
||||
|
||||
/**
|
||||
* FileUploadController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
NodeJWTService $jwtService
|
||||
) {
|
||||
public function __construct(NodeJWTService $jwtService)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->jwtService = $jwtService;
|
||||
|
@ -30,10 +26,8 @@ class FileUploadController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Returns a url where files can be uploaded to.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function __invoke(UploadFileRequest $request, Server $server)
|
||||
public function __invoke(UploadFileRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
return new JsonResponse([
|
||||
'object' => 'signed_url',
|
||||
|
@ -45,10 +39,8 @@ class FileUploadController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Returns a url where files can be uploaded to.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getUploadUrl(Server $server, User $user)
|
||||
protected function getUploadUrl(Server $server, User $user): string
|
||||
{
|
||||
$token = $this->jwtService
|
||||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
|
@ -19,20 +19,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationReq
|
|||
|
||||
class NetworkAllocationController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Allocations\FindAssignableAllocationService
|
||||
*/
|
||||
private $assignableAllocationService;
|
||||
private AllocationRepository $repository;
|
||||
private ServerRepository $serverRepository;
|
||||
private FindAssignableAllocationService $assignableAllocationService;
|
||||
|
||||
/**
|
||||
* NetworkController constructor.
|
||||
|
@ -50,8 +39,10 @@ class NetworkAllocationController extends ClientApiController
|
|||
}
|
||||
|
||||
/**
|
||||
* Lists all of the allocations available to a server and wether or
|
||||
* Lists all of the allocations available to a server and whether or
|
||||
* not they are currently assigned as the primary for this server.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetNetworkRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -65,6 +56,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(UpdateAllocationRequest $request, Server $server, Allocation $allocation): array
|
||||
{
|
||||
|
@ -82,6 +74,7 @@ class NetworkAllocationController extends ClientApiController
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function setPrimary(SetPrimaryAllocationRequest $request, Server $server, Allocation $allocation): array
|
||||
{
|
||||
|
@ -94,9 +87,9 @@ class NetworkAllocationController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Set the notes for the allocation for a server.
|
||||
*s.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function store(NewAllocationRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -114,11 +107,9 @@ class NetworkAllocationController extends ClientApiController
|
|||
/**
|
||||
* Delete an allocation from a server.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function delete(DeleteAllocationRequest $request, Server $server, Allocation $allocation)
|
||||
public function delete(DeleteAllocationRequest $request, Server $server, Allocation $allocation): Response
|
||||
{
|
||||
if ($allocation->id === $server->allocation_id) {
|
||||
throw new DisplayException('You cannot delete the primary allocation for this server.');
|
||||
|
@ -129,6 +120,6 @@ class NetworkAllocationController extends ClientApiController
|
|||
'server_id' => null,
|
||||
]);
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest;
|
|||
|
||||
class PowerController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonPowerRepository
|
||||
*/
|
||||
private $repository;
|
||||
private DaemonPowerRepository $repository;
|
||||
|
||||
/**
|
||||
* PowerController constructor.
|
||||
|
|
|
@ -10,10 +10,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|||
|
||||
class ResourceUtilizationController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
private DaemonServerRepository $repository;
|
||||
|
||||
/**
|
||||
* ResourceUtilizationController constructor.
|
||||
|
@ -29,6 +26,7 @@ class ResourceUtilizationController extends ClientApiController
|
|||
* Return the current resource utilization for a server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function __invoke(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
|
|
|
@ -8,7 +8,6 @@ use Illuminate\Http\Request;
|
|||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Helpers\Utilities;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
||||
|
@ -25,15 +24,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\TriggerScheduleReques
|
|||
|
||||
class ScheduleController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ScheduleRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\ProcessScheduleService
|
||||
*/
|
||||
private $service;
|
||||
private ScheduleRepository $repository;
|
||||
private ProcessScheduleService $service;
|
||||
|
||||
/**
|
||||
* ScheduleController constructor.
|
||||
|
@ -49,9 +41,9 @@ class ScheduleController extends ClientApiController
|
|||
/**
|
||||
* Returns all of the schedules belonging to a given server.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(ViewScheduleRequest $request, Server $server)
|
||||
public function index(ViewScheduleRequest $request, Server $server): array
|
||||
{
|
||||
$schedules = $server->schedule;
|
||||
$schedules->loadMissing('tasks');
|
||||
|
@ -64,12 +56,11 @@ class ScheduleController extends ClientApiController
|
|||
/**
|
||||
* Store a new schedule for a server.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function store(StoreScheduleRequest $request, Server $server)
|
||||
public function store(StoreScheduleRequest $request, Server $server): array
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Schedule $model */
|
||||
$model = $this->repository->create([
|
||||
|
@ -92,9 +83,9 @@ class ScheduleController extends ClientApiController
|
|||
/**
|
||||
* Returns a specific schedule for the server.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(ViewScheduleRequest $request, Server $server, Schedule $schedule)
|
||||
public function view(ViewScheduleRequest $request, Server $server, Schedule $schedule): array
|
||||
{
|
||||
if ($schedule->server_id !== $server->id) {
|
||||
throw new NotFoundHttpException();
|
||||
|
@ -110,13 +101,12 @@ class ScheduleController extends ClientApiController
|
|||
/**
|
||||
* Updates a given schedule with the new data provided.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule)
|
||||
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule): array
|
||||
{
|
||||
$active = (bool) $request->input('is_active');
|
||||
|
||||
|
@ -150,31 +140,27 @@ class ScheduleController extends ClientApiController
|
|||
* Executes a given schedule immediately rather than waiting on it's normally scheduled time
|
||||
* to pass. This does not care about the schedule state.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule)
|
||||
public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule): Response
|
||||
{
|
||||
if (!$schedule->is_active) {
|
||||
throw new BadRequestHttpException('Cannot trigger schedule exection for a schedule that is not currently active.');
|
||||
throw new BadRequestHttpException('Cannot trigger schedule exception for a schedule that is not currently active.');
|
||||
}
|
||||
|
||||
$this->service->handle($schedule, true);
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_ACCEPTED);
|
||||
return $this->returnAccepted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a schedule and it's associated tasks.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule)
|
||||
public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule): Response
|
||||
{
|
||||
$this->repository->delete($schedule->id);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,6 @@ use Pterodactyl\Models\Task;
|
|||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
||||
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||
|
@ -19,10 +18,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\StoreTaskRequest;
|
|||
|
||||
class ScheduleTaskController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\TaskRepository
|
||||
*/
|
||||
private $repository;
|
||||
private TaskRepository $repository;
|
||||
|
||||
/**
|
||||
* ScheduleTaskController constructor.
|
||||
|
@ -37,12 +33,11 @@ class ScheduleTaskController extends ClientApiController
|
|||
/**
|
||||
* Create a new task for a given schedule and store it in the database.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceLimitExceededException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function store(StoreTaskRequest $request, Server $server, Schedule $schedule)
|
||||
public function store(StoreTaskRequest $request, Server $server, Schedule $schedule): array
|
||||
{
|
||||
$limit = config('pterodactyl.client_features.schedules.per_schedule_task_limit', 10);
|
||||
if ($schedule->tasks()->count() >= $limit) {
|
||||
|
@ -69,12 +64,11 @@ class ScheduleTaskController extends ClientApiController
|
|||
/**
|
||||
* Updates a given task for a server.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(StoreTaskRequest $request, Server $server, Schedule $schedule, Task $task)
|
||||
public function update(StoreTaskRequest $request, Server $server, Schedule $schedule, Task $task): array
|
||||
{
|
||||
if ($schedule->id !== $task->schedule_id || $server->id !== $schedule->server_id) {
|
||||
throw new NotFoundHttpException();
|
||||
|
@ -95,11 +89,9 @@ class ScheduleTaskController extends ClientApiController
|
|||
* Delete a given task for a schedule. If there are subsequent tasks stored in the database
|
||||
* for this schedule their sequence IDs are decremented properly.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(ClientApiRequest $request, Server $server, Schedule $schedule, Task $task)
|
||||
public function delete(ClientApiRequest $request, Server $server, Schedule $schedule, Task $task): Response
|
||||
{
|
||||
if ($task->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) {
|
||||
throw new NotFoundHttpException();
|
||||
|
@ -115,6 +107,6 @@ class ScheduleTaskController extends ClientApiController
|
|||
|
||||
$task->delete();
|
||||
|
||||
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,15 +11,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|||
|
||||
class ServerController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
|
||||
*/
|
||||
private $permissionsService;
|
||||
private SubuserRepository $repository;
|
||||
private GetUserPermissionsService $permissionsService;
|
||||
|
||||
/**
|
||||
* ServerController constructor.
|
||||
|
@ -35,6 +28,8 @@ class ServerController extends ClientApiController
|
|||
/**
|
||||
* Transform an individual server into a response that can be consumed by a
|
||||
* client using the API.
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|||
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
|
@ -15,15 +14,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest
|
|||
|
||||
class SettingsController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
||||
*/
|
||||
private $reinstallServerService;
|
||||
private ServerRepository $repository;
|
||||
private ReinstallServerService $reinstallServerService;
|
||||
|
||||
/**
|
||||
* SettingsController constructor.
|
||||
|
@ -41,42 +33,36 @@ class SettingsController extends ClientApiController
|
|||
/**
|
||||
* Renames a server.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function rename(RenameServerRequest $request, Server $server)
|
||||
public function rename(RenameServerRequest $request, Server $server): Response
|
||||
{
|
||||
$this->repository->update($server->id, [
|
||||
'name' => $request->input('name'),
|
||||
]);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinstalls the server on the daemon.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function reinstall(ReinstallServerRequest $request, Server $server)
|
||||
public function reinstall(ReinstallServerRequest $request, Server $server): Response
|
||||
{
|
||||
$this->reinstallServerService->handle($server);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_ACCEPTED);
|
||||
return $this->returnAccepted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the Docker image in use by the server.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function dockerImage(SetDockerImageRequest $request, Server $server)
|
||||
public function dockerImage(SetDockerImageRequest $request, Server $server): Response
|
||||
{
|
||||
if (!in_array($server->image, $server->egg->docker_images)) {
|
||||
throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.');
|
||||
|
@ -84,6 +70,6 @@ class SettingsController extends ClientApiController
|
|||
|
||||
$server->forceFill(['image' => $request->input('docker_image')])->saveOrFail();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,20 +14,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRe
|
|||
|
||||
class StartupController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\VariableValidatorService
|
||||
*/
|
||||
private $service;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerVariableRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\StartupCommandService
|
||||
*/
|
||||
private $startupCommandService;
|
||||
private VariableValidatorService $service;
|
||||
private ServerVariableRepository $repository;
|
||||
private StartupCommandService $startupCommandService;
|
||||
|
||||
/**
|
||||
* StartupController constructor.
|
||||
|
@ -44,9 +33,9 @@ class StartupController extends ClientApiController
|
|||
/**
|
||||
* Returns the startup information for the server including all of the variables.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetStartupRequest $request, Server $server)
|
||||
public function index(GetStartupRequest $request, Server $server): array
|
||||
{
|
||||
$startup = $this->startupCommandService->handle($server, false);
|
||||
|
||||
|
@ -65,13 +54,12 @@ class StartupController extends ClientApiController
|
|||
/**
|
||||
* Updates a single variable for a server.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(UpdateStartupVariableRequest $request, Server $server)
|
||||
public function update(UpdateStartupVariableRequest $request, Server $server): array
|
||||
{
|
||||
/** @var \Pterodactyl\Models\EggVariable $variable */
|
||||
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
||||
|
@ -20,20 +20,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Subusers\UpdateSubuserRequest;
|
|||
|
||||
class SubuserController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Subusers\SubuserCreationService
|
||||
*/
|
||||
private $creationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $serverRepository;
|
||||
private SubuserRepository $repository;
|
||||
private SubuserCreationService $creationService;
|
||||
private DaemonServerRepository $serverRepository;
|
||||
|
||||
/**
|
||||
* SubuserController constructor.
|
||||
|
@ -53,9 +42,9 @@ class SubuserController extends ClientApiController
|
|||
/**
|
||||
* Return the users associated with this server instance.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function index(GetSubuserRequest $request, Server $server)
|
||||
public function index(GetSubuserRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->collection($server->subusers)
|
||||
->transformWith($this->getTransformer(SubuserTransformer::class))
|
||||
|
@ -65,9 +54,9 @@ class SubuserController extends ClientApiController
|
|||
/**
|
||||
* Returns a single subuser associated with this server instance.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function view(GetSubuserRequest $request)
|
||||
public function view(GetSubuserRequest $request): array
|
||||
{
|
||||
$subuser = $request->attributes->get('subuser');
|
||||
|
||||
|
@ -79,14 +68,12 @@ class SubuserController extends ClientApiController
|
|||
/**
|
||||
* Create a new subuser for the given server.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function store(StoreSubuserRequest $request, Server $server)
|
||||
public function store(StoreSubuserRequest $request, Server $server): array
|
||||
{
|
||||
$response = $this->creationService->handle(
|
||||
$server,
|
||||
|
@ -104,6 +91,7 @@ class SubuserController extends ClientApiController
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function update(UpdateSubuserRequest $request, Server $server): array
|
||||
{
|
||||
|
@ -139,10 +127,8 @@ class SubuserController extends ClientApiController
|
|||
|
||||
/**
|
||||
* Removes a subusers from a server's assignment.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(DeleteSubuserRequest $request, Server $server)
|
||||
public function delete(DeleteSubuserRequest $request, Server $server): Response
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Subuser $subuser */
|
||||
$subuser = $request->attributes->get('subuser');
|
||||
|
@ -156,7 +142,7 @@ class SubuserController extends ClientApiController
|
|||
Log::warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]);
|
||||
}
|
||||
|
||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,15 +14,8 @@ use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|||
|
||||
class WebsocketController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Nodes\NodeJWTService
|
||||
*/
|
||||
private $jwtService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
|
||||
*/
|
||||
private $permissionsService;
|
||||
private NodeJWTService $jwtService;
|
||||
private GetUserPermissionsService $permissionsService;
|
||||
|
||||
/**
|
||||
* WebsocketController constructor.
|
||||
|
@ -40,12 +33,10 @@ class WebsocketController extends ClientApiController
|
|||
/**
|
||||
* Generates a one-time token that is sent along in every websocket call to the Daemon.
|
||||
* This is a signed JWT that the Daemon then uses the verify the user's identity, and
|
||||
* allows us to continually renew this token and avoid users mainitaining sessions wrongly,
|
||||
* allows us to continually renew this token and avoid users maintaining sessions wrongly,
|
||||
* as well as ensure that user's only perform actions they're allowed to.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function __invoke(ClientApiRequest $request, Server $server)
|
||||
public function __invoke(ClientApiRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {
|
||||
|
|
|
@ -14,20 +14,9 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|||
|
||||
class TwoFactorController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Users\TwoFactorSetupService
|
||||
*/
|
||||
private $setupService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Validation\Factory
|
||||
*/
|
||||
private $validation;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Users\ToggleTwoFactorService
|
||||
*/
|
||||
private $toggleTwoFactorService;
|
||||
private ToggleTwoFactorService $toggleTwoFactorService;
|
||||
private TwoFactorSetupService $setupService;
|
||||
private Factory $validation;
|
||||
|
||||
/**
|
||||
* TwoFactorController constructor.
|
||||
|
@ -39,9 +28,9 @@ class TwoFactorController extends ClientApiController
|
|||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->toggleTwoFactorService = $toggleTwoFactorService;
|
||||
$this->setupService = $setupService;
|
||||
$this->validation = $validation;
|
||||
$this->toggleTwoFactorService = $toggleTwoFactorService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,12 +38,10 @@ class TwoFactorController extends ClientApiController
|
|||
* it on their account. If two-factor is already enabled this endpoint
|
||||
* will return a 400 error.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
if ($request->user()->use_totp) {
|
||||
throw new BadRequestHttpException('Two-factor authentication is already enabled on this account.');
|
||||
|
@ -70,17 +57,9 @@ class TwoFactorController extends ClientApiController
|
|||
/**
|
||||
* Updates a user's account to have two-factor enabled.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validator = $this->validation->make($request->all(), [
|
||||
'code' => 'required|string',
|
||||
|
@ -103,10 +82,8 @@ class TwoFactorController extends ClientApiController
|
|||
/**
|
||||
* Disables two-factor authentication on an account if the password provided
|
||||
* is valid.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
public function delete(Request $request): JsonResponse
|
||||
{
|
||||
if (!password_verify($request->input('password') ?? '', $request->user()->password)) {
|
||||
throw new BadRequestHttpException('The password provided was not valid.');
|
||||
|
@ -120,6 +97,6 @@ class TwoFactorController extends ClientApiController
|
|||
'use_totp' => false,
|
||||
]);
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue