mirror of https://github.com/aredn/aredn.git
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:
parent
5016da26c7
commit
e0ea513c5e
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue