From 120b24620ba81de27878e0b18ca09b626dcf3593 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 09:08:29 +1000 Subject: [PATCH 01/12] Beta: Fix Timezone issues --- Dockerfile | 1 + config/version.conf | 3 +-- front/php/server/db.php | 9 ++++++++- front/php/server/devices.php | 4 +++- front/php/server/events.php | 2 +- front/php/server/util.php | 7 +++++++ 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd17f6c6..fc8df2a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ + && sed -i.bak 's/^\(TIMEZONE=\).*/\'${TZ}'/' /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually diff --git a/config/version.conf b/config/version.conf index 7110989f..5dc33c9d 100644 --- a/config/version.conf +++ b/config/version.conf @@ -1,4 +1,3 @@ VERSION = '3.5_leiweibau' VERSION_YEAR = '2022' -VERSION_DATE = '2022-07-07' -TZ = 'Europe/London' \ No newline at end of file +VERSION_DATE = '2022-07-07' \ No newline at end of file diff --git a/front/php/server/db.php b/front/php/server/db.php index c54f5e79..4bc80da8 100644 --- a/front/php/server/db.php +++ b/front/php/server/db.php @@ -8,6 +8,13 @@ // Puche 2021 pi.alert.application@gmail.com GNU GPLv3 //------------------------------------------------------------------------------ +// ## TimeZone processing +$config_file = "../config/pialert.conf"; +$config_file_lines = file($config_file); +$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); +$timezone_line = explode("'", $config_file_lines_timezone[0]); +$Pia_TimeZone = $timezone_line[1]; +date_default_timezone_set($Pia_TimeZone); //------------------------------------------------------------------------------ // DB File Path @@ -58,4 +65,4 @@ function OpenDB () { } } -?> +?> \ No newline at end of file diff --git a/front/php/server/devices.php b/front/php/server/devices.php index 2be29ee7..5bd7073f 100644 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -116,8 +116,10 @@ function getDeviceData() { $row = $result -> fetchArray (SQLITE3_NUM); $deviceData['dev_DownAlerts'] = $row[0]; + // Get current date using php, sql datetime does not return time respective to timezone. + $currentdate = date("Y-m-d H:i:s"); // Presence hours - $sql = 'SELECT CAST(( MAX (0, SUM (julianday (IFNULL (ses_DateTimeDisconnection, DATETIME("now","localtime"))) + $sql = 'SELECT CAST(( MAX (0, SUM (julianday (IFNULL (ses_DateTimeDisconnection,"'. $currentdate .'" )) - julianday (CASE WHEN ses_DateTimeConnection < '. $periodDate .' THEN '. $periodDate .' ELSE ses_DateTimeConnection END)) *24 )) AS INT) FROM Sessions diff --git a/front/php/server/events.php b/front/php/server/events.php index 1e927ecc..df7a4b08 100644 --- a/front/php/server/events.php +++ b/front/php/server/events.php @@ -275,7 +275,7 @@ function getDevicePresence() { END AS ses_DateTimeConnectionCorrected, CASE - WHEN ses_EventTypeDisconnection = "" THEN + WHEN ses_EventTypeDisconnection = "" OR ses_EventTypeDisconnection = NULL THEN (SELECT MIN(ses_DateTimeConnection) FROM Sessions AS SES2 WHERE SES2.ses_MAC = SES1.ses_MAC AND SES2.ses_DateTimeConnection > SES1.ses_DateTimeConnection) ELSE ses_DateTimeDisconnection END AS ses_DateTimeDisconnectionCorrected diff --git a/front/php/server/util.php b/front/php/server/util.php index a4f345f3..ee4f8370 100644 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -8,6 +8,13 @@ // Puche 2021 pi.alert.application@gmail.com GNU GPLv3 //------------------------------------------------------------------------------ +// ## TimeZone processing +$config_file = "../config/pialert.conf"; +$config_file_lines = file($config_file); +$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); +$timezone_line = explode("'", $config_file_lines_timezone[0]); +$Pia_TimeZone = $timezone_line[1]; +date_default_timezone_set($Pia_TimeZone); //------------------------------------------------------------------------------ // Formatting data functions From 623e68480c86e805e53e01b1d6fdee2af8e4c541 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 09:18:20 +1000 Subject: [PATCH 02/12] Fix Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fc8df2a6..81c8ff47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed -i.bak 's/^\(TIMEZONE=\).*/\'${TZ}'/' /home/pi/pialert/config/pialert.conf \ + && sed -i.bak 's/^\(TIMEZONE=\).*/\ '${TZ}'/' /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From f37da64d435752706cd33d3bed4221fe502419ef Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 09:29:53 +1000 Subject: [PATCH 03/12] Fix Dockerfile again --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 81c8ff47..e86ff176 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed -i.bak 's/^\(TIMEZONE=\).*/\ '${TZ}'/' /home/pi/pialert/config/pialert.conf \ + && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='\'${TZ}\''/' /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From 24c74ebf8674577364554b0bbddf95f54247c2eb Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 09:42:53 +1000 Subject: [PATCH 04/12] try to fix dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e86ff176..a214725c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='\'${TZ}\''/' /home/pi/pialert/config/pialert.conf \ + && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='${TZ}'/' /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From 34bc3bd60d47a80e100b8f80645cca7dfbd190f6 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 09:47:15 +1000 Subject: [PATCH 05/12] remove line --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a214725c..1685fe7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='${TZ}'/' /home/pi/pialert/config/pialert.conf \ + # && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='${TZ}'/' /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From ebb754088ba02d4c80c3915135d5ef98fbd71e65 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 13:34:12 +1000 Subject: [PATCH 06/12] Fix incorrect config path --- front/php/server/db.php | 2 +- front/php/server/util.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/front/php/server/db.php b/front/php/server/db.php index 4bc80da8..d4458bc6 100644 --- a/front/php/server/db.php +++ b/front/php/server/db.php @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ // ## TimeZone processing -$config_file = "../config/pialert.conf"; +$config_file = "../../../config/pialert.conf"; $config_file_lines = file($config_file); $config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); $timezone_line = explode("'", $config_file_lines_timezone[0]); diff --git a/front/php/server/util.php b/front/php/server/util.php index ee4f8370..0869214d 100644 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ // ## TimeZone processing -$config_file = "../config/pialert.conf"; +$config_file = "../../../config/pialert.conf"; $config_file_lines = file($config_file); $config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); $timezone_line = explode("'", $config_file_lines_timezone[0]); From 6586a56e1079ec3eaf004ff17e279a44e1fbf2a0 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 14:25:17 +1000 Subject: [PATCH 07/12] Dockerfile Pass Timezone --- Dockerfile | 2 +- front/php/server/devices.php | 7 +++++++ front/php/server/events.php | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1685fe7e..a7013e1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - # && sed -i.bak 's/^TIMEZONE=.*/TIMEZONE='${TZ}'/' /home/pi/pialert/config/pialert.conf \ + sed "s+TIMEZONE.*+TIMEZONE = '" ${TZ} "'+" /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually diff --git a/front/php/server/devices.php b/front/php/server/devices.php index 5bd7073f..8b55d3ac 100644 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -7,6 +7,13 @@ //------------------------------------------------------------------------------ // Puche 2021 pi.alert.application@gmail.com GNU GPLv3 //------------------------------------------------------------------------------ +// ## TimeZone processing +$config_file = "../../../config/pialert.conf"; +$config_file_lines = file($config_file); +$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); +$timezone_line = explode("'", $config_file_lines_timezone[0]); +$Pia_TimeZone = $timezone_line[1]; +date_default_timezone_set($Pia_TimeZone); foreach (glob("../../../db/setting_language*") as $filename) { $pia_lang_selected = str_replace('setting_language_','',basename($filename)); diff --git a/front/php/server/events.php b/front/php/server/events.php index df7a4b08..28b714e7 100644 --- a/front/php/server/events.php +++ b/front/php/server/events.php @@ -7,7 +7,13 @@ //------------------------------------------------------------------------------ // Puche 2021 pi.alert.application@gmail.com GNU GPLv3 //------------------------------------------------------------------------------ - +// ## TimeZone processing +$config_file = "../../../config/pialert.conf"; +$config_file_lines = file($config_file); +$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines)); +$timezone_line = explode("'", $config_file_lines_timezone[0]); +$Pia_TimeZone = $timezone_line[1]; +date_default_timezone_set($Pia_TimeZone); //------------------------------------------------------------------------------ // External files From a55d02de5e426fa19d2e1565fc200709808ee6b2 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 14:27:43 +1000 Subject: [PATCH 08/12] Fix Dockerfile error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a7013e1e..2cef8aa7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ COPY . /home/pi/pialert # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - sed "s+TIMEZONE.*+TIMEZONE = '" ${TZ} "'+" /home/pi/pialert/config/pialert.conf \ + && sed "s+TIMEZONE.*+TIMEZONE = '" ${TZ} "'+" /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From 58db58e178245daff52528614f2357aeeec2dab4 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 14:52:17 +1000 Subject: [PATCH 09/12] try to fix docker --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2cef8aa7..4f0c15c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,10 +28,12 @@ RUN groupadd --gid "${USER_GID}" "${USER}" && \ COPY . /home/pi/pialert +RUN chmod -R a+rxw /home/pi/pialert/ + # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed "s+TIMEZONE.*+TIMEZONE = '" ${TZ} "'+" /home/pi/pialert/config/pialert.conf \ + && sed "s+TIMEZONE.*+TIMEZONE = '"${TZ}"'+" /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From 5b783ebff915b77b4933ebce2187c81d0077c7ee Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 27 Jul 2022 15:01:35 +1000 Subject: [PATCH 10/12] Revert dockerfile changes --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f0c15c0..cd17f6c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,12 +28,9 @@ RUN groupadd --gid "${USER_GID}" "${USER}" && \ COPY . /home/pi/pialert -RUN chmod -R a+rxw /home/pi/pialert/ - # Pi.Alert RUN python /home/pi/pialert/back/pialert.py update_vendors \ && sed -ie 's/= 80/= '${PORT}'/g' /etc/lighttpd/lighttpd.conf \ - && sed "s+TIMEZONE.*+TIMEZONE = '"${TZ}"'+" /home/pi/pialert/config/pialert.conf \ && (crontab -l 2>/dev/null; cat /home/pi/pialert/install/pialert.cron) | crontab - # it's easy for permissions set in Git to be overridden, so doing it manually From 5e98961faafc17df2b43014776c1277db64bd99a Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 29 Jul 2022 21:03:01 +1000 Subject: [PATCH 11/12] Fix down alerts and improve txt template --- back/pialert.py | 5 +++++ back/report_template.txt | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index fcbe2933..d2376399 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1184,6 +1184,11 @@ def email_reporting (): ( SELECT dev_MAC FROM Devices WHERE dev_AlertEvents = 0 )""") + sql.execute ("""UPDATE Events SET eve_PendingAlertEmail = 0 + WHERE eve_PendingAlertEmail = 1 AND eve_EventType = 'Device Down' AND eve_MAC IN + ( + SELECT dev_MAC FROM Devices WHERE dev_AlertDeviceDown = 0 + )""") # Open text Template template_file = open(PIALERT_BACK_PATH + '/report_template.txt', 'r') diff --git a/back/report_template.txt b/back/report_template.txt index 9a2d72e3..9f5ebdad 100644 --- a/back/report_template.txt +++ b/back/report_template.txt @@ -1,12 +1,6 @@ Report Date: -Scan Cycle: Server: - - -Internet ----------------------- - - + New Devices ---------------------- @@ -18,4 +12,8 @@ Devices Down Events ---------------------- - + +Internet +---------------------- + + \ No newline at end of file From 6c4e354f5ffdc1be83d21c10c078297245e69131 Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 29 Jul 2022 21:07:00 +1000 Subject: [PATCH 12/12] Remove replace cycle from txt as not needed --- back/pialert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/pialert.py b/back/pialert.py index d2376399..c841d904 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1205,7 +1205,7 @@ def email_reporting (): mail_text = mail_text.replace ('', timeFormated) mail_html = mail_html.replace ('', timeFormated) - mail_text = mail_text.replace ('', cycle ) + # mail_text = mail_text.replace ('', cycle ) mail_html = mail_html.replace ('', cycle ) mail_text = mail_text.replace ('', socket.gethostname() )