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 reService = /^([^|]+)\|1\|([^|]+)\|([^|]+)\|(\d+)\|(.*)$/;
|
||||||
const reLink = /^([^|]+)\|0\|\|([^|]+)\|\|$/;
|
const reLink = /^([^|]+)\|0\|\|([^|]+)\|\|$/;
|
||||||
const reType = /^(.+) \[([a-z]+)\]$/;
|
const reType = /^(.+) \[([a-z]+)\]$/;
|
||||||
const reOlsr = /PlParam "service" ".*\|([^|]+)"/;
|
|
||||||
|
|
||||||
const services = [];
|
const services = [];
|
||||||
const devices = [];
|
const devices = [];
|
||||||
const leases = {};
|
const leases = {};
|
||||||
const activesvc = {};
|
const valid = {};
|
||||||
|
|
||||||
const dhcp = configuration.getDHCP();
|
const dhcp = configuration.getDHCP();
|
||||||
|
|
||||||
let f = fs.open("/var/etc/olsrd.conf");
|
let f = fs.open("/tmp/service-validation-state");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
const now = time();
|
||||||
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
||||||
const m = match(l, reOlsr);
|
const m = match(trim(l), /^(\d+) (.+)$/);
|
||||||
if (m) {
|
const n = split(m[2], "|");
|
||||||
activesvc[m[1]] = true;
|
if (length(n) > 1) {
|
||||||
|
valid[n[0]] = (int(m[1]) > now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
|
@ -61,7 +62,7 @@
|
||||||
const v = match(l, reService);
|
const v = match(l, reService);
|
||||||
if (v) {
|
if (v) {
|
||||||
let type = "";
|
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>`;
|
type += ` <div class="icon warning" title="Service cannot be reached"></div>`;
|
||||||
}
|
}
|
||||||
const v2 = match(v[1], reType);
|
const v2 = match(v[1], reType);
|
||||||
|
@ -101,9 +102,17 @@
|
||||||
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
||||||
const v = match(trim(l), /^([^ ]+) ([^ ]+) ([^ ]+) ?(.*)/);
|
const v = match(trim(l), /^([^ ]+) ([^ ]+) ([^ ]+) ?(.*)/);
|
||||||
if (v && v[4] !== "#NOPROP") {
|
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>`);
|
push(devices, `<div class="device">${v[3]}</div>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,7 +474,8 @@ body.authenticated #local-and-neighbor-devices .status.ctrl:hover
|
||||||
color: var(--service-fg-color-status);
|
color: var(--service-fg-color-status);
|
||||||
background-color: var(--service-bg-color-status-inactive);
|
background-color: var(--service-bg-color-status-inactive);
|
||||||
}
|
}
|
||||||
#services .service .icon
|
#services .service .icon,
|
||||||
|
#services .device .icon
|
||||||
{
|
{
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -962,6 +963,10 @@ body.authenticated #local-and-neighbor-devices .status.ctrl:hover
|
||||||
|
|
||||||
/* start icons */
|
/* 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
|
.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;
|
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%.")
|
local dtdip = line:match("^(%d+%.%d+%.%d+%.%d+)%s+dtdlink%.")
|
||||||
if dtdip then
|
if dtdip then
|
||||||
hosts[#hosts + 1] = { ip = dtdip, host = "dtdlink." .. name .. ".local.mesh" }
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -169,8 +172,12 @@ local function get(validate)
|
||||||
do
|
do
|
||||||
if os.execute("/bin/ping -q -c 1 -W 1 " .. host.ip .. " > /dev/null 2>&1") == 0 then
|
if os.execute("/bin/ping -q -c 1 -W 1 " .. host.ip .. " > /dev/null 2>&1") == 0 then
|
||||||
vstate[host.host:lower()] = last
|
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
|
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
|
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
|
||||||
end
|
end
|
||||||
-- Load NAT
|
-- Load NAT
|
||||||
|
@ -215,7 +222,7 @@ local function get(validate)
|
||||||
if port == "0" then
|
if port == "0" then
|
||||||
-- no port so not a link - we can only check the hostname so have to assume the service is good
|
-- no port so not a link - we can only check the hostname so have to assume the service is good
|
||||||
vstate[service] = last
|
vstate[service] = last
|
||||||
elseif proto == "http" then
|
elseif proto == "http" or proto == "pseudo" then
|
||||||
-- http so looks like a link. http check it
|
-- http so looks like a link. http check it
|
||||||
if not hostname:match("%.local%.mesh$") then
|
if not hostname:match("%.local%.mesh$") then
|
||||||
hostname = hostname .. ".local.mesh"
|
hostname = hostname .. ".local.mesh"
|
||||||
|
@ -298,6 +305,7 @@ local function get(validate)
|
||||||
services = {}
|
services = {}
|
||||||
for _, service in ipairs(old_services)
|
for _, service in ipairs(old_services)
|
||||||
do
|
do
|
||||||
|
if not service:match("^pseudo:") and not service:match("^pseudos:") then
|
||||||
local vs = vstate[service]
|
local vs = vstate[service]
|
||||||
if not vs then
|
if not vs then
|
||||||
-- New services will be valid for a while, even if they're not there yet
|
-- 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
|
services[#services + 1] = service
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Store state for next time
|
-- Store state for next time
|
||||||
local f = io.open(validation_state, "w")
|
local f = io.open(validation_state, "w")
|
||||||
|
|
Loading…
Reference in New Issue