PUSHPROD fix settings & LOG_PRINT

This commit is contained in:
Jokob-sk
2022-12-25 10:09:34 +11:00
parent ba8fa0b37b
commit d6a5f23345
5 changed files with 43 additions and 33 deletions

View File

@@ -34,8 +34,8 @@ import requests
from base64 import b64encode
from paho.mqtt import client as mqtt_client
import threading
from ssdpy import SSDPClient
import upnpclient
# from ssdpy import SSDPClient
# import upnpclient
#===============================================================================
# PATHS
@@ -233,6 +233,7 @@ mqtt_thread_up = False
# timestamps of last execution times
time_now = datetime.datetime.now()
log_timestamp = time_now
now_minus_24h = time_now - timedelta(hours = 24)
last_network_scan = now_minus_24h
@@ -277,8 +278,6 @@ def main ():
file_print('\nLoop start')
file_print('---------------------------')
log_timestamp = time_now
# Timestamp
startTime = time_now
startTime = startTime.replace (second=0, microsecond=0)
@@ -2388,25 +2387,31 @@ def upgradeDB ():
ALTER TABLE "Devices" ADD "dev_Network_Node_port" INTEGER
""")
# Missing parameters in the Parameters table
missingSettings = len(sql.execute ("""
SELECT * FROM Parameters WHERE par_ID='Front_Events_Period'
""").fetchall()) == 0
# Re-creating Parameters table
file_print("[upgradeDB] Re-creating Parameters table")
sql.execute("DROP TABLE Parameters;")
if missingSettings:
file_print("[upgradeDB] Adding missing values into the Parameters table")
sql.execute("""
CREATE TABLE "Parameters" (
"par_ID" INTEGER,
"par_Value" TEXT
);
""")
params = [
# General
('Front_Events_Period', 'Subnets to scan'),
('Front_Details_Sessions_Rows', '50'),
('Front_Details_Events_Rows', '50'),
('Front_Details_Events_Hide', 'True'),
('Front_Events_Rows', '50'),
('Front_Details_Period', '1 day')
]
params = [
# General
('Front_Events_Period', '1 day'),
('Front_Details_Sessions_Rows', '50'),
('Front_Details_Events_Rows', '50'),
('Front_Details_Events_Hide', 'True'),
('Front_Events_Rows', '50'),
('Front_Details_Period', '1 day'),
('Front_Devices_Order', '[[3,"desc"],[0,"asc"]]'),
('Front_Devices_Rows', '100'),
('Front_Details_Tab', 'tabDetails')
]
sql.executemany ("""INSERT INTO Parameters ("Par_ID", "Par_Value") VALUES (?, ?)""", params)
sql.executemany ("""INSERT INTO Parameters ("par_ID", "par_Value") VALUES (?, ?)""", params)
# don't hog DB access
@@ -2489,7 +2494,7 @@ def print_log (pText):
log_timestamp2 = datetime.datetime.now()
# Print line + time + elapsed time + text
file_print('--------------------> ',
file_print('[LOG_PRINT] > ',
log_timestamp2, ' ',
log_timestamp2 - log_timestamp, ' ',
pText)

View File

@@ -16,7 +16,7 @@ services:
# comment out / delete below lines, they are only for development purposes
- ${DEV_LOCATION}/back/pialert.py:/home/pi/pialert/back/pialert.py
- ${DEV_LOCATION}/back/update_vendors.sh:/home/pi/pialert/back/update_vendors.sh
# - ${APP_DATA_LOCATION}/pialert/php.ini:/etc/php/7.4/fpm/php.ini
- ${APP_DATA_LOCATION}/pialert/php.ini:/etc/php/7.4/fpm/php.ini
- ${DEV_LOCATION}/front/css:/home/pi/pialert/front/css
- ${DEV_LOCATION}/front/js:/home/pi/pialert/front/js
- ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php

View File

@@ -70,13 +70,12 @@ require '/home/pi/pialert/front/php/templates/language/'.$pia_lang_selected.'.ph
$FUNCTION = [];
$SETTINGS = [];
if(array_search('function', $FUNCTION) != FALSE)
{
if(array_key_exists('function', $_REQUEST) != FALSE)
{echo 'here'.$timestamp ;
$FUNCTION = $_REQUEST['function'];
}
if(array_search('function', $SETTINGS) != FALSE)
if(array_key_exists('settings', $_REQUEST) != FALSE)
{
$SETTINGS = $_REQUEST['settings'];
}
@@ -211,7 +210,7 @@ function saveSettings()
{
global $SETTINGS, $FUNCTION, $config_file, $fullConfPath, $configFolderPath, $timestamp;
echo 'here'.$timestamp ;
// save in the file
$new_name = $config_file.'_'.$timestamp.'.backup';
@@ -233,6 +232,8 @@ function saveSettings()
// generate a clean pialert.conf file
$groups = [];
$txt = "";
$txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n";
$txt = $txt."# #\n";
$txt = $txt."# Generated: ".$timestamp." #\n";
@@ -299,7 +300,7 @@ function saveSettings()
displayMessage("<br/>Settings saved to the <code>".$config_file."</code> file.
Backup of ".$config_file." created: <code>".$new_name."</code>.<br/>
<b>Restart the container for the chanegs to take effect.</b>",
<b>Restart the container for the changes to take effect.</b>",
FALSE, TRUE, TRUE, TRUE);
}

View File

@@ -96,9 +96,11 @@ $db->close();
{
$html = $html.
'<div class="table_row" >
<div class="table_cell setting_name" >';
<div class="table_cell setting_name bold" ><label>';
$html = $html.getString ($set['Code_Name'].'_name', $set['Display_Name'], $pia_lang);
$html = $html.getString ($set['Code_Name'].'_name', $set['Display_Name'], $pia_lang).'</label>';
$html = $html.'<div class="small" ><code>'.$set['Code_Name'].'</code></div>';
$html = $html.
'</div>
@@ -106,6 +108,8 @@ $db->close();
$html = $html.getString ($set['Code_Name'].'_description', $set['Description'], $pia_lang);
$html = $html.
'</div>
<div class="table_cell setting_input" >';