2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.freifunk.freifunk", package.seeall)
17 local i18n = luci.i18n.translate
21 page.target = alias("freifunk")
25 local page = node("freifunk")
26 page.title = "Freifunk"
27 page.target = alias("freifunk", "index")
29 page.setuser = "nobody"
30 page.setgroup = "nogroup"
31 page.i18n = "freifunk"
34 local page = node("freifunk", "index")
35 page.target = template("freifunk/index")
36 page.title = "Übersicht"
38 page.indexignore = true
40 local page = node("freifunk", "index", "contact")
41 page.target = template("freifunk/contact")
42 page.title = "Kontakt"
45 local page = node("freifunk", "status")
46 page.target = form("freifunk/public_status")
49 page.i18n = "admin-core"
53 entry({"freifunk", "status.json"}, call("jsonstatus"))
55 assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
57 if luci.fs.access("/etc/config/luci_statistics") then
58 assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("stat_statistics", "Statistiken"), 40)
61 assign({"mini", "freifunk"}, {"admin", "freifunk"}, "Freifunk", 15)
62 entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), "Freifunk", 15)
63 local page = node("admin", "freifunk", "index")
64 page.target = cbi("freifunk/freifunk")
65 page.title = "Freifunk"
68 local page = node("admin", "freifunk", "contact")
69 page.target = cbi("freifunk/contact")
70 page.title = "Kontakt"
74 local function fetch_olsrd()
75 local sys = require "luci.sys"
76 local util = require "luci.util"
77 local table = require "table"
78 local rawdata = sys.httpget("http://127.0.0.1:2006/")
81 if luci.fs.access("/proc/net/ipv6_route", "r") then
82 rawdata = sys.httpget("http://[::1]:2006/")
93 local tables = util.split(util.trim(rawdata), "\r?\n\r?\n", nil, true)
96 for i, tbl in ipairs(tables) do
97 local lines = util.split(tbl, "\r?\n", nil, true)
98 local name = table.remove(lines, 1):sub(8)
99 local keys = util.split(table.remove(lines, 1), "\t")
100 local split = #keys - 1
104 for j, line in ipairs(lines) do
105 local fields = util.split(line, "\t", split)
107 for k, key in pairs(keys) do
108 data[name][j][key] = fields[k]
111 if data[name][j].Linkcost then
112 data[name][j].LinkQuality,
115 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
123 function jsonstatus()
125 local sys = require "luci.sys"
126 local uci = require "luci.model.uci"
127 local util = require "luci.util"
128 local http = require "luci.http"
129 local json = require "luci.json"
130 local ltn12 = require "luci.ltn12"
131 local version = require "luci.version"
132 local webadmin = require "luci.tools.webadmin"
134 local cursor = uci.cursor_state()
136 local ffzone = webadmin.firewall_find_zone("freifunk")
137 local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
138 local ffwifs = ffznet and util.split(ffznet, " ") or {}
144 uptime = {sys.uptime()},
145 loadavg = {sys.loadavg()},
146 sysinfo = {sys.sysinfo()},
147 hostname = sys.hostname()
151 luciname=version.luciname,
152 luciversion=version.luciversion,
153 distname=version.distname,
154 distversion=version.distversion
158 cursor:foreach("freifunk", "public", function(s)
159 root.freifunk[s[".name"]] = s
162 cursor:foreach("system", "system", function(s)
164 latitude = s.latitude,
165 longitude = s.longitude
170 root.wireless = {devices = {}, interfaces = {}, status = {}}
171 local wifs = root.wireless.interfaces
172 local wifidata = luci.sys.wifi.getiwconfig() or {}
173 local netdata = luci.sys.net.deviceinfo() or {}
175 for _, vif in ipairs(ffwifs) do
176 root.network[vif] = cursor:get_all("network", vif)
177 root.wireless.devices[vif] = cursor:get_all("wireless", vif)
178 cursor:foreach("wireless", "wifi-iface", function(s)
179 if s.device == vif and s.network == vif then
182 root.wireless.status[s.ifname] = wifidata[s.ifname]
188 root.olsrd = fetch_olsrd()
190 http.prepare_content("application/json")
191 ltn12.pump.all(json.Encoder(root):source(), http.write)