summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policyconfig.lua
blob: 06a0fec668bce08f8425f6972969d15809b01e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- ------ extra functions ------ --

function policyCheck() -- check to see if this policy's name exceed the maximum of 15 characters
	policyNameLength = string.len(arg[1])
	if policyNameLength > 15 then
		nameTooLong = 1
	end
end

function policyWarn() -- display status and warning messages at the top of the page
	if nameTooLong == 1 then
		return "<font color=\"ff0000\"><strong>" .. translatef("WARNING: this policy's name is %d characters exceeding the maximum of 15!", policyNameLength) .. "</strong></font>"
	else
		return ""
	end
end

function cbiAddMember(field)
	uci.cursor():foreach("mwan3", "member",
		function (section)
			field:value(section[".name"])
		end
	)
end

-- ------ policy configuration ------ --

dsp = require "luci.dispatcher"
arg[1] = arg[1] or ""

nameTooLong = 0
policyCheck()


m5 = Map("mwan3", translatef("MWAN Policy Configuration - %s", arg[1]),
	policyWarn())
	m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "policy")


mwan_policy = m5:section(NamedSection, arg[1], "policy", "")
	mwan_policy.addremove = false
	mwan_policy.dynamic = false


use_member = mwan_policy:option(DynamicList, "use_member", translate("Member used"))
	cbiAddMember(use_member)

last_resort = mwan_policy:option(ListValue, "last_resort", translate("Last resort"),
	translate("When all policy members are offline use this behavior for matched traffic"))
	last_resort.default = "unreachable"
	last_resort:value("unreachable", translate("unreachable (reject)"))
	last_resort:value("blackhole", translate("blackhole (drop)"))
	last_resort:value("default", translate("default (use main routing table)"))


-- ------ currently configured members ------ --

mwan_member = m5:section(TypedSection, "member", translate("Currently Configured Members"))
	mwan_member.addremove = false
	mwan_member.dynamic = false
	mwan_member.sortable = false
	mwan_member.template = "cbi/tblsection"


return m5