gluon-web-network: add actions, list interfaces based on /etc/config/gluon
This commit is contained in:
		
							parent
							
								
									bb669eefd5
								
							
						
					
					
						commit
						92feadfa23
					
				@ -94,8 +94,7 @@ local function ethernet_interfaces()
 | 
			
		||||
	for iface in files(ifaces_dir) do
 | 
			
		||||
		if iface ~= '.' and iface ~= '..' then
 | 
			
		||||
			local iface_dir = ifaces_dir .. iface
 | 
			
		||||
			if (is_physical(iface_dir) and not has_devtype(iface_dir, 'wlan'))
 | 
			
		||||
			   or has_devtype(iface_dir, 'vlan') then
 | 
			
		||||
			if is_physical(iface_dir) and not has_devtype(iface_dir, 'wlan') then
 | 
			
		||||
				table.insert(eth_ifaces, iface)
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
@ -104,35 +103,30 @@ local function ethernet_interfaces()
 | 
			
		||||
	return eth_ifaces
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local items = {}
 | 
			
		||||
for _, iface in ipairs(ethernet_interfaces()) do
 | 
			
		||||
	-- TODO: here we assume lan_ifname, ... just contain a single line
 | 
			
		||||
	if sysconfig['lan_ifname'] == iface then
 | 
			
		||||
		table.insert(items, {'lan', 'Roles of the LAN-Interface'})
 | 
			
		||||
	elseif sysconfig['wan_ifname'] == iface then
 | 
			
		||||
		table.insert(items, {'wan', 'Roles of the WAN-Interface'})
 | 
			
		||||
	elseif sysconfig['single_ifname'] == iface then
 | 
			
		||||
		table.insert(items, {'single', 'Roles of the Main-Interface'})
 | 
			
		||||
	else
 | 
			
		||||
		table.insert(items, {iface, 'Roles of Interface '..iface})
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
local vlan_interface_sections = {}
 | 
			
		||||
 | 
			
		||||
for _, iface in ipairs(items) do
 | 
			
		||||
	ifaces = s:option(MultiListValue, iface[1], iface[2])
 | 
			
		||||
uci:foreach('gluon', 'interface', function(config)
 | 
			
		||||
	local section_name = config['.name']
 | 
			
		||||
 | 
			
		||||
	if section_name:find("vlan") then
 | 
			
		||||
		vlan_interface_sections[section_name] = config.name
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local ifaces = s:option(MultiListValue, section_name, config.name)
 | 
			
		||||
	ifaces.widget = 'radio'
 | 
			
		||||
	ifaces.orientation = 'horizontal'
 | 
			
		||||
	ifaces:value('uplink', 'Uplink') -- TODO: Uplink and Client should be mutually exclusive.
 | 
			
		||||
	ifaces:value('mesh', 'Mesh')
 | 
			
		||||
	ifaces:value('client', 'Client')
 | 
			
		||||
 | 
			
		||||
	ifaces.default = uci:get_list("gluon", "iface_"..iface[1], "role")
 | 
			
		||||
	ifaces.default = config.role
 | 
			
		||||
 | 
			
		||||
	function ifaces:write(data)
 | 
			
		||||
		-- TODO: create section (and assign name) if not existing
 | 
			
		||||
		uci:set_list("gluon", "iface_"..iface[1], "role", data)
 | 
			
		||||
		uci:set_list("gluon", section_name, "role", data)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
local section
 | 
			
		||||
uci:foreach("system", "gpio_switch", function(si)
 | 
			
		||||
@ -193,4 +187,63 @@ function f:write()
 | 
			
		||||
	uci:commit('system')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return f
 | 
			
		||||
 | 
			
		||||
local f_actions = Form(translate("Actions"))
 | 
			
		||||
 | 
			
		||||
local s = f_actions:section(Section)
 | 
			
		||||
 | 
			
		||||
local action = s:option(ListValue, "action", translate("Action"))
 | 
			
		||||
action:value("create_vlan_interface", translate("Create VLAN interface config"))
 | 
			
		||||
action:value("delete_vlan_interface", translate("Delete VLAN interface config"))
 | 
			
		||||
 | 
			
		||||
action:value("expand_wan_interfaces", translate("Expand WAN interfaces"))
 | 
			
		||||
 | 
			
		||||
action:value("contract_wan_interfaces", translate("Contract WAN interfaces"))
 | 
			
		||||
 | 
			
		||||
-- Options for create_vlan_interface
 | 
			
		||||
 | 
			
		||||
local interface = s:option(ListValue, "interface", translate("Interface"))
 | 
			
		||||
for _, iface in ipairs(ethernet_interfaces()) do
 | 
			
		||||
	-- TODO: this should not include vlan interfaces
 | 
			
		||||
	interface:value(iface, iface)
 | 
			
		||||
end
 | 
			
		||||
interface:depends(action, "create_vlan_interface")
 | 
			
		||||
 | 
			
		||||
local vlan_id = s:option(Value, "vlan_id", translate("VLAN ID"))
 | 
			
		||||
vlan_id.datatype = "irange(1,4094)"
 | 
			
		||||
vlan_id:depends(action, "create_vlan_interface")
 | 
			
		||||
 | 
			
		||||
function create_vlan_interface()
 | 
			
		||||
	local new_iface = interface.data .. '.' .. vlan_id.data
 | 
			
		||||
	local section_name = 'iface_' .. interface.data .. '_vlan' .. vlan_id.data
 | 
			
		||||
 | 
			
		||||
	uci:section('gluon', 'interface', section_name, {
 | 
			
		||||
		name = new_iface,
 | 
			
		||||
		role = {}
 | 
			
		||||
	})
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Options for delete_vlan_interface
 | 
			
		||||
 | 
			
		||||
local vlan_iface_to_delete = s:option(ListValue, "vlan_iface_to_delete", translate("VLAN Interface"))
 | 
			
		||||
vlan_iface_to_delete:depends(action, "delete_vlan_interface")
 | 
			
		||||
for section_name, iface in pairs(vlan_interface_sections) do
 | 
			
		||||
	vlan_iface_to_delete:value(section_name, iface)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function delete_vlan_interface()
 | 
			
		||||
	uci:delete('gluon', vlan_iface_to_delete.data)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function f_actions:write(data)
 | 
			
		||||
	if action.data == 'create_vlan_interface' then
 | 
			
		||||
		create_vlan_interface()
 | 
			
		||||
	elseif action.data == 'delete_vlan_interface' then
 | 
			
		||||
		delete_vlan_interface()
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	uci:commit('gluon')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
return f, f_actions
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user