Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion httpdocs/tables_config/hosts_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "hosts_list",
"data_url": "lua/rest/v2/get/host/active_list.lua",
"use_current_page": false,
"enable_search": false,
"enable_search": true,
"paging": true,
"display_empty_rows": true,
"default_sort": {
Expand Down
4 changes: 2 additions & 2 deletions include/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class NetworkInterface : public NetworkInterfaceAlertableEntity {
bool dhcpOnly, const AddressTree *const cidr_filter,
u_int8_t ipver_filter, int proto_filter,
TrafficType traffic_type_filter, u_int32_t device_ip,
bool alertedHost, u_int8_t mac_location_filter, char *sortColumn);
bool alertedHost, u_int8_t mac_location_filter, char *sortColumn, char *map_search);
int sortASes(struct flowHostRetriever *retriever, char *sortColumn);
int sortObsPoints(struct flowHostRetriever *retriever, char *sortColumn);
int sortCountries(struct flowHostRetriever *retriever, char *sortColumn);
Expand Down Expand Up @@ -813,7 +813,7 @@ class NetworkInterface : public NetworkInterfaceAlertableEntity {
TrafficType traffic_type_filter, u_int32_t device_ip, bool tsLua,
bool anomalousOnly, bool dhcpOnly, const AddressTree *const cidr_filter, bool alertedHost,
char *sortColumn, u_int32_t maxHits, u_int32_t toSkip, bool a2zSortOrder, bool useArrayFormat,
bool getCheckpointOnly = false, u_int8_t mac_location_filter = -1);
bool getCheckpointOnly = false, u_int8_t mac_location_filter = -1, char *map_search = NULL);
int getActiveASList(lua_State *vm, const Paginator *p, bool diff = false, ASType as_type = all);
int getActiveObsPointsList(lua_State *vm, const Paginator *p);
int getActiveCountriesList(lua_State *vm, const Paginator *p);
Expand Down
3 changes: 2 additions & 1 deletion scripts/lua/rest/v2/get/host/active_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local country = _GET["country"]
local os_ = tonumber(_GET["os"])
local mac = _GET["mac"]
local mac_location = _GET["location"]
local map_search = _GET["map_search"] or ""

local c_order = true
local lua_order = asc
Expand Down Expand Up @@ -109,7 +110,7 @@ local mapping_column_lua_c = {

local hosts_stats = hosts_retrv_function(false, mapping_column_lua_c[sort_column], length, start, c_order, country, os_, tonumber(vlan),
tonumber(asn), tonumber(network), mac, tonumber(pool), tonumber(ipversion), tonumber(protocol), traffic_type_filter,
filtered_hosts, blacklisted_hosts, anomalous, dhcp_hosts, cidr, device_ip, true --[[ Array format ]], false, mac_location)
filtered_hosts, blacklisted_hosts, anomalous, dhcp_hosts, cidr, device_ip, true --[[ Array format ]], false, mac_location, map_search)

for key, value in pairs(hosts_stats["hosts"]) do
local record = {}
Expand Down
5 changes: 4 additions & 1 deletion src/LuaEngineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@ static int ntop_get_interface_hosts_criteria(lua_State *vm,
bool alertedHost = false;
AddressTree cidr_filter;
bool arrayFormat = false;
char *map_search = NULL;

ntop->getTrace()->traceEvent(TRACE_DEBUG, "%s() called", __FUNCTION__);

Expand Down Expand Up @@ -1811,6 +1812,8 @@ static int ntop_get_interface_hosts_criteria(lua_State *vm,
if (lua_type(vm, 23) == LUA_TBOOLEAN) alertedHost = lua_toboolean(vm, 23);
if (lua_type(vm, 24) == LUA_TSTRING)
location_filter = str_2_location(lua_tostring(vm, 24));
if (lua_type(vm, 25) == LUA_TSTRING)
map_search = (char *)lua_tostring(vm, 25);

if ((!curr_iface) ||
curr_iface->getActiveHostsList(vm, &begin_slot, walk_all,
Expand All @@ -1820,7 +1823,7 @@ static int ntop_get_interface_hosts_criteria(lua_State *vm,
filtered_hosts, blacklisted_hosts, ipver_filter, proto_filter,
traffic_type_filter, device_ip, false /* host->lua */, anomalousOnly,
dhcpOnly, cidr_filter_enabled ? &cidr_filter : NULL, alertedHost, sortColumn,
maxHits, toSkip, a2zSortOrder, arrayFormat, false, location_filter) < 0)
maxHits, toSkip, a2zSortOrder, arrayFormat, false, location_filter, map_search) < 0)
return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_ERROR));

return (ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_OK));
Expand Down
23 changes: 15 additions & 8 deletions src/NetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5022,6 +5022,7 @@ struct flowHostRetriever {
u_int16_t observationPointId;
u_int8_t *mac, bridge_iface_idx;
char *manufacturer;
char *map_search;
bool sourceMacsOnly, dhcpHostsOnly;
time_t min_first_seen;
char *country;
Expand Down Expand Up @@ -5723,12 +5724,15 @@ static bool flow_search_walker(GenericHashEntry *h, void *user_data, bool *match
static bool host_search_walker(GenericHashEntry *he, void *user_data,
bool *matched) {
char buf[64];
char ipbuf[64];
char namebuf[256];
u_int8_t network_prefix = 0;
IpAddress *ip_addr = NULL;
struct flowHostRetriever *r = (struct flowHostRetriever *)user_data;
Host *h = (Host *)he;
u_int32_t prev_actNumEntries = r->actNumEntries;

const char *ipstr = h->get_ip()->print(ipbuf, sizeof(ipbuf));
const char *namestr = h->get_visual_name(namebuf, sizeof(namebuf));
if (r->actNumEntries >= r->maxNumEntries)
return(true); /* Limit reached */

Expand Down Expand Up @@ -5799,8 +5803,11 @@ static bool host_search_walker(GenericHashEntry *he, void *user_data,
#endif
(r->ipVersionFilter &&
(((r->ipVersionFilter == 4) && (!h->get_ip()->isIPv4())) ||
((r->ipVersionFilter == 6) && (!h->get_ip()->isIPv6()))))
)
((r->ipVersionFilter == 6) && (!h->get_ip()->isIPv6())))) ||
(r->map_search && r->map_search[0] &&
(strncmp(ipstr, r->map_search, strlen(r->map_search)) != 0 &&
strncmp(namestr, r->map_search, strlen(r->map_search)) != 0))
)
return (false); /* false = keep on walking */

if(r->currentSize == r->actNumEntries) {
Expand Down Expand Up @@ -6773,7 +6780,7 @@ int NetworkInterface::sortHosts(u_int32_t *begin_slot, bool walk_all, struct flo
bool blacklisted_hosts, bool anomalousOnly, bool dhcpOnly,
const AddressTree *const cidr_filter, u_int8_t ipver_filter,
int proto_filter, TrafficType traffic_type_filter, u_int32_t device_ip,
bool alertedHost, u_int8_t mac_location_filter, char *sortColumn) {
bool alertedHost, u_int8_t mac_location_filter, char *sortColumn, char *map_search) {
u_int8_t macAddr[6];
int (*sorter)(const void *_a, const void *_b);

Expand Down Expand Up @@ -6802,8 +6809,8 @@ int NetworkInterface::sortHosts(u_int32_t *begin_slot, bool walk_all, struct flo
retriever->device_ip = device_ip,
retriever->maxNumEntries = getHostsHashSize(),
retriever->alerted = alertedHost,
retriever->currentSize = FLOWHOSTRETRIEVER_BLOCK_SIZE;

retriever->currentSize = FLOWHOSTRETRIEVER_BLOCK_SIZE,
retriever->map_search = map_search;
retriever->elems = (struct flowHostRetrieveList *)calloc(sizeof(struct flowHostRetrieveList), retriever->currentSize);

if (retriever->elems == NULL) {
Expand Down Expand Up @@ -7164,7 +7171,7 @@ int NetworkInterface::getActiveHostsList(lua_State *vm, u_int32_t *begin_slot, b
TrafficType traffic_type_filter, u_int32_t device_ip, bool tsLua,
bool anomalousOnly, bool dhcpOnly, const AddressTree *const cidr_filter,
bool alertedHost, char *sortColumn, u_int32_t maxHits, u_int32_t toSkip, bool a2zSortOrder,
bool useArrayFormat, bool getCheckpointOnly, u_int8_t mac_location_filter) {
bool useArrayFormat, bool getCheckpointOnly, u_int8_t mac_location_filter, char *map_search) {
struct flowHostRetriever retriever;
int count = 1;
#ifdef NTOPNG_PRO
Expand All @@ -7190,7 +7197,7 @@ int NetworkInterface::getActiveHostsList(lua_State *vm, u_int32_t *begin_slot, b
pool_filter, filtered_hosts, blacklisted_hosts, anomalousOnly,
dhcpOnly, cidr_filter, ipver_filter, proto_filter,
traffic_type_filter, device_ip, alertedHost,
mac_location_filter, sortColumn) < 0) {
mac_location_filter, sortColumn, map_search) < 0) {
return (-1);
}

Expand Down
Loading