gluon/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces

28 lines
542 B
Lua
Executable File

#!/usr/bin/lua
util = require 'gluon.util'
fs = require 'nixio.fs'
json = require 'luci.jsonc'
io.write("Access-Control-Allow-Origin: *\n")
io.write("Content-type: application/json\n\n")
f = io.popen('batctl if')
interfaces = {}
for line in f:lines() do
ifname = line:match('^(.-):')
if ifname ~= nil then
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))