Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZoneMinder/ZoneMinder
Browse files Browse the repository at this point in the history
  • Loading branch information
connortechnology committed May 12, 2016
2 parents aebfa5c + 9377dca commit 4cd510c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions web/api/app/Controller/MonitorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public function edit($id = null) {
'_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' );
}

/**
Expand Down Expand Up @@ -187,27 +187,35 @@ public function sourceTypes() {
// 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'];
$cmd = strtolower($this->request->params['named']['command']);
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');
Expand Down Expand Up @@ -245,7 +253,7 @@ public function alarm()
}
}

$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(
Expand Down

0 comments on commit 4cd510c

Please sign in to comment.