1 -- Copyright 2014 Aedan Renner <chipdankly@gmail.com>
2 -- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
3 -- Licensed to the public under the GNU General Public License v2.
5 dsp = require "luci.dispatcher"
10 uci.cursor():foreach("mwan3", "rule",
12 rule_error[section[".name"]] = false
13 local uci = uci.cursor(nil, "/var/state")
14 local sourcePort = uci:get("mwan3", section[".name"], "src_port")
15 local destPort = uci:get("mwan3", section[".name"], "dest_port")
16 if sourcePort ~= nil or destPort ~= nil then
17 local protocol = uci:get("mwan3", section[".name"], "proto")
18 if protocol == nil or protocol == "all" then
19 rule_error[section[".name"]] = true
27 function ruleWarn(rule_error)
29 for i, k in pairs(rule_error) do
30 if rule_error[i] == true then
31 warnings = warnings .. string.format("<strong>%s</strong><br />",
32 translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i)
40 m5 = Map("mwan3", translate("MWAN - Rules"),
44 mwan_rule = m5:section(TypedSection, "rule", nil,
45 translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
46 "Rules are based on IP address, port or protocol<br />" ..
47 "Rules are matched from top to bottom<br />" ..
48 "Rules below a matching rule are ignored<br />" ..
49 "Traffic not matching any rule is routed using the main routing table<br />" ..
50 "Traffic destined for known (other than default) networks is handled by the main routing table<br />" ..
51 "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
52 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
53 "Rules may not share the same name as configured interfaces, members or policies"))
54 mwan_rule.addremove = true
55 mwan_rule.anonymous = false
56 mwan_rule.dynamic = false
57 mwan_rule.sectionhead = translate("Rule")
58 mwan_rule.sortable = true
59 mwan_rule.template = "cbi/tblsection"
60 mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s")
61 function mwan_rule.create(self, section)
62 TypedSection.create(self, section)
64 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section))
67 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
69 function src_ip.cfgvalue(self, s)
70 return self.map:get(s, "src_ip") or "—"
73 src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
74 src_port.rawhtml = true
75 function src_port.cfgvalue(self, s)
76 return self.map:get(s, "src_port") or "—"
79 dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
80 dest_ip.rawhtml = true
81 function dest_ip.cfgvalue(self, s)
82 return self.map:get(s, "dest_ip") or "—"
85 dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
86 dest_port.rawhtml = true
87 function dest_port.cfgvalue(self, s)
88 return self.map:get(s, "dest_port") or "—"
91 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
93 function proto.cfgvalue(self, s)
94 return self.map:get(s, "proto") or "all"
97 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
98 use_policy.rawhtml = true
99 function use_policy.cfgvalue(self, s)
100 return self.map:get(s, "use_policy") or "—"