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 luci.util.update(t2.data, sys.wifi.iwscan(ifname))
108 t2._render = t2.render
109 t2.render = function() end
111 t2:option(DummyValue, "Quality", translate("Link"))
112 essid = t2:option(DummyValue, "ESSID", "ESSID")
113 function essid.cfgvalue(self, section)
114 return self.map:get(section, "ESSID")
117 t2:option(DummyValue, "Address", "BSSID")
118 t2:option(DummyValue, "Mode", translate("Mode"))
119 chan = t2:option(DummyValue, "channel", translate("Channel"))
120 function chan.cfgvalue(self, section)
121 return self.map:get(section, "Channel")
122 or self.map:get(section, "Frequency")
126 t2:option(DummyValue, "Encryption key", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
128 t2:option(DummyValue, "Signal level", translate("Signal"))
130 t2:option(DummyValue, "Noise level", translate("Noise"))
134 if #wifidevs < 1 then
140 s = m:section(NamedSection, wifidevs[1], "wifi-device", translate("Devices"))
143 en = s:option(Flag, "disabled", translate("enable"))
148 function en.cfgvalue(self, section)
149 return Flag.cfgvalue(self, section) or "0"
153 local hwtype = m:get(wifidevs[1], "type")
155 if hwtype == "atheros" then
156 mode = s:option(ListValue, "hwmode", translate("Mode"))
157 mode.override_values = true
158 mode:value("", "auto")
159 mode:value("11b", "802.11b")
160 mode:value("11g", "802.11g")
161 mode:value("11a", "802.11a")
162 mode:value("11bg", "802.11b+g")
167 ch = s:option(Value, "channel", translate("Channel"))
169 ch:value(i, i .. " (2.4 GHz)")
173 s = m:section(TypedSection, "wifi-iface", translate("Local Network"))
177 s:option(Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
179 bssid = s:option(Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
182 luci.model.uci.cursor():foreach("wireless", "wifi-device",
184 table.insert(devs, section[".name"])
188 device = s:option(DummyValue, "device", translate("Device"))
190 s.defaults.device = devs[1]
193 mode = s:option(ListValue, "mode", translate("Mode"))
194 mode.override_values = true
195 mode:value("ap", translate("Provide (Access Point)"))
196 mode:value("adhoc", translate("Independent (Ad-Hoc)"))
197 mode:value("sta", translate("Join (Client)"))
199 function mode.write(self, section, value)
200 if value == "sta" then
201 local oldif = m.uci:get("network", "wan", "ifname")
202 if oldif and oldif ~= " " then
203 m.uci:set("network", "wan", "_ifname", oldif)
205 m.uci:set("network", "wan", "ifname", " ")
207 self.map:set(section, "network", "wan")
209 if m.uci:get("network", "wan", "_ifname") then
210 m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
212 self.map:set(section, "network", "lan")
215 return ListValue.write(self, section, value)
218 encr = s:option(ListValue, "encryption", translate("Encryption"))
219 encr.override_values = true
220 encr:value("none", "No Encryption")
221 encr:value("wep", "WEP")
223 if hwtype == "atheros" or hwtype == "mac80211" then
224 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
225 local hostapd = fs.access("/usr/sbin/hostapd")
227 if hostapd and supplicant then
228 encr:value("psk", "WPA-PSK")
229 encr:value("psk2", "WPA2-PSK")
230 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
231 encr:value("wpa", "WPA-Radius", {mode="ap"}, {mode="sta"})
232 encr:value("wpa2", "WPA2-Radius", {mode="ap"}, {mode="sta"})
233 elseif hostapd and not supplicant then
234 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"})
235 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"})
236 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"})
237 encr:value("wpa", "WPA-Radius", {mode="ap"})
238 encr:value("wpa2", "WPA2-Radius", {mode="ap"})
239 encr.description = translate(
240 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
241 "and ad-hoc mode) to be installed."
243 elseif not hostapd and supplicant then
244 encr:value("psk", "WPA-PSK", {mode="sta"})
245 encr:value("psk2", "WPA2-PSK", {mode="sta"})
246 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
247 encr:value("wpa", "WPA-EAP", {mode="sta"})
248 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
249 encr.description = translate(
250 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
251 "and ad-hoc mode) to be installed."
254 encr.description = translate(
255 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
256 "and ad-hoc mode) to be installed."
259 elseif hwtype == "broadcom" then
260 encr:value("psk", "WPA-PSK")
261 encr:value("psk2", "WPA2-PSK")
262 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
265 key = s:option(Value, "key", translate("Key"))
266 key:depends("encryption", "wep")
267 key:depends("encryption", "psk")
268 key:depends("encryption", "psk2")
269 key:depends("encryption", "psk+psk2")
270 key:depends("encryption", "psk-mixed")
271 key:depends({mode="ap", encryption="wpa"})
272 key:depends({mode="ap", encryption="wpa2"})
276 server = s:option(Value, "server", translate("Radius-Server"))
277 server:depends({mode="ap", encryption="wpa"})
278 server:depends({mode="ap", encryption="wpa2"})
279 server.rmempty = true
281 port = s:option(Value, "port", translate("Radius-Port"))
282 port:depends({mode="ap", encryption="wpa"})
283 port:depends({mode="ap", encryption="wpa2"})
287 if hwtype == "atheros" or hwtype == "mac80211" then
288 nasid = s:option(Value, "nasid", translate("NAS ID"))
289 nasid:depends({mode="ap", encryption="wpa"})
290 nasid:depends({mode="ap", encryption="wpa2"})
293 eaptype = s:option(ListValue, "eap_type", translate("EAP-Method"))
295 eaptype:value("TTLS")
296 eaptype:value("PEAP")
297 eaptype:depends({mode="sta", encryption="wpa"})
298 eaptype:depends({mode="sta", encryption="wpa2"})
300 cacert = s:option(FileUpload, "ca_cert", translate("Path to CA-Certificate"))
301 cacert:depends({mode="sta", encryption="wpa"})
302 cacert:depends({mode="sta", encryption="wpa2"})
304 privkey = s:option(FileUpload, "priv_key", translate("Path to Private Key"))
305 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
306 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
308 privkeypwd = s:option(Value, "priv_key_pwd", translate("Password of Private Key"))
309 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
310 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
313 auth = s:option(Value, "auth", translate("Authentication"))
317 auth:value("MSCHAPV2")
318 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
319 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
320 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
321 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
324 identity = s:option(Value, "identity", translate("Identity"))
325 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
326 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
327 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
328 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
330 password = s:option(Value, "password", translate("Password"))
331 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
332 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
333 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
334 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
338 if hwtype == "atheros" or hwtype == "broadcom" then
339 iso = s:option(Flag, "isolate", translate("AP-Isolation"), translate("Prevents Client to Client communication"))
341 iso:depends("mode", "ap")
343 hide = s:option(Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
345 hide:depends("mode", "ap")
348 if hwtype == "mac80211" or hwtype == "atheros" then
349 bssid:depends({mode="adhoc"})
352 if hwtype == "broadcom" then
353 bssid:depends({mode="wds"})
354 bssid:depends({mode="adhoc"})