From fd21d47bbb159863a37dee26f2e4b590115542de Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 23 Jan 2021 16:28:39 -0500 Subject: [PATCH] Merge pull request #3113 from pliablepixels/feature-api-daemon-control new api to control daemon --- web/api/app/Controller/HostController.php | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index cf6e99b53..3d3a23c6e 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -21,6 +21,30 @@ class HostController extends AppController { )); } + // an interface to individually control the various ZM daemons + // invocation: https://server/zm/api/host/daemonControl/.pl/.json + // note that this API is only for interaction with a specific + // daemon. zmdc also allows other functions like logrot/etc + public function daemonControl($daemon_name, $command) { + global $user; + if ($command == 'check' || $command == 'status') { + $permission = 'View'; + } else { + $permission = 'Edit'; + } + $allowed = (!$user) || ($user['System'] == $permission ); + if ( !$allowed ) { + throw new UnauthorizedException(__("Insufficient privileges")); + return; + } + $string = ZM_PATH_BIN."/zmdc.pl $command $daemon_name"; + $result = exec($string); + $this->set(array( + 'result' => $result, + '_serialize' => array('result') + )); + } + function getLoad() { $load = sys_getloadavg();