gluon-web-network: initial draft of role configuration

This commit is contained in:
lemoer 2022-04-15 02:02:44 +02:00
parent 7cd4a189e0
commit f0b2e632d0

View File

@ -9,13 +9,12 @@ http://www.apache.org/licenses/LICENSE-2.0
]]--
local uci = require("simple-uci").cursor()
local sysconfig = require 'gluon.sysconfig'
local util = require 'gluon.util'
local wan = uci:get_all("network", "wan")
local wan6 = uci:get_all("network", "wan6")
local dns_static = uci:get_first("gluon-wan-dnsmasq", "static")
local f = Form(translate("WAN connection"))
local s = f:section(Section)
@ -76,36 +75,22 @@ end
s = f:section(Section)
local wired_mesh_help = {
single = translate('Enable meshing on the Ethernet interface'),
wan = translate('Enable meshing on the WAN interface'),
lan = translate('Enable meshing on the LAN interface'),
}
uci:foreach('gluon', 'interface', function(config)
local section_name = config['.name']
local ifaces = s:option(MultiListValue, section_name, config.name)
local function wired_mesh(iface)
if not sysconfig[iface .. '_ifname'] then return end
local iface_roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
ifaces.orientation = 'horizontal'
ifaces:value('uplink', 'Uplink') -- TODO: Uplink and Client should be mutually exclusive.
ifaces:value('mesh', 'Mesh')
ifaces:value('client', 'Client')
local option = s:option(Flag, 'mesh_' .. iface, wired_mesh_help[iface])
option.default = util.contains(iface_roles, 'mesh') ~= false
ifaces.default = config.role
function option:write(data)
local roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
if data then
util.add_to_set(roles, 'mesh')
else
util.remove_from_set(roles, 'mesh')
function ifaces:write(data)
uci:set_list("gluon", section_name, "role", data)
end
uci:set_list('gluon', 'iface_' .. iface, 'role', roles)
end)
-- Reconfigure on next reboot
uci:set('gluon', 'core', 'reconfigure', true)
end
end
wired_mesh('single')
wired_mesh('wan')
wired_mesh('lan')
local section
uci:foreach("system", "gpio_switch", function(si)
@ -166,4 +151,5 @@ function f:write()
uci:commit('system')
end
return f