From f71776c1cda35263e70659c5ea54a8d5822dba97 Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Fri, 26 Nov 2010 11:01:08 +0000 Subject: [PATCH] modules/freifunk: Rewrite status as view and use iwinfo --- .../luasrc/controller/freifunk/freifunk.lua | 4 +- .../model/cbi/freifunk/public_status.lua | 217 ------------------ .../luasrc/view/freifunk/public_status.htm | 173 ++++++++++++++ po/de/freifunk.po | 10 +- po/templates/freifunk.pot | 8 + 5 files changed, 192 insertions(+), 220 deletions(-) delete mode 100644 modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua create mode 100644 modules/freifunk/luasrc/view/freifunk/public_status.htm diff --git a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua index 6df681afd..49ce9adef 100644 --- a/modules/freifunk/luasrc/controller/freifunk/freifunk.lua +++ b/modules/freifunk/luasrc/controller/freifunk/freifunk.lua @@ -42,12 +42,12 @@ function index() page.title = "Kontakt" local page = node("freifunk", "status") - page.target = form("freifunk/public_status") + page.target = template("freifunk/public_status") page.title = i18n("Status") page.order = 20 page.i18n = "base" page.setuser = false - page.setgroup = false + page.setgroup = false entry({"freifunk", "status.json"}, call("jsonstatus")) entry({"freifunk", "status", "zeroes"}, call("zeroes"), "Testdownload") diff --git a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua deleted file mode 100644 index 80754852f..000000000 --- a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua +++ /dev/null @@ -1,217 +0,0 @@ -require "luci.sys" -require "luci.tools.webadmin" - -local bit = require "bit" -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("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("Memory")).value = -string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", - tonumber(memtotal) / 1024, - 100 * memcached / memtotal, - tostring(translate("cached")), - 100 * membuffers / memtotal, - tostring(translate("buffered")), - 100 * memfree / memtotal, - tostring(translate("free")) -) - -f:field(DummyValue, "_systime", translate("Local Time")).value = -os.date("%c") - -f:field(DummyValue, "_uptime", translate("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) or - ( #ffwifs == 0 and (not v.encryption or v.encryption == "none") ) ) - 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")].hwmode - return mode and "802." .. mode -end - -mode = s:option(DummyValue, "mode", translate("Mode")) -encryption = s:option(DummyValue, "encryption", translate("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("WLAN-Scan"), translate("Wifi networks in your local environment")) - -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("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("Encr.")) - -t2:option(DummyValue, "Signal level", translate("Signal")) - -t2:option(DummyValue, "Noise level", translate("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.dest:prefix() == 0 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].device) - or routes[section].device -end - -target = v:option(DummyValue, "target", translate("Target")) -function target.cfgvalue(self, section) - return routes[section].dest:network():string() -end - -netmask = v:option(DummyValue, "netmask", translate("IPv4-Netmask")) -function netmask.cfgvalue(self, section) - return routes[section].dest:mask():string() -end - -gateway = v:option(DummyValue, "gateway", translate("IPv4-Gateway")) -function gateway.cfgvalue(self, section) - return routes[section].gateway:string() -end - -metric = v:option(DummyValue, "metric", translate("Metric")) -function metric.cfgvalue(self, section) - return routes[section].metric -end - - -local routes6 = {} -for i, route in ipairs(luci.sys.net.routes6() or {}) do - if route.dest:prefix() == 0 then - routes6[#routes6+1] = route - end -end - -if #routes6 > 0 then - v6 = r:section(Table, routes6) - - net = v6:option(DummyValue, "iface", translate("Network")) - function net.cfgvalue(self, section) - return luci.tools.webadmin.iface_get_network(routes6[section].device) - or routes6[section].device - end - - target = v6:option(DummyValue, "target", translate("Target")) - function target.cfgvalue(self, section) - return routes6[section].dest:string() - end - - gateway = v6:option(DummyValue, "gateway6", translate("IPv6-Gateway")) - function gateway.cfgvalue(self, section) - return routes6[section].source:string() - end - - metric = v6:option(DummyValue, "metric", translate("Metric")) - function metric.cfgvalue(self, section) - local metr = routes6[section].metric - local lower = bit.band(metr, 0xffff) - local higher = bit.rshift(bit.band(metr, 0xffff0000), 16) - return "%04X%04X" % {higher, lower} - end -end - -return f, m, r diff --git a/modules/freifunk/luasrc/view/freifunk/public_status.htm b/modules/freifunk/luasrc/view/freifunk/public_status.htm new file mode 100644 index 000000000..efeb40566 --- /dev/null +++ b/modules/freifunk/luasrc/view/freifunk/public_status.htm @@ -0,0 +1,173 @@ +<% +local sys = require "luci.sys" +local twa = require "luci.tools.webadmin" + +-- System +local system, model, memtotal, memcached, membuffers, memfree = sys.sysinfo() +local uptime = twa.date_format(tonumber(sys.uptime())) +local_time = os.date("%c") +local load1, load5, load15 = sys.loadavg() +local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15) +local memory = string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", + tonumber(memtotal) / 1024, + 100 * memcached / memtotal, + tostring(translate("cached")), + 100 * membuffers / memtotal, + tostring(translate("buffered")), + 100 * memfree / memtotal, + tostring(translate("free")) +) + +-- wireless +local uci = require "luci.model.uci".cursor() +local ntm = require "luci.model.network" +ntm.init(uci) +local devices = ntm:get_wifidevs() +local netlist = { } +local netdevs = { } +local dev + +-- Routes +local defroutev4 = sys.net.defaultroute() +local defroutev6 = sys.net.defaultroute6 () + +%> +<%+header%> + +
+

<%:System%>

+
+
<%=system%>
+
<%=model%>
+
<%=load%>
+
<%=memory%>
+
<%=local_time%>
+
<%=uptime%>
+
+
+ +<% if devices[1] then %> + +
+

<%:Wireless Overview%>

+
+
+ + + + + + + + + + + + <% + for _, dev in ipairs(devices) do + local net + for _, net in ipairs(dev:get_wifinets()) do + netlist[#netlist+1] = net:ifname() + netdevs[net:ifname()] = dev:name() + + if net.iwdata.ifname then + local signal = net.iwinfo.signal or "N/A" + local noise = net.iwinfo.noise or "N/A" + local q = net.iwinfo.quality or "0" + local qmax = net.iwinfo.quality_max or "100" + local qperc = q / qmax * 100 + + if qperc == 0 then + icon = "signal-none.png" + elseif qperc < 26 then + icon = "signal-0-25.png" + elseif qperc < 51 then + icon = "signal-25-50.png" + elseif qperc < 76 then + icon = "signal-50-75.png" + elseif qperc < 100 then + icon = "signal-75-100.png" + else + icon = "signal-0.png" + end + + signal_string = "Signal Quality" + + local ssid = net.iwinfo.ssid or "N/A" + local bssid = net.iwinfo.bssid or "N/A" + local chan = net.iwinfo.channel or "N/A" + local mode = net.iwinfo.mode or "N/A" + local txpwr = net.iwinfo.txpower or "N/A" + if txpwr ~= "N/A" then + txpwr = txpwr.." dbm" + end + local bitrate = net.iwinfo.bitrate or "N/A" + if bitrate ~= "N/A" then + bitrate = ( bitrate / 1000 ).."Mb/s" + end + local interface = net.iwdata.ifname or "N/A" + %> + + + + + + + + + + + <% end + end + end %> +
<%:Signal%><%:Bitrate%><%:SSID%><%:BSSID%><%:Channel%><%:Mode%><%:TX%>-<%:Power%><%:Interface%>
<%=signal_string%><%=bitrate%><%=ssid%><%=bssid%><%=chan%><%=mode%><%=txpwr%><%=interface%>
+
+
+
+<% end %> + +
+

<%:Default routes%>

+
+
+ + +<% if not defroutev4 and not defroutev6 then %> + <%:No defaultroutes known.%> +<%else%> + + + + + + + + <% if defroutev4 then %> + + + + + + + + + <% end + if defroutev6 then %> + + + + + + + + + <% end %> + +
<%:Network%><%:Interface%><%:Gateway%><%:Metric%>
<%=defroutev4.dest:string()%><%=defroutev4.device%><%=defroutev4.gateway:string()%><%=defroutev4.metric%>
<%=defroutev6.dest:string()%><%=defroutev6.device%><%=defroutev6.nexthop:string()%><%=defroutev6.metric%>
+
+
+
+<% end %> + +<%+footer%> + diff --git a/po/de/freifunk.po b/po/de/freifunk.po index 0ca7278a1..5cb6a3d8e 100644 --- a/po/de/freifunk.po +++ b/po/de/freifunk.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2010-11-18 09:51+0100\n" +"PO-Revision-Date: 2010-11-26 12:02+0100\n" "Last-Translator: Manuel Munz \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -350,3 +350,11 @@ msgstr "Kontakt" #. Please fill in your contact details below. msgid "Please fill in your contact details below." msgstr "Bitte gib hier deine Kontaktdaten an." + +#. Default routes +msgid "Default routes" +msgstr "Standardrouten" + +#. No defaultroutes known. +msgid "No defaultroutes known." +msgstr "Es sind keine Standardrouten bekannt." diff --git a/po/templates/freifunk.pot b/po/templates/freifunk.pot index d67f41a31..7fb94ebc2 100644 --- a/po/templates/freifunk.pot +++ b/po/templates/freifunk.pot @@ -319,3 +319,11 @@ msgstr "" #. Please fill in your contact details below. msgid "Please fill in your contact details below." msgstr "" + +#. Default routes +msgid "Default routes" +msgstr "" + +#. No defaultroutes known. +msgid "No defaultroutes known." +msgstr "" -- 2.25.1