+ dns: use per-client filtering settings

This commit is contained in:
Simon Zolin 2019-04-26 16:07:12 +03:00
parent 8f7aff93d7
commit 3f89335ed2
1 changed files with 23 additions and 0 deletions

23
dns.go
View File

@ -70,9 +70,32 @@ func generateServerConfig() dnsforward.ServerConfig {
newconfig.Upstreams = upstreamConfig.Upstreams newconfig.Upstreams = upstreamConfig.Upstreams
newconfig.DomainsReservedUpstreams = upstreamConfig.DomainReservedUpstreams newconfig.DomainsReservedUpstreams = upstreamConfig.DomainReservedUpstreams
newconfig.AllServers = config.DNS.AllServers newconfig.AllServers = config.DNS.AllServers
newconfig.FilterHandler = applyClientSettings
return newconfig return newconfig
} }
// If a client has his own settings, apply them
func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) {
c, ok := clientFind(clientAddr)
if !ok || !c.UseOwnSettings {
return
}
log.Debug("Using settings for client with IP %s", clientAddr)
if !c.FilteringEnabled {
setts.FilteringEnabled = false
}
if !c.SafeSearchEnabled {
setts.SafeSearchEnabled = false
}
if !c.SafeBrowsingEnabled {
setts.SafeBrowsingEnabled = false
}
if !c.ParentalEnabled {
setts.ParentalEnabled = false
}
}
func startDNSServer() error { func startDNSServer() error {
if isRunning() { if isRunning() {
return fmt.Errorf("unable to start forwarding DNS server: Already running") return fmt.Errorf("unable to start forwarding DNS server: Already running")