|
@@ -3,16 +3,7 @@
|
|
|
local uci = require('luci.model.uci').cursor()
|
|
|
local json = require 'luci.json'
|
|
|
local site_code = require('gluon.site_config').site_code
|
|
|
-
|
|
|
-function get_config(file)
|
|
|
- local f = io.open(file)
|
|
|
- if f then
|
|
|
- local config = json.decode(f:read('*a'))
|
|
|
- f:close()
|
|
|
- return config
|
|
|
- end
|
|
|
- return nil
|
|
|
-end
|
|
|
+local tools = require 'gluon.site_generate'
|
|
|
|
|
|
function add_var_to_table(table, var)
|
|
|
if type(var) == "table" and type(table) == "table" then
|
|
@@ -27,14 +18,14 @@ function add_var_to_table(table, var)
|
|
|
return table
|
|
|
end
|
|
|
|
|
|
-local default = get_config('/lib/gluon/site-select/default.json')
|
|
|
-local groups = get_config('/lib/gluon/site-select/groups.json')
|
|
|
-local sites = get_config('/lib/gluon/site-select/sites.json')
|
|
|
+local default = tools.get_config('/lib/gluon/site-select/default.json')
|
|
|
+local groups = tools.get_config('/lib/gluon/site-select/groups.json')
|
|
|
+local sites = tools.get_config('/lib/gluon/site-select/sites.json')
|
|
|
local currentsite = uci:get("currentsite", "current", "name")
|
|
|
|
|
|
if site_code ~= currentsite then
|
|
|
local configured = false
|
|
|
- for index, site in pairs(sites) do
|
|
|
+ for _, site in pairs(sites) do
|
|
|
if site.site_code == currentsite then
|
|
|
if site.site_select and site.site_select.group and groups and groups[site.site_select.group] then
|
|
|
default = add_var_to_table(default, groups[site.site_select.group])
|
|
@@ -52,8 +43,6 @@ if site_code ~= currentsite then
|
|
|
end
|
|
|
|
|
|
if configured == false then
|
|
|
- uci:set("currentsite", "current", "name", site_code)
|
|
|
- uci:save('currentsite')
|
|
|
- uci:commit('currentsite')
|
|
|
+ tools.force_site_code(site_code)
|
|
|
end
|
|
|
end
|