Removed service/periodicity maps href for unprivileged users #5617

This commit is contained in:
MatteoBiscosi 2021-07-02 11:54:34 +02:00
parent 06b72839dd
commit 08e4c16375
4 changed files with 48 additions and 60 deletions

View file

@ -35,6 +35,7 @@ local flow_consts = require "flow_consts"
local alert_consts = require "alert_consts"
local plugins_utils = require "plugins_utils"
local am_utils = plugins_utils.loadModule("active_monitoring", "am_utils")
local behavior_utils = require "behavior_utils"
local host_pools_nedge
if ntop.isnEdge() then
@ -302,29 +303,14 @@ else
local service_map_link = ntop.getHttpPrefix() .. "/lua/pro/enterprise/service_map.lua?host=" .. host_ip
local periodicity_map_link = ntop.getHttpPrefix() .. "/lua/pro/enterprise/periodicity_map.lua?&host=" .. host_ip
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local service_map = interface.serviceMap(_GET["host"])
service_map_available, periodicity_map_available = behavior_utils.mapsAvailable()
if service_map and (table.len(service_map) > 0) then
service_map_available = true
end
if host_vlan ~= 0 then
service_map_link = service_map_link .. "&vlan=" .. host_vlan
end
if(service_map_available) and (host_vlan ~= 0) then
service_map_link = service_map_link .. "&vlan=" .. host_vlan
end
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local periodicity_map = interface.periodicityMap(_GET["host"])
if periodicity_map and (table.len(periodicity_map) > 0) then
num_periodicity = table.len(periodicity_map)
periodicity_map_available = true
end
if host_vlan ~= 0 then
periodicity_map_link = periodicity_map_link .. "&vlan=" .. host_vlan
end
if(periodicity_map_available) and (host_vlan ~= 0) then
periodicity_map_link = periodicity_map_link .. "&vlan=" .. host_vlan
end
page_utils.print_navbar(title, url,

View file

@ -25,6 +25,7 @@ local page_utils = require("page_utils")
local ui_utils = require("ui_utils")
local interface_pools = require ("interface_pools")
local auth = require "auth"
local behavior_utils = require("behavior_utils")
require "lua_utils"
require "prefs_utils"
@ -80,11 +81,9 @@ if not ntop.isnEdge() and is_packet_interface then
is_mirrored_traffic = ternary(ntop.getPref(is_mirrored_traffic_pref) == '1', true, false)
end
local service_map = interface.serviceMap()
local service_map_available = false
if(service_map and (table.len(service_map) > 0)) then
service_map_available = true
end
local periodicity_map_available = false
service_map_available, periodicity_map_available = behavior_utils.mapsAvailable()
local disaggregation_criterion_key = "ntopng.prefs.dynamic_sub_interfaces.ifid_"..tostring(ifid)..".mode"
local charts_available = areInterfaceTimeseriesEnabled(ifid)
@ -270,25 +269,6 @@ if (ntop.isPro()) then
sites_granularities = top_sites_update.getGranularitySites(nil, nil, ifId, true)
end
local periodicity_map_available = false
local service_map_available = false
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local service_map = interface.serviceMap(_GET["host"])
if service_map and (table.len(service_map) > 0) then
service_map_available = true
end
end
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local periodicity_map = interface.periodicityMap(_GET["host"])
if periodicity_map and (table.len(periodicity_map) > 0) then
periodicity_map_available = true
end
end
page_utils.print_navbar(title, url,
{
{
@ -406,7 +386,7 @@ page_utils.print_navbar(title, url,
},
{
hidden = (not periodicity_map_available),
page_name = "service_map",
page_name = "periodicity_map",
url = ntop.getHttpPrefix() .. "/lua/pro/enterprise/periodicity_map.lua",
label = "<i class=\"fas fa-lg fa-clock\"></i>",
},

View file

@ -31,6 +31,7 @@ local updates_supported = (is_admin and ntop.isPackage() and not ntop.isWindows(
local has_local_auth = (ntop.getPref("ntopng.prefs.local.auth_enabled") ~= '0')
local observationPointId = _GET["observationPointId"]
local is_system_interface = page_utils.is_system_view()
local behavior_utils = require("behavior_utils")
blog_utils.fetchLatestPosts()
@ -232,22 +233,9 @@ else
-- ##############################################
local service_map_available = false
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local service_map = interface.serviceMap()
local periodicity_map_available = false
if service_map and (table.len(service_map) > 0) then
service_map_available = true
end
end
local periodic_info_available = false
if(ntop.isEnterpriseL() and (ntop.getPref("ntopng.prefs.is_behaviour_analysis_enabled") == "1")) then
local periodicity_map = interface.periodicityMap()
if periodicity_map and (table.len(periodicity_map) > 0) then
periodic_info_available = true
end
end
service_map_available, periodicity_map_available = behavior_utils.mapsAvailable()
-- Hosts
page_utils.add_menubar_section(
@ -331,7 +319,7 @@ else
},
{
entry = page_utils.menu_entries.periodicity_map,
hidden = not periodic_info_available,
hidden = not periodicity_map_available,
url = '/lua/pro/enterprise/periodicity_map.lua',
},
{

View file

@ -6,6 +6,7 @@ local rest_utils = require("rest_utils")
local behavior_utils = {}
local redis_key = "changed_behavior_alert_setup"
local behavior_maps_key = "ntopng.prefs.is_behaviour_analysis_enabled"
-- ##############################################
@ -60,5 +61,38 @@ function behavior_utils.reset()
end
end
local maps_utils = {}
-- ##############################################
local function areMapsEnabled()
return(ntop.isEnterpriseL() and ntop.isAdministrator() and (ntop.getPref(behavior_maps_key) == "1"))
end
-- ##############################################
-- Returns two bools value, one for service map and the other for periodicity map
function behavior_utils.mapsAvailable()
local service_map_available = false
local periodic_map_available = false
if areMapsEnabled() then
local service_map = interface.serviceMap()
local periodicity_map = interface.periodicityMap()
if service_map and (table.len(service_map) > 0) then
service_map_available = true
end
if periodicity_map and (table.len(periodicity_map) > 0) then
periodic_map_available = true
end
end
return service_map_available, periodic_map_available
end
-- ##############################################
return behavior_utils