summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2020-08-04 15:41:27 +0200
committerFlorian Eckert <fe@dev.tdt.de>2020-11-04 12:38:36 +0100
commitc4af30db46da4e776d2d931edec78323e3d22db8 (patch)
tree7fdecbf4acc6a1c51f8cb7b288a1b520e8a60886
parentd8c1366d97ce022761f28b14593c236378461751 (diff)
luci-app-mwan3: unify map, section and option variable handling in ruleconfig
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
-rw-r--r--applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua69
1 files changed, 34 insertions, 35 deletions
diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua
index f20414240..09bf8ffdd 100644
--- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua
+++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua
@@ -5,8 +5,7 @@
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
+local m, s, o
arg[1] = arg[1] or ""
@@ -15,62 +14,62 @@ local ipsets = util.split(util.trim(util.exec("ipset -n -L 2>/dev/null | grep -v
m = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
m.redirect = dsp.build_url("admin", "network", "mwan", "rule")
-mwan_rule = m:section(NamedSection, arg[1], "rule", "")
-mwan_rule.addremove = false
-mwan_rule.dynamic = false
+s = m:section(NamedSection, arg[1], "rule", "")
+s.addremove = false
+s.dynamic = false
-src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"),
+o = s:option(Value, "src_ip", translate("Source address"),
translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
-src_ip.datatype = ipaddr
+o.datatype = ipaddr
-src_port = mwan_rule:option(Value, "src_port", translate("Source port"),
+o = s:option(Value, "src_port", translate("Source port"),
translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes"))
-dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"),
+o = s:option(Value, "dest_ip", translate("Destination address"),
translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
-dest_ip.datatype = ipaddr
+o.datatype = ipaddr
-dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"),
+o = s:option(Value, "dest_port", translate("Destination port"),
translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes"))
-proto = mwan_rule:option(Value, "proto", translate("Protocol"),
+o = s:option(Value, "proto", translate("Protocol"),
translate("View the content of /etc/protocols for protocol description"))
-proto.default = "all"
-proto.rmempty = false
-proto:value("all")
-proto:value("tcp")
-proto:value("udp")
-proto:value("icmp")
-proto:value("esp")
-
-sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"),
+o.default = "all"
+o.rmempty = false
+o:value("all")
+o:value("tcp")
+o:value("udp")
+o:value("icmp")
+o:value("esp")
+
+o = s:option(ListValue, "sticky", translate("Sticky"),
translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
-sticky.default = "0"
-sticky:value("1", translate("Yes"))
-sticky:value("0", translate("No"))
+o.default = "0"
+o:value("1", translate("Yes"))
+o:value("0", translate("No"))
-timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"),
+o = s:option(Value, "timeout", translate("Sticky timeout"),
translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
-timeout.datatype = "range(1, 1000000)"
+o.datatype = "range(1, 1000000)"
-ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
+o = s: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 --"))
+o:value("", translate("-- Please choose --"))
for _, z in ipairs(ipsets) do
- ipset:value(z)
+ o:value(z)
end
-logging = mwan_rule:option(Flag, "logging", translate("Logging"),
+o = s: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"))
+o = s:option(Value, "use_policy", translate("Policy assigned"))
m.uci:foreach("mwan3", "policy",
function(s)
- policy:value(s['.name'], s['.name'])
+ o:value(s['.name'], s['.name'])
end
)
-policy:value("unreachable", translate("unreachable (reject)"))
-policy:value("blackhole", translate("blackhole (drop)"))
-policy:value("default", translate("default (use main routing table)"))
+o:value("unreachable", translate("unreachable (reject)"))
+o:value("blackhole", translate("blackhole (drop)"))
+o:value("default", translate("default (use main routing table)"))
return m