diff options
author | Simon Rettberg | 2019-11-27 17:25:46 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-11-27 17:25:46 +0100 |
commit | ca312a6ace43a6fde58d1c09057c7b0bd34f15a2 (patch) | |
tree | 3cb4e5ac2b29f7fcc99dfda5df26f11a64caeaf3 /modules-available/statistics/api.inc.php | |
parent | [js_ip/locations] Mode cidr/ip handling to own module (diff) | |
download | slx-admin-ca312a6ace43a6fde58d1c09057c7b0bd34f15a2.tar.gz slx-admin-ca312a6ace43a6fde58d1c09057c7b0bd34f15a2.tar.xz slx-admin-ca312a6ace43a6fde58d1c09057c7b0bd34f15a2.zip |
[statistics/rebootcontrol] Implement editing subnet
Diffstat (limited to 'modules-available/statistics/api.inc.php')
-rw-r--r-- | modules-available/statistics/api.inc.php | 24 |
1 files changed, 24 insertions, 0 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') { |