From 01a267ff0547bbbd85a3ab77adf6b5ea446a4f67 Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Sat, 16 Jul 2022 15:07:18 +0200 Subject: [PATCH] Completing the graph extension Known issues: - some small translations are not yet completed in gaph extension - some small translations are not yet completed in entire frontend Modification within the fork: - enforce only one scancycle (crontab and frontend) - if not already done, then sqlite3 must be installed - DB must be patched via install/pialert_patch_DB.sh, otherwise the scan will run into an error --- back/pialert.py | 11 +++++++---- front/devices.php | 3 ++- front/js/graph_online_history.js | 16 +++++++++++----- front/maintenance.php | 6 +++--- front/php/templates/graph.php | 2 ++ install/pialert_patch_DB.sh | 5 +++++ 6 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 install/pialert_patch_DB.sh diff --git a/back/pialert.py b/back/pialert.py index 9d7708c3..f91392a1 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -456,7 +456,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=3', SCAN_SUBNETS] + arpscan_args = ['sudo', 'arp-scan', '--ignoredups', '--bandwidth=512k', '--retry=2', SCAN_SUBNETS] # Default arp-scan # arpscan_args = ['sudo', 'arp-scan', SCAN_SUBNETS, '--ignoredups', '--retry=' + str(pRetries)] @@ -701,12 +701,15 @@ def print_scan_stats (): sql.execute("SELECT * FROM Devices") History_All = sql.fetchall() History_All_Devices = len(History_All) + sql.execute("SELECT * FROM Devices WHERE dev_Archived = 1") + History_Archived = sql.fetchall() + History_Archived_Devices = len(History_Archived) sql.execute("SELECT * FROM CurrentScan") History_Online = sql.fetchall() History_Online_Devices = len(History_Online) - History_Offline_Devices = History_All_Devices - History_Online_Devices - sql.execute ("INSERT INTO Online_History (Scan_Date, Online_Devices, Down_Devices, All_Devices) "+ - "VALUES ( ?, ?, ?, ?)", (startTime, History_Online_Devices, History_Offline_Devices, History_All_Devices ) ) + History_Offline_Devices = History_All_Devices - History_Archived_Devices - History_Online_Devices + sql.execute ("INSERT INTO Online_History (Scan_Date, Online_Devices, Down_Devices, All_Devices, Archived_Devices) "+ + "VALUES ( ?, ?, ?, ?, ?)", (startTime, History_Online_Devices, History_Offline_Devices, History_All_Devices, History_Archived_Devices ) ) #------------------------------------------------------------------------------- def create_new_devices (): diff --git a/front/devices.php b/front/devices.php index ec388348..5cba1fbd 100644 --- a/front/devices.php +++ b/front/devices.php @@ -118,7 +118,8 @@ var pia_js_online_history_time = []; var pia_js_online_history_ondev = []; var pia_js_online_history_dodev = []; - pia_draw_graph_online_history(pia_js_online_history_time, pia_js_online_history_ondev, pia_js_online_history_dodev); + var pia_js_online_history_ardev = []; + pia_draw_graph_online_history(pia_js_online_history_time, pia_js_online_history_ondev, pia_js_online_history_dodev, pia_js_online_history_ardev); diff --git a/front/js/graph_online_history.js b/front/js/graph_online_history.js index 65d672bd..268acdc4 100644 --- a/front/js/graph_online_history.js +++ b/front/js/graph_online_history.js @@ -1,24 +1,30 @@ -function pia_draw_graph_online_history(pia_js_graph_online_history_time, pia_js_graph_online_history_ondev, pia_js_graph_online_history_dodev) { +function pia_draw_graph_online_history(pia_js_graph_online_history_time, pia_js_graph_online_history_ondev, pia_js_graph_online_history_dodev, pia_js_graph_online_history_ardev) { var xValues = pia_js_graph_online_history_time; new Chart("OnlineChart", { type: "bar", data: { labels: xValues, datasets: [{ - label: 'Online Devices', + label: 'Online', data: pia_js_graph_online_history_ondev, - borderColor: "#00a65a", + borderColor: "rgba(0, 166, 89)", fill: true, backgroundColor: "rgba(0, 166, 89, .6)", pointStyle: 'circle', pointRadius: 3, pointHoverRadius: 3 }, { - label: 'Offline/Down Devices', + label: 'Offline/Down', data: pia_js_graph_online_history_dodev, - borderColor: "#dd4b39", + borderColor: "rgba(222, 74, 56)", fill: true, backgroundColor: "rgba(222, 74, 56, .6)", + }, { + label: 'Archived', + data: pia_js_graph_online_history_ardev, + borderColor: "rgba(220,220,220)", + fill: true, + backgroundColor: "rgba(220,220,220, .6)", }] }, options: { diff --git a/front/maintenance.php b/front/maintenance.php index 51462c18..b261011f 100644 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -209,7 +209,7 @@ if (submit && isset($_POST['langselector_set'])) {
-

:

+

@@ -255,7 +255,7 @@ if (submit && isset($_POST['langselector_set'])) {
-

:

+

@@ -290,7 +290,7 @@ if (submit && isset($_POST['langselector_set'])) {
-

Tools:

+

Tools

diff --git a/front/php/templates/graph.php b/front/php/templates/graph.php index 75a7bbb0..3765820e 100644 --- a/front/php/templates/graph.php +++ b/front/php/templates/graph.php @@ -3,6 +3,7 @@ $Pia_Graph_Device_Time = array(); $Pia_Graph_Device_All = array(); $Pia_Graph_Device_Online = array(); $Pia_Graph_Device_Down = array(); +$Pia_Graph_Device_Arch = array(); $db = new SQLite3('../db/pialert.db'); $results = $db->query('SELECT * FROM Online_History ORDER BY Scan_Date DESC LIMIT 144'); while ($row = $results->fetchArray()) { @@ -12,6 +13,7 @@ while ($row = $results->fetchArray()) { 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']); } function pia_graph_devices_data($Pia_Graph_Array) { $Pia_Graph_Array_rev = array_reverse($Pia_Graph_Array); diff --git a/install/pialert_patch_DB.sh b/install/pialert_patch_DB.sh new file mode 100644 index 00000000..fd99ca26 --- /dev/null +++ b/install/pialert_patch_DB.sh @@ -0,0 +1,5 @@ +#!/bin/sh +echo "Create backup before insert new table" +cp ../db/pialert.db ../db/pialert.db.bak +echo "Insert new table 'Online_History' to pialert.db" +sqlite3 ../db/pialert.db "CREATE TABLE 'Online_History' ('Index' INTEGER, 'Scan_Date' TEXT, 'Online_Devices' INTEGER, 'Down_Devices' INTEGER, 'All_Devices' INTEGER, 'Archived_Devices' INTEGER, PRIMARY KEY('Index' AUTOINCREMENT));"