Added support to all and port range for acl

This commit is contained in:
Matteo Biscosi 2025-01-10 11:18:57 +01:00
parent 392ff1117e
commit 72681a36dd
2 changed files with 2180 additions and 2148 deletions

View file

@ -0,0 +1,50 @@
--
-- (C) 2021 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- #################################################################
local validation_utils = {}
-- #################################################################
local function validateNumber(p)
-- integer number validation
local num = tonumber(p)
if (num == nil) then
return false
end
if math.floor(num) == num then
return true
else
-- this is a float number
return false
end
end
-- #################################################################
function validation_utils.validatePortRange(p)
local v = string.split(p, "%-") or {p, p}
if #v ~= 2 then
return false
end
if not validateNumber(v[1]) or not validateNumber(v[2]) then
return false
end
local p0 = tonumber(v[1]) or 0
local p1 = tonumber(v[2]) or 0
return (((p0 >= 1) and (p0 <= 65535)) and ((p1 >= 1) and (p1 <= 65535) and (p1 >= p0)))
end
-- #################################################################
return validation_utils