Add dhcp_server_utils. Use Kea DHCP server when installed

This commit is contained in:
Alfredo Cardigliano 2025-11-07 16:44:14 +01:00
parent c383f14642
commit ef0b101ef2
4 changed files with 109 additions and 83 deletions

View file

@ -4,47 +4,8 @@
local sys_utils = require "sys_utils"
local service_name = "isc-dhcp-server"
local redis_key = "ntopng.nedge.dhcp.enabled"
local isc_dhcp_server = {}
-- ###############################################################
-- This function is used to check if the DHCP server status is up
-- and if not, restart it.
function isc_dhcp_server.checkRestartDHCPService()
if ntop.isnEdge() then
if (ntop.getCache(redis_key) or '0') == '1' then
if not sys_utils.isActiveService(service_name) then
sys_utils.restartService(service_name)
end
end
end
end
-- ###############################################################
-- This function is used to start the DHCP server
function isc_dhcp_server.startDHCPService()
if ntop.isnEdge() then
ntop.setCache(redis_key, '1')
sys_utils.enableService(service_name)
sys_utils.restartService(service_name)
end
end
-- ###############################################################
-- This function is used to stop the DHCP server
function isc_dhcp_server.stopDHCPService()
if ntop.isnEdge() then
ntop.setCache(redis_key, '0')
sys_utils.disableService(service_name)
sys_utils.stopService(service_name)
end
end
isc_dhcp_server.service_name = "isc-dhcp-server"
-- ###############################################################

View file

@ -5,11 +5,8 @@
local sys_utils = require "sys_utils"
local json = require "dkjson"
local service_name = "kea-dhcp4-server"
local redis_key = "ntopng.nedge.dhcp.kea.enabled"
local kea_dhcp_server = {}
kea_dhcp_server.service_name = "kea-dhcp4-server"
-- ###############################################################
@ -38,42 +35,6 @@ end
-- ###############################################################
-- This function is used to check if the DHCP server status is up
-- and if not, restart it.
function kea_dhcp_server.checkRestartDHCPService()
if ntop.isnEdge() then
if (ntop.getCache(redis_key) or '0') == '1' then
if not sys_utils.isActiveService(service_name) then
sys_utils.restartService(service_name)
end
end
end
end
-- ###############################################################
-- This function is used to start the DHCP server
function kea_dhcp_server.startDHCPService()
if ntop.isnEdge() then
ntop.setCache(redis_key, '1')
sys_utils.enableService(service_name)
sys_utils.restartService(service_name)
end
end
-- ###############################################################
-- This function is used to stop the DHCP server
function kea_dhcp_server.stopDHCPService()
if ntop.isnEdge() then
ntop.setCache(redis_key, '0')
sys_utils.disableService(service_name)
sys_utils.stopService(service_name)
end
end
-- ###############################################################
-- Writes the Kea DHCP4 server configuration file in JSON format
-- @param dhcp_config The DHCP server configuration table
-- @param all_interfaces Table mapping interface names to roles (lan/wan)