Merge branch 'develop' of https://github.com/Pterodactyl/Panel into develop

This commit is contained in:
Dane Everitt 2020-12-06 12:01:43 -08:00
commit af360d49dd
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
19 changed files with 287 additions and 58 deletions

View file

@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
This project follows [Semantic Versioning](http://semver.org) guidelines. This project follows [Semantic Versioning](http://semver.org) guidelines.
## Unreleased
### Fixed
* Fixes the application API unable to return server's variables.
## v1.1.3 ## v1.1.3
### Fixed ### Fixed
* Server bulk power actions command will no longer attempt to run commands against installing or suspended servers. * Server bulk power actions command will no longer attempt to run commands against installing or suspended servers.

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\ListFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest; 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\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\CreateFolderRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CompressFilesRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CompressFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DecompressFilesRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DecompressFilesRequest;
@ -263,6 +264,25 @@ class FileController extends ClientApiController
return new JsonResponse([], Response::HTTP_NO_CONTENT); 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 * Encodes a given file name & path in a format that should work for a good majority
* of file names without too much confusing logic. * 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' => 'required|string',
'files.*.mode' => 'required|numeric',
];
}
}

View file

@ -269,4 +269,32 @@ class DaemonFileRepository extends DaemonRepository
throw new DaemonConnectionException($exception); 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

@ -2,7 +2,7 @@
namespace Pterodactyl\Transformers\Api\Application; namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\ServerVariable; use Pterodactyl\Models\EggVariable;
use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Services\Acl\Api\AdminAcl;
class ServerVariableTransformer extends BaseTransformer class ServerVariableTransformer extends BaseTransformer
@ -27,10 +27,10 @@ class ServerVariableTransformer extends BaseTransformer
/** /**
* Return a generic transformed server variable array. * Return a generic transformed server variable array.
* *
* @param \Pterodactyl\Models\ServerVariable $variable * @param \Pterodactyl\Models\EggVariable $variable
* @return array * @return array
*/ */
public function transform(ServerVariable $variable) public function transform(EggVariable $variable)
{ {
return $variable->toArray(); return $variable->toArray();
} }
@ -38,11 +38,11 @@ class ServerVariableTransformer extends BaseTransformer
/** /**
* Return the parent service variable data. * Return the parent service variable data.
* *
* @param \Pterodactyl\Models\ServerVariable $variable * @param \Pterodactyl\Models\EggVariable $variable
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/ */
public function includeParent(ServerVariable $variable) public function includeParent(EggVariable $variable)
{ {
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) { if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null(); return $this->null();

View file

@ -25,6 +25,7 @@ class FileObjectTransformer extends BaseDaemonTransformer
return [ return [
'name' => Arr::get($item, 'name'), 'name' => Arr::get($item, 'name'),
'mode' => Arr::get($item, 'mode'), 'mode' => Arr::get($item, 'mode'),
'mode_bits' => Arr::get($item, 'mode_bits'),
'size' => Arr::get($item, 'size'), 'size' => Arr::get($item, 'size'),
'is_file' => Arr::get($item, 'file', true), 'is_file' => Arr::get($item, 'file', true),
'is_symlink' => Arr::get($item, 'symlink', false), 'is_symlink' => Arr::get($item, 'symlink', false),

View file

@ -0,0 +1,14 @@
import http from '@/api/http';
interface Data {
file: string;
mode: string;
}
export default (uuid: string, directory: string, files: Data[]): Promise<void> => {
return new Promise((resolve, reject) => {
http.post(`/api/client/servers/${uuid}/files/chmod`, { root: directory, files })
.then(() => resolve())
.catch(reject);
});
};

View file

@ -5,6 +5,7 @@ export interface FileObject {
key: string; key: string;
name: string; name: string;
mode: string; mode: string;
modeBits: string,
size: number; size: number;
isFile: boolean; isFile: boolean;
isSymlink: boolean; isSymlink: boolean;

View file

@ -16,6 +16,7 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
key: `${data.attributes.is_file ? 'file' : 'dir'}_${data.attributes.name}`, key: `${data.attributes.is_file ? 'file' : 'dir'}_${data.attributes.name}`,
name: data.attributes.name, name: data.attributes.name,
mode: data.attributes.mode, mode: data.attributes.mode,
modeBits: data.attributes.mode_bits,
size: Number(data.attributes.size), size: Number(data.attributes.size),
isFile: data.attributes.is_file, isFile: data.attributes.is_file,
isSymlink: data.attributes.is_symlink, isSymlink: data.attributes.is_symlink,

View file

@ -17,11 +17,12 @@ const SubNavigation = styled.div`
${tw`ml-2`}; ${tw`ml-2`};
} }
&:active, &:hover { &:hover {
${tw`text-neutral-100`}; ${tw`text-neutral-100`};
} }
&:active, &:hover, &.active { &:active, &.active {
${tw`text-neutral-100`};
box-shadow: inset 0 -2px ${config.theme.colors.cyan['500']}; box-shadow: inset 0 -2px ${config.theme.colors.cyan['500']};
} }
} }

View file

@ -0,0 +1,75 @@
import { fileBitsToString } from '@/helpers';
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
import React from 'react';
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
import { Form, Formik, FormikHelpers } from 'formik';
import Field from '@/components/elements/Field';
import chmodFiles from '@/api/server/files/chmodFiles';
import { ServerContext } from '@/state/server';
import tw from 'twin.macro';
import Button from '@/components/elements/Button';
import useFlash from '@/plugins/useFlash';
interface FormikValues {
mode: string;
}
interface File {
file: string,
mode: string,
}
type OwnProps = RequiredModalProps & { files: File[] };
const ChmodFileModal = ({ files, ...props }: OwnProps) => {
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const { mutate } = useFileManagerSwr();
const { clearFlashes, clearAndAddHttpError } = useFlash();
const directory = ServerContext.useStoreState(state => state.files.directory);
const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles);
const submit = ({ mode }: FormikValues, { setSubmitting }: FormikHelpers<FormikValues>) => {
clearFlashes('files');
mutate(data => data.map(f => f.name === files[0].file ? { ...f, mode: fileBitsToString(mode, !f.isFile), modeBits: mode } : f), false);
const data = files.map(f => ({ file: f.file, mode: mode }));
chmodFiles(uuid, directory, data)
.then((): Promise<any> => files.length > 0 ? mutate() : Promise.resolve())
.then(() => setSelectedFiles([]))
.catch(error => {
mutate();
setSubmitting(false);
clearAndAddHttpError({ key: 'files', error });
})
.then(() => props.onDismissed());
};
return (
<Formik onSubmit={submit} initialValues={{ mode: files.length > 1 ? '' : (files[0].mode || '') }}>
{({ isSubmitting }) => (
<Modal {...props} dismissable={!isSubmitting} showSpinnerOverlay={isSubmitting}>
<Form css={tw`m-0`}>
<div css={tw`flex flex-wrap items-end`}>
<div css={tw`w-full sm:flex-1 sm:mr-4`}>
<Field
type={'string'}
id={'file_mode'}
name={'mode'}
label={'File Mode'}
autoFocus
/>
</div>
<div css={tw`w-full sm:w-auto mt-4 sm:mt-0`}>
<Button css={tw`w-full`}>Update</Button>
</div>
</div>
</Form>
</Modal>
)}
</Formik>
);
};
export default ChmodFileModal;

View file

@ -5,6 +5,7 @@ import {
faCopy, faCopy,
faEllipsisH, faEllipsisH,
faFileArchive, faFileArchive,
faFileCode,
faFileDownload, faFileDownload,
faLevelUpAlt, faLevelUpAlt,
faPencilAlt, faPencilAlt,
@ -30,8 +31,9 @@ import compressFiles from '@/api/server/files/compressFiles';
import decompressFiles from '@/api/server/files/decompressFiles'; import decompressFiles from '@/api/server/files/decompressFiles';
import isEqual from 'react-fast-compare'; import isEqual from 'react-fast-compare';
import ConfirmationModal from '@/components/elements/ConfirmationModal'; import ConfirmationModal from '@/components/elements/ConfirmationModal';
import ChmodFileModal from '@/components/server/files/ChmodFileModal';
type ModalType = 'rename' | 'move'; type ModalType = 'rename' | 'move' | 'chmod';
const StyledRow = styled.div<{ $danger?: boolean }>` const StyledRow = styled.div<{ $danger?: boolean }>`
${tw`p-2 flex items-center rounded`}; ${tw`p-2 flex items-center rounded`};
@ -140,7 +142,15 @@ const FileDropdownMenu = ({ file }: { file: FileObject }) => {
renderToggle={onClick => ( renderToggle={onClick => (
<div css={tw`p-3 hover:text-white`} onClick={onClick}> <div css={tw`p-3 hover:text-white`} onClick={onClick}>
<FontAwesomeIcon icon={faEllipsisH}/> <FontAwesomeIcon icon={faEllipsisH}/>
{!!modal && {modal ?
modal === 'chmod' ?
<ChmodFileModal
visible
appear
files={[ { file: file.name, mode: file.modeBits } ]}
onDismissed={() => setModal(null)}
/>
:
<RenameFileModal <RenameFileModal
visible visible
appear appear
@ -148,6 +158,7 @@ const FileDropdownMenu = ({ file }: { file: FileObject }) => {
useMoveTerminology={modal === 'move'} useMoveTerminology={modal === 'move'}
onDismissed={() => setModal(null)} onDismissed={() => setModal(null)}
/> />
: null
} }
<SpinnerOverlay visible={showSpinner} fixed size={'large'}/> <SpinnerOverlay visible={showSpinner} fixed size={'large'}/>
</div> </div>
@ -156,6 +167,7 @@ const FileDropdownMenu = ({ file }: { file: FileObject }) => {
<Can action={'file.update'}> <Can action={'file.update'}>
<Row onClick={() => setModal('rename')} icon={faPencilAlt} title={'Rename'}/> <Row onClick={() => setModal('rename')} icon={faPencilAlt} title={'Rename'}/>
<Row onClick={() => setModal('move')} icon={faLevelUpAlt} title={'Move'}/> <Row onClick={() => setModal('move')} icon={faLevelUpAlt} title={'Move'}/>
<Row onClick={() => setModal('chmod')} icon={faFileCode} title={'Permissions'}/>
</Can> </Can>
{file.isFile && {file.isFile &&
<Can action={'file.create'}> <Can action={'file.create'}>

View file

@ -44,7 +44,7 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
}; };
return ( return (
<div css={tw`flex items-center text-sm mb-4 text-neutral-500`}> <div css={tw`flex flex-grow-0 items-center text-sm text-neutral-500 overflow-x-hidden`}>
{(files && files.length > 0 && !params?.action) ? {(files && files.length > 0 && !params?.action) ?
<FileActionCheckbox <FileActionCheckbox
type={'checkbox'} type={'checkbox'}

View file

@ -51,9 +51,28 @@ export default () => {
return ( return (
<ServerContentBlock title={'File Manager'} showFlashKey={'files'}> <ServerContentBlock title={'File Manager'} showFlashKey={'files'}>
<div css={tw`flex flex-wrap-reverse md:flex-no-wrap justify-center mb-4`}>
<ErrorBoundary> <ErrorBoundary>
<FileManagerBreadcrumbs/> <FileManagerBreadcrumbs/>
</ErrorBoundary> </ErrorBoundary>
<Can action={'file.create'}>
<ErrorBoundary>
<div css={tw`flex flex-shrink-0 flex-wrap-reverse md:flex-no-wrap justify-end mb-4 md:mb-0 ml-0 md:ml-auto`}>
<NewDirectoryButton css={tw`w-full flex-none mt-4 sm:mt-0 sm:w-auto sm:mr-4`}/>
<UploadButton css={tw`flex-1 mr-4 sm:flex-none sm:mt-0`}/>
<NavLink
to={`/server/${id}/files/new${window.location.hash}`}
css={tw`flex-1 sm:flex-none sm:mt-0`}
>
<Button css={tw`w-full`}>
New File
</Button>
</NavLink>
</div>
</ErrorBoundary>
</Can>
</div>
{ {
!files ? !files ?
<Spinner size={'large'} centered/> <Spinner size={'large'} centered/>
@ -83,22 +102,6 @@ export default () => {
</div> </div>
</CSSTransition> </CSSTransition>
} }
<Can action={'file.create'}>
<ErrorBoundary>
<div css={tw`flex flex-wrap-reverse justify-end mt-4`}>
<NewDirectoryButton css={tw`w-full flex-none mt-4 sm:mt-0 sm:w-auto sm:mr-4`}/>
<UploadButton css={tw`flex-1 mr-4 sm:flex-none sm:mt-0`}/>
<NavLink
to={`/server/${id}/files/new${window.location.hash}`}
css={tw`flex-1 sm:flex-none sm:mt-0`}
>
<Button css={tw`w-full`}>
New File
</Button>
</NavLink>
</div>
</ErrorBoundary>
</Can>
</> </>
} }
</ServerContentBlock> </ServerContentBlock>

View file

@ -64,7 +64,11 @@ const FileObjectRow = ({ file }: { file: FileObject }) => (
> >
<SelectFileCheckbox name={file.name}/> <SelectFileCheckbox name={file.name}/>
<Clickable file={file}> <Clickable file={file}>
<div css={tw`flex-none self-center text-neutral-400 mr-4 text-lg pl-3 ml-6`}> <div css={tw`w-24 ml-6 pl-3 hidden md:block`}>
{file.mode}
</div>
<div css={tw`flex-none self-center text-neutral-400 ml-6 md:ml-0 mr-4 text-lg pl-3`}>
{file.isFile ? {file.isFile ?
<FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/> <FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/>
: :

View file

@ -25,7 +25,8 @@ const schema = object().shape({
const generateDirectoryData = (name: string): FileObject => ({ const generateDirectoryData = (name: string): FileObject => ({
key: `dir_${name.split('/', 1)[0] ?? name}`, key: `dir_${name.split('/', 1)[0] ?? name}`,
name: name.replace(/^(\/*)/, '').split('/', 1)[0] ?? name, name: name.replace(/^(\/*)/, '').split('/', 1)[0] ?? name,
mode: '0644', mode: 'drwxr-xr-x',
modeBits: '0755',
size: 0, size: 0,
isFile: false, isFile: false,
isSymlink: false, isSymlink: false,

View file

@ -48,21 +48,23 @@ export default ({ subuser }: Props) => {
</p> </p>
<p css={tw`text-2xs text-neutral-500 uppercase`}>Permissions</p> <p css={tw`text-2xs text-neutral-500 uppercase`}>Permissions</p>
</div> </div>
<Can action={'user.update'}>
{subuser.uuid !== uuid && {subuser.uuid !== uuid &&
<>
<Can action={'user.update'}>
<button <button
type={'button'} type={'button'}
aria-label={'Edit subuser'} aria-label={'Edit subuser'}
css={tw`block text-sm p-1 md:p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mx-4`} css={tw`block text-sm p-1 md:p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mx-4`}
onClick={() => setVisible(true)} onClick={() => setVisible(true)}
> >
<FontAwesomeIcon icon={faPencilAlt}/> <FontAwesomeIcon icon={faPencilAlt} />
</button> </button>
}
</Can> </Can>
<Can action={'user.delete'}> <Can action={'user.delete'}>
<RemoveSubuserButton subuser={subuser}/> <RemoveSubuserButton subuser={subuser} />
</Can> </Can>
</>
}
</GreyRowBox> </GreyRowBox>
); );
}; };

View file

@ -20,3 +20,33 @@ export const randomInt = (low: number, high: number) => Math.floor(Math.random()
export const cleanDirectoryPath = (path: string) => path.replace(/(^#\/*)|(\/(\/*))|(^$)/g, '/'); export const cleanDirectoryPath = (path: string) => path.replace(/(^#\/*)|(\/(\/*))|(^$)/g, '/');
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(); export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
export function fileBitsToString (mode: string, directory: boolean): string {
const m = parseInt(mode, 8);
let buf = '';
'dalTLDpSugct?'.split('').forEach((c, i) => {
if ((m & (1 << (32 - 1 - i))) !== 0) {
buf = buf + c;
}
});
if (buf.length === 0) {
// If the file is directory, make sure it has the directory flag.
if (directory) {
buf = 'd';
} else {
buf = '-';
}
}
'rwxrwxrwx'.split('').forEach((c, i) => {
if ((m & (1 << (9 - 1 - i))) !== 0) {
buf = buf + c;
} else {
buf = buf + '-';
}
});
return buf;
}

View file

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