From 4c9aba92942c4b9341c46a50aeaa31bea24a8b60 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 9 Jan 2018 17:38:21 +0100 Subject: [exams] implemented permission system --- .../rebootcontrol/lang/de/permissions.json | 5 ++ .../rebootcontrol/lang/en/permissions.json | 5 ++ modules-available/rebootcontrol/page.inc.php | 66 +++++++++++++--- .../rebootcontrol/permissions/permissions.json | 5 ++ .../rebootcontrol/templates/_page.html | 90 +++++++++++----------- 5 files changed, 117 insertions(+), 54 deletions(-) create mode 100644 modules-available/rebootcontrol/lang/de/permissions.json create mode 100644 modules-available/rebootcontrol/lang/en/permissions.json create mode 100644 modules-available/rebootcontrol/permissions/permissions.json (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/lang/de/permissions.json b/modules-available/rebootcontrol/lang/de/permissions.json new file mode 100644 index 00000000..92eeb37e --- /dev/null +++ b/modules-available/rebootcontrol/lang/de/permissions.json @@ -0,0 +1,5 @@ +{ + "shutdown": "Client herunterfahren.", + "reboot": "Client neustarten.", + "newkeypair": "Neues Schlüsselpaar generieren." +} \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/en/permissions.json b/modules-available/rebootcontrol/lang/en/permissions.json new file mode 100644 index 00000000..077890fb --- /dev/null +++ b/modules-available/rebootcontrol/lang/en/permissions.json @@ -0,0 +1,5 @@ +{ + "shutdown": "Shutdown Client.", + "reboot": "Reboot Client.", + "newkeypair": "Generate new Keypair." +} \ No newline at end of file diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index fc3ded8f..fa34a05a 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -4,6 +4,9 @@ class Page_RebootControl extends Page { private $action = false; + private $allowedShutdownLocs = []; + private $allowedRebootLocs = []; + private $allowedLocs = []; /** * Called before any page rendering happens - early hook to check parameters etc. @@ -17,21 +20,40 @@ class Page_RebootControl extends Page Util::redirect('?do=Main'); // does not return } + $this->allowedShutdownLocs = User::getAllowedLocations("shutdown"); + $this->allowedRebootLocs = User::getAllowedLocations("reboot"); + $this->allowedLocs = array_unique(array_merge($this->allowedShutdownLocs, $this->allowedRebootLocs)); + $this->action = Request::any('action', 'show', 'string'); if ($this->action === 'startReboot' || $this->action === 'startShutdown') { - $clients = Request::post('clients'); - if (!is_array($clients) || empty($clients)) { - Message::addError('no-clients-selected'); - Util::redirect(); - } + $locationId = Request::post('locationId', false, 'int'); if ($locationId === false) { Message::addError('locations.invalid-location-id', $locationId); Util::redirect(); } + $shutdown = $this->action === "startShutdown"; + // Check user permission (if user has no permission, the getAllowed-list will be empty and the check will fail) + if ($shutdown) { + if (!in_array($locationId, $this->allowedShutdownLocs)) { + Message::addError('main.no-permission'); + Util::redirect(); + } + } else { + if (!in_array($locationId, $this->allowedRebootLocs)) { + Message::addError('main.no-permission'); + Util::redirect(); + } + } + + $clients = Request::post('clients'); + if (!is_array($clients) || empty($clients)) { + Message::addError('no-clients-selected'); + Util::redirect(); + } $minutes = Request::post('minutes', 0, 'int'); $list = RebootQueries::getMachinesByUuid($clients); @@ -72,12 +94,34 @@ class Page_RebootControl extends Page //location you want to see, default are "not assigned" clients $requestedLocation = Request::get('location', 0, 'int'); - $data['data'] = RebootQueries::getMachineTable($requestedLocation); - $data['locations'] = Location::getLocations($requestedLocation, 0, true); + // only fill table if user has at least one permission for the location + if (in_array($requestedLocation, $this->allowedLocs)) { + $data['data'] = RebootQueries::getMachineTable($requestedLocation); + $data['allowedToSelect'] = True; + } + $data['locations'] = Location::getLocations($requestedLocation, 0, true); + // Always show public key (it's public, isn't it?) $data['pubKey'] = SSHKey::getPublicKey(); + // disable each location user has no permission for + foreach ($data['locations'] as &$loc) { + if (!in_array($loc["locationid"], $this->allowedLocs)) { + $loc["disabled"] = "disabled"; + } + } + + // Only enable shutdown/reboot-button if user has permission for the location + if (in_array($requestedLocation, $this->allowedShutdownLocs)) { + $data['allowedToShutdown'] = True; + } + if (in_array($requestedLocation, $this->allowedRebootLocs)) { + $data['allowedToReboot'] = True; + } + $data['allowedToGenerateKey'] = User::hasPermission("newkeypair"); + Render::addTemplate('_page', $data); + } } } @@ -86,8 +130,12 @@ class Page_RebootControl extends Page { $this->action = Request::post('action', false, 'string'); if ($this->action === 'generateNewKeypair') { - Property::set("rebootcontrol-private-key", false); - echo SSHKey::getPublicKey(); + if (User::hasPermission("newkeypair")) { + Property::set("rebootcontrol-private-key", false); + echo SSHKey::getPublicKey(); + } else { + echo 'No permission.'; + } } else { echo 'Invalid action.'; } diff --git a/modules-available/rebootcontrol/permissions/permissions.json b/modules-available/rebootcontrol/permissions/permissions.json new file mode 100644 index 00000000..5230c9bd --- /dev/null +++ b/modules-available/rebootcontrol/permissions/permissions.json @@ -0,0 +1,5 @@ +[ + "shutdown", + "reboot", + "newkeypair" +] \ No newline at end of file diff --git a/modules-available/rebootcontrol/templates/_page.html b/modules-available/rebootcontrol/templates/_page.html index 1bef8dd4..9b470943 100644 --- a/modules-available/rebootcontrol/templates/_page.html +++ b/modules-available/rebootcontrol/templates/_page.html @@ -8,15 +8,15 @@
- - - + + +
@@ -25,41 +25,41 @@
- - - - - - - - + + + + + + + + {{#data}} - - - - - - - - + + + + + + + + {{/data}}
{{lang_client}}{{lang_ip}}{{lang_status}}{{lang_session}}{{lang_user}}{{lang_selected}}
{{lang_client}}{{lang_ip}}{{lang_status}}{{lang_session}}{{lang_user}}{{lang_selected}}
- {{hostname}} - {{^hostname}}{{clientip}}{{/hostname}} - {{clientip}} - {{#status}} - {{lang_on}} - {{/status}} - {{^status}} - {{lang_off}} - {{/status}} - {{#status}}{{currentsession}}{{/status}}{{#status}}{{currentuser}}{{/status}} -
- - -
-
+ {{hostname}} + {{^hostname}}{{clientip}}{{/hostname}} + {{clientip}} + {{#status}} + {{lang_on}} + {{/status}} + {{^status}} + {{lang_off}} + {{/status}} + {{#status}}{{currentsession}}{{/status}}{{#status}}{{currentuser}}{{/status}} +
+ + +
+
@@ -79,7 +79,7 @@
@@ -115,11 +115,11 @@ @@ -162,7 +162,7 @@ $('#rebootButton').prop('disabled', false); $('#shutdownButton').prop('disabled', false); } - }); + }); $('.checkboxColumn').click(function(e) { if (e.target === this) { $(this).find('input[type="checkbox"]').click(); -- cgit v1.2.3-55-g7522 From e4e62c11eb207ed9b155dd4f49dab55f6c0e42a9 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Thu, 11 Jan 2018 15:53:02 +0100 Subject: [rebootcontrol] this time with correct modul-tag in front. Changed buttons so that they don't open the modals to reboot/shutdown if user has no permission. Deleted some redundancy from stylesheet --- modules-available/rebootcontrol/style.css | 5 +---- modules-available/rebootcontrol/templates/_page.html | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/style.css b/modules-available/rebootcontrol/style.css index 442cd5de..f10a6157 100644 --- a/modules-available/rebootcontrol/style.css +++ b/modules-available/rebootcontrol/style.css @@ -16,11 +16,8 @@ margin-bottom: 0; } -#rebootButton, #settingsButton, #selectAllButton, #unselectAllButton { +.controlButtons { margin-left: 10px; -} - -#rebootButton, #shutdownButton, #selectAllButton, #unselectAllButton { width: 140px; } diff --git a/modules-available/rebootcontrol/templates/_page.html b/modules-available/rebootcontrol/templates/_page.html index 9b470943..e540cafb 100644 --- a/modules-available/rebootcontrol/templates/_page.html +++ b/modules-available/rebootcontrol/templates/_page.html @@ -15,10 +15,10 @@ {{/locations}} - - - - + + + +
-- cgit v1.2.3-55-g7522 From a8b0095b335780ae0bb950bc44021215d43a6b2d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 12 Feb 2018 14:17:07 +0100 Subject: [permissionmanager] Introduce "location-aware" flag for permissions This flag tells wether the permission can be restricted to certain locations in a meaningful way. This flag has to be set in the permissions.json of the according module. For example, the permission to reboot the server cannot be limited to certain locations in a meaningful way, while the view of the client log can be filtered to only show log entries for clients in specific locations. --- .../backup/permissions/permissions.json | 12 +++-- .../permissions/permissions.json | 24 +++++++--- .../dozmod/permissions/permissions.json | 52 ++++++++++++++++------ .../eventlog/permissions/permissions.json | 8 ++-- .../exams/permissions/permissions.json | 13 +++--- .../internetaccess/permissions/permissions.json | 8 ++-- .../locations/permissions/permissions.json | 32 +++++++++---- .../minilinux/permissions/permissions.json | 12 +++-- .../news/permissions/permissions.json | 20 ++++++--- .../permissionmanager/inc/permissionutil.inc.php | 9 ++-- modules-available/permissionmanager/page.inc.php | 21 +++++---- modules-available/permissionmanager/style.css | 28 ++++++------ .../permissionmanager/templates/roleeditor.html | 42 +++++++---------- .../permissionmanager/templates/treenode.html | 23 +++++----- .../permissionmanager/templates/treepanel.html | 2 +- .../rebootcontrol/permissions/permissions.json | 16 ++++--- .../serversetup-bwlp/permissions/permissions.json | 16 ++++--- .../statistics/permissions/permissions.json | 16 ++++--- .../permissions/permissions.json | 36 ++++++++++----- .../syslog/permissions/permissions.json | 8 ++-- .../systemstatus/permissions/permissions.json | 48 ++++++++++++++------ .../vmstore/permissions/permissions.json | 16 ++++--- .../webinterface/permissions/permissions.json | 16 ++++--- 23 files changed, 309 insertions(+), 169 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/backup/permissions/permissions.json b/modules-available/backup/permissions/permissions.json index feeffe33..1f778ab6 100644 --- a/modules-available/backup/permissions/permissions.json +++ b/modules-available/backup/permissions/permissions.json @@ -1,4 +1,8 @@ -[ - "create", - "restore" -] \ No newline at end of file +{ + "create": { + "location-aware": false + }, + "restore": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/baseconfig_partitions_cdn/permissions/permissions.json b/modules-available/baseconfig_partitions_cdn/permissions/permissions.json index 286a975b..3acd5230 100644 --- a/modules-available/baseconfig_partitions_cdn/permissions/permissions.json +++ b/modules-available/baseconfig_partitions_cdn/permissions/permissions.json @@ -1,7 +1,17 @@ -[ - "show", - "partitions.add", - "partitions.delete", - "partitions.edit", - "partitions.reset" -] \ No newline at end of file +{ + "partitions.add": { + "location-aware": false + }, + "partitions.delete": { + "location-aware": false + }, + "partitions.edit": { + "location-aware": false + }, + "partitions.reset": { + "location-aware": false + }, + "show": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/dozmod/permissions/permissions.json b/modules-available/dozmod/permissions/permissions.json index e8dfb558..b4ff034b 100644 --- a/modules-available/dozmod/permissions/permissions.json +++ b/modules-available/dozmod/permissions/permissions.json @@ -1,14 +1,38 @@ -[ - "images.delete", - "mail.save", - "mail.testmail", - "runtimeconfig.save", - "templates.save", - "templates.reset", - "users.setmail", - "users.setlogin", - "users.setsu", - "users.orglogin", - "log.showuser", - "log.showtarget" -] \ No newline at end of file +{ + "images.delete": { + "location-aware": false + }, + "log.showtarget": { + "location-aware": false + }, + "log.showuser": { + "location-aware": false + }, + "mail.save": { + "location-aware": false + }, + "mail.testmail": { + "location-aware": false + }, + "runtimeconfig.save": { + "location-aware": false + }, + "templates.reset": { + "location-aware": false + }, + "templates.save": { + "location-aware": false + }, + "users.orglogin": { + "location-aware": false + }, + "users.setlogin": { + "location-aware": false + }, + "users.setmail": { + "location-aware": false + }, + "users.setsu": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/eventlog/permissions/permissions.json b/modules-available/eventlog/permissions/permissions.json index f04ea714..a1748957 100644 --- a/modules-available/eventlog/permissions/permissions.json +++ b/modules-available/eventlog/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "view" -] \ No newline at end of file +{ + "view": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/exams/permissions/permissions.json b/modules-available/exams/permissions/permissions.json index 215b3399..e44974b6 100644 --- a/modules-available/exams/permissions/permissions.json +++ b/modules-available/exams/permissions/permissions.json @@ -1,5 +1,8 @@ -[ - "exams.add", - "exams.delete", - "exams.edit" -] \ No newline at end of file +{ + "exams.edit": { + "location-aware": true + }, + "exams.view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/internetaccess/permissions/permissions.json b/modules-available/internetaccess/permissions/permissions.json index 67998da7..09652e51 100644 --- a/modules-available/internetaccess/permissions/permissions.json +++ b/modules-available/internetaccess/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "configuration.safe" -] \ No newline at end of file +{ + "configuration.safe": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/locations/permissions/permissions.json b/modules-available/locations/permissions/permissions.json index 609a673a..06b01d2c 100644 --- a/modules-available/locations/permissions/permissions.json +++ b/modules-available/locations/permissions/permissions.json @@ -1,9 +1,23 @@ -[ - "location.view", - "location.edit", - "location.add", - "location.delete", - "subnet.edit", - "subnet.add", - "subnet.delete" -] \ No newline at end of file +{ + "location.add": { + "location-aware": false + }, + "location.delete": { + "location-aware": false + }, + "location.edit": { + "location-aware": false + }, + "location.view": { + "location-aware": false + }, + "subnet.add": { + "location-aware": false + }, + "subnet.delete": { + "location-aware": false + }, + "subnet.edit": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/minilinux/permissions/permissions.json b/modules-available/minilinux/permissions/permissions.json index 457d9810..650f7e71 100644 --- a/modules-available/minilinux/permissions/permissions.json +++ b/modules-available/minilinux/permissions/permissions.json @@ -1,4 +1,8 @@ -[ - "show", - "update" -] \ No newline at end of file +{ + "show": { + "location-aware": false + }, + "update": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/news/permissions/permissions.json b/modules-available/news/permissions/permissions.json index 321e73ea..0d9435d7 100644 --- a/modules-available/news/permissions/permissions.json +++ b/modules-available/news/permissions/permissions.json @@ -1,6 +1,14 @@ -[ - "news.save", - "news.delete", - "help.save", - "help.delete" -] \ No newline at end of file +{ + "help.delete": { + "location-aware": false + }, + "help.save": { + "location-aware": false + }, + "news.delete": { + "location-aware": false + }, + "news.save": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index 5ff41046..3daf422e 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -100,9 +100,9 @@ class PermissionUtil if (!is_array($data)) continue; preg_match('#^modules/([^/]+)/#', $file, $out); - foreach( $data as $p ) { + foreach( $data as $p => $data) { $description = Dictionary::translateFileModule($out[1], "permissions", $p); - self::putInPermissionTree($out[1].".".$p, $description, $permissions); + self::putInPermissionTree($out[1].".".$p, $data['location-aware'], $description, $permissions); } } ksort($permissions); @@ -120,10 +120,11 @@ class PermissionUtil * Place a permission into the given permission tree. * * @param string $permission the permission to place in the tree + * @param bool $locationAware whether this permissions can be restricted to specific locations only * @param string $description the description of the permission * @param array $tree the permission tree to modify */ - private static function putInPermissionTree($permission, $description, &$tree) + private static function putInPermissionTree($permission, $locationAware, $description, &$tree) { $subPermissions = explode('.', $permission); foreach ($subPermissions as $subPermission) { @@ -134,6 +135,6 @@ class PermissionUtil $tree =& $tree[$subPermission]; } } - $tree = $description; + $tree = array('description' => $description, 'location-aware' => $locationAware, 'isLeaf' => true); } } \ No newline at end of file diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php index 13d81c6a..bb8482af 100644 --- a/modules-available/permissionmanager/page.inc.php +++ b/modules-available/permissionmanager/page.inc.php @@ -100,18 +100,21 @@ class Page_PermissionManager extends Page $toplevel = $permString == ""; if ($toplevel && in_array("*", $selectedPermissions)) $selectAll = true; foreach ($permissions as $k => $v) { - $leaf = !is_array($v); + $leaf = isset($v['isLeaf']) && $v['isLeaf']; $nextPermString = $permString ? $permString.".".$k : $k; $id = $leaf ? $nextPermString : $nextPermString.".*"; $selected = $selectAll || in_array($id, $selectedPermissions); - $res .= Render::parse("treenode", - array("id" => $id, - "name" => $toplevel ? Module::get($k)->getDisplayName() : $k, - "toplevel" => $toplevel, - "checkboxname" => "permissions", - "selected" => $selected, - "HTML" => $leaf ? "" : self::generatePermissionHTML($v, $selectedPermissions, $selected, $nextPermString), - "description" => $leaf ? $v : "")); + $data = array("id" => $id, + "name" => $toplevel ? Module::get($k)->getDisplayName() : $k, + "toplevel" => $toplevel, + "checkboxname" => "permissions", + "selected" => $selected, + "HTML" => $leaf ? "" : self::generatePermissionHTML($v, $selectedPermissions, $selected, $nextPermString), + ); + if ($leaf) { + $data += $v; + } + $res .= Render::parse("treenode", $data); } if ($toplevel) { $res = Render::parse("treepanel", diff --git a/modules-available/permissionmanager/style.css b/modules-available/permissionmanager/style.css index 49d631a8..9c39af64 100644 --- a/modules-available/permissionmanager/style.css +++ b/modules-available/permissionmanager/style.css @@ -55,28 +55,28 @@ background-color: rgba(0, 182, 41, 0.23); } -.tree-container { - -moz-column-gap: 20px; - -webkit-column-gap: 20px; - column-gap: 20px; -} - - .tree-container > ul { display: inline-block; width: 100%; padding: 0; } -@media (max-width: 767px) { - .tree-container { - -moz-column-count: 1; - -webkit-column-count: 1; - column-count: 1; - } +.tree-container > ul > li > div > label { + font-weight: bold; +} + +.tree-container { + -moz-column-gap: 20px; + -webkit-column-gap: 20px; + column-gap: 20px; + -moz-column-count: 1; + -webkit-column-count: 1; + column-count: 1; + padding-left: 20px; + padding-right: 20px; } -@media (min-width: 768px) and (max-width: 991px) { +@media (min-width: 768px) { .tree-container { -moz-column-count: 2; -webkit-column-count: 2; diff --git a/modules-available/permissionmanager/templates/roleeditor.html b/modules-available/permissionmanager/templates/roleeditor.html index 871fd0cc..eadce027 100644 --- a/modules-available/permissionmanager/templates/roleeditor.html +++ b/modules-available/permissionmanager/templates/roleeditor.html @@ -4,32 +4,24 @@ -
-
- + +
+
+ {{{permissionHTML}}}
-
-
-
-
-
- {{{permissionHTML}}} -
-
- {{{locationHTML}}} -
-
+
+ {{{locationHTML}}}
diff --git a/modules-available/permissionmanager/templates/treenode.html b/modules-available/permissionmanager/templates/treenode.html index ced973ca..43509237 100644 --- a/modules-available/permissionmanager/templates/treenode.html +++ b/modules-available/permissionmanager/templates/treenode.html @@ -1,11 +1,14 @@ {{#toplevel}}
    {{/toplevel}} -
  • -
    - - -
    -
      - {{{HTML}}} -
    -
  • -{{#toplevel}}
{{/toplevel}} +
  • +
    + + +
    +
      + {{{HTML}}} +
    +
  • +{{#toplevel}}{{/toplevel}} \ No newline at end of file diff --git a/modules-available/permissionmanager/templates/treepanel.html b/modules-available/permissionmanager/templates/treepanel.html index 6f358825..8b510407 100644 --- a/modules-available/permissionmanager/templates/treepanel.html +++ b/modules-available/permissionmanager/templates/treepanel.html @@ -6,7 +6,7 @@
    -
    +
    {{{HTML}}}
    diff --git a/modules-available/rebootcontrol/permissions/permissions.json b/modules-available/rebootcontrol/permissions/permissions.json index 5230c9bd..5de9b633 100644 --- a/modules-available/rebootcontrol/permissions/permissions.json +++ b/modules-available/rebootcontrol/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "shutdown", - "reboot", - "newkeypair" -] \ No newline at end of file +{ + "newkeypair": { + "location-aware": false + }, + "reboot": { + "location-aware": true + }, + "shutdown": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json index 2166cf8e..6bae5422 100644 --- a/modules-available/serversetup-bwlp/permissions/permissions.json +++ b/modules-available/serversetup-bwlp/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "edit.address", - "edit.menu", - "download" -] \ No newline at end of file +{ + "download": { + "location-aware": false + }, + "edit.address": { + "location-aware": false + }, + "edit.menu": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/statistics/permissions/permissions.json b/modules-available/statistics/permissions/permissions.json index 97a49036..c9dca9f3 100644 --- a/modules-available/statistics/permissions/permissions.json +++ b/modules-available/statistics/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "view", - "note", - "delete" -] \ No newline at end of file +{ + "machine.delete": { + "location-aware": true + }, + "machine.note": { + "location-aware": true + }, + "machine.view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/statistics_reporting/permissions/permissions.json b/modules-available/statistics_reporting/permissions/permissions.json index d967b75d..1244027e 100644 --- a/modules-available/statistics_reporting/permissions/permissions.json +++ b/modules-available/statistics_reporting/permissions/permissions.json @@ -1,10 +1,26 @@ -[ - "table.view.total", - "table.view.location", - "table.view.client", - "table.view.user", - "table.view.vm", - "table.export", - "reporting.download", - "reporting.change" -] \ No newline at end of file +{ + "reporting.change": { + "location-aware": false + }, + "reporting.download": { + "location-aware": false + }, + "table.export": { + "location-aware": false + }, + "table.view.client": { + "location-aware": true + }, + "table.view.location": { + "location-aware": true + }, + "table.view.total": { + "location-aware": false + }, + "table.view.user": { + "location-aware": false + }, + "table.view.vm": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/syslog/permissions/permissions.json b/modules-available/syslog/permissions/permissions.json index f04ea714..fcf530c5 100644 --- a/modules-available/syslog/permissions/permissions.json +++ b/modules-available/syslog/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "view" -] \ No newline at end of file +{ + "view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/systemstatus/permissions/permissions.json b/modules-available/systemstatus/permissions/permissions.json index 0333564b..8324f708 100644 --- a/modules-available/systemstatus/permissions/permissions.json +++ b/modules-available/systemstatus/permissions/permissions.json @@ -1,13 +1,35 @@ -[ - "show.overview.diskstat", - "show.overview.services", - "show.overview.adresses", - "show.overview.systeminfo", - "show.overview.dmsdusers", - "show.logs.bwlpserver", - "show.logs.netstat", - "show.logs.pslist", - "show.logs.ldapad", - "show.logs.lighttpd", - "serverreboot" -] \ No newline at end of file +{ + "serverreboot": { + "location-aware": false + }, + "show.logs.bwlpserver": { + "location-aware": false + }, + "show.logs.ldapad": { + "location-aware": false + }, + "show.logs.lighttpd": { + "location-aware": false + }, + "show.logs.netstat": { + "location-aware": false + }, + "show.logs.pslist": { + "location-aware": false + }, + "show.overview.adresses": { + "location-aware": false + }, + "show.overview.diskstat": { + "location-aware": false + }, + "show.overview.dmsdusers": { + "location-aware": false + }, + "show.overview.services": { + "location-aware": false + }, + "show.overview.systeminfo": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/vmstore/permissions/permissions.json b/modules-available/vmstore/permissions/permissions.json index f2c22c72..29ee6a51 100644 --- a/modules-available/vmstore/permissions/permissions.json +++ b/modules-available/vmstore/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "choose.internal", - "choose.nfs", - "choose.cifs" -] \ No newline at end of file +{ + "choose.cifs": { + "location-aware": false + }, + "choose.internal": { + "location-aware": false + }, + "choose.nfs": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/webinterface/permissions/permissions.json b/modules-available/webinterface/permissions/permissions.json index 45b5395d..fa6f493f 100644 --- a/modules-available/webinterface/permissions/permissions.json +++ b/modules-available/webinterface/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "edit.https", - "edit.password", - "edit.design" -] \ No newline at end of file +{ + "edit.design": { + "location-aware": false + }, + "edit.https": { + "location-aware": false + }, + "edit.password": { + "location-aware": false + } +} \ No newline at end of file -- cgit v1.2.3-55-g7522 From 5309badac125114399ec2cf39b095e0d9efcd09f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 15 Feb 2018 13:18:56 +0100 Subject: [rebootcontrol] Rewrite permission handling, simplify html/javascript --- .../rebootcontrol/lang/de/module.json | 1 - .../rebootcontrol/lang/de/permissions.json | 4 +- .../rebootcontrol/lang/de/template-tags.json | 5 +- .../rebootcontrol/lang/en/module.json | 1 - .../rebootcontrol/lang/en/permissions.json | 4 +- .../rebootcontrol/lang/en/template-tags.json | 5 +- modules-available/rebootcontrol/page.inc.php | 107 ++++++-------- .../rebootcontrol/permissions/permissions.json | 4 +- modules-available/rebootcontrol/style.css | 10 +- .../rebootcontrol/templates/_page.html | 162 ++++++--------------- .../rebootcontrol/templates/header.html | 63 ++++++++ 11 files changed, 172 insertions(+), 194 deletions(-) create mode 100644 modules-available/rebootcontrol/templates/header.html (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/lang/de/module.json b/modules-available/rebootcontrol/lang/de/module.json index 03196610..1f325354 100644 --- a/modules-available/rebootcontrol/lang/de/module.json +++ b/modules-available/rebootcontrol/lang/de/module.json @@ -1,5 +1,4 @@ { "module_name": "Reboot Control", - "notAssigned": "Nicht zugewiesen", "page_title": "Reboot Control" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/de/permissions.json b/modules-available/rebootcontrol/lang/de/permissions.json index 92eeb37e..12ec4c83 100644 --- a/modules-available/rebootcontrol/lang/de/permissions.json +++ b/modules-available/rebootcontrol/lang/de/permissions.json @@ -1,5 +1,5 @@ { - "shutdown": "Client herunterfahren.", - "reboot": "Client neustarten.", + "action.shutdown": "Client herunterfahren.", + "action.reboot": "Client neustarten.", "newkeypair": "Neues Schlüsselpaar generieren." } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/de/template-tags.json b/modules-available/rebootcontrol/lang/de/template-tags.json index c5bd1670..eccc8738 100644 --- a/modules-available/rebootcontrol/lang/de/template-tags.json +++ b/modules-available/rebootcontrol/lang/de/template-tags.json @@ -1,12 +1,14 @@ { "lang_authFail": "Authentifizierung fehlgeschlagen", "lang_client": "Client", + "lang_confirmNewKeypair": "Wirklich neues Schl\u00fcsselpaar erzeugen?", "lang_connecting": "Verbinde...", "lang_error": "Nicht erreichbar", "lang_genNew": "Neues Schl\u00fcsselpaar generieren", "lang_ip": "IP", "lang_location": "Standort", "lang_minutes": " Minuten", + "lang_newKeypairExplanation": "Sie k\u00f6nnen ein neues Schl\u00fcsselpaar erzeugen lassen. In diesem Fall wird das alte Schl\u00fcsselpaar verworfen, sodass alle zum jetzigen Zeitpunkt bereits gestarteten Rechner nicht mehr aus der Ferne bedient werden k\u00f6nnen, bis diese manuell neugestartet wurden.", "lang_off": "Aus", "lang_on": "An", "lang_online": "Online", @@ -27,6 +29,5 @@ "lang_shutdownCheck": "Wollen Sie die ausgew\u00e4hlten Rechner wirklich herunterfahren?", "lang_shutdownIn": "Herunterfahren in: ", "lang_status": "Status", - "lang_unselectall": "Alle abw\u00e4hlen", - "lang_user": "Nutzer" + "lang_unselectall": "Alle abw\u00e4hlen" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/en/module.json b/modules-available/rebootcontrol/lang/en/module.json index 129140dd..1f325354 100644 --- a/modules-available/rebootcontrol/lang/en/module.json +++ b/modules-available/rebootcontrol/lang/en/module.json @@ -1,5 +1,4 @@ { "module_name": "Reboot Control", - "notAssigned": "Not assigned", "page_title": "Reboot Control" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/en/permissions.json b/modules-available/rebootcontrol/lang/en/permissions.json index 077890fb..34badbaf 100644 --- a/modules-available/rebootcontrol/lang/en/permissions.json +++ b/modules-available/rebootcontrol/lang/en/permissions.json @@ -1,5 +1,5 @@ { - "shutdown": "Shutdown Client.", - "reboot": "Reboot Client.", + "action.shutdown": "Shutdown Client.", + "action.reboot": "Reboot Client.", "newkeypair": "Generate new Keypair." } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/en/template-tags.json b/modules-available/rebootcontrol/lang/en/template-tags.json index 63a5b4a8..c2346044 100644 --- a/modules-available/rebootcontrol/lang/en/template-tags.json +++ b/modules-available/rebootcontrol/lang/en/template-tags.json @@ -1,12 +1,14 @@ { "lang_authFail": "Authentication failed", "lang_client": "Client", + "lang_confirmNewKeypair": "Really create new key pair?", "lang_connecting": "Connecting...", "lang_error": "Not available", "lang_genNew": "Generate new keypair", "lang_ip": "IP", "lang_location": "Location", "lang_minutes": " Minutes", + "lang_newKeypairExplanation": "You can create a new keypair, which will replace the old one. Please note that after doing so, you cannot poweroff or reboot clients that are already running, since they still use the old key. They have to be rebooted manually first.", "lang_off": "Off", "lang_on": "On", "lang_online": "Online", @@ -27,6 +29,5 @@ "lang_shutdownCheck": "Do you really want to shut down the selected clients?", "lang_shutdownIn": "Shutdown in: ", "lang_status": "Status", - "lang_unselectall": "Unselect all", - "lang_user": "User" + "lang_unselectall": "Unselect all" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index fa34a05a..fa7688d8 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -4,9 +4,6 @@ class Page_RebootControl extends Page { private $action = false; - private $allowedShutdownLocs = []; - private $allowedRebootLocs = []; - private $allowedLocs = []; /** * Called before any page rendering happens - early hook to check parameters etc. @@ -20,54 +17,40 @@ class Page_RebootControl extends Page Util::redirect('?do=Main'); // does not return } - $this->allowedShutdownLocs = User::getAllowedLocations("shutdown"); - $this->allowedRebootLocs = User::getAllowedLocations("reboot"); - $this->allowedLocs = array_unique(array_merge($this->allowedShutdownLocs, $this->allowedRebootLocs)); - $this->action = Request::any('action', 'show', 'string'); - if ($this->action === 'startReboot' || $this->action === 'startShutdown') { - - $locationId = Request::post('locationId', false, 'int'); - if ($locationId === false) { - Message::addError('locations.invalid-location-id', $locationId); - Util::redirect(); - } - - $shutdown = $this->action === "startShutdown"; - // Check user permission (if user has no permission, the getAllowed-list will be empty and the check will fail) - if ($shutdown) { - if (!in_array($locationId, $this->allowedShutdownLocs)) { - Message::addError('main.no-permission'); - Util::redirect(); - } - } else { - if (!in_array($locationId, $this->allowedRebootLocs)) { - Message::addError('main.no-permission'); - Util::redirect(); - } - } + if ($this->action === 'reboot' || $this->action === 'shutdown') { - $clients = Request::post('clients'); - if (!is_array($clients) || empty($clients)) { + $requestedClients = Request::post('clients', false, 'array'); + if (!is_array($requestedClients) || empty($requestedClients)) { Message::addError('no-clients-selected'); Util::redirect(); } $minutes = Request::post('minutes', 0, 'int'); - $list = RebootQueries::getMachinesByUuid($clients); - if (count($list) !== count($clients)) { + $actualClients = RebootQueries::getMachinesByUuid($requestedClients); + if (count($actualClients) !== count($requestedClients)) { // We could go ahead an see which ones were not found in DB but this should not happen anyways unless the // user manipulated the request Message::addWarning('some-machine-not-found'); } - // TODO: Iterate over list and check if a locationid is not in permissions - // TODO: we could also check if the locationid is equal or a sublocation of the $locationId from above - // (this would be more of a sanity check though, or does the UI allow selecting machines from different locations) - - $task = RebootControl::execute($list, $shutdown, $minutes, $locationId); + // Filter ones with no permission + foreach (array_keys($actualClients) as $idx) { + if (!User::hasPermission('action.' . $this->action, $actualClients[$idx]['locationid'])) { + Message::addWarning('main.location-no-permission', $actualClients[$idx]['locationid']); + unset($actualClients[$idx]); + } else { + $locationId = $actualClients[$idx]['locationid']; + } + } + // See if anything is left + if (!is_array($actualClients) || empty($actualClients)) { + Message::addError('no-clients-selected'); + Util::redirect(); + } + $task = RebootControl::execute($actualClients, $this->action === 'shutdown', $minutes, $locationId); Util::redirect("?do=rebootcontrol&taskid=".$task["id"]); } @@ -81,6 +64,7 @@ class Page_RebootControl extends Page { if ($this->action === 'show') { + $data = []; $taskId = Request::get("taskid"); if ($taskId && Taskmanager::isTask($taskId)) { @@ -91,36 +75,42 @@ class Page_RebootControl extends Page $data['clients'] = $task['data']['clients']; Render::addTemplate('status', $data); } else { - //location you want to see, default are "not assigned" clients - $requestedLocation = Request::get('location', 0, 'int'); - // only fill table if user has at least one permission for the location - if (in_array($requestedLocation, $this->allowedLocs)) { - $data['data'] = RebootQueries::getMachineTable($requestedLocation); - $data['allowedToSelect'] = True; + //location you want to see, default are "not assigned" clients + $requestedLocation = Request::get('location', false, 'int'); + $allowedLocs = User::getAllowedLocations("action.*"); + + if ($requestedLocation === false) { + if (in_array(0, $allowedLocs)) { + $requestedLocation = 0; + } elseif (!empty($allowedLocs)) { + $requestedLocation = reset($allowedLocs); + } } $data['locations'] = Location::getLocations($requestedLocation, 0, true); - // Always show public key (it's public, isn't it?) - $data['pubKey'] = SSHKey::getPublicKey(); // disable each location user has no permission for foreach ($data['locations'] as &$loc) { - if (!in_array($loc["locationid"], $this->allowedLocs)) { + if (!in_array($loc["locationid"], $allowedLocs)) { $loc["disabled"] = "disabled"; } } + // Always show public key (it's public, isn't it?) + $data['pubKey'] = SSHKey::getPublicKey(); // Only enable shutdown/reboot-button if user has permission for the location - if (in_array($requestedLocation, $this->allowedShutdownLocs)) { - $data['allowedToShutdown'] = True; - } - if (in_array($requestedLocation, $this->allowedRebootLocs)) { - $data['allowedToReboot'] = True; - } - $data['allowedToGenerateKey'] = User::hasPermission("newkeypair"); + Permission::addGlobalTags($data['perms'], $requestedLocation, ['newkeypair', 'action.shutdown', 'action.reboot']); + + Render::addTemplate('header', $data); - Render::addTemplate('_page', $data); + // only fill table if user has at least one permission for the location + if ($requestedLocation === false) { + Message::addError('main.no-permission'); + } else { + $data['data'] = RebootQueries::getMachineTable($requestedLocation); + Render::addTemplate('_page', $data); + } } } @@ -130,12 +120,9 @@ class Page_RebootControl extends Page { $this->action = Request::post('action', false, 'string'); if ($this->action === 'generateNewKeypair') { - if (User::hasPermission("newkeypair")) { - Property::set("rebootcontrol-private-key", false); - echo SSHKey::getPublicKey(); - } else { - echo 'No permission.'; - } + User::assertPermission("newkeypair"); + Property::set("rebootcontrol-private-key", false); + echo SSHKey::getPublicKey(); } else { echo 'Invalid action.'; } diff --git a/modules-available/rebootcontrol/permissions/permissions.json b/modules-available/rebootcontrol/permissions/permissions.json index 5de9b633..a058ffbf 100644 --- a/modules-available/rebootcontrol/permissions/permissions.json +++ b/modules-available/rebootcontrol/permissions/permissions.json @@ -2,10 +2,10 @@ "newkeypair": { "location-aware": false }, - "reboot": { + "action.reboot": { "location-aware": true }, - "shutdown": { + "action.shutdown": { "location-aware": true } } \ No newline at end of file diff --git a/modules-available/rebootcontrol/style.css b/modules-available/rebootcontrol/style.css index f10a6157..e35bce29 100644 --- a/modules-available/rebootcontrol/style.css +++ b/modules-available/rebootcontrol/style.css @@ -16,9 +16,8 @@ margin-bottom: 0; } -.controlButtons { - margin-left: 10px; - width: 140px; +.select-button { + min-width: 150px; } #dataTable { @@ -29,11 +28,6 @@ #shutdownTimer { text-align: center; } -#pubKeyTitle { - display: inline-block; - margin-top: 7px; - margin-bottom: 20px; -} pre { white-space: pre-wrap; diff --git a/modules-available/rebootcontrol/templates/_page.html b/modules-available/rebootcontrol/templates/_page.html index e540cafb..82f82b02 100644 --- a/modules-available/rebootcontrol/templates/_page.html +++ b/modules-available/rebootcontrol/templates/_page.html @@ -1,26 +1,5 @@ - - -
    -
    -
    - - - - - -
    -
    @@ -53,7 +32,7 @@ -
    {{#status}}{{currentsession}}{{/status}} {{#status}}{{currentuser}}{{/status}} +
    @@ -69,25 +48,6 @@ - - @@ -115,11 +75,11 @@
    @@ -128,104 +88,76 @@ \ No newline at end of file -- cgit v1.2.3-55-g7522 From d5166e77fbb1dc034a421da868f9539fc455e490 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Mar 2018 11:30:29 +0100 Subject: Update translations --- modules-available/locations/lang/de/template-tags.json | 4 ++-- modules-available/locations/lang/en/template-tags.json | 4 ++-- modules-available/rebootcontrol/page.inc.php | 2 +- modules-available/runmode/lang/de/messages.json | 1 + modules-available/runmode/lang/de/template-tags.json | 1 + modules-available/runmode/lang/en/messages.json | 1 + modules-available/runmode/lang/en/template-tags.json | 1 + modules-available/statistics/page.inc.php | 2 +- 8 files changed, 10 insertions(+), 6 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/locations/lang/de/template-tags.json b/modules-available/locations/lang/de/template-tags.json index 04d10d06..43142555 100644 --- a/modules-available/locations/lang/de/template-tags.json +++ b/modules-available/locations/lang/de/template-tags.json @@ -6,7 +6,7 @@ "lang_deleteChildLocations": "Untergeordnete Orte ebenfalls l\u00f6schen", "lang_deleteLocation": "Ort l\u00f6schen", "lang_deleteSubnet": "Bereich l\u00f6schen", - "lang_deleteSubnetWarning": "Alle zum L\u00f6schen markierten Subnetze werden gelöscht. Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.", + "lang_deleteSubnetWarning": "Alle zum L\u00f6schen markierten Subnetze werden gel\u00f6scht. Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.", "lang_editConfigVariables": "Konfig.-Variablen", "lang_editRoomplan": "Raumplan bearbeiten", "lang_endAddress": "Endadresse", @@ -22,10 +22,10 @@ "lang_machineLoad": "Besetzt", "lang_matchingMachines": "Enthaltene Rechner", "lang_name": "Name", - "lang_noParent": "Kein \u00fcbergeordneter Ort", "lang_overrideCount": "Angepasst", "lang_parentLocation": "\u00dcbergeordneter Ort", "lang_referencingLectures": "Veranstaltungen", + "lang_showRoomplan": "Raumplan anzeigen", "lang_startAddress": "Startadresse", "lang_subnet": "IP-Bereich", "lang_sysConfig": "Lokalisierung", diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json index ddb90f83..41261726 100644 --- a/modules-available/locations/lang/en/template-tags.json +++ b/modules-available/locations/lang/en/template-tags.json @@ -22,14 +22,14 @@ "lang_machineLoad": "In use", "lang_matchingMachines": "Matching clients", "lang_name": "Name", - "lang_noParent": "No parent", "lang_overrideCount": "Overridden", "lang_parentLocation": "Parent location", "lang_referencingLectures": "Assigned Lectures", + "lang_showRoomplan": "Show room plan", "lang_startAddress": "Start address", "lang_subnet": "IP range", "lang_sysConfig": "Localization\/Integration", "lang_thisListByLocation": "Locations", "lang_thisListBySubnet": "Subnets", "lang_unassignedMachines": "Machines not matching any location" -} +} \ No newline at end of file diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index fa7688d8..abbdb2c3 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -38,7 +38,7 @@ class Page_RebootControl extends Page // Filter ones with no permission foreach (array_keys($actualClients) as $idx) { if (!User::hasPermission('action.' . $this->action, $actualClients[$idx]['locationid'])) { - Message::addWarning('main.location-no-permission', $actualClients[$idx]['locationid']); + Message::addWarning('locations.no-permission-location', $actualClients[$idx]['locationid']); unset($actualClients[$idx]); } else { $locationId = $actualClients[$idx]['locationid']; diff --git a/modules-available/runmode/lang/de/messages.json b/modules-available/runmode/lang/de/messages.json index 911d48d4..bca70019 100644 --- a/modules-available/runmode/lang/de/messages.json +++ b/modules-available/runmode/lang/de/messages.json @@ -2,6 +2,7 @@ "cannot-edit-module": "Modul {{0}} kann nicht direkt editiert werden", "enabled-removed-save": "{{0}} Rechner gespeichert, {{1}} entfernt", "invalid-modeid": "{{1}} ist kein g\u00fcltiger Betriebsmodus f\u00fcr Modul {{0}}", + "machine-no-permission": "Keine Berechtigung f\u00fcr client {{0}}", "machine-not-found": "Rechner {{0}} nicht gefunden", "machine-not-runmode": "Rechner {{0}} hatte keinen speziellen Betriebsmodus aktiviert", "machine-removed": "Rechner {{0}} entfernt", diff --git a/modules-available/runmode/lang/de/template-tags.json b/modules-available/runmode/lang/de/template-tags.json index 6b45b82c..989e5b1d 100644 --- a/modules-available/runmode/lang/de/template-tags.json +++ b/modules-available/runmode/lang/de/template-tags.json @@ -3,6 +3,7 @@ "lang_assignMachineIntroText": "Definieren Sie hier Clients, die in einem speziellen Betriebsmodus gestartet werden sollen. Sie k\u00f6nnen Rechner anhand der UUID, IP, Hostname oder MAC-Adresse suchen.", "lang_assignRunmodeToMachine": "Betriebsmodus", "lang_confirmDelete": "Wollen Sie den Betriebsmodus f\u00fcr diesen Client entfernen?", + "lang_existingClients": "Vorhandene Clients mit diesem Betriebsmodus", "lang_isclient": "Pool-Client", "lang_machine": "Client", "lang_mode": "Modus", diff --git a/modules-available/runmode/lang/en/messages.json b/modules-available/runmode/lang/en/messages.json index 6d890428..1ca1567a 100644 --- a/modules-available/runmode/lang/en/messages.json +++ b/modules-available/runmode/lang/en/messages.json @@ -2,6 +2,7 @@ "cannot-edit-module": "Module {{0}} cannot be edited directly", "enabled-removed-save": "Saved {{0}} clients, deleted {{1}}", "invalid-modeid": "Module {{0}} doesn't provide mode {{1}}", + "machine-no-permission": "No permission for client {{0}}", "machine-not-found": "Client {{0}} not found", "machine-not-runmode": "No special mode of operation configured for client {{0}}", "machine-removed": "Removed client {{0}}", diff --git a/modules-available/runmode/lang/en/template-tags.json b/modules-available/runmode/lang/en/template-tags.json index 43fd3da5..89cf6b15 100644 --- a/modules-available/runmode/lang/en/template-tags.json +++ b/modules-available/runmode/lang/en/template-tags.json @@ -3,6 +3,7 @@ "lang_assignMachineIntroText": "Define the clients which should start a special runmode configuration. You can search for clients by UUID, IP address, host name or MAC address.", "lang_assignRunmodeToMachine": "Runmode", "lang_confirmDelete": "Do you want to delete the runmode for this client?", + "lang_existingClients": "Existing clients with this run mode", "lang_isclient": "Pool-Client", "lang_machine": "Client", "lang_mode": "Mode", diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 3baac190..60743fb6 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -227,7 +227,7 @@ class Page_Statistics extends Page if (in_array($row['locationid'], $allowedLocations)) { $delete[] = $row['machineuuid']; } else { - Message::addError('no-permission-location', $row['locationid']); + Message::addError('locations.no-permission-location', $row['locationid']); } } if (!empty($delete)) { -- cgit v1.2.3-55-g7522 From 24815e16087b4b1b64e9f380d45d411af32daf42 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 9 Apr 2018 16:56:04 +0200 Subject: Permissions: Consistency: Make all pages require at least one permission to be accessible Closes #3340 --- modules-available/backup/page.inc.php | 1 + modules-available/exams/page.inc.php | 9 +-------- modules-available/locations/page.inc.php | 19 +++++++++++++++---- modules-available/news/page.inc.php | 10 ++-------- modules-available/news/permissions/permissions.json | 3 +++ modules-available/rebootcontrol/page.inc.php | 9 ++++++--- modules-available/serversetup-bwlp/page.inc.php | 6 ++++++ .../serversetup-bwlp/permissions/permissions.json | 3 +++ modules-available/statistics_reporting/page.inc.php | 1 + modules-available/sysconfig/page.inc.php | 2 +- modules-available/syslog/page.inc.php | 1 + modules-available/systemstatus/page.inc.php | 1 + modules-available/webinterface/page.inc.php | 4 ++++ .../webinterface/permissions/permissions.json | 3 +++ 14 files changed, 48 insertions(+), 24 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/backup/page.inc.php b/modules-available/backup/page.inc.php index 14522734..985f39ee 100644 --- a/modules-available/backup/page.inc.php +++ b/modules-available/backup/page.inc.php @@ -23,6 +23,7 @@ class Page_Backup extends Page User::assertPermission("restore"); $this->restore(); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 51975052..15640a73 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -441,16 +441,9 @@ class Page_Exams extends Page protected function doRender() { - if (Request::isPost()) { - $examid = Request::post('examid', 0, 'int'); - } else if (Request::isGet()) { - $examid = Request::get('examid', 0, 'int'); - } else { - die('Neither Post nor Get Request send.'); - } - if ($this->action === "show") { + User::assertPermission('exams.view'); // General title and description Render::addTemplate('page-main-heading'); // List of defined exam periods diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 80a8076b..4d5c6628 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -24,6 +24,9 @@ class Page_Locations extends Page } elseif ($this->action === 'updatesubnets') { $this->updateSubnets(); } + if (Request::isPost()) { + Util::redirect('?do=locations'); + } } private function updateSubnets() @@ -306,10 +309,16 @@ class Page_Locations extends Page protected function doRender() { - $getAction = Request::get('action'); - if (empty($getAction)) { - // Until we have a main landing page? - Util::redirect('?do=Locations&action=showlocations'); + $getAction = Request::get('action', false, 'string'); + if ($getAction === false) { + if (User::hasPermission('location.view')) { + Util::redirect('?do=locations&action=showlocations'); + } elseif (User::hasPermission('subnets.edit')) { + Util::redirect('?do=locations&action=showsubnets'); + } else { + // Trigger permission denied by asserting non-existent permission + User::assertPermission('location.view'); + } } if ($getAction === 'showsubnets') { User::assertPermission('subnets.edit', NULL, '?do=locations'); @@ -324,6 +333,8 @@ class Page_Locations extends Page Render::addTemplate('subnets', array('list' => $rows)); } elseif ($getAction === 'showlocations') { $this->showLocationList(); + } else { + Util::redirect('?do=locations'); } } diff --git a/modules-available/news/page.inc.php b/modules-available/news/page.inc.php index e7b70c0f..1e2e3eef 100644 --- a/modules-available/news/page.inc.php +++ b/modules-available/news/page.inc.php @@ -46,14 +46,8 @@ class Page_News extends Page // check which action we need to do $action = Request::any('action', 'show'); - if ($action === 'clear') { - // clear news input fields - // TODO: is this the right way? - $this->newsId = false; - $this->newsTitle = false; - $this->newsContent = false; - $this->newsDate = false; - } elseif ($action === 'show') { + if ($action === 'show') { + User::assertPermission('access-page'); /* load latest things */ $this->loadLatest('help'); $this->loadLatest('news'); diff --git a/modules-available/news/permissions/permissions.json b/modules-available/news/permissions/permissions.json index 0d9435d7..953599df 100644 --- a/modules-available/news/permissions/permissions.json +++ b/modules-available/news/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "help.delete": { "location-aware": false }, diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index abbdb2c3..041ae74f 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -79,11 +79,14 @@ class Page_RebootControl extends Page //location you want to see, default are "not assigned" clients $requestedLocation = Request::get('location', false, 'int'); $allowedLocs = User::getAllowedLocations("action.*"); + if (empty($allowedLocs)) { + User::assertPermission('action.*'); + } if ($requestedLocation === false) { if (in_array(0, $allowedLocs)) { $requestedLocation = 0; - } elseif (!empty($allowedLocs)) { + } else { $requestedLocation = reset($allowedLocs); } } @@ -105,8 +108,8 @@ class Page_RebootControl extends Page Render::addTemplate('header', $data); // only fill table if user has at least one permission for the location - if ($requestedLocation === false) { - Message::addError('main.no-permission'); + if (!in_array($requestedLocation, $allowedLocs)) { + Message::addError('locations.no-permission-location', $requestedLocation); } else { $data['data'] = RebootQueries::getMachineTable($requestedLocation); Render::addTemplate('_page', $data); diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index ae709da7..78096d7b 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -43,6 +43,12 @@ class Page_ServerSetup extends Page // iPXE stuff changes $this->updatePxeMenu(); } + + if (Request::isPost()) { + Util::redirect('?do=serversetup'); + } + + User::assertPermission('access-page'); } protected function doRender() diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json index 6bae5422..44927506 100644 --- a/modules-available/serversetup-bwlp/permissions/permissions.json +++ b/modules-available/serversetup-bwlp/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "download": { "location-aware": false }, diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index af4b2b12..cc03e4d8 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -84,6 +84,7 @@ class Page_Statistics_Reporting extends Page die(json_encode($report)); } } + User::assertPermission('*'); } /** diff --git a/modules-available/sysconfig/page.inc.php b/modules-available/sysconfig/page.inc.php index 7bb3e599..8d1799af 100644 --- a/modules-available/sysconfig/page.inc.php +++ b/modules-available/sysconfig/page.inc.php @@ -160,7 +160,7 @@ class Page_SysConfig extends Page $pMods = User::hasPermission('module.view-list'); $pConfs = User::hasPermission('config.view-list'); if (!($pMods || $pConfs)) { - Message::addError('main.no-permission'); + User::assertPermission('config.view-list'); } Render::openTag('div', array('class' => 'row')); if ($pConfs) { diff --git a/modules-available/syslog/page.inc.php b/modules-available/syslog/page.inc.php index 3a7513b5..00c55a3f 100644 --- a/modules-available/syslog/page.inc.php +++ b/modules-available/syslog/page.inc.php @@ -25,6 +25,7 @@ class Page_SysLog extends Page } Util::redirect('?do=syslog'); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php index 816caa05..66b30bcf 100644 --- a/modules-available/systemstatus/page.inc.php +++ b/modules-available/systemstatus/page.inc.php @@ -18,6 +18,7 @@ class Page_SystemStatus extends Page User::assertPermission("serverreboot"); $this->rebootTask = Taskmanager::submit('Reboot'); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/webinterface/page.inc.php b/modules-available/webinterface/page.inc.php index 806ffd59..ca52c2ab 100644 --- a/modules-available/webinterface/page.inc.php +++ b/modules-available/webinterface/page.inc.php @@ -28,6 +28,10 @@ class Page_WebInterface extends Page $this->actionCustomization(); break; } + if (Request::isPost()) { + Util::redirect('?do=webinterface'); + } + User::assertPermission('access-page'); } private function actionConfigureHttps() diff --git a/modules-available/webinterface/permissions/permissions.json b/modules-available/webinterface/permissions/permissions.json index fa6f493f..ed81602a 100644 --- a/modules-available/webinterface/permissions/permissions.json +++ b/modules-available/webinterface/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "edit.design": { "location-aware": false }, -- cgit v1.2.3-55-g7522 From 5370b98936418b2b548c023813039b8bf2074a55 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 13 Apr 2018 17:31:56 +0200 Subject: [inc/Module] Overhaul dependency loading and handling of js/css This is supposed to prevent unneeded js/css from being pulled in --- inc/module.inc.php | 63 ++++++++++++++-------- inc/render.inc.php | 4 +- index.php | 2 +- modules-available/adduser/config.json | 4 +- modules-available/backup/config.json | 4 +- modules-available/baseconfig/config.json | 7 ++- modules-available/baseconfig_bwidm/config.json | 6 ++- modules-available/baseconfig_bwlp/config.json | 6 ++- .../baseconfig_partitions_cdn/config.json | 8 +-- modules-available/bootstrap_datepicker/config.json | 17 +++--- modules-available/bootstrap_dialog/config.json | 17 +++--- .../bootstrap_multiselect/config.json | 17 +++--- modules-available/bootstrap_switch/config.json | 13 ++--- modules-available/bootstrap_timepicker/config.json | 17 +++--- modules-available/citymanagement/config.json | 6 +-- modules-available/dnbd3/config.json | 9 ++-- modules-available/dozmod/config.json | 4 +- modules-available/eventlog/config.json | 4 +- modules-available/exams/config.json | 13 +++-- modules-available/imgmanagement/config.json | 6 +-- modules-available/internetaccess/config.json | 4 +- modules-available/js_chart/config.json | 13 ++--- modules-available/js_circles/config.json | 13 ++--- modules-available/js_jqueryui/config.json | 17 +++--- modules-available/js_moment/config.json | 17 +++--- modules-available/js_selectize/config.json | 17 +++--- modules-available/js_stupidtable/config.json | 13 ++--- modules-available/js_vis/config.json | 19 ++++--- modules-available/locationinfo/config.json | 11 ++-- modules-available/locations/config.json | 4 +- modules-available/main/config.json | 3 +- modules-available/minilinux/config.json | 4 +- modules-available/news/config.json | 8 +-- modules-available/permissionmanager/config.json | 10 ++-- modules-available/rebootcontrol/config.json | 9 ++-- modules-available/roomplanner/config.json | 11 +++- modules-available/runmode/config.json | 9 ++-- modules-available/serversetup-bwlp/config.json | 4 +- modules-available/session/config.json | 3 +- modules-available/statistics/config.json | 12 +++-- modules-available/statistics_reporting/config.json | 9 +++- modules-available/summernote/config.json | 17 +++--- modules-available/support/config.json | 4 +- modules-available/sysconfig/config.json | 4 +- modules-available/sysconfignew/config.json | 4 +- modules-available/syslog/config.json | 8 +-- modules-available/systemstatus/config.json | 8 +-- modules-available/translation/config.json | 4 +- modules-available/usermanagement/config.json | 6 +-- modules-available/vmstore/config.json | 4 +- modules-available/webinterface/config.json | 4 +- 51 files changed, 293 insertions(+), 207 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/inc/module.inc.php b/inc/module.inc.php index 7610c720..fa2c4b98 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -35,7 +35,7 @@ class Module if ($module === false) return false; if ($activate) { - $module->activate(); + $module->activate(1, true); } return !$module->hasMissingDependencies(); } @@ -139,9 +139,11 @@ class Module */ private $category = false; + private $clientPlugin = false; private $depsMissing = false; private $depsChecked = false; private $activated = false; + private $directActivation = false; private $dependencies = array(); private $name; /** @@ -165,6 +167,9 @@ class Module if (isset($json['category']) && is_string($json['category'])) { $this->category = $json['category']; } + if (isset($json['client-plugin'])) { + $this->clientPlugin = (bool)$json['client-plugin']; + } $this->name = $name; } @@ -184,21 +189,33 @@ class Module return new $class(); } - public function activate($depth = 1) + public function activate($depth, $direct) { - if ($this->activated !== false || $this->depsMissing) - return $this->activated !== false; + if ($this->depsMissing) + return false; + if ($this->activated !== false && ($this->directActivation || !$direct)) + return true; + if ($depth === null && $direct === null) { + // This is the current page, always load its scripts + $this->clientPlugin = true; + $direct = true; + } + if ($this->activated === false) { + spl_autoload_register(function ($class) { + $file = 'modules/' . $this->name . '/inc/' . preg_replace('/[^a-z0-9]/', '', strtolower($class)) . '.inc.php'; + if (!file_exists($file)) + return; + require_once $file; + }); + } $this->activated = $depth; - spl_autoload_register(function($class) { - $file = 'modules/' . $this->name . '/inc/' . preg_replace('/[^a-z0-9]/', '', strtolower($class)) . '.inc.php'; - if (!file_exists($file)) - return; - require_once $file; - }); + if ($direct) { + $this->directActivation = true; + } foreach ($this->dependencies as $dep) { $get = self::get($dep); if ($get !== false) { - $get->activate($depth + 1); + $get->activate($depth + 1, $direct && $this->clientPlugin); } } return true; @@ -263,26 +280,26 @@ class Module return 'modules/' . $this->name; } - public function getScripts($externalOnly) + public function getScripts() { - if (!$externalOnly) { - if (!isset($this->scripts['clientscript.js']) && file_exists($this->getDir() . '/clientscript.js')) { - $this->scripts['clientscript.js'] = false; + if ($this->directActivation && $this->clientPlugin) { + if (!in_array('clientscript.js', $this->scripts)) { + $this->scripts[] = 'clientscript.js'; } - return array_keys($this->scripts); + return $this->scripts; } - return array_keys(array_filter($this->scripts)); + return []; } - public function getCss($externalOnly) + public function getCss() { - if (!$externalOnly) { - if (!isset($this->css['style.css']) && file_exists($this->getDir() . '/style.css')) { - $this->css['style.css'] = false; + if ($this->directActivation && $this->clientPlugin) { + if (!in_array('style.css', $this->css)) { + $this->css[] = 'style.css'; } - return array_keys($this->css); + return $this->css; } - return array_keys(array_filter($this->css)); + return []; } } diff --git a/inc/render.inc.php b/inc/render.inc.php index 0ce39dbe..4b1d3643 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -84,7 +84,7 @@ class Render '; // Include any module specific styles foreach ($modules as $module) { - $files = $module->getCss($module !== $pageModule); + $files = $module->getCss(); foreach ($files as $file) { echo ''; } @@ -113,7 +113,7 @@ class Render '; foreach ($modules as $module) { - $files = $module->getScripts($module !== $pageModule); + $files = $module->getScripts(); foreach ($files as $file) { echo ''; } diff --git a/index.php b/index.php index 4816ef42..1ecd2109 100644 --- a/index.php +++ b/index.php @@ -79,7 +79,7 @@ abstract class Page if (self::$module === false) { Util::traceError('Invalid Module: ' . $name); } - self::$module->activate(); + self::$module->activate(null, null); self::$instance = self::$module->newPage(); } diff --git a/modules-available/adduser/config.json b/modules-available/adduser/config.json index 706412d0..110f8b67 100644 --- a/modules-available/adduser/config.json +++ b/modules-available/adduser/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/backup/config.json b/modules-available/backup/config.json index 706412d0..110f8b67 100644 --- a/modules-available/backup/config.json +++ b/modules-available/backup/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/baseconfig/config.json b/modules-available/baseconfig/config.json index e4d906e1..357a117e 100644 --- a/modules-available/baseconfig/config.json +++ b/modules-available/baseconfig/config.json @@ -1,4 +1,7 @@ { "category": "main.settings-client", - "dependencies" : ["js_selectize", "bootstrap_multiselect"] -} + "dependencies": [ + "js_selectize", + "bootstrap_multiselect" + ] +} \ No newline at end of file diff --git a/modules-available/baseconfig_bwidm/config.json b/modules-available/baseconfig_bwidm/config.json index af67a188..7e6cf06a 100644 --- a/modules-available/baseconfig_bwidm/config.json +++ b/modules-available/baseconfig_bwidm/config.json @@ -1,3 +1,5 @@ { - "dependencies": ["baseconfig"] -} + "dependencies": [ + "baseconfig" + ] +} \ No newline at end of file diff --git a/modules-available/baseconfig_bwlp/config.json b/modules-available/baseconfig_bwlp/config.json index af67a188..7e6cf06a 100644 --- a/modules-available/baseconfig_bwlp/config.json +++ b/modules-available/baseconfig_bwlp/config.json @@ -1,3 +1,5 @@ { - "dependencies": ["baseconfig"] -} + "dependencies": [ + "baseconfig" + ] +} \ No newline at end of file diff --git a/modules-available/baseconfig_partitions_cdn/config.json b/modules-available/baseconfig_partitions_cdn/config.json index a355eef3..fd4c6f4b 100644 --- a/modules-available/baseconfig_partitions_cdn/config.json +++ b/modules-available/baseconfig_partitions_cdn/config.json @@ -1,4 +1,6 @@ { - "category": "main.settings-client", - "dependencies": [ "baseconfig" ] -} + "category": "main.settings-client", + "dependencies": [ + "baseconfig" + ] +} \ No newline at end of file diff --git a/modules-available/bootstrap_datepicker/config.json b/modules-available/bootstrap_datepicker/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/bootstrap_datepicker/config.json +++ b/modules-available/bootstrap_datepicker/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/bootstrap_dialog/config.json b/modules-available/bootstrap_dialog/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/bootstrap_dialog/config.json +++ b/modules-available/bootstrap_dialog/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/bootstrap_multiselect/config.json b/modules-available/bootstrap_multiselect/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/bootstrap_multiselect/config.json +++ b/modules-available/bootstrap_multiselect/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/bootstrap_switch/config.json b/modules-available/bootstrap_switch/config.json index de4d37b4..3cf0d162 100644 --- a/modules-available/bootstrap_switch/config.json +++ b/modules-available/bootstrap_switch/config.json @@ -1,8 +1,9 @@ { - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true } \ No newline at end of file diff --git a/modules-available/bootstrap_timepicker/config.json b/modules-available/bootstrap_timepicker/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/bootstrap_timepicker/config.json +++ b/modules-available/bootstrap_timepicker/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/citymanagement/config.json b/modules-available/citymanagement/config.json index e87cbf7d..b356dfc6 100644 --- a/modules-available/citymanagement/config.json +++ b/modules-available/citymanagement/config.json @@ -1,4 +1,4 @@ { - "category":"citymanagement.cities", - "permission":"0" -} + "category": "citymanagement.cities", + "permission": "0" +} \ No newline at end of file diff --git a/modules-available/dnbd3/config.json b/modules-available/dnbd3/config.json index f84a4170..9670ded9 100644 --- a/modules-available/dnbd3/config.json +++ b/modules-available/dnbd3/config.json @@ -1,4 +1,7 @@ { - "category":"main.settings-server", - "dependencies":["locations","runmode"] -} + "category": "main.settings-server", + "dependencies": [ + "locations", + "runmode" + ] +} \ No newline at end of file diff --git a/modules-available/dozmod/config.json b/modules-available/dozmod/config.json index 706412d0..110f8b67 100644 --- a/modules-available/dozmod/config.json +++ b/modules-available/dozmod/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/eventlog/config.json b/modules-available/eventlog/config.json index 6778348d..aa23adb5 100644 --- a/modules-available/eventlog/config.json +++ b/modules-available/eventlog/config.json @@ -1,3 +1,3 @@ { - "category":"main.status" -} + "category": "main.status" +} \ No newline at end of file diff --git a/modules-available/exams/config.json b/modules-available/exams/config.json index 0780ebef..a99d1c1a 100644 --- a/modules-available/exams/config.json +++ b/modules-available/exams/config.json @@ -1,5 +1,12 @@ { - "category":"main.content", - "dependencies": [ "locations", "js_vis", "js_stupidtable", "bootstrap_datepicker", "bootstrap_timepicker", "bootstrap_multiselect"], + "category": "main.content", + "dependencies": [ + "locations", + "js_vis", + "js_stupidtable", + "bootstrap_datepicker", + "bootstrap_timepicker", + "bootstrap_multiselect" + ], "permission": "0" -} +} \ No newline at end of file diff --git a/modules-available/imgmanagement/config.json b/modules-available/imgmanagement/config.json index 6454d96f..2fbb822f 100644 --- a/modules-available/imgmanagement/config.json +++ b/modules-available/imgmanagement/config.json @@ -1,4 +1,4 @@ { - "category":"main.content", - "permission":"1" -} + "category": "main.content", + "permission": "1" +} \ No newline at end of file diff --git a/modules-available/internetaccess/config.json b/modules-available/internetaccess/config.json index 706412d0..110f8b67 100644 --- a/modules-available/internetaccess/config.json +++ b/modules-available/internetaccess/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/js_chart/config.json b/modules-available/js_chart/config.json index de4d37b4..3cf0d162 100644 --- a/modules-available/js_chart/config.json +++ b/modules-available/js_chart/config.json @@ -1,8 +1,9 @@ { - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true } \ No newline at end of file diff --git a/modules-available/js_circles/config.json b/modules-available/js_circles/config.json index de4d37b4..3cf0d162 100644 --- a/modules-available/js_circles/config.json +++ b/modules-available/js_circles/config.json @@ -1,8 +1,9 @@ { - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true } \ No newline at end of file diff --git a/modules-available/js_jqueryui/config.json b/modules-available/js_jqueryui/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/js_jqueryui/config.json +++ b/modules-available/js_jqueryui/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/js_moment/config.json b/modules-available/js_moment/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/js_moment/config.json +++ b/modules-available/js_moment/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/js_selectize/config.json b/modules-available/js_selectize/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/js_selectize/config.json +++ b/modules-available/js_selectize/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/js_stupidtable/config.json b/modules-available/js_stupidtable/config.json index cf932d7e..3cf0d162 100644 --- a/modules-available/js_stupidtable/config.json +++ b/modules-available/js_stupidtable/config.json @@ -1,8 +1,9 @@ { - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true } \ No newline at end of file diff --git a/modules-available/js_vis/config.json b/modules-available/js_vis/config.json index 3b027d31..4c870a22 100644 --- a/modules-available/js_vis/config.json +++ b/modules-available/js_vis/config.json @@ -1,9 +1,12 @@ { - "dependencies" : ["js_moment"], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [ + "js_moment" + ], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/locationinfo/config.json b/modules-available/locationinfo/config.json index 87825809..837acfcf 100644 --- a/modules-available/locationinfo/config.json +++ b/modules-available/locationinfo/config.json @@ -1,4 +1,9 @@ { - "category":"main.beta", - "dependencies": ["js_jqueryui", "bootstrap_timepicker", "locations", "bootstrap_switch"] -} + "category": "main.beta", + "dependencies": [ + "js_jqueryui", + "bootstrap_timepicker", + "locations", + "bootstrap_switch" + ] +} \ No newline at end of file diff --git a/modules-available/locations/config.json b/modules-available/locations/config.json index 706412d0..110f8b67 100644 --- a/modules-available/locations/config.json +++ b/modules-available/locations/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/main/config.json b/modules-available/main/config.json index 2c63c085..0637a088 100644 --- a/modules-available/main/config.json +++ b/modules-available/main/config.json @@ -1,2 +1 @@ -{ -} +[] \ No newline at end of file diff --git a/modules-available/minilinux/config.json b/modules-available/minilinux/config.json index 28d71577..6c7b7146 100644 --- a/modules-available/minilinux/config.json +++ b/modules-available/minilinux/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-client" -} + "category": "main.settings-client" +} \ No newline at end of file diff --git a/modules-available/news/config.json b/modules-available/news/config.json index e076ea5c..23cd1443 100644 --- a/modules-available/news/config.json +++ b/modules-available/news/config.json @@ -1,4 +1,6 @@ { - "category":"main.content", - "dependencies": [ "js_stupidtable" ] -} + "category": "main.content", + "dependencies": [ + "js_stupidtable" + ] +} \ No newline at end of file diff --git a/modules-available/permissionmanager/config.json b/modules-available/permissionmanager/config.json index d2071984..25b61de3 100644 --- a/modules-available/permissionmanager/config.json +++ b/modules-available/permissionmanager/config.json @@ -1,4 +1,8 @@ { - "category":"main.content", - "dependencies": [ "locations", "js_stupidtable", "js_selectize" ] -} + "category": "main.content", + "dependencies": [ + "locations", + "js_stupidtable", + "js_selectize" + ] +} \ No newline at end of file diff --git a/modules-available/rebootcontrol/config.json b/modules-available/rebootcontrol/config.json index d8ab5868..43d2c28f 100644 --- a/modules-available/rebootcontrol/config.json +++ b/modules-available/rebootcontrol/config.json @@ -1,4 +1,7 @@ { - "category":"main.beta", - "dependencies": [ "locations", "js_stupidtable" ] -} + "category": "main.beta", + "dependencies": [ + "locations", + "js_stupidtable" + ] +} \ No newline at end of file diff --git a/modules-available/roomplanner/config.json b/modules-available/roomplanner/config.json index 537714c3..62f38773 100644 --- a/modules-available/roomplanner/config.json +++ b/modules-available/roomplanner/config.json @@ -1,3 +1,10 @@ { - "dependencies": ["js_jqueryui", "js_selectize", "bootstrap_dialog", "statistics", "locations", "runmode"] -} + "dependencies": [ + "js_jqueryui", + "js_selectize", + "bootstrap_dialog", + "statistics", + "locations", + "runmode" + ] +} \ No newline at end of file diff --git a/modules-available/runmode/config.json b/modules-available/runmode/config.json index e3c07d48..84e044ce 100644 --- a/modules-available/runmode/config.json +++ b/modules-available/runmode/config.json @@ -1,4 +1,7 @@ { - "dependencies": [ "statistics", "js_selectize" ], - "permission":"0" -} + "dependencies": [ + "statistics", + "js_selectize" + ], + "permission": "0" +} \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/config.json b/modules-available/serversetup-bwlp/config.json index 7205d70a..36268c6a 100644 --- a/modules-available/serversetup-bwlp/config.json +++ b/modules-available/serversetup-bwlp/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-server" -} + "category": "main.settings-server" +} \ No newline at end of file diff --git a/modules-available/session/config.json b/modules-available/session/config.json index 2c63c085..0637a088 100644 --- a/modules-available/session/config.json +++ b/modules-available/session/config.json @@ -1,2 +1 @@ -{ -} +[] \ No newline at end of file diff --git a/modules-available/statistics/config.json b/modules-available/statistics/config.json index 333f881a..412dc3cb 100644 --- a/modules-available/statistics/config.json +++ b/modules-available/statistics/config.json @@ -1,5 +1,9 @@ { - "category":"main.status", - "dependencies": [ "js_chart", "js_selectize", "bootstrap_datepicker"], - "permission":"0" -} + "category": "main.status", + "dependencies": [ + "js_chart", + "js_selectize", + "bootstrap_datepicker" + ], + "permission": "0" +} \ No newline at end of file diff --git a/modules-available/statistics_reporting/config.json b/modules-available/statistics_reporting/config.json index 78ca35ba..c439efa8 100644 --- a/modules-available/statistics_reporting/config.json +++ b/modules-available/statistics_reporting/config.json @@ -1,4 +1,9 @@ { "category": "main.status", - "dependencies": [ "statistics", "locations", "js_stupidtable", "js_jqueryui" ] -} + "dependencies": [ + "statistics", + "locations", + "js_stupidtable", + "js_jqueryui" + ] +} \ No newline at end of file diff --git a/modules-available/summernote/config.json b/modules-available/summernote/config.json index 5a0c7960..69bb0aa9 100644 --- a/modules-available/summernote/config.json +++ b/modules-available/summernote/config.json @@ -1,9 +1,10 @@ { - "dependencies" : [], - "css": { - "style.css": true - }, - "scripts": { - "clientscript.js": true - } -} + "dependencies": [], + "css": [ + "style.css" + ], + "scripts": [ + "clientscript.js" + ], + "client-plugin": true +} \ No newline at end of file diff --git a/modules-available/support/config.json b/modules-available/support/config.json index 706412d0..110f8b67 100644 --- a/modules-available/support/config.json +++ b/modules-available/support/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/sysconfig/config.json b/modules-available/sysconfig/config.json index 28d71577..6c7b7146 100644 --- a/modules-available/sysconfig/config.json +++ b/modules-available/sysconfig/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-client" -} + "category": "main.settings-client" +} \ No newline at end of file diff --git a/modules-available/sysconfignew/config.json b/modules-available/sysconfignew/config.json index 28d71577..6c7b7146 100644 --- a/modules-available/sysconfignew/config.json +++ b/modules-available/sysconfignew/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-client" -} + "category": "main.settings-client" +} \ No newline at end of file diff --git a/modules-available/syslog/config.json b/modules-available/syslog/config.json index 2b718a8e..691bd4df 100644 --- a/modules-available/syslog/config.json +++ b/modules-available/syslog/config.json @@ -1,4 +1,6 @@ { - "category":"main.status", - "dependencies":["js_selectize"] -} + "category": "main.status", + "dependencies": [ + "js_selectize" + ] +} \ No newline at end of file diff --git a/modules-available/systemstatus/config.json b/modules-available/systemstatus/config.json index 3c2efce7..cf774d1b 100644 --- a/modules-available/systemstatus/config.json +++ b/modules-available/systemstatus/config.json @@ -1,4 +1,6 @@ { - "category":"main.status", - "dependencies": [ "js_circles" ] -} + "category": "main.status", + "dependencies": [ + "js_circles" + ] +} \ No newline at end of file diff --git a/modules-available/translation/config.json b/modules-available/translation/config.json index 706412d0..110f8b67 100644 --- a/modules-available/translation/config.json +++ b/modules-available/translation/config.json @@ -1,3 +1,3 @@ { - "category":"main.content" -} + "category": "main.content" +} \ No newline at end of file diff --git a/modules-available/usermanagement/config.json b/modules-available/usermanagement/config.json index 9c66d6bf..428315ba 100644 --- a/modules-available/usermanagement/config.json +++ b/modules-available/usermanagement/config.json @@ -1,4 +1,4 @@ { - "category":"main.users", - "permission":"0" -} + "category": "main.users", + "permission": "0" +} \ No newline at end of file diff --git a/modules-available/vmstore/config.json b/modules-available/vmstore/config.json index 7205d70a..36268c6a 100644 --- a/modules-available/vmstore/config.json +++ b/modules-available/vmstore/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-server" -} + "category": "main.settings-server" +} \ No newline at end of file diff --git a/modules-available/webinterface/config.json b/modules-available/webinterface/config.json index 7205d70a..36268c6a 100644 --- a/modules-available/webinterface/config.json +++ b/modules-available/webinterface/config.json @@ -1,3 +1,3 @@ { - "category":"main.settings-server" -} + "category": "main.settings-server" +} \ No newline at end of file -- cgit v1.2.3-55-g7522 From b48e755affc865547ab148340f586ae9a297c8f5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 24 Apr 2018 15:54:00 +0200 Subject: [rebootcontrol] Try clients first that are known to be online This prevents long delays if a large amount of clients is selected where the majority is offline. --- modules-available/rebootcontrol/inc/rebootqueries.inc.php | 4 ++-- modules-available/rebootcontrol/page.inc.php | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/inc/rebootqueries.inc.php b/modules-available/rebootcontrol/inc/rebootqueries.inc.php index 3dc3183f..525a9e58 100644 --- a/modules-available/rebootcontrol/inc/rebootqueries.inc.php +++ b/modules-available/rebootcontrol/inc/rebootqueries.inc.php @@ -44,13 +44,13 @@ class RebootQueries /** * Get machines by list of UUIDs * @param string[] $list list of system UUIDs - * @return array list of machines with machineuuid, clientip and locationid + * @return array list of machines with machineuuid, clientip, state and locationid */ public static function getMachinesByUuid($list) { if (empty($list)) return array(); - $res = Database::simpleQuery("SELECT machineuuid, clientip, locationid FROM machine + $res = Database::simpleQuery("SELECT machineuuid, clientip, state, locationid FROM machine WHERE machineuuid IN (:list)", compact('list')); return $res->fetchAll(PDO::FETCH_ASSOC); } diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index 041ae74f..675c94f8 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -49,7 +49,13 @@ class Page_RebootControl extends Page Message::addError('no-clients-selected'); Util::redirect(); } - + usort($actualClients, function($a, $b) { + $a = ($a['state'] === 'IDLE' || $a['state'] === 'OCCUPIED'); + $b = ($b['state'] === 'IDLE' || $b['state'] === 'OCCUPIED'); + if ($a === $b) + return 0; + return $a ? -1 : 1; + }); $task = RebootControl::execute($actualClients, $this->action === 'shutdown', $minutes, $locationId); Util::redirect("?do=rebootcontrol&taskid=".$task["id"]); } -- cgit v1.2.3-55-g7522 From 4bfa7b7d0c49d2f6a47f0b279122cefac1752194 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Apr 2018 16:08:50 +0200 Subject: [rebootcontrol] Fix keypair regen feedback --- .../rebootcontrol/templates/header.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/templates/header.html b/modules-available/rebootcontrol/templates/header.html index b84cb426..e171ccd6 100644 --- a/modules-available/rebootcontrol/templates/header.html +++ b/modules-available/rebootcontrol/templates/header.html @@ -41,11 +41,14 @@ @@ -60,4 +63,17 @@ window.location.replace("?do=rebootcontrol&location="+location); } + function generateNewKeypair() { + if (!confirm('{{lang_confirmNewKeypair}}')) + return; + $.ajax({ + url: '?do=rebootcontrol', + type: 'POST', + data: { action: "generateNewKeypair", token: TOKEN }, + success: function(value) { + $('#pubkey').text(value); + } + }); + } + \ No newline at end of file -- cgit v1.2.3-55-g7522 From 7d4b41dc7e85b4f5f249c61db11ae27d53144c9c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Apr 2018 16:46:18 +0200 Subject: [rebootcontrol] Nicer status list; list of all running jobs --- .../rebootcontrol/inc/rebootcontrol.inc.php | 65 ++++++++++++++++++++-- .../rebootcontrol/inc/rebootqueries.inc.php | 4 +- .../rebootcontrol/lang/de/template-tags.json | 6 ++ .../rebootcontrol/lang/en/template-tags.json | 6 ++ modules-available/rebootcontrol/page.inc.php | 48 +++++++++++++--- .../rebootcontrol/templates/_page.html | 44 +++++++-------- .../rebootcontrol/templates/status.html | 26 ++++++--- .../rebootcontrol/templates/task-list.html | 33 +++++++++++ 8 files changed, 186 insertions(+), 46 deletions(-) create mode 100644 modules-available/rebootcontrol/templates/task-list.html (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php index 789552cd..1024b036 100644 --- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php +++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php @@ -3,28 +3,83 @@ class RebootControl { + const KEY_TASKLIST = 'rebootcontrol.tasklist'; + + const REBOOT = 'REBOOT'; + const KEXEC_REBOOT = 'KEXEC_REBOOT'; + const SHUTDOWN = 'SHUTDOWN'; + /** * @param string[] $uuids List of machineuuids to reboot + * @param bool $kexec whether to trigger kexec-reboot instead of full BIOS cycle * @return false|array task struct for the reboot job */ - public static function reboot($uuids) + public static function reboot($uuids, $kexec = false) { $list = RebootQueries::getMachinesByUuid($uuids); if (empty($list)) return false; - return self::execute($list, false, 0, 0); + return self::execute($list, $kexec ? RebootControl::KEXEC_REBOOT : RebootControl::REBOOT, 0, 0); } - public static function execute($list, $shutdown, $minutes, $locationId) + /** + * @param array $list list of clients containing each keys 'machineuuid' and 'clientip' + * @param string $mode reboot mode: RebootControl::REBOOT ::KEXEC_REBOOT or ::SHUTDOWN + * @param int $minutes delay in minutes for action + * @param int $locationId meta data only: locationId of clients + * @return array|false the task, or false if it could not be started + */ + public static function execute($list, $mode, $minutes, $locationId) { - return Taskmanager::submit("RemoteReboot", array( + $task = Taskmanager::submit("RemoteReboot", array( "clients" => $list, - "shutdown" => $shutdown, + "mode" => $mode, "minutes" => $minutes, "locationId" => $locationId, "sshkey" => SSHKey::getPrivateKey(), "port" => 9922, // Hard-coded, must match mgmt-sshd module )); + if (!Taskmanager::isFailed($task)) { + Property::addToList(RebootControl::KEY_TASKLIST, $locationId . '/' . $task["id"], 60 * 24); + } + return $task; + } + + /** + * @param int[]|null $locations filter by these locations + * @return array list of active tasks for reboots/shutdowns. + */ + public static function getActiveTasks($locations = null) + { + if (is_array($locations) && in_array(0,$locations)) { + $locations = null; + } + $list = Property::getList(RebootControl::KEY_TASKLIST); + $return = []; + foreach ($list as $entry) { + $p = explode('/', $entry, 2); + if (count($p) !== 2) { + Property::removeFromList(RebootControl::KEY_TASKLIST, $entry); + continue; + } + if (is_array($locations) && !in_array($p[0], $locations)) // Ignore + continue; + $id = $p[1]; + $task = Taskmanager::status($id); + if ($task === false) { + Property::removeFromList(RebootControl::KEY_TASKLIST, $entry); + continue; + } + $return[] = [ + 'taskId' => $task['id'], + 'locationId' => $task['data']['locationId'], + 'time' => $task['data']['time'], + 'mode' => $task['data']['mode'], + 'clientCount' => count($task['data']['clients']), + 'status' => $task['statusCode'], + ]; + } + return $return; } } \ No newline at end of file diff --git a/modules-available/rebootcontrol/inc/rebootqueries.inc.php b/modules-available/rebootcontrol/inc/rebootqueries.inc.php index 525a9e58..063b36e4 100644 --- a/modules-available/rebootcontrol/inc/rebootqueries.inc.php +++ b/modules-available/rebootcontrol/inc/rebootqueries.inc.php @@ -44,13 +44,13 @@ class RebootQueries /** * Get machines by list of UUIDs * @param string[] $list list of system UUIDs - * @return array list of machines with machineuuid, clientip, state and locationid + * @return array list of machines with machineuuid, hostname, clientip, state and locationid */ public static function getMachinesByUuid($list) { if (empty($list)) return array(); - $res = Database::simpleQuery("SELECT machineuuid, clientip, state, locationid FROM machine + $res = Database::simpleQuery("SELECT machineuuid, hostname, clientip, state, locationid FROM machine WHERE machineuuid IN (:list)", compact('list')); return $res->fetchAll(PDO::FETCH_ASSOC); } diff --git a/modules-available/rebootcontrol/lang/de/template-tags.json b/modules-available/rebootcontrol/lang/de/template-tags.json index eccc8738..c678ef88 100644 --- a/modules-available/rebootcontrol/lang/de/template-tags.json +++ b/modules-available/rebootcontrol/lang/de/template-tags.json @@ -1,13 +1,17 @@ { + "lang_activeTasks": "Laufende Jobs", "lang_authFail": "Authentifizierung fehlgeschlagen", "lang_client": "Client", + "lang_clientCount": "# Clients", "lang_confirmNewKeypair": "Wirklich neues Schl\u00fcsselpaar erzeugen?", "lang_connecting": "Verbinde...", "lang_error": "Nicht erreichbar", "lang_genNew": "Neues Schl\u00fcsselpaar generieren", "lang_ip": "IP", + "lang_kexecRebootCheck": "Schneller Reboot direkt in bwLehrpool", "lang_location": "Standort", "lang_minutes": " Minuten", + "lang_mode": "Modus", "lang_newKeypairExplanation": "Sie k\u00f6nnen ein neues Schl\u00fcsselpaar erzeugen lassen. In diesem Fall wird das alte Schl\u00fcsselpaar verworfen, sodass alle zum jetzigen Zeitpunkt bereits gestarteten Rechner nicht mehr aus der Ferne bedient werden k\u00f6nnen, bis diese manuell neugestartet wurden.", "lang_off": "Aus", "lang_on": "An", @@ -18,6 +22,7 @@ "lang_rebootButton": "Neustarten", "lang_rebootCheck": "Wollen Sie die ausgew\u00e4hlten Rechner wirklich neustarten?", "lang_rebootControl": "Reboot Control", + "lang_rebootIn": "Neustart in:", "lang_rebooting": "Neustart...", "lang_selectall": "Alle ausw\u00e4hlen", "lang_selected": "Ausgew\u00e4hlt", @@ -29,5 +34,6 @@ "lang_shutdownCheck": "Wollen Sie die ausgew\u00e4hlten Rechner wirklich herunterfahren?", "lang_shutdownIn": "Herunterfahren in: ", "lang_status": "Status", + "lang_time": "Zeit", "lang_unselectall": "Alle abw\u00e4hlen" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/lang/en/template-tags.json b/modules-available/rebootcontrol/lang/en/template-tags.json index c2346044..c64014ff 100644 --- a/modules-available/rebootcontrol/lang/en/template-tags.json +++ b/modules-available/rebootcontrol/lang/en/template-tags.json @@ -1,13 +1,17 @@ { + "lang_activeTasks": "Active tasks", "lang_authFail": "Authentication failed", "lang_client": "Client", + "lang_clientCount": "# clients", "lang_confirmNewKeypair": "Really create new key pair?", "lang_connecting": "Connecting...", "lang_error": "Not available", "lang_genNew": "Generate new keypair", "lang_ip": "IP", + "lang_kexecRebootCheck": "Quick reboot straight to bwLehrpool (kexec)", "lang_location": "Location", "lang_minutes": " Minutes", + "lang_mode": "Mode", "lang_newKeypairExplanation": "You can create a new keypair, which will replace the old one. Please note that after doing so, you cannot poweroff or reboot clients that are already running, since they still use the old key. They have to be rebooted manually first.", "lang_off": "Off", "lang_on": "On", @@ -18,6 +22,7 @@ "lang_rebootButton": "Reboot", "lang_rebootCheck": "Do you really want to reboot the selected clients?", "lang_rebootControl": "Reboot Control", + "lang_rebootIn": "Reboot in:", "lang_rebooting": "Rebooting...", "lang_selectall": "Select all", "lang_selected": "Selected", @@ -29,5 +34,6 @@ "lang_shutdownCheck": "Do you really want to shut down the selected clients?", "lang_shutdownIn": "Shutdown in: ", "lang_status": "Status", + "lang_time": "Time", "lang_unselectall": "Unselect all" } \ No newline at end of file diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index 675c94f8..3a438504 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -27,7 +27,6 @@ class Page_RebootControl extends Page Message::addError('no-clients-selected'); Util::redirect(); } - $minutes = Request::post('minutes', 0, 'int'); $actualClients = RebootQueries::getMachinesByUuid($requestedClients); if (count($actualClients) !== count($requestedClients)) { @@ -56,8 +55,22 @@ class Page_RebootControl extends Page return 0; return $a ? -1 : 1; }); - $task = RebootControl::execute($actualClients, $this->action === 'shutdown', $minutes, $locationId); - Util::redirect("?do=rebootcontrol&taskid=".$task["id"]); + if ($this->action === 'shutdown') { + $mode = 'SHUTDOWN'; + $minutes = Request::post('s-minutes', 0, 'int'); + } elseif (Request::any('quick', false, 'string') === 'on') { + $mode = 'KEXEC_REBOOT'; + $minutes = Request::post('r-minutes', 0, 'int'); + } else { + $mode = 'REBOOT'; + $minutes = Request::post('r-minutes', 0, 'int'); + } + $task = RebootControl::execute($actualClients, $mode, $minutes, $locationId); + if (Taskmanager::isTask($task)) { + Util::redirect("?do=rebootcontrol&taskid=" . $task["id"]); + } else { + Util::redirect("?do=rebootcontrol"); + } } } @@ -71,15 +84,22 @@ class Page_RebootControl extends Page if ($this->action === 'show') { $data = []; - $taskId = Request::get("taskid"); + $task = Request::get("taskid", false, 'string'); + if ($task !== false) { + $task = Taskmanager::status($task); + } - if ($taskId && Taskmanager::isTask($taskId)) { - $task = Taskmanager::status($taskId); - $data['taskId'] = $taskId; + if (Taskmanager::isTask($task)) { + + $data['taskId'] = $task['id']; $data['locationId'] = $task['data']['locationId']; $data['locationName'] = Location::getName($task['data']['locationId']); - $data['clients'] = $task['data']['clients']; + $uuids = array_map(function($entry) { + return $entry['machineuuid']; + }, $task['data']['clients']); + $data['clients'] = RebootQueries::getMachinesByUuid($uuids); Render::addTemplate('status', $data); + } else { //location you want to see, default are "not assigned" clients @@ -103,6 +123,8 @@ class Page_RebootControl extends Page foreach ($data['locations'] as &$loc) { if (!in_array($loc["locationid"], $allowedLocs)) { $loc["disabled"] = "disabled"; + } elseif ($loc["locationid"] == $requestedLocation) { + $data['location'] = $loc['locationname']; } } // Always show public key (it's public, isn't it?) @@ -121,6 +143,16 @@ class Page_RebootControl extends Page Render::addTemplate('_page', $data); } + // Append list of active reboot/shutdown tasks + $active = RebootControl::getActiveTasks($allowedLocs); + if (!empty($active)) { + foreach ($active as &$entry) { + $entry['locationName'] = Location::getName($entry['locationId']); + } + unset($entry); + Render::addTemplate('task-list', ['list' => $active]); + } + } } } diff --git a/modules-available/rebootcontrol/templates/_page.html b/modules-available/rebootcontrol/templates/_page.html index 82f82b02..a124e165 100644 --- a/modules-available/rebootcontrol/templates/_page.html +++ b/modules-available/rebootcontrol/templates/_page.html @@ -1,4 +1,6 @@ - +

    {{location}}

    + +
    @@ -45,9 +47,7 @@
    - - -