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"
11 uci.cursor():foreach("mwan3", "rule",
13 rule_error[section[".name"]] = false
14 local uci = uci.cursor(nil, "/var/state")
15 local sourcePort = uci:get("mwan3", section[".name"], "src_port")
16 local destPort = uci:get("mwan3", section[".name"], "dest_port")
17 if sourcePort ~= nil or destPort ~= nil then
18 local protocol = uci:get("mwan3", section[".name"], "proto")
19 if protocol == nil or protocol == "all" then
20 rule_error[section[".name"]] = true
28 function ruleWarn(rule_error)
30 for i, k in pairs(rule_error) do
31 if rule_error[i] == true then
32 warnings = warnings .. string.format("<strong>%s</strong><br />",
33 translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i)
41 m5 = Map("mwan3", translate("MWAN - Rules"),
45 mwan_rule = m5:section(TypedSection, "rule", nil,
46 translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
47 "Rules are based on IP address, port or protocol<br />" ..
48 "Rules are matched from top to bottom<br />" ..
49 "Rules below a matching rule are ignored<br />" ..
50 "Traffic not matching any rule is routed using the main routing table<br />" ..
51 "Traffic destined for known (other than default) networks is handled by the main routing table<br />" ..
52 "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
53 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
54 "Rules may not share the same name as configured interfaces, members or policies"))
55 mwan_rule.addremove = true
56 mwan_rule.anonymous = false
57 mwan_rule.dynamic = false
58 mwan_rule.sectionhead = translate("Rule")
59 mwan_rule.sortable = true
60 mwan_rule.template = "cbi/tblsection"
61 mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s")
62 function mwan_rule.create(self, section)
63 TypedSection.create(self, section)
65 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section))
68 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
70 function src_ip.cfgvalue(self, s)
71 return self.map:get(s, "src_ip") or "—"
74 src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
75 src_port.rawhtml = true
76 function src_port.cfgvalue(self, s)
77 return self.map:get(s, "src_port") or "—"
80 dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
81 dest_ip.rawhtml = true
82 function dest_ip.cfgvalue(self, s)
83 return self.map:get(s, "dest_ip") or "—"
86 dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
87 dest_port.rawhtml = true
88 function dest_port.cfgvalue(self, s)
89 return self.map:get(s, "dest_port") or "—"
92 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
94 function proto.cfgvalue(self, s)
95 return self.map:get(s, "proto") or "all"
98 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
99 use_policy.rawhtml = true
100 function use_policy.cfgvalue(self, s)
101 return self.map:get(s, "use_policy") or "—"