+ GET /control/clients/find: add "disallowed" property
This commit is contained in:
@@ -21,6 +21,13 @@ type clientJSON struct {
|
||||
BlockedServices []string `json:"blocked_services"`
|
||||
|
||||
Upstreams []string `json:"upstreams"`
|
||||
|
||||
WhoisInfo map[string]interface{} `json:"whois_info"`
|
||||
|
||||
// * "": IP is allowed
|
||||
// * not "", e.g. "127.0.0.0/24" - IP is disallowed by "disallowed IP list", and the string contains the matched rule (IP or CIDR)
|
||||
// * "not-in-allowed-list" - IP is disallowed by "allowed IP list"
|
||||
Disallowed string `json:"disallowed"`
|
||||
}
|
||||
|
||||
type clientHostJSON struct {
|
||||
@@ -123,15 +130,9 @@ func clientToJSON(c *Client) clientJSON {
|
||||
return cj
|
||||
}
|
||||
|
||||
type clientHostJSONWithID struct {
|
||||
IDs []string `json:"ids"`
|
||||
Name string `json:"name"`
|
||||
WhoisInfo map[string]interface{} `json:"whois_info"`
|
||||
}
|
||||
|
||||
// Convert ClientHost object to JSON
|
||||
func clientHostToJSON(ip string, ch ClientHost) clientHostJSONWithID {
|
||||
cj := clientHostJSONWithID{
|
||||
func clientHostToJSON(ip string, ch ClientHost) clientJSON {
|
||||
cj := clientJSON{
|
||||
Name: ch.Host,
|
||||
IDs: []string{ip},
|
||||
}
|
||||
@@ -255,9 +256,21 @@ func (clients *clientsContainer) handleFindClient(w http.ResponseWriter, r *http
|
||||
continue // a client with this IP isn't found
|
||||
}
|
||||
cj := clientHostToJSON(ip, ch)
|
||||
|
||||
disallowed, disallowedRule := clients.DNSServer.IsBlockedIP(ip)
|
||||
if disallowed {
|
||||
cj.Disallowed = disallowedRule
|
||||
}
|
||||
|
||||
el[ip] = cj
|
||||
} else {
|
||||
cj := clientToJSON(&c)
|
||||
|
||||
disallowed, disallowedRule := clients.DNSServer.IsBlockedIP(ip)
|
||||
if disallowed {
|
||||
cj.Disallowed = disallowedRule
|
||||
}
|
||||
|
||||
el[ip] = cj
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user