diff options
Diffstat (limited to 'modules-available/remoteaccess/page.inc.php')
-rw-r--r-- | modules-available/remoteaccess/page.inc.php | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/modules-available/remoteaccess/page.inc.php b/modules-available/remoteaccess/page.inc.php index 68781ffa..ba248b4d 100644 --- a/modules-available/remoteaccess/page.inc.php +++ b/modules-available/remoteaccess/page.inc.php @@ -29,10 +29,10 @@ class Page_RemoteAccess extends Page Database::exec("UPDATE remoteaccess_group SET groupname = :name, wolcount = :wol, passwd = :passwd, active = :active WHERE groupid = :id", [ 'id' => $id, - 'name' => isset($group['groupname']) ? $group['groupname'] : $id, - 'wol' => isset($group['wolcount']) ? $group['wolcount'] : 0, - 'passwd' => isset($group['passwd']) ? $group['passwd'] : 0, - 'active' => isset($group['active']) && $group['active'] ? 1 : 0, + 'name' => $group['groupname'] ?? $id, + 'wol' => $group['wolcount'] ?? 0, + 'passwd' => $group['passwd'] ?? 0, + 'active' => (int)($group['active'] ?? 0), ]); } Message::addSuccess('settings-saved'); @@ -40,6 +40,7 @@ class Page_RemoteAccess extends Page User::assertPermission('set-proxy-ip'); Property::set(RemoteAccess::PROP_ALLOWED_VNC_NET, Request::post('allowed-source', '', 'string')); Property::set(RemoteAccess::PROP_TRY_VIRT_HANDOVER, Request::post('virt-handover', false, 'int')); + Property::set(RemoteAccess::PROP_VNC_PORT, Request::post('vncport', 5900, 'int')); Message::addSuccess('settings-saved'); } elseif ($action === 'delete-group') { User::assertPermission('group.edit'); @@ -91,28 +92,62 @@ class Page_RemoteAccess extends Page if ($groupid === false) { // Edit list of groups and their settings $groups = Database::queryAll("SELECT g.groupid, g.groupname, g.wolcount, g.passwd, - Count(l.locationid) AS locs, If(g.active, 'checked', '') AS checked - FROM remoteaccess_group g LEFT JOIN remoteaccess_x_location l USING (groupid) + Count(l.locationid) AS locs, If(g.active, 'checked', '') AS checked, unwoken + FROM remoteaccess_group g + LEFT JOIN remoteaccess_x_location l USING (groupid) GROUP BY g.groupid, g.groupname ORDER BY g.groupname ASC"); $data = [ 'allowed-source' => Property::get(RemoteAccess::PROP_ALLOWED_VNC_NET), 'virt-handover_checked' => Property::get(RemoteAccess::PROP_TRY_VIRT_HANDOVER) ? 'checked' : '', + 'vncport' => Property::get(RemoteAccess::PROP_VNC_PORT, 5900), 'groups' => $groups, ]; + $data['plugin_version'] = Property::get(RemoteAccess::PROP_PLUGIN_VERSION); Permission::addGlobalTags($data['perms'], null, ['group.locations', 'group.add', 'group.edit', 'set-proxy-ip']); + // List of locations used in at least one group + $res = Database::simpleQuery("SELECT l.locationid, l.locationname, g.groupid, g.groupname, g.active + FROM location l + INNER JOIN remoteaccess_x_location rxl USING (locationid) + INNER JOIN remoteaccess_group g USING (groupid) + ORDER BY locationname, locationid"); + $data['locations'] = []; + $last = null; + foreach ($res as $row) { + if ($last === null || $last['locationid'] !== $row['locationid']) { + unset($last); + $last = [ + 'locationid' => $row['locationid'], + 'locationname' => $row['locationname'], + 'lclass' => 'slx-strike', + 'groups' => [], + ]; + $data['locations'][] =& $last; + } + $last['groups'][] = [ + 'groupid' => $row['groupid'], + 'groupname' => $row['groupname'], + 'gclass' => $row['active'] ? '' : 'slx-strike', + ]; + if ($row['active']) { + $last['lclass'] = ''; + } + } + unset($last); + $this->addSchedulerTags($data['locations']); Render::addTemplate('edit-settings', $data); } else { // Edit locations for group $group = $this->groupNameOrFail($groupid); $locationList = Location::getLocationsAssoc(); - $enabled = RemoteAccess::getEnabledLocations($groupid); + $enabled = RemoteAccess::getEnabledLocations($groupid, false); $allowed = User::getAllowedLocations('group.locations'); foreach ($enabled as $lid) { if (isset($locationList[$lid])) { $locationList[$lid]['checked'] = 'checked'; } } + $this->addSchedulerTags($locationList); foreach ($locationList as $lid => &$loc) { if (!in_array($lid, $allowed)) { $loc['disabled'] = 'disabled'; @@ -133,7 +168,7 @@ class Page_RemoteAccess extends Page * @param int $groupid group to check * @return bool if we have permission for all the locations assigned to group */ - private function checkGroupLocations($groupid) + private function checkGroupLocations(int $groupid): bool { $allowed = User::getAllowedLocations('group.locations'); if (in_array(0, $allowed)) @@ -144,4 +179,18 @@ class Page_RemoteAccess extends Page return empty($diff); } + private function addSchedulerTags(array &$locationList) + { + if (!Module::isAvailable('rebootcontrol')) + return; + foreach ($locationList as $lid => &$loc) { + $options = Scheduler::getLocationOptions($loc['locationid'] ?? $lid); + if ($options['ra-mode'] === Scheduler::RA_SELECTIVE) { + $loc['ra_selective'] = true; + } elseif ($options['ra-mode'] === Scheduler::RA_NEVER) { + $loc['ra_never'] = true; + } + } + } + } |