diff --git a/package/gluon-status-page/Makefile b/package/gluon-status-page/Makefile index d0e9d4888894df6c0040013ac1f816c6196c7c2e..4e44e2b29d96e08bdcd7e20d19af76158b7ab237 100644 --- a/package/gluon-status-page/Makefile +++ b/package/gluon-status-page/Makefile @@ -12,7 +12,7 @@ define Package/gluon-status-page SECTION:=gluon CATEGORY:=Gluon TITLE:=Adds a status page showing information about the node. - DEPENDS:=+gluon-core +uhttpd + DEPENDS:=+gluon-core +gluon-neighbour-info +uhttpd endef define Package/gluon-status-page/description diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/status b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/status index e25d460f3426bd4c89ab5bec2f7e0cf2cc420487..aa74b85301916b7df95fafe07cb4b5977f8c587a 100755 --- a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/status +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/status @@ -1,67 +1,99 @@ -#!/bin/sh - -model="$(lua -e 'print(require("platform_info").get_model())')" - -escape_html() { - sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' -} - -linknodes() { - PREFIX=$(uci get network.local_node_route6.target | cut -d: -f 1-4) - 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' -} - -echo Content-type: text/html -echo "" - -cat <<EOF -<!DOCTYPE html> -<html> - <head> - <title>$(cat /proc/sys/kernel/hostname)</title> - </head> - <body> -EOF - -echo "<h1>$(cat /proc/sys/kernel/hostname)</h1>" - -echo "<pre>" - -echo "Model: $model" | escape_html -echo "Firmware release: $(cat /lib/gluon/release | escape_html)" -echo - -uptime | sed 's/^ \+//' | escape_html -echo - -ip address show dev br-client | escape_html -echo - -free -m | escape_html -echo - -df /rom /overlay | escape_html - -echo "</pre>" - -echo "<h2>Neighbours</h2>" - - -iw dev | grep IBSS -B 5 | grep Interface | cut -d' ' -f2 | while read if -do - echo "<h3>$if</h3>" - echo "<pre>" - - iw dev $if link | escape_html - - echo - - iw dev $if station dump | escape_html | linknodes - - echo "</pre>" -done - -cat <<EOF - </body> -</html> -EOF +#!/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 escape_html(s) + return (s:gsub('&', '&'):gsub('<', '<'):gsub('>', '>'):gsub('"', '"')) +end + +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>" .. escape_html(hostname) .. "</title>") +io.write("</head>") +io.write("<body>") + +io.write("<h1>" .. escape_html(hostname) .. "</h1>") +io.write("<pre>") + +io.write("Model: " .. escape_html(model) .. "\n") +io.write("Firmware release: " .. escape_html(release) .. "\n\n") + +io.write(escape_html(util.trim(sys.exec("uptime | sed 's/^ \+//'"))) .. "\n\n") +io.write(escape_html(sys.exec("ip address show dev br-client")) .. "\n") +io.write(escape_html(sys.exec("free -m")) .. "\n") +io.write(escape_html(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>" .. escape_html(ifname) .. "</h3>") + io.write("<pre>") + + io.write(escape_html(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=\"" .. 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>") diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/status.js b/package/gluon-status-page/files/lib/gluon/status-page/www/status.js new file mode 100644 index 0000000000000000000000000000000000000000..e17102d004a0b69273ba6f2c0f28b09296b08ce0 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/status.js @@ -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 + ")"; +}