modules/freifunk: fix same problem
[project/luci.git] / modules / freifunk / luasrc / model / cbi / freifunk / public_status.lua
index 5971e2a..2192697 100644 (file)
@@ -1,6 +1,7 @@
 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")
@@ -26,11 +27,11 @@ 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 "",
+       tostring(translate("mem_cached"), "")),
        100 * membuffers / memtotal,
-       translate("mem_buffered") or "",
+       tostring(translate("mem_buffered", "")),
        100 * memfree / memtotal,
-       translate("mem_free") or "")
+       tostring(translate("mem_free", ""))
 
 f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
 os.date("%c")
@@ -46,7 +47,10 @@ 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
+       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
@@ -175,33 +179,38 @@ end
 
 
 local routes6 = {}
-for i, route in ipairs(luci.sys.net.routes6()) do
+for i, route in ipairs(luci.sys.net.routes6() or {}) do
        if route.dest:prefix() == 0 then
                routes6[#routes6+1] = route
        end
 end
 
-v6 = r:section(Table, routes6)
+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(routes[section].device)
-       or routes6[section].device
-end
+       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
+       target  = v6:option(DummyValue, "target", translate("target"))
+       function target.cfgvalue(self, section)
+               return routes6[section].dest:string()
+       end
 
-gateway = v6:option(DummyValue, "gateway6", translate("gateway6"))
-function gateway.cfgvalue(self, section)
-       return routes6[section].source:string()
-end
+       gateway = v6:option(DummyValue, "gateway6", translate("gateway6"))
+       function gateway.cfgvalue(self, section)
+               return routes6[section].source:string()
+       end
 
-metric = v6:option(DummyValue, "metric", translate("metric"))
-function metric.cfgvalue(self, section)
-       return string.format("%X", routes6[section].metric)
+       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