diff options
author | Manuel Munz <freifunk@somakoma.de> | 2010-12-15 16:35:19 +0000 |
---|---|---|
committer | Manuel Munz <freifunk@somakoma.de> | 2010-12-15 16:35:19 +0000 |
commit | 6951da02ce0b5ffa5593d31173cee92d1b33ee3d (patch) | |
tree | 5569ece365beea8f3bd7843523f9c2c8ca028895 /modules/freifunk/luasrc/controller | |
parent | d0c8c5b5327484dbd88c924d5f44a33c11af8893 (diff) |
modules/freifunk: Make status page update dynamically with javascript and small cosmetic changes.
Diffstat (limited to 'modules/freifunk/luasrc/controller')
-rw-r--r-- | modules/freifunk/luasrc/controller/freifunk/freifunk.lua | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua index 49ce9adeff..f4f9b97c0d 100644 --- a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua @@ -50,7 +50,8 @@ function index() page.setgroup = false entry({"freifunk", "status.json"}, call("jsonstatus")) - entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload") + entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload") + entry({"freifunk", "status", "public_status_json"}, call("public_status_json")).leaf = true assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30) @@ -217,3 +218,65 @@ function jsonstatus() http.prepare_content("application/json") ltn12.pump.all(json.Encoder(root):source(), http.write) end + +function public_status_json() + local twa = require "luci.tools.webadmin" + local sys = require "luci.sys" + local i18n = require "luci.i18n" + local path = luci.dispatcher.context.requestpath + local rv = { } + + local dev + for dev in path[#path]:gmatch("[%w%.%-]+") do + local j = { id = dev } + local iw = luci.sys.wifi.getiwinfo(dev) + if iw then + local f + for _, f in ipairs({ + "channel", "txpower", "bitrate", "signal", "noise", + "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname" + }) do + j[f] = iw[f] + end + end + rv[#rv+1] = j + end + + local load1, load5, load15 = sys.loadavg() + + local _, _, memtotal, memcached, membuffers, memfree = sys.sysinfo() + local mem = string.format("%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)", + tonumber(memtotal) / 1024, + tonumber(memtotal - memfree) / 1024, + tostring(i18n.translate("used")), + memfree / 1024, + tostring(i18n.translate("free")), + memcached / 1024, + tostring(i18n.translate("cached")), + membuffers / 1024, + tostring(i18n.translate("buffered")) + ) + + local dr4 = sys.net.defaultroute() + local dr6 = sys.net.defaultroute6() + + rv[#rv+1] = { + time = os.date("%c"), + uptime = twa.date_format(tonumber(sys.uptime())), + load = string.format("%.2f, %.2f, %.2f", load1, load5, load15), + mem = mem, + defroutev4 = { gateway = dr4.gateway:string(), + dest = dr4.dest:string(), + dev = dr4.device, + metr = dr4.metric }, + defroutev6 = { gateway = dr6.nexthop:string(), + dest = dr6.dest:string(), + dev = dr6.device, + metr = dr6.metric } + } + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end + |