Merge pull request #1239 from kuoruan/zh-cn-tr
[project/luci.git] / applications / luci-app-travelmate / luasrc / view / travelmate / wifi_scan.htm
1 <%#
2 Copyright 2017 Dirk Brenken (dev@brenken.org)
3 This is free software, licensed under the Apache License, Version 2.0
4 -%>
5
6 <%-
7     local sys = require "luci.sys"
8     local utl = require "luci.util"
9     local dev = luci.http.formvalue("device")
10     local iw = luci.sys.wifi.getiwinfo(dev)
11
12     if not iw then
13         luci.http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
14     end
15
16     function format_wifi_encryption(info)
17         if info.wep == true then
18             return translate("WEP")
19         elseif info.wpa > 0 then
20             return translate("WPA / WPA2")
21         elseif info.enabled then
22             return translate("Unknown")
23         else
24             return translate("Open")
25         end
26     end
27
28     function percent_wifi_signal(info)
29         local qc = info.quality or 0
30         local qm = info.quality_max or 0
31         if info.bssid and qc > 0 and qm > 0 then
32             return math.floor((100 / qm) * qc)
33         else
34             return 0
35         end
36     end
37
38     function scanlist(times)
39         local i, k, v
40         local l = { }
41         local s = { }
42
43         for i = 1, times do
44             for k, v in ipairs(iw.scanlist or { }) do
45                 if not s[v.bssid] then
46                     l[#l+1] = v
47                     s[v.bssid] = true
48                 end
49             end
50         end
51         return l
52     end
53 -%>
54
55 <%+header%>
56
57 <div class="cbi-map">
58 <h2 name="content"><%:Wireless Scan%></h2>
59
60     <fieldset class="cbi-section">
61         <table class="cbi-section-table" style="empty-cells:hide">
62             <tr class="cbi-section-table-titles">
63                 <th class="cbi-section-table-cell" style="text-align:left"><%:Uplink SSID%></th>
64                 <th class="cbi-section-table-cell" style="text-align:left"><%:Encryption%></th>
65                 <th class="cbi-section-table-cell" style="text-align:left" colspan="2"><%:Signal strength%></th>
66             </tr>
67             <% for i, net in ipairs(scanlist(3)) do net.encryption = net.encryption or { } %>
68             <tr class="cbi-section-table-row cbi-rowstyle-4">
69                 <td class="cbi-value-field" style="text-align:left">
70                     <strong><%=net.ssid and utl.pcdata(net.ssid) or "<em>%s</em>" % translate("hidden")%></strong>
71                 </td>
72                 <td class="cbi-value-field" style="text-align:left">
73                     <%=format_wifi_encryption(net.encryption)%>
74                 </td>
75                 <td class="cbi-value-field" style="text-align:left">
76                     <%=percent_wifi_signal(net)%> %
77                 </td>
78                 <td class="cbi-value-field" style="width:120px; text-align:right">
79                     <form class="inline" action="<%=url('admin/services/travelmate/wifiadd')%>" method="post">
80                         <input type="hidden" name="token" value="<%=token%>" />
81                         <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>" />
82                         <input type="hidden" name="ssid" value="<%=utl.pcdata(net.ssid)%>" />
83                         <input type="hidden" name="wep" value="<%=net.encryption.wep and 1 or 0%>" />
84                         <% if net.encryption.wpa then %>
85                         <input type="hidden" name="wpa_version" value="<%=net.encryption.wpa%>" />
86                         <% for _, v in ipairs(net.encryption.auth_suites) do %><input type="hidden" name="wpa_suites" value="<%=v%>" />
87                         <% end; for _, v in ipairs(net.encryption.group_ciphers) do %><input type="hidden" name="wpa_group" value="<%=v%>" />
88                         <% end; for _, v in ipairs(net.encryption.pair_ciphers) do %><input type="hidden" name="wpa_pairwise" value="<%=v%>" />
89                         <% end; end %>
90                         <input class="cbi-button cbi-button-apply" style="width:110px" type="submit" value="<%:Add Uplink%>" />
91                     </form>
92                 </td>
93             </tr>
94             <% end %>
95         </table>
96     </fieldset>
97 <div class="cbi-page-actions right">
98     <form class="inline" action="<%=url('admin/services/travelmate/stations')%>" method="post">
99         <input class="cbi-button cbi-button-reset" type="submit" value="<%:Back to overview%>" />
100     </form>
101     <form class="inline" action="<%=url('admin/services/travelmate/wifiscan')%>" method="post">
102         <input type="hidden" name="token" value="<%=token%>" />
103         <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>" />
104         <input class="cbi-button cbi-input-find" type="submit" value="<%:Repeat scan%>" />
105     </form>
106 </div>
107
108 <%+footer%>