diff options
Diffstat (limited to 'modules-available/rebootcontrol/pages')
4 files changed, 59 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 7d1877d2..d9aae234 100644 --- a/modules-available/rebootcontrol/pages/jumphost.inc.php +++ b/modules-available/rebootcontrol/pages/jumphost.inc.php @@ -28,10 +28,16 @@ class SubPage self::execCheckConnection($id); return; } + $id = Request::post('deleteid', false, 'int'); + if ($id !== false) { + User::assertPermission('jumphost.edit'); + self::deleteJumphost($id); + } } private static function execCheckConnection($hostid) { + // Permcheck in caller $host = self::getJumpHost($hostid); $task = RebootControl::wakeViaJumpHost($host, '255.255.255.255', [['macaddr' => '00:11:22:33:44:55']]); if (!Taskmanager::isTask($task)) @@ -39,6 +45,14 @@ class SubPage Util::redirect('?do=rebootcontrol&show=task&type=checkhost&what=task&taskid=' . $task['id']); } + private static function deleteJumphost($hostid) + { + // Permcheck in caller + $host = self::getJumpHost($hostid); + Database::exec('DELETE FROM reboot_jumphost WHERE hostid = :hostid LIMIT 1', ['hostid' => $hostid]); + Message::addSuccess('jumphost-deleted', $host['host']); + } + private static function saveJumpHost() { User::assertPermission('jumphost.edit'); @@ -120,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 = [ @@ -173,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 45151954..a6d8d837 100644 --- a/modules-available/rebootcontrol/pages/subnet.inc.php +++ b/modules-available/rebootcontrol/pages/subnet.inc.php @@ -10,6 +10,8 @@ class SubPage self::addSubnet(); } elseif ($action === 'edit') { self::editSubnet(); + } elseif ($action === 'delete') { + self::deleteSubnet(); } } @@ -22,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; } @@ -59,7 +61,7 @@ class SubPage if (User::hasPermission('jumphost.assign-subnet')) { $hosts = Request::post('jumphost', [], 'array'); if (empty($hosts)) { - Database::exec('DELETE FROM reboot_jumphost_x_subnet WHERE subnetid = :id AND', ['id' => $id]); + Database::exec('DELETE FROM reboot_jumphost_x_subnet WHERE subnetid = :id', ['id' => $id]); } else { $hosts = array_keys($hosts); Database::exec('DELETE FROM reboot_jumphost_x_subnet WHERE subnetid = :id AND hostid NOT IN (:hosts)', @@ -73,6 +75,19 @@ class SubPage Message::addSuccess('subnet-updated'); } + private static function deleteSubnet() + { + User::assertPermission('subnet.edit'); + User::assertPermission('subnet.flag'); + $id = Request::post('id', Request::REQUIRED, 'int'); + $num = Database::exec('DELETE FROM reboot_subnet WHERE subnetid = :id', ['id' => $id]); + if ($num < 1) { + Message::addError('invalid-subnet', $id); + return; + } + Message::addSuccess('subnet-deleted'); + } + /* * Render */ @@ -91,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 @@ -99,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]; @@ -130,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; - } -} |