util.lua 963 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. 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 iw then
  15. local tmplist = iw.scanlist(radio)
  16. for _, net in ipairs(tmplist) do
  17. if net.ssid and net.bssid then
  18. if net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
  19. table.insert (radios[radio], net)
  20. end
  21. end
  22. end
  23. end
  24. end
  25. return radios
  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