From 40c56ddd7797f9e916abe5443784b21ed9ba51cf Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 30 Jan 2020 12:08:35 +0100 Subject: luci-app-vnstat2: fully convert to client side rendering This converts the graph rendering to client side JavaScript and replaces the route registration with declarative JSON. Signed-off-by: Jo-Philipp Wich --- .../luci-app-vnstat2/luasrc/controller/vnstat2.lua | 50 -------------------- .../luasrc/view/vnstat2/graphs.htm | 55 ---------------------- 2 files changed, 105 deletions(-) delete mode 100644 applications/luci-app-vnstat2/luasrc/controller/vnstat2.lua delete mode 100644 applications/luci-app-vnstat2/luasrc/view/vnstat2/graphs.htm (limited to 'applications/luci-app-vnstat2/luasrc') diff --git a/applications/luci-app-vnstat2/luasrc/controller/vnstat2.lua b/applications/luci-app-vnstat2/luasrc/controller/vnstat2.lua deleted file mode 100644 index 139c1f4991..0000000000 --- a/applications/luci-app-vnstat2/luasrc/controller/vnstat2.lua +++ /dev/null @@ -1,50 +0,0 @@ -module("luci.controller.vnstat2", package.seeall) - -function index() - if not nixio.fs.access("/etc/config/vnstat") then - return - end - - entry({"admin", "status", "vnstat2"}, alias("admin", "status", "vnstat2", "graphs"), _("vnStat Traffic Monitor"), 90) - entry({"admin", "status", "vnstat2", "graphs"}, template("vnstat2/graphs"), _("Graphs"), 1) - entry({"admin", "status", "vnstat2", "config"}, view("vnstat2/config"), _("Configuration"), 2) - entry({"admin", "status", "vnstat2", "graph"}, call("action_graph"), nil, 3) -end - -function action_graph() - local util = require "luci.util" - - local param = luci.http.formvalue - - local iface = param("iface") - local style = param("style") - - if not iface or not style then - luci.http.status(404, "Not Found") - return - end - - local style_valid = false - for _, v in ipairs({"s", "t", "5", "h", "d", "m", "y"}) do - if v == style then - style_valid = true - break - end - end - - if not style_valid then - luci.http.status(404, "Not Found") - return - end - - luci.http.prepare_content("image/png") - - local cmd = "vnstati -i %s -%s -o -" % { - util.shellquote(iface), - util.shellquote(style) - } - - local image = io.popen(cmd) - luci.http.write(image:read("*a")) - image:close() -end diff --git a/applications/luci-app-vnstat2/luasrc/view/vnstat2/graphs.htm b/applications/luci-app-vnstat2/luasrc/view/vnstat2/graphs.htm deleted file mode 100644 index 318611a9d6..0000000000 --- a/applications/luci-app-vnstat2/luasrc/view/vnstat2/graphs.htm +++ /dev/null @@ -1,55 +0,0 @@ -<%# - This is free software, licensed under the Apache License, Version 2.0 --%> - -<%- - -local util = require "luci.util" -local json = require "luci.jsonc" - - -local ifaces = {} - -local data = util.exec("vnstat --json f 1 2>/dev/null") -local content = json.parse(data) -if type(content) == "table" then - for _, iface in pairs(content["interfaces"]) do - table.insert(ifaces, iface["name"]) - end -end - - -local function render_section(style, title) - %>
<% - - for _, iface in ipairs(ifaces) do - %>

?iface=<%=iface%>&style=<%=style%>" alt="" style="max-width:100%" />

<% - end - - %>
<% -end - - --%> - -<%+header%> - -

<%:vnStat Graphs%>

- -
- <% - if #ifaces == 0 then - %>

<%:No monitored interfaces have been found. Go to the configuration to enable monitoring for one or more interfaces.%>

<% - else - render_section("s", translate("Summary")) - render_section("t", translate("Top")) - render_section("5", translate("5 Minute")) - render_section("h", translate("Hourly")) - render_section("d", translate("Daily")) - render_section("m", translate("Monthly")) - render_section("y", translate("Yearly")) - end - %> -
- -<%+footer%> -- cgit v1.2.3