Added comments and updated variable names

This commit is contained in:
Alice Sedgwick 2024-12-06 22:35:43 -05:00
parent f3dc7acc2f
commit 51715550c4
2 changed files with 103 additions and 95 deletions

View File

@ -22,41 +22,41 @@
<thead>
<tr>
<th scope="col">Drone</th>
<td id="name"></th>
<td id="droneName"></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">IP Address</th>
<td id="address"></td>
<td id="ipAddress"></td>
</tr>
<tr>
<th scope="row">Docker Container</th>
<td id="container"></td>
<td id="dockerContainer"></td>
</tr>
<tr>
<th scope="row">Connection Upstream</th>
<td id="upstream"></td>
<td id="connectionUpstream"></td>
</tr>
<tr>
<th scope="row">Network SSID</th>
<td id="ssid"></td>
<td id="networkSSID"></td>
</tr>
<tr>
<th scope="row">Camera Devices</th>
<td id="camera"></td>
<td id="cameraDevices"></td>
</tr>
<tr>
<th scope="row">Connected Devices</th>
<td id="devices"></td>
<td id="connectedDevices"></td>
</tr>
<tr>
<th scope="row">Zerotier IP</th>
<td id="zerotier">N/A</td>
<td id="zerotierIP">N/A</td>
</tr>
<tr>
<th scope="row">Hotspot Connections</th>
<td id="hotspot">N/A</td>
<td id="hotspotConnections">N/A</td>
</tr>
<tr>
<th scope="row">GCS</th>
@ -64,7 +64,7 @@
</tr>
<tr>
<th scope="row">FCU Firmware</th>
<td id="fcu">N/A</td>
<td id="fcuFirmware">N/A</td>
</tr>
</tbody>
</table>

View File

@ -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,94 +15,102 @@ 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])
// Extract the IP Address from console output
cockpit.spawn(["bash", "-c", ipAddressCommand])
.then((data) => {
address.innerHTML = data.split(" ")[0];
ipAddress.innerHTML = data.split(" ")[0];
})
.catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command3])
// 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] == ""){
container.className = "p-3 mb-2 bg-danger text-white";
container.innerHTML += "Error: No Docker Containers to Display";
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++) {
container.innerHTML += datalist[i + 1].split(" ")[0];
container.innerHTML += "<br>";
dockerContainer.innerHTML += datalist[i + 1].split(" ")[0];
dockerContainer.innerHTML += "<br>";
}
container.innerHTML += datalist[datalist.length - 1].split(" ")[0];
dockerContainer.innerHTML += datalist[datalist.length - 1].split(" ")[0];
}
})
.catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command4])
// Extract the Connection Upstream Status from console output
cockpit.spawn(["bash", "-c", connectionUpstreamCommand])
.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";
// 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));
// Extract the Network SSID from console output
cockpit.spawn(["bash", "-c", networkSSIDCommand])
.then((data) => {
if (data.length == 0) {
networkSSID.innerHTML = "None";
} else {
upstream.innerHTML = "Connection DOWN";
networkSSID.innerHTML = data
}
})
.catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command5])
// Extract the Camera Devices from console output
cockpit.spawn(["bash", "-c", cameraDevicesCommand])
.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";
}
// 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", "<br>");
camera.innerHTML += datalist;
cameraDevices.innerHTML += datalist;
}
})
.catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", devices_command])
// Extract the Connected Devices List from console output
cockpit.spawn(["bash", "-c", connectedDevicesCommand])
.then((data) => {
const datalist = data.split("\n");
if (data.length == 0) {
devices.innerHTML = "No devices detected";
}
// 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++) {
devices.innerHTML += name[j] + " ";
connectedDevices.innerHTML += name[j] + " ";
}
devices.innerHTML += "<br>";
devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", "");
connectedDevices.innerHTML += "<br>";
connectedDevices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", "");
if (i != datalist.length - 2) {
devices.innerHTML += "<br><br>";
connectedDevices.innerHTML += "<br><br>";
}
}
})