From 1bd9def63eb21aa2e1439d65fbfda801e87001c2 Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 23 Apr 2023 22:07:24 +0200 Subject: [PATCH] [API] Fix User variable from array to object Fix $user variable from array to object to make API work again. --- web/api/app/Controller/AppController.php | 12 ++++++------ web/api/app/Controller/CameraModelsController.php | 8 ++++---- web/api/app/Controller/EventDataController.php | 2 +- web/api/app/Controller/EventsController.php | 12 ++++++------ web/api/app/Controller/FramesController.php | 4 ++-- web/api/app/Controller/GroupsController.php | 8 ++++---- web/api/app/Controller/HostController.php | 2 +- web/api/app/Controller/LogsController.php | 8 ++++---- web/api/app/Controller/ManufacturersController.php | 8 ++++---- web/api/app/Controller/MonitorsController.php | 8 ++++---- web/api/app/Controller/ServerStatsController.php | 8 ++++---- web/api/app/Controller/ServersController.php | 8 ++++---- web/api/app/Controller/SnapshotsController.php | 8 ++++---- web/api/app/Controller/StatesController.php | 10 +++++----- web/api/app/Controller/StorageController.php | 8 ++++---- web/api/app/Controller/UserPreferenceController.php | 2 +- web/api/app/Controller/UsersController.php | 12 ++++++------ web/api/app/Controller/ZonesController.php | 10 +++++----- 18 files changed, 69 insertions(+), 69 deletions(-) diff --git a/web/api/app/Controller/AppController.php b/web/api/app/Controller/AppController.php index e952fe9a2..9cf77be39 100644 --- a/web/api/app/Controller/AppController.php +++ b/web/api/app/Controller/AppController.php @@ -92,7 +92,7 @@ class AppController extends Controller { if ( $stateful ) { zm_session_start(); $_SESSION['remoteAddr'] = $_SERVER['REMOTE_ADDR']; // To help prevent session hijacking - $_SESSION['username'] = $user['Username']; + $_SESSION['username'] = $user->Username(); if ( ZM_AUTH_RELAY == 'plain' ) { // Need to save this in session, can't use the value in User because it is hashed $_SESSION['password'] = $_REQUEST['password']; @@ -132,19 +132,19 @@ class AppController extends Controller { } } # end if token - if ( $user and ( $user['APIEnabled'] != 1 ) ) { - ZM\Error('API disabled for: '.$user['Username']); - throw new UnauthorizedException(__('API disabled for: '.$user['Username'])); + if ( $user and ( $user->APIEnabled() != 1 ) ) { + ZM\Error('API disabled for: '.$user->Username()); + throw new UnauthorizedException(__('API disabled for: '.$user->Username())); $user = null; } // We need to reject methods that are not authenticated // besides login and logout if ( strcasecmp($this->params->action, 'logout') ) { - if ( !( $user and $user['Username'] ) ) { + if ( !( $user and $user->Username() ) ) { throw new UnauthorizedException(__('Not Authenticated')); return; - } else if ( !( $user and $user['Enabled'] ) ) { + } else if ( !( $user and $user->Enabled() ) ) { throw new UnauthorizedException(__('User is not enabled')); return; } diff --git a/web/api/app/Controller/CameraModelsController.php b/web/api/app/Controller/CameraModelsController.php index 691fd0767..db66f1208 100644 --- a/web/api/app/Controller/CameraModelsController.php +++ b/web/api/app/Controller/CameraModelsController.php @@ -22,7 +22,7 @@ class CameraModelsController extends AppController { * So it has been decided for now to just let everyone read it. global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -81,7 +81,7 @@ class CameraModelsController extends AppController { if ($this->request->is('post')) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -105,7 +105,7 @@ class CameraModelsController extends AppController { $this->CameraModel->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -135,7 +135,7 @@ class CameraModelsController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/EventDataController.php b/web/api/app/Controller/EventDataController.php index 5a20e5a2d..c295c75cf 100644 --- a/web/api/app/Controller/EventDataController.php +++ b/web/api/app/Controller/EventDataController.php @@ -18,7 +18,7 @@ class EventDataController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['Events'] != 'None'); + $canView = (!$user) || ($user->Events() != 'None'); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; diff --git a/web/api/app/Controller/EventsController.php b/web/api/app/Controller/EventsController.php index c2daece16..350b4abdf 100644 --- a/web/api/app/Controller/EventsController.php +++ b/web/api/app/Controller/EventsController.php @@ -22,7 +22,7 @@ class EventsController extends AppController { public function beforeFilter() { parent::beforeFilter(); global $user; - $canView = (!$user) || ($user['Events'] != 'None'); + $canView = (!$user) || ($user->Events() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -40,7 +40,7 @@ class EventsController extends AppController { global $user; require_once __DIR__ .'/../../../includes/Event.php'; - $allowedMonitors = $user ? preg_split('@,@', $user['MonitorIds'], NULL, PREG_SPLIT_NO_EMPTY) : null; + $allowedMonitors = $user ? preg_split('@,@', $user->MonitorIds(), NULL, PREG_SPLIT_NO_EMPTY) : null; if ( $allowedMonitors ) { $mon_options = array('Event.MonitorId' => $allowedMonitors); @@ -135,7 +135,7 @@ class EventsController extends AppController { } 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; if ( $allowedMonitors ) { $mon_options = array('Event.MonitorId' => $allowedMonitors); @@ -188,7 +188,7 @@ class EventsController extends AppController { public function add() { global $user; - $canEdit = (!$user) || ($user['Events'] == 'Edit'); + $canEdit = (!$user) || ($user->Events() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -214,7 +214,7 @@ class EventsController extends AppController { public function edit($id = null) { global $user; - $canEdit = (!$user) || ($user['Events'] == 'Edit'); + $canEdit = (!$user) || ($user->Events() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -247,7 +247,7 @@ class EventsController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['Events'] == 'Edit'); + $canEdit = (!$user) || ($user->Events() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/FramesController.php b/web/api/app/Controller/FramesController.php index 4c3e46c33..bed51b7a7 100644 --- a/web/api/app/Controller/FramesController.php +++ b/web/api/app/Controller/FramesController.php @@ -19,7 +19,7 @@ class FramesController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['Events'] != 'None'); + $canView = (!$user) || ($user->Events() != 'None'); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -34,7 +34,7 @@ class FramesController extends AppController { $this->Frame->recursive = -1; 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; if ( $allowedMonitors ) { $mon_options = array('Event.MonitorId' => $allowedMonitors); } else { diff --git a/web/api/app/Controller/GroupsController.php b/web/api/app/Controller/GroupsController.php index fe83bd3b3..518e69aed 100644 --- a/web/api/app/Controller/GroupsController.php +++ b/web/api/app/Controller/GroupsController.php @@ -18,7 +18,7 @@ class GroupsController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['Groups'] != 'None'); + $canView = (!$user) || ($user->Groups() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -93,7 +93,7 @@ class GroupsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Groups'] == 'Edit'); + $canEdit = (!$user) || ($user->Groups() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -134,7 +134,7 @@ class GroupsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Groups'] == 'Edit'); + $canEdit = (!$user) || ($user->Groups() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -176,7 +176,7 @@ class GroupsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Groups'] == 'Edit'); + $canEdit = (!$user) || ($user->Groups() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index ac4d68aec..2d40320d1 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -37,7 +37,7 @@ class HostController extends AppController { } else { $permission = 'Edit'; } - $allowed = (!$user) || ($user['System'] == $permission ); + $allowed = (!$user) || ($user->System() == $permission ); if ( !$allowed ) { throw new UnauthorizedException(__("Insufficient privileges")); return; diff --git a/web/api/app/Controller/LogsController.php b/web/api/app/Controller/LogsController.php index 126dec861..776dd9abe 100644 --- a/web/api/app/Controller/LogsController.php +++ b/web/api/app/Controller/LogsController.php @@ -24,7 +24,7 @@ class LogsController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -66,7 +66,7 @@ class LogsController extends AppController { */ public function add() { global $user; - $canAdd = (!$user) || (($user['System'] == 'Edit') || ZM_LOG_INJECT); + $canAdd = (!$user) || (($user->System() == 'Edit') || ZM_LOG_INJECT); if (!$canAdd) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -88,7 +88,7 @@ class LogsController extends AppController { */ public function edit($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -115,7 +115,7 @@ class LogsController extends AppController { * @return void */ public function delete($id = null) { - $canDelete = (!$user) || ($user['System'] == 'Edit'); + $canDelete = (!$user) || ($user->System() == 'Edit'); if (!$canDelete) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/ManufacturersController.php b/web/api/app/Controller/ManufacturersController.php index 0249af6af..e389427a4 100644 --- a/web/api/app/Controller/ManufacturersController.php +++ b/web/api/app/Controller/ManufacturersController.php @@ -22,7 +22,7 @@ class ManufacturersController extends AppController { * So it has been decided for now to just let everyone read it. global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -81,7 +81,7 @@ class ManufacturersController extends AppController { if ( $this->request->is('post') ) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -107,7 +107,7 @@ class ManufacturersController extends AppController { $this->Manufacturer->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -139,7 +139,7 @@ class ManufacturersController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index b1a229738..4ae2ba38c 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -106,7 +106,7 @@ class MonitorsController extends AppController { if ( $this->request->is('post') ) { global $user; - $canAdd = (!$user) || ($user['System'] == 'Edit' ); + $canAdd = (!$user) || ($user->System() == 'Edit' ); if ( !$canAdd ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -189,7 +189,7 @@ class MonitorsController extends AppController { throw new NotFoundException(__('Invalid monitor')); } global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -277,9 +277,9 @@ class MonitorsController extends AppController { $password = $_SESSION['password']; } - $auth = ' -U ' .$user['Username'].' -P '.$password; + $auth = ' -U ' .$user->Username().' -P '.$password; } else if (ZM_AUTH_RELAY == 'none') { - $auth = ' -U ' .$user['Username']; + $auth = ' -U ' .$user->Username(); } } diff --git a/web/api/app/Controller/ServerStatsController.php b/web/api/app/Controller/ServerStatsController.php index 70cff5122..80d639aa6 100644 --- a/web/api/app/Controller/ServerStatsController.php +++ b/web/api/app/Controller/ServerStatsController.php @@ -22,7 +22,7 @@ class ServerStatsController extends AppController { * So it has been decided for now to just let everyone read it. global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -80,7 +80,7 @@ class ServerStatsController extends AppController { public function add() { if ( $this->request->is('post') ) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -104,7 +104,7 @@ class ServerStatsController extends AppController { $this->ServerStat->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -134,7 +134,7 @@ class ServerStatsController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/ServersController.php b/web/api/app/Controller/ServersController.php index bbde27fae..df7fa6cd5 100644 --- a/web/api/app/Controller/ServersController.php +++ b/web/api/app/Controller/ServersController.php @@ -22,7 +22,7 @@ class ServersController extends AppController { * So it has been decided for now to just let everyone read it. global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -81,7 +81,7 @@ class ServersController extends AppController { if ( $this->request->is('post') ) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -105,7 +105,7 @@ class ServersController extends AppController { $this->Server->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -135,7 +135,7 @@ class ServersController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/SnapshotsController.php b/web/api/app/Controller/SnapshotsController.php index 15d5f7a9a..0214545a1 100644 --- a/web/api/app/Controller/SnapshotsController.php +++ b/web/api/app/Controller/SnapshotsController.php @@ -18,7 +18,7 @@ class SnapshotsController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['Snapshots'] != 'None'); + $canView = (!$user) || ($user->Snapshots() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -93,7 +93,7 @@ class SnapshotsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Snapshots'] == 'Edit'); + $canEdit = (!$user) || ($user->Snapshots() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -134,7 +134,7 @@ class SnapshotsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Snapshots'] == 'Edit'); + $canEdit = (!$user) || ($user->Snapshots() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -176,7 +176,7 @@ class SnapshotsController extends AppController { global $user; # We already tested for auth in appController, # so we just need to test for specific permission - $canEdit = (!$user) || ($user['Snapshots'] == 'Edit'); + $canEdit = (!$user) || ($user->Snapshots() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; diff --git a/web/api/app/Controller/StatesController.php b/web/api/app/Controller/StatesController.php index b96efe0aa..f3f010ab2 100644 --- a/web/api/app/Controller/StatesController.php +++ b/web/api/app/Controller/StatesController.php @@ -14,7 +14,7 @@ public $components = array('RequestHandler'); public function beforeFilter() { parent::beforeFilter(); global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -60,7 +60,7 @@ public function add() { if ($this->request->is('post')) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -86,7 +86,7 @@ public function edit($id = null) { } global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -112,7 +112,7 @@ public function edit($id = null) { public function delete($id = null) { $this->State->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -131,7 +131,7 @@ public function delete($id = null) { public function change() { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/StorageController.php b/web/api/app/Controller/StorageController.php index 5450b4582..07ef9b70d 100644 --- a/web/api/app/Controller/StorageController.php +++ b/web/api/app/Controller/StorageController.php @@ -18,7 +18,7 @@ class StorageController extends AppController { public function beforeFilter() { parent::beforeFilter(); global $user; - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -84,7 +84,7 @@ class StorageController extends AppController { if ( $this->request->is('post') ) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -110,7 +110,7 @@ class StorageController extends AppController { $this->Storage->id = $id; global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; @@ -142,7 +142,7 @@ class StorageController extends AppController { */ public function delete($id = null) { global $user; - $canEdit = (!$user) || ($user['System'] == 'Edit'); + $canEdit = (!$user) || ($user->System() == 'Edit'); if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient privileges')); return; diff --git a/web/api/app/Controller/UserPreferenceController.php b/web/api/app/Controller/UserPreferenceController.php index 6f06d56a8..9ad9b8c4f 100644 --- a/web/api/app/Controller/UserPreferenceController.php +++ b/web/api/app/Controller/UserPreferenceController.php @@ -18,7 +18,7 @@ class UserPreferenceController extends AppController { parent::beforeFilter(); global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['Users'] != 'None'); + $canView = (!$user) || ($user->Users() != 'None'); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; diff --git a/web/api/app/Controller/UsersController.php b/web/api/app/Controller/UsersController.php index 7096da669..39dc98e02 100644 --- a/web/api/app/Controller/UsersController.php +++ b/web/api/app/Controller/UsersController.php @@ -19,7 +19,7 @@ class UsersController extends AppController { global $user; # We already tested for auth in appController, so we just need to test for specific permission - $canView = (!$user) || ($user['System'] != 'None'); + $canView = (!$user) || ($user->System() != 'None'); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -36,7 +36,7 @@ class UsersController extends AppController { global $user; # We should actually be able to list our own user, but I'm not bothering at this time. - if ($user['System'] == 'None' ) { + if ($user->System() == 'None' ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; } @@ -57,7 +57,7 @@ class UsersController extends AppController { global $user; # We can view ourselves - $canView = ($user['System'] != 'None') or ($user['Id'] == $id); + $canView = ($user->System() != 'None') or ($user->Id() == $id); if (!$canView) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -84,7 +84,7 @@ class UsersController extends AppController { public function add() { if ($this->request->is('post')) { global $user; - if ($user['System'] != 'Edit') { + if ($user->System() != 'Edit') { throw new UnauthorizedException(__('Insufficient Privileges')); return; } @@ -120,7 +120,7 @@ class UsersController extends AppController { $this->User->id = $id; global $user; - $canEdit = ($user['System'] == 'Edit') or (($user['Id'] == $id) and ZM_USER_SELF_EDIT); + $canEdit = ($user->System() == 'Edit') or (($user->Id() == $id) and ZM_USER_SELF_EDIT); if (!$canEdit) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -164,7 +164,7 @@ class UsersController extends AppController { global $user; # Can't delete ourselves - if ( ($user['System'] != 'Edit') or ($user['Id'] == $id) ) { + if ( ($user->System() != 'Edit') or ($user->Id() == $id) ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; } diff --git a/web/api/app/Controller/ZonesController.php b/web/api/app/Controller/ZonesController.php index 37cc6a8a5..f42904f9a 100644 --- a/web/api/app/Controller/ZonesController.php +++ b/web/api/app/Controller/ZonesController.php @@ -18,7 +18,7 @@ class ZonesController extends AppController { parent::beforeFilter(); global $user; - $canView = (!$user) || ($user['Monitors'] != 'None'); + $canView = (!$user) || ($user->Monitors() != 'None'); if ( !$canView ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -45,7 +45,7 @@ class ZonesController extends AppController { $this->Zone->recursive = -1; 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; if ( $allowedMonitors ) { $mon_options = array('Zones.MonitorId' => $allowedMonitors); } else { @@ -71,7 +71,7 @@ class ZonesController extends AppController { } global $user; - $canEdit = (!$user) || $user['Monitors'] == 'Edit'; + $canEdit = (!$user) || $user->Monitors() == 'Edit'; if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -118,7 +118,7 @@ class ZonesController extends AppController { $message = ''; if ( $this->request->is(array('post', 'put')) ) { global $user; - $canEdit = (!$user) || $user['Monitors'] == 'Edit'; + $canEdit = (!$user) || $user->Monitors() == 'Edit'; if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return; @@ -149,7 +149,7 @@ class ZonesController extends AppController { } $this->request->allowMethod('post', 'delete'); global $user; - $canEdit = (!$user) || $user['Monitors'] == 'Edit'; + $canEdit = (!$user) || $user->Monitors() == 'Edit'; if ( !$canEdit ) { throw new UnauthorizedException(__('Insufficient Privileges')); return;