Restore api behaviour. Add zmu output to response
This commit is contained in:
parent
829708f8f2
commit
a4e4ebe3fd
|
@ -260,47 +260,49 @@ class MonitorsController extends AppController {
|
||||||
// form auth key based on auth credentials
|
// form auth key based on auth credentials
|
||||||
$auth = '';
|
$auth = '';
|
||||||
|
|
||||||
if ( ZM_OPT_USE_AUTH ) {
|
if (ZM_OPT_USE_AUTH) {
|
||||||
global $user;
|
global $user;
|
||||||
$mToken = $this->request->query('token') ? $this->request->query('token') : $this->request->data('token');;
|
$mToken = $this->request->query('token') ? $this->request->query('token') : $this->request->data('token');;
|
||||||
if ( $mToken ) {
|
if ($mToken) {
|
||||||
$auth = ' -T '.$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']:'');
|
$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
|
# 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');;
|
$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');
|
$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
|
# 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');
|
$stateful = $this->request->query('stateful') ? $this->request->query('stateful') : $this->request->data('stateful');
|
||||||
if ( $stateful ) {
|
if ($stateful) {
|
||||||
$password = $_SESSION['password'];
|
$password = $_SESSION['password'];
|
||||||
}
|
}
|
||||||
} else if ( $_COOKIE['ZMSESSID'] ) {
|
} else if ($_COOKIE['ZMSESSID']) {
|
||||||
$password = $_SESSION['password'];
|
$password = $_SESSION['password'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$auth = ' -U ' .$user['Username'].' -P '.$password;
|
$auth = ' -U ' .$user['Username'].' -P '.$password;
|
||||||
} else if ( ZM_AUTH_RELAY == 'none' ) {
|
} else if (ZM_AUTH_RELAY == 'none') {
|
||||||
$auth = ' -U ' .$user['Username'];
|
$auth = ' -U ' .$user['Username'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$shellcmd = escapeshellcmd(ZM_PATH_BIN."/zmu $verbose -m$id $q $auth");
|
$shellcmd = escapeshellcmd(ZM_PATH_BIN."/zmu $verbose -m$id $q $auth");
|
||||||
$status = exec($shellcmd, $output, $rc);
|
$status = exec($shellcmd, $output, $rc);
|
||||||
if ($status) {
|
if ($rc) {
|
||||||
$this->set(array(
|
$this->set(array(
|
||||||
'status'=>$rc,
|
'status'=>'false',
|
||||||
'error'=>$output,
|
'code' => $rc,
|
||||||
'_serialize' => array('status','error'),
|
'error'=> implode(PHP_EOL, $output),
|
||||||
|
'_serialize' => array('status','code','error'),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$this->set(array(
|
$this->set(array(
|
||||||
'status' => 'Ok',
|
'status' => $status,
|
||||||
'_serialize' => array('status'),
|
'output' => implode(PHP_EOL, $output),
|
||||||
|
'_serialize' => array('status','output'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue