blob: 2b8d9ff9c902a0e84e8cd9da49260974aba4466f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<%#
Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
Licensed to the public under the Apache 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
style = style:gsub("[^%w]", "")
iface = iface:gsub("[^%w%.%-%_]", "")
luci.http.prepare_content("image/png")
local png = io.popen("vnstati -i '%s' '-%s' -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 name="content"><%:VnStat Graphs%></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">
<%
empty = true
ifdir = fs.dir(dbdir)
if ifdir then
for iface in ifdir do
if iface:sub(1,1) ~= "." then
empty = false
%>
<img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" />
<br /><br />
<%
end
end
end
%>
<% if empty then %>
<p><em><%:No database has been set up yet. Go to the VnStat configuration and enable monitoring for one or more interfaces.%></em></p>
<% end %>
</div>
<%+footer%>
|