2024-10-28 12:02:39 -03:00
|
|
|
// Elements
|
2024-11-24 18:23:45 -04:00
|
|
|
const droneName = document.getElementById("name");
|
|
|
|
const address = document.getElementById("address");
|
|
|
|
const container = document.getElementById("container");
|
2024-11-29 17:04:26 -04:00
|
|
|
const upstream = document.getElementById("upstream");
|
|
|
|
const ssid = document.getElementById("ssid");
|
|
|
|
const camera = document.getElementById("camera");
|
|
|
|
const devices = document.getElementById("devices");
|
2024-11-10 03:13:25 -04:00
|
|
|
|
2024-11-27 04:53:47 -04:00
|
|
|
// Load page + drone settings
|
2024-10-28 12:02:39 -03:00
|
|
|
document.onload = initPage();
|
|
|
|
|
|
|
|
// Function to initialize the page
|
|
|
|
function initPage() {
|
2024-11-27 04:53:47 -04:00
|
|
|
// 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
|
2024-11-24 18:23:45 -04:00
|
|
|
const command1 = "hostname"
|
|
|
|
const command2 = "hostname -I"
|
2024-11-24 17:47:47 -04:00
|
|
|
const command3 = "docker container ls"
|
2024-11-30 21:30:05 -04:00
|
|
|
const command4 = "ping google.com -c 1"
|
2024-11-29 17:04:26 -04:00
|
|
|
const command5 = "iwgetid -r"
|
2024-11-30 21:30:05 -04:00
|
|
|
const command6 = "ls /dev/video*"
|
|
|
|
|
|
|
|
// Commands for listing all Connected Devices
|
|
|
|
const command7 = "ls /dev/block/*"
|
|
|
|
const command8 = "ls /dev/bus/*"
|
|
|
|
const command9 = "ls /dev/char/*"
|
|
|
|
const command10 = "ls /dev/cpu/*"
|
|
|
|
const command11 = "ls /dev/disk/*"
|
|
|
|
const command12 = "ls /dev/dma_heap/*"
|
|
|
|
const command13 = "ls /dev/dri/*"
|
|
|
|
const command14 = "ls /dev/fd/*"
|
|
|
|
const command15 = "ls /dev/hugepages/*"
|
|
|
|
const command16 = "ls /dev/input/*"
|
|
|
|
const command17 = "ls /dev/mapper/*"
|
|
|
|
const command18 = "ls /dev/mqueue/*"
|
|
|
|
const command19 = "ls /dev/net/*"
|
|
|
|
const command20 = "ls /dev/pts/*"
|
|
|
|
const command21 = "ls /dev/shm/*"
|
|
|
|
const command22 = "ls /dev/snd/*"
|
|
|
|
const command23 = "ls /dev/v4l/*"
|
|
|
|
const command24 = "ls /dev/vfio/*"
|
|
|
|
const devices_commands = [command7, command8, command9, command10, command11, command12, command13, command14, command15,
|
|
|
|
command16, command17, command18, command19, command20, command21, command22, command23, command24
|
|
|
|
];
|
2024-11-29 17:04:26 -04:00
|
|
|
|
2024-11-24 17:47:47 -04:00
|
|
|
cockpit.spawn(["bash", "-c", command1])
|
|
|
|
.then((data) => {
|
2024-11-24 18:23:45 -04:00
|
|
|
droneName.innerHTML = data.split(" ")[0];
|
2024-11-24 17:47:47 -04:00
|
|
|
})
|
|
|
|
.catch((error) => console.log(error));
|
2024-11-29 17:04:26 -04:00
|
|
|
|
2024-11-24 17:47:47 -04:00
|
|
|
cockpit.spawn(["bash", "-c", command2])
|
|
|
|
.then((data) => {
|
2024-11-24 18:23:45 -04:00
|
|
|
address.innerHTML = data.split(" ")[0];
|
2024-11-24 17:47:47 -04:00
|
|
|
})
|
|
|
|
.catch((error) => console.log(error));
|
2024-11-29 17:04:26 -04:00
|
|
|
|
2024-11-24 17:47:47 -04:00
|
|
|
cockpit.spawn(["bash", "-c", command3])
|
|
|
|
.then((data) => {
|
2024-11-24 18:23:45 -04:00
|
|
|
const datalist = data.split("\n");
|
2024-11-29 14:35:27 -04:00
|
|
|
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 += "<br>";
|
|
|
|
}
|
|
|
|
container.innerHTML += datalist[datalist.length - 1].split(" ")[0];
|
2024-11-24 18:23:45 -04:00
|
|
|
}
|
2024-11-24 17:47:47 -04:00
|
|
|
})
|
|
|
|
.catch((error) => console.log(error));
|
2024-11-29 17:04:26 -04:00
|
|
|
|
|
|
|
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") {
|
2024-11-30 21:30:05 -04:00
|
|
|
upstream.innerHTML = "Connection OK";
|
2024-11-29 17:04:26 -04:00
|
|
|
} else {
|
2024-11-30 21:30:05 -04:00
|
|
|
upstream.innerHTML = "Connection DOWN";
|
2024-11-29 17:04:26 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.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) => {
|
2024-11-30 21:30:05 -04:00
|
|
|
if (data.length == 0) {
|
|
|
|
camera.innerHTML = "No Camera Devices Detected";
|
2024-11-29 17:04:26 -04:00
|
|
|
}
|
2024-11-30 21:30:05 -04:00
|
|
|
else {
|
|
|
|
const datalist = data.replaceAll("\n", "<br>");
|
|
|
|
camera.innerHTML += datalist;
|
2024-11-29 17:04:26 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => console.log(error));
|
|
|
|
|
2024-11-30 21:30:05 -04:00
|
|
|
count = 0;
|
|
|
|
for (let i = 0; i < devices_commands.length; i++) {
|
|
|
|
cockpit.spawn(["bash", "-c", devices_commands[i]])
|
|
|
|
.then((data) => {
|
|
|
|
if (data.length != 0) {
|
|
|
|
devices.innerHTML += data.replaceAll("\n", "<br>");
|
|
|
|
devices.innerHTML += "<br>";
|
|
|
|
count++
|
2024-11-29 17:04:26 -04:00
|
|
|
}
|
2024-11-30 21:30:05 -04:00
|
|
|
})
|
|
|
|
.catch((error) => console.log(error));
|
|
|
|
}
|
|
|
|
if (count > 0) {
|
|
|
|
devices.innerHTML -= "<br>"
|
|
|
|
}
|
2024-11-16 19:38:52 -04:00
|
|
|
}
|