util.lua 990 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. 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. local ssid = net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*')
  18. if ssid then
  19. return radio, ssid
  20. end
  21. end
  22. end
  23. end
  24. return false
  25. end
  26. function get_update_hosts()
  27. local hosts = {}
  28. local branch = uci:get('autoupdater', 'settings', 'branch')
  29. local mirrors = uci:get_list('autoupdater', branch, 'mirror')
  30. while #mirrors > 0 do
  31. local m = table.remove(mirrors)
  32. mirror = m:match("://%[?([a-zA-Z0-9\:\.]+)%]?/")
  33. table.insert(hosts, 1, mirror)
  34. end
  35. return hosts
  36. end