+ GET /control/clients/find: add "disallowed" property
This commit is contained in:
@@ -80,6 +80,8 @@ type clientsContainer struct {
|
||||
// dhcpServer is used for looking up clients IP addresses by MAC addresses
|
||||
dhcpServer *dhcpd.Server
|
||||
|
||||
DNSServer *dnsforward.Server
|
||||
|
||||
autoHosts *util.AutoHosts // get entries from system hosts-files
|
||||
|
||||
testing bool // if TRUE, this object is used for internal tests
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ func initDNSServer() error {
|
||||
p.DHCPServer = Context.dhcpServer
|
||||
}
|
||||
Context.dnsServer = dnsforward.NewServer(p)
|
||||
Context.clients.DNSServer = Context.dnsServer
|
||||
dnsConfig := generateServerConfig()
|
||||
err = Context.dnsServer.Prepare(&dnsConfig)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user