Don't allow opening of files we know cannot be edited; closes #2286
This commit is contained in:
parent
906cfce81c
commit
d87438621f
|
@ -14,14 +14,6 @@ class FileObjectTransformer extends BaseDaemonTransformer
|
||||||
*/
|
*/
|
||||||
private $editable = [];
|
private $editable = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* FileObjectTransformer constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->editable = config('pterodactyl.files.editable', []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a file object response from the daemon into a standardized response.
|
* Transform a file object response from the daemon into a standardized response.
|
||||||
*
|
*
|
||||||
|
@ -36,8 +28,7 @@ class FileObjectTransformer extends BaseDaemonTransformer
|
||||||
'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),
|
||||||
'is_editable' => in_array(Arr::get($item, 'mime', ''), $this->editable),
|
'mimetype' => Arr::get($item, 'mime', 'application/octet-stream'),
|
||||||
'mimetype' => Arr::get($item, 'mime'),
|
|
||||||
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(),
|
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(),
|
||||||
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(),
|
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(),
|
||||||
];
|
];
|
||||||
|
|
|
@ -178,20 +178,6 @@ return [
|
||||||
*/
|
*/
|
||||||
'files' => [
|
'files' => [
|
||||||
'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 1024 * 4),
|
'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 1024 * 4),
|
||||||
'editable' => [
|
|
||||||
'application/json',
|
|
||||||
'application/javascript',
|
|
||||||
'application/xml',
|
|
||||||
'application/xhtml+xml',
|
|
||||||
'inode/x-empty',
|
|
||||||
'text/xml',
|
|
||||||
'text/css',
|
|
||||||
'text/html',
|
|
||||||
'text/plain',
|
|
||||||
'text/x-perl',
|
|
||||||
'text/x-shellscript',
|
|
||||||
'text/x-python',
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -8,11 +8,11 @@ export interface FileObject {
|
||||||
size: number;
|
size: number;
|
||||||
isFile: boolean;
|
isFile: boolean;
|
||||||
isSymlink: boolean;
|
isSymlink: boolean;
|
||||||
isEditable: boolean;
|
|
||||||
mimetype: string;
|
mimetype: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
modifiedAt: Date;
|
modifiedAt: Date;
|
||||||
isArchiveType: () => boolean;
|
isArchiveType: () => boolean;
|
||||||
|
isEditable: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {
|
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {
|
||||||
|
|
|
@ -19,7 +19,6 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
|
||||||
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,
|
||||||
isEditable: data.attributes.is_editable,
|
|
||||||
mimetype: data.attributes.mimetype,
|
mimetype: data.attributes.mimetype,
|
||||||
createdAt: new Date(data.attributes.created_at),
|
createdAt: new Date(data.attributes.created_at),
|
||||||
modifiedAt: new Date(data.attributes.modified_at),
|
modifiedAt: new Date(data.attributes.modified_at),
|
||||||
|
@ -39,6 +38,19 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
|
||||||
'application/zip', // .zip
|
'application/zip', // .zip
|
||||||
].indexOf(this.mimetype) >= 0;
|
].indexOf(this.mimetype) >= 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isEditable: function () {
|
||||||
|
if (this.isArchiveType() || !this.isFile) return false;
|
||||||
|
|
||||||
|
const matches = [
|
||||||
|
'application/jar',
|
||||||
|
'application/octet-stream',
|
||||||
|
'inode/directory',
|
||||||
|
/^image\//,
|
||||||
|
];
|
||||||
|
|
||||||
|
return matches.every(m => !this.mimetype.match(m));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({
|
||||||
|
|
|
@ -16,7 +16,7 @@ const Row = styled.div`
|
||||||
${tw`flex bg-neutral-700 rounded-sm mb-px text-sm hover:text-neutral-100 cursor-pointer items-center no-underline hover:bg-neutral-600`};
|
${tw`flex bg-neutral-700 rounded-sm mb-px text-sm hover:text-neutral-100 cursor-pointer items-center no-underline hover:bg-neutral-600`};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const FileObjectRow = ({ file }: { file: FileObject }) => {
|
const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
|
||||||
const directory = ServerContext.useStoreState(state => state.files.directory);
|
const directory = ServerContext.useStoreState(state => state.files.directory);
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
@ -35,48 +35,59 @@ const FileObjectRow = ({ file }: { file: FileObject }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row
|
file.isFile && !file.isEditable() ?
|
||||||
key={file.name}
|
<div css={tw`flex flex-1 text-neutral-300 no-underline p-3 cursor-default`}>
|
||||||
onContextMenu={e => {
|
{children}
|
||||||
e.preventDefault();
|
</div>
|
||||||
window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX }));
|
:
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SelectFileCheckbox name={file.name}/>
|
|
||||||
<NavLink
|
<NavLink
|
||||||
to={`${match.url}/${file.isFile ? 'edit/' : ''}#${cleanDirectoryPath(`${directory}/${file.name}`)}`}
|
to={`${match.url}/${file.isFile ? 'edit/' : ''}#${cleanDirectoryPath(`${directory}/${file.name}`)}`}
|
||||||
css={tw`flex flex-1 text-neutral-300 no-underline p-3`}
|
css={tw`flex flex-1 text-neutral-300 no-underline p-3`}
|
||||||
onClick={onRowClick}
|
onClick={onRowClick}
|
||||||
>
|
>
|
||||||
<div css={tw`flex-none self-center text-neutral-400 mr-4 text-lg pl-3 ml-6`}>
|
{children}
|
||||||
{file.isFile ?
|
|
||||||
<FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/>
|
|
||||||
:
|
|
||||||
<FontAwesomeIcon icon={faFolder}/>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
<div css={tw`flex-1`}>
|
|
||||||
{file.name}
|
|
||||||
</div>
|
|
||||||
{file.isFile &&
|
|
||||||
<div css={tw`w-1/6 text-right mr-4`}>
|
|
||||||
{bytesToHuman(file.size)}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<div
|
|
||||||
css={tw`w-1/5 text-right mr-4`}
|
|
||||||
title={file.modifiedAt.toString()}
|
|
||||||
>
|
|
||||||
{Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ?
|
|
||||||
format(file.modifiedAt, 'MMM do, yyyy h:mma')
|
|
||||||
:
|
|
||||||
formatDistanceToNow(file.modifiedAt, { addSuffix: true })
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</NavLink>
|
</NavLink>
|
||||||
<FileDropdownMenu file={file}/>
|
|
||||||
</Row>
|
|
||||||
);
|
);
|
||||||
};
|
}, isEqual);
|
||||||
|
|
||||||
export default memo(FileObjectRow, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file));
|
const FileObjectRow = ({ file }: { file: FileObject }) => (
|
||||||
|
<Row
|
||||||
|
key={file.name}
|
||||||
|
onContextMenu={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX }));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectFileCheckbox name={file.name}/>
|
||||||
|
<Clickable file={file}>
|
||||||
|
<div css={tw`flex-none self-center text-neutral-400 mr-4 text-lg pl-3 ml-6`}>
|
||||||
|
{file.isFile ?
|
||||||
|
<FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/>
|
||||||
|
:
|
||||||
|
<FontAwesomeIcon icon={faFolder}/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div css={tw`flex-1`}>
|
||||||
|
{file.name}
|
||||||
|
</div>
|
||||||
|
{file.isFile &&
|
||||||
|
<div css={tw`w-1/6 text-right mr-4`}>
|
||||||
|
{bytesToHuman(file.size)}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div
|
||||||
|
css={tw`w-1/5 text-right mr-4`}
|
||||||
|
title={file.modifiedAt.toString()}
|
||||||
|
>
|
||||||
|
{Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ?
|
||||||
|
format(file.modifiedAt, 'MMM do, yyyy h:mma')
|
||||||
|
:
|
||||||
|
formatDistanceToNow(file.modifiedAt, { addSuffix: true })
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</Clickable>
|
||||||
|
<FileDropdownMenu file={file}/>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default memo(FileObjectRow, isEqual);
|
||||||
|
|
|
@ -26,12 +26,12 @@ const generateDirectoryData = (name: string): FileObject => ({
|
||||||
mode: '0644',
|
mode: '0644',
|
||||||
size: 0,
|
size: 0,
|
||||||
isFile: false,
|
isFile: false,
|
||||||
isEditable: false,
|
|
||||||
isSymlink: false,
|
isSymlink: false,
|
||||||
mimetype: '',
|
mimetype: '',
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
modifiedAt: new Date(),
|
modifiedAt: new Date(),
|
||||||
isArchiveType: () => false,
|
isArchiveType: () => false,
|
||||||
|
isEditable: () => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
|
Loading…
Reference in New Issue