From 51715550c40669739171a0693989a27da6523aa3 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Fri, 6 Dec 2024 22:35:43 -0500 Subject: [PATCH] Added comments and updated variable names --- ui/general/health.html | 20 ++--- ui/general/health.js | 178 +++++++++++++++++++++-------------------- 2 files changed, 103 insertions(+), 95 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 690520a..0b1403c 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -22,41 +22,41 @@ Drone - + IP Address - + Docker Container - + Connection Upstream - + Network SSID - + Camera Devices - + Connected Devices - + Zerotier IP - N/A + N/A Hotspot Connections - N/A + N/A GCS @@ -64,7 +64,7 @@ FCU Firmware - N/A + N/A diff --git a/ui/general/health.js b/ui/general/health.js index dc7629b..95cfc8f 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,11 +1,11 @@ // Elements -const droneName = document.getElementById("name"); -const address = document.getElementById("address"); -const container = document.getElementById("container"); -const upstream = document.getElementById("upstream"); -const ssid = document.getElementById("ssid"); -const camera = document.getElementById("camera"); -const devices = document.getElementById("devices"); +const droneName = document.getElementById("droneName"); +const ipAddress = document.getElementById("ipAddress"); +const dockerContainer = document.getElementById("dockerContainer"); +const connectionUpstream = document.getElementById("connectionUpstream"); +const networkSSID = document.getElementById("networkSSID"); +const cameraDevices = document.getElementById("cameraDevices"); +const connectedDevices = document.getElementById("connectedDevices"); // Load page + drone settings document.onload = initPage(); @@ -15,96 +15,104 @@ function initPage() { // Populate table with drone name, drone IP address, and drone docker containers that are running // Name corresponds to host computer's name, IP address is host computer's address // and docker containers are all those displayed by docker container ls - const command1 = "hostname" - const command2 = "hostname -I" - const command3 = "docker container ls" - const command4 = "ping google.com -c 1" - const command5 = "iwgetid -r" - const command6 = "ls /dev/video*" + const droneNameCommand = "hostname" + const ipAddressCommand = "hostname -I" + const dockerContainerCommand = "docker container ls" + const connectionUpstreamCommand = "ping google.com -c 1" + const networkSSIDCommand = "iwgetid -r" + const cameraDevicesCommand = "ls /dev/video*" // Command for listing all Connected Devices - const devices_command = "lsusb" + const connectedDevicesCommand = "lsusb" - cockpit.spawn(["bash", "-c", command1]) + // Extract the Drone Name from console output + cockpit.spawn(["bash", "-c", droneNameCommand]) .then((data) => { droneName.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command2]) - .then((data) => { - address.innerHTML = data.split(" ")[0]; - }) - .catch((error) => console.log(error)); + // Extract the IP Address from console output + cockpit.spawn(["bash", "-c", ipAddressCommand]) + .then((data) => { + ipAddress.innerHTML = data.split(" ")[0]; + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command3]) - .then((data) => { - const datalist = data.split("\n"); - if (datalist[1].split(" ")[0] == ""){ - container.className = "p-3 mb-2 bg-danger text-white"; - container.innerHTML += "Error: No Docker Containers to Display"; - } else { - for (let i = 0; i < datalist.length - 2; i++) { - container.innerHTML += datalist[i + 1].split(" ")[0]; - container.innerHTML += "
"; + // Extract the Docker Container IDs from console output + cockpit.spawn(["bash", "-c", dockerContainerCommand]) + .then((data) => { + const datalist = data.split("\n"); + // If no Docker Containers up + if (datalist[1].split(" ")[0] == ""){ + dockerContainer.className = "p-3 mb-2 bg-danger text-white"; + dockerContainer.innerHTML += "Error: No Docker Containers to Display"; + } else { + // List each container on a new line + for (let i = 0; i < datalist.length - 2; i++) { + dockerContainer.innerHTML += datalist[i + 1].split(" ")[0]; + dockerContainer.innerHTML += "
"; + } + dockerContainer.innerHTML += datalist[datalist.length - 1].split(" ")[0]; } - container.innerHTML += datalist[datalist.length - 1].split(" ")[0]; - } - }) - .catch((error) => console.log(error)); + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command4]) - .then((data) => { - const datalist = data.split(" "); - if (datalist[0] == "ping:"){ - upstream.innerHTML = "Connection LIMITED - No upstream"; - } else if (datalist[0] == "PING") { - upstream.innerHTML = "Connection OK"; - } else { - upstream.innerHTML = "Connection DOWN"; - } - }) - .catch((error) => console.log(error)); + // Extract the Connection Upstream Status from console output + cockpit.spawn(["bash", "-c", connectionUpstreamCommand]) + .then((data) => { + const datalist = data.split(" "); + // If error no upstream returned + if (datalist[0] == "ping:") {connectionUpstream.innerHTML = "Connection LIMITED - No upstream";} + // If ping succeeded + else if (datalist[0] == "PING") {connectionUpstream.innerHTML = "Connection OK";} + // If some other output returned + else {connectionUpstream.innerHTML = "Connection DOWN";} + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command5]) - .then((data) => { - if (data.length == 0) { - ssid.innerHTML = "None"; - } else { - ssid.innerHTML = data - } - }) - .catch((error) => console.log(error)); - - cockpit.spawn(["bash", "-c", command6]) - .then((data) => { - if (data.length == 0) { - camera.innerHTML = "No Camera Devices Detected"; - } - else { - const datalist = data.replaceAll("\n", "
"); - camera.innerHTML += datalist; - } - }) - .catch((error) => console.log(error)); - - cockpit.spawn(["bash", "-c", devices_command]) - .then((data) => { - const datalist = data.split("\n"); - if (data.length == 0) { - devices.innerHTML = "No devices detected"; - } - for (let i = 0; i < datalist.length - 1; i++) { - const name = datalist[i].split(" "); - for (let j = 6; j < name.length; j++) { - devices.innerHTML += name[j] + " "; + // Extract the Network SSID from console output + cockpit.spawn(["bash", "-c", networkSSIDCommand]) + .then((data) => { + if (data.length == 0) { + networkSSID.innerHTML = "None"; + } else { + networkSSID.innerHTML = data } - devices.innerHTML += "
"; - devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", ""); - if (i != datalist.length - 2) { - devices.innerHTML += "

"; + }) + .catch((error) => console.log(error)); + + // Extract the Camera Devices from console output + cockpit.spawn(["bash", "-c", cameraDevicesCommand]) + .then((data) => { + // If no devices detected + if (data.length == 0) {cameraDevices.innerHTML = "No Camera Devices Detected";} + // Otherwise print the list of Camera Devices + else { + const datalist = data.replaceAll("\n", "
"); + cameraDevices.innerHTML += datalist; } - } - }) - .catch((error) => console.log(error)); + }) + .catch((error) => console.log(error)); + + // Extract the Connected Devices List from console output + cockpit.spawn(["bash", "-c", connectedDevicesCommand]) + .then((data) => { + const datalist = data.split("\n"); + // If no devices listed + if (data.length == 0) {connectedDevices.innerHTML = "No devices detected";} + // Otherwise, list each device by name and path + for (let i = 0; i < datalist.length - 1; i++) { + const name = datalist[i].split(" "); + for (let j = 6; j < name.length; j++) { + connectedDevices.innerHTML += name[j] + " "; + } + connectedDevices.innerHTML += "
"; + connectedDevices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", ""); + if (i != datalist.length - 2) { + connectedDevices.innerHTML += "

"; + } + } + }) + .catch((error) => console.log(error)); } \ No newline at end of file