From 8511d814df8b8345d22a3b7a3f9110a3729a6ad5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 28 May 2021 12:28:35 -0400 Subject: [PATCH] Restore api behaviour. Add zmu output to response --- web/api/app/Controller/MonitorsController.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index eb4eecf1f..110f590a6 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -260,47 +260,49 @@ class MonitorsController extends AppController { // form auth key based on auth credentials $auth = ''; - if ( ZM_OPT_USE_AUTH ) { + if (ZM_OPT_USE_AUTH) { global $user; $mToken = $this->request->query('token') ? $this->request->query('token') : $this->request->data('token');; - if ( $mToken ) { + if ($mToken) { $auth = ' -T '.$mToken; - } else if ( ZM_AUTH_RELAY == 'hashed' ) { + } else if (ZM_AUTH_RELAY == 'hashed') { $auth = ' -A '.calculateAuthHash(ZM_AUTH_HASH_IPS?$_SERVER['REMOTE_ADDR']:''); - } else if ( ZM_AUTH_RELAY == 'plain' ) { + } else if (ZM_AUTH_RELAY == 'plain') { # Plain requires the plain text password which must either be in request or stored in session $password = $this->request->query('pass') ? $this->request->query('pass') : $this->request->data('pass');; - if ( !$password ) + if (!$password) $password = $this->request->query('password') ? $this->request->query('password') : $this->request->data('password'); - if ( ! $password ) { + if (!$password) { # during auth the session will have been populated with the plaintext password $stateful = $this->request->query('stateful') ? $this->request->query('stateful') : $this->request->data('stateful'); - if ( $stateful ) { + if ($stateful) { $password = $_SESSION['password']; } - } else if ( $_COOKIE['ZMSESSID'] ) { + } else if ($_COOKIE['ZMSESSID']) { $password = $_SESSION['password']; } $auth = ' -U ' .$user['Username'].' -P '.$password; - } else if ( ZM_AUTH_RELAY == 'none' ) { + } else if (ZM_AUTH_RELAY == 'none') { $auth = ' -U ' .$user['Username']; } } $shellcmd = escapeshellcmd(ZM_PATH_BIN."/zmu $verbose -m$id $q $auth"); $status = exec($shellcmd, $output, $rc); - if ($status) { + if ($rc) { $this->set(array( - 'status'=>$rc, - 'error'=>$output, - '_serialize' => array('status','error'), + 'status'=>'false', + 'code' => $rc, + 'error'=> implode(PHP_EOL, $output), + '_serialize' => array('status','code','error'), )); } else { $this->set(array( - 'status' => 'Ok', - '_serialize' => array('status'), + 'status' => $status, + 'output' => implode(PHP_EOL, $output), + '_serialize' => array('status','output'), )); } }