working on getting information for connections upstream, camera devices, and connected devices

This commit is contained in:
Alice Sedgwick 2024-11-29 16:04:26 -05:00
parent d739e3de69
commit 6e4c4fe371
1 changed files with 71 additions and 1 deletions

View File

@ -2,6 +2,10 @@
const droneName = document.getElementById("name"); const droneName = document.getElementById("name");
const address = document.getElementById("address"); const address = document.getElementById("address");
const container = document.getElementById("container"); 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");
// Load page + drone settings // Load page + drone settings
document.onload = initPage(); document.onload = initPage();
@ -14,17 +18,22 @@ function initPage() {
const command1 = "hostname" const command1 = "hostname"
const command2 = "hostname -I" const command2 = "hostname -I"
const command3 = "docker container ls" const command3 = "docker container ls"
const command4 = "" const command4 = "ping google.com"
const command5 = "iwgetid -r"
const command6 = "ls /dev/"
cockpit.spawn(["bash", "-c", command1]) cockpit.spawn(["bash", "-c", command1])
.then((data) => { .then((data) => {
droneName.innerHTML = data.split(" ")[0]; droneName.innerHTML = data.split(" ")[0];
}) })
.catch((error) => console.log(error)); .catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command2]) cockpit.spawn(["bash", "-c", command2])
.then((data) => { .then((data) => {
address.innerHTML = data.split(" ")[0]; address.innerHTML = data.split(" ")[0];
}) })
.catch((error) => console.log(error)); .catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command3]) cockpit.spawn(["bash", "-c", command3])
.then((data) => { .then((data) => {
const datalist = data.split("\n"); const datalist = data.split("\n");
@ -40,4 +49,65 @@ function initPage() {
} }
}) })
.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));
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) => {
const datalist = data.split(" ");
count = 0
for (let i = 0; i < datalist.length - 2; i++) {
if (datalist[i].contains(video)){
if (count == 0) {
camera.innerHTML += "/dev/" + datalist[i];
count++
} else {
camera.innerHTML += "<br>";
camera.innerHTML += "/dev/" + datalist[i];
count++
}
}
}
if (count == 0) {
camera.innerHTML = "No Video Devices";
}
})
.catch((error) => console.log(error));
cockpit.spawn(["bash", "-c", command7])
.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 += "<br>";
}
container.innerHTML += datalist[datalist.length - 1].split(" ")[0];
}
})
.catch((error) => console.log(error));
} }