d75ead282ac3ff71f001869bbfbf9a962530ae5b
[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", "Access Point")
54 mode:value("adhoc", "Ad-Hoc")
55 mode:value("sta", "Client")
56
57 function mode.write(self, section, value)
58         if value == "sta" then
59                 luci.model.uci.set("network", "wan", "type", "bridge")
60                 luci.model.uci.set("wireless", section, "network", "wan")
61         else
62                 luci.model.uci.delete("network", "wan", "type")
63                 luci.model.uci.set("wireless", section, "network", "lan")
64         end
65         luci.model.uci.save("network")
66         return ListValue.write(self, section, value)
67 end
68
69 encr = s:option(ListValue, "encryption", translate("encryption"))
70 encr:value("none", "keine")
71 encr:value("wep", "WEP")
72 encr:value("psk", "WPA-PSK")
73 encr:value("wpa", "WPA-Radius")
74 encr:value("psk2", "WPA2-PSK")
75 encr:value("wpa2", "WPA2-Radius")
76
77 key = s:option(Value, "key", translate("key"))
78 key:depends("encryption", "wep")
79 key:depends("encryption", "psk")
80 key:depends("encryption", "wpa")
81 key:depends("encryption", "psk2")
82 key:depends("encryption", "wpa2")
83 key.rmempty = true
84
85 server = s:option(Value, "server", translate("a_w_radiussrv"))
86 server:depends("encryption", "wpa")
87 server:depends("encryption", "wpa2")
88 server.rmempty = true
89
90 port = s:option(Value, "port", translate("a_w_radiusport"))
91 port:depends("encryption", "wpa")
92 port:depends("encryption", "wpa2")
93 port.rmempty = true
94
95 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
96 iso.rmempty = true
97 iso:depends("mode", "ap")
98
99 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
100 hide.rmempty = true
101 hide:depends("mode", "ap")
102
103 return m