|
@@ -0,0 +1,52 @@
|
|
|
+#!/usr/bin/lua
|
|
|
+
|
|
|
+util = require 'luci.util'
|
|
|
+json = require 'luci.jsonc'
|
|
|
+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.stringify(get_stations(iw, ifname))
|
|
|
+ io.write("data: " .. stations .. "\n\n")
|
|
|
+ io.flush()
|
|
|
+ nixio.nanosleep(0, 150e6)
|
|
|
+end
|