Add /api/client/servers/{server}/files/chmod endpoint

This commit is contained in:
Matthew Penner 2020-11-29 13:49:29 -07:00
parent 77abfd01ec
commit 8611ebb2d6
4 changed files with 80 additions and 0 deletions

View file

@ -16,6 +16,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ChmodFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CreateFolderRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CompressFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DecompressFilesRequest;
@ -263,6 +264,25 @@ class FileController extends ClientApiController
return new JsonResponse([], Response::HTTP_NO_CONTENT);
}
/**
* Updates file permissions for file(s) in the given root directory.
*
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\ChmodFilesRequest $request
* @param \Pterodactyl\Models\Server $server
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function chmod(ChmodFilesRequest $request, Server $server): JsonResponse
{
$this->fileRepository->setServer($server)
->chmodFiles(
$request->input('root'), $request->input('files')
);
return new JsonResponse([], Response::HTTP_NO_CONTENT);
}
/**
* Encodes a given file name & path in a format that should work for a good majority
* of file names without too much confusing logic.

View file

@ -0,0 +1,31 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Files;
use Pterodactyl\Models\Permission;
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
class ChmodFilesRequest extends ClientApiRequest implements ClientPermissionsRequest
{
/**
* @return string
*/
public function permission(): string
{
return Permission::ACTION_FILE_UPDATE;
}
/**
* @return array
*/
public function rules(): array
{
return [
'root' => 'required|nullable|string',
'files' => 'required|array',
'files.file' => 'string',
'files.mode' => 'integer',
];
}
}

View file

@ -269,4 +269,32 @@ class DaemonFileRepository extends DaemonRepository
throw new DaemonConnectionException($exception);
}
}
/**
* Chmods the given files.
*
* @param string|null $root
* @param array $files
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function chmodFiles(?string $root, array $files): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/files/chmod', $this->server->uuid),
[
'json' => [
'root' => $root ?? '/',
'files' => $files,
],
]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}

View file

@ -64,6 +64,7 @@ Route::group(['prefix' => '/servers/{server}', 'middleware' => [AuthenticateServ
Route::post('/decompress', 'Servers\FileController@decompress');
Route::post('/delete', 'Servers\FileController@delete');
Route::post('/create-folder', 'Servers\FileController@create');
Route::post('/chmod', 'Servers\FileController@chmod');
Route::get('/upload', 'Servers\FileUploadController');
});