From ca312a6ace43a6fde58d1c09057c7b0bd34f15a2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 27 Nov 2019 17:25:46 +0100 Subject: [statistics/rebootcontrol] Implement editing subnet --- modules-available/statistics/api.inc.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'modules-available/statistics/api.inc.php') 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') { -- cgit v1.2.3-55-g7522