Pass along new fields to Wings instance when endpoint is used; closes #4048

This commit is contained in:
DaneEveritt 2022-05-28 13:45:23 -04:00
parent 3fceb588fb
commit c14c7b436e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 57 additions and 33 deletions

View file

@ -97,17 +97,20 @@ class FileController extends ClientApiController
*/ */
public function download(GetFileContentsRequest $request, Server $server) public function download(GetFileContentsRequest $request, Server $server)
{ {
$token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) { $token = $server->audit(
$audit->metadata = ['file' => $request->get('file')]; AuditLog::SERVER__FILESYSTEM_DOWNLOAD,
function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['file' => $request->get('file')];
return $this->jwtService return $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)) ->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setClaims([ ->setClaims([
'file_path' => rawurldecode($request->get('file')), 'file_path' => rawurldecode($request->get('file')),
'server_uuid' => $server->uuid, 'server_uuid' => $server->uuid,
]) ])
->handle($server->node, $request->user()->id . $server->uuid); ->handle($server->node, $request->user()->id . $server->uuid);
}); }
);
return [ return [
'object' => 'signed_url', 'object' => 'signed_url',
@ -201,18 +204,21 @@ class FileController extends ClientApiController
*/ */
public function compress(CompressFilesRequest $request, Server $server): array public function compress(CompressFilesRequest $request, Server $server): array
{ {
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_COMPRESS, function (AuditLog $audit, Server $server) use ($request) { $file = $server->audit(
// Allow up to five minutes for this request to process before timing out. AuditLog::SERVER__FILESYSTEM_COMPRESS,
set_time_limit(300); function (AuditLog $audit, Server $server) use ($request) {
// Allow up to five minutes for this request to process before timing out.
set_time_limit(300);
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')]; $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
return $this->fileRepository->setServer($server) return $this->fileRepository->setServer($server)
->compressFiles( ->compressFiles(
$request->input('root'), $request->input('root'),
$request->input('files') $request->input('files')
); );
}); }
);
return $this->fractal->item($file) return $this->fractal->item($file)
->transformWith($this->getTransformer(FileObjectTransformer::class)) ->transformWith($this->getTransformer(FileObjectTransformer::class))
@ -224,15 +230,18 @@ class FileController extends ClientApiController
*/ */
public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse
{ {
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) { $file = $server->audit(
// Allow up to five minutes for this request to process before timing out. AuditLog::SERVER__FILESYSTEM_DECOMPRESS,
set_time_limit(300); function (AuditLog $audit, Server $server) use ($request) {
// Allow up to five minutes for this request to process before timing out.
set_time_limit(300);
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('file')]; $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('file')];
$this->fileRepository->setServer($server) $this->fileRepository->setServer($server)
->decompressFile($request->input('root'), $request->input('file')); ->decompressFile($request->input('root'), $request->input('file'));
}); }
);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
} }
@ -276,8 +285,6 @@ class FileController extends ClientApiController
/** /**
* Requests that a file be downloaded from a remote location by Wings. * Requests that a file be downloaded from a remote location by Wings.
* *
* @param $request
*
* @throws \Throwable * @throws \Throwable
*/ */
public function pull(PullFileRequest $request, Server $server): JsonResponse public function pull(PullFileRequest $request, Server $server): JsonResponse
@ -285,7 +292,13 @@ class FileController extends ClientApiController
$server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')]; $audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')];
$this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory')); $this->fileRepository
->setServer($server)
->pull(
$request->input('url'),
$request->input('directory'),
$request->safe(['filename', 'use_header', 'foreground'])
);
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new JsonResponse([], Response::HTTP_NO_CONTENT);

View file

@ -20,7 +20,10 @@ class PullFileRequest extends ClientApiRequest implements ClientPermissionsReque
{ {
return [ return [
'url' => 'required|string|url', 'url' => 'required|string|url',
'directory' => 'sometimes|nullable|string', 'directory' => 'nullable|string',
'filename' => 'nullable|string',
'use_header' => 'boolean',
'foreground' => 'boolean',
]; ];
} }
} }

View file

@ -267,15 +267,23 @@ class DaemonFileRepository extends DaemonRepository
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function pull(string $url, ?string $directory): ResponseInterface public function pull(string $url, ?string $directory, array $params = []): ResponseInterface
{ {
Assert::isInstanceOf($this->server, Server::class); Assert::isInstanceOf($this->server, Server::class);
$attributes = [
'url' => $url,
'root' => $directory ?? '/',
'file_name' => $params['filename'] ?? null,
'use_header' => $params['use_header'] ?? null,
'foreground' => $params['foreground'] ?? null,
];
try { try {
return $this->getHttpClient()->post( return $this->getHttpClient()->post(
sprintf('/api/servers/%s/files/pull', $this->server->uuid), sprintf('/api/servers/%s/files/pull', $this->server->uuid),
[ [
'json' => ['url' => $url, 'directory' => $directory ?? '/'], 'json' => array_filter($attributes, fn ($value) => !is_null($value)),
] ]
); );
} catch (TransferException $exception) { } catch (TransferException $exception) {