1 -- ------ extra functions ------ --
3 function ruleCheck() -- determine if rules needs a proper protocol configured
4 uci.cursor():foreach("mwan3", "rule",
6 local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".src_port"))
7 local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".dest_port"))
8 if sourcePort ~= "" or destPort ~= "" then -- ports configured
9 local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".proto"))
10 if protocol == "" or protocol == "all" then -- no or improper protocol
11 error_protocol_list = error_protocol_list .. section[".name"] .. " "
18 function ruleWarn() -- display warning messages at the top of the page
19 if error_protocol_list ~= " " then
20 return "<font color=\"ff0000\"><strong>" .. translate("WARNING: Some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
26 -- ------ rule configuration ------ --
28 dsp = require "luci.dispatcher"
29 sys = require "luci.sys"
30 ut = require "luci.util"
32 error_protocol_list = " "
36 m5 = Map("mwan3", translate("MWAN - Rules"),
39 mwan_rule = m5:section(TypedSection, "rule", nil,
40 translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
41 "Rules are based on IP address, port or protocol<br />" ..
42 "Rules are matched from top to bottom<br />" ..
43 "Rules below a matching rule are ignored<br />" ..
44 "Traffic not matching any rule is routed using the main routing table<br />" ..
45 "Traffic destined for known (other than default) networks is handled by the main routing table<br />" ..
46 "Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
47 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
48 "Rules may not share the same name as configured interfaces, members or policies"))
49 mwan_rule.addremove = true
50 mwan_rule.anonymous = false
51 mwan_rule.dynamic = false
52 mwan_rule.sectionhead = translate("Rule")
53 mwan_rule.sortable = true
54 mwan_rule.template = "cbi/tblsection"
55 mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s")
56 function mwan_rule.create(self, section)
57 TypedSection.create(self, section)
59 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 sticky = mwan_rule:option(DummyValue, "sticky", translate("Sticky"))
95 function sticky.cfgvalue(self, s)
96 if self.map:get(s, "sticky") == "1" then
98 return translate("Yes")
101 return translate("No")
105 timeout = mwan_rule:option(DummyValue, "timeout", translate("Sticky timeout"))
106 timeout.rawhtml = true
107 function timeout.cfgvalue(self, s)
109 local timeoutValue = self.map:get(s, "timeout")
111 return timeoutValue .. "s"
120 ipset = mwan_rule:option(DummyValue, "ipset", translate("IPset"))
122 function ipset.cfgvalue(self, s)
123 return self.map:get(s, "ipset") or "—"
126 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
127 use_policy.rawhtml = true
128 function use_policy.cfgvalue(self, s)
129 return self.map:get(s, "use_policy") or "—"
132 errors = mwan_rule:option(DummyValue, "errors", translate("Errors"))
133 errors.rawhtml = true
134 function errors.cfgvalue(self, s)
135 if not string.find(error_protocol_list, " " .. s .. " ") then
138 return "<span title=\"" .. translate("No protocol specified") .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"