diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index 8268383ed3..2287e6295a 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -224,8 +224,6 @@ class NetworkInterface : public Checkpointable { const char *sortColumn); bool isNumber(const char *str); - bool validInterface(char *name); - bool isInterfaceUp(char *name); bool checkIdle(); void dumpPacketDisk(const struct pcap_pkthdr *h, const u_char *packet, dump_reason reason); void dumpPacketTap(const struct pcap_pkthdr *h, const u_char *packet, dump_reason reason); diff --git a/include/Utils.h b/include/Utils.h index 9a2fa7a916..c2ba16ceab 100755 --- a/include/Utils.h +++ b/include/Utils.h @@ -130,6 +130,7 @@ class Utils { static u_int64_t mac2int(u_int8_t *mac); static u_int8_t* int2mac(u_int64_t mac, u_int8_t *buf); static void listInterfaces(lua_State* vm); + static bool validInterface(char *name); /* System Host Montoring and Diagnose Functions */ static void luaCpuLoad(lua_State* vm); diff --git a/scripts/locales/en.lua b/scripts/locales/en.lua index a4f786bf91..47642a2993 100644 --- a/scripts/locales/en.lua +++ b/scripts/locales/en.lua @@ -198,11 +198,11 @@ local lang = { ["host_entity"] = "host %{entity_value}", ["host_pool_has_connected"] = "The host pool %{pool} has connected to the network.", ["host_pool_has_disconnected"] = "The host pool %{pool} has disconnected from the network.", + ["host_remote_to_remote"] = "Remote host %{ip} [ %{mac} ] has contacted a remote host. Remote-to-remote flows available from the flow alerts page.", ["interface_entity"] = "interface %{entity_value}", ["mac_ip_association_change"] = "IP %{ip} changed association from %{old_mac} to %{new_mac}", ["network_entity"] = "network %{entity_value}", ["nfq_flushed"] = "Interface %{name} packets queue flushed. Queue %{pct}%% full with %{tot} packets and %{dropped} drops.", - ["host_remote_to_remote"] = "Remote host %{ip} [ %{mac} ] has contacted a remote host. Remote-to-remote flows available from the flow alerts page.", ["ntopng_anomalous_termination"] = "Started after anomalous termination (bug report)", ["ntopng_start"] = "Started", ["ntopng_stop"] = "Stopped", @@ -2828,11 +2828,13 @@ local lang = { ["disk_space"] = "Disk Space", ["disk_space_desc"] = "Maximum disk space to use for each interface, configure this according to the desired data retention time.", ["enable_interface_desc"] = "Enable continuous traffic recording on %{interface}.", + ["failure"] = "Failure", ["interface"] = "Network Interface", ["license"] = "License", ["license_desc"] = "Configure here your n2disk license key.", ["network_interfaces"] = "Network Interfaces", ["not_a_ntopng_interface"] = "This interface is not controlled by ntopng: please add this interface to the ntopng configuration and restart ntopng.", + ["recording"] = "Recording", ["running_instances_license"] = "Please restart the recording on all interfaces after configuring a new license in order to apply the change.", ["running_instances_storage"] = "Please stop recording on all interfaces before changing the storage settings.", ["storage"] = "Storage", diff --git a/scripts/lua/admin/traffic_recording.lua b/scripts/lua/admin/traffic_recording.lua index 16bd3141d3..68f14a94a0 100644 --- a/scripts/lua/admin/traffic_recording.lua +++ b/scripts/lua/admin/traffic_recording.lua @@ -161,8 +161,10 @@ function printInterfaces() if_desc = i18n("traffic_recording.not_a_ntopng_interface") end + local if_badge = "" + prefsToggleButton(subpage_active, { - title = if_name, + title = if_name.." "..if_badge, description = if_desc, redis_prefix = "ntopng.prefs.traffic_recording.", field = "iface_on_"..if_id, content = "", default = "0", to_switch = nil, disabled = disabled @@ -212,10 +214,21 @@ function printInterfaces() success: function(content) { var data = jQuery.parseJSON(content); for (var ifname in data) { - var btn = $('#iface_on_'+ifname+'_on_id'); - if (btn) { - if (data[ifname].status == 'on') eval('iface_on_'+ifname+'_functionOn()'); - else eval('iface_on_'+ifname+'_functionOff()'); + var badge = $('#iface_on_badge_'+ifname); + if (badge) { + if (data[ifname].status == 'on') { + badge.removeClass(); + badge.addClass("label label-success"); + badge.text("]] print(i18n("traffic_recording.recording")) print [["); + badge.show(); + } else if (data[ifname].status == 'failure') { + badge.removeClass(); + badge.addClass("label label-danger"); + badge.text("]] print(i18n("traffic_recording.failure")) print [["); + badge.show(); + } else { + badge.hide(); + } } } } diff --git a/scripts/lua/modules/recording_utils.lua b/scripts/lua/modules/recording_utils.lua index 8451535236..adac9bc28b 100644 --- a/scripts/lua/modules/recording_utils.lua +++ b/scripts/lua/modules/recording_utils.lua @@ -38,30 +38,29 @@ function recording_utils.getInterfaces() local n2disk_interfaces = {} for k,v in pairs(all_interfaces) do - if not string.match(k, "usb") then - local is_zc = false - local in_use = false + local in_use = false + local description = v.description - -- TODO check RSS queues - if ntopng_interfaces_map[k] ~= nil or - ntopng_interfaces_map['zc:'..k] ~= nil then - in_use = true - end - - local proc_info = io.open("/proc/net/pf_ring/dev/"..k.."/info", "r") - if proc_info ~= nil then - local info = proc_info:read "*a" - if string.match(info, "ZC") then - is_zc = true - end - end - - n2disk_interfaces[k] = { - desc = v.description, - is_zc = is_zc, - in_use = in_use - } + -- TODO check RSS queues + if ntopng_interfaces_map[k] ~= nil or + ntopng_interfaces_map['zc:'..k] ~= nil then + in_use = true end + + local proc_info = io.open("/proc/net/pf_ring/dev/"..k.."/info", "r") + if proc_info ~= nil then + local info = proc_info:read "*a" + if string.match(info, "ZC") then + is_zc = true + description = description.." [ZC]" + end + end + + n2disk_interfaces[k] = { + desc = description, + is_zc = is_zc, + in_use = in_use + } end return n2disk_interfaces diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 2e02f44526..39eae61004 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -5485,24 +5485,6 @@ bool NetworkInterface::findHostsByName(lua_State* vm, /* **************************************************** */ -bool NetworkInterface::validInterface(char *name) { -#ifdef HAVE_NEDGE - return((name && (strncmp(name, "nf:", 3) == 0)) ? true : false); -#else - if(name && - (strstr(name, "PPP") /* Avoid to use the PPP interface */ - || strstr(name, "dialup") /* Avoid to use the dialup interface */ - || strstr(name, "ICSHARE") /* Avoid to use the internet sharing interface */ - || strstr(name, "NdisWan"))) { /* Avoid to use the internet sharing interface */ - return(false); - } - - return(true); -#endif -} - -/* **************************************************** */ - u_int NetworkInterface::printAvailableInterfaces(bool printHelp, int idx, char *ifname, u_int ifname_len) { char ebuf[256]; @@ -5526,7 +5508,7 @@ u_int NetworkInterface::printAvailableInterfaces(bool printHelp, int idx, } for(int i = 0; devpointer != NULL; i++) { - if(validInterface(devpointer->description)) { + if(Utils::validInterface(devpointer->description)) { numInterfaces++; if(ifname == NULL) { @@ -5763,29 +5745,6 @@ void NetworkInterface::listHTTPHosts(lua_State *vm, char *key) { /* **************************************** */ -bool NetworkInterface::isInterfaceUp(char *name) { -#ifdef WIN32 - return(true); -#else - struct ifreq ifr; - int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - - if(strlen(name) >= sizeof(ifr.ifr_name)) - return(false); - - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, name); - if(ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { - closesocket(sock); - return(false); - } - closesocket(sock); - return(!!(ifr.ifr_flags & IFF_UP)); -#endif -} - -/* **************************************** */ - void NetworkInterface::addAllAvailableInterfaces() { char ebuf[256] = { '\0' }; pcap_if_t *devpointer; @@ -5794,9 +5753,9 @@ void NetworkInterface::addAllAvailableInterfaces() { ; } else { for(int i = 0; devpointer != 0; i++) { - if(validInterface(devpointer->description) + if(Utils::validInterface(devpointer->description) && (strncmp(devpointer->name, "virbr", 5) != 0) /* Ignore virtual interfaces */ - && isInterfaceUp(devpointer->name) + && Utils::isInterfaceUp(devpointer->name) ) { ntop->getPrefs()->add_network_interface(devpointer->name, devpointer->description); diff --git a/src/Utils.cpp b/src/Utils.cpp index 907730f80c..a10a6ed411 100755 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -3212,7 +3212,8 @@ void Utils::listInterfaces(lua_State* vm) { devpointer = devs; while (devpointer != NULL) { - if (!(devpointer->flags & PCAP_IF_LOOPBACK)) { + if (Utils::validInterface(devpointer->description) && + Utils::isInterfaceUp(devpointer->name)) { lua_newtable(vm); lua_push_str_table_entry(vm, "description", devpointer->description ? devpointer->description : (char *) ""); @@ -3231,3 +3232,21 @@ void Utils::listInterfaces(lua_State* vm) { /* ****************************************************** */ +bool Utils::validInterface(char *name) { +#ifdef HAVE_NEDGE + return((name && (strncmp(name, "nf:", 3) == 0)) ? true : false); +#else + if(name && + (strstr(name, "PPP") /* Avoid to use the PPP interface */ + || strstr(name, "dialup") /* Avoid to use the dialup interface */ + || strstr(name, "ICSHARE") /* Avoid to use the internet sharing interface */ + || strstr(name, "NdisWan"))) { /* Avoid to use the internet sharing interface */ + return(false); + } + + return(true); +#endif +} + +/* ****************************************************** */ +