luci-app-mwan3: Fix luci tools cannot detect translate()
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / policy.lua
1 -- ------ extra functions ------ --
2
3 function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters
4 uci.cursor():foreach("mwan3", "policy",
5 function (section)
6 if string.len(section[".name"]) > 15 then
7 nameTooLong = 1
8 err_name_list = err_name_list .. section[".name"] .. " "
9 end
10 end
11 )
12 end
13
14 function policyWarn() -- display status and warning messages at the top of the page
15 if nameTooLong == 1 then
16 return "<font color=\"ff0000\"><strong>" .. translate("WARNING: Some policies have names exceeding the maximum of 15 characters!") .. "</strong></font>"
17 else
18 return ""
19 end
20 end
21
22 -- ------ policy configuration ------ --
23
24 ds = require "luci.dispatcher"
25 sys = require "luci.sys"
26
27 nameTooLong = 0
28 err_name_list = " "
29 policyCheck()
30
31
32 m5 = Map("mwan3", translate("MWAN Policy Configuration"),
33 policyWarn())
34 m5:append(Template("mwan/config_css"))
35
36
37 mwan_policy = m5:section(TypedSection, "policy", translate("Policies"),
38 translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
39 "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance<br />" ..
40 "Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
41 "Names may contain characters A-Z, a-z, 0-9, _ and no spaces. Names must be 15 characters or less<br />" ..
42 "Policies may not share the same name as configured interfaces, members or rules"))
43 mwan_policy.addremove = true
44 mwan_policy.dynamic = false
45 mwan_policy.sectionhead = "Policy"
46 mwan_policy.sortable = true
47 mwan_policy.template = "cbi/tblsection"
48 mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "configuration", "policy", "%s")
49 function mwan_policy.create(self, section)
50 TypedSection.create(self, section)
51 m5.uci:save("mwan3")
52 luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "policy", section))
53 end
54
55
56 use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned"))
57 use_member.rawhtml = true
58 function use_member.cfgvalue(self, s)
59 local memberConfig, memberList = self.map:get(s, "use_member"), ""
60 if memberConfig then
61 for k,v in pairs(memberConfig) do
62 memberList = memberList .. v .. "<br />"
63 end
64 return memberList
65 else
66 return "&#8212;"
67 end
68
69 end
70
71 last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort"))
72 last_resort.rawhtml = true
73 function last_resort.cfgvalue(self, s)
74 local action = self.map:get(s, "last_resort")
75 if action == "blackhole" then
76 return "blackhole (drop)"
77 elseif action == "default" then
78 return "default (use main routing table)"
79 else
80 return "unreachable (reject)"
81 end
82 end
83
84 errors = mwan_policy:option(DummyValue, "errors", translate("Errors"))
85 errors.rawhtml = true
86 function errors.cfgvalue(self, s)
87 if not string.find(err_name_list, " " .. s .. " ") then
88 return ""
89 else
90 return "<span title=\"Name exceeds 15 characters\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
91 end
92 end
93
94
95 return m5