2 LuCI - Lua Configuration Interface
4 Copyright 2009 Steven Barth <steven@midlink.org>
5 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
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
16 local fs = require "nixio.fs"
17 local uci = require "luci.model.uci"
18 local nixio = require "nixio"
19 local iwinfo = require "iwinfo"
21 local cursor = uci.inst
22 local state = uci.inst_state
23 cursor:unload("wireless")
24 state:unload("wireless")
26 local has_ipv6 = fs.access("/proc/net/ipv6_route")
27 local device = cursor:get("wireless", "client", "device")
28 local hwtype = cursor:get("wireless", device, "type")
31 -- Bring up interface and scan --
33 if not state:get("wireless", "client", "network") then
34 local olduci = uci.cursor(nil, "")
35 local oldcl = olduci:get_all("wireless", "client")
36 olduci:unload("wireless")
38 local newuci = uci.cursor()
39 local newcl = newuci:get_all("wireless", "client")
42 local proc = nixio.fork()
44 newuci:delete("wireless", "client", "ssid")
45 newuci:commit("wireless")
46 nixio.exec("/sbin/wifi", "up", device)
51 newuci:delete("wireless", "client")
52 newuci:section("wireless", "wifi-iface", "client", oldcl)
53 newuci:commit("wireless")
54 newuci:tset("wireless", "client", newcl)
55 newuci:save("wireless")
56 newuci:unload("wireless")
58 state:unload("wireless")
61 local ifname = state:get("wireless", "client", "ifname") or "wlan0dummy"
62 local iwlib = iwinfo.type(ifname) and iwinfo[iwinfo.type(ifname)]
65 none = {{["!default"] = 1}},
66 wep = {{["!default"] = 1}},
67 psk = {{["!default"] = 1}},
68 psk2 = {{["!default"] = 1}},
69 wpa = {{["!default"] = 1}},
70 wpa2 = {{["!default"] = 1}}
74 suggest = iwlib.scanlist(ifname)
81 m2 = Map("wireless", "Configure WLAN-Adapter for Internet Connection")
83 s = m2:section(NamedSection, "client", "wifi-iface", "Wireless Settings")
86 s:tab("general", translate("General Settings"))
87 s:tab("expert", translate("Expert Settings"))
89 local ssid = s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
92 for _, v in ipairs(suggest) do
93 if v.mode == "Master" then
97 encrdep.wep[#encrdep.wep+1] = {ssid = v.ssid, ["!reverse"] = 1}
99 if v.wpa ~= 1 or (v.wpa == 1 and v.auth_suites[1] ~= "802.1x") then
100 encrdep.wpa[#encrdep.wpa+1] = {ssid = v.ssid, ["!reverse"] = 1}
102 if v.wpa ~= 1 or (v.wpa == 1 and v.auth_suites[1] ~= "PSK") then
103 encrdep.psk[#encrdep.psk+1] = {ssid = v.ssid, ["!reverse"] = 1}
105 if not v.wpa or v.wpa < 2 or (v.wpa >= 2 and v.auth_suites[1] ~= "802.1x") then
106 encrdep.wpa2[#encrdep.wpa2+1] = {ssid = v.ssid, ["!reverse"] = 1}
108 if not v.wpa or v.wpa < 2 or (v.wpa >= 2 and v.auth_suites[1] ~= "PSK") then
109 encrdep.psk2[#encrdep.psk2+1] = {ssid = v.ssid, ["!reverse"] = 1}
111 if v.wpa or v.wep then
112 encrdep.none[#encrdep.none+1] = {ssid = v.ssid, ["!reverse"] = 1}
117 encr = s:taboption("general", ListValue, "encryption", translate("Encryption"))
120 if hwtype == "mac80211" then
121 s:taboption("expert", Flag, "powersave", "Enable Powersaving")
122 elseif hwtype == "atheros" then
123 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
130 encr.override_values = true
131 encr.override_depends = true
132 encr:value("none", "No Encryption", unpack(encrdep.none))
133 encr:value("wep", "WEP", unpack(encrdep.wep))
135 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
136 local supplicant = fs.access("/usr/sbin/wpa_supplicant") or os.getenv("LUCI_SYSROOT")
138 encr:value("psk", "WPA", unpack(encrdep.psk))
139 encr:value("wpa", "WPA-EAP", unpack(encrdep.wpa))
140 encr:value("psk2", "WPA2", unpack(encrdep.psk2))
141 encr:value("wpa2", "WPA2-EAP (802.11i)", unpack(encrdep.wpa2))
143 elseif hwtype == "broadcom" then
144 encr:value("psk", "WPA", unpack(encrdep.psk))
145 encr:value("psk2", "WPA2", unpack(encrdep.psk2))
148 key = s:taboption("general", Value, "key", translate("Password"))
149 key:depends("encryption", "wep")
150 key:depends("encryption", "psk")
151 key:depends("encryption", "psk2")
155 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
156 eaptype = s:taboption("general", ListValue, "eap_type", translate("EAP-Method"))
158 eaptype:value("TTLS")
159 eaptype:value("PEAP")
160 eaptype:depends({encryption="wpa"})
161 eaptype:depends({encryption="wpa2"})
163 cacert = s:taboption("general", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
164 cacert:depends({encryption="wpa"})
165 cacert:depends({encryption="wpa2"})
167 privkey = s:taboption("general", FileUpload, "priv_key", translate("Path to Private Key"))
168 privkey:depends({eap_type="TLS", encryption="wpa2"})
169 privkey:depends({eap_type="TLS", encryption="wpa"})
171 privkeypwd = s:taboption("general", Value, "priv_key_pwd", translate("Password of Private Key"))
172 privkeypwd:depends({eap_type="TLS", encryption="wpa2"})
173 privkeypwd:depends({eap_type="TLS", encryption="wpa"})
176 auth = s:taboption("general", Value, "auth", translate("Authentication"))
180 auth:value("MSCHAPV2")
181 auth:depends({eap_type="PEAP", encryption="wpa2"})
182 auth:depends({eap_type="PEAP", encryption="wpa"})
183 auth:depends({eap_type="TTLS", encryption="wpa2"})
184 auth:depends({eap_type="TTLS", encryption="wpa"})
187 identity = s:taboption("general", Value, "identity", translate("Identity"))
188 identity:depends({eap_type="PEAP", encryption="wpa2"})
189 identity:depends({eap_type="PEAP", encryption="wpa"})
190 identity:depends({eap_type="TTLS", encryption="wpa2"})
191 identity:depends({eap_type="TTLS", encryption="wpa"})
193 password = s:taboption("general", Value, "password", translate("Password"))
194 password:depends({eap_type="PEAP", encryption="wpa2"})
195 password:depends({eap_type="PEAP", encryption="wpa"})
196 password:depends({eap_type="TTLS", encryption="wpa2"})
197 password:depends({eap_type="TTLS", encryption="wpa"})
206 s = m:section(NamedSection, "wan", "interface", translate("Address Settings"))
209 s:tab("general", translate("General Settings"))
210 s:tab("expert", translate("Expert Settings"))
212 p = s:taboption("general", ListValue, "proto", "Connection Type")
213 p.override_scheme = true
215 p:value("dhcp", "Automatic Configuration (DHCP)")
216 p:value("static", "Static Configuration")
220 ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
221 ipaddr.rmempty = true
222 ipaddr:depends("proto", "static")
224 nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
226 nm:depends("proto", "static")
227 nm:value("255.255.255.0")
228 nm:value("255.255.0.0")
229 nm:value("255.0.0.0")
231 gw = s:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
232 gw:depends("proto", "static")
235 bcast = s:taboption("expert", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
236 bcast:depends("proto", "static")
239 ip6addr = s:taboption("expert", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
240 ip6addr:depends("proto", "static")
242 ip6gw = s:taboption("expert", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
243 ip6gw:depends("proto", "static")
246 dns = s:taboption("expert", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
247 dns:depends("peerdns", "")
249 mtu = s:taboption("expert", Value, "mtu", "MTU")
252 mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))