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

View File

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