wifi_scan.htm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. local sys = require("luci.sys")
  7. local utl = require("luci.util")
  8. local dev = luci.http.formvalue("device")
  9. local iw = luci.sys.wifi.getiwinfo(dev)
  10. if not iw then
  11. luci.http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))
  12. end
  13. function format_wifi_encryption(info)
  14. if info.wep == true then
  15. return translate("WEP")
  16. elseif info.wpa > 0 then
  17. return translate("WPA / WPA2")
  18. elseif info.enabled then
  19. return translate("Unknown")
  20. else
  21. return translate("Open")
  22. end
  23. end
  24. function percent_wifi_signal(info)
  25. local qc = info.quality or 0
  26. local qm = info.quality_max or 0
  27. if info.ssid and qc > 0 and qm > 0 then
  28. return math.floor((100 / qm) * qc)
  29. else
  30. return 0
  31. end
  32. end
  33. -%>
  34. <%+header%>
  35. <div class="cbi-map">
  36. <h2 name="content"><%:Wireless Scan%></h2>
  37. <fieldset class="cbi-section">
  38. <table class="cbi-section-table" style="empty-cells:hide">
  39. <tr class="cbi-section-table-titles">
  40. <th class="cbi-section-table-cell" style="text-align:left"><%:Uplink SSID%></th>
  41. <th class="cbi-section-table-cell" style="text-align:left"><%:Encryption%></th>
  42. <th class="cbi-section-table-cell" style="text-align:left" colspan="2"><%:Signal strength%></th>
  43. </tr>
  44. <% for i, net in ipairs(iw.scanlist or { }) do %>
  45. <tr class="cbi-section-table-row cbi-rowstyle-1">
  46. <td class="cbi-value-field" style="text-align:left">
  47. <strong><%=net.ssid and utl.pcdata(net.ssid) or "<em>%s</em>" % translate("hidden")%></strong>
  48. </td>
  49. <td class="cbi-value-field" style="text-align:left">
  50. <%=format_wifi_encryption(net.encryption)%>
  51. </td>
  52. <td class="cbi-value-field" style="text-align:left">
  53. <%=percent_wifi_signal(net)%> %
  54. </td>
  55. <td class="cbi-value-field" style="width:100px;text-align:right">
  56. <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/wifiadd')%>" method="post">
  57. <input type="hidden" name="token" value="<%=token%>"/>
  58. <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>"/>
  59. <input type="hidden" name="ssid" value="<%=utl.pcdata(net.ssid)%>"/>
  60. <input type="hidden" name="wep" value="<%=net.encryption.wep and 1 or 0%>"/>
  61. <% if net.encryption.wpa then %>
  62. <input type="hidden" name="wpa_version" value="<%=net.encryption.wpa%>"/>
  63. <% for _, v in ipairs(net.encryption.auth_suites) do %><input type="hidden" name="wpa_suites" value="<%=v%>"/>
  64. <% end; end %>
  65. <input class="cbi-button cbi-button-apply" type="submit" value="<%:Add Uplink%>"/>
  66. </form>
  67. </td>
  68. </tr>
  69. <% end %>
  70. </table>
  71. </fieldset>
  72. <div class="cbi-page-actions right">
  73. <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/wifiscan')%>" method="post">
  74. <input type="hidden" name="token" value="<%=token%>"/>
  75. <input type="hidden" name="device" value="<%=utl.pcdata(dev)%>"/>
  76. <input class="cbi-button cbi-input-find" type="submit" value="<%:Repeat scan%>"/>
  77. </form>
  78. <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/stations')%>" method="post">
  79. <input class="cbi-button cbi-button-reset" type="submit" value="<%:Back to overview%>"/>
  80. </form>
  81. </div>
  82. </div>
  83. <%+footer%>