From 363b48d7aee428eaf048ed0fa7665ab6269bbdcf Mon Sep 17 00:00:00 2001 From: Alfredo Cardigliano Date: Wed, 1 Feb 2023 15:43:55 +0100 Subject: [PATCH] Accept CIDR in IP filters --- scripts/lua/modules/ntop_utils.lua | 14 ++++++++++++-- scripts/lua/modules/tag_utils.lua | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/lua/modules/ntop_utils.lua b/scripts/lua/modules/ntop_utils.lua index 233a706f37..1c384eef7c 100644 --- a/scripts/lua/modules/ntop_utils.lua +++ b/scripts/lua/modules/ntop_utils.lua @@ -179,7 +179,9 @@ end -- ############################################## -function isIPv4Network(address) +-- Check if address is a CIDR +-- strict (optional) do not accept subnets without the '/' +function isIPv4Network(address, strict) -- Check for @ VLAN local parts = split(address, "@") if #parts == 2 then @@ -195,6 +197,9 @@ function isIPv4Network(address) return false end + elseif #parts == 1 and strict then + return false + -- Check empty elseif #parts ~= 1 then return false @@ -206,7 +211,9 @@ end -- ############################################## -function isIPv6Network(address) +-- Check if address is a CIDR +-- strict (optional) do not accept subnets without the '/' +function isIPv6Network(address, strict) -- Check for @ VLAN local parts = split(address, "@") if #parts == 2 then @@ -222,6 +229,9 @@ function isIPv6Network(address) return false end + elseif #parts == 1 and strict then + return false + -- Check empty elseif #parts ~= 1 then return false diff --git a/scripts/lua/modules/tag_utils.lua b/scripts/lua/modules/tag_utils.lua index 83dd78c8a5..8122af147a 100644 --- a/scripts/lua/modules/tag_utils.lua +++ b/scripts/lua/modules/tag_utils.lua @@ -74,19 +74,19 @@ tag_utils.defined_tags = { operators = {'eq','neq'}, }, ip = { - value_type = 'ip', + value_type = 'cidr', -- Set to 'ip' to accept IP only i18n_label = i18n('db_search.tags.ip'), operators = {'eq', 'neq'}, bpf_key = 'ip host', }, cli_ip = { - value_type = 'ip', + value_type = 'cidr', -- Set to 'ip' to accept IP only i18n_label = i18n('db_search.tags.cli_ip'), operators = {'eq', 'neq'}, bpf_key = 'ip host', }, srv_ip = { - value_type = 'ip', + value_type = 'cidr', -- Set to 'ip' to accept IP only i18n_label = i18n('db_search.tags.srv_ip'), operators = {'eq', 'neq'}, bpf_key = 'ip host',