diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-04-21 22:57:07 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-04-21 22:57:07 +0000 |
commit | f375c498f2058b9d8244a628ca78ef5110b2be79 (patch) | |
tree | 55f4ae37fb1aeee0bd45a2f8d6dab6aae41d9a6a /applications/luci-vnstat/luasrc/view | |
parent | 34b3ae2a428f75165001dc0ef19cd33bc7f2323a (diff) |
applications: add luci-vnstat, frontend for the VnStat traffic monitor
Diffstat (limited to 'applications/luci-vnstat/luasrc/view')
-rw-r--r-- | applications/luci-vnstat/luasrc/view/vnstat.htm | 88 |
1 files changed, 88 insertions, 0 deletions
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 <xm@subsignal.org> + +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%> + +<h2><a id="content" name="content"><%:VnStat Graphs%></a></h2> + +<form action="" method="get"> + +<select name="style"> + <option value="s"<%=(style == "s") and ' selected="selected"' or ''%>><%:Summary display%></option> + <option value="t"<%=(style == "t") and ' selected="selected"' or ''%>><%:Top 10 display%></option> + <option value="h"<%=(style == "h") and ' selected="selected"' or ''%>><%:Hourly traffic%></option> + <option value="d"<%=(style == "d") and ' selected="selected"' or ''%>><%:Daily traffic%></option> + <option value="m"<%=(style == "m") and ' selected="selected"' or ''%>><%:Monthly traffic%></option> +</select> + +<input type="submit" value="<%:Update ยป%>" /> + +</form> + +<br /><hr /><br /> + +<div style="text-align:center"> +<% for iface in fs.dir(dbdir) do if iface:sub(1,1) ~= "." then %> + <img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" /> + <br /><br /> +<% end end %> +</div> + +<%+footer%> |