f612e9d537867d8a69b71e94ba22ee6b39490a1b
[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", "interface")
62                         luci.model.uci.set("network", "wan", "proto", "none")
63                 end
64
65                 luci.model.uci.set("network", "wan", "type", "bridge")
66                 luci.model.uci.save("network")
67
68                 self.map:set(section, "network", "wan")
69         else
70                 self.map:set(section, "network", "lan")
71         end
72
73         return ListValue.write(self, section, value)
74 end
75
76 encr = s:option(ListValue, "encryption", translate("encryption"))
77 encr:value("none", "keine")
78 encr:value("wep", "WEP")
79 encr:value("psk", "WPA-PSK")
80 encr:value("wpa", "WPA-Radius")
81 encr:value("psk2", "WPA2-PSK")
82 encr:value("wpa2", "WPA2-Radius")
83
84 key = s:option(Value, "key", translate("key"))
85 key:depends("encryption", "wep")
86 key:depends("encryption", "psk")
87 key:depends("encryption", "wpa")
88 key:depends("encryption", "psk2")
89 key:depends("encryption", "wpa2")
90 key.rmempty = true
91
92 server = s:option(Value, "server", translate("a_w_radiussrv"))
93 server:depends("encryption", "wpa")
94 server:depends("encryption", "wpa2")
95 server.rmempty = true
96
97 port = s:option(Value, "port", translate("a_w_radiusport"))
98 port:depends("encryption", "wpa")
99 port:depends("encryption", "wpa2")
100 port.rmempty = true
101
102 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
103 iso.rmempty = true
104 iso:depends("mode", "ap")
105
106 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
107 hide.rmempty = true
108 hide:depends("mode", "ap")
109
110 return m