Initial support for DHCP range configuration

This commit is contained in:
emanuele-f 2019-02-26 18:08:02 +01:00
parent 2ac8f4f716
commit b778e77207
13 changed files with 427 additions and 10 deletions

View file

@ -0,0 +1,40 @@
--
-- (C) 2017-18 - ntop.org
--
local dhcp_utils = {}
-- ##############################################
local function getDhcpRangesKey(ifid)
return string.format("ntopng.prefs.ifid_%u.dhcp_ranges", ifid)
end
-- ##############################################
function dhcp_utils.listRanges(ifid)
local ranges_str = ntop.getPref(getDhcpRangesKey(ifid))
local ranges = string.split(ranges_str, ",") or {ranges_str}
local res = {}
for _, range in ipairs(ranges) do
local r = string.split(range, "%-")
if r and #r == 2 then
res[#res + 1] = {r[1], r[2]}
end
end
return res
end
-- ##############################################
function dhcp_utils.setRanges(ifid, ranges_str)
ntop.setPref(getDhcpRangesKey(ifid), ranges_str)
interface.reloadDhcpRanges()
end
-- ##############################################
return dhcp_utils