diff options
Diffstat (limited to 'modules-available/statistics')
-rw-r--r-- | modules-available/statistics/api.inc.php | 24 | ||||
-rw-r--r-- | modules-available/statistics/lang/de/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/statistics/lang/en/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/statistics/page.inc.php | 64 | ||||
-rw-r--r-- | modules-available/statistics/pages/list.inc.php | 6 | ||||
-rw-r--r-- | modules-available/statistics/templates/clientlist.html | 12 |
6 files changed, 87 insertions, 21 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 1cf98ae4..64925791 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -158,6 +158,30 @@ if ($type{0} === '~') { } } + // Inform WOL (rebootcontrol) module about subnet size + if (Module::get('rebootcontrol') !== false) { + $subnet = Request::post('subnet', false, 'string'); + if ($subnet !== false && ($subnet = explode('/', $subnet)) !== false && count($subnet) === 2 + && $subnet[0] === $ip && $subnet[1] >= 8 && $subnet[1] < 32) { + $start = ip2long($ip); + if ($start !== false) { + $maskHost = (int)(pow(2, 32 - $subnet[1]) - 1); + $maskNet = ~$maskHost & 0xffffffff; + $end = $start | $maskHost; + $start &= $maskNet; + $netparams = ['start' => sprintf('%u', $start), 'end' => sprintf('%u', $end), 'now' => $NOW]; + $affected = Database::exec('UPDATE reboot_subnet + SET lastseen = :now, seencount = seencount + 1 + WHERE start = :start AND end = :end', $netparams); + if ($affected === 0) { + // New entry + Database::exec('INSERT INTO reboot_subnet (start, end, fixed, isdirect, lastseen, seencount) + VALUES (:start, :end, 0, 0, :now, 1)', $netparams); + } + } + } + } + // Write statistics data } else if ($type === '~runstate') { diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json index 1e92aeed..68056a7a 100644 --- a/modules-available/statistics/lang/de/template-tags.json +++ b/modules-available/statistics/lang/de/template-tags.json @@ -115,6 +115,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 68649d91..533a9bf9 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -72,6 +72,12 @@ class Page_Statistics extends Page $this->rebootControl(true); } elseif ($action === 'shutdownmachines') { $this->rebootControl(false); + } elseif ($action === 'wol') { + $this->wol(); + } elseif ($action === 'prepare-exec') { + if (Module::isAvailable('rebootcontrol')) { + RebootControl::prepareExec(); + } } // Make sure we don't render any content for POST requests - should be handled above and then @@ -79,6 +85,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 +115,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 +156,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&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..e2e7ff09 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -59,6 +59,8 @@ 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'); + $execAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.exec'); // 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 +125,10 @@ class SubPage 'canReboot' => !empty($rebootAllowedLocations), 'canShutdown' => !empty($shutdownAllowedLocations), 'canDelete' => !empty($deleteAllowedLocations), + 'canWol' => !empty($wolAllowedLocations), + 'canExec' => !empty($execAllowedLocations), ); 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..47be4dd0 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -172,6 +172,18 @@ {{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}} + {{#canExec}} + <button type="submit" name="action" value="prepare-exec" class="btn btn-primary btn-machine-action"> + <span class="glyphicon glyphicon-play"></span> + {{lang_remoteExec}} + </button> + {{/canExec}} {{/rebootcontrol}} {{#canDelete}} <button type="submit" name="action" value="delmachines" class="btn btn-danger btn-machine-action" |