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"
44 entry({"freifunk", "status"}, alias("freifunk", "status", "status"), "Status", 20)
46 local page = node("freifunk", "status", "status")
47 page.target = form("freifunk/public_status")
48 page.title = i18n("Overview")
54 entry({"freifunk", "status.json"}, call("jsonstatus"))
55 entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload")
57 assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30)
59 if nixio.fs.access("/etc/config/luci_statistics") then
60 assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("Statistics"), 40)
63 assign({"mini", "freifunk"}, {"admin", "freifunk"}, "Freifunk", 15)
64 entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), "Freifunk", 15)
65 local page = node("admin", "freifunk", "index")
66 page.target = cbi("freifunk/freifunk")
67 page.title = "Freifunk"
70 local page = node("admin", "freifunk", "contact")
71 page.target = cbi("freifunk/contact")
72 page.title = "Kontakt"
75 entry({"freifunk", "map"}, template("freifunk-map/frame"), i18n("Karte"), 50)
76 entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
79 local function fetch_olsrd()
80 local sys = require "luci.sys"
81 local util = require "luci.util"
82 local table = require "table"
83 local rawdata = sys.httpget("http://127.0.0.1:2006/")
86 if nixio.fs.access("/proc/net/ipv6_route", "r") then
87 rawdata = sys.httpget("http://[::1]:2006/")
98 local tables = util.split(util.trim(rawdata), "\r?\n\r?\n", nil, true)
101 for i, tbl in ipairs(tables) do
102 local lines = util.split(tbl, "\r?\n", nil, true)
103 local name = table.remove(lines, 1):sub(8)
104 local keys = util.split(table.remove(lines, 1), "\t")
105 local split = #keys - 1
109 for j, line in ipairs(lines) do
110 local fields = util.split(line, "\t", split)
112 for k, key in pairs(keys) do
113 data[name][j][key] = fields[k]
116 if data[name][j].Linkcost then
117 data[name][j].LinkQuality,
120 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
129 local string = require "string"
130 local http = require "luci.http"
131 local zeroes = string.rep(string.char(0), 8192)
133 local lim = 1024 * 1024 * 1024
135 http.prepare_content("application/x-many-zeroes")
143 function jsonstatus()
145 local sys = require "luci.sys"
146 local uci = require "luci.model.uci"
147 local util = require "luci.util"
148 local http = require "luci.http"
149 local json = require "luci.json"
150 local ltn12 = require "luci.ltn12"
151 local version = require "luci.version"
152 local webadmin = require "luci.tools.webadmin"
154 local cursor = uci.cursor_state()
156 local ffzone = webadmin.firewall_find_zone("freifunk")
157 local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
158 local ffwifs = ffznet and util.split(ffznet, " ") or {}
164 uptime = {sys.uptime()},
165 loadavg = {sys.loadavg()},
166 sysinfo = {sys.sysinfo()},
167 hostname = sys.hostname()
171 luciname=version.luciname,
172 luciversion=version.luciversion,
173 distname=version.distname,
174 distversion=version.distversion
178 cursor:foreach("freifunk", "public", function(s)
179 root.freifunk[s[".name"]] = s
182 cursor:foreach("system", "system", function(s)
184 latitude = s.latitude,
185 longitude = s.longitude
190 root.wireless = {devices = {}, interfaces = {}, status = {}}
191 local wifs = root.wireless.interfaces
192 local wifidata = luci.sys.wifi.getiwconfig() or {}
193 local netdata = luci.sys.net.deviceinfo() or {}
195 for _, vif in ipairs(ffwifs) do
196 root.network[vif] = cursor:get_all("network", vif)
197 root.wireless.devices[vif] = cursor:get_all("wireless", vif)
198 cursor:foreach("wireless", "wifi-iface", function(s)
199 if s.device == vif and s.network == vif then
202 root.wireless.status[s.ifname] = wifidata[s.ifname]
208 root.olsrd = fetch_olsrd()
210 http.prepare_content("application/json")
211 ltn12.pump.all(json.Encoder(root):source(), http.write)