Merge pull request #278 from nmav/ocserv
[project/luci.git] / applications / luci-vnstat / luasrc / view / vnstat.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
4
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
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 -%>
12
13 <%-
14
15 local fs = require "nixio.fs"
16 local sys = require "luci.sys"
17 local utl = require "luci.util"
18
19 local param = luci.http.formvalue
20
21 local iface = param("iface")
22 local style = param("style")
23
24 style = (style and #style > 0) and style or "s"
25
26
27 --
28 -- render image
29 --
30 if iface then
31 style = style:gsub("[^%w]", "")
32 iface = iface:gsub("[^%w%.%-]", "")
33
34 luci.http.prepare_content("image/png")
35
36 local png = io.popen("vnstati -i '%s' '-%s' -o -" % { iface, style })
37 luci.http.write(png:read("*a"))
38 png:close()
39
40 return
41
42 --
43 -- update database
44 --
45 else
46 sys.call("vnstat -u >/dev/null 2>/dev/null")
47 end
48
49
50 --
51 -- find databases
52 --
53 local dbdir, line
54
55 for line in io.lines("/etc/vnstat.conf") do
56 dbdir = line:match("^%s*DatabaseDir%s+[\"'](%S-)[\"']")
57 if dbdir then break end
58 end
59
60 dbdir = dbdir or "/var/lib/vnstat"
61
62 -%>
63
64 <%+header%>
65
66 <h2><a id="content" name="content"><%:VnStat Graphs%></a></h2>
67
68 <form action="" method="get">
69
70 <select name="style">
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>
76 </select>
77
78 <input type="submit" value="<%:Update ยป%>" />
79
80 </form>
81
82 <br /><hr /><br />
83
84 <div style="text-align:center">
85 <%
86 empty = true
87 ifdir = fs.dir(dbdir)
88
89 if ifdir then
90 for iface in ifdir do
91 if iface:sub(1,1) ~= "." then
92 empty = false
93 %>
94 <img src="<%=REQUEST_URI%>?iface=<%=iface%>&amp;style=<%=param('style')%>" alt="" />
95 <br /><br />
96 <%
97 end
98 end
99 end
100 %>
101
102 <% if empty then %>
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>
104 <% end %>
105
106 </div>
107
108 <%+footer%>