Merge pull request #4349 from TDT-AG/pr/20200804-luci-app-mwan3

luci-app-mwan3: rulconfig variable name refactoring and dependency fixes
This commit is contained in:
Florian Eckert 2020-11-05 15:25:33 +01:00 committed by GitHub
commit b8053fff59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 76 deletions

View file

@ -3,61 +3,40 @@
local net = require "luci.model.network".init() local net = require "luci.model.network".init()
local s, m, mask, rtmon, rtlookup, logging, loglevel local s, m, o
m = Map("mwan3", translate("MWAN - Globals")) m = Map("mwan3", translate("MWAN - Globals"))
s = m:section(NamedSection, "globals", "globals", nil) s = m:section(NamedSection, "globals", "globals", nil)
mask = s:option( o = s:option(Value, "mmx_mask",
Value,
"mmx_mask",
translate("Firewall mask"), translate("Firewall mask"),
translate("Enter value in hex, starting with <code>0x</code>")) translate("Enter value in hex, starting with <code>0x</code>"))
mask.datatype = "hex(4)" o.datatype = "hex(4)"
mask.default = "0xff00" o.default = "0x3F00"
logging = s:option(Flag, o = s:option(Flag, "logging",
"logging",
translate("Logging"), translate("Logging"),
translate("Enables global firewall logging")) translate("Enables global firewall logging"))
loglevel = s:option( o = s:option(ListValue, "loglevel",
ListValue,
"loglevel",
translate("Loglevel"), translate("Loglevel"),
translate("Firewall loglevel")) translate("Firewall loglevel"))
loglevel.default = "notice" o.default = "notice"
loglevel:value("emerg", translate("Emergency")) o:value("emerg", translate("Emergency"))
loglevel:value("alert", translate("Alert")) o:value("alert", translate("Alert"))
loglevel:value("crit", translate("Critical")) o:value("crit", translate("Critical"))
loglevel:value("error", translate("Error")) o:value("error", translate("Error"))
loglevel:value("warning", translate("Warning")) o:value("warning", translate("Warning"))
loglevel:value("notice", translate("Notice")) o:value("notice", translate("Notice"))
loglevel:value("info", translate("Info")) o:value("info", translate("Info"))
loglevel:value("debug", translate("Debug")) o:value("debug", translate("Debug"))
loglevel:depends("logging", "1") o:depends("logging", "1")
rtmon = s:option( o = s:option(DynamicList, "rt_table_lookup",
Value,
"rtmon_interval",
translate("Update interval"),
translate("How often should rtmon update the interface routing table"))
rtmon.datatype = "integer"
rtmon.default = "5"
rtmon:value("1", translatef("%d second", 1))
rtmon:value("3", translatef("%d seconds", 3))
rtmon:value("5", translatef("%d seconds", 5))
rtmon:value("7", translatef("%d seconds", 7))
rtmon:value("10", translatef("%d seconds", 10))
rtlookup = s:option(DynamicList,
"rt_table_lookup",
translate("Routing table lookup"), translate("Routing table lookup"),
translate("Also scan this Routing table for connected networks")) translate("Also scan this Routing table for connected networks"))
rtlookup.datatype = "integer" o.datatype = "integer"
rtlookup:value("1", translatef("Routing table %d", 1)) o:value("220", translatef("Routing table %d", 220))
rtlookup:value("2", translatef("Routing table %d", 2))
rtlookup:value("220", translatef("Routing table %d", 220))
return m return m

View file

@ -140,8 +140,7 @@ m = Map("mwan3", translate("MWAN - Interfaces"),
interfaceWarnings(configCheck())) interfaceWarnings(configCheck()))
mwan_interface = m:section(TypedSection, "interface", nil, mwan_interface = m:section(TypedSection, "interface", nil,
translate("MWAN supports up to 252 physical and/or logical interfaces<br />" .. translate("mwan3 requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
"MWAN requires that all interfaces have a unique metric configured in /etc/config/network<br />" ..
"Names must match the interface name found in /etc/config/network<br />" .. "Names must match the interface name found in /etc/config/network<br />" ..
"Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
"Interfaces may not share the same name as configured members, policies or rules")) "Interfaces may not share the same name as configured members, policies or rules"))

View file

@ -5,8 +5,7 @@
local dsp = require "luci.dispatcher" local dsp = require "luci.dispatcher"
local util = require("luci.util") local util = require("luci.util")
local m, mwan_rule, src_ip, src_port, dest_ip, dest_port, proto, sticky local m, s, o
local timeout, ipset, logging, policy
arg[1] = arg[1] or "" arg[1] = arg[1] or ""
@ -15,62 +14,72 @@ 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 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
m.redirect = dsp.build_url("admin", "network", "mwan", "rule") m.redirect = dsp.build_url("admin", "network", "mwan", "rule")
mwan_rule = m:section(NamedSection, arg[1], "rule", "") s = m:section(NamedSection, arg[1], "rule", "")
mwan_rule.addremove = false s.addremove = false
mwan_rule.dynamic = false s.dynamic = false
src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"), o = s:option(ListValue, "family", translate("Internet Protocol"))
o.default = ""
o:value("", translate("IPv4 and IPv6"))
o:value("ipv4", translate("only IPv4"))
o:value("ipv6", translate("only IPv6"))
o = s:option(Value, "src_ip", translate("Source address"),
translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes")) 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")) 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"))
o:depends("proto", "tcp")
o:depends("proto", "udp")
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")) 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")) 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"))
o:depends("proto", "tcp")
o:depends("proto", "udp")
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")) translate("View the content of /etc/protocols for protocol description"))
proto.default = "all" o.default = "all"
proto.rmempty = false o.rmempty = false
proto:value("all") o:value("all")
proto:value("tcp") o:value("tcp")
proto:value("udp") o:value("udp")
proto:value("icmp") o:value("icmp")
proto:value("esp") o:value("esp")
sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"), 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")) 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" o.default = "0"
sticky:value("1", translate("Yes")) o:value("1", translate("Yes"))
sticky:value("0", translate("No")) 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")) 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\")")) 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 for _, z in ipairs(ipsets) do
ipset:value(z) o:value(z)
end 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)")) 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", m.uci:foreach("mwan3", "policy",
function(s) function(s)
policy:value(s['.name'], s['.name']) o:value(s['.name'], s['.name'])
end end
) )
policy:value("unreachable", translate("unreachable (reject)")) o:value("unreachable", translate("unreachable (reject)"))
policy:value("blackhole", translate("blackhole (drop)")) o:value("blackhole", translate("blackhole (drop)"))
policy:value("default", translate("default (use main routing table)")) o:value("default", translate("default (use main routing table)"))
return m return m