From c29bcc2bdde492b008dade3a1cd2b5bbf2a1a31c Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Fri, 8 Nov 2024 14:29:32 -0800 Subject: [PATCH] Improve which local devices and service we show when logged out or logged in. (#1682) * Show more devices when logged in as admin * Updates --- files/app/partial/local-services.ut | 97 ++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 28 deletions(-) diff --git a/files/app/partial/local-services.ut b/files/app/partial/local-services.ut index d4dfff06..58d03eb6 100755 --- a/files/app/partial/local-services.ut +++ b/files/app/partial/local-services.ut @@ -61,25 +61,28 @@ const l = trim(svcs[i]); const v = match(l, reService); if (v) { - let type = ""; - if (valid[`${v[2]}://${v[3]}:${v[4]}/${v[5]}`] === false) { - type += `
`; - } - const v2 = match(v[1], reType); - if (v2) { - v[1] = v2[1]; - type += `
`; - } - switch (v[4]) { - case "80": - push(services, `
${v[1]}${type}
`); - break; - case "443": - push(services, `
${v[1]}${type}
`); - break; - default: - push(services, `
${v[1]}${type}
`); - break; + const reachable = valid[`${v[2]}://${v[3]}:${v[4]}/${v[5]}`] !== false; + if (reachable || auth.isAdmin) { + let type = ""; + if (!reachable) { + type += `
`; + } + const v2 = match(v[1], reType); + if (v2) { + v[1] = v2[1]; + type += `
`; + } + switch (v[4]) { + case "80": + push(services, `
${v[1]}${type}
`); + break; + case "443": + push(services, `
${v[1]}${type}
`); + break; + default: + push(services, `
${v[1]}${type}
`); + break; + } } } else { @@ -97,24 +100,62 @@ } if (dhcp.enabled) { - f = fs.open(dhcp.reservations); + const leased = {}; + f = fs.open(dhcp.leases); if (f) { for (let l = f.read("line"); length(l); l = f.read("line")) { - const v = match(trim(l), /^([^ ]+) ([^ ]+) ([^ ]+) ?(.*)/); - if (v && v[4] !== "#NOPROP") { - if (valid[`pseudo://${v[3]}:80/`] === true) { - push(devices, `
${v[3]}
`); - } - else if (valid[`pseudos://${v[3]}:443/`] === true) { - push(devices, `
${v[3]}
`); + const m = split(trim(l), " "); + if (length(m) === 5) { + if (m[3] === "*") { + leased[lc(m[1])] = { n: m[2], p: 0, s: auth.isAdmin, v: true }; } else { - push(devices, `
${v[3]}
`); + leased[lc(m[1])] = { n: m[3], p: 0, s: auth.isAdmin, v: true }; } } } f.close(); } + f = fs.open(dhcp.reservations); + if (f) { + for (let l = f.read("line"); length(l); l = f.read("line")) { + const v = match(trim(l), /^([^ ]+) ([^ ]+) ([^ ]+) ?(.*)/); + if (v && (v[4] !== "#NOPROP" || auth.isAdmin)) { + const k = lc(v[1]); + const l = leased[k] || (leased[k] = { n: null, p: 0, s: true, v: false }); + l.n = v[3]; + l.s = true; + if (valid[`pseudo://${v[3]}:80/`] === true) { + l.p = 80; + } + else if (valid[`pseudos://${v[3]}:443/`] === true) { + l.p = 443; + } + } + } + f.close(); + } + for (let k in leased) { + const l = leased[k]; + if (l.s) { + if (!l.v) { + if (auth.isAdmin) { + push(devices, `
${l.n}
`); + } + } + else { + if (l.p === 80) { + push(devices, `
${l.n}
`); + } + else if (l.p === 443) { + push(devices, `
${l.n}
`); + } + else { + push(devices, `
${l.n}
`); + } + } + } + } } %}