modules/admin-full, modules/freifunk, modules/niu, libs/web, applications/luci-upnp...
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / wifi_join.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11 $Id$
12
13 -%>
14
15 <%-
16
17         local sys = require "luci.sys"
18         local utl = require "luci.util"
19
20         function guess_wifi_signal(info)
21                 local scale = (100 / (info.quality_max or 100) * (info.quality or 0))
22                 local icon
23
24                 if not info.bssid or info.bssid == "00:00:00:00:00:00" then
25                         icon = resource .. "/icons/signal-none.png"
26                 elseif scale < 15 then
27                         icon = resource .. "/icons/signal-0.png"
28                 elseif scale < 35 then
29                         icon = resource .. "/icons/signal-0-25.png"
30                 elseif scale < 55 then
31                         icon = resource .. "/icons/signal-25-50.png"
32                 elseif scale < 75 then
33                         icon = resource .. "/icons/signal-50-75.png"
34                 else
35                         icon = resource .. "/icons/signal-75-100.png"
36                 end
37
38                 return icon
39         end
40
41         function percent_wifi_signal(info)
42                 local qc = info.quality or 0
43                 local qm = info.quality_max or 0
44
45                 if info.bssid and qc > 0 and qm > 0 then
46                         return math.floor((100 / qm) * qc)
47                 else
48                         return 0
49                 end
50         end
51
52         function format_wifi_encryption(info)
53                 if info.wep == true and not info.wpa_version then
54                         return "WEP"
55                 elseif info.wpa then
56                         return "<abbr title='Pairwise: %s / Group: %s'>%s - %s</abbr>" % {
57                                 table.concat(info.pair_ciphers, ", "),
58                                 table.concat(info.group_ciphers, ", "),
59                                 (info.wpa == 3) and "mixed WPA/WPA2"
60                                         or (info.wpa == 2 and "WPA2" or "WPA"),
61                                 table.concat(info.auth_suites, ", ")
62                         }
63                 else
64                         return "<em>None</em>"
65                 end
66         end
67
68         local dev = luci.http.formvalue("device")
69         local iw = luci.sys.wifi.getiwinfo(dev)
70
71         if not iw then
72                 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
73                 return
74         end
75 -%>
76
77 <%+header%>
78
79 <h2><a id="content" name="content"><%:Join Network: Wireless Scan%></a></h2>
80
81 <div class="cbi-map">
82         <fieldset class="cbi-section">
83                 <table class="cbi-section-table" style="empty-cells:hide">
84                         <!-- scan list -->
85                         <% for i, net in ipairs(iw.scanlist) do net.encryption = net.encryption or { } %>
86                         <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
87                                 <td class="cbi-value-field" style="width:16px; padding:3px">
88                                         <abbr title="Signal: <%=net.signal%> dB / Quality: <%=net.quality%>/<%=net.quality_max%>">
89                                                 <img src="<%=guess_wifi_signal(net)%>" /><br />
90                                                 <small><%=percent_wifi_signal(net)%>%</small>
91                                         </abbr>
92                                 </td>
93                                 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
94                                         <big><strong><%=net.ssid and utl.pcdata(net.ssid) or "<em>hidden</em>"%></strong></big><br />
95                                         <strong>Channel:</strong> <%=net.channel%> |
96                                         <strong>Mode:</strong> <%=net.mode%> |
97                                         <strong>BSSID:</strong> <%=net.bssid%> |
98                                         <strong>Encryption:</strong> <%=net.encryption.description or translate("Open")%>
99                                 </td>
100                                 <td class="cbi-value-field" style="width:40px">
101                                         <form action="<%=REQUEST_URI%>" method="post">
102                                                 <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>" />
103                                                 <input type="hidden" name="join" value="<%=utl.pcdata(net.ssid)%>" />
104                                                 <input type="hidden" name="mode" value="<%=net.mode%>" />
105                                                 <input type="hidden" name="bssid" value="<%=net.bssid%>" />
106                                                 <input type="hidden" name="channel" value="<%=net.channel%>" />
107                                                 <input type="hidden" name="wep" value="<%=net.encryption.wep and 1 or 0%>" />
108                                                 <% if net.encryption.wpa then %>
109                                                 <input type="hidden" name="wpa_version" value="<%=net.encryption.wpa%>" />
110                                                 <% for _, v in ipairs(net.encryption.auth_suites) do %><input type="hidden" name="wpa_suites" value="<%=v%>" />
111                                                 <% end; for _, v in ipairs(net.encryption.group_ciphers) do %><input type="hidden" name="wpa_group" value="<%=v%>" />
112                                                 <% end; for _, v in ipairs(net.encryption.pair_ciphers) do %><input type="hidden" name="wpa_pairwise" value="<%=v%>" />
113                                                 <% end; end %>
114
115                                                 <input type="hidden" name="clbridge" value="<%=iw.type == "wl" and 1 or 0%>" />
116
117                                                 <input class="cbi-button-apply" type="submit" value="<%:Join Network%>" />
118                                         </form>
119                                 </td>
120                         </tr>
121                         <% end %>
122                         <!-- /scan list -->
123                 </table>
124         </fieldset>
125 </div>
126 <div class="cbi-page-actions right">
127         <form class="inline" action="<%=luci.dispatcher.build_url("admin/network/wireless")%>" method="get">
128                 <input class="cbi-button-reset" type="submit" value="<%:Back to overview%>" />
129         </form>
130         <form class="inline" action="<%=REQUEST_URI%>" method="get">
131                 <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>" />
132                 <input class="cbi-button cbi-input-find" type="submit" value="<%:Repeat scan%>" />
133         </form>
134 </div>
135
136 <%+footer%>