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 luci.http.prepare_content("image/png")
26 local png = io.popen("vnstati -i %s -%s -o -" %{
27 utl.shellquote(iface),
31 luci.http.write(png:read("*a"))
40 sys.call("vnstat -u >/dev/null 2>/dev/null")
49 for line in io.lines("/etc/vnstat.conf") do
50 dbdir = line:match("^%s*DatabaseDir%s+[\"'](%S-)[\"']")
51 if dbdir then break end
54 dbdir = dbdir or "/var/lib/vnstat"
60 <h2 name="content"><%:VnStat Graphs%></h2>
62 <form action="" method="get">
65 <option value="s"<%=(style == "s") and ' selected="selected"' or ''%>><%:Summary display%></option>
66 <option value="t"<%=(style == "t") and ' selected="selected"' or ''%>><%:Top 10 display%></option>
67 <option value="h"<%=(style == "h") and ' selected="selected"' or ''%>><%:Hourly traffic%></option>
68 <option value="d"<%=(style == "d") and ' selected="selected"' or ''%>><%:Daily traffic%></option>
69 <option value="m"<%=(style == "m") and ' selected="selected"' or ''%>><%:Monthly traffic%></option>
72 <input type="submit" value="<%:Update ยป%>" />
78 <div style="text-align:center">
85 if iface:sub(1,1) ~= "." then
88 <img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" />
97 <p><em><%:No database has been set up yet. Go to the VnStat configuration and enable monitoring for one or more interfaces.%></em></p>