diff --git a/internal/home/clients.go b/internal/home/clients.go index 2396281ef58..92efc0befcb 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -270,13 +270,25 @@ func copyStrings(a []string) (b []string) { return append(b, a...) } +func toQueryLogWhois(wi *RuntimeClientWhoisInfo) (cw *querylog.ClientWhois) { + if wi == nil { + return &querylog.ClientWhois{} + } + + return &querylog.ClientWhois{ + City: wi.City, + Country: wi.Country, + Orgname: wi.Orgname, + } +} + // findMultiple is a wrapper around Find to make it a valid client finder for // the query log. err is always nil. func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client, err error) { for _, id := range ids { var name string var foundIDs []string - var whois *querylog.ClientWhois + whois := &querylog.ClientWhois{} c, ok := clients.Find(id) if ok { @@ -290,14 +302,7 @@ func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client, } foundIDs = []string{ac.Host} - - if wi := ac.WhoisInfo; wi != nil { - whois = &querylog.ClientWhois{ - City: wi.City, - Country: wi.Country, - Orgname: wi.Orgname, - } - } + whois = toQueryLogWhois(ac.WhoisInfo) } ip := net.ParseIP(id) @@ -660,8 +665,9 @@ func (clients *clientsContainer) addHostLocked(ip, host string, src clientSource ch.Source = src } else { ch = &ClientHost{ - Host: host, - Source: src, + Host: host, + Source: src, + WhoisInfo: &RuntimeClientWhoisInfo{}, } clients.ipHost[ip] = ch diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 75a1d3c24cc..5c961a9f6c7 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -60,17 +60,10 @@ func (clients *clientsContainer) handleGetClients(w http.ResponseWriter, _ *http data.Clients = append(data.Clients, cj) } for ip, ch := range clients.ipHost { - whois := ch.WhoisInfo - if whois == nil { - // The frontent currently expects an empty object - // instead of null. - whois = &RuntimeClientWhoisInfo{} - } - cj := clientHostJSON{ IP: ip, Name: ch.Host, - WhoisInfo: whois, + WhoisInfo: ch.WhoisInfo, } cj.Source = "etc/hosts" diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 7733cc9560b..c0eb90961ad 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1882,11 +1882,10 @@ 'description': > Client information for a query log item. 'properties': - 'name': + 'disallowed': + 'type': 'boolean' 'description': > - Persistent client's name or an empty string if this is a runtime - client. - 'type': 'string' + Whether the client's IP is blocked or not. 'disallowed_rule': 'type': 'string' 'description': > @@ -1894,21 +1893,25 @@ set to true, and this string is empty, then the client IP is disallowed by the "allowed IP list", that is it is not included in the allowed list. - 'whois': - '$ref': '#/components/schemas/QueryLogItemClientWhois' 'ids': 'description': > IP, CIDR, MAC, or client ID. 'items': 'type': 'string' 'type': 'array' - 'disallowed': - 'type': 'boolean' + 'name': 'description': > - Whether the client's IP is blocked or not. + Persistent client's name or an empty string if this is a runtime + client. + 'type': 'string' + 'whois': + '$ref': '#/components/schemas/QueryLogItemClientWhois' 'required': + - 'disallowed' + - 'disallowed_rule' - 'ids' - 'name' + - 'whois' 'type': 'object' 'QueryLogItemClientWhois': 'description': > @@ -2256,7 +2259,7 @@ 'use_global_blocked_services': true 'blocked_services': null 'upstreams': null - 'whois_info': null + 'whois_info': {} 'disallowed': false 'disallowed_rule': '' - '1.2.3.4': @@ -2270,7 +2273,7 @@ 'use_global_blocked_services': true 'blocked_services': null 'upstreams': null - 'whois_info': null + 'whois_info': {} 'disallowed': false 'disallowed_rule': '' 'AccessListResponse':