diff --git a/back/pialert.py b/back/pialert.py index fcbe2933..c841d904 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') @@ -1200,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() ) 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 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..d4458bc6 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..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)); @@ -116,8 +123,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..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 @@ -275,7 +281,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..0869214d 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