From 06f4271b50862579e331d4c1e53bd852f9fc887e Mon Sep 17 00:00:00 2001 From: CptainObvious Date: Mon, 2 Mar 2020 09:12:51 +0000 Subject: [PATCH] Blacklist implemented + WIP on error message formatting --- js/index.js | 6 +++++- lib/Controller/OccController.php | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/js/index.js b/js/index.js index 4641951..5df1a39 100644 --- a/js/index.js +++ b/js/index.js @@ -28,7 +28,11 @@ }).done(function (response) { term.echo('\n' + response).resume(); }).fail(function (response, code) { - term.echo('\n' + response).resume(); + if (response.status === 403) { + term.echo(response.responseJSON.error).resume(); + } else { + term.echo('\n[[;red;]Error]\n' + response).resume(); + } }); } }, { diff --git a/lib/Controller/OccController.php b/lib/Controller/OccController.php index 1df129b..4c62a13 100644 --- a/lib/Controller/OccController.php +++ b/lib/Controller/OccController.php @@ -21,13 +21,13 @@ class OccController extends Controller private $application; private $output; - + private $blacklist; public function __construct(ILogger $logger, $AppName, IRequest $request, $userId) { parent::__construct($AppName, $request); $this->logger = $logger; $this->userId = $userId; - + $this->blacklist = array("maintenance:mode on"); $this->application = new Application( OC::$server->getConfig(), OC::$server->getEventDispatcher(), @@ -58,8 +58,9 @@ class OccController extends Controller $this->application->run($input, $this->output); return $this->output->fetch(); } catch (Exception $ex) { - $this->logger->logException($ex); - return "error: " . $ex->getMessage(); + exceptionHandler($ex); + } catch (Error $ex) { + exceptionHandler($ex); } } @@ -70,6 +71,10 @@ class OccController extends Controller public function cmd($command) { $this->logger->debug($command); + if (in_array($command, $this->blacklist)) { + $this->logger->debug("Command blacklist"); + return new DataResponse(array("error" => "\n".'\u001b[37;41m \u001b[39;49m'."\n".'\u001b[37;41m Command blacklisted. \u001b[39;49m'."\n".'\u001b[37;41m \u001b[39;49m'."\n\n"), 403); + } $input = new StringInput($command); $response = $this->run($input); $this->logger->debug($response); @@ -86,3 +91,9 @@ class OccController extends Controller } } +function exceptionHandler($exception) +{ + echo "An unhandled exception has been thrown:" . PHP_EOL; + echo $exception; + exit(1); +} -- 2.45.2