util.lua 965 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/lua
  2. local uci = require('luci.model.uci').cursor()
  3. local iwinfo = require "iwinfo"
  4. function get_available_wifi_networks()
  5. local radios = {}
  6. uci:foreach('wireless', 'wifi-device',
  7. function(s)
  8. table.insert(radios, s['.name'])
  9. end
  10. )
  11. for _, radio in ipairs(radios) do
  12. local wifitype = iwinfo.type(radio)
  13. local iw = iwinfo[wifitype]
  14. if iw then
  15. local list = iw.scanlist(radio)
  16. for _, net in ipairs(list) do
  17. if net.ssid and net.bssid then
  18. if net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
  19. return radio, net.ssid, net.bssid
  20. end
  21. end
  22. end
  23. end
  24. end
  25. return false
  26. end
  27. function get_update_hosts(branch)
  28. local hosts = {}
  29. local mirrors = uci:get_list('autoupdater', branch, 'mirror')
  30. for _, mirror in ipairs(mirrors) do
  31. local host = mirror:match("://%[?([a-zA-Z0-9\:\.]+)%]?/")
  32. table.insert(hosts, 1, host)
  33. end
  34. return hosts
  35. end