Skip to content

Commit

Permalink
all: add more fields to querylog client
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Apr 1, 2021
1 parent 4b2a2db commit aa1769f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 27 deletions.
4 changes: 4 additions & 0 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// IsBlockedIP - return TRUE if this client should be blocked
func (s *Server) IsBlockedIP(ip net.IP) (bool, string) {
if ip == nil {
return false, ""
}

return s.access.IsBlockedIP(ip)
}
44 changes: 27 additions & 17 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,31 +274,41 @@ func copyStrings(a []string) (b []string) {
// 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

c, ok := clients.Find(id)
if ok {
return &querylog.Client{
Name: c.Name,
IDs: c.IDs,
}, nil
}
name = c.Name
foundIDs = c.IDs
} else {
var ac ClientHost
ac, ok = clients.FindAutoClient(id)
if !ok {
continue
}

ac, ok := clients.FindAutoClient(id)
if !ok {
continue
}
foundIDs = []string{ac.Host}

var whois *querylog.ClientWhois
if wi := ac.WhoisInfo; wi != nil {
whois = &querylog.ClientWhois{
City: wi.City,
Country: wi.Country,
Orgname: wi.Orgname,
if wi := ac.WhoisInfo; wi != nil {
whois = &querylog.ClientWhois{
City: wi.City,
Country: wi.Country,
Orgname: wi.Orgname,
}
}
}

ip := net.ParseIP(id)
disallowed, disallowedRule := clients.dnsServer.IsBlockedIP(ip)

return &querylog.Client{
IDs: []string{ac.Host},
Whois: whois,
Name: name,
DisallowedRule: disallowedRule,
Whois: whois,
IDs: foundIDs,
Disallowed: disallowed,
}, nil
}

Expand Down
9 changes: 8 additions & 1 deletion internal/home/clientshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ 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: ch.WhoisInfo,
WhoisInfo: whois,
}

cj.Source = "etc/hosts"
Expand Down
8 changes: 5 additions & 3 deletions internal/querylog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package querylog
// Client is the information required by the query log to match against clients
// during searches.
type Client struct {
Name string `json:"name"`
Whois *ClientWhois `json:"whois,omitempty"`
IDs []string `json:"ids"`
Name string `json:"name"`
DisallowedRule string `json:"disallowed_rule"`
Whois *ClientWhois `json:"whois,omitempty"`
IDs []string `json:"ids"`
Disallowed bool `json:"disallowed"`
}

// ClientWhois is the filtered WHOIS data for the client.
Expand Down
23 changes: 17 additions & 6 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1882,19 +1882,30 @@
'description': >
Client information for a query log item.
'properties':
'ids':
'description': >
IP, CIDR, MAC, or client ID.
'items':
'type': 'string'
'type': 'array'
'name':
'description': >
Persistent client's name or an empty string if this is a runtime
client.
'type': 'string'
'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'
'description': >
Whether the client's IP is blocked or not.
'required':
- 'ids'
- 'name'
Expand Down

0 comments on commit aa1769f

Please sign in to comment.