luci-app-mwan3: update rule help text
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / rule.lua
1 -- ------ extra functions ------ --
2
3 function ruleCheck() -- determine if rules needs a proper protocol configured
4 uci.cursor():foreach("mwan3", "rule",
5 function (section)
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"] .. " "
12 end
13 end
14 end
15 )
16 end
17
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>"
21 else
22 return ""
23 end
24 end
25
26 -- ------ rule configuration ------ --
27
28 dsp = require "luci.dispatcher"
29 sys = require "luci.sys"
30 ut = require "luci.util"
31
32 error_protocol_list = " "
33 ruleCheck()
34
35
36 m5 = Map("mwan3", translate("MWAN - Rules"),
37 ruleWarn())
38
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)
58 m5.uci:save("mwan3")
59 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section))
60 end
61
62
63 src_ip = mwan_rule:option(DummyValue, "src_ip", translate("Source address"))
64 src_ip.rawhtml = true
65 function src_ip.cfgvalue(self, s)
66 return self.map:get(s, "src_ip") or "&#8212;"
67 end
68
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 "&#8212;"
73 end
74
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 "&#8212;"
79 end
80
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 "&#8212;"
85 end
86
87 proto = mwan_rule:option(DummyValue, "proto", translate("Protocol"))
88 proto.rawhtml = true
89 function proto.cfgvalue(self, s)
90 return self.map:get(s, "proto") or "all"
91 end
92
93 sticky = mwan_rule:option(DummyValue, "sticky", translate("Sticky"))
94 sticky.rawhtml = true
95 function sticky.cfgvalue(self, s)
96 if self.map:get(s, "sticky") == "1" then
97 stickied = 1
98 return translate("Yes")
99 else
100 stickied = nil
101 return translate("No")
102 end
103 end
104
105 timeout = mwan_rule:option(DummyValue, "timeout", translate("Sticky timeout"))
106 timeout.rawhtml = true
107 function timeout.cfgvalue(self, s)
108 if stickied then
109 local timeoutValue = self.map:get(s, "timeout")
110 if timeoutValue then
111 return timeoutValue .. "s"
112 else
113 return "600s"
114 end
115 else
116 return "&#8212;"
117 end
118 end
119
120 ipset = mwan_rule:option(DummyValue, "ipset", translate("IPset"))
121 ipset.rawhtml = true
122 function ipset.cfgvalue(self, s)
123 return self.map:get(s, "ipset") or "&#8212;"
124 end
125
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 "&#8212;"
130 end
131
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
136 return ""
137 else
138 return "<span title=\"" .. translate("No protocol specified") .. "\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
139 end
140 end
141
142
143 return m5