From 171b21e7ee219989daf87de7131d7644e527f4c2 Mon Sep 17 00:00:00 2001
From: Dane Everitt
Date: Sun, 29 Mar 2020 22:12:50 -0700
Subject: [PATCH] Add permissions handling to the console; remove kill
permission (wrapped in with stop)
---
.../Api/Client/Servers/SendPowerRequest.php | 3 +-
app/Models/Permission.php | 2 -
.../scripts/components/server/Console.tsx | 10 +++-
.../components/server/ServerConsole.tsx | 53 +++++++++++--------
resources/scripts/state/server/subusers.ts | 2 +-
5 files changed, 42 insertions(+), 28 deletions(-)
diff --git a/app/Http/Requests/Api/Client/Servers/SendPowerRequest.php b/app/Http/Requests/Api/Client/Servers/SendPowerRequest.php
index 8686b4f67..ea7e00fcc 100644
--- a/app/Http/Requests/Api/Client/Servers/SendPowerRequest.php
+++ b/app/Http/Requests/Api/Client/Servers/SendPowerRequest.php
@@ -18,11 +18,10 @@ class SendPowerRequest extends ClientApiRequest
case 'start':
return Permission::ACTION_CONTROL_START;
case 'stop':
+ case 'kill':
return Permission::ACTION_CONTROL_STOP;
case 'restart':
return Permission::ACTION_CONTROL_RESTART;
- case 'kill':
- return Permission::ACTION_CONTROL_KILL;
}
return '__invalid';
diff --git a/app/Models/Permission.php b/app/Models/Permission.php
index 9a834ff76..df19f595c 100644
--- a/app/Models/Permission.php
+++ b/app/Models/Permission.php
@@ -20,7 +20,6 @@ class Permission extends Validable
const ACTION_CONTROL_START = 'control.start';
const ACTION_CONTROL_STOP = 'control.stop';
const ACTION_CONTROL_RESTART = 'control.restart';
- const ACTION_CONTROL_KILL = 'control.kill';
const ACTION_DATABASE_READ = 'database.read';
const ACTION_DATABASE_CREATE = 'database.create';
@@ -111,7 +110,6 @@ class Permission extends Validable
'start' => 'Allows a user to start the server if it is stopped.',
'stop' => 'Allows a user to stop a server if it is running.',
'restart' => 'Allows a user to perform a server restart. This allows them to start the server if it is offline, but not put the server in a completely stopped state.',
- 'kill' => 'Allows a user to terminate a server process.',
],
],
diff --git a/resources/scripts/components/server/Console.tsx b/resources/scripts/components/server/Console.tsx
index 099943fe9..54d6e9620 100644
--- a/resources/scripts/components/server/Console.tsx
+++ b/resources/scripts/components/server/Console.tsx
@@ -4,6 +4,9 @@ import * as TerminalFit from 'xterm/lib/addons/fit/fit';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import { ServerContext } from '@/state/server';
import styled from 'styled-components';
+import Can from '@/components/elements/Can';
+import { usePermissions } from '@/plugins/usePermissions';
+import classNames from 'classnames';
const theme = {
background: 'transparent',
@@ -52,6 +55,7 @@ export default () => {
const useRef = useCallback(node => setTerminalElement(node), []);
const terminal = useMemo(() => new Terminal({ ...terminalProps }), []);
const { connected, instance } = ServerContext.useStoreState(state => state.socket);
+ const [ canSendCommands ] = usePermissions([ 'control.console']);
const handleConsoleOutput = (line: string, prelude = false) => terminal.writeln(
(prelude ? TERMINAL_PRELUDE : '') + line.replace(/(?:\r\n|\r|\n)$/im, '') + '\u001b[0m',
@@ -121,7 +125,9 @@ export default () => {
{
>
+ {canSendCommands &&
$
@@ -140,6 +147,7 @@ export default () => {
/>
+ }
);
};
diff --git a/resources/scripts/components/server/ServerConsole.tsx b/resources/scripts/components/server/ServerConsole.tsx
index 55668ffbd..434589f10 100644
--- a/resources/scripts/components/server/ServerConsole.tsx
+++ b/resources/scripts/components/server/ServerConsole.tsx
@@ -9,6 +9,7 @@ import { faMicrochip } from '@fortawesome/free-solid-svg-icons/faMicrochip';
import { bytesToHuman } from '@/helpers';
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
+import Can from '@/components/elements/Can';
type PowerAction = 'start' | 'stop' | 'restart' | 'kill';
@@ -109,28 +110,36 @@ export default () => {
{cpu.toFixed(2)} %
-
-
-
- sendPowerCommand(action)}/>
-
+
+
+
+
+
+
+
+
+
+ sendPowerCommand(action)}/>
+
+
+
diff --git a/resources/scripts/state/server/subusers.ts b/resources/scripts/state/server/subusers.ts
index c859ecead..5a6224853 100644
--- a/resources/scripts/state/server/subusers.ts
+++ b/resources/scripts/state/server/subusers.ts
@@ -2,7 +2,7 @@ import { action, Action } from 'easy-peasy';
export type SubuserPermission =
'websocket.*' |
- 'control.console' | 'control.start' | 'control.stop' | 'control.restart' | 'control.kill' |
+ 'control.console' | 'control.start' | 'control.stop' | 'control.restart' |
'user.create' | 'user.read' | 'user.update' | 'user.delete' |
'file.create' | 'file.read' | 'file.update' | 'file.delete' | 'file.archive' | 'file.sftp' |
'allocation.read' | 'allocation.update' |