rewritten network tab

This commit is contained in:
jokob-sk
2022-07-31 19:48:43 +10:00
parent 21bbca62c1
commit f6490f5325
5 changed files with 324 additions and 371 deletions

View File

@@ -41,6 +41,7 @@ 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 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'createBackupDB': createBackupDB(); break;
@@ -94,8 +95,8 @@ function getDeviceData() {
$deviceData = $row;
$mac = $deviceData['dev_MAC'];
$deviceData['dev_Infrastructure'] = $row['dev_Infrastructure'];
$deviceData['dev_Infrastructure_port'] = $row['dev_Infrastructure_port'];
$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
@@ -165,8 +166,8 @@ function setDeviceData() {
dev_Group = "'. quotes($_REQUEST['group']) .'",
dev_Location = "'. quotes($_REQUEST['location']) .'",
dev_Comments = "'. quotes($_REQUEST['comments']) .'",
dev_Infrastructure = "'. quotes($_REQUEST['infrastructure']).'",
dev_Infrastructure_port = "'. quotes($_REQUEST['infrastructureport']).'",
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']) .'",
@@ -599,12 +600,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
@@ -613,7 +645,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"
@@ -624,6 +656,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"
@@ -636,8 +669,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"
@@ -646,6 +683,8 @@ function getDeviceTypes() {
UNION SELECT 10 as dev_Order, "Other"
ORDER BY 1,2';
$result = $db->query($sql);
// arrays of rows
@@ -658,8 +697,6 @@ function getDeviceTypes() {
// Return json
echo (json_encode ($tableData));
}
//------------------------------------------------------------------------------
// Query the List of groups
//------------------------------------------------------------------------------