luci-app-mwan3: refactoring warning compilation on the rule config pages
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
de1afe2a90
commit
aae3d298c2
2 changed files with 38 additions and 64 deletions
|
@ -1,40 +1,42 @@
|
||||||
-- ------ extra functions ------ --
|
|
||||||
|
|
||||||
function ruleCheck() -- determine if rules needs a proper protocol configured
|
|
||||||
uci.cursor():foreach("mwan3", "rule",
|
|
||||||
function (section)
|
|
||||||
local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".src_port"))
|
|
||||||
local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".dest_port"))
|
|
||||||
if sourcePort ~= "" or destPort ~= "" then -- ports configured
|
|
||||||
local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".proto"))
|
|
||||||
if protocol == "" or protocol == "all" then -- no or improper protocol
|
|
||||||
error_protocol_list = error_protocol_list .. section[".name"] .. " "
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ruleWarn() -- display warning messages at the top of the page
|
|
||||||
if error_protocol_list ~= " " then
|
|
||||||
return "<font color=\"ff0000\"><strong>" .. translate("WARNING: Some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
|
|
||||||
else
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ------ rule configuration ------ --
|
|
||||||
|
|
||||||
dsp = require "luci.dispatcher"
|
dsp = require "luci.dispatcher"
|
||||||
sys = require "luci.sys"
|
sys = require "luci.sys"
|
||||||
ut = require "luci.util"
|
ut = require "luci.util"
|
||||||
|
|
||||||
error_protocol_list = " "
|
function ruleCheck()
|
||||||
ruleCheck()
|
local rule_error = {}
|
||||||
|
uci.cursor():foreach("mwan3", "rule",
|
||||||
|
function (section)
|
||||||
|
rule_error[section[".name"]] = false
|
||||||
|
local uci = uci.cursor(nil, "/var/state")
|
||||||
|
local sourcePort = uci:get("mwan3", section[".name"], "src_port")
|
||||||
|
local destPort = uci:get("mwan3", section[".name"], "dest_port")
|
||||||
|
if sourcePort ~= nil or destPort ~= nil then
|
||||||
|
local protocol = uci:get("mwan3", section[".name"], "proto")
|
||||||
|
if protocol == nil or protocol == "all" then
|
||||||
|
rule_error[section[".name"]] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return rule_error
|
||||||
|
end
|
||||||
|
|
||||||
|
function ruleWarn(rule_error)
|
||||||
|
local warnings = ""
|
||||||
|
for i, k in pairs(rule_error) do
|
||||||
|
if rule_error[i] == true then
|
||||||
|
warnings = warnings .. string.format("<strong>%s</strong></br>",
|
||||||
|
translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return warnings
|
||||||
|
end
|
||||||
|
|
||||||
m5 = Map("mwan3", translate("MWAN - Rules"),
|
m5 = Map("mwan3", translate("MWAN - Rules"),
|
||||||
ruleWarn())
|
ruleWarn(ruleCheck())
|
||||||
|
)
|
||||||
|
|
||||||
mwan_rule = m5:section(TypedSection, "rule", nil,
|
mwan_rule = m5:section(TypedSection, "rule", nil,
|
||||||
translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
|
translate("Rules specify which traffic will use a particular MWAN policy<br />" ..
|
||||||
|
|
|
@ -1,23 +1,7 @@
|
||||||
-- ------ extra functions ------ --
|
dsp = require "luci.dispatcher"
|
||||||
|
sys = require "luci.sys"
|
||||||
function ruleCheck() -- determine if rule needs a protocol specified
|
ut = require "luci.util"
|
||||||
local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".src_port"))
|
arg[1] = arg[1] or ""
|
||||||
local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".dest_port"))
|
|
||||||
if sourcePort ~= "" or destPort ~= "" then -- ports configured
|
|
||||||
local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".proto"))
|
|
||||||
if protocol == "" or protocol == "all" then -- no or improper protocol
|
|
||||||
error_protocol = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ruleWarn() -- display warning message at the top of the page
|
|
||||||
if error_protocol == 1 then
|
|
||||||
return "<font color=\"ff0000\"><strong>" .. translate("WARNING: This rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!") .. "</strong></font>"
|
|
||||||
else
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function cbiAddPolicy(field)
|
function cbiAddPolicy(field)
|
||||||
uci.cursor():foreach("mwan3", "policy",
|
uci.cursor():foreach("mwan3", "policy",
|
||||||
|
@ -34,20 +18,8 @@ function cbiAddProtocol(field)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ------ rule configuration ------ --
|
m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
|
||||||
|
m5.redirect = dsp.build_url("admin", "network", "mwan", "rule")
|
||||||
dsp = require "luci.dispatcher"
|
|
||||||
sys = require "luci.sys"
|
|
||||||
ut = require "luci.util"
|
|
||||||
arg[1] = arg[1] or ""
|
|
||||||
|
|
||||||
error_protocol = 0
|
|
||||||
ruleCheck()
|
|
||||||
|
|
||||||
|
|
||||||
m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]),
|
|
||||||
ruleWarn())
|
|
||||||
m5.redirect = dsp.build_url("admin", "network", "mwan", "rule")
|
|
||||||
|
|
||||||
|
|
||||||
mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
|
mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
|
||||||
|
|
Loading…
Reference in a new issue