summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-11-19 14:24:42 +0100
committerSimon Rettberg2019-11-19 14:24:42 +0100
commit7745e2dc3ebe8770c4ffe186841e1b4ee253a04d (patch)
tree3708232cfb666f88a47af5773fe21ba5326bfd7a
parent[sysconfig] Allow deleting modules that are still used by a config (diff)
downloadslx-admin-7745e2dc3ebe8770c4ffe186841e1b4ee253a04d.tar.gz
slx-admin-7745e2dc3ebe8770c4ffe186841e1b4ee253a04d.tar.xz
slx-admin-7745e2dc3ebe8770c4ffe186841e1b4ee253a04d.zip
[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.
-rw-r--r--modules-available/statistics/api.inc.php19
1 files 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";