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 based on IP address, port or protocol<br />" ..
41 "Rules are matched from top to bottom. Rules below a matching rule are ignored. Traffic not matching any rule is routed using the main routing table<br />" ..
42 "Traffic destined for known (other than default) networks is handled by the main routing table. Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed<br />" ..
43 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
44 "Rules may not share the same name as configured interfaces, members or policies"))
45 mwan_rule.addremove = true
46 mwan_rule.anonymous = false
47 mwan_rule.dynamic = false
48 mwan_rule.sectionhead = translate("Rule")
49 mwan_rule.sortable = true
50 mwan_rule.template = "cbi/tblsection"
51 mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s")
52 function mwan_rule.create(self, section)
53 TypedSection.create(self, section)
55 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section))
59 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
61 function src_ip.cfgvalue(self, s)
62 return self.map:get(s, "src_ip") or "—"
65 src_port = mwan_rule:option(DummyValue, "src_port", translate("Source port"))
66 src_port.rawhtml = true
67 function src_port.cfgvalue(self, s)
68 return self.map:get(s, "src_port") or "—"
71 dest_ip = mwan_rule:option(DummyValue, "dest_ip", translate("Destination address"))
72 dest_ip.rawhtml = true
73 function dest_ip.cfgvalue(self, s)
74 return self.map:get(s, "dest_ip") or "—"
77 dest_port = mwan_rule:option(DummyValue, "dest_port", translate("Destination port"))
78 dest_port.rawhtml = true
79 function dest_port.cfgvalue(self, s)
80 return self.map:get(s, "dest_port") or "—"
83 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
85 function proto.cfgvalue(self, s)
86 return self.map:get(s, "proto") or "all"
89 sticky = mwan_rule:option(DummyValue, "sticky", translate("Sticky"))
91 function sticky.cfgvalue(self, s)
92 if self.map:get(s, "sticky") == "1" then
94 return translate("Yes")
97 return translate("No")
101 timeout = mwan_rule:option(DummyValue, "timeout", translate("Sticky timeout"))
102 timeout.rawhtml = true
103 function timeout.cfgvalue(self, s)
105 local timeoutValue = self.map:get(s, "timeout")
107 return timeoutValue .. "s"
116 ipset = mwan_rule:option(DummyValue, "ipset", translate("IPset"))
118 function ipset.cfgvalue(self, s)
119 return self.map:get(s, "ipset") or "—"
122 use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned"))
123 use_policy.rawhtml = true
124 function use_policy.cfgvalue(self, s)
125 return self.map:get(s, "use_policy") or "—"
128 errors = mwan_rule:option(DummyValue, "errors", translate("Errors"))
129 errors.rawhtml = true
130 function errors.cfgvalue(self, s)
131 if not string.find(error_protocol_list, " " .. s .. " ") then
134 return "<span title=\"" .. translate("No protocol specified") .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"