DB Maintenance

merge Fork from https://github.com/jokob-sk/Pi.Alert
This commit is contained in:
leiweibau
2022-06-01 19:19:14 +02:00
parent 64c6589448
commit b6f22b7736
7 changed files with 258 additions and 8 deletions

View File

@@ -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()

View File

@@ -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;
}

View File

@@ -120,9 +120,9 @@
<th>Last IP</th>
<th>MAC</th>
<th>Status</th>
<th>MAC</th>
<th>Last IP Order</th>
<th>Rowid</th>
<!-- <th>MAC</th> -->
<!-- <th>Last IP Order</th> -->
<!-- <th>Rowid</th> -->
</tr>
</thead>
</table>

View File

@@ -120,9 +120,9 @@
<th>Last IP</th>
<th>MAC</th>
<th>Status</th>
<th>MAC</th>
<th>Last IP Order</th>
<th>Rowid</th>
<!-- <th>MAC</th> -->
<!-- <th>Last IP Order</th> -->
<!-- <th>Rowid</th> -->
</tr>
</thead>
</table>

139
front/maintenance.php Normal file
View File

@@ -0,0 +1,139 @@
<?php
//------------------------------------------------------------------------------
// Pi.Alert
// Open Source Network Guard / WIFI & LAN intrusion detector
//
// devices.php - Front module. Server side. Manage Devices
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
// jokob-sk 2022 jokob.sk@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
?>
<?php
require 'php/templates/header.php';
?>
<!-- Page ------------------------------------------------------------------ -->
<div class="content-wrapper">
<!-- Content header--------------------------------------------------------- -->
<section class="content-header">
<?php require 'php/templates/notification.php'; ?>
<h1 id="pageTitle">
Maintenance tools
</h1>
</section>
<!-- Main content ---------------------------------------------------------- -->
<section class="content">
<div class="col-xs-12">
<div class="center">
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
id="btnDeleteMAC" onclick="askDeleteDevicesWithEmptyMACs()"> Delete Devices with empty MACs </button>
</div>
<div class="center">
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
id="btnDeleteMAC" onclick="askDeleteAllDevices()"> Delete All Devices </button>
</div>
<div class="center">
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
id="btnDeleteUnknown" onclick="askDeleteUnknown()"> Delete (unknown) Devices </button>
</div>
<div class="center">
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
id="btnDeleteEvents" onclick="askDeleteEvents()"> Delete all Events </button>
</div>
</div>
<!-- ----------------------------------------------------------------------- -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- ----------------------------------------------------------------------- -->
<?php
require 'php/templates/footer.php';
?>
<script>
// delete devices with emty macs
function askDeleteDevicesWithEmptyMACs () {
// Ask
showModalWarning('Delete Devices', 'Are you sure you want to delete all devices with empty MAC addresses?<br>(maybe you prefer to archive it)',
'Cancel', 'Delete', 'deleteDevicesWithEmptyMACs');
}
function deleteDevicesWithEmptyMACs()
{
// Delete device
$.get('php/server/devices.php?action=deleteAllWithEmptyMACs', function(msg) {
showMessage (msg);
});
}
// delete all devices
function askDeleteAllDevices () {
// Ask
showModalWarning('Delete Devices', 'Are you sure you want to delete all devices?',
'Cancel', 'Delete', 'deleteAllDevices');
}
function deleteAllDevices()
{
// Delete device
$.get('php/server/devices.php?action=deleteAllDevices', function(msg) {
showMessage (msg);
});
}
// delete all (unknown) devices
function askDeleteUnknown () {
// Ask
showModalWarning('Delete (unknown) Devices', 'Are you sure you want to delete all (unknown) devices?',
'Cancel', 'Delete', 'deleteUnknownDevices');
}
function deleteUnknownDevices()
{
// Execute
$.get('php/server/devices.php?action=deleteUnknownDevices', function(msg) {
showMessage (msg);
});
}
// delete all Events
function askDeleteEvents () {
// Ask
showModalWarning('Delete Events', 'Are you sure you want to delete all Events?',
'Cancel', 'Delete', 'deleteEvents');
}
function deleteEvents()
{
// Execute
$.get('php/server/devices.php?action=deleteEvents', function(msg) {
showMessage (msg);
});
}
</script>

View File

@@ -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

View File

@@ -192,6 +192,7 @@ if ($ENABLED_DARKMODE === True) {
<!--
<li><a href="devices.php?status=favorites"><i class="fa fa-star"></i> <span>Favorites Devices</span></a></li>
-->
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('presence.php') ) ){ echo 'active'; } ?>">
<a href="presence.php"><i class="fa fa-calendar"></i> <span>Presence</span></a>
</li>
@@ -200,6 +201,10 @@ if ($ENABLED_DARKMODE === True) {
<a href="events.php"><i class="fa fa-bolt"></i> <span>Events</span></a>
</li>
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('maintenance.php') ) ){ echo 'active'; } ?>">
<a href="maintenance.php"><i class="fa fa-cog"></i> <span>Maintenance</span></a>
</li>
<!--
<li class="treeview">
<a href="#"><i class="fa fa-link"></i> <span>Config</span>