<commit_before><%

local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"

-- System
local system, model, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
local uptime = twa.date_format(tonumber(sys.uptime()))
local_time = os.date("%c")
local load1, load5, load15 = sys.loadavg()
local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)

local mem = string.format(
	"%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)",
	tonumber(memtotal) / 1024,
	tonumber(memtotal - memfree) / 1024,
	tostring(i18n.translate("used")),
	memfree / 1024,
	tostring(i18n.translate("free")),
	memcached / 1024,
	tostring(i18n.translate("cached")),
	membuffers / 1024,
	tostring(i18n.translate("buffered"))
)

-- update interval
local bogomips = bogomips or 100
local interval
if bogomips > 350 then
	interval = "5000"
else
	interval = "10000"
end

-- wireless
local ntm = require "luci.model.network".init()
local devices  = ntm:get_wifidevs()
local netlist = { }
local netdevs = { }
local dev
for _, dev in ipairs(devices) do
	local net
	for _, net in ipairs(dev:get_wifinets()) do
		netlist[#netlist+1] = net:ifname()
		netdevs[net:ifname()] = dev:name()
	end
end
local has_iwinfo = pcall(require, "iwinfo")

-- Routes
local defroutev4 = sys.net.defaultroute()
local defroutev6 = sys.net.defaultroute6()

-%>

<%+header%>


<script type="text/javascript" src="<%=resource%>/cbi.js"></script>

<script type="text/javascript">//<![CDATA[
	var iwxhr = new XHR();

	var update_wifi_status = function() {
		iwxhr.get('<%=luci.dispatcher.build_url("freifunk", "status", "public_status_json", table.concat(netlist, ","))%>', null,
			function(x, st)
			{
				if (st)
				{
					for( var i = 0; i < st.length; i++ )
					{
						var iw = st[i];
						var is_assoc = (iw.bssid && iw.channel);
						var p = (100 / iw.quality_max * iw.quality);
						var q = is_assoc ? p : -1;

						var icon;
						if (q < 0)
							icon = "<%=resource%>/icons/signal-none.png";
						else if (q == 0)
							icon = "<%=resource%>/icons/signal-0.png";
						else if (q < 25)
							icon = "<%=resource%>/icons/signal-0-25.png";
						else if (q < 50)
							icon = "<%=resource%>/icons/signal-25-50.png";
						else if (q < 75)
							icon = "<%=resource%>/icons/signal-50-75.png";
						else
							icon = "<%=resource%>/icons/signal-75-100.png";

						var power = document.getElementById(iw.id + '-txpower');
						if (power)
							power.innerHTML = String.format('%s dbm', iw.txpower);

						var signal = document.getElementById(iw.id + '-signal');
						if (signal)
							signal.innerHTML = String.format(
								'<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
								icon, iw.signal, iw.noise
							);

						var bitrate = document.getElementById(iw.id + '-bitrate');
						if (bitrate)
							bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');

						var ssid = document.getElementById(iw.id + '-ssid');
						if (ssid)
							ssid.innerHTML = iw.ssid;

						var bssid = document.getElementById(iw.id + '-bssid');
						if (bssid)
							bssid.innerHTML = iw.bssid;

						var channel = document.getElementById(iw.id + '-channel');
						if (channel)
							channel.innerHTML = iw.channel;

						var mode = document.getElementById(iw.id + '-mode');
						if (mode)
						mode.innerHTML = iw.mode;
					}

					i = st.length - 1
					var u
					
					if (u = document.getElementById('dynuptime'))
						u.innerHTML = st[i].uptime;

					if (u = document.getElementById('dynload'))
						u.innerHTML = st[i].load;

					if (u = document.getElementById('dynmem'))
						u.innerHTML = st[i].mem;

					if (u = document.getElementById('dyntime'))
						u.innerHTML = st[i].time;

					if (st[i].defroutev4)
					{
						if (u = document.getElementById('v4dst'))
							u.innerHTML = st[i].defroutev4.dest;

						if (u = document.getElementById('v4gw'))
							u.innerHTML = st[i].defroutev4.gateway;

						if (u = document.getElementById('v4dev'))
							u.innerHTML = st[i].defroutev4.dev;

						if (u = document.getElementById('v4metr'))
							u.innerHTML = st[i].defroutev4.metr;
					}

					if (st[i].defroutev6)
					{
						if (u = document.getElementById('v6dst'))
							u.innerHTML = st[i].defroutev6.dest;

						if (u = document.getElementById('v6gw'))
							u.innerHTML = st[i].defroutev6.gateway);

						if (u = document.getElementById('v6dev'))
							u.innerHTML = st[i].defroutev6.dev);

						if (u = document.getElementById('v6metr'))
							u.innerHTML = st[i].defroutev6.metr);
					}
				}

				window.setTimeout(update_wifi_status, <%=interval%>);
			}
		)
	};

	update_wifi_status();
//]]></script>

<div class="cbi-map">
	<h2><%:System%></h2>
	<div class="cbi-section-node">
		<div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=system%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=local_time%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
	</div>
</div><commit_msg>modules/freifunk: Fix js in public_status.htm<commit_after><%

local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"

-- System
local system, model, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
local uptime = twa.date_format(tonumber(sys.uptime()))
local_time = os.date("%c")
local load1, load5, load15 = sys.loadavg()
local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)

local mem = string.format(
	"%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)",
	tonumber(memtotal) / 1024,
	tonumber(memtotal - memfree) / 1024,
	tostring(i18n.translate("used")),
	memfree / 1024,
	tostring(i18n.translate("free")),
	memcached / 1024,
	tostring(i18n.translate("cached")),
	membuffers / 1024,
	tostring(i18n.translate("buffered"))
)

-- update interval
local bogomips = bogomips or 100
local interval
if bogomips > 350 then
	interval = "5000"
else
	interval = "10000"
end

-- wireless
local ntm = require "luci.model.network".init()
local devices  = ntm:get_wifidevs()
local netlist = { }
local netdevs = { }
local dev
for _, dev in ipairs(devices) do
	local net
	for _, net in ipairs(dev:get_wifinets()) do
		netlist[#netlist+1] = net:ifname()
		netdevs[net:ifname()] = dev:name()
	end
end
local has_iwinfo = pcall(require, "iwinfo")

-- Routes
local defroutev4 = sys.net.defaultroute()
local defroutev6 = sys.net.defaultroute6()

-%>

<%+header%>


<script type="text/javascript" src="<%=resource%>/cbi.js"></script>

<script type="text/javascript">//<![CDATA[
	var iwxhr = new XHR();

	var update_wifi_status = function() {
		iwxhr.get('<%=luci.dispatcher.build_url("freifunk", "status", "public_status_json", table.concat(netlist, ","))%>', null,
			function(x, st)
			{
				if (st)
				{
					for( var i = 0; i < st.length; i++ )
					{
						var iw = st[i];
						var is_assoc = (iw.bssid && iw.channel);
						var p = (100 / iw.quality_max * iw.quality);
						var q = is_assoc ? p : -1;

						var icon;
						if (q < 0)
							icon = "<%=resource%>/icons/signal-none.png";
						else if (q == 0)
							icon = "<%=resource%>/icons/signal-0.png";
						else if (q < 25)
							icon = "<%=resource%>/icons/signal-0-25.png";
						else if (q < 50)
							icon = "<%=resource%>/icons/signal-25-50.png";
						else if (q < 75)
							icon = "<%=resource%>/icons/signal-50-75.png";
						else
							icon = "<%=resource%>/icons/signal-75-100.png";

						var power = document.getElementById(iw.id + '-txpower');
						if (power)
							power.innerHTML = String.format('%s dbm', iw.txpower);

						var signal = document.getElementById(iw.id + '-signal');
						if (signal)
							signal.innerHTML = String.format(
								'<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
								icon, iw.signal, iw.noise
							);

						var bitrate = document.getElementById(iw.id + '-bitrate');
						if (bitrate)
							bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');

						var ssid = document.getElementById(iw.id + '-ssid');
						if (ssid)
							ssid.innerHTML = iw.ssid;

						var bssid = document.getElementById(iw.id + '-bssid');
						if (bssid)
							bssid.innerHTML = iw.bssid;

						var channel = document.getElementById(iw.id + '-channel');
						if (channel)
							channel.innerHTML = iw.channel;

						var mode = document.getElementById(iw.id + '-mode');
						if (mode)
						mode.innerHTML = iw.mode;
					}

					i = st.length - 1
					var u
					
					if (u = document.getElementById('dynuptime'))
						u.innerHTML = st[i].uptime;

					if (u = document.getElementById('dynload'))
						u.innerHTML = st[i].load;

					if (u = document.getElementById('dynmem'))
						u.innerHTML = st[i].mem;

					if (u = document.getElementById('dyntime'))
						u.innerHTML = st[i].time;

					if (st[i].defroutev4)
					{
						if (u = document.getElementById('v4dst'))
							u.innerHTML = st[i].defroutev4.dest;

						if (u = document.getElementById('v4gw'))
							u.innerHTML = st[i].defroutev4.gateway;

						if (u = document.getElementById('v4dev'))
							u.innerHTML = st[i].defroutev4.dev;

						if (u = document.getElementById('v4metr'))
							u.innerHTML = st[i].defroutev4.metr;
					}

					if (st[i].defroutev6)
					{
						if (u = document.getElementById('v6dst'))
							u.innerHTML = st[i].defroutev6.dest;

						if (u = document.getElementById('v6gw'))
							u.innerHTML = st[i].defroutev6.gateway;

						if (u = document.getElementById('v6dev'))
							u.innerHTML = st[i].defroutev6.dev;

						if (u = document.getElementById('v6metr'))
							u.innerHTML = st[i].defroutev6.metr;
					}
				}

				window.setTimeout(update_wifi_status, <%=interval%>);
			}
		)
	};

	update_wifi_status();
//]]></script>

<div class="cbi-map">
	<h2><%:System%></h2>
	<div class="cbi-section-node">
		<div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=system%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=local_time%></div></div>
		<div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
	</div>
</div>
{'fraction_non_alphanumeric': 0.19293117193728407, 'fraction_numerical': 0.020905306050137303, 'mean_word_length': 3.2111152555016784, 'pattern_counts': {'":': 0, '<': 157, '<?xml version=': 0, '>': 149, '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': '2492155', 'n_tokens_mistral': 5182, 'n_tokens_neox': 4144, 'n_words': 785}