Fix urltoken passing on several pages
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / wireless.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 require("luci.sys")
16 require("luci.tools.webadmin")
17
18 local wireless = luci.model.uci.cursor_state():get_all("wireless")
19 local wifidata = luci.sys.wifi.getiwconfig()
20 local ifaces = {}
21
22 for k, v in pairs(wireless) do
23 if v[".type"] == "wifi-iface" then
24 table.insert(ifaces, v)
25 end
26 end
27
28
29 m = SimpleForm("wireless", translate("wifi"))
30
31 s = m:section(Table, ifaces, translate("networks"))
32
33 function s.extedit(self, section)
34 local device = self.map:get(section, "device") or ""
35 return luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path)) .. "/" .. device
36 end
37
38 link = s:option(DummyValue, "_link", translate("link"))
39 function link.cfgvalue(self, section)
40 local ifname = self.map:get(section, "ifname")
41 return wifidata[ifname] and wifidata[ifname]["Link Quality"] or "-"
42 end
43
44 essid = s:option(DummyValue, "ssid", "ESSID")
45
46 bssid = s:option(DummyValue, "_bsiid", "BSSID")
47 function bssid.cfgvalue(self, section)
48 local ifname = self.map:get(section, "ifname")
49 return (wifidata[ifname] and (wifidata[ifname].Cell
50 or wifidata[ifname]["Access Point"])) or "-"
51 end
52
53 channel = s:option(DummyValue, "channel", translate("channel"))
54 function channel.cfgvalue(self, section)
55 return wireless[self.map:get(section, "device")].channel
56 end
57
58 protocol = s:option(DummyValue, "_mode", translate("protocol"))
59 function protocol.cfgvalue(self, section)
60 local mode = wireless[self.map:get(section, "device")].mode
61 return mode and "802." .. mode
62 end
63
64 mode = s:option(DummyValue, "mode", translate("mode"))
65 encryption = s:option(DummyValue, "encryption", translate("iwscan_encr"))
66
67 power = s:option(DummyValue, "_power", translate("power"))
68 function power.cfgvalue(self, section)
69 local ifname = self.map:get(section, "ifname")
70 return wifidata[ifname] and wifidata[ifname]["Tx-Power"] or "-"
71 end
72
73 scan = s:option(Button, "_scan", translate("scan"))
74 scan.inputstyle = "find"
75
76 function scan.cfgvalue(self, section)
77 return self.map:get(section, "ifname") or false
78 end
79
80 t2 = m:section(Table, {}, translate("iwscan"), translate("iwscan1"))
81
82 function scan.write(self, section)
83 t2.render = t2._render
84 local ifname = self.map:get(section, "ifname")
85 luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname))
86 end
87
88 t2._render = t2.render
89 t2.render = function() end
90
91 t2:option(DummyValue, "Quality", translate("iwscan_link"))
92 essid = t2:option(DummyValue, "ESSID", "ESSID")
93 function essid.cfgvalue(self, section)
94 return luci.util.pcdata(self.map:get(section, "ESSID"))
95 end
96
97 t2:option(DummyValue, "Address", "BSSID")
98 t2:option(DummyValue, "Mode", translate("mode"))
99 chan = t2:option(DummyValue, "channel", translate("channel"))
100 function chan.cfgvalue(self, section)
101 return self.map:get(section, "Channel")
102 or self.map:get(section, "Frequency")
103 or "-"
104 end
105
106 t2:option(DummyValue, "Encryption key", translate("iwscan_encr"))
107
108 t2:option(DummyValue, "Signal level", translate("iwscan_signal"))
109
110 t2:option(DummyValue, "Noise level", translate("iwscan_noise"))
111
112
113 s2 = m:section(SimpleSection, translate("a_w_create"))
114 create = s2:option(ListValue, "create", translate("device"))
115 create:value("", translate("cbi_select"))
116 for k, v in pairs(wireless) do
117 if v[".type"] == "wifi-device" then
118 create:value(k)
119 end
120 end
121
122 function create.write(self, section, value)
123 local uci = luci.model.uci.cursor()
124 uci:load("wireless")
125 uci:section("wireless", "wifi-iface", nil, {device=value})
126 uci:save("wireless")
127 luci.http.redirect(luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path)) .. "/" .. value)
128 end
129
130 function create.cbid(self, section)
131 return "priv.cbid.create"
132 end
133
134 return m