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 local dsp = require "luci.dispatcher"
6 local uci = require "uci"
10 function policyCheck()
11 local policy_error = {}
13 uci.cursor():foreach("mwan3", "policy",
15 policy_error[section[".name"]] = false
16 if string.len(section[".name"]) > 15 then
17 policy_error[section[".name"]] = true
25 function policyError(policy_error)
27 for i, k in pairs(policy_error) do
28 if policy_error[i] == true then
29 warnings = warnings .. string.format("<strong>%s</strong><br />",
30 translatef("WARNING: Policy %s has exceeding the maximum name of 15 characters", i)
38 m = Map("mwan3", translate("MWAN - Policies"),
39 policyError(policyCheck()))
41 s = m:section(TypedSection, "policy", nil,
42 translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
43 "Member interfaces with lower metrics are used first<br />" ..
44 "Member interfaces with the same metric will be load-balanced<br />" ..
45 "Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
46 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
47 "Names must be 15 characters or less<br />" ..
48 "Policies may not share the same name as configured interfaces, members or rules"))
51 s.sectionhead = translate("Policy")
53 s.template = "cbi/tblsection"
54 s.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s")
55 function s.create(self, section)
57 self.invalid_cts = true
59 TypedSection.create(self, section)
61 luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section))
65 o = s:option(DummyValue, "use_member", translate("Members assigned"))
67 function o.cfgvalue(self, s)
68 local memberConfig, memberList = self.map:get(s, "use_member"), ""
70 for k,v in pairs(memberConfig) do
71 memberList = memberList .. v .. "<br />"
79 o = s:option(DummyValue, "last_resort", translate("Last resort"))
81 function o.cfgvalue(self, s)
82 local action = self.map:get(s, "last_resort")
83 if action == "blackhole" then
84 return translate("blackhole (drop)")
85 elseif action == "default" then
86 return translate("default (use main routing table)")
88 return translate("unreachable (reject)")