diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index a7b194558b..31e5129d80 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -213,9 +213,6 @@ class NetworkInterface : public Checkpointable { LocalTrafficStats *_localStats, nDPIStats *_ndpiStats, PacketStats *_pktStats, TcpPacketStats *_tcpPacketStats); - Host* findHostsByIP(AddressTree *allowed_hosts, - char *host_ip, u_int16_t vlan_id); - void topItemsCommit(const struct timeval *when); public: @@ -640,6 +637,7 @@ class NetworkInterface : public Checkpointable { u_int32_t dstHost, u_int16_t dport, u_int32_t s2d_pkts, u_int32_t d2s_pkts, u_int32_t s2d_bytes, u_int32_t d2s_bytes); + Host* findHostByIP(AddressTree *allowed_hosts, char *host_ip, u_int16_t vlan_id); }; #endif /* _NETWORK_INTERFACE_H_ */ diff --git a/scripts/locales/en.lua b/scripts/locales/en.lua index e419f24bd3..8dc77146d2 100644 --- a/scripts/locales/en.lua +++ b/scripts/locales/en.lua @@ -103,6 +103,7 @@ local en = { throughput = "Throughput", seen_since = "Seen Since", language = "Language", + remote_networks = "Remote Networks", locales = { en = "English", diff --git a/scripts/lua/modules/top_talkers_utils.lua b/scripts/lua/modules/top_talkers_utils.lua index b617c9359c..3d227143da 100644 --- a/scripts/lua/modules/top_talkers_utils.lua +++ b/scripts/lua/modules/top_talkers_utils.lua @@ -156,8 +156,13 @@ function top_talkers_utils.makeTopJson(_ifname) os_key = "local os" end - for what_key, what_value in - pairs({["hosts"] = hostname, ["asn"] = hoststats["asn"], [os_key] = hoststats["os"]}) do + local country = interface.getHostCountry(hostname) + + for what_key, what_value in pairs({ + ["hosts"] = hostname, ["asn"] = hoststats["asn"],[os_key] = hoststats["os"], + ["countries"] = ternary(not isEmptyString(country), country, nil), + ["networks"] = hoststats["local_network_id"], + }) do updateRes(res, vlan, what_key, what_value, direction, delta) end end @@ -190,11 +195,25 @@ function top_talkers_utils.enrichRecordInformation(class_key, rec) end elseif class_key == "asn" then url = ntop.getHttpPrefix()..'/lua/hosts_stats.lua?asn=' + elseif class_key == "networks" then + url = ntop.getHttpPrefix()..'/lua/hosts_stats.lua?network=' + + local network_name = nil + if rec.address == "-1" then + network_name = i18n("remote_networks") + else + network_name = ntop.getNetworkNameById(tonumber(rec.address)) + end + if not isEmptyString(network_name) then + label = network_name + end elseif class_key:contains("os") then url = ntop.getHttpPrefix()..'/lua/hosts_stats.lua?os=' end - url = url .. rec.address + if not isEmptyString(url) then + url = url .. rec.address + end end -- Update record information diff --git a/src/Lua.cpp b/src/Lua.cpp index 2571a3db14..fff8c602e2 100644 --- a/src/Lua.cpp +++ b/src/Lua.cpp @@ -2054,6 +2054,28 @@ static int ntop_get_interface_host_info(lua_State* vm) { return(CONST_LUA_OK); } +/* ****************************************** */ + +static int ntop_get_interface_host_country(lua_State* vm) { + NetworkInterface *ntop_interface = getCurrentInterface(vm); + char *host_ip; + u_int16_t vlan_id = 0; + char buf[64]; + Host* h = NULL; + + ntop->getTrace()->traceEvent(TRACE_DEBUG, "%s() called", __FUNCTION__); + + if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TSTRING)) return(CONST_LUA_ERROR); + get_host_vlan_info((char*)lua_tostring(vm, 1), &host_ip, &vlan_id, buf, sizeof(buf)); + + if((!ntop_interface) || ((h = ntop_interface->findHostByIP(get_allowed_nets(vm), host_ip, vlan_id)) == NULL)) + return(CONST_LUA_ERROR); + else { + lua_pushstring(vm, h->get_country(buf, sizeof(buf))); + return(CONST_LUA_OK); + } +} + /* ****************************************** */ #ifdef NOTUSED static int ntop_get_grouped_interface_host(lua_State* vm) { @@ -6494,6 +6516,7 @@ static const luaL_Reg ntop_interface_reg[] = { { "getBatchedLocalHostsInfo", ntop_get_batched_interface_local_hosts_info }, { "getBatchedRemoteHostsInfo", ntop_get_batched_interface_remote_hosts_info }, { "getHostInfo", ntop_get_interface_host_info }, + { "getHostCountry", ntop_get_interface_host_country }, { "getGroupedHosts", ntop_get_grouped_interface_hosts }, { "addMacsIpAddresses", ntop_add_macs_ip_addresses }, { "getNetworksStats", ntop_get_interface_networks_stats }, diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index b97206b72c..d3e86f63cf 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -2436,7 +2436,7 @@ void NetworkInterface::getnDPIStats(nDPIStats *stats, AddressTree *allowed_hosts bool walk_all = true; if(host_ip) - h = findHostsByIP(allowed_hosts, (char *)host_ip, vlan_id); + h = findHostByIP(allowed_hosts, (char *)host_ip, vlan_id); retriever.stats = stats; retriever.host = h; @@ -2992,7 +2992,7 @@ bool NetworkInterface::getHostInfo(lua_State* vm, disablePurge(false); - h = findHostsByIP(allowed_hosts, host_ip, vlan_id); + h = findHostByIP(allowed_hosts, host_ip, vlan_id); if(h) { h->lua(vm, allowed_hosts, true, true, true, false); @@ -3050,7 +3050,7 @@ bool NetworkInterface::serializeCheckpoint(json_object *my_object, DetailsLevel /* **************************************************** */ -Host* NetworkInterface::findHostsByIP(AddressTree *allowed_hosts, +Host* NetworkInterface::findHostByIP(AddressTree *allowed_hosts, char *host_ip, u_int16_t vlan_id) { if(host_ip != NULL) { Host *h = getHost(host_ip, vlan_id); @@ -6249,7 +6249,7 @@ int NetworkInterface::updateHostTrafficPolicy(AddressTree* allowed_networks, int rv; disablePurge(false); - if((h = findHostsByIP(allowed_networks, host_ip, host_vlan)) != NULL) { + if((h = findHostByIP(allowed_networks, host_ip, host_vlan)) != NULL) { h->updateHostTrafficPolicy(host_ip); rv = CONST_LUA_OK; } else @@ -6267,7 +6267,7 @@ int NetworkInterface::setHostDumpTrafficPolicy(AddressTree* allowed_networks, ch int rv; disablePurge(false); - if((h = findHostsByIP(allowed_networks, host_ip, host_vlan)) != NULL) { + if((h = findHostByIP(allowed_networks, host_ip, host_vlan)) != NULL) { h->setDumpTrafficPolicy(dump_traffic_to_disk); rv = CONST_LUA_OK; } else