mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
maintenance task DB
This commit is contained in:
23
back/maintenance.py
Normal file
23
back/maintenance.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
|
||||
def main ():
|
||||
|
||||
argument = str(sys.argv[1])
|
||||
|
||||
## Main Commands
|
||||
if argument == 'backup_db':
|
||||
res = backup_db()
|
||||
|
||||
if argument == 'restore_db':
|
||||
res = restore_db()
|
||||
|
||||
def backup_db ():
|
||||
# Header
|
||||
shutil.copyfile("/home/pi/pialert/db/pialert.db", "/home/pi/pialert/config/pialert.db_bak")
|
||||
|
||||
|
||||
def restore_db ():
|
||||
# Header
|
||||
shutil.copyfile("/home/pi/pialert/config/pialert.db_bak", "/home/pi/pialert/db/pialert.db")
|
||||
@@ -36,28 +36,28 @@
|
||||
<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>
|
||||
|
||||
<div class="col-xs-12">
|
||||
|
||||
<div class="pull-right">
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
|
||||
id="btnDelete" onclick="askDeleteAllDevices()"> Delete All Devices</button>
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-create" style="margin-left:0px;"
|
||||
id="btnDelete" onclick="askRunScan1min()"> Run 1 min scan now</button>
|
||||
</div>
|
||||
|
||||
<div class="pull-right">
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-create" style="margin-left:0px;"
|
||||
id="btnDelete" onclick="askRunScan15min()"> Run 15 min scan now</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="col-xs-12">
|
||||
<div class="pull-right">
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-create" style="margin-left:0px;"
|
||||
id="btnBackup" onclick="askCreateBackupDB()"> Backup DB </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12">
|
||||
<div class="pull-right">
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
|
||||
id="btnRestore" onclick="askRestoreBackupDB()"> Restore DB </button>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ----------------------------------------------------------------------- -->
|
||||
</section>
|
||||
@@ -73,6 +73,9 @@
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
// delete devices with emty macs
|
||||
|
||||
function askDeleteDevicesWithEmptyMACs () {
|
||||
// Ask delete device
|
||||
|
||||
@@ -89,7 +92,7 @@ function deleteDevicesWithEmptyMACs()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// delete all devices
|
||||
function askDeleteAllDevices () {
|
||||
// Ask delete device
|
||||
|
||||
@@ -107,6 +110,39 @@ function deleteAllDevices()
|
||||
}
|
||||
|
||||
|
||||
// Run ad-hoc scans
|
||||
|
||||
function askRunScan1min () {
|
||||
// Ask delete device
|
||||
|
||||
showModalWarning('Scan 1 min now', 'This runs the 1 min scan sequence',
|
||||
'Cancel', 'Scan', 'runScan1min');
|
||||
}
|
||||
|
||||
|
||||
function runScan1min()
|
||||
{
|
||||
// Scan
|
||||
$.get('php/server/devices.php?action=runScan1min', function(msg) {
|
||||
showMessage (msg);
|
||||
});
|
||||
}
|
||||
|
||||
function askRunScan15min () {
|
||||
// Ask delete device
|
||||
|
||||
showModalWarning('Scan 15 min now', 'This runs the 15 min scan sequence',
|
||||
'Cancel', 'Scan', 'runScan15min');
|
||||
}
|
||||
|
||||
|
||||
function runScan15min()
|
||||
{
|
||||
// Scan
|
||||
$.get('php/server/devices.php?action=runScan15min', function(msg) {
|
||||
showMessage (msg);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// DB backup
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
case 'createBackupDB': createBackupDB(); break;
|
||||
case 'restoreBackupDB': restoreBackupDB(); break;
|
||||
case 'deleteAllDevices': deleteAllDevices(); break;
|
||||
case 'runScan15min': runScan15min(); break;
|
||||
case 'runScan1min': runScan1min(); break;
|
||||
|
||||
|
||||
|
||||
@@ -217,20 +219,51 @@ function deleteAllDevices() {
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Run scan 1 min now
|
||||
//------------------------------------------------------------------------------
|
||||
function runScan1min() {
|
||||
|
||||
$command = escapeshellcmd('/home/pi/pialert/back/pialert.py 1');
|
||||
$output = shell_exec($command);
|
||||
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Run scan 15 min now
|
||||
//------------------------------------------------------------------------------
|
||||
function runScan15min() {
|
||||
|
||||
$command = escapeshellcmd('/home/pi/pialert/back/pialert.py 15');
|
||||
$output = shell_exec($command);
|
||||
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Create a DB backup
|
||||
//------------------------------------------------------------------------------
|
||||
function createBackupDB() {
|
||||
|
||||
//
|
||||
$result = copy("/home/pi/pialert/db/pialert.db","/home/pi/pialert/config/pialert.db_bak");
|
||||
// check result
|
||||
if ($result == TRUE) {
|
||||
echo "Copied successfully";
|
||||
} else {
|
||||
echo "Error copying DB. SSH into instance and copy manually.";
|
||||
}
|
||||
// //
|
||||
// $result = copy("/home/pi/pialert/db/pialert.db","/home/pi/pialert/config/pialert.db_bak");
|
||||
// // check result
|
||||
// if ($result == TRUE) {
|
||||
// echo "Copied successfully";
|
||||
// } else {
|
||||
// echo "Error copying DB. SSH into instance and copy manually.";
|
||||
// }
|
||||
|
||||
$command = escapeshellcmd('/home/pi/pialert/back/maintenance.py backup_DB');
|
||||
$output = shell_exec($command);
|
||||
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -238,14 +271,20 @@ function createBackupDB() {
|
||||
//------------------------------------------------------------------------------
|
||||
function restoreBackupDB() {
|
||||
|
||||
//
|
||||
$result = copy("/home/pi/pialert/config/pialert.db_bak", "/home/pi/pialert/db/pialert.db");
|
||||
// check result
|
||||
if ($result == TRUE) {
|
||||
echo "Copied successfully";
|
||||
} else {
|
||||
echo "Error copying DB. SSH into instance and copy manually.";
|
||||
}
|
||||
// //
|
||||
// $result = copy("/home/pi/pialert/config/pialert.db_bak", "/home/pi/pialert/db/pialert.db");
|
||||
// // check result
|
||||
// if ($result == TRUE) {
|
||||
// echo "Copied successfully";
|
||||
// } else {
|
||||
// echo "Error copying DB. SSH into instance and copy manually.";
|
||||
// }
|
||||
|
||||
$command = escapeshellcmd('/home/pi/pialert/back/maintenance.py restore_DB');
|
||||
$output = shell_exec($command);
|
||||
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user