1 dsp = require "luci.dispatcher"
6 uci.cursor():foreach("mwan3", "rule",
8 rule_error[section[".name"]] = false
9 local uci = uci.cursor(nil, "/var/state")
10 local sourcePort = uci:get("mwan3", section[".name"], "src_port")
11 local destPort = uci:get("mwan3", section[".name"], "dest_port")
12 if sourcePort ~= nil or destPort ~= nil then
13 local protocol = uci:get("mwan3", section[".name"], "proto")
14 if protocol == nil or protocol == "all" then
15 rule_error[section[".name"]] = true
23 function ruleWarn(rule_error)
25 for i, k in pairs(rule_error) do
26 if rule_error[i] == true then
27 warnings = warnings .. string.format("<strong>%s</strong></br>",
28 translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i)
36 m5 = Map("mwan3", translate("MWAN - Rules"),
40 mwan_rule = m5:section(TypedSection, "rule", nil,
41 translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
42 "Rules are based on IP address, port or protocol<br />" ..
43 "Rules are matched from top to bottom<br />" ..
44 "Rules below a matching rule are ignored<br />" ..
45 "Traffic not matching any rule is routed using the main routing table<br />" ..
46 "Traffic destined for known (other than default) networks is handled by the main routing table<br />" ..
47 "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
48 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
49 "Rules may not share the same name as configured interfaces, members or policies"))
50 mwan_rule.addremove = true
51 mwan_rule.anonymous = false
52 mwan_rule.dynamic = false
53 mwan_rule.sectionhead = translate("Rule")
54 mwan_rule.sortable = true
55 mwan_rule.template = "cbi/tblsection"
56 mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s")
57 function mwan_rule.create(self, section)
58 TypedSection.create(self, section)
60 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section))
64 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
66 function src_ip.cfgvalue(self, s)
67 return self.map:get(s, "src_ip") or "—"
70 src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
71 src_port.rawhtml = true
72 function src_port.cfgvalue(self, s)
73 return self.map:get(s, "src_port") or "—"
76 dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
77 dest_ip.rawhtml = true
78 function dest_ip.cfgvalue(self, s)
79 return self.map:get(s, "dest_ip") or "—"
82 dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
83 dest_port.rawhtml = true
84 function dest_port.cfgvalue(self, s)
85 return self.map:get(s, "dest_port") or "—"
88 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
90 function proto.cfgvalue(self, s)
91 return self.map:get(s, "proto") or "all"
94 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
95 use_policy.rawhtml = true
96 function use_policy.cfgvalue(self, s)
97 return self.map:get(s, "use_policy") or "—"