-- -- (C) 2013-21 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path require "lua_utils" local host_pools_nedge if ntop.isnEdge() then host_pools_nedge = require "host_pools_nedge" end local host_pools = require "host_pools" -- Instantiate host pools local host_pools_instance = host_pools:create() local page_utils = require("page_utils") local custom_column_utils = require("custom_column_utils") local discover = require("discover_utils") local have_nedge = ntop.isnEdge() local function generate_map_url(map, map_url, query, icon) local url = "" if (ntop.isPro()) then local map_available = table.len(map) > 0 if (map_available) then url = "" end end return url end sendHTTPContentTypeHeader('text/html') page_utils.set_active_menu_entry(page_utils.menu_entries.hosts) local protocol = _GET["protocol"] local asn = _GET["asn"] local vlan = _GET["vlan"] local network = _GET["network"] local cidr = _GET["network_cidr"] local country = _GET["country"] local mac = _GET["mac"] local os_ = _GET["os"] local community = _GET["community"] local pool = _GET["pool"] local ipversion = _GET["version"] local traffic_type = _GET["traffic_type"] local base_url = ntop.getHttpPrefix() .. "/lua/hosts_stats.lua" local page_params = {} local charts_icon = "" local mode = _GET["mode"] if isEmptyString(mode) then mode = "all" else page_params["mode"] = mode end local hosts_filter = '' if ((mode ~= "all") or (not isEmptyString(pool))) then hosts_filter = '' end function getPageTitle(protocol_name, traffic_type_title, network_name, cidr, ipver_title, os_, country, asninfo, mac, pool_, vlan_title) local mode_label = "" if mode == "remote" then mode_label = i18n("hosts_stats.remote") elseif mode == "local" then mode_label = i18n("hosts_stats.local") elseif mode == "filtered" then mode_label = i18n("hosts_stats.filtered") elseif mode == "blacklisted" then mode_label = i18n("hosts_stats.blacklisted") elseif mode == "dhcp" then mode_label = i18n("nedge.network_conf_dhcp") end -- Note: we must use the empty string as fallback. Multiple spaces will be collapsed into one automatically. return i18n("hosts_stats.hosts_page_title", { all = isEmptyString(mode_label) and i18n("hosts_stats.all") or "", traffic_type = traffic_type_title or "", local_remote = mode_label, protocol = protocol_name or "", network = not isEmptyString(network_name) and i18n("hosts_stats.in_network", {network=network_name}) or "", network_cidr = not isEmptyString(cidr) and i18n("hosts_stats.in_network", {network=cidr}) or "", ip_version = ipver_title or "", ["os"] = discover.getOsName(os_), country_asn_or_mac = country or asninfo or mac or pool_ or "", vlan = vlan_title or "", }) .. charts_icon end dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") local ifstats = interface.getStats() -- Parameters necessary for the page title local protocol_name = nil local network_name = nil local traffic_type_title = nil local ipver_title = nil local asninfo = nil local os_title = nil local country_title = nil local mac_title = nil local vlan_title = nil local pool_title = nil if((protocol ~= nil) and (protocol ~= "")) then protocol_name = interface.getnDPIProtoName(tonumber(protocol)) end if(protocol_name == nil) then protocol_name = protocol end local traffic_type_title if not isEmptyString(traffic_type) then page_params["traffic_type"] = traffic_type if traffic_type == "one_way" then traffic_type_title = i18n("hosts_stats.traffic_type_one_way") elseif traffic_type == "bidirectional" then traffic_type_title = i18n("hosts_stats.traffic_type_two_ways") end else traffic_type_title = "" end if(network ~= nil) then local network_key = ntop.getNetworkNameById(tonumber(network)) network_name = getLocalNetworkAlias(network_key) if isEmptyString(network_name) then network_name = i18n("hosts_stats.remote") end else network_name = "" end if not isEmptyString(ipversion) then ipver_title = i18n("hosts_stats.ipver_title", {version_num=ipversion}) else ipver_title = "" end if(asn ~= nil) then asninfo = " " .. i18n("hosts_stats.asn_title",{asn=asn}) .. "  " end if(os_ ~= nil) then os_title = " " .. os_ end if(country ~= nil) then country_title = " " .. i18n("hosts_stats.country_title", {country=country}) end if(mac ~= nil) then mac_title = " " .. i18n("hosts_stats.mac_title", {mac=mac}) end if(vlan ~= nil) then local link_service_map = generate_map_url(interface.serviceMap(nil, tonumber(vlan)), "service_map.lua", "vlan=" .. vlan, "fas fa-concierge-bell") local link_periodicity_map = generate_map_url(interface.periodicityMap(nil, tonumber(vlan)), "periodicity_map.lua", "vlan=" .. vlan, "fas fa-clock") vlan_title = " [".. i18n("hosts_stats.vlan_title", {vlan=vlan}) .."] " .. link_service_map .. " " .. link_periodicity_map end if(pool ~= nil) then local link_service_map = "" local link_periodicity_map = "" local charts_available = areHostPoolsTimeseriesEnabled(ifstats.id) if (tonumber(pool) ~= host_pools_instance.DEFAULT_POOL_ID) then link_service_map = generate_map_url(interface.serviceMap(nil, nil, tonumber(pool)), "service_map.lua", "host_pool_id=".. pool, "fas fa-concierge-bell") link_periodicity_map = generate_map_url(interface.periodicityMap(nil, nil, tonumber(pool)), "periodicity_map.lua", "host_pool_id=".. pool, "fas fa-clock") end local pool_edit = "" local pool_link local title if(tonumber(pool) ~= host_pools_instance.DEFAULT_POOL_ID) or (have_nedge) then if have_nedge then pool_link = "/lua/pro/nedge/admin/nf_edit_user.lua?username=" .. ternary(pool == host_pools_nedge.DEFAULT_POOL_ID, "", host_pools_nedge.poolIdToUsername(pool)) title = i18n("nedge.edit_user") else pool_link = "/lua/admin/manage_host_members.lua?pool="..pool title = i18n("host_pools.manage_pools") end pool_edit = "  " end pool_title = " "..i18n(ternary(have_nedge, "hosts_stats.user_title", "hosts_stats.pool_title"), {poolname=host_pools_instance:get_pool_name(pool)}) .."".. pool_edit .. ternary(charts_available, " ", "") ..link_service_map .. link_periodicity_map.. "" end page_utils.print_page_title(getPageTitle(protocol_name, traffic_type_title, network_name, cidr, ipver_title, os_title, country_title, asninfo, mac_title, pool_title, vlan_title)) if (_GET["page"] ~= "historical") then if(asn ~= nil) then print [[
") -- close .card-header if (asn ~= nil) then print("
") end if(asn ~= nil) then print [[
]] end -- build the current filter url page_params["os"] = os_ page_params["asn"] = asn page_params["community"] = community page_params["vlan"] = vlan page_params["country"] = country page_params["mac"] = mac page_params["pool"] = pool page_params["network_cidr"] = cidr if(protocol ~= nil) then -- Example HTTP.Facebook dot = string.find(protocol, '%.') if(dot ~= nil) then protocol = string.sub(protocol, dot+1) end page_params["protocol"] = protocol end if(network ~= nil) then page_params["network"] = network local network_key = ntop.getNetworkNameById(tonumber(network)) if not isEmptyString(network_name) then local charts_available = areInterfaceTimeseriesEnabled(ifstats.id) charts_icon = " " if charts_available then charts_icon = charts_icon.."  " end charts_icon = charts_icon.."" end end if not isEmptyString(ipversion) then page_params["version"] = ipversion end custom_column_utils.updateCustomColumn() local custom_name, custom_key, custom_align = custom_column_utils.getCustomColumnName() print [[
]] if(have_nedge) then print[[ ]] end if(asn ~= nil) then print [[
]] if (asn ~= nil) then print("
") print("
") print("
") end print[[ ]] end -- if(asn ~= nil) end dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")