Merge branch 'master' into fix_2167

pull/2168/head
Isaac Connor 2018-07-24 16:48:29 -04:00
commit c095b9cd33
6 changed files with 163 additions and 158 deletions

View File

@ -78,8 +78,11 @@ class AppController extends Controller {
if ( ZM_OPT_USE_AUTH ) { if ( ZM_OPT_USE_AUTH ) {
// We need to reject methods that are not authenticated // We need to reject methods that are not authenticated
// besides login and logout // besides login and logout
if ( strcasecmp($this->params->action, 'login') && if (
strcasecmp($this->params->action, 'logout')) { strcasecmp($this->params->action, 'login')
&&
strcasecmp($this->params->action, 'logout')
) {
if ( !( $user and $user['Username'] ) ) { if ( !( $user and $user['Username'] ) ) {
throw new UnauthorizedException(__('Not Authenticated')); throw new UnauthorizedException(__('Not Authenticated'));
return; return;

View File

@ -8,12 +8,12 @@ App::uses('AppController', 'Controller');
*/ */
class EventsController extends AppController { class EventsController extends AppController {
/** /**
* Components * Components
* *
* @var array * @var array
*/ */
public $components = array('RequestHandler', 'Scaler', 'Image', 'Paginator'); public $components = array('RequestHandler', 'Scaler', 'Image', 'Paginator');
public function beforeFilter() { public function beforeFilter() {
parent::beforeFilter(); parent::beforeFilter();
@ -25,14 +25,14 @@ class EventsController extends AppController {
} }
} }
/** /**
* index method * index method
* *
* @return void * @return void
* This also creates a thumbnail for each event. * This also creates a thumbnail for each event.
*/ */
public function index() { public function index() {
$this->Event->recursive = -1; $this->Event->recursive = -1;
global $user; global $user;
$allowedMonitors = $user ? preg_split('@,@', $user['MonitorIds'], NULL, PREG_SPLIT_NO_EMPTY) : null; $allowedMonitors = $user ? preg_split('@,@', $user['MonitorIds'], NULL, PREG_SPLIT_NO_EMPTY) : null;
@ -43,26 +43,26 @@ class EventsController extends AppController {
$mon_options = ''; $mon_options = '';
} }
if ( $this->request->params['named'] ) { if ( $this->request->params['named'] ) {
//$this->FilterComponent = $this->Components->load('Filter'); //$this->FilterComponent = $this->Components->load('Filter');
//$conditions = $this->FilterComponent->buildFilter($this->request->params['named']); //$conditions = $this->FilterComponent->buildFilter($this->request->params['named']);
$conditions = $this->request->params['named']; $conditions = $this->request->params['named'];
} else { } else {
$conditions = array(); $conditions = array();
} }
$settings = array( $settings = array(
// https://github.com/ZoneMinder/ZoneMinder/issues/995 // https://github.com/ZoneMinder/ZoneMinder/issues/995
// 'limit' => $limit['ZM_WEB_EVENTS_PER_PAGE'], // 'limit' => $limit['ZM_WEB_EVENTS_PER_PAGE'],
// 25 events per page which is what the above // 25 events per page which is what the above
// default is, is way too low for an API // default is, is way too low for an API
// changing this to 100 so we don't kill ZM // changing this to 100 so we don't kill ZM
// with many event APIs. In future, we can // with many event APIs. In future, we can
// make a nice ZM_API_ITEMS_PER_PAGE for all pagination // make a nice ZM_API_ITEMS_PER_PAGE for all pagination
// API // API
'limit' => '100', 'limit' => '100',
'order' => array('StartTime'), 'order' => array('StartTime'),
'paramType' => 'querystring', 'paramType' => 'querystring',
); );
if ( isset($conditions['GroupId']) ) { if ( isset($conditions['GroupId']) ) {
$settings['joins'] = array( $settings['joins'] = array(
@ -78,36 +78,36 @@ class EventsController extends AppController {
} }
$settings['conditions'] = array($conditions, $mon_options); $settings['conditions'] = array($conditions, $mon_options);
// How many events to return // How many events to return
$this->loadModel('Config'); $this->loadModel('Config');
$limit = $this->Config->find('list', array( $limit = $this->Config->find('list', array(
'conditions' => array('Name' => 'ZM_WEB_EVENTS_PER_PAGE'), 'conditions' => array('Name' => 'ZM_WEB_EVENTS_PER_PAGE'),
'fields' => array('Name', 'Value') 'fields' => array('Name', 'Value')
)); ));
$this->Paginator->settings = $settings; $this->Paginator->settings = $settings;
$events = $this->Paginator->paginate('Event'); $events = $this->Paginator->paginate('Event');
// For each event, get the frameID which has the largest score // For each event, get the frameID which has the largest score
foreach ( $events as $key => $value ) { foreach ( $events as $key => $value ) {
$maxScoreFrameId = $this->getMaxScoreAlarmFrameId($value['Event']['Id']); $maxScoreFrameId = $this->getMaxScoreAlarmFrameId($value['Event']['Id']);
$events[$key]['Event']['MaxScoreFrameId'] = $maxScoreFrameId; $events[$key]['Event']['MaxScoreFrameId'] = $maxScoreFrameId;
} }
$this->set(compact('events')); $this->set(compact('events'));
} // end public function index() } // end public function index()
/** /**
* view method * view method
* *
* @throws NotFoundException * @throws NotFoundException
* @param string $id * @param string $id
* @return void * @return void
*/ */
public function view($id = null) { public function view($id = null) {
$this->loadModel('Config'); $this->loadModel('Config');
$this->Event->recursive = 1; $this->Event->recursive = 1;
if (!$this->Event->exists($id)) { if ( !$this->Event->exists($id) ) {
throw new NotFoundException(__('Invalid event')); throw new NotFoundException(__('Invalid event'));
} }
@ -232,7 +232,7 @@ class EventsController extends AppController {
foreach ($this->params['named'] as $param_name => $value) { foreach ($this->params['named'] as $param_name => $value) {
// Transform params into mysql // Transform params into mysql
if (preg_match('/interval/i', $value, $matches)) { if ( preg_match('/interval/i', $value, $matches) ) {
$condition = array("$param_name >= (date_sub(now(), $value))"); $condition = array("$param_name >= (date_sub(now(), $value))");
} else { } else {
$condition = array($param_name => $value); $condition = array($param_name => $value);
@ -289,12 +289,12 @@ class EventsController extends AppController {
// Find the max Frame for this Event. Error out otherwise. // Find the max Frame for this Event. Error out otherwise.
$this->loadModel('Frame'); $this->loadModel('Frame');
if (! $frame = $this->Frame->find('first', array( if ( !( $frame = $this->Frame->find('first', array(
'conditions' => array( 'conditions' => array(
'EventId' => $event['Event']['Id'], 'EventId' => $event['Event']['Id'],
'Score' => $event['Event']['MaxScore'] 'Score' => $event['Event']['MaxScore']
) )
))) { ))) ) {
throw new NotFoundException(__('Can not find Frame for Event ' . $event['Event']['Id'])); throw new NotFoundException(__('Can not find Frame for Event ' . $event['Event']['Id']));
} }
@ -315,8 +315,8 @@ class EventsController extends AppController {
'ZM_DIR_IMAGES', 'ZM_DIR_IMAGES',
$thumbs, $thumbs,
'ZM_DIR_EVENTS' 'ZM_DIR_EVENTS'
) )
)), )),
'fields' => array('Name', 'Value') 'fields' => array('Name', 'Value')
)); ));
$config['ZM_WEB_SCALE_THUMBS'] = $config[$thumbs]; $config['ZM_WEB_SCALE_THUMBS'] = $config[$thumbs];
@ -345,7 +345,7 @@ class EventsController extends AppController {
public function archive($id = null) { public function archive($id = null) {
$this->Event->recursive = -1; $this->Event->recursive = -1;
if (!$this->Event->exists($id)) { if ( !$this->Event->exists($id) ) {
throw new NotFoundException(__('Invalid event')); throw new NotFoundException(__('Invalid event'));
} }
@ -370,7 +370,7 @@ class EventsController extends AppController {
public function getMaxScoreAlarmFrameId($id = null) { public function getMaxScoreAlarmFrameId($id = null) {
$this->Event->recursive = -1; $this->Event->recursive = -1;
if (!$this->Event->exists($id)) { if ( !$this->Event->exists($id) ) {
throw new NotFoundException(__('Invalid event')); throw new NotFoundException(__('Invalid event'));
} }
@ -387,7 +387,7 @@ class EventsController extends AppController {
'Score' => $event['Event']['MaxScore'] 'Score' => $event['Event']['MaxScore']
) )
))) { ))) {
throw new NotFoundException(__("Can not find Frame for Event " . $event['Event']['Id'])); throw new NotFoundException(__('Can not find Frame for Event ' . $event['Event']['Id']));
} }
return $frame['Frame']['Id']; return $frame['Frame']['Id'];
} }

View File

@ -127,7 +127,7 @@ class MonitorsController extends AppController {
} }
$this->Monitor->create(); $this->Monitor->create();
if ($this->Monitor->save($this->request->data)) { if ( $this->Monitor->save($this->request->data) ) {
$this->daemonControl($this->Monitor->id, 'start'); $this->daemonControl($this->Monitor->id, 'start');
//return $this->flash(__('The monitor has been saved.'), array('action' => 'index')); //return $this->flash(__('The monitor has been saved.'), array('action' => 'index'));
$message = 'Saved'; $message = 'Saved';
@ -151,7 +151,7 @@ class MonitorsController extends AppController {
public function edit($id = null) { public function edit($id = null) {
$this->Monitor->id = $id; $this->Monitor->id = $id;
if (!$this->Monitor->exists($id)) { if ( !$this->Monitor->exists($id) ) {
throw new NotFoundException(__('Invalid monitor')); throw new NotFoundException(__('Invalid monitor'));
} }
global $user; global $user;
@ -243,7 +243,7 @@ class MonitorsController extends AppController {
public function alarm() { public function alarm() {
$id = $this->request->params['named']['id']; $id = $this->request->params['named']['id'];
$cmd = strtolower($this->request->params['named']['command']); $cmd = strtolower($this->request->params['named']['command']);
if (!$this->Monitor->exists($id)) { if ( !$this->Monitor->exists($id) ) {
throw new NotFoundException(__('Invalid monitor')); throw new NotFoundException(__('Invalid monitor'));
} }
if ( $cmd != 'on' && $cmd != 'off' && $cmd != 'status' ) { if ( $cmd != 'on' && $cmd != 'off' && $cmd != 'status' ) {

View File

@ -8,92 +8,93 @@ App::uses('AppController', 'Controller');
*/ */
class ZonePresetsController extends AppController { class ZonePresetsController extends AppController {
/** /**
* Components * Components
* *
* @var array * @var array
*/ */
public $components = array('RequestHandler'); public $components = array('RequestHandler');
/** /**
* index method * index method
* *
* @return void * @return void
*/ */
public function index() { public function index() {
$zonePresets = $this->ZonePreset->find('all'); $zonePresets = $this->ZonePreset->find('all');
$this->set(array( $this->set(array(
'zonePresets' => $zonePresets, 'zonePresets' => $zonePresets,
'_serialize' => array('zonePresets') '_serialize' => array('zonePresets')
)); ));
} }
/** /**
* view method * view method
* *
* @throws NotFoundException * @throws NotFoundException
* @param string $id * @param string $id
* @return void * @return void
*/ */
public function view($id = null) { public function view($id = null) {
if (!$this->ZonePreset->exists($id)) { if ( !$this->ZonePreset->exists($id) ) {
throw new NotFoundException(__('Invalid zone preset')); throw new NotFoundException(__('Invalid zone preset'));
} }
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id)); $options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
$this->set('zonePreset', $this->ZonePreset->find('first', $options)); $this->set('zonePreset', $this->ZonePreset->find('first', $options));
} }
/** /**
* add method * add method
* *
* @return void * @return void
*/ */
public function add() { public function add() {
if ($this->request->is('post')) { if ( $this->request->is('post') ) {
$this->ZonePreset->create(); $this->ZonePreset->create();
if ($this->ZonePreset->save($this->request->data)) { if ( $this->ZonePreset->save($this->request->data) ) {
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index')); return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
} }
} }
} }
/** /**
* edit method * edit method
* *
* @throws NotFoundException * @throws NotFoundException
* @param string $id * @param string $id
* @return void * @return void
*/ */
public function edit($id = null) { public function edit($id = null) {
if (!$this->ZonePreset->exists($id)) { if ( !$this->ZonePreset->exists($id) ) {
throw new NotFoundException(__('Invalid zone preset')); throw new NotFoundException(__('Invalid zone preset'));
} }
if ($this->request->is(array('post', 'put'))) { if ( $this->request->is(array('post', 'put')) ) {
if ($this->ZonePreset->save($this->request->data)) { if ( $this->ZonePreset->save($this->request->data) ) {
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index')); return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
} }
} else { } else {
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id)); $options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
$this->request->data = $this->ZonePreset->find('first', $options); $this->request->data = $this->ZonePreset->find('first', $options);
} }
} }
/** /**
* delete method * delete method
* *
* @throws NotFoundException * @throws NotFoundException
* @param string $id * @param string $id
* @return void * @return void
*/ */
public function delete($id = null) { public function delete($id = null) {
$this->ZonePreset->id = $id; $this->ZonePreset->id = $id;
if (!$this->ZonePreset->exists()) { if ( !$this->ZonePreset->exists() ) {
throw new NotFoundException(__('Invalid zone preset')); throw new NotFoundException(__('Invalid zone preset'));
} }
$this->request->allowMethod('post', 'delete'); $this->request->allowMethod('post', 'delete');
if ($this->ZonePreset->delete()) { if ( $this->ZonePreset->delete() ) {
return $this->flash(__('The zone preset has been deleted.'), array('action' => 'index')); return $this->flash(__('The zone preset has been deleted.'), array('action' => 'index'));
} else { } else {
return $this->flash(__('The zone preset could not be deleted. Please, try again.'), array('action' => 'index')); return $this->flash(__('The zone preset could not be deleted. Please, try again.'), array('action' => 'index'));
} }
}} }
} // end class ZonePresetsController

View File

@ -56,6 +56,7 @@ class ZonesController extends AppController {
'_serialize' => array('zones') '_serialize' => array('zones')
)); ));
} }
/** /**
* add method * add method
* *
@ -137,7 +138,7 @@ class ZonesController extends AppController {
} }
} }
public function createZoneImage( $id = null ) { public function createZoneImage($id = null) {
$this->loadModel('Monitor'); $this->loadModel('Monitor');
$this->Monitor->id = $id; $this->Monitor->id = $id;
if ( !$this->Monitor->exists() ) { if ( !$this->Monitor->exists() ) {
@ -158,7 +159,7 @@ class ZonesController extends AppController {
chdir($images_path); chdir($images_path);
$command = escapeshellcmd("$zm_path_bin/zmu -z -m $id"); $command = escapeshellcmd("$zm_path_bin/zmu -z -m $id");
system( $command, $status ); system($command, $status);
$this->set(array( $this->set(array(
'status' => $status, 'status' => $status,

View File

@ -54,7 +54,7 @@ var popupSizes = {
'monitorselect':{ 'width': 160, 'height': 200 }, 'monitorselect':{ 'width': 160, 'height': 200 },
'montage': { 'width': -1, 'height': -1 }, 'montage': { 'width': -1, 'height': -1 },
'onvifprobe': { 'width': 700, 'height': 550 }, 'onvifprobe': { 'width': 700, 'height': 550 },
'optionhelp': { 'width': 400, 'height': 320 }, 'optionhelp': { 'width': 400, 'height': 400 },
'options': { 'width': 1000, 'height': 660 }, 'options': { 'width': 1000, 'height': 660 },
'preset': { 'width': 300, 'height': 220 }, 'preset': { 'width': 300, 'height': 220 },
'server': { 'width': 600, 'height': 405 }, 'server': { 'width': 600, 'height': 405 },