diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 19e1e231..0d79320e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,7 @@ name: docker on: schedule: - - cron: 0 14 * * 0 # every sunday at 14:00 + - cron: 0 0 1 * * # The first of the month at 00:00 push: branches: - '**' diff --git a/README.md b/README.md index 7f5d0d97..55069a83 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ JavaScript)* ![Main screen dark][main_dark] Dark mode (and Device presence over time) within this fork courtesy of [leiweibau](https://github.com/leiweibau/Pi.Alert) +## Modifications within this Fork +... will follow soon + ## How it works The system continuously scans the network for: - New devices @@ -102,9 +105,18 @@ With the work of [jokob-sk/Pi.Alert](https://github.com/jokob-sk/Pi.Alert) and o Initially designed to run on a Raspberry Pi, probably it can run on many other Linux distributions. +> ⚠ Please note, this [fork (jokob-sk)](https://github.com/jokob-sk/Pi.Alert) is only tested via the [docker install method](dockerfiles/README.md) + +Instructions for [pucherot's original code](https://github.com/pucherot/Pi.Alert/) + +- One-step Automated Install: + #### `curl -sSL https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_install.sh | bash` + +Instructions for [leiweibau's fork](https://github.com/leiweibau/Pi.Alert/) + - One-step Automated Install: #### `curl -sSL https://github.com/leiweibau/Pi.Alert/raw/main/install/pialert_install.sh | bash` - + - One-step Automated Install without Webserver if another Webserver is already installed. (not recommended): #### `curl -sSL https://github.com/leiweibau/Pi.Alert/raw/main/install/pialert_install_no_webserver.sh | bash` @@ -113,7 +125,10 @@ Linux distributions. # Update -- One-step Automated Update: +- One-step Automated Update (pucherot): + #### `curl -sSL https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_update.sh | bash` + +- One-step Automated Update (leiweibau): #### `curl -sSL https://github.com/leiweibau/Pi.Alert/raw/main/install/pialert_update.sh | bash` # Uninstall process diff --git a/back/pialert.py b/back/pialert.py index c841d904..16314b7a 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1206,7 +1206,7 @@ def email_reporting (): mail_html = mail_html.replace ('', timeFormated) # mail_text = mail_text.replace ('', cycle ) - mail_html = mail_html.replace ('', cycle ) + # mail_html = mail_html.replace ('', cycle ) mail_text = mail_text.replace ('', socket.gethostname() ) mail_html = mail_html.replace ('', socket.gethostname() ) diff --git a/back/report_template.html b/back/report_template.html index e6b340ad..4ef981db 100644 --- a/back/report_template.html +++ b/back/report_template.html @@ -24,9 +24,7 @@ - - - +
Report Date: Scan Cycle: Report Date:
diff --git a/config/version.conf b/config/version.conf index 5dc33c9d..232e1d0f 100644 --- a/config/version.conf +++ b/config/version.conf @@ -1,3 +1,3 @@ -VERSION = '3.5_leiweibau' +VERSION = '3.6_leiweibau' VERSION_YEAR = '2022' -VERSION_DATE = '2022-07-07' \ No newline at end of file +VERSION_DATE = '2022-07-07' diff --git a/front/css/pialert.css b/front/css/pialert.css index 9f329b8d..6d44a6e1 100644 --- a/front/css/pialert.css +++ b/front/css/pialert.css @@ -541,4 +541,4 @@ height: 50px; .infobox_label { font-size: 16px !important; -} \ No newline at end of file +} diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 5bb283bc..74e9313a 100644 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -17,6 +17,7 @@ if ($_SESSION["login"] != 1) } require 'php/templates/header.php'; + require 'php/server/db.php'; ?> @@ -262,6 +263,32 @@ if ($_REQUEST['mac'] == 'Internet') { $DevDetail_Tap_temp = "Tools"; } else { $D + +

+
+ +
+
+ + +
+ + + +
+ +
+
+
+
+ +
+ +
+
+ @@ -455,7 +482,7 @@ if ($_REQUEST['mac'] == 'Internet') { ?>

Online Speedtest

- +
- - - + + + -
+
  • @@ -788,10 +815,11 @@ function initializeiCheck () { // ----------------------------------------------------------------------------- function initializeCombos () { // Initialize combos with queries - initializeCombo ( $('#dropdownOwner')[0], 'getOwners', 'txtOwner'); - initializeCombo ( $('#dropdownDeviceType')[0], 'getDeviceTypes', 'txtDeviceType'); - initializeCombo ( $('#dropdownGroup')[0], 'getGroups', 'txtGroup'); - initializeCombo ( $('#dropdownLocation')[0], 'getLocations', 'txtLocation'); + initializeCombo ( $('#dropdownOwner')[0], 'getOwners', 'txtOwner'); + initializeCombo ( $('#dropdownDeviceType')[0], 'getDeviceTypes', 'txtDeviceType'); + initializeCombo ( $('#dropdownGroup')[0], 'getGroups', 'txtGroup'); + initializeCombo ( $('#dropdownLocation')[0], 'getLocations', 'txtLocation'); + initializeCombo ( $('#dropdownNetworkNodeMac')[0], 'getNetworkNodes', 'txtNetworkNodeMac'); // Initialize static combos initializeComboSkipRepeated (); @@ -812,10 +840,17 @@ function initializeCombo (HTMLelement, queryAction, txtDataField) { order = item['order']; } + id = item['name']; + // use explicitly specified id (value) if avaliable + if(item['id']) + { + id = item['id']; + } + // add dropdown item HTMLelement.innerHTML += '
  • '+ item['name'] + '
  • ' + txtDataField +'\',\''+ id +'\')">'+ item['name'] + '' }); }); } @@ -1091,33 +1126,35 @@ function getDeviceData (readAllData=false) { $('#deviceStatus')[0].className = 'text-gray'; $('#deviceStatusIcon')[0].className = ''; - $('#deviceSessions').html ('--'); - $('#deviceDownAlerts').html ('--'); - $('#deviceEvents').html ('--'); + $('#deviceSessions').html ('--'); + $('#deviceDownAlerts').html ('--'); + $('#deviceEvents').html ('--'); - $('#txtMAC').val ('--'); - $('#txtName').val ('--'); - $('#txtOwner').val ('--'); - $('#txtDeviceType').val ('--'); - $('#txtVendor').val ('--'); + $('#txtMAC').val ('--'); + $('#txtName').val ('--'); + $('#txtOwner').val ('--'); + $('#txtDeviceType').val ('--'); + $('#txtVendor').val ('--'); - $('#chkFavorite').iCheck ('uncheck'); - $('#txtGroup').val ('--'); - $('#txtLocation').val ('--'); - $('#txtComments').val ('--'); + $('#chkFavorite').iCheck ('uncheck'); + $('#txtGroup').val ('--'); + $('#txtLocation').val ('--'); + $('#txtComments').val ('--'); + $('#txtNetworkNodeMac').val ('--'); + $('#txtNetworkPort').val ('--'); - $('#txtFirstConnection').val ('--'); - $('#txtLastConnection').val ('--'); - $('#txtLastIP').val ('--'); - $('#txtStatus').val ('--'); - $('#chkStaticIP').iCheck ('uncheck'); + $('#txtFirstConnection').val ('--'); + $('#txtLastConnection').val ('--'); + $('#txtLastIP').val ('--'); + $('#txtStatus').val ('--'); + $('#chkStaticIP').iCheck ('uncheck'); - $('#txtScanCycle').val ('--'); - $('#chkAlertEvents').iCheck ('uncheck') - $('#chkAlertDown').iCheck ('uncheck') - $('#txtSkipRepeated').val ('--'); - $('#chkNewDevice').iCheck ('uncheck'); - $('#chkArchived').iCheck ('uncheck'); + $('#txtScanCycle').val ('--'); + $('#chkAlertEvents').iCheck ('uncheck') + $('#chkAlertDown').iCheck ('uncheck') + $('#txtSkipRepeated').val ('--'); + $('#chkNewDevice').iCheck ('uncheck'); + $('#chkArchived').iCheck ('uncheck'); $('#iconRandomMACactive').addClass ('hidden'); $('#iconRandomMACinactive').removeClass ('hidden'); @@ -1192,6 +1229,8 @@ function getDeviceData (readAllData=false) { $('#txtGroup').val (deviceData['dev_Group']); $('#txtLocation').val (deviceData['dev_Location']); $('#txtComments').val (deviceData['dev_Comments']); + $('#txtNetworkNodeMac').val (deviceData['dev_Network_Node_MAC']); + $('#txtNetworkPort').val (deviceData['dev_Network_Node_port']); $('#txtFirstConnection').val (deviceData['dev_FirstConnection']); $('#txtLastConnection').val (deviceData['dev_LastConnection']); @@ -1300,6 +1339,8 @@ function setDeviceData (refreshCallback='') { + '&group=' + $('#txtGroup').val() + '&location=' + $('#txtLocation').val() + '&comments=' + $('#txtComments').val() + + '&networknode=' + $('#txtNetworkNodeMac').val() + + '&networknodeport=' + $('#txtNetworkPort').val() + '&staticIP=' + ($('#chkStaticIP')[0].checked * 1) + '&scancycle=' + $('#txtScanCycle').val().split(' ')[0] + '&alertevents=' + ($('#chkAlertEvents')[0].checked * 1) @@ -1321,6 +1362,7 @@ function setDeviceData (refreshCallback='') { } + // ----------------------------------------------------------------------------- function askSkipNotifications () { // Check MAC @@ -1332,7 +1374,7 @@ function askSkipNotifications () { if ($('#chkArchived')[0].checked && $('#txtScanCycle').val().split(' ')[0] != "0") { // Ask skip notifications showModalDefault ('Device Archived', 'Do you want to skip all notifications for this device?', - 'Cancel', 'Ok', 'skipNotifications'); + '', '', 'skipNotifications'); } } @@ -1384,7 +1426,7 @@ function askDeleteDevice () { // Ask delete device showModalWarning ('Delete Device', 'Are you sure you want to delete this device?
    (maybe you prefer to archive it)', - 'Cancel', 'Delete', 'deleteDevice'); + '', '', 'deleteDevice'); } diff --git a/front/index.php b/front/index.php index 4aae0831..6272222a 100644 --- a/front/index.php +++ b/front/index.php @@ -19,7 +19,7 @@ $config_file_lines_bypass = array_values(preg_grep('/^PIALERT_WEB_PROTECTION\s.* $protection_line = explode("=", $config_file_lines_bypass[0]); $Pia_WebProtection = strtolower(trim($protection_line[1])); -if ($Pia_WebProtection != 'true') +if ($Pia_WebProtection == 'false') { header('Location: /pialert/devices.php'); $_SESSION["login"] = 1; @@ -48,7 +48,15 @@ if ($_SESSION["login"] == 1) if ($_SESSION["login"] != 1) { if (file_exists('../db/setting_darkmode')) {$ENABLED_DARKMODE = True;} - if ($Pia_Password == '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92') {$login_info = 'Defaultpassword "123456" is still active'; + if ($Pia_Password == '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92') { + $login_info = 'Defaultpassword "123456" is still active'; + $login_mode = 'danger'; + $login_headline = 'Password Alert!'; + $login_icon = 'fa-ban'; + } else { + $login_mode = 'info'; + $login_headline = 'Password Information'; + $login_icon = 'fa-info'; } // ################################################## @@ -122,9 +130,9 @@ if ($ENABLED_DARKMODE === True) {
    -
    +
    -

    Password Alert!

    +

    To set a new password run:
    ./reset_password.sh yournewpassword
    in the config folder.

    @@ -156,4 +164,4 @@ if ($ENABLED_DARKMODE === True) { +?> \ No newline at end of file diff --git a/front/maintenance.php b/front/maintenance.php index a753e805..49389505 100644 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -310,8 +310,12 @@ if (submit && isset($_POST['langselector_set'])) {
    - - +
    +
    + +
    +
    +
    @@ -379,7 +383,7 @@ function deleteDevicesWithEmptyMACs() function askDeleteAllDevices () { // Ask showModalWarning('', '', - 'Cancel', 'Delete', 'deleteAllDevices'); + '', '', 'deleteAllDevices'); } function deleteAllDevices() { @@ -393,7 +397,7 @@ function deleteAllDevices() function askDeleteUnknown () { // Ask showModalWarning('', '', - 'Cancel', 'Delete', 'deleteUnknownDevices'); + '', '', 'deleteUnknownDevices'); } function deleteUnknownDevices() { @@ -407,7 +411,7 @@ function deleteUnknownDevices() function askDeleteEvents () { // Ask showModalWarning('', '', - 'Cancel', 'Delete', 'deleteEvents'); + '', '', 'deleteEvents'); } function deleteEvents() { @@ -417,11 +421,25 @@ function deleteEvents() }); } +// delete all Events older than 30 days +function askDeleteEvents30 () { + // Ask + showModalWarning('', '', + '', '', 'deleteEvents30'); +} +function deleteEvents30() +{ + // Execute + $.get('php/server/devices.php?action=deleteEvents30', function(msg) { + showMessage (msg); + }); +} + // delete Hostory function askDeleteActHistory () { // Ask showModalWarning('', '', - 'Cancel', 'Delete', 'deleteActHistory'); + '', '', 'deleteActHistory'); } function deleteActHistory() { @@ -435,7 +453,7 @@ function deleteActHistory() function askPiaBackupDBtoArchive () { // Ask showModalWarning('', '', - 'Cancel', 'Run Backup', 'PiaBackupDBtoArchive'); + '', '', 'PiaBackupDBtoArchive'); } function PiaBackupDBtoArchive() { @@ -449,7 +467,7 @@ function PiaBackupDBtoArchive() function askPiaRestoreDBfromArchive () { // Ask showModalWarning('', '', - 'Cancel', 'Run Restore', 'PiaRestoreDBfromArchive'); + '', '', 'PiaRestoreDBfromArchive'); } function PiaRestoreDBfromArchive() { @@ -463,7 +481,7 @@ function PiaRestoreDBfromArchive() function askPiaPurgeDBBackups() { // Ask showModalWarning('', '', - 'Cancel', 'Purge', 'PiaPurgeDBBackups'); + '', '', 'PiaPurgeDBBackups'); } function PiaPurgeDBBackups() { @@ -477,7 +495,7 @@ function PiaPurgeDBBackups() function askPiaEnableDarkmode() { // Ask showModalWarning('', '', - 'Cancel', 'Switch', 'PiaEnableDarkmode'); + '', '', 'PiaEnableDarkmode'); } function PiaEnableDarkmode() { @@ -491,7 +509,7 @@ function PiaEnableDarkmode() function askPiaToggleArpScan () { // Ask showModalWarning('', '', - 'Cancel', 'Switch', 'PiaToggleArpScan'); + '', '', 'PiaToggleArpScan'); } function PiaToggleArpScan() { diff --git a/front/network.php b/front/network.php new file mode 100644 index 00000000..fca75ab5 --- /dev/null +++ b/front/network.php @@ -0,0 +1,349 @@ +Online
    '); + define('badge_offline', '
    Offline
    '); + define('circle_online', '
     
    '); + define('circle_offline', '
     
    '); + + + $DBFILE = '../db/pialert.db'; + $NETWORKTYPES = getNetworkTypes(); + + OpenDB(); + + // ##################################### + // ## Expand Devices Table + // ##################################### + $sql = 'ALTER TABLE "Devices" ADD "dev_Network_Node_MAC" INTEGER'; + $result = $db->query($sql); + $sql = 'ALTER TABLE "Devices" ADD "dev_Network_Node_port" INTEGER'; + $result = $db->query($sql); +?> + + +
    + + +
    + +

    + +

    +
    + + + + +
    + + ' + .$node_name.' ' .$str_port.$node_badge. + ' + '; + + echo $str_tab_header; + + } + + // Create pane content (displayed inside of the tabs) + function createPane($node_mac, $node_name, $node_status, $node_type, $node_ports_count, $activetab){ + global $pia_lang; //language strings + + // online/offline status circle (red/green) + $node_badge = ""; + if($node_status == 1) // 1 means online, 0 offline + { + $node_badge = badge_online; + } else + { + $node_badge = badge_offline; + } + + $str_tab_pane = '
    + +

    '.$node_name.'

    +
    + + + + + + + + + + + + + + + +
    + MAC: + ' + .$node_mac. + '
    + '.$pia_lang['Device_TableHead_Type'].' + + ' .$node_type. ' +
    + '.$pia_lang['Network_Table_State'].': + ' + .$node_badge. + '
    +
    +
    '; + + $str_table = '

    + '.$pia_lang['Device_Title'].' +

    + + + + + + + + '; + + // Prepare Array for Devices with Port value + // If no Port is set, the Port number is set to 0 + if ($node_ports_count == "") { + $node_ports_count = 0; + } + + // Get all leafs connected to a node based on the node_mac + $func_sql = 'SELECT dev_Network_Node_port as port, + dev_MAC as mac, + dev_PresentLastScan as online, + dev_Name as name, + dev_DeviceType as type, + dev_LastIP as last_ip, + (select dev_DeviceType from Devices a where dev_MAC = "'.$node_mac.'") as node_type + FROM Devices WHERE dev_Network_Node_MAC = "'.$node_mac.'" order by port asc'; + + global $db; + $func_result = $db->query($func_sql); + + // array + $tableData = array(); + while ($row = $func_result -> fetchArray (SQLITE3_ASSOC)) { + // Push row data + $tableData[] = array( 'port' => $row['port'], + 'mac' => $row['mac'], + 'online' => $row['online'], + 'name' => $row['name'], + 'type' => $row['type'], + 'last_ip' => $row['last_ip'], + 'node_type' => $row['node_type']); + } + + // Control no rows + if (empty($tableData)) { + $tableData = []; + } + + $str_table_rows = ""; + + foreach ($tableData as $row) { + + if ($row['online'] == 1) { + $port_state = badge_online; + } else { + $port_state = badge_offline; + } + + // prepare HTML for the port table column cell + $port_content = "N/A"; + + if ($row['node_type'] == "WLAN" || $row['node_type'] == "AP" ) { + $port_content = ''; + } elseif ($row['node_type'] == "Powerline") + { + $port_content = ''; + } elseif ($row['port'] != NULL && $row['port'] != "") + { + $port_content = $row['port']; + } + + $str_table_rows = $str_table_rows. + ' + + + + + '; + + } + + $str_table_close = ' +
    Port'.$pia_lang['Network_Table_State'].''.$pia_lang['Network_Table_Hostname'].''.$pia_lang['Network_Table_IP'].'
    + '.$port_content.' + ' + .$port_state. + ' + + '.$row['name'].' + + ' + .$row['last_ip']. + '
    '; + + // no connected device - don't render table, just dispaly some info + if($str_table_rows == "") + { + $str_table = "
    +

    + ".$pia_lang['Device_Title']." +

    +
    + This network device (node) doesn't have any assigned devices (leaf nodes). + Go to ".$pia_lang['Device_Title'].", select a device you want to attach to this node and assign it in the Details tab by selecting it in the ".$pia_lang['DevDetail_MainInfo_Network'] ." dropdown. +
    +
    "; + $str_table_close = ""; + } + + $str_close_pane = '
    +
    '; + + // write the HTML + echo ''.$str_tab_header. + $str_tab_pane. + $str_table. + $str_table_rows. + $str_table_close. + $str_close_pane; + } + + + // Create Top level tabs (List of network devices), explanation of the terminology below: + // + // Switch 1 (node) + // /(p1) \ (p2) <----- port numbers + // / \ + // Smart TV (leaf) Switch 2 (node (for the PC) and leaf (for Switch 1)) + // \ + // PC (leaf) + + $sql = "SELECT node_name, node_mac, online, node_type, node_ports_count + FROM + ( + SELECT a.dev_Name as node_name, + a.dev_MAC as node_mac, + a.dev_PresentLastScan as online, + a.dev_DeviceType as node_type + FROM Devices a + WHERE a.dev_DeviceType in ('AP', 'Gateway', 'Powerline', 'Switch', 'WLAN', 'PLC', 'Router','USB LAN Adapter', 'USB WIFI Adapter', 'Internet') + ) t1 + LEFT JOIN + ( + SELECT b.dev_Network_Node_MAC as node_mac_2, + count() as node_ports_count + FROM Devices b + WHERE b.dev_Network_Node_MAC NOT NULL group by b.dev_Network_Node_MAC + ) t2 + ON (t1.node_mac = t2.node_mac_2); + "; + + $result = $db->query($sql); + + // array + $tableData = array(); + while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { + // Push row data + $tableData[] = array( 'node_mac' => $row['node_mac'], + 'node_name' => $row['node_name'], + 'online' => $row['online'], + 'node_type' => $row['node_type'], + 'node_ports_count' => $row['node_ports_count']); + } + + // Control no rows + if (empty($tableData)) { + $tableData = []; + } + + echo '
    + + +
    + + + + diff --git a/front/php/server/devices.php b/front/php/server/devices.php index ffd99c6e..0d05715c 100644 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -41,8 +41,8 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';} switch ($action) { case 'getDeviceData': getDeviceData(); break; case 'setDeviceData': setDeviceData(); break; + case 'getNetworkNodes': getNetworkNodes(); break; case 'deleteDevice': deleteDevice(); break; - case 'deleteDeviceEvents': deleteDeviceEvents(); break; case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break; case 'createBackupDB': createBackupDB(); break; case 'restoreBackupDB': restoreBackupDB(); break; @@ -51,7 +51,9 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';} case 'runScan1min': runScan1min(); break; case 'deleteUnknownDevices': deleteUnknownDevices(); break; case 'deleteEvents': deleteEvents(); break; + case 'deleteEvents30': deleteEvents30(); break; case 'deleteActHistory': deleteActHistory(); break; + case 'deleteDeviceEvents': deleteDeviceEvents(); break; case 'PiaBackupDBtoArchive': PiaBackupDBtoArchive(); break; case 'PiaRestoreDBfromArchive': PiaRestoreDBfromArchive(); break; case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break; @@ -94,6 +96,8 @@ function getDeviceData() { $deviceData = $row; $mac = $deviceData['dev_MAC']; + $deviceData['dev_Network_Node_MAC'] = $row['dev_Network_Node_MAC']; + $deviceData['dev_Network_Node_port'] = $row['dev_Network_Node_port']; $deviceData['dev_FirstConnection'] = formatDate ($row['dev_FirstConnection']); // Date formated $deviceData['dev_LastConnection'] = formatDate ($row['dev_LastConnection']); // Date formated @@ -163,6 +167,8 @@ function setDeviceData() { dev_Group = "'. quotes($_REQUEST['group']) .'", dev_Location = "'. quotes($_REQUEST['location']) .'", dev_Comments = "'. quotes($_REQUEST['comments']) .'", + dev_Network_Node_MAC = "'. quotes($_REQUEST['networknode']).'", + dev_Network_Node_port = "'. quotes($_REQUEST['networknodeport']).'", dev_StaticIP = "'. quotes($_REQUEST['staticIP']) .'", dev_ScanCycle = "'. quotes($_REQUEST['scancycle']) .'", dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'", @@ -203,26 +209,6 @@ function deleteDevice() { } } -//------------------------------------------------------------------------------ -// Delete Device Events -//------------------------------------------------------------------------------ -function deleteDeviceEvents() { - global $db; - global $pia_lang; - - // sql - $sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"'; - // execute sql - $result = $db->query($sql); - - // check result - if ($result == TRUE) { - echo $pia_lang['BackDevices_DBTools_DelEvents']; - } else { - echo $pia_lang['BackDevices_DBTools_DelEventsError']."\n\n$sql \n\n". $db->lastErrorMsg(); - } -} - //------------------------------------------------------------------------------ // Delete all devices with empty MAC addresses //------------------------------------------------------------------------------ @@ -263,6 +249,26 @@ function deleteUnknownDevices() { } } +//------------------------------------------------------------------------------ +// Delete Device Events +//------------------------------------------------------------------------------ +function deleteDeviceEvents() { + global $db; + global $pia_lang; + + // sql + $sql = 'DELETE FROM Events WHERE eve_MAC="' . $_REQUEST['mac'] .'"'; + // execute sql + $result = $db->query($sql); + + // check result + if ($result == TRUE) { + echo $pia_lang['BackDevices_DBTools_DelEvents']; + } else { + echo $pia_lang['BackDevices_DBTools_DelEventsError']."\n\n$sql \n\n". $db->lastErrorMsg(); + } +} + //------------------------------------------------------------------------------ // Delete all devices //------------------------------------------------------------------------------ @@ -303,6 +309,26 @@ function deleteEvents() { } } +//------------------------------------------------------------------------------ +// Delete all Events older than 30 days +//------------------------------------------------------------------------------ +function deleteEvents30() { + global $db; + global $pia_lang; + + // sql + $sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-30 day')"; + // execute sql + $result = $db->query($sql); + + // check result + if ($result == TRUE) { + echo $pia_lang['BackDevices_DBTools_DelEvents']; + } else { + echo $pia_lang['BackDevices_DBTools_DelEventsError']."\n\n$sql \n\n". $db->lastErrorMsg(); + } +} + //------------------------------------------------------------------------------ // Delete History //------------------------------------------------------------------------------ @@ -595,12 +621,43 @@ function getOwners() { } +//------------------------------------------------------------------------------ +// Query Device Data +//------------------------------------------------------------------------------ +function getNetworkNodes() { + global $db; + + // Device Data + $sql = 'SELECT * FROM Devices WHERE dev_DeviceType in ( "AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter")'; + + $result = $db->query($sql); + + // arrays of rows + $tableData = array(); + while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { + // Push row data + $tableData[] = array('id' => $row['dev_MAC'], + 'name' => $row['dev_Name'] ); + } + + // Control no rows + if (empty($tableData)) { + $tableData = []; + } + + // Return json + echo (json_encode ($tableData)); +} + + //------------------------------------------------------------------------------ // Query the List of types //------------------------------------------------------------------------------ function getDeviceTypes() { global $db; + $networkTypes = getNetworkTypes(); + // SQL $sql = 'SELECT DISTINCT 9 as dev_Order, dev_DeviceType FROM Devices @@ -609,7 +666,7 @@ function getDeviceTypes() { "Laptop", "Mini PC", "PC", "Printer", "Server", "Singleboard Computer (SBC)", "Game Console", "SmartTV", "TV Decoder", "Virtual Assistance", "Clock", "House Appliance", "Phone", "Radio", - "AP", "NAS", "PLC", "Router") + "AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter" ) UNION SELECT 1 as dev_Order, "Smartphone" UNION SELECT 1 as dev_Order, "Tablet" @@ -620,6 +677,7 @@ function getDeviceTypes() { UNION SELECT 2 as dev_Order, "Printer" UNION SELECT 2 as dev_Order, "Server" UNION SELECT 2 as dev_Order, "Singleboard Computer (SBC)" + UNION SELECT 2 as dev_Order, "NAS" UNION SELECT 3 as dev_Order, "Domotic" UNION SELECT 3 as dev_Order, "Game Console" @@ -632,8 +690,12 @@ function getDeviceTypes() { UNION SELECT 4 as dev_Order, "Phone" UNION SELECT 4 as dev_Order, "Radio" + -- network devices UNION SELECT 5 as dev_Order, "AP" - UNION SELECT 5 as dev_Order, "NAS" + UNION SELECT 5 as dev_Order, "Gateway" + UNION SELECT 5 as dev_Order, "Powerline" + UNION SELECT 5 as dev_Order, "Switch" + UNION SELECT 5 as dev_Order, "WLAN" UNION SELECT 5 as dev_Order, "PLC" UNION SELECT 5 as dev_Order, "Router" UNION SELECT 5 as dev_Order, "USB LAN Adapter" @@ -642,6 +704,8 @@ function getDeviceTypes() { UNION SELECT 10 as dev_Order, "Other" ORDER BY 1,2'; + + $result = $db->query($sql); // arrays of rows @@ -654,8 +718,6 @@ function getDeviceTypes() { // Return json echo (json_encode ($tableData)); } - - //------------------------------------------------------------------------------ // Query the List of groups //------------------------------------------------------------------------------ diff --git a/front/php/server/util.php b/front/php/server/util.php index 0869214d..c87da3ae 100644 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -65,4 +65,12 @@ function logServerConsole ($text) { $y = $x['__________'. $text .'__________']; } +function getNetworkTypes(){ + + $array = array( + "AP", "Gateway", "Powerline", "Switch", "WLAN", "PLC", "Router","USB LAN Adapter", "USB WIFI Adapter" + ); + + return $array; +} ?> diff --git a/front/php/templates/footer.php b/front/php/templates/footer.php index ae604c36..0bc35294 100644 --- a/front/php/templates/footer.php +++ b/front/php/templates/footer.php @@ -24,7 +24,7 @@ ('. $conf_data['VERSION_DATE'] .')'; + echo 'Pi.Alert  '. $conf_data['VERSION'] .'  ('. $conf_data['VERSION_DATE'] .')'; ?>
    diff --git a/front/php/templates/graph.php b/front/php/templates/graph.php index 3765820e..a2983aae 100644 --- a/front/php/templates/graph.php +++ b/front/php/templates/graph.php @@ -1,10 +1,16 @@ query('SELECT * FROM Online_History ORDER BY Scan_Date DESC LIMIT 144'); while ($row = $results->fetchArray()) { $time_raw = explode(' ', $row['Scan_Date']); diff --git a/front/php/templates/header.php b/front/php/templates/header.php index 5f3aba36..d0b2b8b0 100644 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -92,6 +92,7 @@ require 'php/templates/language/'.$pia_lang_selected.'.php'; + -