code cleanup

This commit is contained in:
Jokob-sk
2022-12-26 20:30:28 +11:00
parent 7b5be5feee
commit 31d7c5173f
13 changed files with 149 additions and 295 deletions

View File

@@ -51,6 +51,8 @@ fullConfPath = pialertPath + confPath
fullDbPath = pialertPath + dbPath
STOPARPSCAN = pialertPath + "/db/setting_stoparpscan"
time_now = datetime.datetime.now()
log_timestamp = time_now
sql_connection = None
@@ -101,7 +103,7 @@ def print_log (pText):
log_timestamp2 = datetime.datetime.now()
# Print line + time + elapsed time + text
file_print('[LOG_PRINT] ',
file_print('[PRINT_LOG] ',
log_timestamp2, ' ',
log_timestamp2 - log_timestamp, ' ',
pText)
@@ -469,8 +471,6 @@ check_report = [1, "internet_IP", "update_vendors_silent"]
mqtt_thread_up = False
# timestamps of last execution times
time_now = datetime.datetime.now()
log_timestamp = time_now
startTime = time_now
now_minus_24h = time_now - timedelta(hours = 24)
@@ -2560,7 +2560,7 @@ def upgradeDB ():
""").fetchone() == None
# Re-creating Settings table
if settingsMissing:
# if settingsMissing:
file_print("[upgradeDB] Re-creating Settings table")
sql.execute("DROP TABLE Settings;")

View File

@@ -10,69 +10,17 @@ if(array_search('action', $_REQUEST) != FALSE)
}
}
require 'php/templates/language/lang.php';
require 'php/templates/skinUI.php';
// ##################################################
// ## Login Processing start
// ##################################################
$config_file = "../config/pialert.conf";
$config_file_lines = file($config_file);
// ###################################
// ## GUI settings processing start
// ###################################
if (file_exists('../db/setting_darkmode')) {
$ENABLED_DARKMODE = True;
}
foreach (glob("../db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (isset($pia_skin_selected) == FALSE or (strlen($pia_skin_selected) == 0)) {$pia_skin_selected = 'skin-blue';}
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require '/home/pi/pialert/front/php/templates/language/'.$pia_lang_selected.'.php';
// ###################################
// ## GUI settings processing end
// ###################################
// ###################################
// ## Languages
// ###################################
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require 'php/templates/language/en_us.php';
require 'php/templates/language/de_de.php';
require 'php/templates/language/es_es.php';
function lang($key)
{
global $pia_lang_selected, $lang ;
// try to get the selected language translation
$temp = $lang[$pia_lang_selected][$key];
if(isset($temp) == FALSE)
{
// if not found, use English
$temp = $lang[$pia_lang_selected]["en_us"];
// echo $temp;
if(isset($temp) == FALSE)
{
// if not found, in English, use placeholder
$temp = "String not found";
}
}
// echo $temp;
return $temp;
}
// ###################################
// ## PIALERT_WEB_PROTECTION FALSE
// ###################################

View File

@@ -146,32 +146,6 @@ if (submit && isset($_POST['skinselector_set'])) {
// Language selector -----------------------------------------------------------------
if (submit && isset($_POST['langselector_set'])) {
$pia_lang_set_dir = '../db/';
$pia_lang_selector = htmlspecialchars($_POST['langselector']);
if (in_array($pia_lang_selector, $pia_installed_langs)) {
foreach ($pia_installed_langs as $file) {
unlink ($pia_lang_set_dir.'/setting_language_'.$file);
}
foreach ($pia_installed_langs as $file) {
if (file_exists($pia_lang_set_dir.'/setting_language_'.$file)) {
$pia_lang_error = True;
break;
} else {
$pia_lang_error = False;
}
}
if ($pia_lang_error == False) {
$testlang = fopen($pia_lang_set_dir.'setting_language_'.$pia_lang_selector, 'w');
//$pia_lang_test = '';
echo("<meta http-equiv='refresh' content='1'>");
} else {
//$pia_lang_test = '';
echo("<meta http-equiv='refresh' content='1'>");
}
}
}
?>
<div class="row">
@@ -240,14 +214,12 @@ if (submit && isset($_POST['langselector_set'])) {
<div class="db_tools_table_cell_a" style="text-align:center;">
<form method="post" action="maintenance.php">
<div style="display: inline-block;">
<select name="langselector" class="form-control bg-green" style="width:160px; margin-bottom:5px;">
<select name="langselector" id="langselector" class="form-control bg-green" style="width:160px; margin-bottom:5px;">
<option value=""><?php echo lang('Maintenance_lang_selector_empty');?></option>
<option value="en_us"><?php echo lang('Maintenance_lang_en_us');?></option>
<option value="de_de"><?php echo lang('Maintenance_lang_de_de');?></option>
<option value="es_es"><?php echo lang('Maintenance_lang_es_es');?></option>
</select></div>
<div style="display: block;"><input type="submit" name="langselector_set" value="<?php echo lang('Maintenance_lang_selector_apply');?>" class="btn bg-green" style="width:160px;">
<?php // echo $pia_lang_test; ?>
</select>
</div>
</form>
</div>
@@ -722,6 +694,14 @@ function initializeTabs () {
});
}
// save language in a cookie
$('#langselector').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
setCookie("language",valueSelected )
location.reload();
});
// load footer asynchronously not to block the page load/other sections
window.onload = function asyncFooter()

View File

@@ -7,54 +7,11 @@
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ###################################
// ## TimeZone processing start
// ###################################
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
//------------------------------------------------------------------------------
// External files
require 'db.php';
require 'util.php';
require '/home/pi/pialert/front/php/templates/timezone.php';
require '/home/pi/pialert/front/php/server/db.php';
require '/home/pi/pialert/front/php/server/util.php';
//------------------------------------------------------------------------------
// Action selector

View File

@@ -8,57 +8,10 @@
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ###################################
// ## TimeZone processing start
// ###################################
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
require '/home/pi/pialert/front/php/templates/timezone.php';
require '/home/pi/pialert/front/php/templates/skinUI.php';
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
// ###################################
// ## GUI settings processing start
// ###################################
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require '/home/pi/pialert/front/php/templates/language/'.$pia_lang_selected.'.php';
// ###################################
// ## GUI settings processing end
// ###################################
$FUNCTION = [];
$SETTINGS = [];

View File

@@ -8,101 +8,11 @@
#--------------------------------------------------------------------------- -->
<?php
// ###################################
// ## TimeZone processing start
// ###################################
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
require '/home/pi/pialert/front/php/templates/timezone.php';
require '/home/pi/pialert/front/php/templates/skinUI.php';
require '/home/pi/pialert/front/php/templates/language/lang.php';
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
// ###################################
// ## GUI settings processing start
// ###################################
if (file_exists('../db/setting_darkmode')) {
$ENABLED_DARKMODE = True;
}
foreach (glob("../db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (isset($pia_skin_selected) == FALSE or (strlen($pia_skin_selected) == 0)) {$pia_skin_selected = 'skin-blue';}
// ###################################
// ## Languages
// ###################################
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require 'php/templates/language/en_us.php';
require 'php/templates/language/de_de.php';
require 'php/templates/language/es_es.php';
function lang($key)
{
global $pia_lang_selected, $lang ;
// try to get the selected language translation
$temp = $lang[$pia_lang_selected][$key];
if(isset($temp) == FALSE)
{
// if not found, use English
$temp = $lang[$pia_lang_selected]["en_us"];
// echo $temp;
if(isset($temp) == FALSE)
{
// if not found, in English, use placeholder
$temp = "String not found";
}
}
// echo $temp;
return $temp;
}
// ###################################
// ## GUI settings processing end
// ###################################
?>
<!DOCTYPE html>

View File

@@ -205,7 +205,7 @@ $lang['de_de'] = array(
'DevDetail_Nmap_buttonDetail_text' => 'Detailierter Scan: Standardscan mit aktivierter Betriebssystemerkennung, Versionserkennung, Skript-Scan und Traceroute (bis zu 30 oder mehr Sekunden)',
'DevDetail_Nmap_buttonSkipDiscovery' => 'Ohne Erreichbarkeitsprüfung',
'DevDetail_Nmap_buttonSkipDiscovery_text' => 'Ohne Erreichbarkeitsprüfung (-Pn Parameter): Standard Scan bei dem nmap annimmt, dass der Host erreichbar ist.',
'DevDetail_Nmap_resultsLink' => 'Results will be also available in the <code>pialert_front.log</code> file.',
//////////////////////////////////////////////////////////////////
// Maintenance Page

View File

@@ -203,7 +203,7 @@ $lang['en_us'] = array(
'DevDetail_Nmap_buttonDetail_text' => 'Detailed Scan: Default scan with enabled OS detection, version detection, script scanning and traceroute (up to 30 seconds or more)',
'DevDetail_Nmap_buttonSkipDiscovery' => 'Skip host discovery',
'DevDetail_Nmap_buttonSkipDiscovery_text' => 'Skip host discovery (-Pn option): Default scan without host discovery',
'DevDetail_Nmap_resultsLink' => 'Results will be also available in the <code>pialert_front.log</code> file.',
'DevDetail_Nmap_resultsLink' => 'You can leave this page after starting a scan. Results will be also available in the <code>pialert_front.log</code> file.',
//////////////////////////////////////////////////////////////////
// Maintenance Page
@@ -212,7 +212,7 @@ $lang['en_us'] = array(
'Maintenance_Title' => 'Maintenance tools',
'Maintenance_database_path' => 'Database-Path',
'Maintenance_database_size' => 'Database-Size',
'Maintenance_database_lastmod' => 'last Modification',
'Maintenance_database_lastmod' => 'Last Modification',
'Maintenance_database_backup' => 'DB Backups',
'Maintenance_database_backup_found' => 'backups were found',
'Maintenance_database_backup_total' => 'total disk usage',
@@ -228,7 +228,7 @@ $lang['en_us'] = array(
'Maintenance_lang_en_us' => 'English (US)',
'Maintenance_lang_de_de' => 'German (DE)',
'Maintenance_lang_es_es' => 'Spanish (ES)',
'Maintenance_lang_selector_text' => 'The change takes place on the server side, so it affects all devices in use.',
'Maintenance_lang_selector_text' => 'The change takes place on the client side, so it affects only the current browser.',
'Maintenance_lang_selector_apply' => 'Apply',
'Maintenance_Tools_Tab_Settings' => 'Settings',
'Maintenance_Tools_Tab_Tools' => 'Tools',
@@ -422,6 +422,9 @@ $lang['en_us'] = array(
// Settings
//////////////////////////////////////////////////////////////////
'settings_missing' => 'Not all settings loaded, refresh the page!',
//General
'SCAN_SUBNETS_name' => 'Subnets to scan',
'SCAN_SUBNETS_description' => '

View File

@@ -47,7 +47,7 @@ $lang['es_es'] = array(
'Navigation_Presence' => 'Historial',
'Navigation_Events' => 'Eventos',
'Navigation_Maintenance' => 'Cantenimiento',
'Navigation_Settings' => 'configuración',
'Navigation_Settings' => 'Configuración',
'Navigation_Network' => 'Red',
'Navigation_HelpFAQ' => 'Ayuda / FAQ',
'Device_Title' => 'Dispositivos',
@@ -199,7 +199,6 @@ $lang['es_es'] = array(
'DevDetail_Nmap_buttonDetail_text' => 'Escaneo detallado: escaneo predeterminado con detección de sistema operativo habilitado, detección de versiones, escaneo de script y traceroute (hasta 30 segundos o más)',
'DevDetail_Nmap_buttonSkipDiscovery' => 'Omitir detección de host',
'DevDetail_Nmap_buttonSkipDiscovery_text' => 'Omitir detección de host (-Pn opción): Escaneo predeterminado sin detección de host',
'DevDetail_Nmap_resultsLink' => 'Results will be also available in the <code>pialert_front.log</code> file.',
//////////////////////////////////////////////////////////////////
// Maintenance Page - Update by @TeroRERO 07ago2022

View File

@@ -0,0 +1,43 @@
<?php
// ###################################
// ## Languages
// ###################################
if(!isset($_COOKIE["language"])) {
$pia_lang_selected = "en_us";
} else {
$pia_lang_selected = $_COOKIE["language"];
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require 'en_us.php';
require 'de_de.php';
require 'es_es.php';
function lang($key)
{
global $pia_lang_selected, $lang ;
// try to get the selected language translation
$temp = $lang[$pia_lang_selected][$key];
if(isset($temp) == FALSE)
{
// if not found, use English
$temp = $lang[$pia_lang_selected]["en_us"];
// echo $temp;
if(isset($temp) == FALSE)
{
// if not found, in English, use placeholder
$temp = "String not found";
}
}
// echo $temp;
return $temp;
}
?>

View File

@@ -0,0 +1,19 @@
<?php
// ###################################
// ## GUI settings processing start
// ###################################
if (file_exists('/home/pi/pialert/db/setting_darkmode')) {
$ENABLED_DARKMODE = True;
}
foreach (glob("/home/pi/pialert/db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (isset($pia_skin_selected) == FALSE or (strlen($pia_skin_selected) == 0)) {$pia_skin_selected = 'skin-blue';}
// ###################################
// ## GUI settings processing end
// ###################################
?>

View File

@@ -0,0 +1,44 @@
<?php
// ###################################
// ## TimeZone processing start
// ###################################
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
?>

View File

@@ -19,9 +19,6 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
// External files
require 'php/server/db.php';
require 'php/server/util.php';
require 'php/templates/language/'.$pia_lang_selected.'.php';
//------------------------------------------------------------------------------
// Action selector
@@ -47,8 +44,7 @@ $result = $db->query("SELECT * FROM Settings");
$settings = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// Push row data
$settings[] = array( 'Index' => $row['Index'],
'Code_Name' => $row['Code_Name'],
$settings[] = array( 'Code_Name' => $row['Code_Name'],
'Display_Name' => $row['Display_Name'],
'Description' => $row['Description'],
'Type' => $row['Type'],
@@ -61,6 +57,8 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
$db->close();
echo "<script>if(".count($settings)." != 46)alert('".lang("settings_missing")."')</script>";
?>
<!-- Page ------------------------------------------------------------------ -->
<div class="content-wrapper">