gluon-statuspage-api: make lib/gluon/status-page/www/cgi-bin/interfaces mesh-protocol agnostic

This commit is contained in:
Christof Schulze 2017-02-11 17:25:06 +01:00 committed by Matthias Schiffer
parent b3e609dca9
commit 8b63ac792a
2 changed files with 9 additions and 12 deletions

View File

@ -14,7 +14,7 @@ define Package/gluon-status-page-api
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=API for gluon-status-page
DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-respondd +libiwinfo +libjson-c +libnl-tiny
DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-respondd +libiwinfo +libjson-c +libnl-tiny +libubus-lua
endef
define Build/Prepare

View File

@ -1,27 +1,24 @@
#!/usr/bin/lua
util = require 'gluon.util'
fs = require 'nixio.fs'
json = require 'luci.jsonc'
ubus = require 'ubus'
io.write("Access-Control-Allow-Origin: *\n")
io.write("Content-type: application/json\n\n")
f = io.popen('batctl if')
local uconn = ubus.connect()
if not uconn then
error("Failed to connect to ubusd")
end
list = util.get_mesh_devices(uconn)
ubus.close(uconn)
interfaces = {}
for line in f:lines() do
ifname = line:match('^(.-):')
if ifname ~= nil then
for _,ifname in ipairs(list) do
pcall(function()
local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
interfaces[ifname] = { address = address }
end)
end
end
f:close()
io.write(json.stringify(interfaces))