Skip to content
Snippets Groups Projects
Commit 26271615 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

Merge remote-tracking branch 'origin/status-page-164'

parents 15adcae3 5266a073
No related branches found
Tags
No related merge requests found
...@@ -12,7 +12,7 @@ define Package/gluon-status-page ...@@ -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
......
#!/bin/sh #!/usr/bin/lua
model="$(lua -e 'print(require("platform_info").get_model())')" local util = require("luci.util")
local fs = require("luci.fs")
escape_html() { local sys = require("luci.sys")
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' local json = require("luci.json")
} local platform_info = require("platform_info")
linknodes() { local hostname = sys.hostname()
PREFIX=$(uci get network.local_node_route6.target | cut -d: -f 1-4) local model = platform_info.get_model()
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 release = util.trim(fs.readfile("/lib/gluon/release") or "")
}
function escape_html(s)
echo Content-type: text/html return (s:gsub('&', '&amp;'):gsub('<', '&lt;'):gsub('>', '&gt;'):gsub('"', '&quot;'))
echo "" end
cat <<EOF function neighbours(ifname)
<!DOCTYPE html> local info = util.exec("gluon-neighbour-info -d ff02::2:1001 -p 1001 -r nodeinfo -t 3 -i " .. ifname)
<html> local macs = {}
<head> for _, line in ipairs(util.split(info)) do
<title>$(cat /proc/sys/kernel/hostname)</title> local data = json.decode(line)
</head> if data then
<body> if data["network"] and data["network"]["mesh_interfaces"] then
EOF for _, mac in ipairs(data["network"]["mesh_interfaces"]) do
macs[mac] = data
echo "<h1>$(cat /proc/sys/kernel/hostname)</h1>" end
end
echo "<pre>" end
end
echo "Model: $model" | escape_html
echo "Firmware release: $(cat /lib/gluon/release | escape_html)" return macs
echo end
uptime | sed 's/^ \+//' | escape_html io.write("Content-type: text/html\n\n")
echo io.write("<!DOCTYPE html>\n")
io.write("<html>")
ip address show dev br-client | escape_html io.write("<head>")
echo io.write("<script src=\"/status.js\"></script>")
io.write("<title>" .. escape_html(hostname) .. "</title>")
free -m | escape_html io.write("</head>")
echo io.write("<body>")
df /rom /overlay | escape_html io.write("<h1>" .. escape_html(hostname) .. "</h1>")
io.write("<pre>")
echo "</pre>"
io.write("Model: " .. escape_html(model) .. "\n")
echo "<h2>Neighbours</h2>" io.write("Firmware release: " .. escape_html(release) .. "\n\n")
io.write(escape_html(util.trim(sys.exec("uptime | sed 's/^ \+//'"))) .. "\n\n")
iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2 | while read if io.write(escape_html(sys.exec("ip address show dev br-client")) .. "\n")
do io.write(escape_html(sys.exec("free -m")) .. "\n")
echo "<h3>$if</h3>" io.write(escape_html(sys.exec("df /rom /overlay")))
echo "<pre>" io.write("</pre>")
iw dev $if link | escape_html io.write("<h2>Neighbours</h2>")
echo local interfaces = util.split(util.trim(util.exec("iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2")))
iw dev $if station dump | escape_html | linknodes for _, ifname in ipairs(interfaces) do
io.write("<h3>" .. escape_html(ifname) .. "</h3>")
echo "</pre>" io.write("<pre>")
done
io.write(escape_html(sys.exec("iw dev " .. ifname .. " link")) .. "\n")
cat <<EOF
</body> for _, line in ipairs(util.split(util.exec("iw dev " .. ifname .. " station dump"))) do
</html> local mac = line:match("^Station (.*) %(on ")
EOF if mac then
io.write("Station <a id=\"" .. escape_html(ifname) .. "-" .. mac .. "\">" .. mac .. "</a> (on " .. escape_html(ifname) .. ")\n")
else
io.write(escape_html(line) .. "\n")
end
end
io.write("</pre>")
end
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(\"" .. escape_html(ifname) .. "-" .. mac .. "\", \"" .. escape_html(ip) .. "\", \"" .. escape_html(hostname) .. "\");")
end
end
end
io.write("</script>")
io.write("</body>")
io.write("</html>")
function update_node(id, ip, hostname) {
var el = document.getElementById(id);
if (!el)
return;
el.href = "http://[" + ip + "]/";
el.textContent += " (" + hostname + ")";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment