summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-04-27 13:38:32 +0200
committerSimon Rettberg2020-04-27 13:38:32 +0200
commitf18139dfb2252f0d869e7d63ee657c6d1015941a (patch)
tree107963503b0f349fa80ff718f72c756330092d3e
parent[inc/Database] Force strict mode with CONFIG_DEBUG (diff)
downloadslx-admin-f18139dfb2252f0d869e7d63ee657c6d1015941a.tar.gz
slx-admin-f18139dfb2252f0d869e7d63ee657c6d1015941a.tar.xz
slx-admin-f18139dfb2252f0d869e7d63ee657c6d1015941a.zip
[rebootcontrol/statistics] Move subnet size handling to hook
-rw-r--r--modules-available/rebootcontrol/hooks/client-update.inc.php24
-rw-r--r--modules-available/statistics/api.inc.php24
2 files changed, 24 insertions, 24 deletions
diff --git a/modules-available/rebootcontrol/hooks/client-update.inc.php b/modules-available/rebootcontrol/hooks/client-update.inc.php
new file mode 100644
index 00000000..48c16b66
--- /dev/null
+++ b/modules-available/rebootcontrol/hooks/client-update.inc.php
@@ -0,0 +1,24 @@
+<?php
+
+if ($type === '~poweron') {
+ $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);
+ }
+ }
+ }
+}
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index 70811b2b..2b878680 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -158,30 +158,6 @@ if ($type{0} === '~') {
}
}
- // Inform WOL (rebootcontrol) module about subnet size (TODO: Use upcoming hook)
- 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') {