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))
63 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
65 function src_ip.cfgvalue(self, s)
66 return self.map:get(s, "src_ip") or "—"
69 src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
70 src_port.rawhtml = true
71 function src_port.cfgvalue(self, s)
72 return self.map:get(s, "src_port") or "—"
75 dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
76 dest_ip.rawhtml = true
77 function dest_ip.cfgvalue(self, s)
78 return self.map:get(s, "dest_ip") or "—"
81 dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
82 dest_port.rawhtml = true
83 function dest_port.cfgvalue(self, s)
84 return self.map:get(s, "dest_port") or "—"
87 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
89 function proto.cfgvalue(self, s)
90 return self.map:get(s, "proto") or "all"
93 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
94 use_policy.rawhtml = true
95 function use_policy.cfgvalue(self, s)
96 return self.map:get(s, "use_policy") or "—"