entry({"freifunk", "status.json"}, call("jsonstatus"))
entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload")
- entry({"freifunk", "status", "public_status_json"}, call("public_status_json")).leaf = true
if nixio.fs.access("/usr/sbin/luci-splash") then
assign({"freifunk", "status", "splash"}, {"splash", "publicstatus"}, _("Splash"), 40)
http.prepare_content("application/json")
ltn12.pump.all(json.Encoder(root):source(), http.write)
end
-
-function public_status_json(devs)
- local twa = require "luci.tools.webadmin"
- local sys = require "luci.sys"
- local i18n = require "luci.i18n"
- local rv = { }
-
- local dev
- for dev in devs: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"))
- )
-
- local dr4 = sys.net.defaultroute()
- local dr6 = sys.net.defaultroute6()
-
- 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 }
- 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
-
- rv[#rv+1] = {
- time = os.date("%a, %d %b %Y, %H:%M:%S"),
- uptime = twa.date_format(tonumber(sys.uptime())),
- load = string.format("%.2f, %.2f, %.2f", load1, load5, load15),
- mem = mem,
- defroutev4 = def4,
- defroutev6 = def6
- }
-
- luci.http.prepare_content("application/json")
- luci.http.write_json(rv)
- return
-end
<%
-
local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"
-- System
local model, system, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
local uptime = twa.date_format(tonumber(sys.uptime()))
-local_time = os.date("%a, %d %b %Y, %H:%M:%S")
+local time = os.date("%a, %d %b %Y, %H:%M:%S")
local load1, load5, load15 = sys.loadavg()
local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)
defroutev4.dest = defroutev4.dest:string()
defroutev4.gateway = defroutev4.gateway:string()
else
+ -- probably policy routing activated, try olsr-default table
local dr4 = sys.exec("ip r s t olsr-default")
if dr4 then
defroutev4 = { }
- defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev (%w+) +metric (%d+)")
+ defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
end
end
+if defroutev6 then
+ defroutev6.dest = defroutev6.dest:string()
+ defroutev6.nexthop = defroutev6.nexthop:string()
+end
+if luci.http.formvalue("status") == "1" then
+ local rv = { }
+ for dev in ipairs(netdevs) 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
+
+ if defroutev6 then
+ def6 = {
+ gateway = defroutev6.nexthop,
+ dest = defroutev6.dest,
+ dev = defroutev6.device,
+ metr = defroutev6.metric
+ }
+ end
+
+ if defroutev4 then
+ def4 = {
+ gateway = defroutev4.gateway,
+ dest = defroutev4.dest,
+ dev = defroutev4.device,
+ metr = defroutev4.metric
+ }
+ end
+
+ rv[#rv+1] = {
+ time = time,
+ uptime = uptime,
+ load = load,
+ mem = mem,
+ defroutev4 = def4,
+ defroutev6 = def6
+ }
+
+ luci.http.prepare_content("application/json")
+ luci.http.write_json(rv)
+ return
+end
-%>
<%+header%>
-
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
- XHR.poll(<%=interval%>, '<%=luci.dispatcher.build_url("freifunk", "status", "public_status_json", table.concat(netlist, ","))%>', null,
+ XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
function(x, st)
{
if (st)
if defroutev6 then %>
<tr class="cbi-section-table-row cbi-rowstyle-2">
- <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest:string()%></td>
+ <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
<td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
- <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop:string()%></td>
+ <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
<td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>
</tr>