From acd63d1b88bf8605b3ef0f05ce9a2e25e10abcd0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Dec 2022 15:46:50 +0100 Subject: [remoteaccess] Add list of active locations to overview page References #3767 --- .../remoteaccess/lang/de/template-tags.json | 3 ++ .../remoteaccess/lang/en/template-tags.json | 3 ++ modules-available/remoteaccess/page.inc.php | 54 ++++++++++++++++++---- .../remoteaccess/templates/edit-settings.html | 31 +++++++++++++ 4 files changed, 82 insertions(+), 9 deletions(-) (limited to 'modules-available/remoteaccess') diff --git a/modules-available/remoteaccess/lang/de/template-tags.json b/modules-available/remoteaccess/lang/de/template-tags.json index bc9ef969..1a502a6b 100644 --- a/modules-available/remoteaccess/lang/de/template-tags.json +++ b/modules-available/remoteaccess/lang/de/template-tags.json @@ -9,7 +9,10 @@ "lang_groupListText": "Liste verf\u00fcgbarer Gruppen (\"virtuelle R\u00e4ume\")", "lang_groups": "Gruppen", "lang_keepAvailableWol": "WoL#", + "lang_location": "Ort", "lang_locationSelectionText": "Ausgew\u00e4hlte Orte werden in den Remote-Modus geschaltet (beim n\u00e4chsten Boot des Clients) und sind damit im Pool f\u00fcr den Fernzugriff.", + "lang_locations": "Konfigurierte Orte", + "lang_locationsInUse": "Liste der Orte, die in mindestens einer Gruppe verwendet werden", "lang_numLocs": "R\u00e4ume", "lang_pluginVersion": "Plugin-Version", "lang_pluginVersionOldOrUnknown": "Unbekannt oder zu alt", diff --git a/modules-available/remoteaccess/lang/en/template-tags.json b/modules-available/remoteaccess/lang/en/template-tags.json index 87dc8161..037550e4 100644 --- a/modules-available/remoteaccess/lang/en/template-tags.json +++ b/modules-available/remoteaccess/lang/en/template-tags.json @@ -9,7 +9,10 @@ "lang_groupListText": "Available groups (\"virtual locations\")", "lang_groups": "Groups", "lang_keepAvailableWol": "WoL#", + "lang_location": "Location", "lang_locationSelectionText": "Clients in the selected locations will start the remoteaccess-mode after the next reboot.", + "lang_locations": "Configured locations", + "lang_locationsInUse": "List of locations that are active in at least one group", "lang_numLocs": "Locations", "lang_pluginVersion": "Plugin version", "lang_pluginVersionOldOrUnknown": "Unknown or too old", diff --git a/modules-available/remoteaccess/page.inc.php b/modules-available/remoteaccess/page.inc.php index fa94e193..ee9305dc 100644 --- a/modules-available/remoteaccess/page.inc.php +++ b/modules-available/remoteaccess/page.inc.php @@ -105,6 +105,36 @@ class Page_RemoteAccess extends Page ]; $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 @@ -117,19 +147,11 @@ class Page_RemoteAccess extends Page $locationList[$lid]['checked'] = 'checked'; } } - $scheduler = Module::isAvailable('rebootcontrol'); + $this->addSchedulerTags($locationList); foreach ($locationList as $lid => &$loc) { if (!in_array($lid, $allowed)) { $loc['disabled'] = 'disabled'; } - if ($scheduler) { - $options = Scheduler::getLocationOptions($lid); - if ($options['ra-mode'] === Scheduler::RA_SELECTIVE) { - $loc['ra_selective'] = true; - } elseif ($options['ra-mode'] === Scheduler::RA_NEVER) { - $loc['ra_never'] = true; - } - } } $data = [ 'groupid' => $groupid, @@ -157,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; + } + } + } + } diff --git a/modules-available/remoteaccess/templates/edit-settings.html b/modules-available/remoteaccess/templates/edit-settings.html index a14bac45..4c4c011a 100644 --- a/modules-available/remoteaccess/templates/edit-settings.html +++ b/modules-available/remoteaccess/templates/edit-settings.html @@ -109,3 +109,34 @@
+ +

{{lang_locations}}

+ +

{{lang_locationsInUse}}

+ + + + + + + + + + {{#locations}} + + + + + {{/locations}} + +
{{lang_location}}{{lang_groups}}
+ {{locationname}} + {{#ra_never}} + + {{/ra_never}} + {{#ra_selective}} + + {{/ra_selective}} + {{#groups}} + [{{groupname}}] + {{/groups}}
\ No newline at end of file -- cgit v1.2.3-55-g7522