diff --git a/back/pialert.py b/back/pialert.py index c6541a3d..8653638f 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -335,7 +335,7 @@ def importConfig (): PUSHSAFER_TOKEN = ccd('PUSHSAFER_TOKEN', 'ApiKey' , c_d, 'PUSHSAFER token', 'text', '', 'PUSHSAFER') # MQTT - REPORT_MQTT = ccd('REPORT_MQTT', False , c_d, 'Enable MQTT', 'boolean', '', 'MQTT', ['test']) + REPORT_MQTT = ccd('REPORT_MQTT', False , c_d, 'Enable MQTT', 'boolean', '', 'MQTT') MQTT_BROKER = ccd('MQTT_BROKER', '' , c_d, 'MQTT broker', 'text', '', 'MQTT') MQTT_PORT = ccd('MQTT_PORT', 1883 , c_d, 'MQTT broker port', 'integer', '', 'MQTT') MQTT_USER = ccd('MQTT_USER', '' , c_d, 'MQTT user', 'text', '', 'MQTT') @@ -2423,7 +2423,7 @@ def send_webhook (_json, _html): if WEBHOOK_PAYLOAD == 'text': payloadData = to_text(_json) - #Define slack-compatible payload + # Define slack-compatible payload _json_payload = { "text": payloadData } if WEBHOOK_PAYLOAD == 'text' else { "username": "Pi.Alert", "text": "There are new notifications", @@ -2767,7 +2767,7 @@ def upgradeDB (): ('Back_Settings_Imported', round(time.time() * 1000)), ('Back_App_State', 'Initializing'), ('Back_New_Version_Available', False), - ('Front_Event', 'none') + ('Front_Event', 'finished') ] sql.executemany ("""INSERT INTO Parameters ("par_ID", "par_Value") VALUES (?, ?)""", params) @@ -2905,6 +2905,15 @@ def checkIPV4(ip): else: return False +#------------------------------------------------------------------------------- +def get_file_content(path): + + f = open(path, 'r') + content = f.read() + f.close() + + return content + #------------------------------------------------------------------------------- def updateSubnets(): @@ -3023,7 +3032,7 @@ def check_and_run_event(): rows = sql.fetchall() event, param = ['',''] - if len(rows) > 0 and rows[0]['par_Value'] != 'none': + if len(rows) > 0 and rows[0]['par_Value'] != 'finished': event = rows[0]['par_Value'].split('|')[0] param = rows[0]['par_Value'].split('|')[1] else: @@ -3033,31 +3042,38 @@ def check_and_run_event(): handle_test(param) # clear event execution flag - sql.execute ("UPDATE Parameters SET par_Value='none' WHERE par_ID='Front_Event'") + sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'") # commit to DB commitDB () #------------------------------------------------------------------------------- def handle_test(testType): - if testType == 'REPORT_MAIL': - test_email() -#------------------------------------------------------------------------------- -def test_email(): + file_print('[', timeNow(), '] START Test: ', testType) - # Open text Template - template_file = open(pialertPath + '/back/report_sample_1.txt', 'r') - mail_text_txt = template_file.read() - template_file.close() + # Open text sample + sample_txt = get_file_content(pialertPath + '/back/report_sample_1.txt') - # Open html Template - template_file = open(pialertPath + '/back/report_sample_2.html', 'r') - mail_text_html = template_file.read() - template_file.close() + # Open html sample + sample_html = get_file_content(pialertPath + '/back/report_sample_2.html') - send_email(mail_text_txt, mail_text_html) + # Open json sample and get only the payload part + sample_json_payload = json.loads(get_file_content(pialertPath + '/back/webhook_json_sample.json'))[0]["body"]["attachments"][0]["text"] + if testType == 'REPORT_MAIL': + send_email(sample_txt, sample_html) + if testType == 'REPORT_WEBHOOK': + send_webhook (sample_json_payload, sample_txt) + if testType == 'REPORT_APPRISE': + send_apprise (sample_html) + if testType == 'REPORT_NTFY': + send_ntfy (sample_txt) + if testType == 'REPORT_PUSHSAFER': + send_pushsafer (sample_txt) + + file_print('[', timeNow(), '] END Test: ', testType) + #------------------------------------------------------------------------------- def isNewVersion(): diff --git a/docker-compose.yml b/docker-compose.yml index 71e426aa..9a1a0286 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,9 @@ services: network_mode: "host" restart: unless-stopped volumes: - - ${APP_DATA_LOCATION}/pialert/config2:/home/pi/pialert/config + - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config # - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db - - ${APP_DATA_LOCATION}/pialert/db2:/home/pi/pialert/db + - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db # (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt - ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode # (optional) useful for debugging if you have issues setting up the container diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index 7f417ede..0b6c988d 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -430,6 +430,17 @@ $lang['en_us'] = array( 'HelpFAQ_Cat_Network_600_text' => 'This page should offer you the possibility to map the assignment of your network devices. For this purpose, you can create one or more switches, WLANs, routers, etc., provide them with a port number if necessary and assign already detected devices to them. This assignment is done in the detailed view of the device to be assigned. So it is possible for you to quickly determine to which port a host is connected and if it is online.', +////////////////////////////////////////////////////////////////// +// Front end events +////////////////////////////////////////////////////////////////// + +'test_event_tooltip' => 'Save your changes at first before you test your settings.', +'test_event_icon' => 'fa-vial-circle-check', +'general_event_title' => 'Executing an ad-hoc event', +'general_event_description' => 'The event you\'ve triggered might take a while until background processes finish. The execution ended once you see finished below. Check the error log if you didn\'t get the expected result.

Status: ', + + + ////////////////////////////////////////////////////////////////// // Settings ////////////////////////////////////////////////////////////////// @@ -441,6 +452,7 @@ $lang['en_us'] = array( 'settings_imported' => 'Last time settings were imported from the pialert.conf file:', 'settings_expand_all' => 'Expand all', + //General 'ENABLE_ARPSCAN_name' => 'Enable ARP scan', 'ENABLE_ARPSCAN_description' => 'Arp-scan is a command-line tool that uses the ARP protocol to discover and fingerprint IP hosts on the local network. An alternative to ARP scan is to enable the PIHOLE_ACTIVEPiHole integration settings.', diff --git a/front/settings.php b/front/settings.php index 194481cb..6e7a6b37 100644 --- a/front/settings.php +++ b/front/settings.php @@ -82,7 +82,7 @@ CommitDB();

'.$group.'

-
+
'; $isIn = ' '; // open the first panel only by default on page load @@ -234,20 +234,22 @@ CommitDB(); // render any buttons or additional actions if specified $eventsHtml = ""; - - // displayMessage($set['Events'], FALSE, TRUE, TRUE, TRUE); - + // if available get all the events associated with this setting $eventsList = createArray($set['Events']); - $iconMap = [ - "test" => ["To test this configuration you have to save it at first.","fa-vial-circle-check"] - ]; + // icon map for the events + // $iconMap = [ + // "test" => [lang("settings_event_tooltip"),""] + // ]; if(count($eventsList) > 0) { foreach ($eventsList as $event) { $eventsHtml = $eventsHtml.' - + + '; } } @@ -384,8 +386,8 @@ CommitDB(); } } - // --------------------------------------------------------- - function getParam(targetId, key, skipCache = false, callback) { + // --------------------------------------------------------- + function getParam(targetId, key, skipCache = false) { skipCacheQuery = ""; @@ -395,9 +397,9 @@ CommitDB(); } // get parameter value - $.get('php/server/parameters.php?action=get¶meter='+ key + skipCacheQuery, function(data, callback) { + $.get('php/server/parameters.php?action=get¶meter='+ key + skipCacheQuery, function(data) { - var result = data; + var result = data; if(key == "Back_Settings_Imported") { @@ -415,8 +417,7 @@ CommitDB(); result = result.replaceAll('"', ''); } - document.getElementById(targetId).innerHTML = result; - + document.getElementById(targetId).innerHTML = result.replaceAll('"', ''); }); } @@ -427,7 +428,7 @@ CommitDB(); inStr = ' in'; allOpen = true; openIcon = 'fa-angle-double-down'; - closeIcon = 'fa-angle-double-up'; + closeIcon = 'fa-angle-double-up'; $('.panel-collapse').each(function(){ if($(this).attr('class').indexOf(inStr) == -1) @@ -435,16 +436,17 @@ CommitDB(); allOpen = false; } }) - + if(allOpen) { // close all - $('.panel-collapse').each(function(){$(this).attr('class', 'panel-collapse collapse ')}) + $('div[data-myid="collapsible"]').each(function(){$(this).attr('class', 'panel-collapse collapse ')}) $('#toggleSettings').attr('class', $('#toggleSettings').attr('class').replace(closeIcon, openIcon)) } else{ // open all - $('.panel-collapse').each(function(){$(this).attr('class', 'panel-collapse collapse in')}) + $('div[data-myid="collapsible"]').each(function(){$(this).attr('class', 'panel-collapse collapse in')}) + $('div[data-myid="collapsible"]').each(function(){$(this).attr('style', 'height:inherit')}) $('#toggleSettings').attr('class', $('#toggleSettings').attr('class').replace(openIcon, closeIcon)) } @@ -465,11 +467,44 @@ CommitDB(); }); }); - function handleEvent (value){ + modalEventStatusId = 'modal-message-front-event' + function handleEvent (value){ setParameter ('Front_Event', value) + // console.log(value) + + // show message + showModalOk("", " "); + + // Periodically update state of the requested action + getParam(modalEventStatusId,"Front_Event", true, updateModalState) + + updateModalState() } + + + function updateModalState(){ + + setTimeout(function(){ + displayedEvent = $('#'+modalEventStatusId).html() + + // console.log(displayedEvent) + // console.log(displayedEvent.indexOf('finished') == -1) + + // loop until finished + if(displayedEvent.indexOf('finished') == -1) // if the message is different from finished, check again in 4s + { + + getParam(modalEventStatusId,"Front_Event", true) + + updateModalState() + + } + }, 2000); + } + + // ----------------------------------------------------------------------------- // handling events on the backend initiated by the front end END // -----------------------------------------------------------------------------