From e7d22dce50b4a0c50c9f8ae8c18eeb5a37a51b3e Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 8 Feb 2020 22:12:17 +0100 Subject: luci-app-statistics: convert collectd configuration to client side views Signed-off-by: Jo-Philipp Wich --- .../root/usr/bin/stat-genconfig | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'applications/luci-app-statistics/root/usr') diff --git a/applications/luci-app-statistics/root/usr/bin/stat-genconfig b/applications/luci-app-statistics/root/usr/bin/stat-genconfig index 4a7487ccf..8b14c29e5 100755 --- a/applications/luci-app-statistics/root/usr/bin/stat-genconfig +++ b/applications/luci-app-statistics/root/usr/bin/stat-genconfig @@ -17,13 +17,11 @@ $Id$ require("luci.model.uci") -require("luci.sys.iptparser") require("luci.util") require("luci.i18n") require("luci.jsonc") require("nixio.fs") -local ipt = luci.sys.iptparser.IptParser() local uci = luci.model.uci.cursor() local sections = uci:get_all( "luci_statistics" ) @@ -138,29 +136,25 @@ end function config_iptables( c ) local str = "" - for s in pairs(sections) do - if sections[s][".type"] == "collectd_iptables_match" then + for id, s in pairs(sections) do + if s[".type"] == "collectd_iptables_match" or s[".type"] == "collectd_iptables_match6" then + local tname = s.table and tostring(s.table) + local chain = s.chain and tostring(s.chain) - search = { } + if tname and tname:match("^%S+$") and chain and chain:match("^%S+$") then + local line = { #s[".type"] > 23 and "\tChain6" or "\tChain", tname, chain } + local rule = s.rule and tostring(s.rule) - for i, k in ipairs( { - "table", "chain", "target", "protocol", "source", "destination", - "inputif", "outputif", "options" - } ) do - v = sections[s][k] + if rule and rule:match("^%S+$") then + line[#line+1] = rule - if type(v) == "string" then - if k == "options" then v = luci.util.split( v, "%s+", nil, true ) end - search[k] = v + local name = s.name and tostring(s.name) + if name and name:match("^%S+$") then + line[#line+1] = name + end end - end - - for i, rule in ipairs( ipt:find( search ) ) do - - name = sections[s].name:gsub( "%s+", "_" ) - if i > 1 then name = name .. "_(" .. i .. ")" end - str = str .. "\tChain " .. rule.table .. " " .. rule.chain .. " " .. rule.index .. ' "' .. name .. "\"\n" + str = str .. table.concat(line, " ") .. "\n" end end end -- cgit v1.2.3