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 mode = s:taboption("expert", ListValue, "mode", translate("Operating Mode"))
118 mode.override_values = true
119 mode:value("sta", translate("Client"))
121 encr = s:taboption("general", ListValue, "encryption", translate("Encryption"))
124 if hwtype == "mac80211" then
125 mode:value("mesh", translate("Mesh (802.11s)"))
126 local meshid = s:taboption("expert", Value, "mesh_id", translate("Mesh ID"))
127 meshid:depends("mode", "mesh")
129 local ps = s:taboption("expert", Flag, "powersave", translate("Enable Powersaving"))
130 ps:depends("mode", "sta")
131 elseif hwtype == "atheros" then
132 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
139 encr.override_values = true
140 encr.override_depends = true
141 encr:value("none", "No Encryption", unpack(encrdep.none))
142 encr:value("wep", "WEP", unpack(encrdep.wep))
144 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
145 local supplicant = fs.access("/usr/sbin/wpa_supplicant") or os.getenv("LUCI_SYSROOT")
147 encr:value("psk", "WPA", unpack(encrdep.psk))
148 encr:value("wpa", "WPA-EAP", unpack(encrdep.wpa))
149 encr:value("psk2", "WPA2", unpack(encrdep.psk2))
150 encr:value("wpa2", "WPA2-EAP (802.11i)", unpack(encrdep.wpa2))
152 elseif hwtype == "broadcom" then
153 encr:value("psk", "WPA", unpack(encrdep.psk))
154 encr:value("psk2", "WPA2", unpack(encrdep.psk2))
157 key = s:taboption("general", Value, "key", translate("Password"))
158 key:depends("encryption", "wep")
159 key:depends("encryption", "psk")
160 key:depends("encryption", "psk2")
164 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
165 eaptype = s:taboption("general", ListValue, "eap_type", translate("EAP-Method"))
167 eaptype:value("TTLS")
168 eaptype:value("PEAP")
169 eaptype:depends({encryption="wpa"})
170 eaptype:depends({encryption="wpa2"})
172 cacert = s:taboption("general", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
173 cacert:depends({encryption="wpa"})
174 cacert:depends({encryption="wpa2"})
176 privkey = s:taboption("general", FileUpload, "priv_key", translate("Path to Private Key"))
177 privkey:depends({eap_type="TLS", encryption="wpa2"})
178 privkey:depends({eap_type="TLS", encryption="wpa"})
180 privkeypwd = s:taboption("general", Value, "priv_key_pwd", translate("Password of Private Key"))
181 privkeypwd:depends({eap_type="TLS", encryption="wpa2"})
182 privkeypwd:depends({eap_type="TLS", encryption="wpa"})
185 auth = s:taboption("general", Value, "auth", translate("Authentication"))
189 auth:value("MSCHAPV2")
190 auth:depends({eap_type="PEAP", encryption="wpa2"})
191 auth:depends({eap_type="PEAP", encryption="wpa"})
192 auth:depends({eap_type="TTLS", encryption="wpa2"})
193 auth:depends({eap_type="TTLS", encryption="wpa"})
196 identity = s:taboption("general", Value, "identity", translate("Identity"))
197 identity:depends({eap_type="PEAP", encryption="wpa2"})
198 identity:depends({eap_type="PEAP", encryption="wpa"})
199 identity:depends({eap_type="TTLS", encryption="wpa2"})
200 identity:depends({eap_type="TTLS", encryption="wpa"})
202 password = s:taboption("general", Value, "password", translate("Password"))
203 password:depends({eap_type="PEAP", encryption="wpa2"})
204 password:depends({eap_type="PEAP", encryption="wpa"})
205 password:depends({eap_type="TTLS", encryption="wpa2"})
206 password:depends({eap_type="TTLS", encryption="wpa"})
215 s = m:section(NamedSection, "wan", "interface", translate("Address Settings"))
218 s:tab("general", translate("General Settings"))
219 s:tab("expert", translate("Expert Settings"))
221 p = s:taboption("general", ListValue, "proto", "Connection Type")
222 p.override_scheme = true
224 p:value("dhcp", "Automatic Configuration (DHCP)")
225 p:value("static", "Static Configuration")
229 ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
230 ipaddr.rmempty = true
231 ipaddr:depends("proto", "static")
233 nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
235 nm:depends("proto", "static")
236 nm:value("255.255.255.0")
237 nm:value("255.255.0.0")
238 nm:value("255.0.0.0")
240 gw = s:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
241 gw:depends("proto", "static")
244 bcast = s:taboption("expert", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
245 bcast:depends("proto", "static")
248 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"))
249 ip6addr:depends("proto", "static")
251 ip6gw = s:taboption("expert", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
252 ip6gw:depends("proto", "static")
255 dns = s:taboption("expert", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
256 dns:depends("peerdns", "")
258 mtu = s:taboption("expert", Value, "mtu", "MTU")
261 mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))