Fix interface switch while processing alerts causing alerts release to fail

getInterfaceId and getInterfaceName now do not change selected interface after the call
This commit is contained in:
emanuele-f 2018-04-06 16:15:36 +02:00
parent 3410091736
commit 11517970ac
3 changed files with 27 additions and 25 deletions

View file

@ -45,25 +45,39 @@ end
function getInterfaceName(interface_id, windows_skip_description)
local ifnames = interface.getIfNames()
local iface = ifnames[tostring(interface_id)]
interface_id = tonumber(interface_id)
for _,if_name in pairs(ifnames) do
--io.write(if_name.."\n")
interface.select(if_name)
_ifstats = interface.getStats()
if(_ifstats.id == interface_id) then
local ret = _ifstats.name
if iface ~= nil then
if(windows_skip_description ~= true and string.contains(iface, "{")) then -- Windows
local old_iface = interface.getStats().id
if(windows_skip_description ~= true and string.contains(ret, "{")) then -- Windows
ret = _ifstats.description
end
return(ret)
-- Use the interface description instead of the name
interface.select(tostring(iface))
iface = interface.getStats().description
interface.select(tostring(old_iface))
end
return(iface)
end
return("")
end
function getInterfaceId(interface_name)
local ifnames = interface.getIfNames()
for if_id, if_name in pairs(ifnames) do
if if_name == interface_name then
return tonumber(if_id)
end
end
return(-1)
end
-- ##############################################
-- Note that ifname can be set by Lua.cpp so don't touch it if already defined
if((ifname == nil) and (_GET ~= nil)) then
ifname = _GET["ifid"]
@ -1315,18 +1329,6 @@ function http_escape(s)
return s
end
function getInterfaceId(interface_name)
ifnames = interface.getIfNames()
for _,if_name in pairs(ifnames) do
interface.select(if_name)
_ifstats = interface.getStats()
if(_ifstats.name == interface_name) then return(_ifstats.id) end
end
return(-1)
end
-- Windows fixes for interfaces with "uncommon chars"
function purifyInterfaceName(interface_name)
-- io.write(debug.traceback().."\n")