mirror of https://github.com/aredn/aredn.git
Add pseudo services for Local Devices (#1665)
* Add pseudo services for Local Devices * Whitespace
This commit is contained in:
parent
83c5243bb6
commit
f4b949fa68
|
@ -36,21 +36,22 @@
|
|||
const reService = /^([^|]+)\|1\|([^|]+)\|([^|]+)\|(\d+)\|(.*)$/;
|
||||
const reLink = /^([^|]+)\|0\|\|([^|]+)\|\|$/;
|
||||
const reType = /^(.+) \[([a-z]+)\]$/;
|
||||
const reOlsr = /PlParam "service" ".*\|([^|]+)"/;
|
||||
|
||||
const services = [];
|
||||
const devices = [];
|
||||
const leases = {};
|
||||
const activesvc = {};
|
||||
const valid = {};
|
||||
|
||||
const dhcp = configuration.getDHCP();
|
||||
|
||||
let f = fs.open("/var/etc/olsrd.conf");
|
||||
let f = fs.open("/tmp/service-validation-state");
|
||||
if (f) {
|
||||
const now = time();
|
||||
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
||||
const m = match(l, reOlsr);
|
||||
if (m) {
|
||||
activesvc[m[1]] = true;
|
||||
const m = match(trim(l), /^(\d+) (.+)$/);
|
||||
const n = split(m[2], "|");
|
||||
if (length(n) > 1) {
|
||||
valid[n[0]] = (int(m[1]) > now);
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
@ -61,7 +62,7 @@
|
|||
const v = match(l, reService);
|
||||
if (v) {
|
||||
let type = "";
|
||||
if (!activesvc[v[1]]) {
|
||||
if (valid[`${v[2]}://${v[3]}:${v[4]}/${v[5]}`] === false) {
|
||||
type += ` <div class="icon warning" title="Service cannot be reached"></div>`;
|
||||
}
|
||||
const v2 = match(v[1], reType);
|
||||
|
@ -101,9 +102,17 @@
|
|||
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, `<div class="device"><a target="_blank" href="http://${v[3]}.local.mesh" onclick="event.stopPropagation()">${v[3]} <div class="icon link" title="link"></div></a></div>`);
|
||||
}
|
||||
else if (valid[`pseudos://${v[3]}:443/`] === true) {
|
||||
push(devices, `<div class="device"><a target="_blank" href="https://${v[3]}.local.mesh" onclick="event.stopPropagation()">${v[3]} <div class="icon link" title="link"></div></a></div>`);
|
||||
}
|
||||
else {
|
||||
push(devices, `<div class="device">${v[3]}</div>`);
|
||||
}
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -474,7 +474,8 @@ body.authenticated #local-and-neighbor-devices .status.ctrl:hover
|
|||
color: var(--service-fg-color-status);
|
||||
background-color: var(--service-bg-color-status-inactive);
|
||||
}
|
||||
#services .service .icon
|
||||
#services .service .icon,
|
||||
#services .device .icon
|
||||
{
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
|
@ -962,6 +963,10 @@ body.authenticated #local-and-neighbor-devices .status.ctrl:hover
|
|||
|
||||
/* start icons */
|
||||
|
||||
.icon.link
|
||||
{
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244" /></svg>') !important;
|
||||
}
|
||||
.icon.status
|
||||
{
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" /></svg>') !important;
|
||||
|
|
|
@ -109,7 +109,10 @@ local function get(validate)
|
|||
local dtdip = line:match("^(%d+%.%d+%.%d+%.%d+)%s+dtdlink%.")
|
||||
if dtdip then
|
||||
hosts[#hosts + 1] = { ip = dtdip, host = "dtdlink." .. name .. ".local.mesh" }
|
||||
break
|
||||
end
|
||||
local lanip = line:match("^(%d+%.%d+%.%d+%.%d+)%s+localnode$")
|
||||
if lanip then
|
||||
hosts[#hosts + 1] = { ip = lanip, host = "lan." .. name .. ".local.mesh" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -169,8 +172,12 @@ local function get(validate)
|
|||
do
|
||||
if os.execute("/bin/ping -q -c 1 -W 1 " .. host.ip .. " > /dev/null 2>&1") == 0 then
|
||||
vstate[host.host:lower()] = last
|
||||
services[#services + 1] = string.format("pseudo://%s:80/|tcp|pseudo", host.host)
|
||||
services[#services + 1] = string.format("pseudos://%s:443/|tcp|pseudos", host.host)
|
||||
elseif os.execute("/usr/sbin/arping -q -f -c 1 -w 1 -I " .. laniface .. " " .. host.ip .. " > /dev/null 2>&1") == 0 then
|
||||
vstate[host.host:lower()] = last
|
||||
services[#services + 1] = string.format("pseudo://%s:80/|tcp|pseudo", host.host)
|
||||
services[#services + 1] = string.format("pseudos://%s:443/|tcp|pseudos", host.host)
|
||||
end
|
||||
end
|
||||
-- Load NAT
|
||||
|
@ -215,7 +222,7 @@ local function get(validate)
|
|||
if port == "0" then
|
||||
-- no port so not a link - we can only check the hostname so have to assume the service is good
|
||||
vstate[service] = last
|
||||
elseif proto == "http" then
|
||||
elseif proto == "http" or proto == "pseudo" then
|
||||
-- http so looks like a link. http check it
|
||||
if not hostname:match("%.local%.mesh$") then
|
||||
hostname = hostname .. ".local.mesh"
|
||||
|
@ -298,6 +305,7 @@ local function get(validate)
|
|||
services = {}
|
||||
for _, service in ipairs(old_services)
|
||||
do
|
||||
if not service:match("^pseudo:") and not service:match("^pseudos:") then
|
||||
local vs = vstate[service]
|
||||
if not vs then
|
||||
-- New services will be valid for a while, even if they're not there yet
|
||||
|
@ -307,6 +315,7 @@ local function get(validate)
|
|||
services[#services + 1] = service
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Store state for next time
|
||||
local f = io.open(validation_state, "w")
|
||||
|
|
Loading…
Reference in New Issue