wifi_join.htm 4.8 KB

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