From 5d5c75dba72248841abcfa788040f773683f6e21 Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Thu, 21 Jul 2022 21:22:39 +0200 Subject: [PATCH 1/8] improve pushsafer support Thanks to Final-Hawk https://github.com/Final-Hawk/Pi.Alert/commit/70b6ccc52382e18ac593b36cbfba92c2ce2486a8 --- back/pialert.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 7fc7ecef..150d340b 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1229,15 +1229,15 @@ def email_reporting (): mail_text = mail_text.replace ('', VERSION_DATE ) mail_html = mail_html.replace ('', VERSION_DATE ) - mail_text = mail_text.replace ('', VERSION_YEAR ) - mail_html = mail_html.replace ('', VERSION_YEAR ) + # mail_text = mail_text.replace ('', VERSION_YEAR ) + # mail_html = mail_html.replace ('', VERSION_YEAR ) # Compose Internet Section print (' Formating report...') mail_section_Internet = False mail_text_Internet = '' mail_html_Internet = '' - text_line_template = ' {} \t{}\t{}\t{}\n' + text_line_template = '{} \t{}\t{}\t{}\n' html_line_template = '\n'+ \ ' {} \n {} \n'+ \ ' {} \n'+ \ @@ -1264,7 +1264,7 @@ def email_reporting (): mail_section_new_devices = False mail_text_new_devices = '' mail_html_new_devices = '' - text_line_template = ' {}\t{}\t{}\t{}\t{}\n' + text_line_template = '{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\n' html_line_template = '\n'+ \ ' {} \n {} \n'+\ ' {} \n {} \n {} \n\n' @@ -1277,9 +1277,8 @@ def email_reporting (): for eventAlert in sql : mail_section_new_devices = True mail_text_new_devices += text_line_template.format ( - eventAlert['eve_MAC'], eventAlert['eve_DateTime'], - eventAlert['eve_IP'], eventAlert['dev_Name'], - eventAlert['eve_AdditionalInfo']) + 'Name: ', eventAlert['dev_Name'], 'MAC: ', eventAlert['eve_MAC'], 'IP: ', eventAlert['eve_IP'], + 'Time: ', eventAlert['eve_DateTime'], 'More Info: ', eventAlert['eve_AdditionalInfo']) mail_html_new_devices += html_line_template.format ( REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'], eventAlert['eve_DateTime'], eventAlert['eve_IP'], @@ -1292,7 +1291,7 @@ def email_reporting (): mail_section_devices_down = False mail_text_devices_down = '' mail_html_devices_down = '' - text_line_template = ' {}\t{}\t{}\t{}\n' + text_line_template = '{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\n' html_line_template = '\n'+ \ ' {} \n {} \n'+ \ ' {} \n {} \n\n' @@ -1305,8 +1304,8 @@ def email_reporting (): for eventAlert in sql : mail_section_devices_down = True mail_text_devices_down += text_line_template.format ( - eventAlert['eve_MAC'], eventAlert['eve_DateTime'], - eventAlert['eve_IP'], eventAlert['dev_Name']) + 'Name: ', eventAlert['dev_Name'], 'MAC: ', eventAlert['eve_MAC'], + 'Time: ', eventAlert['eve_DateTime'],'IP: ', eventAlert['eve_IP']) mail_html_devices_down += html_line_template.format ( REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'], eventAlert['eve_DateTime'], eventAlert['eve_IP'], @@ -1319,7 +1318,7 @@ def email_reporting (): mail_section_events = False mail_text_events = '' mail_html_events = '' - text_line_template = ' {}\t{}\t{}\t{}\t{}\t{}\n' + text_line_template = '{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\t{}\t{}\n\n' html_line_template = '\n '+ \ ' {} \n {} \n'+ \ ' {} \n {} \n {} \n'+ \ @@ -1334,9 +1333,9 @@ def email_reporting (): for eventAlert in sql : mail_section_events = True mail_text_events += text_line_template.format ( - eventAlert['eve_MAC'], eventAlert['eve_DateTime'], - eventAlert['eve_IP'], eventAlert['eve_EventType'], - eventAlert['dev_Name'], eventAlert['eve_AdditionalInfo']) + 'Name: ', eventAlert['dev_Name'], 'MAC: ', eventAlert['eve_MAC'], + 'IP: ', eventAlert['eve_IP'],'Time: ', eventAlert['eve_DateTime'], + 'Event: ', eventAlert['eve_EventType'],'More Info: ', eventAlert['eve_AdditionalInfo']) mail_html_events += html_line_template.format ( REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'], eventAlert['eve_DateTime'], eventAlert['eve_IP'], @@ -1359,13 +1358,14 @@ def email_reporting (): send_email (mail_text, mail_html) else : print (' Skip mail...') + if REPORT_PUSHSAFER : + print (' Sending report by PUSHSAFER...') + send_pushsafer (mail_text) + else : + print (' Skip PUSHSAFER...') else : print (' No changes to report...') - if REPORT_PUSHSAFER : - print (' Sending report by PUSHSAFER...') - send_pushsafer (mail_text) - else : - print (' Skip PUSHSAFER...') + # Clean Pending Alert Events @@ -1388,8 +1388,8 @@ def email_reporting (): def send_pushsafer (_Text): url = 'https://www.pushsafer.com/api' post_fields = { - "t" : 'Pi.Alert Message', - "m" : 'Something has changed', +# "t" : 'Pi.Alert Message', + "m" : _Text, "s" : 11, "v" : 3, "i" : 148, From b855fca9be0346a3f6d497cab2a33226f029b97e Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Thu, 21 Jul 2022 22:31:46 +0200 Subject: [PATCH 2/8] improve pushsafer support - merged commit https://github.com/leiweibau/Pi.Alert/commit/7beec7f584600f13506f21d59154b3205e8b4551 - merged parts of commit https://github.com/Final-Hawk/Pi.Alert/commit/70b6ccc52382e18ac593b36cbfba92c2ce2486a8 - add headline/titel in pushsafer notification --- back/pialert.py | 2 +- back/report_template.html | 38 ++++++++++++++++++-------------------- back/report_template.txt | 20 +++++++------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 150d340b..ebb1dcc5 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1388,7 +1388,7 @@ def email_reporting (): def send_pushsafer (_Text): url = 'https://www.pushsafer.com/api' post_fields = { -# "t" : 'Pi.Alert Message', + "t" : 'Pi.Alert Message', "m" : _Text, "s" : 11, "v" : 3, diff --git a/back/report_template.html b/back/report_template.html index 0bc0ecc0..e6b340ad 100644 --- a/back/report_template.html +++ b/back/report_template.html @@ -14,20 +14,19 @@ - +
- @@ -36,9 +35,9 @@
+ Pi.Alert Report
- - - - - +
Report Date: Scan Cycle: Server:
+ + +
Report Date: Scan Cycle:
-

Internet:

+

Internet:

- +
@@ -53,11 +52,11 @@ -

New Devices:

+

New Devices:

-
Event Type Datetime
+
- + @@ -71,9 +70,9 @@ -

Devices Down:

+

Devices Down:

-
MAC MAC Datetime IP Device Name
+
@@ -88,9 +87,9 @@ -

Events:

+

Events:

-
MAC Datetime
+
@@ -108,11 +107,10 @@ @@ -120,4 +118,4 @@
MAC Datetime
- +
- + -
© Puche Pi.Alert - Pi.Alert     () GNU GPLv3
- + \ No newline at end of file diff --git a/back/report_template.txt b/back/report_template.txt index 0d777f57..9a2d72e3 100644 --- a/back/report_template.txt +++ b/back/report_template.txt @@ -1,27 +1,21 @@ -======================================== - Pi.Alert Report -======================================== - - Report Date: - Scan Cycle: - Server: +Report Date: +Scan Cycle: +Server: Internet ----------------------------------------------------------------------- +---------------------- New Devices ----------------------------------------------------------------------- +---------------------- Devices Down ----------------------------------------------------------------------- +---------------------- Events ----------------------------------------------------------------------- +---------------------- ----------------------------------------------------------------------- -(?) Puche Pi.Alert () GNU GPLv3 From fec58bf028b0fa07039e2eb732c2e925f1c57eff Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Fri, 22 Jul 2022 21:21:43 +0200 Subject: [PATCH 3/8] Basic Login - Default password is "123456" - there is a warning on the login page, when the default password is active - to set ne new password, use the reset_password.sh in the config folder (./reset_password.sh newpassword) - the password is stored as a sha256 hash - the script creates a backup of the config file, just in case --- config/pialert.conf | 1 + config/reset_password.sh | 7 ++ front/deviceDetails.php | 8 ++ front/devices.php | 8 ++ front/events.php | 8 ++ front/index.php | 137 ++++++++++++++++++++++++++++++++- front/maintenance.php | 8 ++ front/php/templates/header.php | 28 ++----- front/presence.php | 8 ++ 9 files changed, 188 insertions(+), 25 deletions(-) create mode 100644 config/reset_password.sh diff --git a/config/pialert.conf b/config/pialert.conf index d58f0f3d..8b9628e0 100644 --- a/config/pialert.conf +++ b/config/pialert.conf @@ -12,6 +12,7 @@ DB_PATH = PIALERT_PATH + '/db/pialert.db' LOG_PATH = PIALERT_PATH + '/log' VENDORS_DB = '/usr/share/arp-scan/ieee-oui.txt' PRINT_LOG = False +PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92' SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 diff --git a/config/reset_password.sh b/config/reset_password.sh new file mode 100644 index 00000000..a7f933ee --- /dev/null +++ b/config/reset_password.sh @@ -0,0 +1,7 @@ +cp pialert.conf pialert.conf.bak +PIA_PASS=$1 +echo "The password '$1' is hashed" +PIA_PASS_HASH=$(echo -n $PIA_PASS | sha256sum | awk '{print $1}') +echo "The hashed password is: $PIA_PASS_HASH" +sed -i "/PIALERT_WEB_PASSWORD/c\PIALERT_WEB_PASSWORD = '$PIA_PASS_HASH'" pialert.conf +echo "The hash was saved in the configuration file" \ No newline at end of file diff --git a/front/deviceDetails.php b/front/deviceDetails.php index b5b11762..aefd7542 100644 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -8,6 +8,14 @@ #--------------------------------------------------------------------------- --> diff --git a/front/devices.php b/front/devices.php index dcdea723..f0033d05 100644 --- a/front/devices.php +++ b/front/devices.php @@ -8,6 +8,14 @@ #--------------------------------------------------------------------------- --> diff --git a/front/events.php b/front/events.php index 0655c08a..597cca30 100644 --- a/front/events.php +++ b/front/events.php @@ -8,6 +8,14 @@ #--------------------------------------------------------------------------- --> diff --git a/front/index.php b/front/index.php index a1338922..6c4a1c74 100644 --- a/front/index.php +++ b/front/index.php @@ -1,5 +1,136 @@ + + + + + + + + + + Pi-Alert | Log in + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/front/maintenance.php b/front/maintenance.php index a78abd09..d65f5fad 100644 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -1,4 +1,12 @@ diff --git a/front/presence.php b/front/presence.php index 5ab20310..0f2b61ab 100644 --- a/front/presence.php +++ b/front/presence.php @@ -8,6 +8,14 @@ #--------------------------------------------------------------------------- --> From f372529cdba9a7192f632721f3e4d89f5ace3109 Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Fri, 22 Jul 2022 21:43:27 +0200 Subject: [PATCH 4/8] support for Gotify from https://github.com/Haecky/Pi.Alert-TLS.On-Off merge Commit https://github.com/Haecky/Pi.Alert-TLS.On-Off/commit/b5cd865a27541e0fcbcff9d4d72d7ae8b9ffe386 merge Commit https://github.com/Haecky/Pi.Alert-TLS.On-Off/commit/4e61e2ee45b2054375f884389f141b77853206dc --- back/pialert.py | 26 ++++++++++++++++++-------- config/pialert.conf | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index ebb1dcc5..7b8308f7 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -458,7 +458,7 @@ def execute_arpscan (pRetries): # arp-scan for larger Networks like /16 # otherwise the system starts multiple processes. the 15min cronjob isn't necessary. # the scan is about 4min on a /16 network - arpscan_args = ['sudo', 'arp-scan', '--ignoredups', '--bandwidth=512k', '--retry=2', SCAN_SUBNETS] + arpscan_args = ['sudo', 'arp-scan', '--ignoredups', '--bandwidth=512k', '--retry=3', SCAN_SUBNETS] # Default arp-scan # arpscan_args = ['sudo', 'arp-scan', SCAN_SUBNETS, '--ignoredups', '--retry=' + str(pRetries)] @@ -1223,11 +1223,11 @@ def email_reporting (): mail_text = mail_text.replace ('', socket.gethostname() ) mail_html = mail_html.replace ('', socket.gethostname() ) - mail_text = mail_text.replace ('', VERSION ) - mail_html = mail_html.replace ('', VERSION ) + # mail_text = mail_text.replace ('', VERSION ) + # mail_html = mail_html.replace ('', VERSION ) - mail_text = mail_text.replace ('', VERSION_DATE ) - mail_html = mail_html.replace ('', VERSION_DATE ) + # mail_text = mail_text.replace ('', VERSION_DATE ) + # mail_html = mail_html.replace ('', VERSION_DATE ) # mail_text = mail_text.replace ('', VERSION_YEAR ) # mail_html = mail_html.replace ('', VERSION_YEAR ) @@ -1474,12 +1474,22 @@ def send_email (pText, pHTML): # Send mail smtp_connection = smtplib.SMTP (SMTP_SERVER, SMTP_PORT) smtp_connection.ehlo() - smtp_connection.starttls() - smtp_connection.ehlo() - smtp_connection.login (SMTP_USER, SMTP_PASS) +# smtp_connection.starttls() +# smtp_connection.ehlo() +# smtp_connection.login (SMTP_USER, SMTP_PASS) + if not SafeParseGlobalBool("SMTP_SKIP_TLS"): + smtp_connection.starttls() + smtp_connection.ehlo() + if not SafeParseGlobalBool("SMTP_SKIP_LOGIN"): + smtp_connection.login (SMTP_USER, SMTP_PASS) smtp_connection.sendmail (REPORT_FROM, REPORT_TO, msg.as_string()) smtp_connection.quit() +#------------------------------------------------------------------------------- +def SafeParseGlobalBool(boolVariable): + if boolVariable in globals(): + return eval(boolVariable) + return False #=============================================================================== # DB diff --git a/config/pialert.conf b/config/pialert.conf index 8b9628e0..7c6f8043 100644 --- a/config/pialert.conf +++ b/config/pialert.conf @@ -18,6 +18,8 @@ SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 SMTP_USER = 'user@gmail.com' SMTP_PASS = 'password' +SMTP_SKIP_TLS = False +SMTP_SKIP_LOGIN = False REPORT_MAIL = False REPORT_FROM = 'Pi.Alert <' + SMTP_USER +'>' From 0b3ba217764edcc40a709fa7fa2d214a3113e7d3 Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Fri, 22 Jul 2022 23:35:45 +0200 Subject: [PATCH 5/8] Translation work continued - maintenance page (tab titel) --- front/maintenance.php | 6 +++--- front/php/templates/language/de_de.php | 3 +++ front/php/templates/language/en_us.php | 3 +++ front/php/templates/language/es_es.php | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/front/maintenance.php b/front/maintenance.php index d65f5fad..b43ffdfa 100644 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -217,9 +217,9 @@ if (submit && isset($_POST['langselector_set'])) {