]])
else
return ([[
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
]])
end
end
-- ##############################################
function page_utils.is_system_view()
return ((ntop.getPref("ntopng.prefs.system_mode_enabled") == "1") and isAdministrator())
end
-- ##############################################
function page_utils.set_system_view(toggle)
local t
if toggle == "1" or toggle == true then
t = "1"
elseif toggle == "0" or toggle == false then
t = "0"
end
if t then
ntop.setPref("ntopng.prefs.system_mode_enabled", t)
end
end
-- ##############################################
--- Check if the current page is valid
--- @return boolean True if the current page is in available_pages, false otherwise
function page_utils.is_valid_page(selected_page, available_pages)
if selected_page == nil then
traceError(TRACE_WARNING, TRACE_DEBUG, "selected_pages is nil!")
return false
end
if available_pages == nil then
traceError(TRACE_WARNING, TRACE_DEBUG, "available_pages is nil!")
return false
end
if type(available_pages) ~= 'table' then
traceError(TRACE_WARNING, TRACE_DEBUG, "available_pages is not a table!")
return false
end
-- do a linear search
for _, page in ipairs(available_pages) do
if (page == selected_page) then return true end
end
return false
end
-- ##############################################
-- @brief Prepares the URL which will be used for the redirect after interface switch
-- @param ifid The interface identifier of the interface that will be switched
-- @param if_type The type of the interface that will be switched
-- @return The URL
function page_utils.switch_interface_form_action_url(ifid, if_type)
local action_url = ""
local is_system_interface = page_utils.is_system_view()
local page_params = table.clone(_GET)
-- Read the currently active page
local active_page = page_utils.get_active_section()
if is_system_interface then
-- If the currently selected interface is system,
-- then the switch redirects to the root and not to the
-- currently selected page
action_url = ntop.getHttpPrefix() .. '/'
elseif page_utils.menu_sections[active_page] and page_utils.menu_sections[active_page]["zmq_only"] and if_type ~= "zmq" and if_type ~= "custom" then
-- If the interface that will be switched is non-ZMQ, and the currently
-- selected page is for ZMQ-only interfaces, then a redirection to root
-- is performed, rather than preserving the current page
action_url = ntop.getHttpPrefix() .. '/'
end
-- Attach the interface id of the interface that will be switched
page_params.ifid = ifid
-- Return the url, preserving all existing page parameters (e.g., host=xx)
return getPageUrl(action_url, page_params)
end
-- ##############################################
return page_utils