2 Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
3 Licensed to the public under the Apache License 2.0.
8 local fs = require "nixio.fs"
9 local sys = require "luci.sys"
10 local utl = require "luci.util"
12 local param = luci.http.formvalue
14 local iface = param("iface")
15 local style = param("style")
17 style = (style and #style > 0) and style or "s"
24 style = style:gsub("[^%w]", "")
25 iface = iface:gsub("[^%w%.%-%_]", "")
27 luci.http.prepare_content("image/png")
29 local png = io.popen("vnstati -i '%s' '-%s' -o -" % { iface, style })
30 luci.http.write(png:read("*a"))
39 sys.call("vnstat -u >/dev/null 2>/dev/null")
48 for line in io.lines("/etc/vnstat.conf") do
49 dbdir = line:match("^%s*DatabaseDir%s+[\"'](%S-)[\"']")
50 if dbdir then break end
53 dbdir = dbdir or "/var/lib/vnstat"
59 <h2 name="content"><%:VnStat Graphs%></h2>
61 <form action="" method="get">
64 <option value="s"<%=(style == "s") and ' selected="selected"' or ''%>><%:Summary display%></option>
65 <option value="t"<%=(style == "t") and ' selected="selected"' or ''%>><%:Top 10 display%></option>
66 <option value="h"<%=(style == "h") and ' selected="selected"' or ''%>><%:Hourly traffic%></option>
67 <option value="d"<%=(style == "d") and ' selected="selected"' or ''%>><%:Daily traffic%></option>
68 <option value="m"<%=(style == "m") and ' selected="selected"' or ''%>><%:Monthly traffic%></option>
71 <input type="submit" value="<%:Update ยป%>" />
77 <div style="text-align:center">
84 if iface:sub(1,1) ~= "." then
87 <img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" />
96 <p><em><%:No database has been set up yet. Go to the VnStat configuration and enable monitoring for one or more interfaces.%></em></p>