util.lua 908 B

1234567891011121314151617181920212223242526272829303132333435363738
  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:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
  18. return radio, net.ssid, net.bssid
  19. end
  20. end
  21. end
  22. end
  23. return false
  24. end
  25. function get_update_hosts(branch)
  26. local hosts = {}
  27. local mirrors = uci:get_list('autoupdater', branch, 'mirror')
  28. for _, mirror in ipairs(mirrors) do
  29. local host = mirror:match("://%[?([a-zA-Z0-9\:\.]+)%]?/")
  30. table.insert(hosts, 1, host)
  31. end
  32. return hosts
  33. end