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")
33 for k, v in pairs(wireless) do
34 if v[".type"] == "wifi-iface" then
35 table.insert(ifaces, v)
39 wlcursor:foreach("wireless", "wifi-device",
41 table.insert(wifidevs, section[".name"])
47 m = Map("wireless", translate("Wifi"), translate("Here you can configure installed wifi devices."))
52 s = m:section(Table, ifaces, translate("Networks"))
54 link = s:option(DummyValue, "_link", translate("Link"))
55 function link.cfgvalue(self, section)
56 local ifname = self.map:get(section, "ifname")
57 local iwinfo = sys.wifi.getiwinfo(ifname)
58 return iwinfo and "%d/%d" %{ iwinfo.quality, iwinfo.quality_max } 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 local iwinfo = sys.wifi.getiwinfo(ifname)
67 return iwinfo and iwinfo.bssid 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 local iwinfo = sys.wifi.getiwinfo(ifname)
88 return iwinfo and "%d dBm" % iwinfo.txpower or "-"
91 scan = s:option(Button, "_scan", translate("Scan"))
92 scan.inputstyle = "find"
94 function scan.cfgvalue(self, section)
95 return self.map:get(section, "ifname") or false
100 t2 = m:section(Table, {}, translate("<abbr title=\"Wireless Local Area Network\">WLAN</abbr>-Scan"), translate("Wifi networks in your local environment"))
102 function scan.write(self, section)
104 t2.render = t2._render
105 local ifname = self.map:get(section, "ifname")
106 local iwinfo = sys.wifi.getiwinfo(ifname)
109 for _, cell in ipairs(iwinfo.scanlist) do
110 t2.data[#t2.data+1] = {
111 Quality = "%d/%d" %{ cell.quality, cell.quality_max },
113 Address = cell.bssid,
115 ["Encryption key"] = cell.encryption.enabled and "On" or "Off",
116 ["Signal level"] = "%d dBm" % cell.signal,
117 ["Noise level"] = "%d dBm" % iwinfo.noise
123 t2._render = t2.render
124 t2.render = function() end
126 t2:option(DummyValue, "Quality", translate("Link"))
127 essid = t2:option(DummyValue, "ESSID", "ESSID")
128 function essid.cfgvalue(self, section)
129 return self.map:get(section, "ESSID")
132 t2:option(DummyValue, "Address", "BSSID")
133 t2:option(DummyValue, "Mode", translate("Mode"))
134 chan = t2:option(DummyValue, "channel", translate("Channel"))
135 function chan.cfgvalue(self, section)
136 return self.map:get(section, "Channel")
137 or self.map:get(section, "Frequency")
141 t2:option(DummyValue, "Encryption key", translate("<abbr title=\"Encrypted\">Encr.</abbr>"))
143 t2:option(DummyValue, "Signal level", translate("Signal"))
145 t2:option(DummyValue, "Noise level", translate("Noise"))
149 if #wifidevs < 1 then
155 s = m:section(NamedSection, wifidevs[1], "wifi-device", translate("Devices"))
158 en = s:option(Flag, "disabled", translate("enable"))
163 function en.cfgvalue(self, section)
164 return Flag.cfgvalue(self, section) or "0"
168 local hwtype = m:get(wifidevs[1], "type")
170 if hwtype == "atheros" then
171 mode = s:option(ListValue, "hwmode", translate("Mode"))
172 mode.override_values = true
173 mode:value("", "auto")
174 mode:value("11b", "802.11b")
175 mode:value("11g", "802.11g")
176 mode:value("11a", "802.11a")
177 mode:value("11bg", "802.11b+g")
182 ch = s:option(Value, "channel", translate("Channel"))
184 ch:value(i, i .. " (2.4 GHz)")
188 s = m:section(TypedSection, "wifi-iface", translate("Local Network"))
192 s:option(Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
194 bssid = s:option(Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
197 luci.model.uci.cursor():foreach("wireless", "wifi-device",
199 table.insert(devs, section[".name"])
203 device = s:option(DummyValue, "device", translate("Device"))
205 s.defaults.device = devs[1]
208 mode = s:option(ListValue, "mode", translate("Mode"))
209 mode.override_values = true
210 mode:value("ap", translate("Provide (Access Point)"))
211 mode:value("adhoc", translate("Independent (Ad-Hoc)"))
212 mode:value("sta", translate("Join (Client)"))
214 function mode.write(self, section, value)
215 if value == "sta" then
216 local oldif = m.uci:get("network", "wan", "ifname")
217 if oldif and oldif ~= " " then
218 m.uci:set("network", "wan", "_ifname", oldif)
220 m.uci:set("network", "wan", "ifname", " ")
222 self.map:set(section, "network", "wan")
224 if m.uci:get("network", "wan", "_ifname") then
225 m.uci:set("network", "wan", "ifname", m.uci:get("network", "wan", "_ifname"))
227 self.map:set(section, "network", "lan")
230 return ListValue.write(self, section, value)
233 encr = s:option(ListValue, "encryption", translate("Encryption"))
234 encr.override_values = true
235 encr:value("none", "No Encryption")
236 encr:value("wep", "WEP")
238 if hwtype == "atheros" or hwtype == "mac80211" then
239 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
240 local hostapd = fs.access("/usr/sbin/hostapd")
242 if hostapd and supplicant then
243 encr:value("psk", "WPA-PSK")
244 encr:value("psk2", "WPA2-PSK")
245 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
246 encr:value("wpa", "WPA-Radius", {mode="ap"}, {mode="sta"})
247 encr:value("wpa2", "WPA2-Radius", {mode="ap"}, {mode="sta"})
248 elseif hostapd and not supplicant then
249 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"})
250 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"})
251 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"})
252 encr:value("wpa", "WPA-Radius", {mode="ap"})
253 encr:value("wpa2", "WPA2-Radius", {mode="ap"})
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."
258 elseif not hostapd and supplicant then
259 encr:value("psk", "WPA-PSK", {mode="sta"})
260 encr:value("psk2", "WPA2-PSK", {mode="sta"})
261 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
262 encr:value("wpa", "WPA-EAP", {mode="sta"})
263 encr:value("wpa2", "WPA2-EAP", {mode="sta"})
264 encr.description = translate(
265 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
266 "and ad-hoc mode) to be installed."
269 encr.description = translate(
270 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
271 "and ad-hoc mode) to be installed."
274 elseif hwtype == "broadcom" then
275 encr:value("psk", "WPA-PSK")
276 encr:value("psk2", "WPA2-PSK")
277 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
280 key = s:option(Value, "key", translate("Key"))
281 key:depends("encryption", "wep")
282 key:depends("encryption", "psk")
283 key:depends("encryption", "psk2")
284 key:depends("encryption", "psk+psk2")
285 key:depends("encryption", "psk-mixed")
286 key:depends({mode="ap", encryption="wpa"})
287 key:depends({mode="ap", encryption="wpa2"})
291 server = s:option(Value, "server", translate("Radius-Server"))
292 server:depends({mode="ap", encryption="wpa"})
293 server:depends({mode="ap", encryption="wpa2"})
294 server.rmempty = true
296 port = s:option(Value, "port", translate("Radius-Port"))
297 port:depends({mode="ap", encryption="wpa"})
298 port:depends({mode="ap", encryption="wpa2"})
302 if hwtype == "atheros" or hwtype == "mac80211" then
303 nasid = s:option(Value, "nasid", translate("NAS ID"))
304 nasid:depends({mode="ap", encryption="wpa"})
305 nasid:depends({mode="ap", encryption="wpa2"})
308 eaptype = s:option(ListValue, "eap_type", translate("EAP-Method"))
310 eaptype:value("TTLS")
311 eaptype:value("PEAP")
312 eaptype:depends({mode="sta", encryption="wpa"})
313 eaptype:depends({mode="sta", encryption="wpa2"})
315 cacert = s:option(FileUpload, "ca_cert", translate("Path to CA-Certificate"))
316 cacert:depends({mode="sta", encryption="wpa"})
317 cacert:depends({mode="sta", encryption="wpa2"})
319 privkey = s:option(FileUpload, "priv_key", translate("Path to Private Key"))
320 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
321 privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
323 privkeypwd = s:option(Value, "priv_key_pwd", translate("Password of Private Key"))
324 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
325 privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
328 auth = s:option(Value, "auth", translate("Authentication"))
332 auth:value("MSCHAPV2")
333 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
334 auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
335 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
336 auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
339 identity = s:option(Value, "identity", translate("Identity"))
340 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
341 identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
342 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
343 identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
345 password = s:option(Value, "password", translate("Password"))
346 password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
347 password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
348 password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
349 password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
353 if hwtype == "atheros" or hwtype == "broadcom" then
354 iso = s:option(Flag, "isolate", translate("AP-Isolation"), translate("Prevents Client to Client communication"))
356 iso:depends("mode", "ap")
358 hide = s:option(Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
360 hide:depends("mode", "ap")
363 if hwtype == "mac80211" or hwtype == "atheros" then
364 bssid:depends({mode="adhoc"})
367 if hwtype == "broadcom" then
368 bssid:depends({mode="wds"})
369 bssid:depends({mode="adhoc"})