From 15345d3615c3956c3f8fb86a03e180a8c13f0e97 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 14 Sep 2008 01:05:11 +0000 Subject: [PATCH] Reworked Freifunk public status pages --- .../luasrc/controller/freifunk/freifunk.lua | 5 +- .../luasrc/model/cbi/freifunk/freifunk.lua | 8 - .../luasrc/model/cbi/freifunk/public_status.lua | 173 +++++++++++++++++++++ .../freifunk/luasrc/view/public_status/index.htm | 97 ------------ 4 files changed, 175 insertions(+), 108 deletions(-) create mode 100644 modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua delete mode 100644 modules/freifunk/luasrc/view/public_status/index.htm diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua index 07b12f3f7..af584cd83 100644 --- a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua @@ -39,14 +39,13 @@ function index() local page = node("freifunk", "status") - page.target = call("action_status") + page.target = form("freifunk/public_status") page.title = "Status" page.order = 20 + page.i18n = "admin-core" page.setuser = false page.setgroup = false - assign({"freifunk", "status", "iwscan"}, {"admin", "status", "iwscan"}, "WLAN-Scan", 20) - assign({"freifunk", "olsr"}, {"admin", "status", "olsr"}, "OLSR", 30) if luci.fs.isfile("/etc/config/luci_statistics") then diff --git a/modules/freifunk/luasrc/model/cbi/freifunk/freifunk.lua b/modules/freifunk/luasrc/model/cbi/freifunk/freifunk.lua index 54d984988..f1bf64163 100644 --- a/modules/freifunk/luasrc/model/cbi/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/model/cbi/freifunk/freifunk.lua @@ -18,14 +18,6 @@ für die lokale Freifunkgemeinschaft. Diese Werte wirken sich NICHT auf die Konf des Routers aus, sondern definieren nur die Vorgaben für den Freifunkassistenten.]]) c:option(Value, "name", "Gemeinschaft") c:option(Value, "homepage", "Webseite") -c:option(Value, "essid", "ESSID") -c:option(Value, "bssid", "BSSID") -c:option(Value, "channel", "Funkkanal") c:option(Value, "realm", "Realm") -c:option(Value, "net", "Adressbereich") -c:option(Value, "mask", "Netzmaske") -c:option(Value, "dns", "DNS-Server") -c:option(Value, "dhcp", "DHCP-Bereich") -c:option(Value, "dhcpmask", "DHCP-Maske") return m \ No newline at end of file diff --git a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua new file mode 100644 index 000000000..08201f703 --- /dev/null +++ b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua @@ -0,0 +1,173 @@ +require "luci.sys" +require "luci.tools.webadmin" + +local uci = luci.model.uci.cursor_state() + +local ffzone = luci.tools.webadmin.firewall_find_zone("freifunk") +local ffznet = ffzone and uci:get("firewall", ffzone, "network") +local ffwifs = ffznet and luci.util.split(ffznet, " ") or {} + +-- System -- + +f = SimpleForm("system", "System") +f.submit = false +f.reset = false +local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo() +local uptime = luci.sys.uptime() + +f:field(DummyValue, "_system", translate("system")).value = system +f:field(DummyValue, "_cpu", translate("m_i_processor")).value = model + +local load1, load5, load15 = luci.sys.loadavg() +f:field(DummyValue, "_la", translate("load")).value = +string.format("%.2f, %.2f, %.2f", load1, load5, load15) + +f:field(DummyValue, "_memtotal", translate("m_i_memory")).value = +string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", + tonumber(memtotal) / 1024, + 100 * memcached / memtotal, + translate("mem_cached") or "", + 100 * membuffers / memtotal, + translate("mem_buffered") or "", + 100 * memfree / memtotal, + translate("mem_free") or "") + +f:field(DummyValue, "_systime", translate("m_i_systemtime")).value = +os.date("%c") + +f:field(DummyValue, "_uptime", translate("m_i_uptime")).value = +luci.tools.webadmin.date_format(tonumber(uptime)) + + +-- Wireless -- + +local wireless = uci:get_all("wireless") +local wifidata = luci.sys.wifi.getiwconfig() +local ifaces = {} + +for k, v in pairs(wireless) do + if v[".type"] == "wifi-iface" and luci.util.contains(ffwifs, v.device) then + table.insert(ifaces, v) + end +end + + +m = SimpleForm("wireless", "Freifunk WLAN") +m.submit = false +m.reset = false + +s = m:section(Table, ifaces, translate("networks")) + +link = s:option(DummyValue, "_link", translate("link")) +function link.cfgvalue(self, section) + local ifname = self.map:get(section, "ifname") + return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-" +end + +essid = s:option(DummyValue, "ssid", "ESSID") + +bssid = s:option(DummyValue, "_bsiid", "BSSID") +function bssid.cfgvalue(self, section) + local ifname = self.map:get(section, "ifname") + return (wifidata[ifname] and (wifidata[ifname].Cell + or wifidata[ifname]["Access Point"])) or "-" +end + +channel = s:option(DummyValue, "channel", translate("channel")) + function channel.cfgvalue(self, section) + return wireless[self.map:get(section, "device")].channel +end + +protocol = s:option(DummyValue, "_mode", translate("protocol")) +function protocol.cfgvalue(self, section) + local mode = wireless[self.map:get(section, "device")].mode + return mode and "802." .. mode +end + +mode = s:option(DummyValue, "mode", translate("mode")) +encryption = s:option(DummyValue, "encryption", translate("iwscan_encr")) + +power = s:option(DummyValue, "_power", translate("power")) +function power.cfgvalue(self, section) + local ifname = self.map:get(section, "ifname") + return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-" +end + +scan = s:option(Button, "_scan", translate("scan")) +scan.inputstyle = "find" + +function scan.cfgvalue(self, section) + return self.map:get(section, "ifname") or false +end + +t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1")) + +function scan.write(self, section) + t2.render = t2._render + local ifname = self.map:get(section, "ifname") + luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname)) +end + +t2._render = t2.render +t2.render = function() end + +t2:option(DummyValue, "Quality", translate("iwscan_link")) +essid = t2:option(DummyValue, "ESSID", "ESSID") +function essid.cfgvalue(self, section) + return luci.util.pcdata(self.map:get(section, "ESSID")) +end + +t2:option(DummyValue, "Address", "BSSID") +t2:option(DummyValue, "Mode", translate("mode")) +chan = t2:option(DummyValue, "channel", translate("channel")) +function chan.cfgvalue(self, section) + return self.map:get(section, "Channel") + or self.map:get(section, "Frequency") + or "-" +end + +t2:option(DummyValue, "Encryption key", translate("iwscan_encr")) + +t2:option(DummyValue, "Signal level", translate("iwscan_signal")) + +t2:option(DummyValue, "Noise level", translate("iwscan_noise")) + + +-- Routes -- +r = SimpleForm("routes", "Standardrouten") +r.submit = false +r.reset = false +local routes = {} +for i, route in ipairs(luci.sys.net.routes()) do + if route.Destination == "00000000" then + routes[#routes+1] = route + end +end + +v = r:section(Table, routes) + +net = v:option(DummyValue, "iface", translate("network")) +function net.cfgvalue(self, section) + return luci.tools.webadmin.iface_get_network(routes[section].Iface) + or routes[section].Iface +end + +target = v:option(DummyValue, "target", translate("target")) +function target.cfgvalue(self, section) + return luci.ip.Hex(routes[section].Destination, 32):string() +end + +netmask = v:option(DummyValue, "netmask", translate("netmask")) +function netmask.cfgvalue(self, section) + return luci.ip.Hex(routes[section].Mask, 32):string() +end + +gateway = v:option(DummyValue, "gateway", translate("gateway")) +function gateway.cfgvalue(self, section) + return luci.ip.Hex(routes[section].Gateway, 32):string() +end + +metric = v:option(DummyValue, "Metric", translate("metric")) + + +return f, m, r diff --git a/modules/freifunk/luasrc/view/public_status/index.htm b/modules/freifunk/luasrc/view/public_status/index.htm deleted file mode 100644 index aa56834ba..000000000 --- a/modules/freifunk/luasrc/view/public_status/index.htm +++ /dev/null @@ -1,97 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -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$ - --%> -<%+header%> -

<%:status%>

-

<%:system%>

- -
- - - - - - - - - - - - - -
<%:system_type%>:<%=system%>
<%:cpu%>:<%=model%>
<%:ram%>:
<%:total%>/<%:cached%>/<%:buffers%>/<%:free%>
<%=memtotal%> / <%=memcached%> / <%=membuffers%> / <%=memfree%> KB
-
-
-
-
-
-
-

- -

<%:wifi%>

-
- - - - - - - - - - - - - -<%for k, v in pairs(luci.sys.wifi.getiwconfig()) do -%> - - - - - - - - - - - - - - - - -<%end%> -
<%:name%><%:protocol%><%:frequency%><%:power%><%:bitrate%><%:rts%><%:frag%><%:link%><%:signal%><%:noise%>
<%=k%><%=v[1]%><%=v.Frequency%><%=v["Tx-Power"]%><%=v["Bit Rate"]%><%=v["RTS thr"]%><%=v["Fragment thr"]%><%=v["Link Quality"]%><%=v["Signal level"]%><%=v["Noise level"]%>
ESSID: <%=v.ESSID%>BSSID: <%=(v.Cell or v["Access Point"])%>
-
-
-

<%:defroutes%>

-
- - - - - - -<% -for i, rt in pairs(routes) do -%> - - -<% end %> -
<%:gateway%><%:metric%><%:iface%>
<%=luci.ip.Hex(rt.Gateway, 32):string()%> -<%=rt.Metric%> -<%=rt.Iface%> -
-<%+footer%> \ No newline at end of file -- 2.11.0