summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-02-18 16:26:47 +0100
committerSimon Rettberg2021-02-18 16:26:47 +0100
commit1b5ecd7071f96555c62689878381eecb6e93c994 (patch)
treecb30a40fccd767342d5a72c543a9d7f0f6c9f295
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.
-rw-r--r--modules-available/statistics/lang/de/messages.json1
-rw-r--r--modules-available/statistics/lang/de/template-tags.json2
-rw-r--r--modules-available/statistics/lang/en/messages.json1
-rw-r--r--modules-available/statistics/lang/en/template-tags.json2
-rw-r--r--modules-available/statistics/page.inc.php20
-rw-r--r--modules-available/statistics/pages/replace.inc.php9
-rw-r--r--modules-available/statistics/templates/clientlist.html23
7 files changed, 48 insertions, 10 deletions
diff --git a/modules-available/statistics/lang/de/messages.json b/modules-available/statistics/lang/de/messages.json
index 65ddc2c7..e1688cbf 100644
--- a/modules-available/statistics/lang/de/messages.json
+++ b/modules-available/statistics/lang/de/messages.json
@@ -1,4 +1,5 @@
{
+ "cleared-n-machines": "{{0}} Clients zur\u00fcckgesetzt",
"deleted-n-machines": "{{0}} Clients gel\u00f6scht",
"ignored-both-in-use": "Rechnerpaar ignoriert, da beide noch in Betrieb zu sein scheinen. ({{0}} und {{1}})",
"invalid-cidr-notion": "Ung\u00fcltiges CIDR-Format: {{0}}",
diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json
index d152390f..43665a78 100644
--- a/modules-available/statistics/lang/de/template-tags.json
+++ b/modules-available/statistics/lang/de/template-tags.json
@@ -90,6 +90,7 @@
"lang_replaceMachinesHeading": "Rechner ersetzen",
"lang_replaceNew": "Alter Rechner",
"lang_replaceOld": "Neuer Rechner",
+ "lang_resetClearIp": "IP-Adresse zur\u00fccksetzen",
"lang_roomplan": "Raumplan",
"lang_runMode": "Betriebsmodus",
"lang_runmodeMachines": "Mit besonderem Betriebsmodus",
@@ -100,6 +101,7 @@
"lang_shutdown": "Herunterfahren",
"lang_shutdownConfirm": "Ausgew\u00e4hlte Rechner wirklich herunterfahren?",
"lang_sockets": "Sockel",
+ "lang_sureClearIp": "Die IP-Adresse der ausgew\u00e4hlten Rechner wird auf 0.0.0.0 gesetzt, wodurch die Zuordnung zum aktuellen Raum aufgehoben wird.\r\nDie Rechner bleiben mit ihren sonstigen Daten in der Datenbank vorhanden, und sobald ein Rechner das n\u00e4chste mal startet, wird die IP-Adresse wieder aktualisiert. Diese Funktion ist dann n\u00fctzlich, wenn einige Rechner in einem Raum abgebaut wurden, und in der Zukunft in einem anderen Raum wieder aufgebaut werden sollen. Durch zur\u00fccksetzen der IP-Adresse werden die Rechner in der Zwischenzeit nicht mehr im alten Raum angezeigt, was die \u00dcbersicht verbessern kann, bleiben aber \u00fcber ihre sonstigen Merkmale weiterhin in den Statistiken aufsuchbar.",
"lang_sureDeletePermanent": "M\u00f6chten Sie diese(n) Rechner wirklich unwiderruflich aus der Datenbank entfernen?\r\n\r\nWichtig: L\u00f6schen verhindert nicht, dass ein Rechner nach erneutem Starten von bwLehrpool wieder in die Datenbank aufgenommen wird.",
"lang_sureReplaceNoUndo": "Wollen Sie die Daten der ausgew\u00e4hlten Rechner \u00fcbertragen? Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.",
"lang_swap": "Swap",
diff --git a/modules-available/statistics/lang/en/messages.json b/modules-available/statistics/lang/en/messages.json
index 922fe111..e4974923 100644
--- a/modules-available/statistics/lang/en/messages.json
+++ b/modules-available/statistics/lang/en/messages.json
@@ -1,4 +1,5 @@
{
+ "cleared-n-machines": "Reset {{0}} clients",
"deleted-n-machines": "Deleted {{0}} clients",
"ignored-both-in-use": "Ignoring machine pair as both still seem to be in use. ({{0}} and {{1}})",
"invalid-cidr-notion": "Invalid CIDR argument: {{0}}",
diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json
index 6a9b0623..3fcbc049 100644
--- a/modules-available/statistics/lang/en/template-tags.json
+++ b/modules-available/statistics/lang/en/template-tags.json
@@ -90,6 +90,7 @@
"lang_replaceMachinesHeading": "Replace machines",
"lang_replaceNew": "Old machine",
"lang_replaceOld": "New machine",
+ "lang_resetClearIp": "Reset IP address",
"lang_roomplan": "Location",
"lang_runMode": "Mode of operation",
"lang_runmodeMachines": "With special mode of operation",
@@ -100,6 +101,7 @@
"lang_shutdown": "Shutdown",
"lang_shutdownConfirm": "Shutdown selected machines?",
"lang_sockets": "Sockets",
+ "lang_sureClearIp": "The IP address of the selected machine(s) is set to 0.0.0.0, which removes the assignment to the current room\/location.\r\nThe computers otherwise remain in the database, and as soon as a computer starts the next time, the IP address is updated again. This function is useful if some computers have been removed from one room and are to be set up in another room in the future. By resetting the IP address now, those machines are no longer displayed in the old room, which de-clutters the list view, but they remain searchable in the statistics via their other characteristics.",
"lang_sureDeletePermanent": "Are your sure you want to delete the selected machine(s) from the database? This cannot be undone.\r\n\r\nNote: Deleting machines from the database does not prevent booting up bwLehrpool again, which would recreate their respective database entries.",
"lang_sureReplaceNoUndo": "Are you sure you want to replace the selected machine pairs? This action cannot be undone.",
"lang_swap": "swap",
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)));
diff --git a/modules-available/statistics/pages/replace.inc.php b/modules-available/statistics/pages/replace.inc.php
index ae9c6108..9c16aed7 100644
--- a/modules-available/statistics/pages/replace.inc.php
+++ b/modules-available/statistics/pages/replace.inc.php
@@ -69,14 +69,17 @@ class SubPage
// Finalize by updating machine table
foreach ($list as $entry) {
unset($entry['datelimit']);
- Database::exec('UPDATE machine old, machine new SET
+ Database::exec("UPDATE machine old, machine new SET
new.fixedlocationid = old.fixedlocationid,
new.position = old.position,
old.position = NULL,
+ old.subnetlocationid = NULL,
+ old.fixedlocationid = NULL,
new.notes = old.notes,
old.notes = NULL,
- old.lastseen = new.firstseen
- WHERE old.machineuuid = :old AND new.machineuuid = :new', $entry);
+ old.lastseen = new.firstseen,
+ old.clientip = '0.0.0.0'
+ WHERE old.machineuuid = :old AND new.machineuuid = :new", $entry);
}
Message::addSuccess('x-machines-replaced', count($list));
}
diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html
index 19fbaaa4..af349437 100644
--- a/modules-available/statistics/templates/clientlist.html
+++ b/modules-available/statistics/templates/clientlist.html
@@ -146,8 +146,9 @@
<span class="glyphicon glyphicon-refresh"></span>
{{lang_reset}}
</button>
- <div class="dropdown" style="display:inline">
- <button class="btn btn-default dropdown-toggle btn-machine-action" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true">
+ <div class="btn-group">
+ <button class="btn btn-default dropdown-toggle btn-machine-action" type="button" id="dropdownMenu1"
+ data-toggle="dropdown" aria-haspopup="true">
<span class="glyphicon glyphicon-list"></span>
{{lang_listDropdown}}
<span class="caret"></span>
@@ -172,7 +173,7 @@
</ul>
</div>
{{#rebootcontrol}}
- <div class="dropdown" style="display:inline">
+ <div class="btn-group">
<button class="btn btn-default dropdown-toggle btn-machine-action" type="button" id="dropdownMenu2"
data-toggle="dropdown" aria-haspopup="true">
<span class="glyphicon glyphicon-list"></span>
@@ -212,11 +213,27 @@
</div>
{{/rebootcontrol}}
{{#canDelete}}
+ <div class="btn-group">
<button type="submit" name="action" value="delmachines" class="btn btn-danger btn-machine-action"
data-confirm="{{lang_sureDeletePermanent}}">
<span class="glyphicon glyphicon-trash"></span>
{{lang_delete}}
</button>
+ <button type="button" class="btn btn-danger btn-machine-action dropdown-toggle"
+ data-toggle="dropdown" aria-haspopup="true">
+ <span class="caret"></span>
+ <span class="sr-only">Toggle Dropdown</span>
+ </button>
+ <div class="dropdown-menu" style="padding:0">
+ <div class="btn-group-vertical">
+ <button type="submit" name="action" value="clear-machines" class="btn btn-danger btn-machine-action"
+ data-confirm="{{lang_sureClearIp}}">
+ <span class="glyphicon glyphicon-refresh"></span>
+ {{lang_resetClearIp}}
+ </button>
+ </div>
+ </div>
+ </div>
{{/canDelete}}
</div>
<div class="hidden" id="confirm-reboot">