mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Follow-up to the numeric field-name guard. FilterComponent::buildFilter() takes an optional $validFields allow-list, but only EventsController's search index and MonitorsController (via qualifyFields) used it; the other index/search/ consoleEvents call sites passed none, so a field name was checked only by the character class, not against a known column set. Pass array_keys($this->Model->schema()) - the pattern EventsController already uses - at the remaining sites across Configs, EventData, Events (three), Frames, Groups, ServerStats, Snapshots, Storage, Tags and UserPreference, so a field must be a real column of the queried model and an unknown field is a 400 rather than a MySQL 500. The injection itself is already closed by the numeric field-name guard; this is defense in depth and consistent error handling. ServerStatsController's commented-out permission check is left as-is (clients need the data to render monitors); only the allow-list is added there. Add tests/php/test_api_filter_fields_enforced.php. Reported by arpitjain099. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
173 lines
4.3 KiB
PHP
173 lines
4.3 KiB
PHP
<?php
|
|
App::uses('AppController', 'Controller');
|
|
/**
|
|
* Storage Controller
|
|
*
|
|
* @property Storage $Storage
|
|
* @property PaginatorComponent $Paginator
|
|
*/
|
|
class StorageController extends AppController {
|
|
|
|
/**
|
|
* Components
|
|
*
|
|
* @var array
|
|
*/
|
|
public $components = array('Paginator', 'RequestHandler');
|
|
|
|
public function beforeFilter() {
|
|
parent::beforeFilter();
|
|
global $user;
|
|
$canView = (!$user) || ($user->System() != 'None');
|
|
if ( !$canView ) {
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
return;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* index method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function index() {
|
|
$this->Storage->recursive = -1;
|
|
|
|
$named_params = $this->request->params['named'];
|
|
if ( $named_params ) {
|
|
$this->FilterComponent = $this->Components->load('Filter');
|
|
$conditions = $this->FilterComponent->buildFilter($named_params, array_keys($this->Storage->schema()));
|
|
} else {
|
|
$conditions = array();
|
|
}
|
|
$options = ['conditions'=>&$conditions];
|
|
$storage_areas = $this->Storage->find('all', $options);
|
|
require_once __DIR__ .'/../../../includes/Storage.php';
|
|
|
|
foreach ($storage_areas as &$s) {
|
|
$storage = new ZM\Storage($s['Storage']);
|
|
$s['Storage']['DiskTotalSpace'] = $storage->disk_total_space();
|
|
$s['Storage']['DiskUsedSpace'] = $storage->disk_used_space();
|
|
}
|
|
|
|
$this->set(array(
|
|
'storage' => $storage_areas,
|
|
'_serialize' => array('storage')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* view method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function view($id = null) {
|
|
$this->Storage->recursive = 0;
|
|
if (!$this->Storage->exists($id)) {
|
|
throw new NotFoundException(__('Invalid storage area'));
|
|
}
|
|
$restricted = '';
|
|
|
|
$options = array('conditions' => array(
|
|
array('Storage.' . $this->Storage->primaryKey => $id),
|
|
$restricted
|
|
)
|
|
);
|
|
$storage = $this->Storage->find('first', $options);
|
|
$this->set(array(
|
|
'storage' => $storage,
|
|
'_serialize' => array('storage')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* add method
|
|
*
|
|
* @return void
|
|
*/
|
|
public function add() {
|
|
if ( $this->request->is('post') ) {
|
|
|
|
global $user;
|
|
$canEdit = (!$user) || ($user->System() == 'Edit');
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
return;
|
|
}
|
|
|
|
$this->Storage->create();
|
|
if ( $this->Storage->save($this->request->data) ) {
|
|
# Might be nice to send it a start request
|
|
#$this->daemonControl($this->Storage->id, 'start', $this->request->data);
|
|
return $this->flash(__('The storage area has been saved.'), array('action' => 'index'));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* edit method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function edit($id = null) {
|
|
$this->Storage->id = $id;
|
|
|
|
global $user;
|
|
$canEdit = (!$user) || ($user->System() == 'Edit');
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
return;
|
|
}
|
|
|
|
if ( !$this->Storage->exists($id) ) {
|
|
throw new NotFoundException(__('Invalid storage area'));
|
|
}
|
|
if ( $this->Storage->save($this->request->data) ) {
|
|
$message = 'Saved';
|
|
} else {
|
|
$message = 'Error';
|
|
}
|
|
|
|
$this->set(array(
|
|
'message' => $message,
|
|
'_serialize' => array('message')
|
|
));
|
|
// - restart this storage area after change
|
|
#$this->daemonControl($this->Storage->id, 'restart', $this->request->data);
|
|
}
|
|
|
|
/**
|
|
* delete method
|
|
*
|
|
* @throws NotFoundException
|
|
* @param string $id
|
|
* @return void
|
|
*/
|
|
public function delete($id = null) {
|
|
global $user;
|
|
$canEdit = (!$user) || ($user->System() == 'Edit');
|
|
if ( !$canEdit ) {
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
return;
|
|
}
|
|
|
|
$this->Storage->id = $id;
|
|
if ( !$this->Storage->exists() ) {
|
|
throw new NotFoundException(__('Invalid storage area'));
|
|
}
|
|
$this->request->allowMethod('post', 'delete');
|
|
|
|
#$this->daemonControl($this->Storage->id, 'stop');
|
|
|
|
if ( $this->Storage->delete() ) {
|
|
return $this->flash(__('The storage area has been deleted.'), array('action' => 'index'));
|
|
} else {
|
|
return $this->flash(__('The storage area could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
}
|
|
}
|
|
}
|