<commit_before><%
local utl = require "luci.util"
local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"

-- System

local sysinfo = utl.ubus("system", "info") or { }
local boardinfo = utl.ubus("system", "board") or { }

local loads = sysinfo.load or { 0, 0, 0 }
local meminfo = sysinfo.memory or {
	total = 0,
	free = 0,
	buffered = 0,
	shared = 0
}

local uptime = twa.date_format(sysinfo.uptime or 0)
local time = os.date("%a, %d %b %Y, %H:%M:%S")
local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)

local mem = string.format(
	"%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
	memory.total / 1024 / 1024,
	(memory.total - memory.free) / 1024 / 1024,
	tostring(i18n.translate("used")),
	memory.free / 1024 / 1024,
	tostring(i18n.translate("free")),
	memory.buffered / 1024 / 1024,
	tostring(i18n.translate("buffered"))
)

local interval = 5

-- 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()

if defroutev4 then
	defroutev4.dest = defroutev4.dest:string()
	defroutev4.gateway = defroutev4.gateway:string()
else
	-- probably policy routing activated, try olsr-default table
	local dr4 = sys.exec("ip r s t olsr-default")
	if dr4 then
		defroutev4 = { }
		defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
	end
end

if defroutev6 then
	defroutev6.dest = defroutev6.dest:string()
	defroutev6.nexthop = defroutev6.nexthop:string()
end

if luci.http.formvalue("status") == "1" then
	local rv = { }
	for dev in pairs(netdevs) do
		local j = { id = dev }
		local iw = luci.sys.wifi.getiwinfo(dev)
		if iw then
			local f
			for _, f in ipairs({
				"channel", "txpower", "bitrate", "signal", "noise",
				"quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
			}) do
				j[f] = iw[f]
			end
		end
		rv[#rv+1] = j
	end

	if defroutev6 then
		def6 = {
			gateway = defroutev6.nexthop,
			dest = defroutev6.dest,
			dev = defroutev6.device,
			metr = defroutev6.metric
		}
	end

	if defroutev4 then
		def4 = {
			gateway = defroutev4.gateway,
			dest = defroutev4.dest,
			dev = defroutev4.device,
			metr = defroutev4.metric
		}
	end

	rv[#rv+1] = {
		time = time,
		uptime = uptime,
		load = load,<commit_msg>luci-mod-freifunk: switch to luci.ip route functions<commit_after><%
local utl = require "luci.util"
local sys = require "luci.sys"
local twa = require "luci.tools.webadmin"
local ip  = require "luci.ip"

-- System

local sysinfo = utl.ubus("system", "info") or { }
local boardinfo = utl.ubus("system", "board") or { }

local loads = sysinfo.load or { 0, 0, 0 }
local meminfo = sysinfo.memory or {
	total = 0,
	free = 0,
	buffered = 0,
	shared = 0
}

local uptime = twa.date_format(sysinfo.uptime or 0)
local time = os.date("%a, %d %b %Y, %H:%M:%S")
local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)

local mem = string.format(
	"%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
	memory.total / 1024 / 1024,
	(memory.total - memory.free) / 1024 / 1024,
	tostring(i18n.translate("used")),
	memory.free / 1024 / 1024,
	tostring(i18n.translate("free")),
	memory.buffered / 1024 / 1024,
	tostring(i18n.translate("buffered"))
)

local interval = 5

-- 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")

if luci.http.formvalue("status") == "1" then
	local rv = { }
	for dev in pairs(netdevs) do
		local j = { id = dev }
		local iw = luci.sys.wifi.getiwinfo(dev)
		if iw then
			local f
			for _, f in ipairs({
				"channel", "txpower", "bitrate", "signal", "noise",
				"quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
			}) do
				j[f] = iw[f]
			end
		end
		rv[#rv+1] = j
	end


	-- Find default routes

	local _, r, def4, def6

	for _, r in ipairs(ip.routes({ type = 1, dest_exact = "0.0.0.0/0" })) do
		def4 = {
			gateway = r.gw:string(),
			dest = r.dest:string(),
			dev = r.dev,
			metr = r.metric or 0
		}
		break
	end

	for _, r in ipairs(ip.routes({ type = 1, dest_exact = "::/0" })) do
		def6 = {
			gateway = r.gw:string(),
			dest = r.dest:string(),
			dev = r.dev,
			metr = r.metric or 0
		}
		break
	end

	rv[#rv+1] = {
		time = time,
		uptime = uptime,
		load = load,
{'fraction_non_alphanumeric': 0.1690567562108665, 'fraction_numerical': 0.0414057766107857, 'mean_word_length': 3.4372759856630823, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6614122', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2043, 'n_words': 511}