Merge 4008
This commit is contained in:
parent
09ef00ec1c
commit
88a826934c
2 changed files with 117 additions and 1 deletions
|
@ -321,7 +321,7 @@ endef
|
||||||
|
|
||||||
define Package/luci-mod-freifunk
|
define Package/luci-mod-freifunk
|
||||||
$(call Package/luci/fftemplate)
|
$(call Package/luci/fftemplate)
|
||||||
DEPENDS:=+luci-admin-full
|
DEPENDS:=+luci-admin-full +luci-json
|
||||||
TITLE:=LuCI Freifunk module
|
TITLE:=LuCI Freifunk module
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ function index()
|
||||||
page.setuser = false
|
page.setuser = false
|
||||||
page.setgroup = false
|
page.setgroup = false
|
||||||
|
|
||||||
|
entry({"freifunk", "status.json"}, call("jsonstatus"))
|
||||||
|
|
||||||
assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
|
assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
|
||||||
|
|
||||||
if luci.fs.access("/etc/config/luci_statistics") then
|
if luci.fs.access("/etc/config/luci_statistics") then
|
||||||
|
@ -68,3 +70,117 @@ function index()
|
||||||
page.title = "Kontakt"
|
page.title = "Kontakt"
|
||||||
page.order = 40
|
page.order = 40
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function fetch_olsrd()
|
||||||
|
local sys = require "luci.sys"
|
||||||
|
local util = require "luci.util"
|
||||||
|
local table = require "table"
|
||||||
|
local rawdata = sys.httpget("http://127.0.0.1:2006/")
|
||||||
|
|
||||||
|
if #rawdata == 0 then
|
||||||
|
if luci.fs.access("/proc/net/ipv6_route", "r") then
|
||||||
|
rawdata = sys.httpget("http://[::1]:2006/")
|
||||||
|
if #rawdata == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local data = {}
|
||||||
|
|
||||||
|
local tables = util.split(util.trim(rawdata), "\r?\n\r?\n", nil, true)
|
||||||
|
|
||||||
|
|
||||||
|
for i, tbl in ipairs(tables) do
|
||||||
|
local lines = util.split(tbl, "\r?\n", nil, true)
|
||||||
|
local name = table.remove(lines, 1):sub(8)
|
||||||
|
local keys = util.split(table.remove(lines, 1), "\t")
|
||||||
|
local split = #keys - 1
|
||||||
|
|
||||||
|
data[name] = {}
|
||||||
|
|
||||||
|
for j, line in ipairs(lines) do
|
||||||
|
local fields = util.split(line, "\t", split)
|
||||||
|
data[name][j] = {}
|
||||||
|
for k, key in pairs(keys) do
|
||||||
|
data[name][j][key] = fields[k]
|
||||||
|
end
|
||||||
|
|
||||||
|
if data[name][j].Linkcost then
|
||||||
|
data[name][j].LinkQuality,
|
||||||
|
data[name][j].NLQ,
|
||||||
|
data[name][j].ETX =
|
||||||
|
data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
function jsonstatus()
|
||||||
|
local root = {}
|
||||||
|
local sys = require "luci.sys"
|
||||||
|
local uci = require "luci.model.uci"
|
||||||
|
local util = require "luci.util"
|
||||||
|
local http = require "luci.http"
|
||||||
|
local json = require "luci.json"
|
||||||
|
local ltn12 = require "luci.ltn12"
|
||||||
|
local webadmin = require "luci.tools.webadmin"
|
||||||
|
|
||||||
|
local cursor = uci.cursor_state()
|
||||||
|
|
||||||
|
local ffzone = webadmin.firewall_find_zone("freifunk")
|
||||||
|
local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
|
||||||
|
local ffwifs = ffznet and util.split(ffznet, " ") or {}
|
||||||
|
|
||||||
|
|
||||||
|
root.protocol = 1
|
||||||
|
|
||||||
|
root.system = {
|
||||||
|
uptime = {sys.uptime()},
|
||||||
|
loadavg = {sys.loadavg()},
|
||||||
|
sysinfo = {sys.sysinfo()},
|
||||||
|
hostname = sys.hostname()
|
||||||
|
}
|
||||||
|
|
||||||
|
root.brand = cursor:get_all("luci", "brand")
|
||||||
|
|
||||||
|
root.freifunk = {}
|
||||||
|
cursor:foreach("freifunk", "public", function(s)
|
||||||
|
root.freifunk[s[".name"]] = s
|
||||||
|
end)
|
||||||
|
|
||||||
|
cursor:foreach("system", "system", function(s)
|
||||||
|
root.geo = {
|
||||||
|
latitude = s.latitude,
|
||||||
|
longitude = s.longitude
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
root.network = {}
|
||||||
|
root.wireless = {devices = {}, interfaces = {}, status = {}}
|
||||||
|
local wifs = root.wireless.interfaces
|
||||||
|
local wifidata = luci.sys.wifi.getiwconfig() or {}
|
||||||
|
local netdata = luci.sys.net.deviceinfo() or {}
|
||||||
|
|
||||||
|
for _, vif in ipairs(ffwifs) do
|
||||||
|
root.network[vif] = cursor:get_all("network", vif)
|
||||||
|
root.wireless.devices[vif] = cursor:get_all("wireless", vif)
|
||||||
|
cursor:foreach("wireless", "wifi-iface", function(s)
|
||||||
|
if s.device == vif and s.network == vif then
|
||||||
|
wifs[#wifs+1] = s
|
||||||
|
if s.ifname then
|
||||||
|
root.wireless.status[s.ifname] = wifidata[s.ifname]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
root.olsrd = fetch_olsrd()
|
||||||
|
|
||||||
|
http.prepare_content("application/json")
|
||||||
|
ltn12.pump.all(json.Encoder(root):source(), http.write)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue