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
15 module("luci.controller.freifunk.freifunk", package.seeall)
18 local uci = require "luci.model.uci".cursor()
24 page.target = alias("freifunk")
28 page = node("freifunk")
29 page.title = _("Freifunk")
30 page.target = alias("freifunk", "index")
32 page.setuser = "nobody"
33 page.setgroup = "nogroup"
34 page.i18n = "freifunk"
37 page = node("freifunk", "index")
38 page.target = template("freifunk/index")
39 page.title = _("Overview")
41 page.indexignore = true
43 page = node("freifunk", "contact")
44 page.target = template("freifunk/contact")
45 page.title = _("Contact")
48 page = node("freifunk", "status")
49 page.target = template("freifunk/public_status")
50 page.title = _("Status")
56 entry({"freifunk", "status.json"}, call("jsonstatus"))
57 entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload")
59 if nixio.fs.access("/usr/sbin/luci-splash") then
60 assign({"freifunk", "status", "splash"}, {"splash", "publicstatus"}, _("Splash"), 40)
63 page = assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, _("OLSR"), 30)
67 if nixio.fs.access("/etc/config/luci_statistics") then
68 assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, _("Statistics"), 40)
72 assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
73 entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), _("Freifunk"), 5)
75 page = node("admin", "freifunk")
76 page.target = template("freifunk/adminindex")
77 page.title = _("Freifunk")
80 page = node("admin", "freifunk", "basics")
81 page.target = cbi("freifunk/basics")
82 page.title = _("Basic Settings")
85 page = node("admin", "freifunk", "basics", "profile")
86 page.target = cbi("freifunk/profile")
87 page.title = _("Profile")
90 page = node("admin", "freifunk", "basics", "profile_expert")
91 page.target = cbi("freifunk/profile_expert")
92 page.title = _("Profile (Expert)")
95 page = node("admin", "freifunk", "Index-Page")
96 page.target = cbi("freifunk/user_index")
97 page.title = _("Index Page")
100 page = node("admin", "freifunk", "contact")
101 page.target = cbi("freifunk/contact")
102 page.title = _("Contact")
105 entry({"freifunk", "map"}, template("freifunk-map/frame"), _("Map"), 50)
106 entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
107 entry({"admin", "freifunk", "profile_error"}, template("freifunk/profile_error"))
111 local string = require "string"
112 local http = require "luci.http"
113 local zeroes = string.rep(string.char(0), 8192)
115 local lim = 1024 * 1024 * 1024
117 http.prepare_content("application/x-many-zeroes")
125 function jsonstatus()
127 local sys = require "luci.sys"
128 local uci = require "luci.model.uci"
129 local util = require "luci.util"
130 local http = require "luci.http"
131 local json = require "luci.json"
132 local ltn12 = require "luci.ltn12"
133 local version = require "luci.version"
134 local webadmin = require "luci.tools.webadmin"
136 local cursor = uci.cursor_state()
138 local ffzone = webadmin.firewall_find_zone("freifunk")
139 local ffznet = ffzone and cursor:get("firewall", ffzone, "network")
140 local ffwifs = ffznet and util.split(ffznet, " ") or {}
146 uptime = {sys.uptime()},
147 loadavg = {sys.loadavg()},
148 sysinfo = {sys.sysinfo()},
149 hostname = sys.hostname()
153 luciname=version.luciname,
154 luciversion=version.luciversion,
155 distname=version.distname,
156 distversion=version.distversion
160 cursor:foreach("freifunk", "public", function(s)
161 root.freifunk[s[".name"]] = s
164 cursor:foreach("system", "system", function(s)
166 latitude = s.latitude,
167 longitude = s.longitude
172 root.wireless = {devices = {}, interfaces = {}, status = {}}
173 local wifs = root.wireless.interfaces
174 local netdata = luci.sys.net.deviceinfo() or {}
176 for _, vif in ipairs(ffwifs) do
177 root.network[vif] = cursor:get_all("network", vif)
178 root.wireless.devices[vif] = cursor:get_all("wireless", vif)
179 cursor:foreach("wireless", "wifi-iface", function(s)
180 if s.device == vif and s.network == vif then
183 local iwinfo = luci.sys.wifi.getiwinfo(s.ifname)
185 root.wireless.status[s.ifname] = { }
189 "channel", "txpower", "bitrate", "signal", "noise",
190 "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
192 root.wireless.status[s.ifname][f] = iwinfo[f]
200 http.prepare_content("application/json")
201 ltn12.pump.all(json.Encoder(root):source(), http.write)