2 Copyright 2009 Jo-Philipp Wich <jow@openwrt.org>
3 Licensed to the public under the Apache License 2.0.
8 local sys = require "luci.sys"
9 local utl = require "luci.util"
11 function guess_wifi_signal(info)
12 local scale = (100 / (info.quality_max or 100) * (info.quality or 0))
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"
26 icon = resource .. "/icons/signal-75-100.png"
32 function percent_wifi_signal(info)
33 local qc = info.quality or 0
34 local qm = info.quality_max or 0
36 if info.bssid and qc > 0 and qm > 0 then
37 return math.floor((100 / qm) * qc)
43 function format_wifi_encryption(info)
44 if info.wep == true then
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, ", ")
54 elseif info.enabled then
55 return "<em>%s</em>" % translate("unknown")
57 return "<em>%s</em>" % translate("open")
61 local dev = luci.http.formvalue("device")
62 local iw = luci.sys.wifi.getiwinfo(dev)
65 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
70 function scanlist(times)
76 for k, v in ipairs(iw.scanlist or { }) do
77 if not s[v.bssid] then
90 <h2 name="content"><%:Join Network: Wireless Scan%></h2>
93 <fieldset class="cbi-section">
94 <table class="cbi-section-table" style="empty-cells:hide">
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>
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)%>
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%>" />
126 <input type="hidden" name="clbridge" value="<%=iw.type == "wl" and 1 or 0%>" />
128 <input class="cbi-button cbi-button-apply" type="submit" value="<%:Join Network%>" />
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%>" />
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%>" />