diff options
Diffstat (limited to 'modules-available/runmode/page.inc.php')
-rw-r--r-- | modules-available/runmode/page.inc.php | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php index f8b48152..5654456a 100644 --- a/modules-available/runmode/page.inc.php +++ b/modules-available/runmode/page.inc.php @@ -30,7 +30,7 @@ class Page_RunMode extends Page $module = Request::post('module', false, 'string'); $modeId = Request::post('modeid', false, 'string'); $modConfig = RunMode::getModuleConfig($module); - if ($modConfig === false) { + if ($modConfig === null) { Message::addError('runmode.module-hasnt-runmode', $module); return; } @@ -70,7 +70,7 @@ class Page_RunMode extends Page if ($oldMachineMode !== false) { $machineLocation = $oldMachineMode['locationid']; $oldModule = RunMode::getModuleConfig($oldMachineMode['module']); - if ($oldModule !== false) { + if ($oldModule !== null) { if ($oldMachineMode['module'] !== $module || $oldMachineMode['modeid'] !== $modeId) { if (!$oldModule->allowGenericEditor || $oldModule->deleteUrlSnippet !== false) { Message::addError('runmode.machine-still-assigned', $machine, $oldMachineMode['module']); @@ -87,7 +87,7 @@ class Page_RunMode extends Page } else { // Not existing, no old mode - query machine to get location, so we can do a perm-check for new loc $m = Statistics::getMachine($machine, Machine::NO_DATA); - if ($m !== false) { + if ($m !== null) { $machineLocation = $m->locationid; } } @@ -134,7 +134,7 @@ class Page_RunMode extends Page return; } $modConfig = RunMode::getModuleConfig($mode['module']); - if ($modConfig === false) { + if ($modConfig === null) { Message::addError('module-hasnt-runmode', $mode['moduleName']); return; } @@ -172,7 +172,7 @@ class Page_RunMode extends Page } $module->activate(1, false); $config = RunMode::getModuleConfig($moduleId); - if ($config === false) { + if ($config === null) { Message::addError('module-hasnt-runmode', $moduleId); Util::redirect('?do=runmode'); } @@ -187,7 +187,6 @@ class Page_RunMode extends Page if (!$config->userHasPermission(null) && !User::hasPermission('list-all')) { Message::addError('main.no-permission'); Util::redirect('?do=runmode'); - return; } // Show list of machines with assigned mode for this module $this->renderClientList($moduleId); @@ -198,19 +197,24 @@ class Page_RunMode extends Page { if ($onlyModule === false) { $where = ''; + $args = []; } else { $where = ' AND r.module = :moduleId '; + $args = ['moduleId' => $onlyModule]; } $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, r.module, r.modeid, r.isclient" . " FROM runmode r" . " INNER JOIN machine m ON (m.machineuuid = r.machineuuid $where )" - . " ORDER BY m.hostname ASC, m.clientip ASC", array('moduleId' => $onlyModule)); + . " ORDER BY m.hostname ASC, m.clientip ASC", $args); $modules = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (!isset($modules[$row['module']])) { if (!Module::isAvailable($row['module'])) continue; - $modules[$row['module']] = array('config' => RunMode::getModuleConfig($row['module']), 'list' => array()); + $config = RunMode::getModuleConfig($row['module']); + if ($config === null) + continue; + $modules[$row['module']] = array('config' => $config, 'list' => array()); } if (empty($row['hostname'])) { $row['hostname'] = $row['clientip']; @@ -220,17 +224,20 @@ class Page_RunMode extends Page } $modules[$row['module']]['list'][] = $row; } + $anythingOk = false; foreach ($modules as $moduleId => $rows) { + $disabled = ''; if ($onlyModule === false) { // Permissions - not required if rendering specific module, since it's been already done - if ($rows['config']->userHasPermission(null)) { - $disabled = ''; - } elseif (User::hasPermission('list-all')) { + // in $this->renderModule() + /** @var array{config: RunModeModuleConfig} $rows */ + if (!$rows['config']->userHasPermission(null)) { + if (!User::hasPermission('list-all')) + continue; $disabled = 'disabled'; - } else { - continue; } // </Permissions> } + $anythingOk = true; $module = Module::get($moduleId); if ($module === false) continue; @@ -239,19 +246,17 @@ class Page_RunMode extends Page 'list' => $rows['list'], 'modulename' => $module->getDisplayName(), 'module' => $moduleId, - 'canedit' => $config !== false && $config->allowGenericEditor && $config->deleteUrlSnippet === false, + 'canedit' => $config !== null && $config->allowGenericEditor && $config->deleteUrlSnippet === false, 'deleteUrl' => $config->deleteUrlSnippet, 'disabled' => $disabled, )); } + if (!empty($modules) && !$anythingOk) { + User::assertPermission('list-all'); + } } - /** - * @param \Module $module - * @param string $modeId - * @param \RunModeModuleConfig $config - */ - private function renderModuleMode($module, $modeId, $config) + private function renderModuleMode(Module $module, string $modeId, RunModeModuleConfig $config) { $moduleId = $module->getIdentifier(); $modeName = RunMode::getModeName($moduleId, $modeId); @@ -275,7 +280,6 @@ class Page_RunMode extends Page } else { Message::addError('main.no-permission'); Util::redirect('?do=runmode'); - return; } $machines = RunMode::getForMode($module, $modeId, true); if ($config->permission !== false) { @@ -309,7 +313,7 @@ class Page_RunMode extends Page $config = RunMode::getModuleConfig(Request::any('module', '', 'string')); $returnObject = ['machines' => []]; - if ($config !== false) { + if ($config !== null) { $params = ['query' => "%$query%"]; if ($config->permission === false) { // Global @@ -333,7 +337,7 @@ class Page_RunMode extends Page LIMIT 100", $params); $returnObject = [ - 'machines' => $result->fetchAll(PDO::FETCH_ASSOC) + 'machines' => $result->fetchAll() ]; } } |