<commit_before><%#
 Copyright 2010 <NAME> <<EMAIL>>
 Licensed to the public under the Apache License 2.0.
-%>

<%-
	local ntm = require "luci.model.network".init()
	local fwm = require "luci.model.firewall".init()

	local net
	local ifaces = { }
	local netlist = { }
	for _, net in ipairs(ntm:get_networks()) do
		if net:name() ~= "loopback" then
			local z = fwm:get_zone_by_network(net:name())
			ifaces[#ifaces+1] = net:name()
			netlist[#netlist+1] = {
				net:name(), z and z:name() or "-", z
			}
		end
	end

	table.sort(netlist,
		function(a, b)
			if a[2] ~= b[2] then
				return a[2] < b[2]
			else
				return a[1] < b[1]
			end
		end)
-%>

<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
	function iface_shutdown(id, reconnect) {
		if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
			return;

		var d = document.getElementById(id + '-ifc-description');
		if (d)
			d.innerHTML = reconnect
				? '<em><%:Interface is reconnecting...%></em>'
				: '<em><%:Interface is shutting down...%></em>';

		var s = document.getElementById('ifc-rc-status');
		if (s)
		{
			s.parentNode.style.display = 'block';
			s.innerHTML = '<%:Waiting for changes to be applied...%>';
		}

		XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
			function(x)
			{
				if (s)
				{
					s.innerHTML = reconnect
						? '<%:Interface reconnected%>'
						: '<%:Interface shut down%>';

					window.setTimeout(function() {
						s.parentNode.style.display = 'none';
					}, 1000);
				}
			}
		);
	}


	var iwxhr = new XHR();
	var wifidevs = <%=luci.http.write_json(netdevs)%>;
	var arptable = <%=luci.http.write_json(arpcache)%>;

	XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(ifaces, ","))%>', null,
		function(x, ifcs)
		{
			if (ifcs)
			{
				for (var idx = 0; idx < ifcs.length; idx++)
				{
					var ifc = ifcs[idx];
					var html = '';

					var s = document.getElementById(ifc.id + '-ifc-devices');
					if (s)
					{
						var stat = String.format(
							'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
								ifc.type,
								ifc.is_up ? '' : '_disabled'
						);

						if (ifc.subdevices && ifc.subdevices.length)
						{
							stat += ' <strong>(';

							for (var j = 0; j < ifc.subdevices.length; j++)
							{
								var sif = ifc.subdevices[j];

								stat += String.format(
									'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
										sif.type,
										sif.is_up ? '' : '_disabled',
										sif.name
								);
							}

							stat += ')</strong>';
						}

						stat += String.format(
							'<br /><small>%h</small>',
								ifc.name
						);

						s.innerHTML = stat;
					}

					var d = document.getElementById(ifc.id + '-ifc-description');
					if (d && ifc.proto && ifc.ifname)
					{
						if (ifc.is_up)
						{
							html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
						}

						if (ifc.type != 'tunnel')
						{
							html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
						}

						html += String.format(
							'<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
							'<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
								ifc.rx_bytes, ifc.rx_packets,
								ifc.tx_bytes, ifc.tx_packets
						);

						if (ifc.ipaddrs && ifc.ipaddrs.length)
						{
							html += '<strong><%:IPv4%>: </strong>';

							for (var i = 0; i < ifc.ipaddrs.length; i++)
								html += String.format(
									'%s%s/%d',
									i ? ', ' : '',
									ifc.ipaddrs[i].addr,
									ifc.ipaddrs[i].prefix
								);

							html += '<br />';
						}

						if (ifc.ip6addrs && ifc.ip6addrs.length)
						{
							html += '<strong><%:IPv6%>: </strong>';

							for (var i = 0; i < ifc.ip6addrs.length; i++)
								html += String.format(
									'%s%s/%d',
									i ? ', ' : '',
									ifc.ip6addrs[i].addr.toUpperCase(),
									ifc.ip6addrs[i].prefix
								);

							html += '<br />';
						}

						d.innerHTML = html;
					}
					else if (d && !ifc.proto)
					{
						var e = document.getElementById(ifc.id + '-ifc-edit');
						if (e)
							e.disabled = true;

						d.innerHTML = String.format(
							'<em><%:Unsupported protocol type.%></em><br />' +
							'<a href="%h"><%:Install protocol extensions...%></a>',
								'<%=luci.dispatcher.build_url("admin/system/packages")%>?query=luci-proto&display=available'
						);
					}
					else if (d && !ifc.ifname)
					{
						d.innerHTML = String.format(
							'<em><%:Network without interfaces.%></em><br />' +
							'<a href="<%=luci.dispatcher.build_url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',<commit_msg>for-15-05: luci-mod-admin-full: update IPv4/IPv6 list views<commit_after><%#
 Copyright 2010 <NAME> <<EMAIL>>
 Licensed to the public under the Apache License 2.0.
-%>

<%-
	local ntm = require "luci.model.network".init()
	local fwm = require "luci.model.firewall".init()

	local net
	local ifaces = { }
	local netlist = { }
	for _, net in ipairs(ntm:get_networks()) do
		if net:name() ~= "loopback" then
			local z = fwm:get_zone_by_network(net:name())
			ifaces[#ifaces+1] = net:name()
			netlist[#netlist+1] = {
				net:name(), z and z:name() or "-", z
			}
		end
	end

	table.sort(netlist,
		function(a, b)
			if a[2] ~= b[2] then
				return a[2] < b[2]
			else
				return a[1] < b[1]
			end
		end)
-%>

<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
	function iface_shutdown(id, reconnect) {
		if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
			return;

		var d = document.getElementById(id + '-ifc-description');
		if (d)
			d.innerHTML = reconnect
				? '<em><%:Interface is reconnecting...%></em>'
				: '<em><%:Interface is shutting down...%></em>';

		var s = document.getElementById('ifc-rc-status');
		if (s)
		{
			s.parentNode.style.display = 'block';
			s.innerHTML = '<%:Waiting for changes to be applied...%>';
		}

		XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
			function(x)
			{
				if (s)
				{
					s.innerHTML = reconnect
						? '<%:Interface reconnected%>'
						: '<%:Interface shut down%>';

					window.setTimeout(function() {
						s.parentNode.style.display = 'none';
					}, 1000);
				}
			}
		);
	}


	var iwxhr = new XHR();
	var wifidevs = <%=luci.http.write_json(netdevs)%>;
	var arptable = <%=luci.http.write_json(arpcache)%>;

	XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(ifaces, ","))%>', null,
		function(x, ifcs)
		{
			if (ifcs)
			{
				for (var idx = 0; idx < ifcs.length; idx++)
				{
					var ifc = ifcs[idx];
					var html = '';

					var s = document.getElementById(ifc.id + '-ifc-devices');
					if (s)
					{
						var stat = String.format(
							'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
								ifc.type,
								ifc.is_up ? '' : '_disabled'
						);

						if (ifc.subdevices && ifc.subdevices.length)
						{
							stat += ' <strong>(';

							for (var j = 0; j < ifc.subdevices.length; j++)
							{
								var sif = ifc.subdevices[j];

								stat += String.format(
									'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
										sif.type,
										sif.is_up ? '' : '_disabled',
										sif.name
								);
							}

							stat += ')</strong>';
						}

						stat += String.format(
							'<br /><small>%h</small>',
								ifc.name
						);

						s.innerHTML = stat;
					}

					var d = document.getElementById(ifc.id + '-ifc-description');
					if (d && ifc.proto && ifc.ifname)
					{
						if (ifc.is_up)
						{
							html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
						}

						if (ifc.type != 'tunnel')
						{
							html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
						}

						html += String.format(
							'<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
							'<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
								ifc.rx_bytes, ifc.rx_packets,
								ifc.tx_bytes, ifc.tx_packets
						);

						if (ifc.ipaddrs && ifc.ipaddrs.length)
						{
							for (var i = 0; i < ifc.ipaddrs.length; i++)
								html += String.format(
									'<strong><%:IPv4%>:</strong> %s/%d<br />',
									ifc.ipaddrs[i].addr,
									ifc.ipaddrs[i].prefix
								);
						}

						if (ifc.ip6addrs && ifc.ip6addrs.length)
						{
							for (var i = 0; i < ifc.ip6addrs.length; i++)
								html += String.format(
									'<strong><%:IPv6%>:</strong> %s/%d<br />',
									ifc.ip6addrs[i].addr,
									ifc.ip6addrs[i].prefix
								);
						}

						d.innerHTML = html;
					}
					else if (d && !ifc.proto)
					{
						var e = document.getElementById(ifc.id + '-ifc-edit');
						if (e)
							e.disabled = true;

						d.innerHTML = String.format(
							'<em><%:Unsupported protocol type.%></em><br />' +
							'<a href="%h"><%:Install protocol extensions...%></a>',
								'<%=luci.dispatcher.build_url("admin/system/packages")%>?query=luci-proto&display=available'
						);
					}
					else if (d && !ifc.ifname)
					{
						d.innerHTML = String.format(
							'<em><%:Network without interfaces.%></em><br />' +
							'<a href="<%=luci.dispatcher.build_url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
{'fraction_non_alphanumeric': 0.20665866826634674, 'fraction_numerical': 0.008598280343931213, 'mean_word_length': 2.39660441426146, 'pattern_counts': {'":': 0, '<': 165, '<?xml version=': 0, '>': 151, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2017000', 'n_tokens_mistral': 5039, 'n_tokens_neox': 3747, 'n_words': 684}