From 5d86cbb74ae294068d90f2008d5f10524b79bb0d Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 30 Nov 2024 22:21:27 -0500 Subject: [PATCH] Added connected devices list to health table --- ui/general/health.js | 54 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index fab1f36..ec04394 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -22,28 +22,8 @@ function initPage() { const command5 = "iwgetid -r" 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 - ]; + // Command for listing all Connected Devices + const devices_command = "lsusb" cockpit.spawn(["bash", "-c", command1]) .then((data) => { @@ -108,19 +88,21 @@ function initPage() { }) .catch((error) => console.log(error)); - 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", "
"); - devices.innerHTML += "
"; - count++ + 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] + " "; } - }) - .catch((error) => console.log(error)); - } - if (count > 0) { - devices.innerHTML -= "
" - } + devices.innerHTML += "
"; + devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3]; + devices.innerHTML += "

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