diff --git a/include/ntop_typedefs.h b/include/ntop_typedefs.h index 224d359954..9293a1dd2e 100644 --- a/include/ntop_typedefs.h +++ b/include/ntop_typedefs.h @@ -134,6 +134,8 @@ typedef enum { location_local_only, location_remote_only, location_broadcast_domain_only, + location_private_only, /* Only 192.168.0.0/16 and other private */ + location_public_only, /* Only non-private */ location_all, } LocationPolicy; diff --git a/scripts/lua/get_geo_hosts.lua b/scripts/lua/get_geo_hosts.lua index 3ca9205ddc..b08faf4de3 100644 --- a/scripts/lua/get_geo_hosts.lua +++ b/scripts/lua/get_geo_hosts.lua @@ -15,7 +15,7 @@ local response = {} local host_key = _GET["host"] or "" local host_info = url2hostinfo(_GET) -local MAX_HOSTS = 100 +local MAX_HOSTS = 512 local function is_localizable(host) return host and host["ip"] and not host["privatehost"] and not host["is_multicast"] and not host["is_broadcast"] and not isBroadMulticast(host["ip"]) @@ -32,111 +32,6 @@ local function get_max_bytes_from_peers(peers) return max end -local function load_hosts() - local hosts = {} - - if (host_info["host"] == nil) then - local hosts_stats = interface.getHostsInfo(true, "column_traffic", MAX_HOSTS) - hosts_stats = hosts_stats["hosts"] - - for host_ip, host in pairs(hosts_stats) do - if is_localizable(host) then - local res = { - lat = host["latitude"], - lng = host["longitude"], - name = host_ip, - html = getFlag(host["country"]) - } - - if not isEmptyString(host["city"]) then - host["city"] = host["city"] - end - - table.insert(hosts, res) - end - end - end - - return hosts -end - --- BEGIN OLD CODE - -local function load_flows(hosts_count, host_key) - local flows = {} - local peers = getTopFlowPeers(hostinfo2hostkey(host_info), MAX_HOSTS - hosts_count, nil, {detailsLevel="max"}) - - local max_bytes = get_max_bytes_from_peers(peers) - local min_threshold = 0 - - for key, value in pairs(peers) do - local flow = {} - local bytes = value["bytes"] - local percentage = (bytes * 100) / max_bytes - - local client = { - lat = value["cli.latitude"], - lng = value["cli.longitude"] - } - - local is_public = (not(value["cli.private"] and value["srv.private"]) and - not(isBroadMulticast(value["cli.ip"])) and - not(isBroadMulticast(value["srv.ip"]))) - - if not is_public then goto continue end - - if (percentage >= min_threshold) and (client.lat ~= nil) and (client.lng ~= nil) then - - -- set up the client informations - - -- if the client is private then disable his rendering - client["isDrawable"] = not(value["cli.private"]) - -- check if the client is the root - client["isRoot"] = (value["cli.ip"] == host_key); - - if not isEmptyString(value["cli.city"]) then - client["city"] = value["cli.city"] - end - - client["html"] = getFlag(value["cli.country"]) - client["name"] = hostinfo2hostkey(value, "cli") - - -- set up the server informations - local server = { - lat = value["srv.latitude"], - lng = value["srv.longitude"], - isDrawable = not(value["srv.private"]), - isRoot = (value["srv.ip"] == host_key), - html = getFlag(value["srv.country"]), - name = hostinfo2hostkey(value, "srv") - } - - if not isEmptyString(value["srv.city"]) then - server["city"] = value["srv.city"] - end - - flow["client"] = client - flow["server"] = server - - flow["flow"] = percentage - flow["html"] = hostinfo2hostkey(value, "cli").." -> "..hostinfo2hostkey(value, "srv") - - end - - table.insert(flows, flow) - ::continue:: - end - - return flows -end - --- Initialize host array object --- response["hosts"] = load_hosts() --- response["flows"] = load_flows(table.len(response["hosts"]), host_key) --- print(json.encode(response)) - --- END OLD CODE - -- ############################################################ local function handlePeer(prefix, host_key, value) @@ -187,10 +82,8 @@ end local function show_hosts(hosts_count, host_key) local hosts = {} - if((host_key == nil) or (host_key == "")) then - local what = interface.getHostsInfo(true, "column_traffic", MAX_HOSTS) - + local what = interface.getPublicHostsInfo(true, "column_traffic", MAX_HOSTS) for key,value in pairs(what.hosts) do local h = handleHost(key, value) diff --git a/src/LuaEngineInterface.cpp b/src/LuaEngineInterface.cpp index 6b95c3f70d..abf12d7eb6 100644 --- a/src/LuaEngineInterface.cpp +++ b/src/LuaEngineInterface.cpp @@ -3327,6 +3327,10 @@ static int ntop_get_interface_broadcast_domain_hosts_info(lua_State* vm) { return(ntop_get_interface_hosts(vm, location_broadcast_domain_only)); } +static int ntop_get_public_hosts_info(lua_State* vm) { + return(ntop_get_interface_hosts(vm, location_public_only)); +} + /* ****************************************** */ static int ntop_get_batched_interface_hosts_info(lua_State* vm) { @@ -4388,6 +4392,7 @@ static luaL_Reg _ntop_interface_reg[] = { { "getLocalHostsInfo", ntop_get_interface_local_hosts_info }, { "getRemoteHostsInfo", ntop_get_interface_remote_hosts_info }, { "getBroadcastDomainHostsInfo", ntop_get_interface_broadcast_domain_hosts_info }, + { "getPublicHostsInfo", ntop_get_public_hosts_info }, { "getBatchedFlowsInfo", ntop_get_batched_interface_flows_info }, { "getBatchedHostsInfo", ntop_get_batched_interface_hosts_info }, { "getBatchedLocalHostsInfo", ntop_get_batched_interface_local_hosts_info }, diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 3af4850ca7..7075c85c4b 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -4216,6 +4216,9 @@ static bool host_search_walker(GenericHashEntry *he, void *user_data, bool *matc if((r->location == location_local_only && !h->isLocalHost()) || (r->location == location_remote_only && h->isLocalHost()) || (r->location == location_broadcast_domain_only && !h->isBroadcastDomainHost()) || + (r->location == location_private_only && !h->isPrivateHost()) || + (r->location == location_public_only && h->isPrivateHost()) || + (r->location == location_public_only && h->isPrivateHost()) || ((r->vlan_id != ((u_int16_t)-1)) && (r->vlan_id != h->get_vlan_id())) || ((r->ndpi_proto != -1) && (h->get_ndpi_stats()->getProtoBytes(r->ndpi_proto) == 0)) || ((r->asnFilter != (u_int32_t)-1) && (r->asnFilter != h->get_asn())) ||