luci-app-mwan3: fix possibility to not select an ipset
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / ruleconfig.lua
index 84adfcf910e66da5deeb13fdc76cb5f67e522748..f20414240e952160e91faa0a0079f6747138447e 100644 (file)
@@ -2,14 +2,20 @@
 -- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
 -- Licensed to the public under the GNU General Public License v2.
 
-dsp = require "luci.dispatcher"
+local dsp = require "luci.dispatcher"
+local util   = require("luci.util")
+
+local m, mwan_rule, src_ip, src_port, dest_ip, dest_port, proto, sticky
+local timeout, ipset, logging, policy
+
 arg[1] = arg[1] or ""
 
+local ipsets = util.split(util.trim(util.exec("ipset -n -L 2>/dev/null | grep -v mwan3_ | sort")), "\n", nil, true) or {}
 
-m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
-m5.redirect = dsp.build_url("admin", "network", "mwan", "rule")
+m = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
+m.redirect = dsp.build_url("admin", "network", "mwan", "rule")
 
-mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
+mwan_rule = m:section(NamedSection, arg[1], "rule", "")
 mwan_rule.addremove = false
 mwan_rule.dynamic = false
 
@@ -49,9 +55,16 @@ timeout.datatype = "range(1, 1000000)"
 
 ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
        translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
+ipset:value("", translate("-- Please choose --"))
+for _, z in ipairs(ipsets) do
+       ipset:value(z)
+end
+
+logging = mwan_rule:option(Flag, "logging", translate("Logging"),
+       translate("Enables firewall rule logging (global mwan3 logging must also be enabled)"))
 
 policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
-m5.uci:foreach("mwan3", "policy",
+m.uci:foreach("mwan3", "policy",
        function(s)
                policy:value(s['.name'], s['.name'])
        end
@@ -60,4 +73,4 @@ policy:value("unreachable", translate("unreachable (reject)"))
 policy:value("blackhole", translate("blackhole (drop)"))
 policy:value("default", translate("default (use main routing table)"))
 
-return m5
+return m