From f375c498f2058b9d8244a628ca78ef5110b2be79 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 21 Apr 2010 22:57:07 +0000 Subject: applications: add luci-vnstat, frontend for the VnStat traffic monitor --- applications/luci-vnstat/luasrc/view/vnstat.htm | 88 +++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 applications/luci-vnstat/luasrc/view/vnstat.htm (limited to 'applications/luci-vnstat/luasrc/view/vnstat.htm') diff --git a/applications/luci-vnstat/luasrc/view/vnstat.htm b/applications/luci-vnstat/luasrc/view/vnstat.htm new file mode 100644 index 0000000000..440252caa7 --- /dev/null +++ b/applications/luci-vnstat/luasrc/view/vnstat.htm @@ -0,0 +1,88 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +-%> + +<%- + +local fs = require "nixio.fs" +local sys = require "luci.sys" +local utl = require "luci.util" + +local param = luci.http.formvalue + +local iface = param("iface") +local style = param("style") + +style = (style and #style > 0) and style or "s" + + +-- +-- render image +-- +if iface then + luci.http.prepare_content("image/png") + + local png = io.popen("vnstati -i %q -%q -o -" % { iface, style }) + luci.http.write(png:read("*a")) + png:close() + + return + +-- +-- update database +-- +else + sys.call("vnstat -u >/dev/null 2>/dev/null") +end + + +-- +-- find databases +-- +local dbdir, line + +for line in io.lines("/etc/vnstat.conf") do + dbdir = line:match("^%s*DatabaseDir%s+[\"'](%S-)[\"']") + if dbdir then break end +end + +dbdir = dbdir or "/var/lib/vnstat" + +-%> + +<%+header%> + +

<%:VnStat Graphs%>

+ +
+ + + + + +
+ +


+ +
+<% for iface in fs.dir(dbdir) do if iface:sub(1,1) ~= "." then %> + +

+<% end end %> +
+ +<%+footer%> -- cgit v1.2.3