From eeeb03839a14029d47685666f7869d908ffadbd2 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Thu, 28 Jan 2021 19:39:33 +0300 Subject: [PATCH] Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog --- client/src/actions/queryLogs.js | 2 +- client/src/helpers/helpers.js | 17 +++++++++++++---- internal/home/clientshttp.go | 10 ++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/client/src/actions/queryLogs.js b/client/src/actions/queryLogs.js index de8af4a3..076a9008 100644 --- a/client/src/actions/queryLogs.js +++ b/client/src/actions/queryLogs.js @@ -12,7 +12,7 @@ const enrichWithClientInfo = async (logs) => { if (Object.keys(clientsParams).length > 0) { const clients = await apiClient.findClients(clientsParams); - return addClientInfo(logs, clients, 'client'); + return addClientInfo(logs, clients, 'client_id', 'client'); } return logs; diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index 2acf5315..f8f276c8 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -128,12 +128,21 @@ export const normalizeTopStats = (stats) => ( })) ); -export const addClientInfo = (data, clients, param) => data.map((row) => { - const clientIp = row[param]; - const info = clients.find((item) => item[clientIp]) || ''; +export const addClientInfo = (data, clients, ...params) => data.map((row) => { + let info = ''; + params.find((param) => { + const id = row[param]; + if (id) { + const client = clients.find((item) => item[id]) || ''; + info = client?.[id] ?? ''; + } + + return info; + }); + return { ...row, - info: info?.[clientIp] ?? '', + info, }; }); diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 42d7fa20..edeaf585 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -264,8 +264,12 @@ func (clients *clientsContainer) handleFindClient(w http.ResponseWriter, r *http // findTemporary looks up the IP in temporary storages, like autohosts or // blocklists. func (clients *clientsContainer) findTemporary(ip net.IP, idStr string) (cj clientJSON, found bool) { + if ip == nil { + return cj, false + } + ch, ok := clients.FindAutoClient(idStr) - if !ok && ip != nil { + if !ok { // It is still possible that the IP used to be in the runtime // clients list, but then the server was reloaded. So, check // the DNS server's blocked IP list. @@ -286,9 +290,7 @@ func (clients *clientsContainer) findTemporary(ip net.IP, idStr string) (cj clie } cj = clientHostToJSON(idStr, ch) - if ip != nil { - cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) - } + cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) return cj, true }