mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
chore: 🧹Removal of DB backups functionality
This commit is contained in:
@@ -7,7 +7,7 @@ require 'php/templates/security.php';
|
||||
|
||||
$CookieSaveLoginName = 'NetAlertX_SaveLogin';
|
||||
|
||||
if ($Pia_WebProtection != 'true')
|
||||
if ($nax_WebProtection != 'true')
|
||||
{
|
||||
header('Location: devices.php');
|
||||
$_SESSION["login"] = 1;
|
||||
@@ -24,7 +24,7 @@ if (isset ($_GET["action"]) && $_GET["action"] == 'logout')
|
||||
}
|
||||
|
||||
// Password without Cookie check -> pass and set initial cookie
|
||||
if (isset ($_POST["loginpassword"]) && $Pia_Password == hash('sha256',$_POST["loginpassword"]))
|
||||
if (isset ($_POST["loginpassword"]) && $nax_Password == hash('sha256',$_POST["loginpassword"]))
|
||||
{
|
||||
header('Location: devices.php');
|
||||
$_SESSION["login"] = 1;
|
||||
@@ -32,7 +32,7 @@ if (isset ($_POST["loginpassword"]) && $Pia_Password == hash('sha256',$_POST["lo
|
||||
}
|
||||
|
||||
// active Session or valid cookie (cookie not extends)
|
||||
if (( isset ($_SESSION["login"]) && ($_SESSION["login"] == 1)) || (isset ($_COOKIE[$CookieSaveLoginName]) && $Pia_Password == $_COOKIE[$CookieSaveLoginName]))
|
||||
if (( isset ($_SESSION["login"]) && ($_SESSION["login"] == 1)) || (isset ($_COOKIE[$CookieSaveLoginName]) && $nax_Password == $_COOKIE[$CookieSaveLoginName]))
|
||||
{
|
||||
header('Location: devices.php');
|
||||
$_SESSION["login"] = 1;
|
||||
@@ -48,7 +48,7 @@ $login_icon = 'fa-info';
|
||||
// no active session, cookie not checked
|
||||
if (isset ($_SESSION["login"]) == FALSE || $_SESSION["login"] != 1)
|
||||
{
|
||||
if ($Pia_Password == '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92')
|
||||
if ($nax_Password == '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92')
|
||||
{
|
||||
$login_info = lang('Login_Default_PWD');
|
||||
$login_mode = 'danger';
|
||||
|
||||
@@ -39,46 +39,17 @@
|
||||
|
||||
// Size and last mod of DB ------------------------------------------------------
|
||||
|
||||
$pia_db = str_replace('front', 'db', getcwd()).'/app.db';
|
||||
$pia_db_size = number_format((filesize($pia_db) / 1000000),2,",",".") . ' MB';
|
||||
$pia_db_mod = date ("F d Y H:i:s", filemtime($pia_db));
|
||||
$nax_db = str_replace('front', 'db', getcwd()).'/app.db';
|
||||
$nax_db_size = number_format((filesize($nax_db) / 1000000),2,",",".") . ' MB';
|
||||
$nax_db_mod = date ("F d Y H:i:s", filemtime($nax_db));
|
||||
|
||||
|
||||
// Count and Calc Backups -------------------------------------------------------
|
||||
|
||||
$Pia_Archive_Path = str_replace('front', 'db', getcwd()).'/';
|
||||
$Pia_Archive_count = 0;
|
||||
$Pia_Archive_diskusage = 0;
|
||||
$files = glob($Pia_Archive_Path."appdb_*.zip");
|
||||
if ($files){
|
||||
$Pia_Archive_count = count($files);
|
||||
}
|
||||
foreach ($files as $result) {
|
||||
$Pia_Archive_diskusage = $Pia_Archive_diskusage + filesize($result);
|
||||
}
|
||||
$Pia_Archive_diskusage = number_format(($Pia_Archive_diskusage / 1000000),2,",",".") . ' MB';
|
||||
|
||||
// Find latest Backup for restore -----------------------------------------------
|
||||
|
||||
$latestfiles = glob($Pia_Archive_Path."appdb_*.zip");
|
||||
natsort($latestfiles);
|
||||
$latestfiles = array_reverse($latestfiles,False);
|
||||
|
||||
$latestbackup = 'none';
|
||||
$latestbackup_date = 'no backup';
|
||||
|
||||
if (count($latestfiles) > 0)
|
||||
{
|
||||
$latestbackup = $latestfiles[0];
|
||||
$latestbackup_date = date ("Y-m-d H:i:s", filemtime($latestbackup));
|
||||
}
|
||||
|
||||
// Table sizes -----------------------------------------------------------------
|
||||
|
||||
$tableSizesHTML = "";
|
||||
|
||||
// Open a connection to the SQLite database
|
||||
$db = new SQLite3($pia_db);
|
||||
$db = new SQLite3($nax_db);
|
||||
|
||||
// Retrieve the table names from sqlite_master
|
||||
$query = "SELECT name FROM sqlite_master WHERE type='table'";
|
||||
@@ -133,13 +104,13 @@ $db->close();
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_info_table_cell" style="min-width: 140px"><?= lang('Maintenance_database_path');?></div>
|
||||
<div class="db_info_table_cell">
|
||||
<?php echo $pia_db;?>
|
||||
<?php echo $nax_db;?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_info_table_cell"><?= lang('Maintenance_database_size');?></div>
|
||||
<div class="db_info_table_cell">
|
||||
<?php echo $pia_db_size;?>
|
||||
<?php echo $nax_db_size;?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
@@ -151,13 +122,7 @@ $db->close();
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_info_table_cell"><?= lang('Maintenance_database_lastmod');?></div>
|
||||
<div class="db_info_table_cell">
|
||||
<?php echo $pia_db_mod;?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_info_table_cell"><?= lang('Maintenance_database_backup');?></div>
|
||||
<div class="db_info_table_cell">
|
||||
<?php echo $Pia_Archive_count.' '.lang('Maintenance_database_backup_found').' / '.lang('Maintenance_database_backup_total').': '.$Pia_Archive_diskusage;?>
|
||||
<?php echo $nax_db_mod;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -255,24 +220,6 @@ $db->close();
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportPastedCSV_text');?></div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" >
|
||||
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnPiaBackupDBtoArchive" onclick="askPiaBackupDBtoArchive()"><?= lang('Maintenance_Tool_backup');?></button>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_backup_text');?></div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" >
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnPiaRestoreDBfromArchive" onclick="askPiaRestoreDBfromArchive()"><?= lang('Maintenance_Tool_restore');?><br><?php echo $latestbackup_date;?></button>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_restore_text');?></div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" >
|
||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnPiaPurgeDBBackups" onclick="askPiaPurgeDBBackups()"><?= lang('Maintenance_Tool_purgebackup');?></button>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_purgebackup_text');?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ---------------------------Logging-------------------------------------------- -->
|
||||
@@ -458,51 +405,6 @@ function deleteActHistory()
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Backup DB to Archive
|
||||
function askPiaBackupDBtoArchive () {
|
||||
// Ask
|
||||
showModalWarning('<?= lang('Maintenance_Tool_backup_noti');?>', '<?= lang('Maintenance_Tool_backup_noti_text');?>',
|
||||
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Backup');?>', 'PiaBackupDBtoArchive');
|
||||
}
|
||||
function PiaBackupDBtoArchive()
|
||||
{
|
||||
// Execute
|
||||
$.get('php/server/devices.php?action=PiaBackupDBtoArchive', function(msg) {
|
||||
showMessage (msg);
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Restore DB from Archive
|
||||
function askPiaRestoreDBfromArchive () {
|
||||
// Ask
|
||||
showModalWarning('<?= lang('Maintenance_Tool_restore_noti');?>', '<?= lang('Maintenance_Tool_restore_noti_text');?>',
|
||||
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Restore');?>', 'PiaRestoreDBfromArchive');
|
||||
}
|
||||
function PiaRestoreDBfromArchive()
|
||||
{
|
||||
// Execute
|
||||
$.get('php/server/devices.php?action=PiaRestoreDBfromArchive', function(msg) {
|
||||
showMessage (msg);
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Purge Backups
|
||||
function askPiaPurgeDBBackups() {
|
||||
// Ask
|
||||
showModalWarning('<?= lang('Maintenance_Tool_purgebackup_noti');?>', '<?= lang('Maintenance_Tool_purgebackup_noti_text');?>',
|
||||
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Purge');?>', 'PiaPurgeDBBackups');
|
||||
}
|
||||
function PiaPurgeDBBackups()
|
||||
{
|
||||
// Execute
|
||||
$.get('php/server/devices.php?action=PiaPurgeDBBackups', function(msg) {
|
||||
showMessage (msg);
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Restart Backend Python Server
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ $config_file = "../../../config/app.conf"; // depends on where this file is call
|
||||
$config_file_lines = file($config_file);
|
||||
$config_file_lines = array_values(preg_grep('/^SETPWD_password.*=/', $config_file_lines));
|
||||
$password_line = explode("'", $config_file_lines[0]);
|
||||
$Pia_Password = $password_line[1];
|
||||
$nax_Password = $password_line[1];
|
||||
|
||||
if (isset($_COOKIE[$CookieSaveLoginName]) && $Pia_Password == $_COOKIE[$CookieSaveLoginName]) {
|
||||
if (isset($_COOKIE[$CookieSaveLoginName]) && $nax_Password == $_COOKIE[$CookieSaveLoginName]) {
|
||||
$isAuthenticated = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ if(array_search('action', $_REQUEST) != FALSE)
|
||||
session_destroy();
|
||||
setcookie($CookieSaveLoginName, "", time() - 3600);
|
||||
header('Location: index.php');
|
||||
exit(); // ensure script stops after header redirection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,41 +29,63 @@ if(array_search('action', $_REQUEST) != FALSE)
|
||||
// ## Login Processing start
|
||||
// ##################################################
|
||||
$config_file = $_SERVER['DOCUMENT_ROOT'] . "/../config/app.conf";
|
||||
$config_file_lines = file($config_file);
|
||||
|
||||
if (file_exists($config_file)) {
|
||||
$config_file_lines = file($config_file);
|
||||
} else {
|
||||
// handle missing config file
|
||||
die("Configuration file not found.");
|
||||
}
|
||||
|
||||
$CookieSaveLoginName = "NetAlertX_SaveLogin";
|
||||
|
||||
// ###################################
|
||||
// ## SETPWD_enable_password FALSE
|
||||
// ###################################
|
||||
|
||||
// Find SETPWD_enable_password line
|
||||
$config_file_lines_bypass = array_values(preg_grep('/^SETPWD_enable_password.*=/', $config_file_lines));
|
||||
$protection_line = explode("=", $config_file_lines_bypass[0]);
|
||||
$Pia_WebProtection = strtolower(trim($protection_line[1]));
|
||||
|
||||
if (!empty($config_file_lines_bypass)) {
|
||||
$protection_line = explode("=", $config_file_lines_bypass[0]);
|
||||
$nax_WebProtection = strtolower(trim($protection_line[1]));
|
||||
} else {
|
||||
// Default behavior if SETPWD_enable_password is not found
|
||||
$nax_WebProtection = 'false'; // or another default value
|
||||
}
|
||||
|
||||
// ###################################
|
||||
// ## SETPWD_enable_password TRUE
|
||||
// ###################################
|
||||
|
||||
$config_file_lines = array_values(preg_grep('/^SETPWD_password.*=/', $config_file_lines));
|
||||
$password_line = explode("'", $config_file_lines[0]);
|
||||
$Pia_Password = $password_line[1];
|
||||
// Find SETPWD_password line
|
||||
$config_file_lines_password = array_values(preg_grep('/^SETPWD_password.*=/', $config_file_lines));
|
||||
|
||||
if (!empty($config_file_lines_password)) {
|
||||
$password_line = explode("'", $config_file_lines_password[0]);
|
||||
$nax_Password = $password_line[1];
|
||||
} else {
|
||||
// Default behavior if SETPWD_password is not found
|
||||
$nax_Password = ''; // or handle accordingly
|
||||
}
|
||||
|
||||
// active Session or valid cookie (cookie not extends)
|
||||
if($Pia_WebProtection == 'true')
|
||||
if($nax_WebProtection == 'true')
|
||||
{
|
||||
if(isset ($_SESSION["login"]) == FALSE )
|
||||
if(isset($_SESSION["login"]) == FALSE )
|
||||
{
|
||||
$_SESSION["login"] = 0;
|
||||
}
|
||||
|
||||
if ( ($_SESSION["login"] == 1) || $isLogonPage || (( isset($_COOKIE[$CookieSaveLoginName]) && $Pia_Password == $_COOKIE[$CookieSaveLoginName ])))
|
||||
if ($_SESSION["login"] == 1 || $isLogonPage || (isset($_COOKIE[$CookieSaveLoginName]) && $nax_Password == $_COOKIE[$CookieSaveLoginName]))
|
||||
{
|
||||
//Logged in or stay on this page if we are on the index.php already
|
||||
// Logged in or stay on this page if we are on the index.php already
|
||||
|
||||
} else
|
||||
{
|
||||
// we need to redirect
|
||||
header('Location: /index.php');
|
||||
exit(); // ensure script stops after header redirection
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
||||
|
||||
} else {
|
||||
|
||||
console.error(`[saveSettings] Couldn't determnine how to handle (setCodeName|dataType|inputType):(${setCodeName}|${dataType}|${inputType})`);
|
||||
console.error(`[saveSettings] Couldn't determine how to handle (setCodeName|dataType|inputType):(${setCodeName}|${dataType}|${inputType})`);
|
||||
|
||||
value = $('#' + setCodeName).val();
|
||||
value = applyTransformers(value, transformers);
|
||||
@@ -795,11 +795,13 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
||||
clearCache()
|
||||
} else{
|
||||
// something went wrong
|
||||
// write_notification(data, 'interrupt')
|
||||
write_notification("Please screenshot the next popup (or check Monitoring > Notifications), dev console (F12) and submit it as a new issue here: https://github.com/jokob-sk/NetAlertX/issues", 'interrupt')
|
||||
write_notification("[Important] DO NOT REFERSH the page. Open the browser DEV console (F12). Please take a screenshot of it. Submit it (with the nginx and php error logs) as a new issue here: https://github.com/jokob-sk/NetAlertX/issues", 'interrupt')
|
||||
|
||||
console.log("🔽");
|
||||
console.log(settingsArray);
|
||||
console.log(JSON.stringify(settingsArray));
|
||||
write_notification(JSON.stringify(settingsArray), 'interrupt')
|
||||
console.log(data);
|
||||
console.log("🔼");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user