From f5546b6a4951f413f41c4a9e5127c4eea3e1fa06 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 15 Jan 2023 14:23:32 +1100 Subject: [PATCH] Network page improvements --- front/deviceDetails.php | 21 ++- front/js/pialert_common.js | 4 +- front/maintenance.php | 47 +++---- front/network.php | 173 +++++++++++++++++++------ front/php/server/devices.php | 31 ++++- front/php/server/util.php | 2 + front/php/templates/header.php | 2 +- front/php/templates/language/en_us.php | 15 ++- 8 files changed, 212 insertions(+), 83 deletions(-) diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 001a479a..f9b1363e 100755 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -253,13 +253,13 @@

- -
+ +
+
-
- -
+ +
@@ -547,7 +547,7 @@ Port State Service - Extra + Extra (Notes) @@ -910,6 +910,15 @@ function editDrp(dropdownId) $('#'+dropdownId).focus(); } +// ----------------------------------------------------------------------------- +// Go to the corect network node in the Network section +function goToNetworkNode(dropdownId) +{ + setCache('activeNetworkTab', $('#'+dropdownId).val().replaceAll(":","_")+'_id'); + window.location.href = './network.php'; + +} + // ----------------------------------------------------------------------------- // write out the HTML for the dropdown function writeDropdownHtml(dropdownId, dropdownHtmlContent) diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 8ff73acb..18a426f2 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -230,11 +230,11 @@ function setParameter (parameter, value) { // ----------------------------------------------------------------------------- -function saveData(functionName, index, value) { +function saveData(functionName, id, value) { $.ajax({ method: "GET", url: "php/server/devices.php", - data: { action: functionName, index: index, value:value }, + data: { action: functionName, id: id, value:value }, success: function(data) { if(sanitize(data) == 'OK') diff --git a/front/maintenance.php b/front/maintenance.php index 90c1ecf2..d7d9a074 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -669,11 +669,15 @@ function PiaToggleArpScan() }); } +// -------------------------------------------------------- // Clean log file var targetLogFile = ""; var logFileAction = ""; + +// -------------------------------------------------------- + function logManage(callback) { targetLogFile = arguments[0]; // target logFileAction = arguments[1]; // action @@ -682,6 +686,7 @@ function logManage(callback) { '', '', "performLogManage"); } +// -------------------------------------------------------- function performLogManage() { // Execute console.log("targetLogFile:" + targetLogFile) @@ -697,37 +702,24 @@ function performLogManage() { }) } +// -------------------------------------------------------- function scrollDown() { - var tempArea = $('#pialert_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); + var areaIDs = ['pialert_log', 'pialert_front_log', 'IP_changes_log', 'stdout_log', 'stderr_log', 'pialert_pholus_log', 'pialert_pholus_lastrun_log']; + + for (let i = 0; i < areaIDs.length; i++) { - tempArea = $('#pialert_front_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); - - tempArea = $('#IP_changes_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); - - tempArea = $('#stdout_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); - - tempArea = $('#stderr_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); - - tempArea = $('#pialert_pholus_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); - - tempArea = $('#pialert_pholus_lastrun_log'); - $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); + var tempArea = $('#' + areaIDs[i]); + $(tempArea[0]).scrollTop(tempArea[0].scrollHeight); + } } +// -------------------------------------------------------- function initializeTabs () { key = "activeMaintenanceTab" - // -------------------------------------------------------- - // default selection selectedTab = "tab_Settings" @@ -736,9 +728,8 @@ function initializeTabs () { // update cookie if target specified if(target != "") - { - // console.log(target) - setCache(key, target+'_id') + { + setCache(key, target+'_id') // _id is added so it doesn't conflict with AdminLTE tab behavior } // get the tab id from the cookie (already overriden by the target) @@ -748,10 +739,6 @@ function initializeTabs () { } // Activate panel - if(!emptyArr.includes(getCache(key))) - { - selectedTab = getCache(key); - } $('.nav-tabs a[id='+ selectedTab +']').tab('show'); // When changed save new current tab @@ -770,6 +757,8 @@ function initializeTabs () { }); } +// -------------------------------------------------------- + // save language in a cookie $('#langselector').on('change', function (e) { var optionSelected = $("option:selected", this); @@ -777,7 +766,7 @@ $('#langselector').on('change', function (e) { setCookie("language",valueSelected ) location.reload(); }); - +// -------------------------------------------------------- // load footer asynchronously not to block the page load/other sections window.onload = function asyncFooter() diff --git a/front/network.php b/front/network.php index 0a04980f..8d227c99 100755 --- a/front/network.php +++ b/front/network.php @@ -20,7 +20,7 @@

- +

@@ -47,9 +47,9 @@ $node_badge = circle_offline; } - + $idFromMac = str_replace(":", "_", $node_mac); $str_tab_header = '
  • - ' + ' // _id is added so it doesn't conflict with AdminLTE tab behavior .$node_name.' ' .$str_port.$node_badge. '
  • '; @@ -71,17 +71,29 @@ $node_badge = badge_offline; } - $str_tab_pane = '
    - -

    '.$node_name.'

    -
    - + $idFromMac = str_replace(":", "_", $node_mac); + $idParentMac = str_replace(":", "_", $node_parent_mac); + $str_tab_pane = '
    +
    + +
    +
    - - + + + + @@ -95,7 +107,7 @@
    - MAC: + + '.lang('Network_Node').' ' + + + '.$node_name.' + +
    + MAC + ' .$node_mac. '
    - '.lang('Network_Table_State').': + '.lang('Network_Table_State').' ' .$node_badge. @@ -103,29 +115,33 @@
    - '.lang('DevDetail_MainInfo_Network').' + '.lang('Network_Parent').' - - '.$node_parent_mac.' + + '.$idParentMac.'

    -
    '; +
    + + '; - $str_table = '

    - '.lang('Device_Title').' -

    - + $str_table = '
    - - - - + + + + + '; // Prepare Array for Devices with Port value @@ -204,6 +220,9 @@ + '; } @@ -214,13 +233,9 @@ // no connected device - don't render table, just display some info if($str_table_rows == "") { - $str_table = "
    -

    - ".lang('Device_Title')." -

    + $str_table = "
    - This network device (node) doesn't have any assigned devices (leaf nodes). - Go to ".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 ".lang('DevDetail_MainInfo_Network') ." dropdown. + ".lang("Network_NoAssignedDevices")."
    "; $str_table_close = ""; @@ -354,17 +369,19 @@ if (!(empty($tableData))) { $str_table_header = '
    -
    +
    -

    - '.lang('Network_UnassignedDevices').' -

    +

    + '.lang('Network_UnassignedDevices').' +

    Port'.lang('Network_Table_State').''.lang('Network_Table_Hostname').''.lang('Network_Table_IP').'Port'.lang('Network_Table_State').''.lang('Network_Table_Hostname').''.lang('Network_Table_IP').''.lang('Network_ManageLeaf').'
    ' .$row['last_ip']. ' + +
    - - - + + + + + '; $str_table_rows = ""; @@ -378,7 +395,9 @@ } $str_table_rows = $str_table_rows. - ' + ' + + @@ -389,9 +408,11 @@ + ' + '; - } $str_table_close = ' @@ -415,3 +436,75 @@ + + + \ No newline at end of file diff --git a/front/php/server/devices.php b/front/php/server/devices.php index 9ac42e44..e3b0f553 100755 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -58,6 +58,7 @@ case 'getPholus': getPholus(); break; case 'getNmap': getNmap(); break; case 'saveNmapPort': saveNmapPort(); break; + case 'updateNetworkLeaf': updateNetworkLeaf(); break; default: logServerConsole ('Action: '. $action); break; } @@ -969,7 +970,7 @@ function getNmap() { function saveNmapPort() { - $portIndex = $_REQUEST['index']; + $portIndex = $_REQUEST['id']; $value = $_REQUEST['value']; if(is_integer((int)$portIndex)) @@ -987,9 +988,35 @@ function saveNmapPort() echo 'KO'; } } - // echo "asdasdasasd"; + } +// ---------------------------------------------------------------------------------------- +function updateNetworkLeaf() +{ + $nodeMac = $_REQUEST['value']; + $leafMac = $_REQUEST['id']; + + if ((false === filter_var($nodeMac , FILTER_VALIDATE_MAC) && $nodeMac != "Internet" && $nodeMac != "") || false === filter_var($leafMac , FILTER_VALIDATE_MAC) ) { + throw new Exception('Invalid mac address'); + } + else + { + global $db; + // sql + $sql = 'UPDATE Devices SET "dev_Network_Node_MAC_ADDR" = "'. $nodeMac .'" WHERE "dev_MAC"="' . $leafMac.'"' ; + // update Data + $result = $db->query($sql); + + // check result + if ($result == TRUE) { + echo 'OK'; + } else { + echo 'KO'; + } + } + +} //------------------------------------------------------------------------------ // Status Where conditions diff --git a/front/php/server/util.php b/front/php/server/util.php index 7cfdbd6b..de90b879 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -205,6 +205,8 @@ function cleanLog($logFile) } } + + // ---------------------------------------------------------------------------------------- function saveSettings() { diff --git a/front/php/templates/header.php b/front/php/templates/header.php index ac9214de..9f02c9eb 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -222,7 +222,7 @@ if ($ENABLED_DARKMODE === True) {
  • - +
  • diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index 7e745f75..00d0fa03 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -170,9 +170,9 @@ $lang['en_us'] = array( 'DevDetail_MainInfo_Group' => 'Group', 'DevDetail_MainInfo_Location' => 'Location', 'DevDetail_MainInfo_Comments' => 'Comments', -'DevDetail_MainInfo_Network_Title' => 'Network', -'DevDetail_MainInfo_Network' => 'Network Node (MAC)', -'DevDetail_MainInfo_Network_Port' => 'Connected to Port', +'DevDetail_MainInfo_Network_Title' => ' Network', +'DevDetail_MainInfo_Network' => ' Node (MAC)', +'DevDetail_MainInfo_Network_Port' => ' Port', 'DevDetail_SessionInfo_Title' => 'Session Info', 'DevDetail_SessionInfo_Status' => 'Status', 'DevDetail_SessionInfo_FirstSession' => 'First Session', @@ -339,6 +339,8 @@ $lang['en_us'] = array( 'Network_Title' => 'Network overview', 'Network_ManageDevices' => 'Manage Devices', 'Network_ManageAdd' => 'Add Device', +'Network_ManageAssign' => 'Assign Device', +'Network_ManageUnassign' => 'Unassign', 'Network_ManageEdit' => 'Update Device', 'Network_ManageDel' => 'Delete Device', 'Network_ManageAdd_Name' => 'Device Name', @@ -364,6 +366,13 @@ $lang['en_us'] = array( 'Network_Table_Hostname' => 'Hostname', 'Network_Table_IP' => 'IP', 'Network_UnassignedDevices' => 'Unassigned devices', +'Network_Assign' => 'Connect to the above Network node', +'Network_Connected' => 'Connected devices', +'Network_ManageLeaf' => 'Manage assignment', +'Network_Node' => 'Network node', +'Network_Node_Name' => 'Node name', +'Network_Parent' => 'Parent network device', +'Network_NoAssignedDevices' => 'This network node doesn\'t have any assigned devices (leaf nodes). Assign one from bellow or go to the Details tab of any device in Devices, and assign it to a network Node (MAC) and Port there.', ////////////////////////////////////////////////////////////////// // Help Page
  • '.lang('Network_Table_State').''.lang('Network_Table_Hostname').''.lang('Network_Table_IP').''.lang('Network_Table_State').''.lang('Network_Table_Hostname').''.lang('Network_Table_IP').''.lang('Network_Assign').'
    ' .$state. ' ' .$row['last_ip']. - ' + +