applications: add luci-vnstat, frontend for the VnStat traffic monitor
This commit is contained in:
parent
34b3ae2a42
commit
f375c498f2
6 changed files with 257 additions and 0 deletions
4
applications/luci-vnstat/Makefile
Normal file
4
applications/luci-vnstat/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
PO = vnstat
|
||||||
|
|
||||||
|
include ../../build/config.mk
|
||||||
|
include ../../build/module.mk
|
14
applications/luci-vnstat/luasrc/controller/vnstat.lua
Normal file
14
applications/luci-vnstat/luasrc/controller/vnstat.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module("luci.controller.vnstat", package.seeall)
|
||||||
|
|
||||||
|
function index()
|
||||||
|
require("luci.i18n").loadc("vnstat")
|
||||||
|
local i18n = luci.i18n.translate
|
||||||
|
|
||||||
|
entry({"admin", "network", "vnstat"}, alias("admin", "network", "vnstat", "graphs"), i18n("VnStat Traffic Monitor"), 90).i18n = "vnstat"
|
||||||
|
entry({"admin", "network", "vnstat", "graphs"}, template("vnstat"), i18n("Graphs"), 1)
|
||||||
|
entry({"admin", "network", "vnstat", "config"}, cbi("vnstat"), i18n("VnStat Traffic Monitor"), 2)
|
||||||
|
|
||||||
|
entry({"mini", "network", "vnstat"}, alias("mini", "network", "vnstat", "graphs"), i18n("VnStat Traffic Monitor"), 90).i18n = "vnstat"
|
||||||
|
entry({"mini", "network", "vnstat", "graphs"}, template("vnstat"), i18n("Graphs"), 1)
|
||||||
|
entry({"mini", "network", "vnstat", "config"}, cbi("vnstat"), i18n("VnStat Traffic Monitor"), 2)
|
||||||
|
end
|
90
applications/luci-vnstat/luasrc/model/cbi/vnstat.lua
Normal file
90
applications/luci-vnstat/luasrc/model/cbi/vnstat.lua
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
--[[
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
|
||||||
|
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
]]--
|
||||||
|
|
||||||
|
local utl = require "luci.util"
|
||||||
|
local sys = require "luci.sys"
|
||||||
|
local fs = require "nixio.fs"
|
||||||
|
local nw = require "luci.model.network"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
m = SimpleForm("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 ifaces = { }
|
||||||
|
local enabled = { }
|
||||||
|
local iface
|
||||||
|
|
||||||
|
for iface in fs.dir(dbdir) do
|
||||||
|
if iface:sub(1,1) ~= '.' then
|
||||||
|
ifaces[iface] = iface
|
||||||
|
enabled[iface] = iface
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, iface in ipairs(sys.net.devices()) do
|
||||||
|
ifaces[iface] = iface
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local s = m:section(SimpleSection)
|
||||||
|
|
||||||
|
mon_ifaces = s:option(Value, "ifaces", translate("Monitor selected interfaces"))
|
||||||
|
mon_ifaces.template = "cbi/network_ifacelist"
|
||||||
|
mon_ifaces.widget = "checkbox"
|
||||||
|
mon_ifaces.default = utl.keys(enabled)
|
||||||
|
|
||||||
|
function mon_ifaces.write(self, s, 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
|
||||||
|
|
||||||
|
for i, _ in pairs(ifaces) do
|
||||||
|
if s[i] then
|
||||||
|
sys.call("vnstat -u -i %q" % i)
|
||||||
|
else
|
||||||
|
fs.unlink(dbdir .. "/" .. i)
|
||||||
|
fs.unlink(dbdir .. "/." .. i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
sys.call("/etc/init.d/vnstat restart >/dev/null 2>/dev/null")
|
||||||
|
|
||||||
|
m.message = "<p><strong>%s</strong></p>"
|
||||||
|
% translate("The VnStat service has been restarted."), cmd
|
||||||
|
|
||||||
|
self.default = utl.keys(s)
|
||||||
|
end
|
||||||
|
|
||||||
|
mon_ifaces.remove = mon_ifaces.write
|
||||||
|
|
||||||
|
return m
|
||||||
|
|
88
applications/luci-vnstat/luasrc/view/vnstat.htm
Normal file
88
applications/luci-vnstat/luasrc/view/vnstat.htm
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<%#
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/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 %q -%q -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><a id="content" name="content"><%:VnStat Graphs%></a></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 fs.dir(dbdir) do if iface:sub(1,1) ~= "." then %>
|
||||||
|
<img src="<%=REQUEST_URI%>?iface=<%=iface%>&style=<%=param('style')%>" alt="" />
|
||||||
|
<br /><br />
|
||||||
|
<% end end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%+footer%>
|
|
@ -788,6 +788,17 @@ define Package/luci-app-wol/install
|
||||||
$(call Package/luci/install/template,$(1),applications/luci-wol)
|
$(call Package/luci/install/template,$(1),applications/luci-wol)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
define Package/luci-app-vnstat
|
||||||
|
$(call Package/luci/webtemplate)
|
||||||
|
TITLE:=LuCI Support for VnStat
|
||||||
|
DEPENDS+=+luci-admin-core +PACKAGE_luci-app-vnstat:vnstat \
|
||||||
|
+PACKAGE_luci-app-vnstat:vnstati
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/luci-app-vnstat/install
|
||||||
|
$(call Package/luci/install/template,$(1),applications/luci-vnstat)
|
||||||
|
endef
|
||||||
|
|
||||||
|
|
||||||
### Server Gateway Interfaces ###
|
### Server Gateway Interfaces ###
|
||||||
|
|
||||||
|
@ -1215,6 +1226,9 @@ endif
|
||||||
ifneq ($(CONFIG_PACKAGE_luci-app-wol),)
|
ifneq ($(CONFIG_PACKAGE_luci-app-wol),)
|
||||||
PKG_SELECTED_MODULES+=applications/luci-wol
|
PKG_SELECTED_MODULES+=applications/luci-wol
|
||||||
endif
|
endif
|
||||||
|
ifneq ($(CONFIG_PACKAGE_luci-app-vnstat),)
|
||||||
|
PKG_SELECTED_MODULES+=applications/luci-vnstat
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_PACKAGE_luci-sgi-cgi),)
|
ifneq ($(CONFIG_PACKAGE_luci-sgi-cgi),)
|
||||||
|
@ -1351,6 +1365,7 @@ $(eval $(call BuildPackage,luci-app-openvpn))
|
||||||
$(eval $(call BuildPackage,luci-app-p2pblock))
|
$(eval $(call BuildPackage,luci-app-p2pblock))
|
||||||
$(eval $(call BuildPackage,luci-app-multiwan))
|
$(eval $(call BuildPackage,luci-app-multiwan))
|
||||||
$(eval $(call BuildPackage,luci-app-wol))
|
$(eval $(call BuildPackage,luci-app-wol))
|
||||||
|
$(eval $(call BuildPackage,luci-app-vnstat))
|
||||||
|
|
||||||
$(eval $(call BuildPackage,luci-sgi-cgi))
|
$(eval $(call BuildPackage,luci-sgi-cgi))
|
||||||
$(eval $(call BuildPackage,luci-sgi-uhttpd))
|
$(eval $(call BuildPackage,luci-sgi-uhttpd))
|
||||||
|
|
46
po/templates/vnstat.pot
Normal file
46
po/templates/vnstat.pot
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
msgid ""
|
||||||
|
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||||
|
|
||||||
|
msgid "Daily traffic"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Graphs"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Hourly traffic"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Monitor selected interfaces"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Monthly traffic"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Restart VnStat"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Summary display"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "The VnStat service has been restarted."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Top 10 display"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Update »"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "VnStat"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "VnStat Graphs"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "VnStat Traffic Monitor"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid ""
|
||||||
|
"VnStat is a network traffic monitor for Linux that keeps a log of network "
|
||||||
|
"traffic for the selected interface(s)."
|
||||||
|
msgstr ""
|
Loading…
Reference in a new issue