Txt message cleanup

This commit is contained in:
Jokob-sk
2023-02-01 21:46:59 +11:00
parent eec0dcca82
commit 4d67c25e5a
4 changed files with 41 additions and 18 deletions

View File

@@ -308,7 +308,7 @@ def importConfig ():
# Import setting if found in the dictionary # Import setting if found in the dictionary
# General # General
ENABLE_ARPSCAN = ccd('ENABLE_ARPSCAN', True , c_d, 'Enable arpscan', 'boolean', '', 'General') ENABLE_ARPSCAN = ccd('ENABLE_ARPSCAN', True , c_d, 'Enable arpscan', 'boolean', '', 'General', ['run'])
SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', 'subnets', '', 'General') SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', 'subnets', '', 'General')
PRINT_LOG = ccd('PRINT_LOG', False , c_d, 'Print additional logging', 'boolean', '', 'General') PRINT_LOG = ccd('PRINT_LOG', False , c_d, 'Print additional logging', 'boolean', '', 'General')
TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General') TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General')
@@ -1030,7 +1030,7 @@ def scan_network ():
return reporting return reporting
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def query_ScanCycle_Data (pOpenCloseDB = False): def query_ScanCycle_Data (pOpenCloseDB = False, cycle = 1):
# Query Data # Query Data
sql.execute ("""SELECT cic_arpscanCycles, cic_EveryXmin sql.execute ("""SELECT cic_arpscanCycles, cic_EveryXmin
FROM ScanCycles FROM ScanCycles
@@ -2251,8 +2251,12 @@ def send_notifications ():
notiStruc = construct_notifications("", "Ports", True, changedPorts_json_struc) notiStruc = construct_notifications("", "Ports", True, changedPorts_json_struc)
mail_html = mail_html.replace ('<PORTS_TABLE>', notiStruc.html) mail_html = mail_html.replace ('<PORTS_TABLE>', notiStruc.html)
# mail_text = mail_text.replace ('<PORTS_TABLE>', notiStruc.text + '\n')
mail_text = mail_text.replace ('<PORTS_TABLE>', "Ports changed! Check PiAlert for details!" + '\n') portsTxt = ""
if changedPorts_json_struc is not None:
portsTxt = "Ports \n---------\n Ports changed! Check PiAlert for details!\n"
mail_text = mail_text.replace ('<PORTS_TABLE>', portsTxt )
json_final = { json_final = {
"internet": json_internet, "internet": json_internet,
@@ -2262,6 +2266,8 @@ def send_notifications ():
"ports": json_ports, "ports": json_ports,
} }
mail_text = removeDuplicateNewLines(mail_text)
# Create clickable MAC links # Create clickable MAC links
mail_html = generate_mac_links (mail_html, deviceUrl) mail_html = generate_mac_links (mail_html, deviceUrl)
@@ -2355,6 +2361,7 @@ def construct_notifications(sqlQuery, tableTitle, skipText = False, suppliedJson
text = "" text = ""
if json["data"] != []: if json["data"] != []:
text = tableTitle + "\n---------\n"
html = convert(json, build_direction=build_direction, table_attributes=table_attributes) html = convert(json, build_direction=build_direction, table_attributes=table_attributes)
@@ -3158,6 +3165,8 @@ def write_file (pPath, pText):
file.close() file.close()
else: else:
file = open (pPath, 'w', encoding='utf-8') file = open (pPath, 'w', encoding='utf-8')
if pText is None:
pText = ""
file.write (pText) file.write (pText)
file.close() file.close()
@@ -3304,6 +3313,14 @@ def get_all_devices():
return row return row
#-------------------------------------------------------------------------------
def removeDuplicateNewLines(text):
if "\n\n" in text:
return removeDuplicateNewLines(text.replace("\n\n\n", "\n\n"))
else:
return text
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def hide_email(email): def hide_email(email):
m = email.split('@') m = email.split('@')
@@ -3327,6 +3344,8 @@ def check_and_run_event():
if event == 'test': if event == 'test':
handle_test(param) handle_test(param)
if event == 'run':
handle_run(param)
# clear event execution flag # clear event execution flag
sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'") sql.execute ("UPDATE Parameters SET par_Value='finished' WHERE par_ID='Front_Event'")
@@ -3334,6 +3353,17 @@ def check_and_run_event():
# commit to DB # commit to DB
commitDB () commitDB ()
#-------------------------------------------------------------------------------
def handle_run(runType):
global last_network_scan
file_print('[', timeNow(), '] START Run: ', runType)
if runType == 'ENABLE_ARPSCAN':
last_network_scan = now_minus_24h
file_print('[', timeNow(), '] END Run: ', runType)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def handle_test(testType): def handle_test(testType):

View File

@@ -1,18 +1,8 @@
Report Date: <REPORT_DATE> Report Date: <REPORT_DATE>
Server: <SERVER_NAME> Server: <SERVER_NAME>
New Devices
----------------------
<SECTION_NEW_DEVICES> <SECTION_NEW_DEVICES>
Devices Down
----------------------
<SECTION_DEVICES_DOWN> <SECTION_DEVICES_DOWN>
Events
----------------------
<SECTION_EVENTS> <SECTION_EVENTS>
Internet
----------------------
<SECTION_INTERNET> <SECTION_INTERNET>
Ports
----------------------
<PORTS_TABLE> <PORTS_TABLE>

View File

@@ -462,6 +462,8 @@ $lang['en_us'] = array(
'test_event_tooltip' => 'Save your changes at first before you test your settings.', 'test_event_tooltip' => 'Save your changes at first before you test your settings.',
'test_event_icon' => 'fa-vial-circle-check', 'test_event_icon' => 'fa-vial-circle-check',
'run_event_tooltip' => 'Enable the setting and save your changes at first before you run it.',
'run_event_icon' => 'fa-play',
'general_event_title' => 'Executing an ad-hoc event', '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 <code>finished</code> below. Check the <a onclick=\'setCache(\"activeMaintenanceTab\", \"tab_Logging_id\")\' href=\"/maintenance.php#tab_Logging\">error log</a> if you didn\'t get the expected result. <br/> <br/> Status: ', 'general_event_description' => 'The event you\'ve triggered might take a while until background processes finish. The execution ended once you see <code>finished</code> below. Check the <a onclick=\'setCache(\"activeMaintenanceTab\", \"tab_Logging_id\")\' href=\"/maintenance.php#tab_Logging\">error log</a> if you didn\'t get the expected result. <br/> <br/> Status: ',

View File

@@ -238,10 +238,11 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
if(count($eventsList) > 0) if(count($eventsList) > 0)
{ {
foreach ($eventsList as $event) { foreach ($eventsList as $event) {
$eventsHtml = $eventsHtml.'<span class="input-group-addon"> $eventsHtml = $eventsHtml.'<span class="input-group-addon pointer"
<i title="'.lang($event."_event_tooltip").'" class="fa '.lang($event."_event_icon").' pointer"
data-myparam="'.$set['Code_Name'].'" data-myparam="'.$set['Code_Name'].'"
data-myevent="'.$event.'"> data-myevent="'.$event.'"
>
<i title="'.lang($event."_event_tooltip").'" class="fa '.lang($event."_event_icon").' " >
</i> </i>
</span>'; </span>';
} }
@@ -451,7 +452,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// handling events on the backend initiated by the front end START // handling events on the backend initiated by the front end START
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
$(window).on('load', function() { $(window).on('load', function() {
$('i[data-myevent]').each(function(index, element){ $('span[data-myevent]').each(function(index, element){
$(element).attr('onclick', $(element).attr('onclick',
'handleEvent(\"' + $(element).attr('data-myevent') + '|'+ $(element).attr('data-myparam') + '\")' 'handleEvent(\"' + $(element).attr('data-myevent') + '|'+ $(element).attr('data-myparam') + '\")'
); );