Extra bad olsr protection (#992)

* Better protection for missing olsrd files
This commit is contained in:
Tim Wilkinson 2023-12-06 12:24:43 -08:00 committed by GitHub
parent da8ef31dd1
commit 6d15dfb869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 39 deletions

View File

@ -1 +1 @@
src-git arednpackages https://github.com/aredn/aredn_packages;develop src-git arednpackages https://github.com/kn6plv/aredn_packages;working

View File

@ -70,26 +70,28 @@ function do_namechange()
local subdomains = "" local subdomains = ""
-- Load the hosts file -- Load the hosts file
for line in io.lines("/var/run/hosts_olsr.stable") if nixio.fs.stat("/var/run/hosts_olsr.stable") then
do for line in io.lines("/var/run/hosts_olsr.stable")
local v = line:splitWhiteSpace() do
local ip = v[1] local v = line:splitWhiteSpace()
local name = v[2] local ip = v[1]
local originator = v[4] local name = v[2]
local mid = v[5] local originator = v[4]
if ip then local mid = v[5]
if ip:match("^%d") and originator and originator ~= "myself" and (ip == originator or mid == "(mid") then if ip then
if hosts[ip] then if ip:match("^%d") and originator and originator ~= "myself" and (ip == originator or mid == "(mid") then
hosts[ip] = hosts[ip] .. "/" .. name if hosts[ip] then
else hosts[ip] = hosts[ip] .. "/" .. name
hosts[ip] = name else
hosts[ip] = name
end
end end
end if name and name:sub(1,2) == "*." then
if name and name:sub(1,2) == "*." then if not name:match("%.local%.mesh$") then
if not name:match("%.local%.mesh$") then name = name .. ".local.mesh"
name = name .. ".local.mesh" end
subdomains = subdomains .. "address=/." .. name:sub(3) .. "/" .. ip .. "\n"
end end
subdomains = subdomains .. "address=/." .. name:sub(3) .. "/" .. ip .. "\n"
end end
end end
end end

View File

@ -312,26 +312,28 @@ end
-- discard -- discard
routes = nil routes = nil
for line in io.lines("/var/run/services_olsr") if nixio.fs.stat("/var/run/services_olsr") then
do for line in io.lines("/var/run/services_olsr")
if line:match("^%w") then do
local url, name = line:match("^(.*)|.*|(.*)$") if line:match("^%w") then
if name then local url, name = line:match("^(.*)|.*|(.*)$")
local protocol, host, port, path = url:match("^([%w][%w%+%-%.]+)%://(.+):(%d+)/(.*)") if name then
if path then local protocol, host, port, path = url:match("^([%w][%w%+%-%.]+)%://(.+):(%d+)/(.*)")
local name, originator = name:match("(.*%S)%s*#(.*)") if path then
if originator == " my own service" or (hosts[originator] and hosts[originator].name) then local name, originator = name:match("(.*%S)%s*#(.*)")
if not host:match("%.local%.mesh$") then if originator == " my own service" or (hosts[originator] and hosts[originator].name) then
host = host .. ".local.mesh" if not host:match("%.local%.mesh$") then
end host = host .. ".local.mesh"
if not services[host] then end
services[host] = {} if not services[host] then
end services[host] = {}
if not services[host][name] then end
if port ~= "0" then if not services[host][name] then
services[host][name] = "<a href='" .. protocol .. "://" .. host .. ":" .. port .. "/" .. path .. "' target='_blank'>" .. name .. "</a>" if port ~= "0" then
else services[host][name] = "<a href='" .. protocol .. "://" .. host .. ":" .. port .. "/" .. path .. "' target='_blank'>" .. name .. "</a>"
services[host][name] = name else
services[host][name] = name
end
end end
end end
end end