95 lines
2.6 KiB
Lua
Executable File
95 lines
2.6 KiB
Lua
Executable File
#!/usr/bin/lua
|
|
|
|
local util = require("luci.util")
|
|
local fs = require("luci.fs")
|
|
local sys = require("luci.sys")
|
|
local json = require("luci.json")
|
|
local platform_info = require("platform_info")
|
|
|
|
local hostname = sys.hostname()
|
|
local model = platform_info.get_model()
|
|
local release = util.trim(fs.readfile("/lib/gluon/release") or "")
|
|
|
|
function neighbours(ifname)
|
|
local info = util.exec("gluon-neighbour-info -d ff02::2:1001 -p 1001 -r nodeinfo -t 3 -i " .. ifname)
|
|
local macs = {}
|
|
for _, line in ipairs(util.split(info)) do
|
|
local data = json.decode(line)
|
|
if data then
|
|
if data["network"] and data["network"]["mesh_interfaces"] then
|
|
for _, mac in ipairs(data["network"]["mesh_interfaces"]) do
|
|
macs[mac] = data
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return macs
|
|
end
|
|
|
|
io.write("Content-type: text/html\n\n")
|
|
io.write("<!DOCTYPE html>\n")
|
|
io.write("<html>")
|
|
io.write("<head>")
|
|
io.write("<script src=\"/status.js\"></script>")
|
|
io.write("<title>" .. hostname .. "</title>")
|
|
io.write("</head>")
|
|
io.write("<body>")
|
|
|
|
io.write("<h1>" .. hostname .. "</h1>")
|
|
io.write("<pre>")
|
|
|
|
io.write("Model: " .. model .. "\n")
|
|
io.write("Firmware release: " .. release .. "\n\n")
|
|
|
|
io.write(util.trim(sys.exec("uptime | sed 's/^ \+//'")) .. "\n\n")
|
|
io.write(sys.exec("ip address show dev br-client") .. "\n")
|
|
io.write(sys.exec("free -m") .. "\n")
|
|
io.write(sys.exec("df /rom /overlay"))
|
|
io.write("</pre>")
|
|
|
|
io.write("<h2>Neighbours</h2>")
|
|
|
|
local interfaces = util.split(util.trim(util.exec("iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2")))
|
|
|
|
for _, ifname in ipairs(interfaces) do
|
|
io.write("<h3>" .. ifname .. "</h3>")
|
|
io.write("<pre>")
|
|
|
|
io.write(sys.exec("iw dev " .. ifname .. " link") .. "\n")
|
|
|
|
for _, line in ipairs(util.split(util.exec("iw dev " .. ifname .. " station dump"))) do
|
|
local mac = line:match("^Station (.*) %(on ")
|
|
if mac then
|
|
io.write("Station <a id=\"" .. ifname .. "-" .. mac .. "\">" .. mac .. "</a> (on " .. ifname .. ")\n")
|
|
else
|
|
io.write(line .. "\n")
|
|
end
|
|
end
|
|
|
|
io.write("</pre>")
|
|
end
|
|
|
|
io.write("</body>")
|
|
io.write("<script>")
|
|
for _, ifname in ipairs(interfaces) do
|
|
local macs = neighbours(ifname)
|
|
for mac, node in pairs(macs) do
|
|
local hostname = node["hostname"]
|
|
local ip
|
|
if node["network"] and node["network"]["addresses"] then
|
|
for _, myip in ipairs(node["network"]["addresses"]) do
|
|
if ip == nil and myip:sub(1, 5) ~= "fe80:" then
|
|
ip = myip
|
|
end
|
|
end
|
|
end
|
|
|
|
if ip and hostname then
|
|
io.write("update_node(\"" .. ifname .. "-" .. mac .. "\", \"" .. ip .. "\", \"" .. hostname .. "\");")
|
|
end
|
|
end
|
|
end
|
|
io.write("</script>")
|
|
io.write("</html>")
|