From 13ff08641253a57dbdea0cce90b19eeb18357fdc Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sat, 20 May 2023 12:42:30 +1000 Subject: [PATCH] Setting select presence statuses #221 --- back/pialert.py | 1 + front/php/templates/graph.php | 44 +++++++++++++++++++++----- front/php/templates/language/en_us.php | 4 ++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 502cb62d..904266ba 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -371,6 +371,7 @@ def importConfigs (): REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://pi.alert/' , c_d, 'PiAlert URL', 'text', '', 'General') DIG_GET_IP_ARG = ccd('DIG_GET_IP_ARG', '-4 myip.opendns.com @resolver1.opendns.com' , c_d, 'DIG arguments', 'text', '', 'General') UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'selecttext', "['English', 'German', 'Spanish']", 'General') + UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'multiselect', "['online', 'offline', 'archived']", 'General') # Email REPORT_MAIL = ccd('REPORT_MAIL', False , c_d, 'Enable email', 'boolean', '', 'Email', ['test']) diff --git a/front/php/templates/graph.php b/front/php/templates/graph.php index 5a87078b..55f5f1d4 100755 --- a/front/php/templates/graph.php +++ b/front/php/templates/graph.php @@ -8,15 +8,43 @@ $Pia_Graph_Device_Online = array(); $Pia_Graph_Device_Down = array(); $Pia_Graph_Device_Arch = array(); +$statusesToShow = "'online', 'offline', 'archived'"; + +$statQuery = $db->query("SELECT * FROM Settings WHERE Code_Name = 'UI_PRESENCE'"); + +while($r = $statQuery->fetchArray(SQLITE3_ASSOC)) +{ + $statusesToShow = $r['Value']; +} + $results = $db->query('SELECT * FROM Online_History ORDER BY Scan_Date DESC LIMIT 144'); -while ($row = $results->fetchArray()) { - $time_raw = explode(' ', $row['Scan_Date']); - $time = explode(':', $time_raw[1]); - array_push($Pia_Graph_Device_Time, $time[0].':'.$time[1]); - array_push($Pia_Graph_Device_Down, $row['Down_Devices']); - array_push($Pia_Graph_Device_All, $row['All_Devices']); - array_push($Pia_Graph_Device_Online, $row['Online_Devices']); - array_push($Pia_Graph_Device_Arch, $row['Archived_Devices']); + +while ($row = $results->fetchArray()) +{ + $time_raw = explode(' ', $row['Scan_Date']); + $time = explode(':', $time_raw[1]); + array_push($Pia_Graph_Device_Time, $time[0].':'.$time[1]); + + // Offline + if(strpos($statusesToShow, 'offline') !== false) + { + array_push($Pia_Graph_Device_Down, $row['Down_Devices']); + } + + // All + array_push($Pia_Graph_Device_All, $row['All_Devices']); + + // Online + if(strpos($statusesToShow, 'online') !== false) + { + array_push($Pia_Graph_Device_Online, $row['Online_Devices']); + } + + // Archived + if(strpos($statusesToShow, 'archived') !== false) + { + array_push($Pia_Graph_Device_Arch, $row['Archived_Devices']); + } } function pia_graph_devices_data($Pia_Graph_Array) { $Pia_Graph_Array_rev = array_reverse($Pia_Graph_Array); diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index eaad4a10..4228fa50 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -528,7 +528,7 @@ The arp-scan time itself depends on the number of IP addresses to check so set t 'PIALERT_WEB_PASSWORD_name' => 'Login password', 'PIALERT_WEB_PASSWORD_description' => 'The default password is 123456. To change the password run /home/pi/pialert/back/pialert-cli in the container', 'INCLUDED_SECTIONS_name' => 'Notify on', -'INCLUDED_SECTIONS_description' => 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).', +'INCLUDED_SECTIONS_description' => 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select/deselect).', 'SCAN_CYCLE_MINUTES_name' => 'Scan cycle delay', 'SCAN_CYCLE_MINUTES_description' => 'The delay between scans in minutes. If using arp-scan, the scan time itself depends on the number of IP addresses to check. This is influenced by the network mask set in the SCAN_SUBNETS setting at the top. Every IP takes a couple seconds to scan.', 'DAYS_TO_KEEP_EVENTS_name' => 'Delete events older than', @@ -539,6 +539,8 @@ The arp-scan time itself depends on the number of IP addresses to check so set t 'DIG_GET_IP_ARG_description' => 'Change the dig utility arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: dig +short .', 'UI_LANG_name' => 'UI Language', 'UI_LANG_description' => 'Select the preferred UI language.', +'UI_PRESENCE_name' => 'Show in presence chart', +'UI_PRESENCE_description' => 'Select what statuses should be shown in the Device presence over time chart in the Devices page. (CTRL + Click to select/deselect)', //Email 'Email_display_name' => 'Email',