Merge pull request #1104 from musashino205/mwan3-fix-trans
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / policyconfig.lua
1 -- ------ extra functions ------ --
2
3 function policyCheck() -- check to see if this policy's name exceed the maximum of 15 characters
4         policyNameLength = string.len(arg[1])
5         if policyNameLength > 15 then
6                 nameTooLong = 1
7         end
8 end
9
10 function policyWarn() -- display status and warning messages at the top of the page
11         if nameTooLong == 1 then
12                 return "<font color=\"ff0000\"><strong>" .. translatef("WARNING: this policy's name is %d characters exceeding the maximum of 15!", policyNameLength) .. "</strong></font>"
13         else
14                 return ""
15         end
16 end
17
18 function cbiAddMember(field)
19         uci.cursor():foreach("mwan3", "member",
20                 function (section)
21                         field:value(section[".name"])
22                 end
23         )
24 end
25
26 -- ------ policy configuration ------ --
27
28 dsp = require "luci.dispatcher"
29 arg[1] = arg[1] or ""
30
31 nameTooLong = 0
32 policyCheck()
33
34
35 m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1]),
36         policyWarn())
37         m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "policy")
38
39
40 mwan_policy = m5:section(NamedSection, arg[1], "policy", "")
41         mwan_policy.addremove = false
42         mwan_policy.dynamic = false
43
44
45 use_member = mwan_policy:option(DynamicList, "use_member", translate("Member used"))
46         cbiAddMember(use_member)
47
48 last_resort = mwan_policy:option(ListValue, "last_resort", translate("Last resort"),
49         translate("When all policy members are offline use this behavior for matched traffic"))
50         last_resort.default = "unreachable"
51         last_resort:value("unreachable", translate("unreachable (reject)"))
52         last_resort:value("blackhole", translate("blackhole (drop)"))
53         last_resort:value("default", translate("default (use main routing table)"))
54
55
56 -- ------ currently configured members ------ --
57
58 mwan_member = m5:section(TypedSection, "member", translate("Currently Configured Members"))
59         mwan_member.addremove = false
60         mwan_member.dynamic = false
61         mwan_member.sortable = false
62         mwan_member.template = "cbi/tblsection"
63
64
65 return m5