modules/admin-mini: Fixed WLAN client mode
[project/luci.git] / modules / admin-mini / luasrc / model / cbi / mini / wifi.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
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
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
16
17 s = m:section(TypedSection, "wifi-device", translate("devices"))
18
19 en = s:option(Flag, "disabled", translate("enable"))
20 en.enabled = "0"
21 en.disabled = "1"
22
23 mode = s:option(ListValue, "mode", translate("mode"))
24 mode:value("", "standard")
25 mode:value("11b", "802.11b")
26 mode:value("11g", "802.11g")
27 mode:value("11a", "802.11a")
28 mode:value("11bg", "802.11b+g")
29 mode.rmempty = true
30
31 s:option(Value, "channel", translate("a_w_channel"))
32
33
34
35 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
36 s.anonymous = true
37
38 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
39
40 local devs = {}
41 luci.model.uci.foreach("wireless", "wifi-device",
42         function (section)
43                 table.insert(devs, section[".name"])
44         end)
45         
46 if #devs > 1 then
47         device = s:option(DummyValue, "device", translate("device"))
48 else
49         s.defaults.device = devs[1]
50 end
51
52 mode = s:option(ListValue, "mode", translate("mode"))
53 mode:value("ap", translate("m_w_ap"))
54 mode:value("adhoc", translate("m_w_adhoc"))
55 mode:value("sta", translate("m_w_client"))
56
57 function mode.write(self, section, value)
58         if value == "sta" then
59                 -- ToDo: Move this away
60                 if not luci.model.uci.get("network", "wan") then
61                         luci.model.uci.set("network", "wan", "proto", "none")
62                         luci.model.uci.set("network", "wan", "ifname", " ")
63                 end
64
65                 luci.model.uci.set("network", "wan", "_ifname", luci.model.uci.get("network", "wan", "ifname") or " ")
66                 luci.model.uci.set("network", "wan", "ifname", " ")
67                 luci.model.uci.save("network")
68                 luci.model.uci.unload("network")
69
70                 self.map:set(section, "network", "wan")
71         else
72                 if luci.model.uci.get("network", "wan", "_ifname") then
73                         luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
74                 end
75                 self.map:set(section, "network", "lan")
76         end
77
78         return ListValue.write(self, section, value)
79 end
80
81 encr = s:option(ListValue, "encryption", translate("encryption"))
82 encr:value("none", "keine")
83 encr:value("wep", "WEP")
84 encr:value("psk", "WPA-PSK")
85 encr:value("wpa", "WPA-Radius")
86 encr:value("psk2", "WPA2-PSK")
87 encr:value("wpa2", "WPA2-Radius")
88
89 key = s:option(Value, "key", translate("key"))
90 key:depends("encryption", "wep")
91 key:depends("encryption", "psk")
92 key:depends("encryption", "wpa")
93 key:depends("encryption", "psk2")
94 key:depends("encryption", "wpa2")
95 key.rmempty = true
96
97 server = s:option(Value, "server", translate("a_w_radiussrv"))
98 server:depends("encryption", "wpa")
99 server:depends("encryption", "wpa2")
100 server.rmempty = true
101
102 port = s:option(Value, "port", translate("a_w_radiusport"))
103 port:depends("encryption", "wpa")
104 port:depends("encryption", "wpa2")
105 port.rmempty = true
106
107 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
108 iso.rmempty = true
109 iso:depends("mode", "ap")
110
111 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
112 hide.rmempty = true
113 hide:depends("mode", "ap")
114
115 return m