30766a47c9ffee6c35c74c381f04d56bcfe335dd
[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                 local oldif = luci.model.uci.get("network", "wan", "ifname")
66                 if oldif and oldif ~= " " then
67                         luci.model.uci.set("network", "wan", "_ifname", oldif)
68                 end
69                 luci.model.uci.set("network", "wan", "ifname", " ")
70                 luci.model.uci.save("network")
71                 luci.model.uci.unload("network")
72
73                 self.map:set(section, "network", "wan")
74         else
75                 if luci.model.uci.get("network", "wan", "_ifname") then
76                         luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
77                 end
78                 self.map:set(section, "network", "lan")
79         end
80
81         return ListValue.write(self, section, value)
82 end
83
84 encr = s:option(ListValue, "encryption", translate("encryption"))
85 encr:value("none", "keine")
86 encr:value("wep", "WEP")
87 encr:value("psk", "WPA-PSK")
88 encr:value("wpa", "WPA-Radius")
89 encr:value("psk2", "WPA2-PSK")
90 encr:value("wpa2", "WPA2-Radius")
91
92 key = s:option(Value, "key", translate("key"))
93 key:depends("encryption", "wep")
94 key:depends("encryption", "psk")
95 key:depends("encryption", "wpa")
96 key:depends("encryption", "psk2")
97 key:depends("encryption", "wpa2")
98 key.rmempty = true
99
100 server = s:option(Value, "server", translate("a_w_radiussrv"))
101 server:depends("encryption", "wpa")
102 server:depends("encryption", "wpa2")
103 server.rmempty = true
104
105 port = s:option(Value, "port", translate("a_w_radiusport"))
106 port:depends("encryption", "wpa")
107 port:depends("encryption", "wpa2")
108 port.rmempty = true
109
110 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
111 iso.rmempty = true
112 iso:depends("mode", "ap")
113
114 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
115 hide.rmempty = true
116 hide:depends("mode", "ap")
117
118 return m