modules/admin-full: link to wifi network adding in overview
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / wifi_overview.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <%-
17
18 local sys = require "luci.sys"
19 local utl = require "luci.util"
20 local uci = require "luci.model.uci".cursor()
21 local wlm = require "luci.model.wireless"
22
23 wlm.init(uci)
24
25 function guess_wifi_hw(ifname)
26 local name, idx = ifname:match("^([a-z]+)(%d+)")
27 idx = tonumber(idx)
28
29 -- wl.o
30 if name == "wl" then
31 local name = "Broadcom 802.11 Wireless Controller"
32 local nm = 0
33
34 local fd = nixio.open("/proc/bus/pci/devices", "r")
35 if fd then
36 local ln
37 for ln in fd:linesource() do
38 if ln:match("wl$") then
39 if nm == idx then
40 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
41 name = string.format(
42 "Broadcom BCM%04x 802.11 Wireless Controller",
43 tonumber(version, 16)
44 )
45
46 break
47 else
48 nm = nm + 1
49 end
50 end
51 end
52 fd:close()
53 end
54
55 return name
56
57 -- madwifi
58 elseif name == "ath" or name == "wifi" then
59 return "Atheros 802.11 Wireless Controller"
60
61 -- ralink
62 elseif name == "ra" then
63 return "RaLink 802.11 Wireless Controller"
64
65 -- prism?
66 elseif name == "eth" then
67 return "Prism 802.11 Wireless Controller"
68
69 -- dunno yet
70 else
71 return "Generic 802.11 Wireless Controller"
72 end
73 end
74
75 function guess_wifi_signal(scale)
76 local icon
77
78 if scale < 0 then
79 icon = resource .. "/icons/signal-none.png"
80 elseif scale < 1 then
81 icon = resource .. "/icons/signal-0.png"
82 elseif scale < 2 then
83 icon = resource .. "/icons/signal-0-25.png"
84 elseif scale < 3 then
85 icon = resource .. "/icons/signal-25-50.png"
86 elseif scale < 4 then
87 icon = resource .. "/icons/signal-50-75.png"
88 else
89 icon = resource .. "/icons/signal-75-100.png"
90 end
91
92 return icon
93 end
94
95 local devices = wlm:get_devices()
96 local arpcache = { }
97 sys.net.arptable(function(e) arpcache[e["HW address"]] = e["IP address"] end)
98 -%>
99
100 <%+header%>
101
102 <h2><a id="content" name="content"><%:Wireless Overview%></a></h2>
103
104 <div class="cbi-map">
105
106 <% for _, dev in ipairs(devices) do local nets = dev:get_networks() %>
107 <!-- device <%=dev:name()%> -->
108 <fieldset class="cbi-section">
109 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
110 <!-- physical device -->
111 <tr>
112 <td style="width:34px"><img src="<%=resource%>/icons/wifi<%=dev:is_up() and "" or "_disabled"%>.png" style="float:left; margin-right:10px" /></td>
113 <td colspan="2" style="text-align:left">
114 <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br />
115 <% if nets[1] then %>
116 <strong>Channel:</strong> <%=nets[1]:channel() or "?"%> (<%=nets[1]:frequency() or "?"%> GHz) |
117 <strong>Bitrate:</strong> <%=nets[1]:bitrate() or "?"%> Mb/s
118 <% end %>
119 </td>
120 <td style="width:40px">
121 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_join?device="..dev:name())%>"><img style="border:none" src="<%=resource%>/cbi/find.gif" alt="Find and join network" title="Find and join network" /></a>
122 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_add?device="..dev:name())%>"><img style="border:none" src="<%=resource%>/cbi/add.gif" alt="Provide new network" title="Provide new network" /></a>
123 </td>
124 </tr>
125 <!-- /physical device -->
126
127 <!-- network list -->
128 <% if #nets > 0 then %>
129 <% for i, net in ipairs(nets) do %>
130 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
131 <td></td>
132 <td class="cbi-value-field" style="width:16px; padding:3px">
133 <img src="<%=guess_wifi_signal(net:signal_level())%>" title="Signal: <%=net:signal()%> dBm / Noise: <%=net:noise()%> dBm" /><br />
134 <small><%=net:signal_percent()%>%</small>
135 </td>
136 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
137 <strong>SSID:</strong> <%=utl.pcdata(net:active_ssid())%> |
138 <strong>Mode:</strong> <%=net:active_mode_i18n()%><br />
139 <strong>BSSID:</strong> <%=net:active_bssid()%> |
140 <strong>Encryption:</strong> <%=net:active_encryption()%>
141 </td>
142 <td class="cbi-value-field" style="width:40px">
143 <a href="<%=REQUEST_URI%>/<%=dev:name()%>/<%=net:name()%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="Edit this network" title="Edit this network" /></a>
144 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:name())%>"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="Delete this network" title="Delete this network" /></a>
145 </td>
146 </tr>
147 <% end %>
148 <% else %>
149 <tr class="cbi-section-table-row cbi-rowstyle-2">
150 <td></td>
151 <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
152 <em>(No network configured on this device)</em>
153 </td>
154 </tr>
155 <% end %>
156 <!-- /network list -->
157 </table>
158 </fieldset>
159 <!-- /device <%=dev:name()%> -->
160 <% end %>
161
162
163
164
165 <h2><a id="content" name="content"><%:Associated Stations%></a></h2>
166
167 <fieldset class="cbi-section">
168 <table class="cbi-section-table" style="margin:10px; width:50%">
169 <tr class="cbi-section-table-titles">
170 <th class="cbi-section-table-cell"></th>
171 <th class="cbi-section-table-cell">SSID</th>
172 <th class="cbi-section-table-cell">MAC</th>
173 <th class="cbi-section-table-cell">Address</th>
174 <th class="cbi-section-table-cell">Signal</th>
175 <th class="cbi-section-table-cell">Noise</th>
176 </tr>
177
178 <% local count = -1 %>
179 <% for _, dev in ipairs(devices) do local nets = dev:get_networks() %>
180 <% for _, net in ipairs(nets) do %>
181 <% for mac, info in utl.kspairs(net:assoclist()) do count = count + 1 %>
182 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + (count % 2)%>">
183 <td class="cbi-value-field"><img src="<%=guess_wifi_signal(net:signal_level(info.signal, info.noise))%>" title="Signal: <%=info.signal%> dBm / Noise: <%=info.noise%> dBm" /></td>
184 <td class="cbi-value-field"><%=net:active_ssid()%></td>
185 <td class="cbi-value-field"><%=mac%></td>
186 <td class="cbi-value-field"><%=arpcache[mac] or "n/a"%></td>
187 <td class="cbi-value-field"><%=info.signal%> dBm</td>
188 <td class="cbi-value-field"><%=info.noise%> dBm</td>
189 </tr>
190 <% end %>
191 <% end %>
192 <% end %>
193 <% if count <= 0 then %>
194 <tr class="cbi-section-table-row cbi-rowstyle-2">
195 <td class="cbi-value-field" colspan="6">
196 <em>No information available</em>
197 </td>
198 </tr>
199 <% end %>
200 </table>
201 </fieldset>
202 </div>
203
204 <%+footer%>