1 -- ------ extra functions ------ --
3 function ruleCheck() -- determine if rule needs a protocol specified
4 local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".src_port"))
5 local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".dest_port"))
6 if sourcePort ~= "" or destPort ~= "" then -- ports configured
7 local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".proto"))
8 if protocol == "" or protocol == "all" then -- no or improper protocol
14 function ruleWarn() -- display warning message at the top of the page
15 if error_protocol == 1 then
16 return "<font color=\"ff0000\"><strong>" .. translate("WARNING: this rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
22 function cbiAddPolicy(field)
23 uci.cursor():foreach("mwan3", "policy",
25 field:value(section[".name"])
30 function cbiAddProtocol(field)
31 local protocols = ut.trim(sys.exec("cat /etc/protocols | grep ' # ' | awk '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '"))
32 for p in string.gmatch(protocols, "%S+") do
37 -- ------ rule configuration ------ --
39 dsp = require "luci.dispatcher"
40 sys = require "luci.sys"
41 ut = require "luci.util"
48 m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]),
50 m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "rule")
53 mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
54 mwan_rule.addremove = false
55 mwan_rule.dynamic = false
58 src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"),
59 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
60 src_ip.datatype = ipaddr
62 src_port = mwan_rule:option(Value, "src_port", translate("Source port"),
63 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"))
65 dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"),
66 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
67 dest_ip.datatype = ipaddr
69 dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"),
70 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"))
72 proto = mwan_rule:option(Value, "proto", translate("Protocol"),
73 translate("View the contents of /etc/protocols for protocol descriptions"))
84 sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"),
85 translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
87 sticky:value("1", translate("Yes"))
88 sticky:value("0", translate("No"))
90 timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"),
91 translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
92 timeout.datatype = "range(1, 1000000)"
94 ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
95 translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
97 use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
98 cbiAddPolicy(use_policy)
99 use_policy:value("unreachable", translate("unreachable (reject)"))
100 use_policy:value("blackhole", translate("blackhole (drop)"))
101 use_policy:value("default", translate("default (use main routing table)"))
104 -- ------ currently configured policies ------ --
106 mwan_policy = m5:section(TypedSection, "policy", translate("Currently Configured Policies"))
107 mwan_policy.addremove = false
108 mwan_policy.dynamic = false
109 mwan_policy.sortable = false
110 mwan_policy.template = "cbi/tblsection"