2 require "luci.tools.webadmin"
4 local bit = require "bit"
5 local uci = luci.model.uci.cursor_state()
7 local ffzone = luci.tools.webadmin.firewall_find_zone("freifunk")
8 local ffznet = ffzone and uci:get("firewall", ffzone, "network")
9 local ffwifs = ffznet and luci.util.split(ffznet, " ") or {}
13 f = SimpleForm("system", "System")
16 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
17 local uptime = luci.sys.uptime()
19 f:field(DummyValue, "_system", translate("system")).value = system
20 f:field(DummyValue, "_cpu", translate("m_i_processor")).value = model
22 local load1, load5, load15 = luci.sys.loadavg()
23 f:field(DummyValue, "_la", translate("load")).value =
24 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
26 f:field(DummyValue, "_memtotal", translate("m_i_memory")).value =
27 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
28 tonumber(memtotal) / 1024,
29 100 * memcached / memtotal,
30 translate("mem_cached") or "",
31 100 * membuffers / memtotal,
32 translate("mem_buffered") or "",
33 100 * memfree / memtotal,
34 translate("mem_free") or "")
36 f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
39 f:field(DummyValue, "_uptime", translate("m_i_uptime")).value =
40 luci.tools.webadmin.date_format(tonumber(uptime))
45 local wireless = uci:get_all("wireless")
46 local wifidata = luci.sys.wifi.getiwconfig()
49 for k, v in pairs(wireless) do
50 if v[".type"] == "wifi-iface" and luci.util.contains(ffwifs, v.device) then
51 table.insert(ifaces, v)
56 m = SimpleForm("wireless", "Freifunk WLAN")
60 s = m:section(Table, ifaces, translate("networks"))
62 link = s:option(DummyValue, "_link", translate("link"))
63 function link.cfgvalue(self, section)
64 local ifname = self.map:get(section, "ifname")
65 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
68 essid = s:option(DummyValue, "ssid", "ESSID")
70 bssid = s:option(DummyValue, "_bsiid", "BSSID")
71 function bssid.cfgvalue(self, section)
72 local ifname = self.map:get(section, "ifname")
73 return (wifidata[ifname] and (wifidata[ifname].Cell
74 or wifidata[ifname]["Access Point"])) or "-"
77 channel = s:option(DummyValue, "channel", translate("channel"))
78 function channel.cfgvalue(self, section)
79 return wireless[self.map:get(section, "device")].channel
82 protocol = s:option(DummyValue, "_mode", translate("protocol"))
83 function protocol.cfgvalue(self, section)
84 local mode = wireless[self.map:get(section, "device")].mode
85 return mode and "802." .. mode
88 mode = s:option(DummyValue, "mode", translate("mode"))
89 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
91 power = s:option(DummyValue, "_power", translate("power"))
92 function power.cfgvalue(self, section)
93 local ifname = self.map:get(section, "ifname")
94 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
97 scan = s:option(Button, "_scan", translate("scan"))
98 scan.inputstyle = "find"
100 function scan.cfgvalue(self, section)
101 return self.map:get(section, "ifname") or false
104 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
106 function scan.write(self, section)
107 t2.render = t2._render
108 local ifname = self.map:get(section, "ifname")
109 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
112 t2._render = t2.render
113 t2.render = function() end
115 t2:option(DummyValue, "Quality", translate("iwscan_link"))
116 essid = t2:option(DummyValue, "ESSID", "ESSID")
117 function essid.cfgvalue(self, section)
118 return luci.util.pcdata(self.map:get(section, "ESSID"))
121 t2:option(DummyValue, "Address", "BSSID")
122 t2:option(DummyValue, "Mode", translate("mode"))
123 chan = t2:option(DummyValue, "channel", translate("channel"))
124 function chan.cfgvalue(self, section)
125 return self.map:get(section, "Channel")
126 or self.map:get(section, "Frequency")
130 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
132 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
134 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
138 r = SimpleForm("routes", "Standardrouten")
143 for i, route in ipairs(luci.sys.net.routes()) do
144 if route.dest:prefix() == 0 then
145 routes[#routes+1] = route
149 v = r:section(Table, routes)
151 net = v:option(DummyValue, "iface", translate("network"))
152 function net.cfgvalue(self, section)
153 return luci.tools.webadmin.iface_get_network(routes[section].device)
154 or routes[section].device
157 target = v:option(DummyValue, "target", translate("target"))
158 function target.cfgvalue(self, section)
159 return routes[section].dest:network():string()
162 netmask = v:option(DummyValue, "netmask", translate("netmask"))
163 function netmask.cfgvalue(self, section)
164 return routes[section].dest:mask():string()
167 gateway = v:option(DummyValue, "gateway", translate("gateway"))
168 function gateway.cfgvalue(self, section)
169 return routes[section].gateway:string()
172 metric = v:option(DummyValue, "metric", translate("metric"))
173 function metric.cfgvalue(self, section)
174 return routes[section].metric
179 for i, route in ipairs(luci.sys.net.routes6() or {}) do
180 if route.dest:prefix() == 0 then
181 routes6[#routes6+1] = route
186 v6 = r:section(Table, routes6)
188 net = v6:option(DummyValue, "iface", translate("network"))
189 function net.cfgvalue(self, section)
190 return luci.tools.webadmin.iface_get_network(routes[section].device)
191 or routes6[section].device
194 target = v6:option(DummyValue, "target", translate("target"))
195 function target.cfgvalue(self, section)
196 return routes6[section].dest:string()
199 gateway = v6:option(DummyValue, "gateway6", translate("gateway6"))
200 function gateway.cfgvalue(self, section)
201 return routes6[section].source:string()
204 metric = v6:option(DummyValue, "metric", translate("metric"))
205 function metric.cfgvalue(self, section)
206 local metr = routes6[section].metric
207 local lower = bit.band(metr, 0xffff)
208 local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
209 return "%04X%04X" % {higher, lower}