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("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("Memory")).value =
27 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
28 tonumber(memtotal) / 1024,
29 100 * memcached / memtotal,
30 tostring(translate("cached")),
31 100 * membuffers / memtotal,
32 tostring(translate("buffered")),
33 100 * memfree / memtotal,
34 tostring(translate("free"))
37 f:field(DummyValue, "_systime", translate("Local Time")).value =
40 f:field(DummyValue, "_uptime", translate("Uptime")).value =
41 luci.tools.webadmin.date_format(tonumber(uptime))
46 local wireless = uci:get_all("wireless")
47 local wifidata = luci.sys.wifi.getiwconfig()
50 for k, v in pairs(wireless) do
51 if v[".type"] == "wifi-iface" and (
52 luci.util.contains(ffwifs, v.device) or
53 ( #ffwifs == 0 and (not v.encryption or v.encryption == "none") ) )
55 table.insert(ifaces, v)
60 m = SimpleForm("wireless", "Freifunk WLAN")
64 s = m:section(Table, ifaces, translate("Networks"))
66 link = s:option(DummyValue, "_link", translate("Link"))
67 function link.cfgvalue(self, section)
68 local ifname = self.map:get(section, "ifname")
69 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
72 essid = s:option(DummyValue, "ssid", "ESSID")
74 bssid = s:option(DummyValue, "_bsiid", "BSSID")
75 function bssid.cfgvalue(self, section)
76 local ifname = self.map:get(section, "ifname")
77 return (wifidata[ifname] and (wifidata[ifname].Cell
78 or wifidata[ifname]["Access Point"])) or "-"
81 channel = s:option(DummyValue, "channel", translate("Channel"))
82 function channel.cfgvalue(self, section)
83 return wireless[self.map:get(section, "device")].channel
86 protocol = s:option(DummyValue, "_mode", translate("Protocol"))
87 function protocol.cfgvalue(self, section)
88 local mode = wireless[self.map:get(section, "device")].mode
89 return mode and "802." .. mode
92 mode = s:option(DummyValue, "mode", translate("Mode"))
93 encryption = s:option(DummyValue, "encryption", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
95 power = s:option(DummyValue, "_power", translate("Power"))
96 function power.cfgvalue(self, section)
97 local ifname = self.map:get(section, "ifname")
98 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
101 scan = s:option(Button, "_scan", translate("Scan"))
102 scan.inputstyle = "find"
104 function scan.cfgvalue(self, section)
105 return self.map:get(section, "ifname") or false
108 t2 = m:section(Table, {}, translate("<abbr title=\"Wireless Local Area Network\">WLAN</abbr>-Scan"), translate("Wifi networks in your local environment"))
110 function scan.write(self, section)
111 t2.render = t2._render
112 local ifname = self.map:get(section, "ifname")
113 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
116 t2._render = t2.render
117 t2.render = function() end
119 t2:option(DummyValue, "Quality", translate("Link"))
120 essid = t2:option(DummyValue, "ESSID", "ESSID")
121 function essid.cfgvalue(self, section)
122 return luci.util.pcdata(self.map:get(section, "ESSID"))
125 t2:option(DummyValue, "Address", "BSSID")
126 t2:option(DummyValue, "Mode", translate("Mode"))
127 chan = t2:option(DummyValue, "channel", translate("Channel"))
128 function chan.cfgvalue(self, section)
129 return self.map:get(section, "Channel")
130 or self.map:get(section, "Frequency")
134 t2:option(DummyValue, "Encryption key", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
136 t2:option(DummyValue, "Signal level", translate("Signal"))
138 t2:option(DummyValue, "Noise level", translate("Noise"))
142 r = SimpleForm("routes", "Standardrouten")
147 for i, route in ipairs(luci.sys.net.routes()) do
148 if route.dest:prefix() == 0 then
149 routes[#routes+1] = route
153 v = r:section(Table, routes)
155 net = v:option(DummyValue, "iface", translate("Network"))
156 function net.cfgvalue(self, section)
157 return luci.tools.webadmin.iface_get_network(routes[section].device)
158 or routes[section].device
161 target = v:option(DummyValue, "target", translate("Target"))
162 function target.cfgvalue(self, section)
163 return routes[section].dest:network():string()
166 netmask = v:option(DummyValue, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
167 function netmask.cfgvalue(self, section)
168 return routes[section].dest:mask():string()
171 gateway = v:option(DummyValue, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
172 function gateway.cfgvalue(self, section)
173 return routes[section].gateway:string()
176 metric = v:option(DummyValue, "metric", translate("Metric"))
177 function metric.cfgvalue(self, section)
178 return routes[section].metric
183 for i, route in ipairs(luci.sys.net.routes6() or {}) do
184 if route.dest:prefix() == 0 then
185 routes6[#routes6+1] = route
190 v6 = r:section(Table, routes6)
192 net = v6:option(DummyValue, "iface", translate("Network"))
193 function net.cfgvalue(self, section)
194 return luci.tools.webadmin.iface_get_network(routes6[section].device)
195 or routes6[section].device
198 target = v6:option(DummyValue, "target", translate("Target"))
199 function target.cfgvalue(self, section)
200 return routes6[section].dest:string()
203 gateway = v6:option(DummyValue, "gateway6", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
204 function gateway.cfgvalue(self, section)
205 return routes6[section].source:string()
208 metric = v6:option(DummyValue, "metric", translate("Metric"))
209 function metric.cfgvalue(self, section)
210 local metr = routes6[section].metric
211 local lower = bit.band(metr, 0xffff)
212 local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
213 return "%04X%04X" % {higher, lower}