diff options
Diffstat (limited to 'modules-available/rebootcontrol/pages')
4 files changed, 29 insertions, 26 deletions
diff --git a/modules-available/rebootcontrol/pages/exec.inc.php b/modules-available/rebootcontrol/pages/exec.inc.php index e5fe3cd8..6b5ea407 100644 --- a/modules-available/rebootcontrol/pages/exec.inc.php +++ b/modules-available/rebootcontrol/pages/exec.inc.php @@ -46,7 +46,6 @@ class SubPage return; } Session::set('exec-' . $id, false); - Session::save(); Render::addTemplate('exec-enter-command', ['clients' => $machines, 'id' => $id]); } diff --git a/modules-available/rebootcontrol/pages/jumphost.inc.php b/modules-available/rebootcontrol/pages/jumphost.inc.php index bf0a67e2..d9aae234 100644 --- a/modules-available/rebootcontrol/pages/jumphost.inc.php +++ b/modules-available/rebootcontrol/pages/jumphost.inc.php @@ -32,7 +32,6 @@ class SubPage if ($id !== false) { User::assertPermission('jumphost.edit'); self::deleteJumphost($id); - return; } } @@ -135,7 +134,7 @@ class SubPage LEFT JOIN reboot_jumphost_x_subnet jxs USING (hostid) GROUP BY hostid ORDER BY hostid'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $hosts[] = $row; } $data = [ @@ -188,7 +187,7 @@ class SubPage ORDER BY start ASC', ['id' => $id]); $list = []; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']); if ($row['hostid'] !== null) { $row['checked'] = 'checked'; diff --git a/modules-available/rebootcontrol/pages/subnet.inc.php b/modules-available/rebootcontrol/pages/subnet.inc.php index cbd5d8f2..a6d8d837 100644 --- a/modules-available/rebootcontrol/pages/subnet.inc.php +++ b/modules-available/rebootcontrol/pages/subnet.inc.php @@ -24,7 +24,7 @@ class SubPage User::assertPermission('subnet.edit'); $cidr = Request::post('cidr', Request::REQUIRED, 'string'); $range = IpUtil::parseCidr($cidr); - if ($range === false) { + if ($range === null) { Message::addError('invalid-cidr', $cidr); return; } @@ -106,6 +106,7 @@ class SubPage { User::assertPermission('subnet.*'); $nets = []; + $c2c = Property::get(RebootControl::KEY_SCAN_CLIENT_TO_CLIENT); $res = Database::simpleQuery('SELECT subnetid, start, end, fixed, isdirect, nextdirectcheck, lastseen, seencount, Count(hxs.hostid) AS jumphostcount, Count(sxs.srcid) AS sourcecount FROM reboot_subnet s @@ -114,12 +115,15 @@ class SubPage GROUP BY subnetid, start, end ORDER BY start ASC, end DESC'); $deadline = strtotime('-60 days'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']); $row['lastseen_s'] = Util::prettyTime($row['lastseen']); if ($row['lastseen'] && $row['lastseen'] < $deadline) { $row['lastseen_class'] = 'text-danger'; } + if (!$c2c) { + $row['sourcecount'] = '-'; + } $nets[] = $row; } $data = ['subnets' => $nets]; @@ -145,20 +149,24 @@ class SubPage ORDER BY h.host ASC', ['id' => $id]); // Mark those assigned to the current subnet $jh = []; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $row['checked'] = $row['subnetid'] === null ? '' : 'checked'; $jh[] = $row; } $subnet['jumpHosts'] = $jh; - // Get list of all subnets that can broadcast into this one - $res = Database::simpleQuery('SELECT s.start, s.end FROM reboot_subnet s + $c2c = Property::get(RebootControl::KEY_SCAN_CLIENT_TO_CLIENT); + if ($c2c) { + // Get list of all subnets that can broadcast into this one + $res = Database::simpleQuery('SELECT s.start, s.end FROM reboot_subnet s INNER JOIN reboot_subnet_x_subnet sxs ON (s.subnetid = sxs.srcid AND sxs.dstid = :id AND sxs.reachable = 1) ORDER BY s.start ASC', ['id' => $id]); - $sn = []; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $sn[] = ['cidr' => IpUtil::rangeToCidr($row['start'], $row['end'])]; + $sn = []; + foreach ($res as $row) { + $sn[] = ['cidr' => IpUtil::rangeToCidr($row['start'], $row['end'])]; + } + $subnet['sourceNets'] = $sn; + $subnet['showC2C'] = true; } - $subnet['sourceNets'] = $sn; Permission::addGlobalTags($subnet['perms'], null, ['subnet.flag', 'jumphost.view', 'jumphost.assign-subnet']); Render::addTemplate('subnet-edit', $subnet); } diff --git a/modules-available/rebootcontrol/pages/task.inc.php b/modules-available/rebootcontrol/pages/task.inc.php index 691fd9e2..7db2a90b 100644 --- a/modules-available/rebootcontrol/pages/task.inc.php +++ b/modules-available/rebootcontrol/pages/task.inc.php @@ -26,6 +26,8 @@ class SubPage private static function showTask() { + // No permission check here - user had to guess the UUID, not very likely, + // but this way we can still link to some implicitly triggered job $taskid = Request::get("taskid", Request::REQUIRED, 'string'); $type = Request::get('type', false, 'string'); if ($type === 'checkhost') { @@ -93,8 +95,9 @@ class SubPage } elseif ($type === RebootControl::TASK_WOL) { // Nothing (yet) } else { - Util::traceError('oopsie'); + ErrorHandler::traceError('oopsie'); } + $job['timestamp_s'] = Util::prettyTime($job['timestamp']); Render::addTemplate('status-' . $template, $job); } @@ -103,6 +106,9 @@ class SubPage Render::addTemplate('task-header'); // Append list of active reboot/shutdown tasks $allowedLocs = User::getAllowedLocations("action.*"); + if (empty($allowedLocs)) { + User::assertPermission('action.*'); + } $active = RebootControl::getActiveTasks($allowedLocs); if (empty($active)) { Message::addInfo('no-current-tasks'); @@ -112,8 +118,10 @@ class SubPage if (isset($entry['clients'])) { $entry['clients'] = count($entry['clients']); } + $entry['timestamp_s'] = Util::prettyTime($entry['timestamp']); } unset($entry); + ArrayUtil::sortByColumn($active, 'timestamp', SORT_ASC, SORT_NUMERIC); Render::addTemplate('task-list', ['list' => $active]); } } @@ -121,7 +129,7 @@ class SubPage private static function expandLocationIds(&$lids) { foreach ($lids as &$locid) { - if ($locid === 0) { + if ($locid === null || $locid === 0) { $name = '-'; } else { $name = Location::getName($locid); @@ -137,14 +145,3 @@ class SubPage } } - - -// Remove when we require >= 7.3.0 -if (!function_exists('array_key_first')) { - function array_key_first(array $arr) { - foreach($arr as $key => $unused) { - return $key; - } - return NULL; - } -} |