Updated Wifi Configuration in Mini, removed some orphaned pages
[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
16 -- Data init --
17
18 luci.model.uci.load_state("wireless")
19 local wireless = luci.model.uci.get_all("wireless")
20 luci.model.uci.unload("wireless")
21
22 local wifidata = luci.sys.wifi.getiwconfig()
23 local ifaces = {}
24
25 for k, v in pairs(wireless) do
26         if v[".type"] == "wifi-iface" then
27                 table.insert(ifaces, v)
28         end
29 end
30
31
32 -- Main Map --
33
34 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
35 m:chain("network")
36
37
38 -- Status Table --
39 s = m:section(Table, ifaces, translate("networks"))
40
41 link = s:option(DummyValue, "_link", translate("link"))
42 function link.cfgvalue(self, section)
43         local ifname = self.map:get(section, "ifname")
44         return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
45 end
46
47 essid = s:option(DummyValue, "ssid", "ESSID")
48
49 bssid = s:option(DummyValue, "_bsiid", "BSSID")
50 function bssid.cfgvalue(self, section)
51         local ifname = self.map:get(section, "ifname")
52         return (wifidata[ifname] and (wifidata[ifname].Cell 
53          or wifidata[ifname]["Access Point"])) or "-"
54 end
55
56 channel = s:option(DummyValue, "channel", translate("channel"))
57 function channel.cfgvalue(self, section)
58         return wireless[self.map:get(section, "device")].channel
59 end
60
61 protocol = s:option(DummyValue, "_mode", translate("protocol"))
62 function protocol.cfgvalue(self, section)
63         return "802." .. wireless[self.map:get(section, "device")].mode
64 end
65
66 mode = s:option(DummyValue, "mode", translate("mode"))
67 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
68
69 power = s:option(DummyValue, "_power", translate("power"))
70 function power.cfgvalue(self, section)
71         local ifname = self.map:get(section, "ifname")
72         return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
73 end
74
75 scan = s:option(Button, "_scan", translate("scan"))
76 scan.inputstyle = "find"
77
78 function scan.cfgvalue(self, section)
79         return self.map:get(section, "ifname") or false
80 end
81
82 -- WLAN-Scan-Table --
83
84 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
85
86 function scan.write(self, section)
87         t2.render = t2._render
88         local ifname = self.map:get(section, "ifname")
89         luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
90 end
91
92 t2._render = t2.render
93 t2.render = function() end
94
95 t2:option(DummyValue, "Quality", translate("iwscan_link"))
96 essid = t2:option(DummyValue, "ESSID", "ESSID")
97 function essid.cfgvalue(self, section)
98         return luci.util.pcdata(self.map:get(section, "ESSID"))
99 end
100
101 t2:option(DummyValue, "Address", "BSSID")
102 t2:option(DummyValue, "Mode", translate("mode"))
103 chan = t2:option(DummyValue, "channel", translate("channel"))
104 function chan.cfgvalue(self, section)
105         return self.map:get(section, "Channel")
106             or self.map:get(section, "Frequency")
107             or "-"
108 end 
109
110 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
111
112 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
113
114 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
115
116
117 -- Config Section --
118
119 s = m:section(TypedSection, "wifi-device", translate("devices"))
120
121 en = s:option(Flag, "disabled", translate("enable"))
122 en.enabled = "0"
123 en.disabled = "1"
124
125 function en.cfgvalue(self, section)
126         return Flag.cfgvalue(self, section) or "0"
127 end
128
129
130 mode = s:option(ListValue, "mode", translate("mode"))
131 mode:value("", "standard")
132 mode:value("11b", "802.11b")
133 mode:value("11g", "802.11g")
134 mode:value("11a", "802.11a")
135 mode:value("11bg", "802.11b+g")
136 mode.rmempty = true
137
138 s:option(Value, "channel", translate("a_w_channel"))
139
140
141
142 s = m:section(TypedSection, "wifi-iface", translate("m_n_local"))
143 s.anonymous = true
144
145 s:option(Value, "ssid", translate("a_w_netid")).maxlength = 32
146
147 local devs = {}
148 luci.model.uci.foreach("wireless", "wifi-device",
149         function (section)
150                 table.insert(devs, section[".name"])
151         end)
152         
153 if #devs > 1 then
154         device = s:option(DummyValue, "device", translate("device"))
155 else
156         s.defaults.device = devs[1]
157 end
158
159 mode = s:option(ListValue, "mode", translate("mode"))
160 mode:value("ap", translate("m_w_ap"))
161 mode:value("adhoc", translate("m_w_adhoc"))
162 mode:value("sta", translate("m_w_client"))
163
164 function mode.write(self, section, value)
165         if value == "sta" then
166                 -- ToDo: Move this away
167                 if not luci.model.uci.get("network", "wan") then
168                         luci.model.uci.set("network", "wan", "proto", "none")
169                         luci.model.uci.set("network", "wan", "ifname", " ")
170                 end
171
172                 local oldif = luci.model.uci.get("network", "wan", "ifname")
173                 if oldif and oldif ~= " " then
174                         luci.model.uci.set("network", "wan", "_ifname", oldif)
175                 end
176                 luci.model.uci.set("network", "wan", "ifname", " ")
177
178                 self.map:set(section, "network", "wan")
179         else
180                 if luci.model.uci.get("network", "wan", "_ifname") then
181                         luci.model.uci.set("network", "wan", "ifname", luci.model.uci.get("network", "wan", "_ifname"))
182                 end
183                 self.map:set(section, "network", "lan")
184         end
185
186         return ListValue.write(self, section, value)
187 end
188
189 encr = s:option(ListValue, "encryption", translate("encryption"))
190 encr:value("none", "keine")
191 encr:value("wep", "WEP")
192 encr:value("psk", "WPA-PSK")
193 encr:value("wpa", "WPA-Radius")
194 encr:value("psk2", "WPA2-PSK")
195 encr:value("wpa2", "WPA2-Radius")
196
197 key = s:option(Value, "key", translate("key"))
198 key:depends("encryption", "wep")
199 key:depends("encryption", "psk")
200 key:depends("encryption", "wpa")
201 key:depends("encryption", "psk2")
202 key:depends("encryption", "wpa2")
203 key.rmempty = true
204
205 server = s:option(Value, "server", translate("a_w_radiussrv"))
206 server:depends("encryption", "wpa")
207 server:depends("encryption", "wpa2")
208 server.rmempty = true
209
210 port = s:option(Value, "port", translate("a_w_radiusport"))
211 port:depends("encryption", "wpa")
212 port:depends("encryption", "wpa2")
213 port.rmempty = true
214
215 iso = s:option(Flag, "isolate", translate("a_w_apisolation"), translate("a_w_apisolation1"))
216 iso.rmempty = true
217 iso:depends("mode", "ap")
218
219 hide = s:option(Flag, "hidden", translate("a_w_hideessid"))
220 hide.rmempty = true
221 hide:depends("mode", "ap")
222
223 return m