Skip to content

Commit

Permalink
home: imp whois resp
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Apr 1, 2021
1 parent fb97e0d commit 3b8ef86
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
28 changes: 17 additions & 11 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions internal/home/clientshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 14 additions & 11 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1882,33 +1882,36 @@
'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': >
The rule due to which the client is disallowed. If disallowed is
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': >
Expand Down Expand Up @@ -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':
Expand All @@ -2270,7 +2273,7 @@
'use_global_blocked_services': true
'blocked_services': null
'upstreams': null
'whois_info': null
'whois_info': {}
'disallowed': false
'disallowed_rule': ''
'AccessListResponse':
Expand Down

0 comments on commit 3b8ef86

Please sign in to comment.