2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
18 local fs = require "nixio.fs"
19 local sys = require "luci.sys"
20 local uci = require "luci.model.uci".cursor()
22 if not uci:get("network", "wan") then
23 uci:section("network", "interface", "wan", {proto="none", ifname=" "})
28 local wlcursor = luci.model.uci.cursor_state()
29 local wireless = wlcursor:get_all("wireless")
30 local wifidata = sys.wifi.getiwconfig()
34 for k, v in pairs(wireless) do
35 if v[".type"] == "wifi-iface" then
36 table.insert(ifaces, v)
40 wlcursor:foreach("wireless", "wifi-device",
42 table.insert(wifidevs, section[".name"])
48 m = Map("wireless", translate("Wifi"), translate("Here you can configure installed wifi devices."))
53 s = m:section(Table, ifaces, translate("Networks"))
55 link = s:option(DummyValue, "_link", translate("Link"))
56 function link.cfgvalue(self, section)
57 local ifname = self.map:get(section, "ifname")
58 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
61 essid = s:option(DummyValue, "ssid", "ESSID")
63 bssid = s:option(DummyValue, "_bsiid", "BSSID")
64 function bssid.cfgvalue(self, section)
65 local ifname = self.map:get(section, "ifname")
66 return (wifidata[ifname] and (wifidata[ifname].Cell
67 or wifidata[ifname]["Access Point"])) or "-"
70 channel = s:option(DummyValue, "channel", translate("Channel"))
71 function channel.cfgvalue(self, section)
72 return wireless[self.map:get(section, "device")].channel
75 protocol = s:option(DummyValue, "_mode", translate("Protocol"))
76 function protocol.cfgvalue(self, section)
77 local mode = wireless[self.map:get(section, "device")].mode
78 return mode and "802." .. mode
81 mode = s:option(DummyValue, "mode", translate("Mode"))
82 encryption = s:option(DummyValue, "encryption", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
84 power = s:option(DummyValue, "_power", translate("Power"))
85 function power.cfgvalue(self, section)
86 local ifname = self.map:get(section, "ifname")
87 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
90 scan = s:option(Button, "_scan", translate("Scan"))
91 scan.inputstyle = "find"
93 function scan.cfgvalue(self, section)
94 return self.map:get(section, "ifname") or false
99 t2 = m:section(Table, {}, translate("<abbr title=\"Wireless Local Area Network\">WLAN</abbr>-Scan"), translate("Wifi networks in your local environment"))
101 function scan.write(self, section)
103 t2.render = t2._render
104 local ifname = self.map:get(section, "ifname")
105 local iwinfo = sys.wifi.getiwinfo(ifname)
108 for _, cell in ipairs(iwinfo.scanlist) do
109 t2.data[#t2.data+1] = {
110 Quality = "%d/%d" %{ cell.quality, cell.quality_max },
112 Address = cell.bssid,
114 ["Encryption key"] = cell.encryption.enabled and "On" or "Off",
115 ["Signal level"] = "%d dBm" % cell.signal,
116 ["Noise level"] = "%d dBm" % iwinfo.noise
122 t2._render = t2.render
123 t2.render = function() end
125 t2:option(DummyValue, "Quality", translate("Link"))
126 essid = t2:option(DummyValue, "ESSID", "ESSID")
127 function essid.cfgvalue(self, section)
128 return self.map:get(section, "ESSID")
131 t2:option(DummyValue, "Address", "BSSID")
132 t2:option(DummyValue, "Mode", translate("Mode"))
133 chan = t2:option(DummyValue, "channel", translate("Channel"))
134 function chan.cfgvalue(self, section)
135 return self.map:get(section, "Channel")
136 or self.map:get(section, "Frequency")
140 t2:option(DummyValue, "Encryption key", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
142 t2:option(DummyValue, "Signal level", translate("Signal"))
144 t2:option(DummyValue, "Noise level", translate("Noise"))
148 if #wifidevs < 1 then
154 s = m:section(NamedSection, wifidevs[1], "wifi-device", translate("Devices"))
157 en = s:option(Flag, "disabled", translate("enable"))
162 function en.cfgvalue(self, section)
163 return Flag.cfgvalue(self, section) or "0"
167 local hwtype = m:get(wifidevs[1], "type")
169 if hwtype == "atheros" then
170 mode = s:option(ListValue, "hwmode", translate("Mode"))
171 mode.override_values = true
172 mode:value("", "auto")
173 mode:value("11b", "802.11b")
174 mode:value("11g", "802.11g")
175 mode:value("11a", "802.11a")
176 mode:value("11bg", "802.11b+g")
181 ch = s:option(Value, "channel", translate("Channel"))
183 ch:value(i, i .. " (2.4 GHz)")
187 s = m:section(TypedSection, "wifi-iface", translate("Local Network"))
191 s:option(Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
193 bssid = s:option(Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
196 luci.model.uci.cursor():foreach("wireless", "wifi-device",
198 table.insert(devs, section[".name"])
202 device = s:option(DummyValue, "device", translate("Device"))
204 s.defaults.device = devs[1]
207 mode = s:option(ListValue, "mode", translate("Mode"))
208 mode.override_values = true
209 mode:value("ap", translate("Provide (Access Point)"))
210 mode:value("adhoc", translate("Independent (Ad-Hoc)"))
211 mode:value("sta", translate("Join (Client)"))
213 function mode.write(self, section, value)
214 if value == "sta" then
215 local oldif = m.uci:get("network", "wan", "ifname")
216 if oldif and oldif ~= " " then
217 m.uci:set("network", "wan", "_ifname", oldif)
219 m.uci:set("network", "wan", "ifname", " ")
221 self.map:set(section, "network", "wan")
223 if m.uci:get("network", "wan", "_ifname") then
224 m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
226 self.map:set(section, "network", "lan")
229 return ListValue.write(self, section, value)
232 encr = s:option(ListValue, "encryption", translate("Encryption"))
233 encr.override_values = true
234 encr:value("none", "No Encryption")
235 encr:value("wep", "WEP")
237 if hwtype == "atheros" or hwtype == "mac80211" then
238 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
239 local hostapd = fs.access("/usr/sbin/hostapd")
241 if hostapd and supplicant then
242 encr:value("psk", "WPA-PSK")
243 encr:value("psk2", "WPA2-PSK")
244 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
245 encr:value("wpa", "WPA-Radius", {mode="ap"}, {mode="sta"})
246 encr:value("wpa2", "WPA2-Radius", {mode="ap"}, {mode="sta"})
247 elseif hostapd and not supplicant then
248 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"})
249 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"})
250 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"})
251 encr:value("wpa", "WPA-Radius", {mode="ap"})
252 encr:value("wpa2", "WPA2-Radius", {mode="ap"})
253 encr.description = translate(
254 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
255 "and ad-hoc mode) to be installed."
257 elseif not hostapd and supplicant then
258 encr:value("psk", "WPA-PSK", {mode="sta"})
259 encr:value("psk2", "WPA2-PSK", {mode="sta"})
260 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
261 encr:value("wpa", "WPA-EAP", {mode="sta"})
262 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
263 encr.description = translate(
264 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
265 "and ad-hoc mode) to be installed."
268 encr.description = translate(
269 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
270 "and ad-hoc mode) to be installed."
273 elseif hwtype == "broadcom" then
274 encr:value("psk", "WPA-PSK")
275 encr:value("psk2", "WPA2-PSK")
276 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
279 key = s:option(Value, "key", translate("Key"))
280 key:depends("encryption", "wep")
281 key:depends("encryption", "psk")
282 key:depends("encryption", "psk2")
283 key:depends("encryption", "psk+psk2")
284 key:depends("encryption", "psk-mixed")
285 key:depends({mode="ap", encryption="wpa"})
286 key:depends({mode="ap", encryption="wpa2"})
290 server = s:option(Value, "server", translate("Radius-Server"))
291 server:depends({mode="ap", encryption="wpa"})
292 server:depends({mode="ap", encryption="wpa2"})
293 server.rmempty = true
295 port = s:option(Value, "port", translate("Radius-Port"))
296 port:depends({mode="ap", encryption="wpa"})
297 port:depends({mode="ap", encryption="wpa2"})
301 if hwtype == "atheros" or hwtype == "mac80211" then
302 nasid = s:option(Value, "nasid", translate("NAS ID"))
303 nasid:depends({mode="ap", encryption="wpa"})
304 nasid:depends({mode="ap", encryption="wpa2"})
307 eaptype = s:option(ListValue, "eap_type", translate("EAP-Method"))
309 eaptype:value("TTLS")
310 eaptype:value("PEAP")
311 eaptype:depends({mode="sta", encryption="wpa"})
312 eaptype:depends({mode="sta", encryption="wpa2"})
314 cacert = s:option(FileUpload, "ca_cert", translate("Path to CA-Certificate"))
315 cacert:depends({mode="sta", encryption="wpa"})
316 cacert:depends({mode="sta", encryption="wpa2"})
318 privkey = s:option(FileUpload, "priv_key", translate("Path to Private Key"))
319 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
320 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
322 privkeypwd = s:option(Value, "priv_key_pwd", translate("Password of Private Key"))
323 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
324 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
327 auth = s:option(Value, "auth", translate("Authentication"))
331 auth:value("MSCHAPV2")
332 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
333 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
334 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
335 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
338 identity = s:option(Value, "identity", translate("Identity"))
339 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
340 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
341 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
342 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
344 password = s:option(Value, "password", translate("Password"))
345 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
346 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
347 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
348 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
352 if hwtype == "atheros" or hwtype == "broadcom" then
353 iso = s:option(Flag, "isolate", translate("AP-Isolation"), translate("Prevents Client to Client communication"))
355 iso:depends("mode", "ap")
357 hide = s:option(Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
359 hide:depends("mode", "ap")
362 if hwtype == "mac80211" or hwtype == "atheros" then
363 bssid:depends({mode="adhoc"})
366 if hwtype == "broadcom" then
367 bssid:depends({mode="wds"})
368 bssid:depends({mode="adhoc"})