X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Ffreifunk%2Fluasrc%2Fcontroller%2Ffreifunk%2Ffreifunk.lua;h=f3538a1f111965e3babf75e411a64d34cadcb332;hb=fc40d9a462fa36a468625911c4ce64a62807d23b;hp=e30cdb10f8fe0a8c06a9c9f079711441d7eeb850;hpb=9e1f802dced46f10c0da7e6acccc1975a59445ed;p=project%2Fluci.git diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua index e30cdb10f..f3538a1f1 100644 --- a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua @@ -15,7 +15,9 @@ module("luci.controller.freifunk.freifunk", package.seeall) function index() local i18n = luci.i18n.translate + local uci = require "luci.model.uci".cursor() + -- Frontend local page = node() page.lock = true page.target = alias("freifunk") @@ -23,7 +25,7 @@ function index() page.index = false local page = node("freifunk") - page.title = "Freifunk" + page.title = i18n("Freifunk") page.target = alias("freifunk", "index") page.order = 5 page.setuser = "nobody" @@ -33,42 +35,69 @@ function index() local page = node("freifunk", "index") page.target = template("freifunk/index") - page.title = "Übersicht" + page.title = i18n("Overview") page.order = 10 page.indexignore = true local page = node("freifunk", "index", "contact") page.target = template("freifunk/contact") - page.title = "Kontakt" - + page.title = i18n("Contact") + page.order = 10 local page = node("freifunk", "status") - page.target = form("freifunk/public_status") - page.title = "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", "public_status_json"}, call("public_status_json")).leaf = true - assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30) + assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, i18n("OLSR"), 30) - if luci.fs.access("/etc/config/luci_statistics") then - assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("stat_statistics", "Statistiken"), 40) + if nixio.fs.access("/etc/config/luci_statistics") then + assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("Statistics"), 40) end - assign({"mini", "freifunk"}, {"admin", "freifunk"}, "Freifunk", 15) - entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), "Freifunk", 15) - local page = node("admin", "freifunk", "index") - page.target = cbi("freifunk/freifunk") - page.title = "Freifunk" - page.order = 30 + -- backend + assign({"mini", "freifunk"}, {"admin", "freifunk"}, i18n("Freifunk"), 5) + entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), i18n("Freifunk"), 5) + + local page = node("admin", "freifunk") + page.target = template("freifunk/adminindex") + page.title = i18n("Freifunk") + page.order = 5 + + local page = node("admin", "freifunk", "basics") + page.target = cbi("freifunk/basics") + page.title = i18n("Basic Settings") + page.order = 5 + + local page = node("admin", "freifunk", "basics", "profile") + page.target = cbi("freifunk/profile") + page.title = i18n("Profile") + page.order = 10 + + local page = node("admin", "freifunk", "basics", "profile_expert") + page.target = cbi("freifunk/profile_expert") + page.title = i18n("Profile (Expert)") + page.order = 20 + + local page = node("admin", "freifunk", "Index-Page") + page.target = cbi("freifunk/user_index") + page.title = i18n("Index Page") + page.order = 50 local page = node("admin", "freifunk", "contact") page.target = cbi("freifunk/contact") - page.title = "Kontakt" - page.order = 40 + page.title = i18n("Contact") + page.order = 15 + + entry({"freifunk", "map"}, template("freifunk-map/frame"), i18n("Map"), 50) + entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51) end local function fetch_olsrd() @@ -78,7 +107,7 @@ local function fetch_olsrd() local rawdata = sys.httpget("http://127.0.0.1:2006/") if #rawdata == 0 then - if luci.fs.access("/proc/net/ipv6_route", "r") then + if nixio.fs.access("/proc/net/ipv6_route", "r") then rawdata = sys.httpget("http://[::1]:2006/") if #rawdata == 0 then return nil @@ -120,6 +149,21 @@ local function fetch_olsrd() return data end +function zeroes() + local string = require "string" + local http = require "luci.http" + local zeroes = string.rep(string.char(0), 8192) + local cnt = 0 + local lim = 1024 * 1024 * 1024 + + http.prepare_content("application/x-many-zeroes") + + while cnt < lim do + http.write(zeroes) + cnt = cnt + #zeroes + end +end + function jsonstatus() local root = {} local sys = require "luci.sys" @@ -190,3 +234,74 @@ 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