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