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:
@@ -1,32 +0,0 @@
|
|||||||
import sys
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def main ():
|
|
||||||
|
|
||||||
argument = str(sys.argv[1])
|
|
||||||
|
|
||||||
## Main Commands
|
|
||||||
if argument == 'backup_db':
|
|
||||||
res = backup_db()
|
|
||||||
print(res)
|
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
#===============================================================================
|
|
||||||
# BEGIN
|
|
||||||
#===============================================================================
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -32,34 +32,15 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div class="pull-right">
|
<div class="center">
|
||||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
|
<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>
|
id="btnDeleteMAC" onclick="askDeleteDevicesWithEmptyMACs()"> Delete Devices with empty MACs </button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="center">
|
||||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
|
<button type="button" class="btn btn-default pa-btn pa-btn-delete" style="margin-left:0px;"
|
||||||
id="btnDeleteMAC" onclick="askDeleteAllDevices()"> Delete All Devices </button>
|
id="btnDeleteMAC" onclick="askDeleteAllDevices()"> Delete All Devices </button>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="pull-right">
|
|
||||||
<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 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 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>
|
||||||
|
|
||||||
|
|
||||||
@@ -114,79 +95,6 @@ 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
|
|
||||||
|
|
||||||
function askCreateBackupDB () {
|
|
||||||
// Ask delete device
|
|
||||||
|
|
||||||
showModalWarning('Backup DB', 'This creates a pialert.db_bak file in the /config folder',
|
|
||||||
'Cancel', 'Create', 'createBackupDB');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function createBackupDB()
|
|
||||||
{
|
|
||||||
// Delete device
|
|
||||||
$.get('php/server/devices.php?action=createBackupDB', function(msg) {
|
|
||||||
showMessage (msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// DB restore
|
|
||||||
|
|
||||||
function askRestoreBackupDB () {
|
|
||||||
// Ask delete device
|
|
||||||
|
|
||||||
showModalWarning('Restore DB', 'This restores a pialert.db_bak file from the /config folder',
|
|
||||||
'Cancel', 'Restore', 'restoreBackupDB');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function restoreBackupDB()
|
|
||||||
{
|
|
||||||
// Delete device
|
|
||||||
$.get('php/server/devices.php?action=restoreBackupDB', function(msg) {
|
|
||||||
showMessage (msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -219,76 +219,6 @@ 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.";
|
|
||||||
// }
|
|
||||||
|
|
||||||
$mystring = system('python /home/pi/pialert/back/maintenance.py backup_db', $retval);
|
|
||||||
// $command = escapeshellcmd('/home/pi/pialert/back/maintenance.py backup_DB');
|
|
||||||
// $output = shell_exec($command);
|
|
||||||
|
|
||||||
|
|
||||||
//echo $output;
|
|
||||||
echo $retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Restore latest DB backup
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
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.";
|
|
||||||
// }
|
|
||||||
|
|
||||||
$command = escapeshellcmd('/home/pi/pialert/back/maintenance.py restore_db');
|
|
||||||
$output = shell_exec($command);
|
|
||||||
|
|
||||||
|
|
||||||
echo $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -11,4 +11,4 @@
|
|||||||
*/1 * * * * python ~/pialert/back/pialert.py internet_IP >~/pialert/log/pialert.IP.log 2>&1
|
*/1 * * * * python ~/pialert/back/pialert.py internet_IP >~/pialert/log/pialert.IP.log 2>&1
|
||||||
*/5 * * * * python ~/pialert/back/pialert.py 1 >~/pialert/log/pialert.1.log 2>&1
|
*/5 * * * * python ~/pialert/back/pialert.py 1 >~/pialert/log/pialert.1.log 2>&1
|
||||||
*/15 * * * * python ~/pialert/back/pialert.py 15 >~/pialert/log/pialert.15.log 2>&1
|
*/15 * * * * python ~/pialert/back/pialert.py 15 >~/pialert/log/pialert.15.log 2>&1
|
||||||
*/1 * * * * cp /home/pi/pialert/db/pialert.db /home/pi/pialert/config/pialert.db_bak
|
*/30 * * * * cp /home/pi/pialert/db/pialert.db /home/pi/pialert/config/pialert.db_bak
|
||||||
|
|||||||
Reference in New Issue
Block a user