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