luci-app-mwan3: update translations
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / policy.lua
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.
4
5 dsp = require "luci.dispatcher"
6 uci = require "uci"
7
8
9 function policyCheck()
10         local policy_error = {}
11
12         uci.cursor():foreach("mwan3", "policy",
13                 function (section)
14                         policy_error[section[".name"]] = false
15                         if string.len(section[".name"]) > 15 then
16                                 policy_error[section[".name"]] = true
17                         end
18                 end
19         )
20
21         return policy_error
22 end
23
24 function policyError(policy_error)
25         local warnings = ""
26         for i, k in pairs(policy_error) do
27                 if policy_error[i] == true then
28                         warnings = warnings .. string.format("<strong>%s</strong><br />",
29                                 translatef("WARNING: Policy %s has exceeding the maximum name of 15 characters", i)
30                                 )
31                 end
32         end
33
34         return warnings
35 end
36
37 m5 = Map("mwan3", translate("MWAN - Policies"),
38         policyError(policyCheck()))
39
40 mwan_policy = m5:section(TypedSection, "policy", nil,
41         translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
42         "Member interfaces with lower metrics are used first<br />" ..
43         "Member interfaces with the same metric will be load-balanced<br />" ..
44         "Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
45         "Names may contain characters A-Z, a-z, 0-9, _ and no spaces<br />" ..
46         "Names must be 15 characters or less<br />" ..
47         "Policies may not share the same name as configured interfaces, members or rules"))
48 mwan_policy.addremove = true
49 mwan_policy.dynamic = false
50 mwan_policy.sectionhead = translate("Policy")
51 mwan_policy.sortable = true
52 mwan_policy.template = "cbi/tblsection"
53 mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s")
54 function mwan_policy.create(self, section)
55         TypedSection.create(self, section)
56         m5.uci:save("mwan3")
57         luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section))
58 end
59
60 use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned"))
61 use_member.rawhtml = true
62 function use_member.cfgvalue(self, s)
63         local memberConfig, memberList = self.map:get(s, "use_member"), ""
64         if memberConfig then
65                 for k,v in pairs(memberConfig) do
66                         memberList = memberList .. v .. "<br />"
67                 end
68                 return memberList
69         else
70                 return "&#8212;"
71         end
72 end
73
74 last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort"))
75 last_resort.rawhtml = true
76 function last_resort.cfgvalue(self, s)
77         local action = self.map:get(s, "last_resort")
78         if action == "blackhole" then
79                 return translate("blackhole (drop)")
80         elseif action == "default" then
81                 return translate("default (use main routing table)")
82         else
83                 return translate("unreachable (reject)")
84         end
85 end
86
87 return m5