libs/cbi: Fixed CBI handling of "Save & Apply"
[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 m:chain("network")
17
18 s = m:section(TypedSection, "wifi-device", translate("devices"))
19
20 en = s:option(Flag, "disabled", translate("enable"))
21 en.enabled = "0"
22 en.disabled = "1"
23
24 mode = s:option(ListValue, "mode", translate("mode"))
25 mode:value("", "standard")
26 mode:value("11b", "802.11b")
27 mode:value("11g", "802.11g")
28 mode:value("11a", "802.11a")
29 mode:value("11bg", "802.11b+g")
30 mode.rmempty = true
31
32 s:option(Value, "channel", translate("a_w_channel"))
33
34
35
36 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
37 s.anonymous = true
38
39 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
40
41 local devs = {}
42 luci.model.uci.foreach("wireless", "wifi-device",
43         function (section)
44                 table.insert(devs, section[".name"])
45         end)
46         
47 if #devs > 1 then
48         device = s:option(DummyValue, "device", translate("device"))
49 else
50         s.defaults.device = devs[1]
51 end
52
53 mode = s:option(ListValue, "mode", translate("mode"))
54 mode:value("ap", translate("m_w_ap"))
55 mode:value("adhoc", translate("m_w_adhoc"))
56 mode:value("sta", translate("m_w_client"))
57
58 function mode.write(self, section, value)
59         if value == "sta" then
60                 -- ToDo: Move this away
61                 if not luci.model.uci.get("network", "wan") then
62                         luci.model.uci.set("network", "wan", "proto", "none")
63                         luci.model.uci.set("network", "wan", "ifname", " ")
64                 end
65
66                 local oldif = luci.model.uci.get("network", "wan", "ifname")
67                 if oldif and oldif ~= " " then
68                         luci.model.uci.set("network", "wan", "_ifname", oldif)
69                 end
70                 luci.model.uci.set("network", "wan", "ifname", " ")
71
72                 self.map:set(section, "network", "wan")
73         else
74                 if luci.model.uci.get("network", "wan", "_ifname") then
75                         luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
76                 end
77                 self.map:set(section, "network", "lan")
78         end
79
80         return ListValue.write(self, section, value)
81 end
82
83 encr = s:option(ListValue, "encryption", translate("encryption"))
84 encr:value("none", "keine")
85 encr:value("wep", "WEP")
86 encr:value("psk", "WPA-PSK")
87 encr:value("wpa", "WPA-Radius")
88 encr:value("psk2", "WPA2-PSK")
89 encr:value("wpa2", "WPA2-Radius")
90
91 key = s:option(Value, "key", translate("key"))
92 key:depends("encryption", "wep")
93 key:depends("encryption", "psk")
94 key:depends("encryption", "wpa")
95 key:depends("encryption", "psk2")
96 key:depends("encryption", "wpa2")
97 key.rmempty = true
98
99 server = s:option(Value, "server", translate("a_w_radiussrv"))
100 server:depends("encryption", "wpa")
101 server:depends("encryption", "wpa2")
102 server.rmempty = true
103
104 port = s:option(Value, "port", translate("a_w_radiusport"))
105 port:depends("encryption", "wpa")
106 port:depends("encryption", "wpa2")
107 port.rmempty = true
108
109 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
110 iso.rmempty = true
111 iso:depends("mode", "ap")
112
113 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
114 hide.rmempty = true
115 hide:depends("mode", "ap")
116
117 return m