2 LuCI - Lua Configuration Interface
4 Copyright 2010-2011 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
13 local utl = require "luci.util"
14 local sys = require "luci.sys"
15 local fs = require "nixio.fs"
16 local nw = require "luci.model.network"
20 for line in io.lines("/etc/vnstat.conf") do
21 dbdir = line:match("^%s*DatabaseDir%s+[\"'](%S-)[\"']")
22 if dbdir then break end
25 dbdir = dbdir or "/var/lib/vnstat"
28 m = Map("vnstat", translate("VnStat"),
29 translate("VnStat is a network traffic monitor for Linux that keeps a log of network traffic for the selected interface(s)."))
31 m.submit = translate("Restart VnStat")
34 nw.init(luci.model.uci.cursor_state())
40 if fs.access(dbdir) then
41 for iface in fs.dir(dbdir) do
42 if iface:sub(1,1) ~= '.' then
44 enabled[iface] = iface
49 for _, iface in ipairs(sys.net.devices()) do
54 local s = m:section(TypedSection, "vnstat")
58 mon_ifaces = s:option(Value, "interface", translate("Monitor selected interfaces"))
59 mon_ifaces.template = "cbi/network_ifacelist"
60 mon_ifaces.widget = "checkbox"
61 mon_ifaces.cast = "table"
62 mon_ifaces.noinactive = true
63 mon_ifaces.nocreate = true
65 function mon_ifaces.write(self, section, val)
70 for _, i in ipairs(type(val) == "table" and val or { val }) do
75 for i, _ in pairs(ifaces) do
77 fs.unlink(dbdir .. "/" .. i)
78 fs.unlink(dbdir .. "/." .. i)
83 m.uci:set_list("vnstat", section, "interface", utl.keys(s))
85 m.uci:delete("vnstat", section, "interface")
89 mon_ifaces.remove = mon_ifaces.write