mirror of https://github.com/aredn/aredn.git
Improve detection and display of services and devices (#1683)
* Improve timeliness of periodic tasks * Improve device and service detection
This commit is contained in:
parent
c29bcc2bdd
commit
83c8dc2d17
|
@ -46,12 +46,17 @@
|
|||
|
||||
let f = fs.open("/tmp/service-validation-state");
|
||||
if (f) {
|
||||
const now = time();
|
||||
const when = int(trim(f.read("line")));
|
||||
for (let l = f.read("line"); length(l); l = f.read("line")) {
|
||||
const m = match(trim(l), /^(\d+) (.+)$/);
|
||||
if (m) {
|
||||
const n = split(m[2], "|");
|
||||
if (length(n) > 1) {
|
||||
valid[n[0]] = (int(m[1]) > now);
|
||||
valid[n[0]] = (int(m[1]) > when);
|
||||
}
|
||||
else {
|
||||
valid[m[2]] = (int(m[1]) > when);
|
||||
}
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
@ -125,10 +130,12 @@
|
|||
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) {
|
||||
if (valid[`pseudo://${l.n}:80/`] === true) {
|
||||
l.v = true;
|
||||
l.p = 80;
|
||||
}
|
||||
else if (valid[`pseudos://${v[3]}:443/`] === true) {
|
||||
else if (valid[`pseudo://${l.n}:443/`] === true) {
|
||||
l.v = true;
|
||||
l.p = 443;
|
||||
}
|
||||
}
|
||||
|
@ -139,8 +146,11 @@
|
|||
const l = leased[k];
|
||||
if (l.s) {
|
||||
if (!l.v) {
|
||||
if (auth.isAdmin) {
|
||||
push(devices, `<div class="device">${l.n} <div class="icon warning" title="No active lease"></div></div>`);
|
||||
if (valid[l.n]) {
|
||||
push(devices, `<div class="device">${l.n}</div>`);
|
||||
}
|
||||
else if (auth.isAdmin) {
|
||||
push(devices, `<div class="device">${l.n} <div class="icon warning" title="Not found"></div></div>`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -173,11 +173,11 @@ local function get(validate)
|
|||
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)
|
||||
services[#services + 1] = string.format("pseudo://%s:443/|tcp|pseudo", 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)
|
||||
services[#services + 1] = string.format("pseudo://%s:443/|tcp|pseudo", host.host)
|
||||
end
|
||||
end
|
||||
-- Load NAT
|
||||
|
@ -222,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" or proto == "pseudo" then
|
||||
elseif proto == "http" or (proto == "pseudo" and port == "80") then
|
||||
-- http so looks like a link. http check it
|
||||
if not hostname:match("%.local%.mesh$") then
|
||||
hostname = hostname .. ".local.mesh"
|
||||
|
@ -305,7 +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
|
||||
if not service:match("^pseudo:") then
|
||||
local vs = vstate[service]
|
||||
if not vs then
|
||||
-- New services will be valid for a while, even if they're not there yet
|
||||
|
@ -320,6 +320,7 @@ local function get(validate)
|
|||
-- Store state for next time
|
||||
local f = io.open(validation_state, "w")
|
||||
if f then
|
||||
f:write(now .. "\n")
|
||||
for key, last in pairs(vstate)
|
||||
do
|
||||
f:write(last .. " " .. key .. "\n")
|
||||
|
|
|
@ -52,18 +52,21 @@ function periodic()
|
|||
local days = 0
|
||||
while true
|
||||
do
|
||||
run_scripts("/etc/cron.hourly")
|
||||
local start = os.time()
|
||||
hours = hours - 1
|
||||
if hours <= 0 then
|
||||
run_scripts("/etc/cron.daily")
|
||||
hours = 24
|
||||
days = days - 1
|
||||
if days <= 0 then
|
||||
run_scripts("/etc/cron.weekly")
|
||||
days = 7
|
||||
end
|
||||
run_scripts("/etc/cron.daily")
|
||||
hours = 24
|
||||
end
|
||||
wait_for_ticks(60 * 60)
|
||||
run_scripts("/etc/cron.hourly")
|
||||
|
||||
-- Allowing for possible clock changes and time taken to run tasks, wait for no more than an hour
|
||||
wait_for_ticks(math.min(3600, math.max(0, 3600 - (os.time() - start))))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue