2 LuCI - Lua Configuration Interface
3 Copyright
2010 Jo-Philipp Wich
<xm@subsignal.org
>
5 Licensed under the Apache License, Version
2.0 (the
"License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-
2.0
15 local fs = require
"nixio.fs"
16 local sys = require
"luci.sys"
17 local utl = require
"luci.util"
19 local param = luci.http.formvalue
21 local iface = param(
"iface")
22 local style = param(
"style")
24 style = (style and #style
> 0) and style or
"s"
31 style = style:gsub(
"[^%w]",
"")
32 iface = iface:gsub(
"[^%w%.%-]",
"")
34 luci.http.prepare_content(
"image/png")
36 local png = io.popen(
"vnstati -i '%s' '-%s' -o -" % { iface, style })
37 luci.http.write(png:read(
"*a"))
46 sys.call(
"vnstat -u >/dev/null 2>/dev/null")
55 for line in io.lines(
"/etc/vnstat.conf") do
56 dbdir = line:match(
"^%s*DatabaseDir%s+[\"'](%S-)[\
"']")
57 if dbdir then break end
60 dbdir = dbdir or
"/var/lib/vnstat"
66 <h2><a id=
"content" name=
"content"><%:VnStat Graphs%
></a></h2>
68 <form action=
"" method=
"get">
71 <option value=
"s"<%=(style ==
"s") and '
selected=
"selected"' or ''%
>><%:Summary display%
></option>
72 <option value=
"t"<%=(style ==
"t") and '
selected=
"selected"' or ''%
>><%:Top
10 display%
></option>
73 <option value=
"h"<%=(style ==
"h") and '
selected=
"selected"' or ''%
>><%:Hourly traffic%
></option>
74 <option value=
"d"<%=(style ==
"d") and '
selected=
"selected"' or ''%
>><%:Daily traffic%
></option>
75 <option value=
"m"<%=(style ==
"m") and '
selected=
"selected"' or ''%
>><%:Monthly traffic%
></option>
78 <input type=
"submit" value=
"<%:Update ยป%>" />
84 <div style=
"text-align:center">
91 if iface:sub(
1,
1) ~=
"." then
94 <img src=
"<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt=
"" />
103 <p><em><%:No database has been set up yet. Go to the VnStat configuration and enable monitoring for one or more interfaces.%
></em></p>