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")
50 page.i18n = "admin-core"
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 luci.fs.access("/etc/config/luci_statistics") then
60 assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, i18n("stat_statistics", "Statistiken"), 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"
76 local function fetch_olsrd()
77 local sys = require "luci.sys"
78 local util = require "luci.util"
79 local table = require "table"
80 local rawdata = sys.httpget("http://127.0.0.1:2006/")
83 if luci.fs.access("/proc/net/ipv6_route", "r") then
84 rawdata = sys.httpget("http://[::1]:2006/")
95 local tables = util.split(util.trim(rawdata), "\r?\n\r?\n", nil, true)
98 for i, tbl in ipairs(tables) do
99 local lines = util.split(tbl, "\r?\n", nil, true)
100 local name = table.remove(lines, 1):sub(8)
101 local keys = util.split(table.remove(lines, 1), "\t")
102 local split = #keys - 1
106 for j, line in ipairs(lines) do
107 local fields = util.split(line, "\t", split)
109 for k, key in pairs(keys) do
110 data[name][j][key] = fields[k]
113 if data[name][j].Linkcost then
114 data[name][j].LinkQuality,
117 data[name][j].Linkcost:match("([%w.]+)/([%w.]+)[%s]+([%w.]+)")
126 local string = require "string"
127 local http = require "luci.http"
128 local zeroes = string.rep(string.char(0), 8192)
130 local lim = 1024 * 1024 * 1024
132 http.prepare_content("application/x-many-zeroes")
140 function jsonstatus()
142 local sys = require "luci.sys"
143 local uci = require "luci.model.uci"
144 local util = require "luci.util"
145 local http = require "luci.http"
146 local json = require "luci.json"
147 local ltn12 = require "luci.ltn12"
148 local version = require "luci.version"
149 local webadmin = require "luci.tools.webadmin"
151 local cursor = uci.cursor_state()
153 local ffzone = webadmin.firewall_find_zone("freifunk")
154 local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
155 local ffwifs = ffznet and util.split(ffznet, " ") or {}
161 uptime = {sys.uptime()},
162 loadavg = {sys.loadavg()},
163 sysinfo = {sys.sysinfo()},
164 hostname = sys.hostname()
168 luciname=version.luciname,
169 luciversion=version.luciversion,
170 distname=version.distname,
171 distversion=version.distversion
175 cursor:foreach("freifunk", "public", function(s)
176 root.freifunk[s[".name"]] = s
179 cursor:foreach("system", "system", function(s)
181 latitude = s.latitude,
182 longitude = s.longitude
187 root.wireless = {devices = {}, interfaces = {}, status = {}}
188 local wifs = root.wireless.interfaces
189 local wifidata = luci.sys.wifi.getiwconfig() or {}
190 local netdata = luci.sys.net.deviceinfo() or {}
192 for _, vif in ipairs(ffwifs) do
193 root.network[vif] = cursor:get_all("network", vif)
194 root.wireless.devices[vif] = cursor:get_all("wireless", vif)
195 cursor:foreach("wireless", "wifi-iface", function(s)
196 if s.device == vif and s.network == vif then
199 root.wireless.status[s.ifname] = wifidata[s.ifname]
205 root.olsrd = fetch_olsrd()
207 http.prepare_content("application/json")
208 ltn12.pump.all(json.Encoder(root):source(), http.write)