mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Fix vnstat interface with latest release
This commit is contained in:
parent
5a6ef8ca2a
commit
a28b5b347d
32 changed files with 2286 additions and 1 deletions
11
luci-app-vnstat/luasrc/controller/vnstat.lua
Normal file
11
luci-app-vnstat/luasrc/controller/vnstat.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
module("luci.controller.vnstat", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "status", "vnstat"}, alias("admin", "status", "vnstat", "graphs"), _("VnStat Traffic Monitor"), 90)
|
||||
entry({"admin", "status", "vnstat", "graphs"}, template("vnstat"), _("Graphs"), 1)
|
||||
entry({"admin", "status", "vnstat", "config"}, cbi("vnstat"), _("Configuration"), 2)
|
||||
|
||||
entry({"mini", "network", "vnstat"}, alias("mini", "network", "vnstat", "graphs"), _("VnStat Traffic Monitor"), 90)
|
||||
entry({"mini", "network", "vnstat", "graphs"}, template("vnstat"), _("Graphs"), 1)
|
||||
entry({"mini", "network", "vnstat", "config"}, cbi("vnstat"), _("Configuration"), 2)
|
||||
end
|
48
luci-app-vnstat/luasrc/model/cbi/vnstat.lua
Normal file
48
luci-app-vnstat/luasrc/model/cbi/vnstat.lua
Normal file
|
@ -0,0 +1,48 @@
|
|||
-- Copyright 2010-2011 Jo-Philipp Wich <jow@openwrt.org>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local utl = require "luci.util"
|
||||
local sys = require "luci.sys"
|
||||
local fs = require "nixio.fs"
|
||||
local nw = require "luci.model.network"
|
||||
|
||||
|
||||
m = Map("vnstat", translate("VnStat"),
|
||||
translate("VnStat is a network traffic monitor for Linux that keeps a log of network traffic for the selected interface(s)."))
|
||||
|
||||
m.submit = translate("Restart VnStat")
|
||||
m.reset = false
|
||||
|
||||
nw.init(luci.model.uci.cursor_state())
|
||||
|
||||
local s = m:section(TypedSection, "vnstat")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
mon_ifaces = s:option(Value, "interface", translate("Monitor selected interfaces"))
|
||||
mon_ifaces.template = "cbi/network_ifacelist"
|
||||
mon_ifaces.widget = "checkbox"
|
||||
mon_ifaces.cast = "table"
|
||||
mon_ifaces.noinactive = true
|
||||
mon_ifaces.nocreate = true
|
||||
|
||||
function mon_ifaces.write(self, section, val)
|
||||
local i
|
||||
local s = { }
|
||||
|
||||
if val then
|
||||
for _, i in ipairs(type(val) == "table" and val or { val }) do
|
||||
s[i] = true
|
||||
end
|
||||
end
|
||||
|
||||
if next(s) then
|
||||
m.uci:set_list("vnstat", section, "interface", utl.keys(s))
|
||||
else
|
||||
m.uci:delete("vnstat", section, "interface")
|
||||
end
|
||||
end
|
||||
|
||||
mon_ifaces.remove = mon_ifaces.write
|
||||
|
||||
return m
|
83
luci-app-vnstat/luasrc/view/vnstat.htm
Normal file
83
luci-app-vnstat/luasrc/view/vnstat.htm
Normal file
|
@ -0,0 +1,83 @@
|
|||
<%#
|
||||
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
|
||||
luci.http.prepare_content("image/png")
|
||||
|
||||
local png = io.popen("vnstati -i %s -%s -o -" %{
|
||||
utl.shellquote(iface),
|
||||
utl.shellquote(style)
|
||||
})
|
||||
|
||||
luci.http.write(png:read("*a"))
|
||||
png:close()
|
||||
|
||||
return
|
||||
|
||||
--
|
||||
-- update database
|
||||
--
|
||||
else
|
||||
sys.call("vnstat -u >/dev/null 2>/dev/null")
|
||||
end
|
||||
|
||||
-%>
|
||||
|
||||
<%+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">
|
||||
<%
|
||||
for _, iface in ipairs(sys.net.devices()) do
|
||||
if iface ~= "lo" and not iface:match("^sit.*") and not iface:match("^if.*") and not iface:match("^teql.*") and not iface:match("^tun.*") then
|
||||
empty = false
|
||||
%>
|
||||
<img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" />
|
||||
<br /><br />
|
||||
<%
|
||||
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%>
|
Loading…
Add table
Add a link
Reference in a new issue