Added jailed hosts refresh when removed a member and at startup

This commit is contained in:
Matteo Biscosi 2021-05-27 11:38:06 +02:00
parent 5f39e99d3a
commit b678a2128e
4 changed files with 73 additions and 40 deletions

View file

@ -54,59 +54,74 @@ end
-- This function checks if the are banned hosts that need ti be unbanned
function drop_host_pool_utils.check_periodic_hosts_list()
-- Check the list length
local list_len = ntop.llenCache(pool_info.list_key)
-- Check the list length
local list_len = ntop.llenCache(pool_info.list_key)
local changed = false
if list_len == 0 then
return
end
if list_len == 0 then
return
end
-- Retrieve the pool
local blocked_hosts_pool_id = -2
-- Get the pool name
local blocked_hosts_pool_name = pools.DROP_HOST_POOL_NAME
local host_pool = host_pools:create()
local all_pools = host_pool:get_all_pools()
local blocked_hosts_pool_members = {}
-- Check the existance of the pool
for _, value in pairs(all_pools) do
if value["name"] == blocked_hosts_pool_name then
-- Retrieve the pool
local blocked_hosts_pool_id = -2
-- Get the pool name
local blocked_hosts_pool_name = pools.DROP_HOST_POOL_NAME
local blocked_hosts_pool_members = {}
-- Check the existance of the pool
for _, value in pairs(all_pools) do
if value["name"] == blocked_hosts_pool_name then
blocked_hosts_pool_id = value["id"]
blocked_hosts_pool_members = value.members
goto continue
end
end
::continue::
-- Check the hosts inside the list
while list_len > 0 do
local data = ntop.lpopCache(pool_info.list_key)
local curr_time = os.time()
end
end
::continue::
-- Check the hosts inside the list
while list_len > 0 do
local data = ntop.lpopCache(pool_info.list_key)
local curr_time = os.time()
local host
local time
host, time = data:match("(%w+)_(%w+)")
-- The host needs to be unbanned
if curr_time >= tonumber(time) + pool_info.expiration_time then
for i, value in pairs(blocked_hosts_pool_members) do
-- Member found, remove it
if string.find(value, host) then
host_pool:bind_member(value, 0)
goto continue_check
end
-- Member found, remove it
if string.find(value, host) then
host_pool:bind_member(value, 0)
changed = true
goto continue_check
end
end
else
-- The host needs to be added again at the start of the list (ordered by time)
ntop.lpushCache(pool_info.list_key, data)
return
-- The host needs to be added again at the start of the list (ordered by time)
ntop.lpushCache(pool_info.list_key, data)
goto policy_changed
end
::continue_check::
list_len = list_len - 1
end
end
::policy_changed::
-- Read rules from configured pools and policies
-- and push rules to the nProbe listeners
if(changed) then
if ntop.isPro() then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
local policy_utils = require "policy_utils"
local rsp = policy_utils.get_ips_rules()
if(rsp ~= nil) then
ntop.broadcastIPSMessage(rsp)
end
end
end
end
-- ############################################