% local http = require "luci.http" local uci = require "luci.model.uci".cursor() local jsonc = require "luci.jsonc" local nsu = require "luci.netstat" local have_vnstat = nsu.vnstat_installed() local ifaces, db = nsu.db_interfaces() local saved_mode = uci:get("netstats", "@config[0]", "mode") or "daily" -- Requested interface, then the Settings choice / default-route device, as -- long as vnStat has a database entry for it; else the first one it has. local cur_iface = nsu.resolve_device(http.formvalue("iface"), db) or nsu.wan_device(db) or ifaces[1] or "" local view_mode = http.formvalue("mode") or saved_mode if view_mode ~= "daily" and view_mode ~= "monthly" then view_mode = "daily" end local title = view_mode == "monthly" and translate("Monthly") or translate("Daily") -- Raw vnStat JSON, parsed in the browser by netstat/vnstat-parse.js. local raw = "" if cur_iface ~= "" then raw = nsu.vnstat_json_raw(view_mode == "monthly" and "m" or "d", view_mode == "monthly" and 12 or 30, cur_iface) or "" end local raw_js = (jsonc.stringify(raw) or '""'):gsub("", "<\\/") %>
<%:Usage is displayed using the Interface and View Mode selected in the Settings tab.%>
<% if have_vnstat and cur_iface ~= "" then %> <% elseif not have_vnstat then %>