root/luci/branches/luci-0.9/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua @ 5611

Revision 5611, 14.3 KB (checked in by jow, 3 years ago)

luci-0.9: labels for black- and whitelist are swapped

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12$Id$
13]]--
14
15local wa = require "luci.tools.webadmin"
16local fs = require "nixio.fs"
17
18arg[1] = arg[1] or ""
19
20m = Map("wireless", translate("networks"), translate("a_w_networks1"))
21
22s = m:section(NamedSection, arg[1], "wifi-device", translate("device") .. " " .. arg[1])
23s.addremove = false
24
25back = s:option(DummyValue, "_overview", translate("overview"))
26back.value = ""
27back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
28
29
30en = s:option(Flag, "disabled", translate("enable"))
31en.enabled = "0"
32en.disabled = "1"
33en.rmempty = false
34
35function en.cfgvalue(self, section)
36    return Flag.cfgvalue(self, section) or "0"
37end
38
39s:option(DummyValue, "type", translate("type"))
40local hwtype = m:get(arg[1], "type")
41-- NanoFoo
42local nsantenna = m:get(arg[1], "antenna")
43
44ch = s:option(Value, "channel", translate("a_w_channel"))
45ch:value("auto", translate("wifi_auto"))
46for c, f in luci.util.kspairs(luci.sys.wifi.channels()) do
47    ch:value(c, "%i (%.3f GHz)" %{ c, f })
48end
49
50
51------------------- MAC80211 Device ------------------
52
53if hwtype == "mac80211" then
54    s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
55end
56
57
58------------------- Madwifi Device ------------------
59
60if hwtype == "atheros" then
61    s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
62
63    mode = s:option(ListValue, "hwmode", translate("mode"))
64    mode:value("", translate("wifi_auto"))
65    mode:value("11b", "802.11b")
66    mode:value("11g", "802.11g")
67    mode:value("11a", "802.11a")
68    mode:value("11bg", "802.11b+g")
69    mode:value("11gst", "802.11g + Turbo")
70    mode:value("11ast", "802.11a + Turbo")
71    mode:value("fh", translate("wifi_fh"))
72
73    s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
74
75    if not nsantenna then
76        s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
77        s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
78    else -- NanoFoo
79        local ant = s:option(ListValue, "antenna", translate("wifi_txantenna"))
80        ant:value("auto")
81        ant:value("vertical")
82        ant:value("horizontal")
83        ant:value("external")
84    end
85    s:option(Value, "distance", translate("wifi_distance"),
86        translate("wifi_distance_desc")).optional = true
87    s:option(Value, "regdomain", translate("wifi_regdomain")).optional = true
88    s:option(Value, "country", translate("wifi_country")).optional = true
89    s:option(Flag, "outdoor", translate("wifi_outdoor")).optional = true
90
91    --s:option(Flag, "nosbeacon", translate("wifi_nosbeacon")).optional = true
92end
93
94
95
96------------------- Broadcom Device ------------------
97
98if hwtype == "broadcom" then
99    s:option(Value, "txpower", translate("a_w_txpwr"), "dBm").rmempty = true
100
101    mp = s:option(ListValue, "macfilter", translate("wifi_macpolicy"))
102    mp.optional = true
103    mp:value("")
104    mp:value("allow", translate("wifi_blacklist"))
105    mp:value("deny", translate("wifi_whitelist"))
106    ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
107    ml:depends({macfilter="allow"})
108    ml:depends({macfilter="deny"})
109
110    s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
111    s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
112
113    s:option(Flag, "frameburst", translate("wifi_bursting")).optional = true
114
115    s:option(Value, "distance", translate("wifi_distance")).optional = true
116    --s:option(Value, "slottime", translate("wifi_slottime")).optional = true
117
118    s:option(Value, "country", translate("wifi_country")).optional = true
119    s:option(Value, "maxassoc", translate("wifi_maxassoc")).optional = true
120end
121
122
123--------------------- HostAP Device ---------------------
124
125if hwtype == "prism2" then
126    s:option(Value, "txpower", translate("a_w_txpwr"), "att units").rmempty = true
127
128    s:option(Flag, "diversity", translate("wifi_diversity")).rmempty = false
129
130    s:option(Value, "txantenna", translate("wifi_txantenna")).optional = true
131    s:option(Value, "rxantenna", translate("wifi_rxantenna")).optional = true
132end
133
134
135----------------------- Interface -----------------------
136
137s = m:section(TypedSection, "wifi-iface", translate("interfaces"))
138s.addremove = true
139s.anonymous = true
140s:depends("device", arg[1])
141s.defaults.device = arg[1]
142
143s:option(Value, "ssid", translate("wifi_essid"))
144
145network = s:option(Value, "network", translate("network"), translate("a_w_network1"))
146network.rmempty = true
147network:value("")
148network.combobox_manual = translate("a_w_netmanual")
149wa.cbi_add_networks(network)
150
151function network.write(self, section, value)
152    if not m.uci:get("network", value) then
153        -- avoid "value not defined in enum" because network is not known yet
154        s.override_scheme = true
155
156        m:chain("network")
157        m.uci:set("network", value, "interface")
158        Value.write(self, section, value)
159    else
160        if m.uci:get("network", value) == "interface" then
161            Value.write(self, section, value)
162        end
163    end
164end
165
166
167mode = s:option(ListValue, "mode", translate("mode"))
168mode.override_values = true
169mode:value("ap", translate("a_w_ap"))
170mode:value("adhoc", translate("a_w_adhoc"))
171mode:value("sta", translate("a_w_client"))
172
173bssid = s:option(Value, "bssid", translate("wifi_bssid"))
174
175
176-------------------- MAC80211 Interface ----------------------
177
178if hwtype == "mac80211" then
179    if fs.access("/usr/sbin/iw") then
180        mode:value("mesh", "802.11s")
181    end
182
183    mode:value("ahdemo", translate("a_w_ahdemo"))
184    mode:value("monitor", translate("a_w_monitor"))
185    bssid:depends({mode="adhoc"})
186
187    s:option(Value, "frag", translate("wifi_frag")).optional = true
188    s:option(Value, "rts", translate("wifi_rts")).optional = true
189end
190
191
192
193-------------------- Madwifi Interface ----------------------
194
195if hwtype == "atheros" then
196    mode:value("ahdemo", translate("a_w_ahdemo"))
197    mode:value("monitor", translate("a_w_monitor"))
198
199    bssid:depends({mode="adhoc"})
200    bssid:depends({mode="ahdemo"})
201
202    wds = s:option(Flag, "wds", translate("a_w_wds"))
203    wds:depends({mode="ap"})
204    wds:depends({mode="sta"})
205    wds.rmempty = true
206    wdssep = s:option(Flag, "wdssep", translate("wifi_wdssep"))
207    wdssep:depends({mode="ap", wds="1"})
208    wdssep.optional = true
209
210    s:option(Flag, "doth", "802.11h").optional = true
211    hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
212    hidden:depends({mode="ap"})
213    hidden:depends({mode="adhoc"})
214    hidden:depends({mode="wds"})
215    hidden.optional = true
216    isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
217     translate("wifi_isolate_desc"))
218    isolate:depends({mode="ap"})
219    isolate.optional = true
220    s:option(Flag, "bgscan", translate("wifi_bgscan")).optional = true
221
222    mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
223    mp.optional = true
224    mp:value("")
225    mp:value("deny", translate("wifi_whitelist"))
226    mp:value("allow", translate("wifi_blacklist"))
227    ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
228    ml:depends({macpolicy="allow"})
229    ml:depends({macpolicy="deny"})
230
231    s:option(Value, "rate", translate("wifi_rate")).optional = true
232    s:option(Value, "mcast_rate", translate("wifi_mcast_rate")).optional = true
233    s:option(Value, "frag", translate("wifi_frag")).optional = true
234    s:option(Value, "rts", translate("wifi_rts")).optional = true
235    s:option(Value, "minrate", translate("wifi_minrate")).optional = true
236    s:option(Value, "maxrate", translate("wifi_maxrate")).optional = true
237    s:option(Flag, "compression", translate("wifi_compression")).optional = true
238
239    s:option(Flag, "bursting", translate("wifi_bursting")).optional = true
240    s:option(Flag, "turbo", translate("wifi_turbo")).optional = true
241    s:option(Flag, "ff", translate("wifi_ff")).optional = true
242
243    s:option(Flag, "wmm", translate("wifi_wmm")).optional = true
244    s:option(Flag, "xr", translate("wifi_xr")).optional = true
245    s:option(Flag, "ar", translate("wifi_ar")).optional = true
246
247    local swm = s:option(Flag, "sw_merge", translate("wifi_nosbeacon"))
248    swm:depends({mode="adhoc"})
249    swm.optional = true
250
251    local nos = s:option(Flag, "nosbeacon", translate("wifi_nosbeacon"))
252    nos:depends({mode="sta"})
253    nos.optional = true
254
255    local probereq = s:option(Flag, "probereq", translate("wifi_noprobereq"))
256    probereq.optional = true
257    probereq.enabled  = "0"
258    probereq.disabled = "1"
259end
260
261
262-------------------- Broadcom Interface ----------------------
263
264if hwtype == "broadcom" then
265    mode:value("wds", translate("a_w_wds"))
266    mode:value("monitor", translate("a_w_monitor"))
267
268    hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
269    hidden:depends({mode="ap"})
270    hidden:depends({mode="adhoc"})
271    hidden:depends({mode="wds"})
272    hidden.optional = true
273
274    isolate = s:option(Flag, "isolate", translate("wifi_isolate"),
275     translate("wifi_isolate_desc"))
276    isolate:depends({mode="ap"})
277    isolate.optional = true
278
279    bssid:depends({mode="wds"})
280    bssid:depends({mode="adhoc"})
281end
282
283
284----------------------- HostAP Interface ---------------------
285
286if hwtype == "prism2" then
287    mode:value("wds", translate("a_w_wds"))
288    mode:value("monitor", translate("a_w_monitor"))
289
290    hidden = s:option(Flag, "hidden", translate("wifi_hidden"))
291    hidden:depends({mode="ap"})
292    hidden:depends({mode="adhoc"})
293    hidden:depends({mode="wds"})
294    hidden.optional = true
295
296    bssid:depends({mode="sta"})
297
298    mp = s:option(ListValue, "macpolicy", translate("wifi_macpolicy"))
299    mp.optional = true
300    mp:value("")
301    mp:value("deny", translate("wifi_whitelist"))
302    mp:value("allow", translate("wifi_blacklist"))
303    ml = s:option(DynamicList, "maclist", translate("wifi_maclist"))
304    ml:depends({macpolicy="allow"})
305    ml:depends({macpolicy="deny"})
306
307    s:option(Value, "rate", translate("wifi_rate")).optional = true
308    s:option(Value, "frag", translate("wifi_frag")).optional = true
309    s:option(Value, "rts", translate("wifi_rts")).optional = true
310end
311
312
313------------------- WiFI-Encryption -------------------
314
315encr = s:option(ListValue, "encryption", translate("encryption"))
316encr.override_values = true
317encr:depends({mode="ap"})
318encr:depends({mode="sta"})
319encr:depends({mode="adhoc"})
320encr:depends({mode="ahdemo"})
321encr:depends({mode="wds"})
322encr:depends({mode="mesh"})
323
324encr:value("none", "No Encryption")
325encr:value("wep", "WEP")
326
327if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
328    local supplicant = fs.access("/usr/sbin/wpa_supplicant")
329    local hostapd = fs.access("/usr/sbin/hostapd")
330
331    if hostapd and supplicant then
332        encr:value("psk", "WPA-PSK")
333        encr:value("psk2", "WPA2-PSK")
334        encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
335        encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"})
336        encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"})
337    elseif hostapd and not supplicant then
338        encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
339        encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
340        encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="adhoc"}, {mode="ahdemo"})
341        encr:value("wpa", "WPA-EAP", {mode="ap"})
342        encr:value("wpa2", "WPA2-EAP", {mode="ap"})
343        encr.description = translate("wifi_wpareq")
344    elseif not hostapd and supplicant then
345        encr:value("psk", "WPA-PSK", {mode="sta"})
346        encr:value("psk2", "WPA2-PSK", {mode="sta"})
347        encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"})
348        encr:value("wpa", "WPA-EAP", {mode="sta"})
349        encr:value("wpa2", "WPA2-EAP", {mode="sta"})
350        encr.description = translate("wifi_wpareq")
351    else
352        encr.description = translate("wifi_wpareq")
353    end
354elseif hwtype == "broadcom" then
355    encr:value("psk", "WPA-PSK")
356    encr:value("psk2", "WPA2-PSK")
357    encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
358end
359
360encr:depends("mode", "ap")
361encr:depends("mode", "sta")
362encr:depends("mode", "wds")
363
364server = s:option(Value, "server", translate("a_w_radiussrv"))
365server:depends({mode="ap", encryption="wpa"})
366server:depends({mode="ap", encryption="wpa2"})
367server.rmempty = true
368
369port = s:option(Value, "port", translate("a_w_radiusport"))
370port:depends({mode="ap", encryption="wpa"})
371port:depends({mode="ap", encryption="wpa2"})
372port.rmempty = true
373
374key = s:option(Value, "key", translate("key"))
375key:depends("encryption", "wep")
376key:depends("encryption", "psk")
377key:depends("encryption", "psk2")
378key:depends("encryption", "psk+psk2")
379key:depends("encryption", "psk-mixed")
380key:depends({mode="ap", encryption="wpa"})
381key:depends({mode="ap", encryption="wpa2"})
382key.rmempty = true
383key.password = true
384
385if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
386    nasid = s:option(Value, "nasid", translate("a_w_nasid"))
387    nasid:depends({mode="ap", encryption="wpa"})
388    nasid:depends({mode="ap", encryption="wpa2"})
389    nasid.rmempty = true
390
391    eaptype = s:option(ListValue, "eap_type", translate("a_w_eaptype"))
392    eaptype:value("TLS")
393    eaptype:value("TTLS")
394    eaptype:value("PEAP")
395    eaptype:depends({mode="sta", encryption="wpa"})
396    eaptype:depends({mode="sta", encryption="wpa2"})
397
398    cacert = s:option(FileUpload, "ca_cert", translate("a_w_cacert"))
399    cacert:depends({mode="sta", encryption="wpa"})
400    cacert:depends({mode="sta", encryption="wpa2"})
401
402    privkey = s:option(FileUpload, "priv_key", translate("a_w_tlsprivkey"))
403    privkey:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
404    privkey:depends({mode="sta", eap_type="TLS", encryption="wpa"})
405
406    privkeypwd = s:option(Value, "priv_key_pwd", translate("a_w_tlsprivkeypwd"))
407    privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa2"})
408    privkeypwd:depends({mode="sta", eap_type="TLS", encryption="wpa"})
409
410
411    auth = s:option(Value, "auth", translate("a_w_peapauth"))
412    auth:value("PAP")
413    auth:value("CHAP")
414    auth:value("MSCHAP")
415    auth:value("MSCHAPV2")
416    auth:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
417    auth:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
418    auth:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
419    auth:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
420
421
422    identity = s:option(Value, "identity", translate("a_w_peapidentity"))
423    identity:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
424    identity:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
425    identity:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
426    identity:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
427
428    password = s:option(Value, "password", translate("a_w_peappassword"))
429    password:depends({mode="sta", eap_type="PEAP", encryption="wpa2"})
430    password:depends({mode="sta", eap_type="PEAP", encryption="wpa"})
431    password:depends({mode="sta", eap_type="TTLS", encryption="wpa2"})
432    password:depends({mode="sta", eap_type="TTLS", encryption="wpa"})
433end
434
435
436return m
Note: See TracBrowser for help on using the browser.