<commit_before>--[[
LuCI - Lua Configuration Interface

Copyright 2008 <NAME> <<EMAIL>>
Copyright 2010-2011 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

]]--

m = Map("network", translate("Switch"), translate("The network ports on this device can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))

local fs = require "nixio.fs"
local switches = { }

m.uci:foreach("network", "switch",
	function(x)
		local sid         = x['.name']
		local switch_name = x.name or sid
		local has_vlan    = nil
		local has_learn   = nil
		local has_vlan4k  = nil
		local has_qos     = nil
		local has_jumbo3  = nil
		local has_mirror  = nil
		local min_vid     = 0
		local max_vid     = 16
		local num_vlans   = 16
		local cpu_port    = tonumber(fs.readfile("/proc/switch/eth0/cpuport") or 5)
		local num_ports   = cpu_port + 1

		local switch_title
		local enable_vlan4k = false

		-- Parse some common switch properties from swconfig help output.
		local swc = io.popen("swconfig dev %q help 2>/dev/null" % switch_name)
		if swc then

			local is_port_attr = false
			local is_vlan_attr = false

			while true do
				local line = swc:read("*l")
				if not line then break end

				if line:match("^%s+%-%-vlan") then
					is_vlan_attr = true

				elseif line:match("^%s+%-%-port") then
					is_vlan_attr = false
					is_port_attr = true

				elseif line:match("cpu @") then
					switch_title = line:match("^switch%d: %w+%((.-)%)")
					num_ports, cpu_port, num_vlans =
						line:match("ports: (%d+) %(cpu @ (%d+)%), vlans: (%d+)")

					num_ports  = tonumber(num_ports) or  6
					num_vlans  = tonumber(num_vlans) or 16
					cpu_port   = tonumber(cpu_port)  or  5
					min_vid    = 1

				elseif line:match(": pvid") or line:match(": tag") or line:match(": vid") then
					if is_vlan_attr then has_vlan4k = line:match(": (%w+)") end

				elseif line:match(": enable_vlan4k") then
					enable_vlan4k = true

				elseif line:match(": enable_qos") then
					has_qos = "enable_qos"

				elseif line:match(": enable_vlan") then
					has_vlan = "enable_vlan"

				elseif line:match(": enable_learning") then
					has_learn = "enable_learning"

				elseif line:match(": enable_mirror_rx") then
					has_mirror = "enable_mirror_rx"

				elseif line:match(": max_length") then
					has_jumbo3 = "max_length"
				end
			end

			swc:close()
		end

		-- Switch properties
		s = m:section(NamedSection, x['.name'], "switch",
			switch_title and translatef("Switch %q (%s)", switch_name, switch_title)
					      or translatef("Switch %q", switch_name))

		s.addremove = false

		if has_vlan then
			s:option(Flag, has_vlan, translate("Enable VLAN functionality"))
		end

		if has_learn then
			x = s:option(Flag, has_learn, translate("Enable learning and aging"))
			x.default = x.enabled
		end

		if has_qos then
			x = s:option(Flag, has_qos, "Enable QoS")
			x.default = x.disabled
		end

		if has_jumbo3 then
			x = s:option(ListValue, has_jumbo3, translate("Enable Jumbo Frame passthrough"))
			x:value("0", "1522")
			x:value("1", "1536")
			x:value("2", "1552")
			x:value("3", "9216")
		end

		-- Does this switch support port mirroring?
		if has_mirror then
			s:option(Flag, "enable_mirror_rx", translate("Enable mirroring of incoming packets"))
			s:option(Flag, "enable_mirror_tx", translate("Enable mirroring of outgoing packets"))
			s:option(Flag, "enable_mirror_pause_frames", translate("Enable mirroring of incoming pause frames"))

			local sp = s:option(ListValue, "mirror_source_port", translate("Mirror source port"))
			local mp = s:option(ListValue, "mirror_monitor_port", translate("Mirror monitor port"))

			local pt
			for pt = 0, num_ports - 1 do<commit_msg>Fix VLAN LuCI<commit_after>--[[
LuCI - Lua Configuration Interface

Copyright 2008 <NAME> <<EMAIL>>
Copyright 2010-2011 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

]]--

m = Map("network", translate("Switch"), translate("The network ports on this device can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))

local fs = require "nixio.fs"
local switches = { }

m.uci:foreach("network", "switch",
	function(x)
		local sid         = x['.name']
		local switch_name = x.name or sid
		local has_vlan    = nil
		local has_learn   = nil
		local has_vlan4k  = nil
		local has_qos     = nil
		local has_jumbo3  = nil
		local has_mirror  = nil
		local min_vid     = 0
		local max_vid     = 16
		local num_vlans   = 16
		local cpu_port    = tonumber(fs.readfile("/proc/switch/eth0/cpuport") or 5)
		local num_ports   = cpu_port + 1

		local switch_title
		local enable_vlan4k = false

		-- Parse some common switch properties from swconfig help output.
		local swc = io.popen("swconfig dev %q help 2>/dev/null" % switch_name)
		if swc then

			local is_port_attr = false
			local is_vlan_attr = false

			while true do
				local line = swc:read("*l")
				if not line then break end

				if line:match("^%s+%-%-vlan") then
					is_vlan_attr = true

				elseif line:match("^%s+%-%-port") then
					is_vlan_attr = false
					is_port_attr = true

				elseif line:match("cpu @") then
					switch_title = line:match("^switch%d: %w+%((.-)%)")
					num_ports, cpu_port, num_vlans =
						line:match("ports: (%d+) %(cpu @ (%d+)%), vlans: (%d+)")

					num_ports  = tonumber(num_ports) or  6
					num_vlans  = tonumber(num_vlans) or 16
					cpu_port   = tonumber(cpu_port)  or  5
					min_vid    = 1

				elseif line:match(": pvid") or line:match(": tag") or line:match(": vid") then
					if is_vlan_attr then has_vlan4k = line:match(": (%w+)") end

				elseif line:match(": enable_vlan4k") then
					enable_vlan4k = true

				elseif line:match(": enable_qos") then
					has_qos = "enable_qos"

				elseif line:match(": enable_vlan") then
					has_vlan = "enable_vlan"

				elseif line:match(": enable_learning") then
					has_learn = "enable_learning"

				elseif line:match(": enable_mirror_rx") then
					has_mirror = "enable_mirror_rx"

				elseif line:match(": max_length") then
					has_jumbo3 = "max_length"
				end
			end

			swc:close()
		end

		-- Switch properties
		s = m:section(NamedSection, x['.name'], "switch",
			switch_title and translatef("Switch %q (%s)", switch_name, switch_title)
					      or translatef("Switch %q", switch_name))

		s.addremove = false

		if has_vlan then
			s:option(Flag, has_vlan, translate("Enable VLAN functionality"))
		end

		if has_learn then
			x = s:option(Flag, has_learn, translate("Enable learning and aging"))
			x.default = x.enabled
		end

		if has_qos then
			x = s:option(Flag, has_qos, "Enable QoS")
			x.addremove = false
		end

		if has_jumbo3 then
			x = s:option(ListValue, has_jumbo3, translate("Enable Jumbo Frame passthrough"))
			x:value("0", "1522")
			x:value("1", "1536")
			x:value("2", "1552")
			x:value("3", "9216")
		end

		-- Does this switch support port mirroring?
		if has_mirror then
			s:option(Flag, "enable_mirror_rx", translate("Enable mirroring of incoming packets"))
			s:option(Flag, "enable_mirror_tx", translate("Enable mirroring of outgoing packets"))
			s:option(Flag, "enable_mirror_pause_frames", translate("Enable mirroring of incoming pause frames"))

			local sp = s:option(ListValue, "mirror_source_port", translate("Mirror source port"))
			local mp = s:option(ListValue, "mirror_monitor_port", translate("Mirror monitor port"))

			local pt
			for pt = 0, num_ports - 1 do
{'fraction_non_alphanumeric': 0.11898794605561523, 'fraction_numerical': 0.014560210048931854, 'mean_word_length': 3.6247240618101544, 'pattern_counts': {'":': 20, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529106', 'n_tokens_mistral': 3316, 'n_tokens_neox': 2801, 'n_words': 859}