feature: added localhosts info to api (#390)

* mesh endpoint can return localhosts

* mesh endpoint can return localhosts

* added localhosts info to api
This commit is contained in:
Ryan McLean 2019-03-27 20:21:23 -07:00 committed by dman776
parent 5016da26c7
commit e0ea513c5e
2 changed files with 32 additions and 1 deletions

View File

@ -319,6 +319,37 @@ function model.getDefaultGW()
return gw
end
-------------------------------------
-- Returns Local Hosts
-------------------------------------
function model.getLocalHosts()
local hosts, line
if nixio.fs.access("/etc/hosts") then
for line in io.lines("/etc/hosts") do
line = line:lower()
-- line is not a comment
local data = line:match("^([^#;]+)[#;]*(.*)$")
if data then
local hostname, entries
local ip, entries = data:match("^%s*([%[%]%x%.%:]+)%s+(%S.-%S)%s*$")
if ip then
local entry = {
["ip"] = ip,
["hostnames"] = { }
}
local index = 0
for hostname in entries:gmatch("%S+") do
entry["hostnames"][index] = hostname
index = index + 1
end
hosts = hosts or { }
hosts[#hosts+1] = entry
end
end
end
end
return hosts
end
return model

View File

@ -305,7 +305,7 @@ for page, comps in pairs(qsset) do
if comp=="sysinfo" then
info['pages'][page][comp]=getSysinfo()
elseif comp=="localhosts" then
info['pages'][page][comp]={}
info['pages'][page][comp]=aredn_info.getLocalHosts()
elseif comp=="remotenodes" then
info['pages'][page][comp]={}
elseif comp=="currentneighbors" then