diff --git a/back/pialert.py b/back/pialert.py index 9ebe1f58..e8b0c560 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -517,7 +517,8 @@ def main (): reporting = False # Header - file_print('[', time_now.replace (microsecond=0), '] Loop start ') + updateState("Process: Start") + file_print('[', time_now.replace (microsecond=0), '] Process: Start') # Timestamp startTime = time_now @@ -562,7 +563,8 @@ def main (): cycle = "" # Footer - file_print('[', time_now.replace (microsecond=0), '] Loop end') + updateState("Process: Wait") + file_print('[', time_now.replace (microsecond=0), '] Process: Wait') else: # do something cycle = "" @@ -578,6 +580,7 @@ def check_internet_IP (): reporting = False # Header + updateState("Scanning: Internet IP") file_print('[', startTime, '] Check Internet IP:') # Get Internet IP @@ -746,6 +749,7 @@ def check_IP_format (pIP): #=============================================================================== def cleanup_database (): # Header + updateState("Maintenance: DB cleanup") file_print('[', startTime, '] Cleanup Database:' ) openDB() @@ -770,6 +774,7 @@ def cleanup_database (): #=============================================================================== def update_devices_MAC_vendors (pArg = ''): # Header + updateState("Maintenance: Update HW Vendors") file_print('[', startTime, '] Update HW Vendors:' ) # Update vendors DB (iab oui) @@ -889,6 +894,7 @@ def scan_network (): # # devtest end # Header + updateState("Scanning: Network") file_print('[', startTime, '] Scan Devices:' ) file_print(' ScanCycle:', cycle) @@ -923,7 +929,7 @@ def scan_network (): reporting = read_DHCP_leases () or reporting # Load current scan data - file_print('Processing scan results') + file_print(' Processing scan results') save_scanned_devices (arpscan_devices, cycle_interval) # Print stats @@ -932,7 +938,7 @@ def scan_network (): print_log ('Stats end') # Create Events - file_print('Updating DB Info') + file_print(' Updating DB Info') file_print(' Sessions Events (connect / discconnect)') insert_events() @@ -1756,7 +1762,7 @@ def email_reporting (): deviceUrl = REPORT_DASHBOARD_URL + '/deviceDetails.php?mac=' # Reporting section - file_print('Check if something to report') + file_print(' Check if something to report') openDB() # prepare variables for JSON construction @@ -1941,38 +1947,42 @@ def email_reporting (): # Send Mail if json_internet != [] or json_new_devices != [] or json_down_devices != [] or json_events != []: - file_print('\nChanges detected, sending reports') + file_print('Changes detected, sending reports') - if REPORT_MAIL and check_config('email'): - file_print(' Sending report by email') + if REPORT_MAIL and check_config('email'): + updateState("Sending: Email") + file_print(' Sending report by Email') send_email (mail_text, mail_html) else : file_print(' Skip mail') if REPORT_APPRISE and check_config('apprise'): + updateState("Sending: Apprise") file_print(' Sending report by Apprise') send_apprise (mail_html) else : file_print(' Skip Apprise') if REPORT_WEBHOOK and check_config('webhook'): - file_print(' Sending report by webhook') + updateState("Sending: Webhook") + file_print(' Sending report by Webhook') send_webhook (json_final, mail_text) else : file_print(' Skip webhook') if REPORT_NTFY and check_config('ntfy'): + updateState("Sending: NTFY") file_print(' Sending report by NTFY') send_ntfy (mail_text) else : file_print(' Skip NTFY') if REPORT_PUSHSAFER and check_config('pushsafer'): + updateState("Sending: PUSHSAFER") file_print(' Sending report by PUSHSAFER') send_pushsafer (mail_text) else : file_print(' Skip PUSHSAFER') # Update MQTT entities if REPORT_MQTT and check_config('mqtt'): - file_print(' Establishing MQTT thread') - # mqtt_thread_up = True # prevent this code to be run multiple times concurrently - # start_mqtt_thread () + updateState("Sending: MQTT") + file_print(' Establishing MQTT thread') mqtt_start() else : file_print(' Skip MQTT') @@ -2338,10 +2348,10 @@ def mqtt_create_client(): global mqtt_connected_to_broker if rc == 0: - file_print("Connected to broker") + file_print(" Connected to broker") mqtt_connected_to_broker = True # Signal connection else: - file_print("Connection failed") + file_print(" Connection failed") mqtt_connected_to_broker = False @@ -2546,7 +2556,7 @@ def upgradeDB (): sql.execute(""" CREATE TABLE "Parameters" ( - "par_ID" INTEGER, + "par_ID" TEXT, "par_Value" TEXT ); """) @@ -2561,14 +2571,25 @@ def upgradeDB (): ('Front_Details_Period', '1 day'), ('Front_Devices_Order', '[[3,"desc"],[0,"asc"]]'), ('Front_Devices_Rows', '100'), - ('Front_Details_Tab', 'tabDetails') + ('Front_Details_Tab', 'tabDetails'), + ('Back_App_State', 'Initializing') ] - 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 closeDB () + +#------------------------------------------------------------------------------- +def updateState(newState): + openDB() + + sql.execute ("UPDATE Parameters SET par_Value='"+ newState +"' WHERE par_ID='Back_App_State'") + + # don't hog DB access + closeDB () + #=============================================================================== # Home Assistant UTILs @@ -2597,7 +2618,7 @@ def to_binary_sensor(input): #=============================================================================== # UTIL #=============================================================================== -#------------------------------------------------------------------------------- + def sanitize_string(input): if isinstance(input, bytes): diff --git a/front/css/pialert.css b/front/css/pialert.css index f1d06e14..5c42b1ca 100755 --- a/front/css/pialert.css +++ b/front/css/pialert.css @@ -560,6 +560,35 @@ height: 50px; /*settings*/ +@media (max-width: 767px) { + .setting_description { + /* color: red; */ + display: none; + } + .setting_input{ + width:70%; + /* background-color: red; */ + } + .setting_name + { + width:30%; + } + } + @media (min-width: 768px) { + .setting_description { + /* color: rgb(0, 255, 106); */ + display: block; + } + .setting_input{ + width:35%; + /* background-color: rgb(0, 255, 106); */ + } + .setting_name + { + width:19%; + } + } + .table_row { padding: 3px; width:100%; @@ -579,7 +608,7 @@ height: 50px; .setting_name { - width:19%; + /* width:19%; */ font-weight: 300; } @@ -588,10 +617,10 @@ height: 50px; width:46%; } -.setting_input +/* .setting_input { width:35%; -} +} */ .center { diff --git a/front/devices.php b/front/devices.php index cc621225..3faeb56b 100755 --- a/front/devices.php +++ b/front/devices.php @@ -224,12 +224,11 @@ function main () { // get parameter value $.get('php/server/parameters.php?action=get¶meter='+ parTableRows, function(data) { var result = JSON.parse(data); - + result = parseInt(result, 10) if (Number.isInteger (result) ) { - tableRows = result; - + tableRows = result; } // get parameter value diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 5623d938..b085b8ab 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -11,6 +11,23 @@ var timerRefreshData = '' var modalCallbackFunction = ''; +function getCache(key) +{ + // check cache + if(sessionStorage.getItem(key)) + { + return sessionStorage.getItem(key); + } else + { + return ""; + } +} + +function setCache(key, data) +{ + sessionStorage.setItem(key, data); +} + // ----------------------------------------------------------------------------- function setCookie (cookie, value, expirationHours='') { diff --git a/front/maintenance.php b/front/maintenance.php index b7a8d22a..10bc6b48 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -723,24 +723,6 @@ function initializeTabs () { } -function getCache(key) -{ - // check cache - if(sessionStorage.getItem(key)) - { - return sessionStorage.getItem(key); - } else - { - return ""; - } -} - -function setCache(key, data) -{ - sessionStorage.setItem(key, data); -} - - // load footer asynchronously not to block the page load/other sections window.onload = function asyncFooter() { diff --git a/front/php/server/parameters.php b/front/php/server/parameters.php index 129eba32..8366ffbe 100755 --- a/front/php/server/parameters.php +++ b/front/php/server/parameters.php @@ -49,6 +49,8 @@ function getParameter() { $row = $result -> fetchArray (SQLITE3_NUM); $value = $row[0]; + // displayMessage ($value); + echo (json_encode ($value)); } diff --git a/front/php/templates/footer.php b/front/php/templates/footer.php index e29b79c9..2c3e339e 100755 --- a/front/php/templates/footer.php +++ b/front/php/templates/footer.php @@ -32,11 +32,7 @@ - - - - diff --git a/front/php/templates/header.php b/front/php/templates/header.php index a3259eb1..623e3993 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -84,6 +84,11 @@ require 'php/templates/language/'.$pia_lang_selected.'.php'; + + + + + @@ -127,30 +132,33 @@ if ($ENABLED_DARKMODE === True) { $BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/boxed-bg-dark.png\');"'; } else { $BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/background.png\');"';} ?> + + @@ -180,11 +188,12 @@ document.addEventListener("visibilitychange",()=>{ Toggle navigation - +