util.lua 938 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/lua
  2. local uci = require('simple-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. radios[s['.name']] = {}
  9. end
  10. )
  11. for radio, _ in pairs(radios) do
  12. local wifitype = iwinfo.type(radio)
  13. local iw = iwinfo[wifitype]
  14. if not iw then
  15. return null
  16. end
  17. local tmplist = iw.scanlist(radio)
  18. for _, net in ipairs(tmplist) do
  19. if net.ssid and net.bssid and net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
  20. table.insert (radios[radio], net)
  21. end
  22. end
  23. end
  24. return radios
  25. end
  26. function get_update_hosts(branch)
  27. local hosts = {}
  28. local mirrors = uci:get_list('autoupdater', branch, 'mirror')
  29. for _, mirror in ipairs(mirrors) do
  30. local host = mirror:match('://%[?([a-zA-Z0-9\-\:\.]+)%]?/')
  31. table.insert(hosts, 1, host)
  32. end
  33. return hosts
  34. end