diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index e6d841c9f..893410ce8 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -138,8 +138,8 @@ public function beforeFilter() { '_serialize' => array('message') )); // - restart this monitor after change - // We don't pass the request data as the monitor object because it may be a subset of the full monitor array - $this->daemonControl( $this->Monitor->id, 'restart' ); + // We don't pass the request data as the monitor object because it may be a subset of the full monitor array + $this->daemonControl( $this->Monitor->id, 'restart' ); } /** @@ -187,7 +187,7 @@ public function beforeFilter() { // arm/disarm alarms // expected format: http(s):/portal-api-url/monitors/alarm/id:M/command:C.json // where M=monitorId - // where C=on|off + // where C=on|off|status public function alarm() { $id = $this->request->params['named']['id']; @@ -195,19 +195,27 @@ public function beforeFilter() { if (!$this->Monitor->exists($id)) { throw new NotFoundException(__('Invalid monitor')); } - if ( $cmd != 'on' && $cmd != 'off') + if ( $cmd != 'on' && $cmd != 'off' && $cmd != 'status') { throw new BadRequestException(__('Invalid command')); } - - if ($this->Session->Read('systemPermission') != 'Edit') - { - throw new UnauthorizedException(__('Insufficient privileges')); - return; - } - $zm_path_bin = Configure::read('ZM_PATH_BIN'); - $q = ($cmd == 'on') ? '-a':'-c'; + + switch ($cmd) + { + case "on": + $q = '-a'; + $verbose = "-v"; + break; + case "off": + $q = "-c"; + $verbose = "-v"; + break; + case "status": + $verbose = ""; // zmu has a bug - gives incorrect verbose output in this case + $q = "-s"; + break; + } // form auth key based on auth credentials $this->loadModel('Config'); @@ -245,7 +253,7 @@ public function beforeFilter() { } } - $shellcmd = escapeshellcmd("$zm_path_bin/zmu -v -m$id $q $auth"); + $shellcmd = escapeshellcmd("$zm_path_bin/zmu $verbose -m$id $q $auth"); $status = exec ($shellcmd); $this->set(array( diff --git a/web/skins/classic/views/js/montage.js b/web/skins/classic/views/js/montage.js index 1367bc8b1..a6c459760 100644 --- a/web/skins/classic/views/js/montage.js +++ b/web/skins/classic/views/js/montage.js @@ -1,10 +1,11 @@ var requestQueue = new Request.Queue( { concurrent: 2 } ); -function Monitor( index, id, connKey ) +function Monitor( index, monitorData ) { this.index = index; - this.id = id; - this.connKey = connKey; + this.id = monitorData.id; + this.connKey = monitorData.connKey; + this.server_url = monitorData.server_url; this.status = null; this.alarmState = STATE_IDLE; this.lastAlarmState = STATE_IDLE; @@ -110,7 +111,7 @@ function Monitor( index, id, connKey ) this.streamCmdReq.send( this.streamCmdParms+"&command="+CMD_QUERY ); } - this.streamCmdReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, onSuccess: this.getStreamCmdResponse.bind( this ), onTimeout: this.streamCmdQuery.bind( this, true ), link: 'cancel' } ); + this.streamCmdReq = new Request.JSON( { url: this.server_url, method: 'get', timeout: AJAX_TIMEOUT, onSuccess: this.getStreamCmdResponse.bind( this ), onTimeout: this.streamCmdQuery.bind( this, true ), link: 'cancel' } ); requestQueue.addRequest( "cmdReq"+this.id, this.streamCmdReq ); } @@ -146,7 +147,7 @@ function initPage() { for ( var i = 0; i < monitorData.length; i++ ) { - monitors[i] = new Monitor( i, monitorData[i].id, monitorData[i].connKey ); + monitors[i] = new Monitor( i, monitorData[i] ); var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout ); monitors[i].start( delay ); } diff --git a/web/skins/classic/views/js/montage.js.php b/web/skins/classic/views/js/montage.js.php index 80f652fd5..7eaebb75b 100644 --- a/web/skins/classic/views/js/montage.js.php +++ b/web/skins/classic/views/js/montage.js.php @@ -35,7 +35,8 @@ monitorData[monitorData.length] = { 'id': Id() ?>, 'connKey': connKey() ?>, 'width': Width() ?>, - 'height':Height() ?> + 'height':Height() ?>, + 'server_url': 'Server()->Url().$_SERVER['PHP_SELF'] ?>' };