--- ------ extra functions ------ --
+dsp = require "luci.dispatcher"
+
+
+function policyCheck()
+ local policy_error = {}
-function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters
uci.cursor():foreach("mwan3", "policy",
function (section)
+ policy_error[section[".name"]] = false
if string.len(section[".name"]) > 15 then
- nameTooLong = 1
- err_name_list = err_name_list .. section[".name"] .. " "
+ policy_error[section[".name"]] = true
end
end
)
-end
-function policyWarn() -- display status and warning messages at the top of the page
- if nameTooLong == 1 then
- return "<font color=\"ff0000\"><strong>WARNING: Some policies have names exceeding the maximum of 15 characters!</strong></font>"
- else
- return ""
- end
+ return policy_error
end
--- ------ policy configuration ------ --
-
-ds = require "luci.dispatcher"
-sys = require "luci.sys"
-
-nameTooLong = 0
-err_name_list = " "
-policyCheck()
+function policyError(policy_error)
+ local warnings = ""
+ for i, k in pairs(policy_error) do
+ if policy_error[i] == true then
+ warnings = warnings .. string.format("<strong>%s</strong></br>",
+ translatef("WARNING: Policie %s has exceeding the maximum name of 15 characters", i)
+ )
+ end
+ end
+ return warnings
+end
-m5 = Map("mwan3", translate("MWAN Policy Configuration"),
- translate(policyWarn()))
- m5:append(Template("mwan/config_css"))
+m5 = Map("mwan3", translate("MWAN - Policies"),
+ policyError(policyCheck()))
-mwan_policy = m5:section(TypedSection, "policy", translate("Policies"),
+mwan_policy = m5:section(TypedSection, "policy", nil,
translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic<br />" ..
"Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance<br />" ..
"Load-balanced member interfaces distribute more traffic out those with higher weights<br />" ..
"Policies may not share the same name as configured interfaces, members or rules"))
mwan_policy.addremove = true
mwan_policy.dynamic = false
- mwan_policy.sectionhead = "Policy"
+ mwan_policy.sectionhead = translate("Policy")
mwan_policy.sortable = true
mwan_policy.template = "cbi/tblsection"
- mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "configuration", "policy", "%s")
+ mwan_policy.extedit = dsp.build_url("admin", "network", "mwan", "policy", "%s")
function mwan_policy.create(self, section)
TypedSection.create(self, section)
m5.uci:save("mwan3")
- luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "policy", section))
+ luci.http.redirect(dsp.build_url("admin", "network", "mwan", "policy", section))
end
else
return "—"
end
-
end
last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort"))
function last_resort.cfgvalue(self, s)
local action = self.map:get(s, "last_resort")
if action == "blackhole" then
- return "blackhole (drop)"
+ return translate("blackhole (drop)")
elseif action == "default" then
- return "default (use main routing table)"
+ return translate("default (use main routing table)")
else
- return "unreachable (reject)"
+ return translate("unreachable (reject)")
end
end
-errors = mwan_policy:option(DummyValue, "errors", translate("Errors"))
- errors.rawhtml = true
- function errors.cfgvalue(self, s)
- if not string.find(err_name_list, " " .. s .. " ") then
- return ""
- else
- return "<span title=\"Name exceeds 15 characters\"><img src=\"/luci-static/resources/cbi/reset.gif\" alt=\"error\"></img></span>"
- end
- end
-
-
return m5