2008-06-08 08:14:31 +00:00
|
|
|
--[[
|
|
|
|
LuCI - Lua Configuration Interface
|
|
|
|
|
|
|
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
]]--
|
2011-08-12 13:16:27 +00:00
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
module("luci.controller.freifunk.freifunk", package.seeall)
|
2008-05-08 16:14:49 +00:00
|
|
|
|
2008-05-22 14:04:03 +00:00
|
|
|
function index()
|
2010-12-21 22:07:57 +00:00
|
|
|
local uci = require "luci.model.uci".cursor()
|
2011-08-12 13:16:27 +00:00
|
|
|
local page
|
2008-06-03 20:22:54 +00:00
|
|
|
|
2011-01-25 21:04:57 +00:00
|
|
|
-- Frontend
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node()
|
|
|
|
page.lock = true
|
|
|
|
page.target = alias("freifunk")
|
2008-10-09 20:28:07 +00:00
|
|
|
page.subindex = true
|
2011-08-12 13:16:27 +00:00
|
|
|
page.index = false
|
2008-05-22 14:04:03 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("freifunk")
|
|
|
|
page.title = _("Freifunk")
|
2008-05-22 14:04:03 +00:00
|
|
|
page.target = alias("freifunk", "index")
|
|
|
|
page.order = 5
|
|
|
|
page.setuser = "nobody"
|
|
|
|
page.setgroup = "nogroup"
|
2008-06-09 20:11:19 +00:00
|
|
|
page.i18n = "freifunk"
|
2008-10-09 20:28:07 +00:00
|
|
|
page.index = true
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("freifunk", "index")
|
|
|
|
page.target = template("freifunk/index")
|
|
|
|
page.title = _("Overview")
|
|
|
|
page.order = 10
|
2008-10-09 20:28:07 +00:00
|
|
|
page.indexignore = true
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2011-10-10 08:32:46 +00:00
|
|
|
page = node("freifunk", "contact")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.target = template("freifunk/contact")
|
|
|
|
page.title = _("Contact")
|
2011-10-10 08:32:46 +00:00
|
|
|
page.order = 15
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("freifunk", "status")
|
|
|
|
page.target = template("freifunk/public_status")
|
|
|
|
page.title = _("Status")
|
|
|
|
page.order = 20
|
|
|
|
page.i18n = "base"
|
2008-05-22 14:04:03 +00:00
|
|
|
page.setuser = false
|
2011-10-10 16:04:27 +00:00
|
|
|
page.setgroup = false
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2009-01-08 17:14:56 +00:00
|
|
|
entry({"freifunk", "status.json"}, call("jsonstatus"))
|
2010-12-15 16:35:19 +00:00
|
|
|
entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload")
|
|
|
|
entry({"freifunk", "status", "public_status_json"}, call("public_status_json")).leaf = true
|
2009-01-08 17:14:56 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, _("OLSR"), 30)
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2009-07-19 00:24:58 +00:00
|
|
|
if nixio.fs.access("/etc/config/luci_statistics") then
|
2011-08-12 13:16:27 +00:00
|
|
|
assign({"freifunk", "graph"}, {"admin", "statistics", "graph"}, _("Statistics"), 40)
|
2008-06-03 20:22:54 +00:00
|
|
|
end
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2011-01-25 21:04:57 +00:00
|
|
|
-- backend
|
2011-08-12 13:16:27 +00:00
|
|
|
assign({"mini", "freifunk"}, {"admin", "freifunk"}, _("Freifunk"), 5)
|
|
|
|
entry({"admin", "freifunk"}, alias("admin", "freifunk", "index"), _("Freifunk"), 5)
|
2011-01-25 21:04:57 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.target = template("freifunk/adminindex")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Freifunk")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 5
|
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk", "basics")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.target = cbi("freifunk/basics")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Basic Settings")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 5
|
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk", "basics", "profile")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.target = cbi("freifunk/profile")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Profile")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 10
|
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk", "basics", "profile_expert")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.target = cbi("freifunk/profile_expert")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Profile (Expert)")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 20
|
2008-11-29 20:46:26 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk", "Index-Page")
|
2010-11-18 03:29:17 +00:00
|
|
|
page.target = cbi("freifunk/user_index")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Index Page")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 50
|
2010-11-18 03:29:17 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
page = node("admin", "freifunk", "contact")
|
2008-05-22 14:04:03 +00:00
|
|
|
page.target = cbi("freifunk/contact")
|
2011-08-12 13:16:27 +00:00
|
|
|
page.title = _("Contact")
|
2011-01-25 21:04:57 +00:00
|
|
|
page.order = 15
|
2009-05-25 13:53:31 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
entry({"freifunk", "map"}, template("freifunk-map/frame"), _("Map"), 50)
|
2009-05-25 13:53:31 +00:00
|
|
|
entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
|
2011-02-19 14:54:16 +00:00
|
|
|
entry({"admin", "freifunk", "profile_error"}, template("freifunk/profile_error"))
|
2008-05-22 14:04:03 +00:00
|
|
|
end
|
2009-01-08 17:14:56 +00:00
|
|
|
|
|
|
|
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
|
2009-07-19 00:24:58 +00:00
|
|
|
if nixio.fs.access("/proc/net/ipv6_route", "r") then
|
2009-01-08 17:14:56 +00:00
|
|
|
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
|
|
|
|
|
2009-04-09 13:56:04 +00:00
|
|
|
function zeroes()
|
|
|
|
local string = require "string"
|
|
|
|
local http = require "luci.http"
|
|
|
|
local zeroes = string.rep(string.char(0), 8192)
|
|
|
|
local cnt = 0
|
|
|
|
local lim = 1024 * 1024 * 1024
|
|
|
|
|
|
|
|
http.prepare_content("application/x-many-zeroes")
|
|
|
|
|
|
|
|
while cnt < lim do
|
|
|
|
http.write(zeroes)
|
|
|
|
cnt = cnt + #zeroes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-08 17:14:56 +00:00
|
|
|
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"
|
2009-01-26 10:20:18 +00:00
|
|
|
local version = require "luci.version"
|
2009-01-08 17:14:56 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2009-01-26 10:20:18 +00:00
|
|
|
root.firmware = {
|
|
|
|
luciname=version.luciname,
|
|
|
|
luciversion=version.luciversion,
|
|
|
|
distname=version.distname,
|
|
|
|
distversion=version.distversion
|
|
|
|
}
|
2009-01-08 17:14:56 +00:00
|
|
|
|
|
|
|
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
|
2010-12-15 16:35:19 +00:00
|
|
|
|
|
|
|
function public_status_json()
|
|
|
|
local twa = require "luci.tools.webadmin"
|
|
|
|
local sys = require "luci.sys"
|
|
|
|
local i18n = require "luci.i18n"
|
|
|
|
local path = luci.dispatcher.context.requestpath
|
|
|
|
local rv = { }
|
|
|
|
|
|
|
|
local dev
|
|
|
|
for dev in path[#path]:gmatch("[%w%.%-]+") do
|
|
|
|
local j = { id = dev }
|
|
|
|
local iw = luci.sys.wifi.getiwinfo(dev)
|
|
|
|
if iw then
|
|
|
|
local f
|
|
|
|
for _, f in ipairs({
|
|
|
|
"channel", "txpower", "bitrate", "signal", "noise",
|
|
|
|
"quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
|
|
|
|
}) do
|
|
|
|
j[f] = iw[f]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rv[#rv+1] = j
|
|
|
|
end
|
|
|
|
|
|
|
|
local load1, load5, load15 = sys.loadavg()
|
|
|
|
|
|
|
|
local _, _, memtotal, memcached, membuffers, memfree = sys.sysinfo()
|
|
|
|
local mem = string.format("%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)",
|
|
|
|
tonumber(memtotal) / 1024,
|
|
|
|
tonumber(memtotal - memfree) / 1024,
|
|
|
|
tostring(i18n.translate("used")),
|
|
|
|
memfree / 1024,
|
|
|
|
tostring(i18n.translate("free")),
|
|
|
|
memcached / 1024,
|
|
|
|
tostring(i18n.translate("cached")),
|
|
|
|
membuffers / 1024,
|
|
|
|
tostring(i18n.translate("buffered"))
|
|
|
|
)
|
2010-12-17 03:35:17 +00:00
|
|
|
|
2010-12-15 16:35:19 +00:00
|
|
|
local dr4 = sys.net.defaultroute()
|
|
|
|
local dr6 = sys.net.defaultroute6()
|
2010-12-17 03:35:17 +00:00
|
|
|
|
|
|
|
if dr6 then
|
|
|
|
def6 = {
|
|
|
|
gateway = dr6.nexthop:string(),
|
|
|
|
dest = dr6.dest:string(),
|
|
|
|
dev = dr6.device,
|
|
|
|
metr = dr6.metric }
|
|
|
|
end
|
|
|
|
|
|
|
|
if dr4 then
|
|
|
|
def4 = {
|
|
|
|
gateway = dr4.gateway:string(),
|
|
|
|
dest = dr4.dest:string(),
|
|
|
|
dev = dr4.device,
|
|
|
|
metr = dr4.metric }
|
2011-10-10 16:04:27 +00:00
|
|
|
else
|
|
|
|
local dr = sys.exec("ip r s t olsr-default")
|
|
|
|
if dr then
|
|
|
|
local dest, gateway, dev, metr = dr:match("^(%w+) via (%d+.%d+.%d+.%d+) dev (%w+) +metric (%d+)")
|
|
|
|
def4 = {
|
|
|
|
dest = dest,
|
|
|
|
gateway = gateway,
|
|
|
|
dev = dev,
|
|
|
|
metr = metr
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2010-12-17 03:35:17 +00:00
|
|
|
|
2010-12-15 16:35:19 +00:00
|
|
|
rv[#rv+1] = {
|
2011-04-04 12:04:42 +00:00
|
|
|
time = os.date("%a, %d %b %Y, %H:%M:%S"),
|
2010-12-15 16:35:19 +00:00
|
|
|
uptime = twa.date_format(tonumber(sys.uptime())),
|
|
|
|
load = string.format("%.2f, %.2f, %.2f", load1, load5, load15),
|
|
|
|
mem = mem,
|
2010-12-17 03:35:17 +00:00
|
|
|
defroutev4 = def4,
|
|
|
|
defroutev6 = def6
|
2010-12-15 16:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
|
|
|
luci.http.write_json(rv)
|
|
|
|
return
|
|
|
|
end
|