diff --git a/package/gluon-status-page/Makefile b/package/gluon-status-page/Makefile index 4e44e2b2..3d9edbfe 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 +gluon-neighbour-info +uhttpd + DEPENDS:=+gluon-core +uhttpd +gluon-neighbour-info +gluon-announce +libiwinfo-lua endef define Package/gluon-status-page/description diff --git a/package/gluon-status-page/files/lib/gluon/announce/nodeinfo.d/software/status-page b/package/gluon-status-page/files/lib/gluon/announce/nodeinfo.d/software/status-page new file mode 100644 index 00000000..20e865f3 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/announce/nodeinfo.d/software/status-page @@ -0,0 +1 @@ +return { api = 1 } diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv new file mode 100755 index 00000000..addecd60 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-batadv @@ -0,0 +1,32 @@ +#!/usr/bin/lua + +local json = require 'luci.json' +local nixio = require 'nixio' + +function neighbours() + local neighbours = {} + local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators") + for line in list do + local mac1, lastseen, tq, mac2, ifname = + line:match("^([0-9a-f:]+) +(%d+%.%d+)s +%( *(%d+)%) +([0-9a-f:]+) +%[ *(.-)%]") + + if mac1 ~= nil and mac1 == mac2 then + neighbours[mac1] = { tq = tonumber(tq) + , lastseen = tonumber(lastseen) + , ifname = ifname + } + end + end + + return neighbours +end + +io.write("Access-Control-Allow-Origin: *\n") +io.write("Content-type: text/event-stream\n\n") + +while true do + local neighbours = json.encode(neighbours()) + io.write("data: " .. neighbours .. "\n\n") + io.flush() + nixio.nanosleep(1, 0) +end diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo new file mode 100755 index 00000000..34c1204e --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/neighbours-nodeinfo @@ -0,0 +1,7 @@ +#!/bin/sh + +echo 'Access-Control-Allow-Origin: *' + +batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || exit 1 + +exec /usr/bin/gluon-neighbour-info -s -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations new file mode 100755 index 00000000..4745c342 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/stations @@ -0,0 +1,52 @@ +#!/usr/bin/lua + +util = require 'luci.util' +json = require 'luci.json' +nixio = require 'nixio' +iwinfo = require 'iwinfo' + +function badrequest() + io.write("Status: 400 Bad Request\n\n") + os.exit(1) +end + +function get_stations(iw, ifname) + local stations = {} + + for k, v in pairs(iw.assoclist(ifname)) do + stations[k:lower()] = {signal = v.signal, noise = v.noise, inactive = v.inactive} + end + + return stations +end + +local ifname = os.getenv("QUERY_STRING") + +if ifname == nil then badrequest() end + +local list = util.exec('batctl if') +local found = false +for _, line in ipairs(util.split(list)) do + if ifname == line:match('^(.-):') then + found = true + break + end +end + +if found == false then badrequest() end + +local wifitype = iwinfo.type(ifname) + +if wifitype == nil then badrequest() end + +local iw = iwinfo[wifitype] + +io.write("Access-Control-Allow-Origin: *\n") +io.write("Content-type: text/event-stream\n\n") + +while true do + local stations = json.encode(get_stations(iw, ifname)) + io.write("data: " .. stations .. "\n\n") + io.flush() + nixio.nanosleep(0, 150e6) +end diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics new file mode 100755 index 00000000..7805afe8 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/dyn/statistics @@ -0,0 +1,18 @@ +#!/usr/bin/lua + +local announce = require 'gluon.announce' +local json = require 'luci.json' +local util = require 'luci.util' +local nixio = require 'nixio' + +local announce_dir = '/lib/gluon/announce/statistics.d/' + +io.write("Access-Control-Allow-Origin: *\n") +io.write("Content-type: text/event-stream\n\n") + +while true do + local data = json.encode(announce.collect_dir(announce_dir)) + io.write("data: " .. data .. "\n\n") + io.flush() + nixio.nanosleep(1, 0) +end diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/interfaces b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/interfaces new file mode 100755 index 00000000..2615ed82 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/interfaces @@ -0,0 +1,24 @@ +#!/usr/bin/lua + +util = require 'luci.util' +json = require 'luci.json' +fs = require 'nixio.fs' + +io.write("Access-Control-Allow-Origin: *\n") +io.write("Content-type: application/json\n\n") + +list = util.exec('batctl if') + +interfaces = {} + +for _, line in ipairs(util.split(list)) 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 + +io.write(json.encode(interfaces)) diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo new file mode 100755 index 00000000..a2ef61c7 --- /dev/null +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/cgi-bin/nodeinfo @@ -0,0 +1,15 @@ +#!/usr/bin/lua + +local announce = require 'gluon.announce' +local json = require 'luci.json' +local util = require 'luci.util' +local nixio = require 'nixio' + +local announce_dir = '/lib/gluon/announce/nodeinfo.d/' + +io.write("Access-Control-Allow-Origin: *\n") +io.write("Content-type: application/json\n\n") + +local data = json.encode(announce.collect_dir(announce_dir)) +io.write(data) +io.flush()