status-page: lua rewrite, use gluon-neighbour-info

This commit is contained in:
Nils Schneider 2014-10-26 15:51:35 +01:00
parent f9cc73187f
commit 710cb8b36c
3 changed files with 88 additions and 52 deletions

View File

@ -12,7 +12,7 @@ define Package/gluon-status-page
SECTION:=gluon SECTION:=gluon
CATEGORY:=Gluon CATEGORY:=Gluon
TITLE:=Adds a status page showing information about the node. TITLE:=Adds a status page showing information about the node.
DEPENDS:=+gluon-core +uhttpd DEPENDS:=+gluon-core +gluon-neighbour-info +uhttpd
endef endef
define Package/gluon-status-page/description define Package/gluon-status-page/description

View File

@ -1,67 +1,94 @@
#!/bin/sh #!/usr/bin/lua
model="$(lua -e 'print(require("platform_info").get_model())')" 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")
escape_html() { local hostname = sys.hostname()
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' local model = platform_info.get_model()
} local release = util.trim(fs.readfile("/lib/gluon/release") or "")
linknodes() { function neighbours(ifname)
PREFIX=$(uci get network.local_node_route6.target | cut -d: -f 1-4) local info = util.exec("gluon-neighbour-info -d ff02::2:1001 -p 1001 -r nodeinfo -t 3 -i " .. ifname)
sed 's#\([0-9a-f]\{2\}\):\([0-9a-f]\{2\}\):\([0-9a-f]\{2\}\):\([0-9a-f]\{2\}\):\([0-9a-f]\{2\}\):\([0-9a-f]\{2\}\)#<a href="http://['$PREFIX':\1\2:\3ff:fe\4:\5\6]/">&</a>#g' 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
echo Content-type: text/html return macs
echo "" end
cat <<EOF io.write("Content-type: text/html\n\n")
<!DOCTYPE html> io.write("<!DOCTYPE html>\n")
<html> io.write("<html>")
<head> io.write("<head>")
<title>$(cat /proc/sys/kernel/hostname)</title> io.write("<script src=\"/status.js\"></script>")
</head> io.write("<title>" .. hostname .. "</title>")
<body> io.write("</head>")
EOF io.write("<body>")
echo "<h1>$(cat /proc/sys/kernel/hostname)</h1>" io.write("<h1>" .. hostname .. "</h1>")
io.write("<pre>")
echo "<pre>" io.write("Model: " .. model .. "\n")
io.write("Firmware release: " .. release .. "\n\n")
echo "Model: $model" | escape_html io.write(util.trim(sys.exec("uptime | sed 's/^ \+//'")) .. "\n\n")
echo "Firmware release: $(cat /lib/gluon/release | escape_html)" io.write(sys.exec("ip address show dev br-client") .. "\n")
echo io.write(sys.exec("free -m") .. "\n")
io.write(sys.exec("df /rom /overlay"))
io.write("</pre>")
uptime | sed 's/^ \+//' | escape_html io.write("<h2>Neighbours</h2>")
echo
ip address show dev br-client | escape_html local interfaces = util.split(util.trim(util.exec("iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2")))
echo
free -m | escape_html for _, ifname in ipairs(interfaces) do
echo io.write("<h3>" .. ifname .. "</h3>")
io.write("<pre>")
df /rom /overlay | escape_html io.write(sys.exec("iw dev " .. ifname .. " link") .. "\n")
echo "</pre>" 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
echo "<h2>Neighbours</h2>" 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
iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2 | while read if if ip and hostname then
do io.write("update_node(\"" .. ifname .. "-" .. mac .. "\", \"" .. ip .. "\", \"" .. hostname .. "\");")
echo "<h3>$if</h3>" end
echo "<pre>" end
end
iw dev $if link | escape_html io.write("</script>")
io.write("</html>")
echo
iw dev $if station dump | escape_html | linknodes
echo "</pre>"
done
cat <<EOF
</body>
</html>
EOF

View File

@ -0,0 +1,9 @@
function update_node(id, ip, hostname) {
var el = document.getElementById(id);
if (!el)
return;
el.href = "http://[" + ip + "]/";
el.textContent += " (" + hostname + ")";
}