summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics
diff options
context:
space:
mode:
authorSimon Rettberg2019-12-07 13:52:54 +0100
committerSimon Rettberg2019-12-07 13:52:54 +0100
commit3e45ec44d22f03ca6642e08f695c6d7274cecfaf (patch)
treea71b2ec81895b198757d8ec7272548b42ee074b8 /modules-available/statistics
parent[apis/cron] Simple logging function for debugging (diff)
downloadslx-admin-3e45ec44d22f03ca6642e08f695c6d7274cecfaf.tar.gz
slx-admin-3e45ec44d22f03ca6642e08f695c6d7274cecfaf.tar.xz
slx-admin-3e45ec44d22f03ca6642e08f695c6d7274cecfaf.zip
[statistics/rebootcontrol] Add WOL button to statistics module
* Overhauled task display in rebootcontrol module * Can only add subnets by CIDR now instead of start and end
Diffstat (limited to 'modules-available/statistics')
-rw-r--r--modules-available/statistics/lang/de/template-tags.json1
-rw-r--r--modules-available/statistics/lang/en/template-tags.json1
-rw-r--r--modules-available/statistics/page.inc.php60
-rw-r--r--modules-available/statistics/pages/list.inc.php4
-rw-r--r--modules-available/statistics/templates/clientlist.html6
5 files changed, 51 insertions, 21 deletions
diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json
index 277ac651..1a2a6513 100644
--- a/modules-available/statistics/lang/de/template-tags.json
+++ b/modules-available/statistics/lang/de/template-tags.json
@@ -114,6 +114,7 @@
"lang_usageState": "Zustand",
"lang_uuid": "UUID",
"lang_virtualCores": "Virtuelle Kerne",
+ "lang_wakeOnLan": "WakeOnLan",
"lang_when": "Wann",
"lang_withBadSectors": "Clients mit potentiell defekten Festplatten (mehr als 10 defekte Sektoren)"
} \ No newline at end of file
diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json
index 781bceb1..c38f3350 100644
--- a/modules-available/statistics/lang/en/template-tags.json
+++ b/modules-available/statistics/lang/en/template-tags.json
@@ -114,6 +114,7 @@
"lang_usageState": "State",
"lang_uuid": "UUID",
"lang_virtualCores": "Virtual cores",
+ "lang_wakeOnLan": "WakeOnLan",
"lang_when": "When",
"lang_withBadSectors": "Clients with potentially bad HDDs (more than 10 reallocated sectors)"
} \ No newline at end of file
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index be838fc0..ff5a59cd 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -72,6 +72,8 @@ class Page_Statistics extends Page
$this->rebootControl(true);
} elseif ($action === 'shutdownmachines') {
$this->rebootControl(false);
+ } elseif ($action === 'wol') {
+ $this->wol();
}
// Make sure we don't render any content for POST requests - should be handled above and then
@@ -79,6 +81,23 @@ class Page_Statistics extends Page
Util::redirect('?do=statistics');
}
+ private function wol()
+ {
+ if (!Module::isAvailable('rebootcontrol'))
+ return;
+ $ids = Request::post('uuid', [], 'array');
+ $ids = array_values($ids);
+ if (empty($ids)) {
+ Message::addError('main.parameter-empty', 'uuid');
+ return;
+ }
+ $this->getAllowedMachines(".rebootcontrol.action.wol", $ids, $allowedMachines);
+ if (empty($allowedMachines))
+ return;
+ $taskid = RebootControl::wakeMachines($allowedMachines);
+ Util::redirect('?do=rebootcontrol&show=task&what=task&taskid=' . $taskid);
+ }
+
/**
* @param bool $reboot true = reboot, false = shutdown
*/
@@ -92,12 +111,31 @@ class Page_Statistics extends Page
Message::addError('main.parameter-empty', 'uuid');
return;
}
- $allowedLocations = User::getAllowedLocations(".rebootcontrol.action." . ($reboot ? 'reboot' : 'shutdown'));
+ $this->getAllowedMachines(".rebootcontrol.action." . ($reboot ? 'reboot' : 'shutdown'), $ids, $allowedMachines);
+ if (empty($allowedMachines))
+ return;
+ if ($reboot && Request::post('kexec', false)) {
+ $action = RebootControl::KEXEC_REBOOT;
+ } elseif ($reboot) {
+ $action = RebootControl::REBOOT;
+ } else {
+ $action = RebootControl::SHUTDOWN;
+ }
+ $task = RebootControl::execute($allowedMachines, $action, 0);
+ if (Taskmanager::isTask($task)) {
+ Util::redirect("?do=rebootcontrol&show=task&what=task&taskid=" . $task["id"]);
+ }
+ }
+
+ private function getAllowedMachines($permission, $ids, &$allowedMachines)
+ {
+ $allowedLocations = User::getAllowedLocations($permission);
if (empty($allowedLocations)) {
Message::addError('main.no-permission');
Util::redirect('?do=statistics');
}
- $res = Database::simpleQuery('SELECT machineuuid, clientip, locationid FROM machine WHERE machineuuid IN (:ids)', compact('ids'));
+ $res = Database::simpleQuery('SELECT machineuuid, clientip, macaddr, locationid FROM machine
+ WHERE machineuuid IN (:ids)', compact('ids'));
$ids = array_flip($ids);
$allowedMachines = [];
$seenLocations = [];
@@ -114,24 +152,6 @@ class Page_Statistics extends Page
if (!empty($ids)) {
Message::addWarning('unknown-machine', implode(', ', array_keys($ids)));
}
- if (!empty($allowedMachines)) {
- if (count($seenLocations) === 1) {
- $locactionId = (int)array_keys($seenLocations)[0];
- } else {
- $locactionId = 0;
- }
- if ($reboot && Request::post('kexec', false)) {
- $action = RebootControl::KEXEC_REBOOT;
- } elseif ($reboot) {
- $action = RebootControl::REBOOT;
- } else {
- $action = RebootControl::SHUTDOWN;
- }
- $task = RebootControl::execute($allowedMachines, $action, 0, $locactionId);
- if (Taskmanager::isTask($task)) {
- Util::redirect("?do=rebootcontrol&what=task&taskid=" . $task["id"]);
- }
- }
}
private function deleteMachines()
diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php
index d1c9f2e9..f223dfb2 100644
--- a/modules-available/statistics/pages/list.inc.php
+++ b/modules-available/statistics/pages/list.inc.php
@@ -59,6 +59,7 @@ class SubPage
$deleteAllowedLocations = User::getAllowedLocations("machine.delete");
$rebootAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.reboot');
$shutdownAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.reboot');
+ $wolAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.wol');
// Only make client clickable if user is allowed to view details page
$detailsAllowedLocations = User::getAllowedLocations("machine.view-details");
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
@@ -123,8 +124,9 @@ class SubPage
'canReboot' => !empty($rebootAllowedLocations),
'canShutdown' => !empty($shutdownAllowedLocations),
'canDelete' => !empty($deleteAllowedLocations),
+ 'canWol' => !empty($wolAllowedLocations),
);
Render::addTemplate('clientlist', $data);
}
-} \ No newline at end of file
+}
diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html
index 5420d65c..6ff9bac7 100644
--- a/modules-available/statistics/templates/clientlist.html
+++ b/modules-available/statistics/templates/clientlist.html
@@ -172,6 +172,12 @@
{{lang_reboot}}
</button>
{{/canReboot}}
+ {{#canWol}}
+ <button type="submit" name="action" value="wol" class="btn btn-primary btn-machine-action">
+ <span class="glyphicon glyphicon-bell"></span>
+ {{lang_wakeOnLan}}
+ </button>
+ {{/canWol}}
{{/rebootcontrol}}
{{#canDelete}}
<button type="submit" name="action" value="delmachines" class="btn btn-danger btn-machine-action"