Global status, CSS/JS fixes

This commit is contained in:
Jokob-sk
2022-12-26 14:53:54 +11:00
parent 5e46ce4210
commit 2d683c6ab1
9 changed files with 146 additions and 71 deletions

View File

@@ -517,7 +517,8 @@ def main ():
reporting = False reporting = False
# Header # Header
file_print('[', time_now.replace (microsecond=0), '] Loop start ') updateState("Process: Start")
file_print('[', time_now.replace (microsecond=0), '] Process: Start')
# Timestamp # Timestamp
startTime = time_now startTime = time_now
@@ -562,7 +563,8 @@ def main ():
cycle = "" cycle = ""
# Footer # Footer
file_print('[', time_now.replace (microsecond=0), '] Loop end') updateState("Process: Wait")
file_print('[', time_now.replace (microsecond=0), '] Process: Wait')
else: else:
# do something # do something
cycle = "" cycle = ""
@@ -578,6 +580,7 @@ def check_internet_IP ():
reporting = False reporting = False
# Header # Header
updateState("Scanning: Internet IP")
file_print('[', startTime, '] Check Internet IP:') file_print('[', startTime, '] Check Internet IP:')
# Get Internet IP # Get Internet IP
@@ -746,6 +749,7 @@ def check_IP_format (pIP):
#=============================================================================== #===============================================================================
def cleanup_database (): def cleanup_database ():
# Header # Header
updateState("Maintenance: DB cleanup")
file_print('[', startTime, '] Cleanup Database:' ) file_print('[', startTime, '] Cleanup Database:' )
openDB() openDB()
@@ -770,6 +774,7 @@ def cleanup_database ():
#=============================================================================== #===============================================================================
def update_devices_MAC_vendors (pArg = ''): def update_devices_MAC_vendors (pArg = ''):
# Header # Header
updateState("Maintenance: Update HW Vendors")
file_print('[', startTime, '] Update HW Vendors:' ) file_print('[', startTime, '] Update HW Vendors:' )
# Update vendors DB (iab oui) # Update vendors DB (iab oui)
@@ -889,6 +894,7 @@ def scan_network ():
# # devtest end # # devtest end
# Header # Header
updateState("Scanning: Network")
file_print('[', startTime, '] Scan Devices:' ) file_print('[', startTime, '] Scan Devices:' )
file_print(' ScanCycle:', cycle) file_print(' ScanCycle:', cycle)
@@ -923,7 +929,7 @@ def scan_network ():
reporting = read_DHCP_leases () or reporting reporting = read_DHCP_leases () or reporting
# Load current scan data # Load current scan data
file_print('Processing scan results') file_print(' Processing scan results')
save_scanned_devices (arpscan_devices, cycle_interval) save_scanned_devices (arpscan_devices, cycle_interval)
# Print stats # Print stats
@@ -932,7 +938,7 @@ def scan_network ():
print_log ('Stats end') print_log ('Stats end')
# Create Events # Create Events
file_print('Updating DB Info') file_print(' Updating DB Info')
file_print(' Sessions Events (connect / discconnect)') file_print(' Sessions Events (connect / discconnect)')
insert_events() insert_events()
@@ -1756,7 +1762,7 @@ def email_reporting ():
deviceUrl = REPORT_DASHBOARD_URL + '/deviceDetails.php?mac=' deviceUrl = REPORT_DASHBOARD_URL + '/deviceDetails.php?mac='
# Reporting section # Reporting section
file_print('Check if something to report') file_print(' Check if something to report')
openDB() openDB()
# prepare variables for JSON construction # prepare variables for JSON construction
@@ -1941,38 +1947,42 @@ def email_reporting ():
# Send Mail # Send Mail
if json_internet != [] or json_new_devices != [] or json_down_devices != [] or json_events != []: 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'): if REPORT_MAIL and check_config('email'):
file_print(' Sending report by email') updateState("Sending: Email")
file_print(' Sending report by Email')
send_email (mail_text, mail_html) send_email (mail_text, mail_html)
else : else :
file_print(' Skip mail') file_print(' Skip mail')
if REPORT_APPRISE and check_config('apprise'): if REPORT_APPRISE and check_config('apprise'):
updateState("Sending: Apprise")
file_print(' Sending report by Apprise') file_print(' Sending report by Apprise')
send_apprise (mail_html) send_apprise (mail_html)
else : else :
file_print(' Skip Apprise') file_print(' Skip Apprise')
if REPORT_WEBHOOK and check_config('webhook'): 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) send_webhook (json_final, mail_text)
else : else :
file_print(' Skip webhook') file_print(' Skip webhook')
if REPORT_NTFY and check_config('ntfy'): if REPORT_NTFY and check_config('ntfy'):
updateState("Sending: NTFY")
file_print(' Sending report by NTFY') file_print(' Sending report by NTFY')
send_ntfy (mail_text) send_ntfy (mail_text)
else : else :
file_print(' Skip NTFY') file_print(' Skip NTFY')
if REPORT_PUSHSAFER and check_config('pushsafer'): if REPORT_PUSHSAFER and check_config('pushsafer'):
updateState("Sending: PUSHSAFER")
file_print(' Sending report by PUSHSAFER') file_print(' Sending report by PUSHSAFER')
send_pushsafer (mail_text) send_pushsafer (mail_text)
else : else :
file_print(' Skip PUSHSAFER') file_print(' Skip PUSHSAFER')
# Update MQTT entities # Update MQTT entities
if REPORT_MQTT and check_config('mqtt'): if REPORT_MQTT and check_config('mqtt'):
file_print(' Establishing MQTT thread') updateState("Sending: MQTT")
# mqtt_thread_up = True # prevent this code to be run multiple times concurrently file_print(' Establishing MQTT thread')
# start_mqtt_thread ()
mqtt_start() mqtt_start()
else : else :
file_print(' Skip MQTT') file_print(' Skip MQTT')
@@ -2338,10 +2348,10 @@ def mqtt_create_client():
global mqtt_connected_to_broker global mqtt_connected_to_broker
if rc == 0: if rc == 0:
file_print("Connected to broker") file_print(" Connected to broker")
mqtt_connected_to_broker = True # Signal connection mqtt_connected_to_broker = True # Signal connection
else: else:
file_print("Connection failed") file_print(" Connection failed")
mqtt_connected_to_broker = False mqtt_connected_to_broker = False
@@ -2546,7 +2556,7 @@ def upgradeDB ():
sql.execute(""" sql.execute("""
CREATE TABLE "Parameters" ( CREATE TABLE "Parameters" (
"par_ID" INTEGER, "par_ID" TEXT,
"par_Value" TEXT "par_Value" TEXT
); );
""") """)
@@ -2561,14 +2571,25 @@ def upgradeDB ():
('Front_Details_Period', '1 day'), ('Front_Details_Period', '1 day'),
('Front_Devices_Order', '[[3,"desc"],[0,"asc"]]'), ('Front_Devices_Order', '[[3,"desc"],[0,"asc"]]'),
('Front_Devices_Rows', '100'), ('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 # don't hog DB access
closeDB () 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 # Home Assistant UTILs
@@ -2597,7 +2618,7 @@ def to_binary_sensor(input):
#=============================================================================== #===============================================================================
# UTIL # UTIL
#=============================================================================== #===============================================================================
#-------------------------------------------------------------------------------
def sanitize_string(input): def sanitize_string(input):
if isinstance(input, bytes): if isinstance(input, bytes):

View File

@@ -560,6 +560,35 @@ height: 50px;
/*settings*/ /*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 { .table_row {
padding: 3px; padding: 3px;
width:100%; width:100%;
@@ -579,7 +608,7 @@ height: 50px;
.setting_name .setting_name
{ {
width:19%; /* width:19%; */
font-weight: 300; font-weight: 300;
} }
@@ -588,10 +617,10 @@ height: 50px;
width:46%; width:46%;
} }
.setting_input /* .setting_input
{ {
width:35%; width:35%;
} } */
.center .center
{ {

View File

@@ -224,12 +224,11 @@ function main () {
// get parameter value // get parameter value
$.get('php/server/parameters.php?action=get&parameter='+ parTableRows, function(data) { $.get('php/server/parameters.php?action=get&parameter='+ parTableRows, function(data) {
var result = JSON.parse(data); var result = JSON.parse(data);
result = parseInt(result, 10) result = parseInt(result, 10)
if (Number.isInteger (result) ) { if (Number.isInteger (result) ) {
tableRows = result; tableRows = result;
} }
// get parameter value // get parameter value

View File

@@ -11,6 +11,23 @@
var timerRefreshData = '' var timerRefreshData = ''
var modalCallbackFunction = ''; 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='') { function setCookie (cookie, value, expirationHours='') {

View File

@@ -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 // load footer asynchronously not to block the page load/other sections
window.onload = function asyncFooter() window.onload = function asyncFooter()
{ {

View File

@@ -49,6 +49,8 @@ function getParameter() {
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
$value = $row[0]; $value = $row[0];
// displayMessage ($value);
echo (json_encode ($value)); echo (json_encode ($value));
} }

View File

@@ -32,11 +32,7 @@
</div> </div>
<!-- ./wrapper --> <!-- ./wrapper -->
<!-- ----------------------------------------------------------------------- -->
<!-- REQUIRED JS SCRIPTS -->
<!-- jQuery 3 -->
<script src="lib/AdminLTE/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 --> <!-- Bootstrap 3.3.7 -->
<script src="lib/AdminLTE/bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <script src="lib/AdminLTE/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

View File

@@ -84,6 +84,11 @@ require 'php/templates/language/'.$pia_lang_selected.'.php';
<!-- Tell the browser to be responsive to screen width --> <!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- ----------------------------------------------------------------------- -->
<!-- REQUIRED JS SCRIPTS -->
<!-- jQuery 3 -->
<script src="lib/AdminLTE/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 --> <!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="lib/AdminLTE/bower_components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="lib/AdminLTE/bower_components/bootstrap/dist/css/bootstrap.min.css">
@@ -127,30 +132,33 @@ if ($ENABLED_DARKMODE === True) {
$BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/boxed-bg-dark.png\');"'; $BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/boxed-bg-dark.png\');"';
} else { $BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/background.png\');"';} } else { $BACKGROUND_IMAGE_PATCH='style="background-image: url(\'img/background.png\');"';}
?> ?>
<!-- Servertime to the right of the hostname --> <!-- Servertime to the right of the hostname -->
<script> <script>
var pia_servertime = new Date(<?php echo date("Y, n, j, G, i, s") ?>); function updateState(){
getParam("state","Back_App_State")
setTimeout("updateState()", 5000);
}
function show_pia_servertime() { function show_pia_servertime() {
if (!document.getElementById) {
return; // datetime in timeZone in the "en-UK" locale
let time = new Date().toLocaleString("en-UK", { timeZone: "<?php echo $timeZone?>" });
if (document.getElementById) {
document.getElementById("PIA_Servertime_place").innerHTML = '('+time+')';
}
setTimeout("show_pia_servertime()", 1000);
}
document.addEventListener("visibilitychange",()=>{
if(document.visibilityState==="visible"){
window.location.href = window.location.href.split('#')[0];
} }
var pia_hour = pia_servertime.getHours(); })
var pia_minute = pia_servertime.getMinutes();
var pia_second = pia_servertime.getSeconds();
pia_servertime.setSeconds(pia_second + 1);
if (pia_hour <= 9) { pia_hour = "0" + pia_hour; }
if (pia_minute <= 9) { pia_minute = "0" + pia_minute; }
if (pia_second <= 9) { pia_second = "0" + pia_second; } realtime_pia_servertime = "(" + pia_hour + ":" + pia_minute + ":" + pia_second + ")";
if (document.getElementById) { document.getElementById("PIA_Servertime_place").innerHTML = realtime_pia_servertime; } setTimeout("show_pia_servertime()", 1000);
}
document.addEventListener("visibilitychange",()=>{
if(document.visibilityState==="visible"){
window.location.href = window.location.href.split('#')[0];
}
})
</script> </script>
@@ -180,11 +188,12 @@ document.addEventListener("visibilitychange",()=>{
<!-- Sidebar toggle button--> <!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button"> <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
</a> </a>
<!-- Navbar Right Menu --> <!-- Navbar Right Menu -->
<div class="navbar-custom-menu"> <div class="navbar-custom-menu">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<!-- Server Status -->
<li><a onclick="setCache('activeMaintenanceTab', 'tab_Logging_id')" href="/maintenance.php#tab_Logging"><code id="state"></code></a></li>
<!-- Server Name --> <!-- Server Name -->
<li><a style="pointer-events:none;"><?php echo gethostname();?> <span id="PIA_Servertime_place"></span></a></li> <li><a style="pointer-events:none;"><?php echo gethostname();?> <span id="PIA_Servertime_place"></span></a></li>
@@ -297,3 +306,24 @@ document.addEventListener("visibilitychange",()=>{
</section> </section>
<!-- /.sidebar --> <!-- /.sidebar -->
</aside> </aside>
<script defer>
function getParam(targetId, key) {
// get parameter value
$.get('php/server/parameters.php?action=get&parameter='+ key, function(data) {
var result = data;
document.getElementById(targetId).innerHTML = result;
});
}
// Update server time in the header
show_pia_servertime()
// Update server state in the header
updateState()
</script>

View File

@@ -112,7 +112,7 @@ $db->close();
'</div> '</div>
<div class="table_cell setting_input" >'; <div class="table_cell setting_input" >';
// render different input types based on the set type // render different input types based on the settings type
$input = ""; $input = "";
// text - textbox // text - textbox
@@ -271,8 +271,7 @@ $db->close();
{ {
var settingsArray = []; var settingsArray = [];
// generate javascript to collect values // generate javascript to collect values
// multiselect, select, password
<?php <?php
$noConversion = array('text', 'integer', 'password', 'readonly', 'selecttext', 'selectinteger', "multiselect"); $noConversion = array('text', 'integer', 'password', 'readonly', 'selecttext', 'selectinteger', "multiselect");