X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Ffreifunk%2Fluasrc%2Fcontroller%2Ffreifunk%2Ffreifunk.lua;h=b9f551b1e4aec1c79dfdb0f8cf3a96e7c6b8f0c2;hp=52b37dc6a164ef3c12da219570cc8897f5df456c;hb=9dcf1d9e603ecf66fc67f3f110168a3e0a4f57fa;hpb=7c765875884d6866c53b63757731b079bace2e9b;ds=sidebyside diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua index 52b37dc6a..b9f551b1e 100644 --- a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua @@ -15,6 +15,7 @@ module("luci.controller.freifunk.freifunk", package.seeall) function index() local i18n = luci.i18n.translate + local uci = require "luci.model.uci".cursor() local page = node() page.lock = true @@ -41,18 +42,17 @@ function index() page.target = template("freifunk/contact") page.title = "Kontakt" - entry({"freifunk", "status"}, alias("freifunk", "status", "status"), "Status", 20) - - local page = node("freifunk", "status", "status") - page.target = form("freifunk/public_status") - page.title = i18n("Overview") + local page = node("freifunk", "status") + page.target = template("freifunk/public_status") + page.title = i18n("Status") page.order = 20 - page.i18n = "admin-core" + page.i18n = "base" page.setuser = false - page.setgroup = false + 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) @@ -67,6 +67,11 @@ function index() page.title = "Freifunk" page.order = 30 + local page = node("admin", "freifunk", "Index-Page") + page.target = cbi("freifunk/user_index") + page.title = "Index-Page" + page.order = 35 + local page = node("admin", "freifunk", "contact") page.target = cbi("freifunk/contact") page.title = "Kontakt" @@ -74,6 +79,16 @@ function index() entry({"freifunk", "map"}, template("freifunk-map/frame"), i18n("Karte"), 50) entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51) + + uci:foreach("olsrd", "LoadPlugin", function(s) + if s.library == "olsrd_nameservice.so.0.3" then + has_serv = true + end + end) + + if has_serv then + entry({"freifunk", "services"}, template("freifunk-services/services"), i18n("Services"), 60) + end end local function fetch_olsrd() @@ -210,3 +225,75 @@ 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() + + if dr6 then + def6 = { + gateway = dr6.nexthop:string(), + dest = dr6.dest:string(), + dev = dr6.device, + metr = dr6.metric } + end + + if dr4 then + def4 = { + gateway = dr4.gateway:string(), + dest = dr4.dest:string(), + dev = dr4.device, + metr = dr4.metric } + end + + 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 = def4, + defroutev6 = def6 + } + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end +