0200-site-select.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local cbi = require "luci.cbi"
  2. local i18n = require "luci.i18n"
  3. local uci = luci.model.uci.cursor()
  4. local site = require 'gluon.site_config'
  5. local fs = require "nixio.fs"
  6. local sites = {}
  7. local M = {}
  8. function M.section(form)
  9. local msg = i18n.translate('Here you have the possibility of selecting the region in which ' ..
  10. 'your node is placed. Please keep in mind that your router ' ..
  11. 'connects only with the mesh of the selected region')
  12. local s = form:section(cbi.SimpleSection, nil, msg)
  13. uci:foreach('siteselect', 'site',
  14. function(s)
  15. table.insert(sites, s['.name'])
  16. end
  17. )
  18. local o = s:option(cbi.ListValue, "community", i18n.translate("Region"))
  19. o.rmempty = false
  20. o.optional = false
  21. if uci:get_first("gluon-setup-mode", "setup_mode", "configured") == "0" then
  22. o:value("")
  23. else
  24. o:value(site.site_code, site.site_name)
  25. end
  26. for index, site in ipairs(sites) do
  27. o:value(site, uci:get('siteselect', site, 'sitename'))
  28. end
  29. end
  30. function M.handle(data)
  31. if data.community ~= site.site_code then
  32. fs.copy(uci:get('siteselect', data.community , 'path'), '/lib/gluon/site.conf')
  33. uci:set('currentsite', 'current', 'name', data.community)
  34. uci:save('currentsite')
  35. uci:commit('currentsite')
  36. os.execute('sh "/lib/gluon/site-upgrade"')
  37. end
  38. end
  39. return M