2014-04-24 03:53:43 +08:00
|
|
|
<?php
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
/**
|
|
|
|
* Zones Controller
|
|
|
|
*
|
|
|
|
* @property Zone $Zone
|
|
|
|
*/
|
|
|
|
class ZonesController extends AppController {
|
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
/**
|
|
|
|
* Components
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $components = array('RequestHandler');
|
|
|
|
|
|
|
|
public function beforeFilter() {
|
|
|
|
parent::beforeFilter();
|
|
|
|
$canView = $this->Session->Read('monitorPermission');
|
|
|
|
if ( $canView =='None' ) {
|
|
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-09-04 02:51:24 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
// Find all zones which belong to a MonitorId
|
|
|
|
public function forMonitor($id = null) {
|
2016-09-04 03:02:32 +08:00
|
|
|
$this->loadModel('Monitor');
|
2018-07-25 04:41:09 +08:00
|
|
|
if ( !$this->Monitor->exists($id) ) {
|
|
|
|
throw new NotFoundException(__('Invalid monitor'));
|
2016-09-04 03:02:32 +08:00
|
|
|
}
|
|
|
|
$this->Zone->recursive = -1;
|
|
|
|
$zones = $this->Zone->find('all', array(
|
2018-07-25 04:41:09 +08:00
|
|
|
'conditions' => array('MonitorId' => $id)
|
2016-09-04 03:02:32 +08:00
|
|
|
));
|
|
|
|
$this->set(array(
|
2018-07-25 04:41:09 +08:00
|
|
|
'zones' => $zones,
|
|
|
|
'_serialize' => array('zones')
|
2016-09-04 03:02:32 +08:00
|
|
|
));
|
2018-07-25 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index() {
|
2016-09-04 03:02:32 +08:00
|
|
|
$this->Zone->recursive = -1;
|
2018-07-25 04:41:09 +08:00
|
|
|
|
|
|
|
$allowedMonitors = preg_split('@,@', $this->Session->Read('allowedMonitors'), NULL, PREG_SPLIT_NO_EMPTY);
|
|
|
|
if ( !empty($allowedMonitors) ) {
|
|
|
|
$mon_options = array('Zones.MonitorId' => $allowedMonitors);
|
|
|
|
} else {
|
|
|
|
$mon_options = '';
|
2016-09-04 03:02:32 +08:00
|
|
|
}
|
|
|
|
$zones = $this->Zone->find('all',$mon_options);
|
|
|
|
$this->set(array(
|
2018-07-25 04:41:09 +08:00
|
|
|
'zones' => $zones,
|
|
|
|
'_serialize' => array('zones')
|
2016-09-04 03:02:32 +08:00
|
|
|
));
|
2018-07-25 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function add() {
|
|
|
|
if ( $this->request->is('post') ) {
|
|
|
|
$this->Zone->create();
|
|
|
|
if ( $this->Zone->save($this->request->data) ) {
|
|
|
|
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
|
|
|
}
|
2016-09-04 03:02:32 +08:00
|
|
|
}
|
2018-07-25 04:41:09 +08:00
|
|
|
$monitors = $this->Zone->Monitor->find('list');
|
|
|
|
$this->set(compact('monitors'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* edit method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function edit($id = null) {
|
|
|
|
$this->Zone->id = $id;
|
|
|
|
|
|
|
|
if ( !$this->Zone->exists($id) ) {
|
|
|
|
throw new NotFoundException(__('Invalid zone'));
|
2016-09-04 03:02:32 +08:00
|
|
|
}
|
2018-07-25 04:41:09 +08:00
|
|
|
if ( $this->request->is(array('post', 'put')) ) {
|
|
|
|
if ( $this->Zone->save($this->request->data) ) {
|
|
|
|
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$options = array('conditions' => array('Zone.' . $this->Zone->primaryKey => $id));
|
|
|
|
$this->request->data = $this->Zone->find('first', $options);
|
2016-09-04 03:02:32 +08:00
|
|
|
}
|
2018-07-25 04:41:09 +08:00
|
|
|
$monitors = $this->Zone->Monitor->find('list');
|
|
|
|
$this->set(compact('monitors'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function delete($id = null) {
|
|
|
|
$this->Zone->id = $id;
|
|
|
|
if ( !$this->Zone->exists() ) {
|
|
|
|
throw new NotFoundException(__('Invalid zone'));
|
|
|
|
}
|
|
|
|
$this->request->allowMethod('post', 'delete');
|
|
|
|
if ( $this->Zone->delete() ) {
|
|
|
|
return $this->flash(__('The zone has been deleted.'), array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
return $this->flash(__('The zone could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
|
|
}
|
|
|
|
}
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
public function createZoneImage($id = null) {
|
|
|
|
$this->loadModel('Monitor');
|
|
|
|
$this->Monitor->id = $id;
|
|
|
|
if ( !$this->Monitor->exists() ) {
|
|
|
|
throw new NotFoundException(__('Invalid zone'));
|
|
|
|
}
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
$this->loadModel('Config');
|
|
|
|
$zm_dir_images = $this->Config->find('list', array(
|
|
|
|
'conditions' => array('Name' => 'ZM_DIR_IMAGES'),
|
|
|
|
'fields' => array('Name', 'Value')
|
|
|
|
));
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
$zm_dir_images = $zm_dir_images['ZM_DIR_IMAGES'];
|
|
|
|
$zm_path_web = Configure::read('ZM_PATH_WEB');
|
|
|
|
$zm_path_bin = Configure::read('ZM_PATH_BIN');
|
|
|
|
$images_path = "$zm_path_web/$zm_dir_images";
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
chdir($images_path);
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
$command = escapeshellcmd("$zm_path_bin/zmu -z -m $id");
|
|
|
|
system($command, $status);
|
2016-09-04 03:02:32 +08:00
|
|
|
|
2018-07-25 04:41:09 +08:00
|
|
|
$this->set(array(
|
|
|
|
'status' => $status,
|
|
|
|
'_serialize' => array('status')
|
|
|
|
));
|
|
|
|
}
|
2015-06-11 10:58:58 +08:00
|
|
|
}
|