summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2021-02-18 16:26:47 +0100
committerSimon Rettberg2021-02-18 16:26:47 +0100
commit1b5ecd7071f96555c62689878381eecb6e93c994 (patch)
treecb30a40fccd767342d5a72c543a9d7f0f6c9f295 /modules-available/statistics/page.inc.php
parent[statistics] Store ID45 live stats (diff)
downloadslx-admin-1b5ecd7071f96555c62689878381eecb6e93c994.tar.gz
slx-admin-1b5ecd7071f96555c62689878381eecb6e93c994.tar.xz
slx-admin-1b5ecd7071f96555c62689878381eecb6e93c994.zip
[statistics] Add soft-delete feature: Resets a client's IP and location
Soft-deleting a client doesn't remove its entire data and usage history from the database, but just resets IP and location, so it doesn't appear in its former location anymore. In case a client is removed from a room, this declutters the client statistics. Once the client boots again, location and and IP address will be updated again.
Diffstat (limited to 'modules-available/statistics/page.inc.php')
-rw-r--r--modules-available/statistics/page.inc.php20
1 files changed, 16 insertions, 4 deletions
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index b51e2956..20ff929a 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -70,8 +70,10 @@ class Page_Statistics extends Page
));
Message::addSuccess('notes-saved');
Util::redirect('?do=statistics&uuid=' . $uuid);
+ } elseif ($action === 'clear-machines') {
+ $this->deleteMachines(true);
} elseif ($action === 'delmachines') {
- $this->deleteMachines();
+ $this->deleteMachines(false);
Util::redirect('?do=statistics', true);
} elseif ($action === 'rebootmachines') {
$this->rebootControl(true);
@@ -184,7 +186,7 @@ class Page_Statistics extends Page
}
}
- private function deleteMachines()
+ private function deleteMachines($soft)
{
$ids = Request::post('uuid', [], 'array');
$ids = array_values($ids);
@@ -209,8 +211,18 @@ class Page_Statistics extends Page
}
}
if (!empty($delete)) {
- Database::exec('DELETE FROM machine WHERE machineuuid IN (:delete)', compact('delete'));
- Message::addSuccess('deleted-n-machines', count($delete));
+ if ($soft) {
+ // "Soft delete" -- keep all data, but set IP address to 0.0.0.0, so it will not be assigned to its
+ // old location anymore. Upon next boot some time in the future, the machine is hopefully relocated
+ // to somewhere else and will appear in a new location
+ Database::exec("UPDATE machine SET clientip = '0.0.0.0', fixedlocationid = NULL, subnetlocationid = NULL
+ WHERE machineuuid IN (:delete)", compact('delete'));
+ Message::addSuccess('cleared-n-machines', count($delete));
+ } else {
+ // Actually purge from DB
+ Database::exec('DELETE FROM machine WHERE machineuuid IN (:delete)', compact('delete'));
+ Message::addSuccess('deleted-n-machines', count($delete));
+ }
}
if (!empty($ids)) {
Message::addWarning('unknown-machine', implode(', ', array_keys($ids)));