applications/olsr: Validate input for lqmult, #654
This commit is contained in:
parent
594c4a68e3
commit
c38187d0d8
2 changed files with 51 additions and 2 deletions
|
@ -15,6 +15,8 @@ $Id$
|
||||||
|
|
||||||
require("luci.tools.webadmin")
|
require("luci.tools.webadmin")
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
|
local util = require "luci.util"
|
||||||
|
local ip = require "luci.ip"
|
||||||
|
|
||||||
local has_ipip = fs.glob("/etc/modules.d/[0-9]*-ipip")()
|
local has_ipip = fs.glob("/etc/modules.d/[0-9]*-ipip")()
|
||||||
|
|
||||||
|
@ -253,7 +255,7 @@ weight.datatype = "uinteger"
|
||||||
weight.placeholder = "0"
|
weight.placeholder = "0"
|
||||||
|
|
||||||
lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
|
lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
|
||||||
translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1. "..
|
translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
|
||||||
"It is only used when LQ-Level is greater than 0. Examples:<br />"..
|
"It is only used when LQ-Level is greater than 0. Examples:<br />"..
|
||||||
"reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
|
"reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
|
||||||
"reduce LQ to all nodes on this interface by 20%: default 0.8"))
|
"reduce LQ to all nodes on this interface by 20%: default 0.8"))
|
||||||
|
@ -262,6 +264,28 @@ lqmult.rmempty = true
|
||||||
lqmult.cast = "table"
|
lqmult.cast = "table"
|
||||||
lqmult.placeholder = "default 1.0"
|
lqmult.placeholder = "default 1.0"
|
||||||
|
|
||||||
|
function lqmult.validate(self, value)
|
||||||
|
for _, v in pairs(value) do
|
||||||
|
if v ~= "" then
|
||||||
|
local val = util.split(v, " ")
|
||||||
|
local host = val[1]
|
||||||
|
local mult = val[2]
|
||||||
|
if not host or not mult then
|
||||||
|
return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
|
||||||
|
end
|
||||||
|
if not (host == "default" or ip.IPv4(host) or ip.IPv6(host)) then
|
||||||
|
return nil, translate("Can only be a valid IPv4 or IPv6 address or 'default'")
|
||||||
|
end
|
||||||
|
if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
|
||||||
|
return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
|
||||||
|
end
|
||||||
|
if not mult:match("[0-1]%.[0-9]+") then
|
||||||
|
return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
|
ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
|
||||||
translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
|
translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
|
||||||
|
|
|
@ -13,6 +13,9 @@ $Id$
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
local util = require "luci.util"
|
||||||
|
local ip = require "luci.ip"
|
||||||
|
|
||||||
function write_float(self, section, value)
|
function write_float(self, section, value)
|
||||||
local n = tonumber(value)
|
local n = tonumber(value)
|
||||||
if n ~= nil then
|
if n ~= nil then
|
||||||
|
@ -77,7 +80,7 @@ weight.datatype = "uinteger"
|
||||||
weight.placeholder = "0"
|
weight.placeholder = "0"
|
||||||
|
|
||||||
lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
|
lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
|
||||||
translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1. "..
|
translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
|
||||||
"It is only used when LQ-Level is greater than 0. Examples:<br />"..
|
"It is only used when LQ-Level is greater than 0. Examples:<br />"..
|
||||||
"reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
|
"reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
|
||||||
"reduce LQ to all nodes on this interface by 20%: default 0.8"))
|
"reduce LQ to all nodes on this interface by 20%: default 0.8"))
|
||||||
|
@ -86,6 +89,28 @@ lqmult.rmempty = true
|
||||||
lqmult.cast = "table"
|
lqmult.cast = "table"
|
||||||
lqmult.placeholder = "default 1.0"
|
lqmult.placeholder = "default 1.0"
|
||||||
|
|
||||||
|
function lqmult.validate(self, value)
|
||||||
|
for _, v in pairs(value) do
|
||||||
|
if v ~= "" then
|
||||||
|
local val = util.split(v, " ")
|
||||||
|
local host = val[1]
|
||||||
|
local mult = val[2]
|
||||||
|
if not host or not mult then
|
||||||
|
return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
|
||||||
|
end
|
||||||
|
if not (host == "default" or ip.IPv4(host) or ip.IPv6(host)) then
|
||||||
|
return nil, translate("Can only be a valid IPv4 or IPv6 address or 'default'")
|
||||||
|
end
|
||||||
|
if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
|
||||||
|
return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
|
||||||
|
end
|
||||||
|
if not mult:match("[0-1]%.[0-9]+") then
|
||||||
|
return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
|
ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
|
||||||
translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
|
translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
|
||||||
|
|
Loading…
Reference in a new issue