From 7745e2dc3ebe8770c4ffe186841e1b4ee253a04d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 19 Nov 2019 14:24:42 +0100 Subject: [statistics] api: Update DB on client ipaddr change Just logging and ignoring the event spams the event log, also it's more likely that the address actually legitimately changed. --- modules-available/statistics/api.inc.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 19ae3cb6..1cf98ae4 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -166,8 +166,7 @@ if ($type{0} === '~') { $strUpdateBoottime = ''; if ($old === false) die("Unknown machine.\n"); if ($old['clientip'] !== $ip) { - EventLog::warning("[runstate] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip)"); - die("Address changed.\n"); + updateIp('runstate', $uuid, $old, $ip); } $used = Request::post('used', 0, 'integer'); $params = array( @@ -236,8 +235,7 @@ if ($type{0} === '~') { } elseif ($type === '~poweroff') { if ($old === false) die("Unknown machine.\n"); if ($old['clientip'] !== $ip) { - EventLog::warning("[poweroff] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip)"); - die("Address changed.\n"); + updateIp('poweroff', $uuid, $old, $ip); } if ($mode === false && $old['state'] === 'OCCUPIED' && $old['logintime'] !== 0) { $sessionLength = $old['lastseen'] - $old['logintime']; @@ -330,8 +328,7 @@ if ($type{0} === '~') { // Client entering suspend if ($old === false) die("Unknown machine.\n"); if ($old['clientip'] !== $ip) { - EventLog::warning("[suspend] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip)"); - die("Address changed.\n"); + updateIp('suspend', $uuid, $old, $ip); } if ($NOW - $old['lastseen'] < 610 && $old['state'] !== 'OFFLINE') { Database::exec("UPDATE machine SET lastseen = UNIX_TIMESTAMP(), state = 'STANDBY' @@ -344,7 +341,7 @@ if ($type{0} === '~') { // Waking up from suspend if ($old === false) die("Unknown machine.\n"); if ($old['clientip'] !== $ip) { - EventLog::info("[resume] IP address of client $uuid seems to have changed ({$old['clientip']} -> $ip), allowed on resume."); + updateIp('resume', $uuid, $old, $ip); } if ($old['state'] === 'STANDBY') { $res = Database::exec("UPDATE machine SET state = 'IDLE', clientip = :ip, lastseen = UNIX_TIMESTAMP() @@ -447,4 +444,12 @@ function checkHardwareChange($old, $new) } } +function updateIp($type, $uuid, $old, $newIp) +{ + EventLog::warning("[$type] IP address of client $uuid seems to have changed ({$old['clientip']} -> $newIp)"); + Database::exec("UPDATE machine SET clientip = :ip + WHERE machineuuid = :uuid AND state = :oldstate AND lastseen = :oldlastseen", + ['uuid' => $uuid, 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state'], 'ip' => $newIp]); +} + echo "OK.\n"; -- cgit v1.2.3-55-g7522