% 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)", meminfo.total / 1024 / 1024, (meminfo.total - meminfo.free) / 1024 / 1024, tostring(i18n.translate("used")), meminfo.free / 1024 / 1024, tostring(i18n.translate("free")), meminfo.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") -- 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 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 rv[#rv+1] = { time = time, uptime = uptime, load = load, mem = mem, defroutev4 = def4, defroutev6 = def6 } luci.http.prepare_content("application/json") luci.http.write_json(rv) return end -%> <%+header%>