From 55fc68eb1b1527a5dfd5b3617b88ba1450ce41aa Mon Sep 17 00:00:00 2001
From: leiweibau <105860611+leiweibau@users.noreply.github.com>
Date: Wed, 1 Jun 2022 19:19:14 +0200
Subject: [PATCH] DB Maintenance
merge Fork from https://github.com/jokob-sk/Pi.Alert
---
back/pialert.py | 10 +++
front/css/dark-patch.css | 11 ++-
front/devices.php | 6 +-
front/index.php | 6 +-
front/maintenance.php | 139 +++++++++++++++++++++++++++++++++
front/php/server/devices.php | 89 +++++++++++++++++++++
front/php/templates/header.php | 5 ++
7 files changed, 258 insertions(+), 8 deletions(-)
create mode 100644 front/maintenance.php
diff --git a/back/pialert.py b/back/pialert.py
index 6c6380ab..60ef1e67 100644
--- a/back/pialert.py
+++ b/back/pialert.py
@@ -1167,6 +1167,16 @@ def email_reporting ():
print ('\nReporting...')
openDB()
+ # Disable reporting on events for devices where reporting is disabled based on the MAC address
+ sql.execute ("""UPDATE Events SET eve_PendingAlertEmail = 0
+ WHERE eve_PendingAlertEmail = 1 AND eve_MAC IN
+ (
+ SELECT dev_MAC FROM Devices WHERE dev_AlertEvents = 0
+ )""")
+
+ # Open text Template
+
+
# Open text Template
template_file = open(PIALERT_BACK_PATH + '/report_template.txt', 'r')
mail_text = template_file.read()
diff --git a/front/css/dark-patch.css b/front/css/dark-patch.css
index 987db900..7863345c 100644
--- a/front/css/dark-patch.css
+++ b/front/css/dark-patch.css
@@ -633,13 +633,16 @@ input[type="password"]::-webkit-caps-lock-indicator {
border-top-right-radius: 10px;
}
.pa-small-box-gray .inner {
- background-color: rgb(189,192,198);
+ background-color: #777;
color: rgba(20,20,20,30%);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
+.pa-small-box-gray .inner h3 {
+ color: #bbb;
+}
.text-gray-20 {
- color: rgba(20,20,20,30%);
+ color: rgba(220,220,220,30%);
}
.bg-gray {
background-color: #888888 !important;
@@ -647,6 +650,9 @@ input[type="password"]::-webkit-caps-lock-indicator {
.badge.bg-green {
background-color: #00A000 !important;
}
+.badge.bg-gray {
+ background-color: #888 !important;
+}
#txtRecord {
background-color: #353c42;
border-color: #888888;
@@ -655,3 +661,4 @@ input[type="password"]::-webkit-caps-lock-indicator {
background-color: rgb(189,192,198);
color: #444;
}
+
diff --git a/front/devices.php b/front/devices.php
index 664061dc..b140f09c 100644
--- a/front/devices.php
+++ b/front/devices.php
@@ -120,9 +120,9 @@
Last IP |
MAC |
Status |
- MAC |
- Last IP Order |
- Rowid |
+
+
+
diff --git a/front/index.php b/front/index.php
index 664061dc..b140f09c 100644
--- a/front/index.php
+++ b/front/index.php
@@ -120,9 +120,9 @@
Last IP |
MAC |
Status |
- MAC |
- Last IP Order |
- Rowid |
+
+
+
diff --git a/front/maintenance.php b/front/maintenance.php
new file mode 100644
index 00000000..d0d94529
--- /dev/null
+++ b/front/maintenance.php
@@ -0,0 +1,139 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/front/php/server/devices.php b/front/php/server/devices.php
index e2b6c531..39585f08 100644
--- a/front/php/server/devices.php
+++ b/front/php/server/devices.php
@@ -31,6 +31,15 @@
case 'getDeviceData': getDeviceData(); break;
case 'setDeviceData': setDeviceData(); break;
case 'deleteDevice': deleteDevice(); break;
+ case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
+ case 'createBackupDB': createBackupDB(); break;
+ case 'restoreBackupDB': restoreBackupDB(); break;
+ case 'deleteAllDevices': deleteAllDevices(); break;
+ case 'runScan15min': runScan15min(); break;
+ case 'runScan1min': runScan1min(); break;
+ case 'deleteUnknownDevices': deleteUnknownDevices(); break;
+ case 'deleteEvents': deleteEvents(); break;
+
case 'getDevicesTotals': getDevicesTotals(); break;
case 'getDevicesList': getDevicesList(); break;
@@ -173,6 +182,86 @@ function deleteDevice() {
}
}
+//------------------------------------------------------------------------------
+// Delete all devices with empty MAC addresses
+//------------------------------------------------------------------------------
+function deleteAllWithEmptyMACs() {
+ global $db;
+
+ // sql
+ $sql = 'DELETE FROM Devices WHERE dev_MAC=""';
+ // execute sql
+ $result = $db->query($sql);
+
+ // check result
+ if ($result == TRUE) {
+ echo "Devices deleted successfully";
+ } else {
+ echo "Error deleting devices\n\n$sql \n\n". $db->lastErrorMsg();
+ }
+}
+
+//------------------------------------------------------------------------------
+// Delete all devices with empty MAC addresses
+//------------------------------------------------------------------------------
+function deleteUnknownDevices() {
+ global $db;
+
+ // sql
+ $sql = 'DELETE FROM Devices WHERE dev_Name="(unknown)"';
+ // execute sql
+ $result = $db->query($sql);
+
+ // check result
+ if ($result == TRUE) {
+ echo "Devices deleted successfully";
+ } else {
+ echo "Error deleting devices\n\n$sql \n\n". $db->lastErrorMsg();
+ }
+}
+
+
+
+//------------------------------------------------------------------------------
+// Delete all devices
+//------------------------------------------------------------------------------
+function deleteAllDevices() {
+ global $db;
+
+ // sql
+ $sql = 'DELETE FROM Devices';
+ // execute sql
+ $result = $db->query($sql);
+
+ // check result
+ if ($result == TRUE) {
+ echo "Devices deleted successfully";
+ } else {
+ echo "Error deleting devices\n\n$sql \n\n". $db->lastErrorMsg();
+ }
+}
+
+//------------------------------------------------------------------------------
+// Delete all Events
+//------------------------------------------------------------------------------
+function deleteEvents() {
+ global $db;
+
+ // sql
+ $sql = 'DELETE FROM Events';
+ // execute sql
+ $result = $db->query($sql);
+
+ // check result
+ if ($result == TRUE) {
+ echo "Events deleted successfully";
+ } else {
+ echo "Error deleting Events\n\n$sql \n\n". $db->lastErrorMsg();
+ }
+}
+
+
+
//------------------------------------------------------------------------------
// Query total numbers of Devices by status
diff --git a/front/php/templates/header.php b/front/php/templates/header.php
index 70827ce0..c74630ed 100644
--- a/front/php/templates/header.php
+++ b/front/php/templates/header.php
@@ -192,6 +192,7 @@ if ($ENABLED_DARKMODE === True) {
+
Presence
@@ -200,6 +201,10 @@ if ($ENABLED_DARKMODE === True) {
Events
+
+ Maintenance
+
+