luci-app-travelmate: enhance wireless security connection settings
[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 translatef("%s (%s/%s)", (info.wpa == 3) and translate("WPA/WPA2") or (info.wpa == 2 and "WPA2" or "WPA"), table.concat(info.auth_suites), table.concat(info.group_ciphers))
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
39 <%+header%>
40
41 <div class="cbi-map">
42 <h2 name="content"><%:Wireless Scan%></h2>
43     <fieldset class="cbi-section">
44         <table class="cbi-section-table" style="empty-cells:hide">
45             <tr class="cbi-section-table-titles">
46                 <th class="cbi-section-table-cell" style="text-align:left"><%:Uplink SSID%></th>
47                 <th class="cbi-section-table-cell" style="text-align:left"><%:Uplink BSSID%></th>
48                 <th class="cbi-section-table-cell" style="text-align:left"><%:Encryption%></th>
49                 <th class="cbi-section-table-cell" style="text-align:left" colspan="2"><%:Signal strength%></th>
50             </tr>
51             <% for i, net in ipairs(iw.scanlist or { }) do %>
52             <tr class="cbi-section-table-row cbi-rowstyle-1">
53                 <td class="cbi-value-field" style="text-align:left">
54                     <%=net.ssid and utl.pcdata(net.ssid) or "<em>%s</em>" % translate("hidden")%>
55                 </td>
56                 <td class="cbi-value-field" style="text-align:left">
57                     <%=net.bssid and utl.pcdata(net.bssid)%>
58                 </td>
59                 <td class="cbi-value-field" style="text-align:left">
60                     <%=format_wifi_encryption(net.encryption)%>
61                 </td>
62                 <td class="cbi-value-field" style="text-align:left">
63                     <%=percent_wifi_signal(net)%> %
64                 </td>
65                 <td class="cbi-value-field" style="width:100px;text-align:right">
66                     <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/wifiadd')%>" method="post">
67                         <input type="hidden" name="token" value="<%=token%>"/>
68                         <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>"/>
69                         <input type="hidden" name="ssid" value="<%=utl.pcdata(net.ssid)%>"/>
70                         <input type="hidden" name="bssid" value="<%=utl.pcdata(net.bssid)%>"/>
71                         <input type="hidden" name="wep" value="<%=net.encryption.wep and 1 or 0%>"/>
72                         <% if net.encryption.wpa then %>
73                             <input type="hidden" name="wpa_version" value="<%=net.encryption.wpa%>"/>
74                             <% for _, v in ipairs(net.encryption.auth_suites) do %><input type="hidden" name="wpa_suites" value="<%=v%>"/><% end %>
75                         <% end %>
76                         <input class="cbi-button cbi-button-apply" type="submit" value="<%:Add Uplink%>"/>
77                     </form>
78                 </td>
79             </tr>
80             <% end %>
81         </table>
82     </fieldset>
83 <div class="cbi-page-actions right">
84     <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/wifiscan')%>" method="post">
85         <input type="hidden" name="token" value="<%=token%>"/>
86         <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>"/>
87         <input class="cbi-button cbi-input-find" type="submit" value="<%:Repeat scan%>"/>
88     </form>
89     <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/stations')%>" method="post">
90         <input class="cbi-button cbi-button-reset" type="submit" value="<%:Back to overview%>"/>
91     </form>
92 </div>
93 </div>
94
95 <%+footer%>