docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
sequencelengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
for dataKey, dataValue := range statsData { d[dataKey] = dataValue
<mask> } <mask> a2 = convertMapToArray(m, maxDomains) <mask> d["top_blocked_domains"] = convertTopArray(a2) <mask> <mask> m = map[string]uint64{} <mask> for _, u := range units { <mask> for _, it := range u.Clients { <mask> m[it.Name] += it.Count <mask> } <mask> } <mask> a2 = convertMapToArray(m, maxClients) <mask> d["top_clients"] = convertTopArray(a2) <mask> <mask> // total counters: </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove a2 = convertMapToArray(m, maxDomains) d["top_blocked_domains"] = convertTopArray(a2) </s> add </s> remove a2 = convertMapToArray(m, maxClients) d["top_clients"] = convertTopArray(a2) </s> add </s> remove a2 := convertMapToArray(m, maxDomains) d["top_queried_domains"] = convertTopArray(a2) </s> add </s> remove m := map[string]uint64{} for _, u := range units { for _, it := range u.Domains { m[it.Name] += it.Count } </s> add dnsQueries := statsCollector(func(u *unitDB) (num uint64) { return u.NTotal }) if timeUnit != Hours && len(dnsQueries) != int(limit/24) { log.Fatalf("len(dnsQueries) != limit: %d %d", len(dnsQueries), limit) </s> remove m = map[string]uint64{} for _, u := range units { for _, it := range u.BlockedDomains { m[it.Name] += it.Count } </s> add statsData := map[string]interface{}{ "dns_queries": dnsQueries, "blocked_filtering": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RFiltered] }), "replaced_safebrowsing": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RSafeBrowsing] }), "replaced_parental": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RParental] }), "top_queried_domains": topsCollector(maxDomains, func(u *unitDB) (pairs []countPair) { return u.Domains }), "top_blocked_domains": topsCollector(maxDomains, func(u *unitDB) (pairs []countPair) { return u.BlockedDomains }), "top_clients": topsCollector(maxClients, func(u *unitDB) (pairs []countPair) { return u.Clients }),
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/stats/stats_unit.go
<mask> for _, it := range u.Clients { <mask> m[it.Name] += it.Count <mask> } <mask> } <mask> a2 = convertMapToArray(m, maxClients) <mask> d["top_clients"] = convertTopArray(a2) <mask> <mask> // total counters: <mask> <mask> sum := unitDB{} <mask> sum.NResult = make([]uint64, rLast) </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove m = map[string]uint64{} for _, u := range units { for _, it := range u.Clients { m[it.Name] += it.Count } </s> add for dataKey, dataValue := range statsData { d[dataKey] = dataValue </s> remove a2 = convertMapToArray(m, maxDomains) d["top_blocked_domains"] = convertTopArray(a2) </s> add </s> remove a2 := convertMapToArray(m, maxDomains) d["top_queried_domains"] = convertTopArray(a2) </s> add </s> remove m := map[string]uint64{} for _, u := range units { for _, it := range u.Domains { m[it.Name] += it.Count } </s> add dnsQueries := statsCollector(func(u *unitDB) (num uint64) { return u.NTotal }) if timeUnit != Hours && len(dnsQueries) != int(limit/24) { log.Fatalf("len(dnsQueries) != limit: %d %d", len(dnsQueries), limit) </s> remove m = map[string]uint64{} for _, u := range units { for _, it := range u.BlockedDomains { m[it.Name] += it.Count } </s> add statsData := map[string]interface{}{ "dns_queries": dnsQueries, "blocked_filtering": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RFiltered] }), "replaced_safebrowsing": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RSafeBrowsing] }), "replaced_parental": statsCollector(func(u *unitDB) (num uint64) { return u.NResult[RParental] }), "top_queried_domains": topsCollector(maxDomains, func(u *unitDB) (pairs []countPair) { return u.Domains }), "top_blocked_domains": topsCollector(maxDomains, func(u *unitDB) (pairs []countPair) { return u.BlockedDomains }), "top_clients": topsCollector(maxClients, func(u *unitDB) (pairs []countPair) { return u.Clients }),
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/stats/stats_unit.go
// timecnt uint64
<mask> fseeker fileSeeker // file seeker object <mask> fpos uint64 // current file offset <mask> nSeekRequests uint32 // number of Seek() requests made (finding a new line doesn't count) <mask> <mask> timecnt uint64 <mask> } <mask> <mask> type fileSeeker struct { <mask> target uint64 // target value <mask> </s> - querylog: remove time counter (fix zero div exception) </s> remove log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, r.timecnt*100/uint64(elapsed.Nanoseconds())) </s> add log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", r.count, elapsed, perunit, r.nSeekRequests) // timePercent := uint64(0) // if elapsed.Nanoseconds() != 0 { // timePercent = r.timecnt * 100 / uint64(elapsed.Nanoseconds()) // } // log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", // r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, timePercent) </s> remove st := time.Now() </s> add // st := time.Now() </s> remove r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) </s> add // r.timecnt += uint64(time.Now().Sub(st).Nanoseconds())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/305df63054852e760cce16d7ede38a01ef88be3f
querylog/querylog_file.go
log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", r.count, elapsed, perunit, r.nSeekRequests) // timePercent := uint64(0) // if elapsed.Nanoseconds() != 0 { // timePercent = r.timecnt * 100 / uint64(elapsed.Nanoseconds()) // } // log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", // r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, timePercent)
<mask> var perunit time.Duration <mask> if r.count > 0 { <mask> perunit = elapsed / time.Duration(r.count) <mask> } <mask> log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", <mask> r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, r.timecnt*100/uint64(elapsed.Nanoseconds())) <mask> <mask> if r.f != nil { <mask> r.f.Close() <mask> } <mask> } </s> - querylog: remove time counter (fix zero div exception) </s> remove st := time.Now() </s> add // st := time.Now() </s> remove r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) </s> add // r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) </s> remove timecnt uint64 </s> add // timecnt uint64
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/305df63054852e760cce16d7ede38a01ef88be3f
querylog/querylog_file.go
// st := time.Now()
<mask> if !r.applySearch(str) { <mask> continue <mask> } <mask> <mask> st := time.Now() <mask> var ent logEntry <mask> decode(&ent, str) <mask> r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) <mask> <mask> return &ent </s> - querylog: remove time counter (fix zero div exception) </s> remove r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) </s> add // r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) </s> remove log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, r.timecnt*100/uint64(elapsed.Nanoseconds())) </s> add log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", r.count, elapsed, perunit, r.nSeekRequests) // timePercent := uint64(0) // if elapsed.Nanoseconds() != 0 { // timePercent = r.timecnt * 100 / uint64(elapsed.Nanoseconds()) // } // log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", // r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, timePercent) </s> remove timecnt uint64 </s> add // timecnt uint64
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/305df63054852e760cce16d7ede38a01ef88be3f
querylog/querylog_file.go
// r.timecnt += uint64(time.Now().Sub(st).Nanoseconds())
<mask> <mask> st := time.Now() <mask> var ent logEntry <mask> decode(&ent, str) <mask> r.timecnt += uint64(time.Now().Sub(st).Nanoseconds()) <mask> <mask> return &ent <mask> } <mask> } <mask> </s> - querylog: remove time counter (fix zero div exception) </s> remove st := time.Now() </s> add // st := time.Now() </s> remove log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, r.timecnt*100/uint64(elapsed.Nanoseconds())) </s> add log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", r.count, elapsed, perunit, r.nSeekRequests) // timePercent := uint64(0) // if elapsed.Nanoseconds() != 0 { // timePercent = r.timecnt * 100 / uint64(elapsed.Nanoseconds()) // } // log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", // r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, timePercent) </s> remove timecnt uint64 </s> add // timecnt uint64
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/305df63054852e760cce16d7ede38a01ef88be3f
querylog/querylog_file.go
<mask> EnableEDNSClientSubnet: s.conf.EnableEDNSClientSubnet, <mask> MaxGoroutines: int(s.conf.MaxGoroutines), <mask> } <mask> <mask> if s.conf.QUICListenAddr != nil { <mask> proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} <mask> } <mask> <mask> if s.conf.CacheSize != 0 { <mask> proxyConfig.CacheEnabled = true <mask> proxyConfig.CacheSizeBytes = int(s.conf.CacheSize) <mask> } <mask> </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { </s> add if len(s.conf.CertificateChainData) == 0 || len(s.conf.PrivateKeyData) == 0 { return nil } if s.conf.TLSListenAddr == nil && s.conf.QUICListenAddr == nil { return nil } if s.conf.TLSListenAddr != nil { </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
if len(s.conf.CertificateChainData) == 0 || len(s.conf.PrivateKeyData) == 0 { return nil } if s.conf.TLSListenAddr == nil && s.conf.QUICListenAddr == nil { return nil } if s.conf.TLSListenAddr != nil {
<mask> } <mask> <mask> // prepareTLS - prepares TLS configuration for the DNS proxy <mask> func (s *Server) prepareTLS(proxyConfig *proxy.Config) error { <mask> if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { <mask> proxyConfig.TLSListenAddr = []*net.TCPAddr{s.conf.TLSListenAddr} <mask> var err error <mask> s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) <mask> if err != nil { <mask> return errorx.Decorate(err, "Failed to parse TLS keypair") </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove return errorx.Decorate(err, "Failed to parse TLS keypair") </s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
} if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0])
<mask> // prepareTLS - prepares TLS configuration for the DNS proxy <mask> func (s *Server) prepareTLS(proxyConfig *proxy.Config) error { <mask> if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { <mask> proxyConfig.TLSListenAddr = []*net.TCPAddr{s.conf.TLSListenAddr} <mask> var err error <mask> s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) <mask> if err != nil { <mask> return errorx.Decorate(err, "Failed to parse TLS keypair") <mask> } <mask> <mask> if s.conf.StrictSNICheck { </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { </s> add if len(s.conf.CertificateChainData) == 0 || len(s.conf.PrivateKeyData) == 0 { return nil } if s.conf.TLSListenAddr == nil && s.conf.QUICListenAddr == nil { return nil } if s.conf.TLSListenAddr != nil { </s> remove return errorx.Decorate(err, "Failed to parse TLS keypair") </s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
return errorx.Decorate(err, "x509.ParseCertificate(): %s", err)
<mask> proxyConfig.TLSListenAddr = []*net.TCPAddr{s.conf.TLSListenAddr} <mask> var err error <mask> s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) <mask> if err != nil { <mask> return errorx.Decorate(err, "Failed to parse TLS keypair") <mask> } <mask> <mask> if s.conf.StrictSNICheck { <mask> x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) <mask> if err != nil { </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { </s> add if len(s.conf.CertificateChainData) == 0 || len(s.conf.PrivateKeyData) == 0 { return nil } if s.conf.TLSListenAddr == nil && s.conf.QUICListenAddr == nil { return nil } if s.conf.TLSListenAddr != nil { </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName)
<mask> s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) <mask> if err != nil { <mask> return errorx.Decorate(err, "Failed to parse TLS keypair") <mask> } <mask> <mask> if s.conf.StrictSNICheck { <mask> x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) <mask> if err != nil { <mask> return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) <mask> } <mask> if len(x.DNSNames) != 0 { <mask> s.conf.dnsNames = x.DNSNames <mask> log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) <mask> sort.Strings(s.conf.dnsNames) <mask> } else { <mask> s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) <mask> log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) <mask> } <mask> } <mask> <mask> proxyConfig.TLSConfig = &tls.Config{ <mask> GetCertificate: s.onGetCertificate, <mask> MinVersion: tls.VersionTLS12, </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, </s> remove return errorx.Decorate(err, "Failed to parse TLS keypair") </s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove if s.conf.TLSListenAddr != nil && len(s.conf.CertificateChainData) != 0 && len(s.conf.PrivateKeyData) != 0 { </s> add if len(s.conf.CertificateChainData) == 0 || len(s.conf.PrivateKeyData) == 0 { return nil } if s.conf.TLSListenAddr == nil && s.conf.QUICListenAddr == nil { return nil } if s.conf.TLSListenAddr != nil {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
}
<mask> } else { <mask> s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) <mask> log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) <mask> } <mask> <mask> proxyConfig.TLSConfig = &tls.Config{ <mask> GetCertificate: s.onGetCertificate, <mask> MinVersion: tls.VersionTLS12, <mask> } <mask> </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, </s> remove if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } </s> add </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove return errorx.Decorate(err, "Failed to parse TLS keypair") </s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12,
<mask> log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) <mask> } <mask> } <mask> <mask> proxyConfig.TLSConfig = &tls.Config{ <mask> GetCertificate: s.onGetCertificate, <mask> MinVersion: tls.VersionTLS12, <mask> } <mask> } <mask> upstream.RootCAs = s.conf.TLSv12Roots <mask> upstream.CipherSuites = s.conf.TLSCiphers <mask> return nil <mask> } </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) </s> remove if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } </s> add </s> remove var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) </s> add } if s.conf.QUICListenAddr != nil { proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr} } var err error s.conf.cert, err = tls.X509KeyPair(s.conf.CertificateChainData, s.conf.PrivateKeyData) if err != nil { return errorx.Decorate(err, "Failed to parse TLS keypair") } if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) </s> remove return errorx.Decorate(err, "Failed to parse TLS keypair") </s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/config.go
"fmt"
<mask> "crypto/x509" <mask> "crypto/x509/pkix" <mask> "encoding/pem" <mask> "math/big" <mask> "net" <mask> "sort" <mask> "sync" </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
dnsforward/dnsforward_test.go
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
<mask> golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= <mask> golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= <mask> golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= <mask> golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= <mask> golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= <mask> golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= <mask> golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= <mask> golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= <mask> golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= <mask> golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
go.sum
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
<mask> gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= <mask> gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= <mask> gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= <mask> gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= <mask> gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= <mask> gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= <mask> gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= <mask> gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= </s> - (dnsforward): fixed running only quic, added a test QUIC was not initialized if DOT port is not set. Also, there were no tests on DoQ functionality. </s> remove proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, } </s> add proxyConfig.TLSConfig = &tls.Config{ GetCertificate: s.onGetCertificate, MinVersion: tls.VersionTLS12, </s> remove if s.conf.StrictSNICheck { x, err := x509.ParseCertificate(s.conf.cert.Certificate[0]) if err != nil { return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) } if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName) } </s> add if len(x.DNSNames) != 0 { s.conf.dnsNames = x.DNSNames log.Debug("DNS: using DNS names from certificate's SAN: %v", x.DNSNames) sort.Strings(s.conf.dnsNames) } else { s.conf.dnsNames = append(s.conf.dnsNames, x.Subject.CommonName) log.Debug("DNS: using DNS name from certificate's CN: %s", x.Subject.CommonName)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb
go.sum
<symbol id="service_qq" viewBox="0 0 32 32" > <g fill="none" fillRule="evenodd"> <path d="M0 0h32v32H0z" /> <g fill="currentColor" fillRule="nonzero"> <path d="M11.25 32C8.342 32 6 30.74 6 29.242c0-1.497 2.342-2.757 5.25-2.757s5.25 1.26 5.25 2.757S14.158 32 11.25 32zM27 29.242c0-1.497-2.342-2.757-5.25-2.757s-5.25 1.26-5.25 2.757S18.842 32 21.75 32 27 30.74 27 29.242zM14.885 7.182c0 .63-.323 1.182-.808 1.182-.485 0-.808-.552-.808-1.182 0-.63.323-1.182.808-1.182.485 0 .808.552.808 1.182zM18.923 6c-.485 0-.808.552-.808 1.182 0 .63.323-.394.808-.394.485 0 .808 1.024.808.394S19.408 6 18.923 6z" /> <path d="M6.653 12.638s4.685 2.465 9.926 2.465c5.242 0 9.927-2.465 9.927-2.465.112-.09.217-.161.316-.212-.002-1.088-.078-2.026-.078-2.808C26.744 4.292 22.138 0 16.5 0S6.176 4.292 6.176 9.618v2.78c.146.042.3.113.477.24zm12.626-8.664c1.112 0 1.986 1.272 1.986 2.782s-.874 2.782-1.986 2.782c-1.111 0-1.985-1.271-1.985-2.782 0-1.51.874-2.782 1.985-2.782zm-5.558 0c1.111 0 1.985 1.272 1.985 2.782s-.874 2.782-1.985 2.782c-1.112 0-1.986-1.271-1.986-2.782 0-1.51.874-2.782 1.986-2.782zm2.779 6.624c2.912 0 5.294.464 5.294.994s-2.382 1.656-5.294 1.656c-2.912 0-5.294-1.126-5.294-1.656s2.382-.994 5.294-.994zm11.374 5.182c-.058.038-.108.076-.177.117-.159.08-5.241 3.18-11.038 3.18-1.43 0-2.7-.239-3.97-.477-.239 1.67-.239 3.259-.239 3.974 0 1.272-1.032 1.193-2.303 1.272-1.27 0-2.223.16-2.303-1.033 0-.16-.08-2.782.397-5.564-1.588-.716-2.62-1.272-2.7-1.352a3.293 3.293 0 01-.335-.216C4.012 17.55 3 19.598 3 21.223c0 3.815 1.112 3.418 1.112 3.418.476 0 1.27-.795 1.985-1.67C7.765 27.662 11.735 31 16.5 31c4.765 0 8.735-3.338 10.403-8.028.715.874 1.509 1.669 1.985 1.669 0 0 1.112.397 1.112-3.418 0-1.588-.968-3.631-2.126-5.443z" /> </g> </g> </symbol>
<mask> </symbol> <mask> <mask> <symbol id="question" width="20px" height="20px"> <mask> <g transform="translate(-982.000000, -454.000000) translate(416.000000, 440.000000) translate(564.000000, 12.000000)" <mask> fill="none" fillRule="evenodd"> <mask> <circle stroke="currentColor" strokeWidth="1.5" cx="12" cy="12" r="9.25" /> </s> + dnsfilter, client: Add qq to blocked services Squashed commit of the following: commit ffb2a1065fc9edd2b840cccbb96a0a2c1334bf00 Merge: 0f966d5b 3acfaa16 Author: ArtemBaskal <[email protected]> Date: Tue Oct 20 11:19:39 2020 +0300 Merge branch 'master' into dnsfilter/update_blocked_services commit 0f966d5b00f96c93bf778e944d68f62ebcdeaa50 Author: ArtemBaskal <[email protected]> Date: Mon Oct 19 20:47:22 2020 +0300 Add qq icon to blocked services commit f9c42551bbb442f83c6354314fc42ea174aacf4b Author: ifurther <[email protected]> Date: Sun Jun 7 12:19:05 2020 +0000 Add qq to blocked services
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3
client/src/components/ui/Icons.js
{ id: 'qq', name: 'QQ', },
<mask> id: 'tiktok', <mask> name: 'TikTok', <mask> }, <mask> ]; <mask> <mask> export const SERVICES_ID_NAME_MAP = SERVICES.reduce((acc, { id, name }) => { <mask> acc[id] = name; <mask> return acc; <mask> }, {}); </s> + dnsfilter, client: Add qq to blocked services Squashed commit of the following: commit ffb2a1065fc9edd2b840cccbb96a0a2c1334bf00 Merge: 0f966d5b 3acfaa16 Author: ArtemBaskal <[email protected]> Date: Tue Oct 20 11:19:39 2020 +0300 Merge branch 'master' into dnsfilter/update_blocked_services commit 0f966d5b00f96c93bf778e944d68f62ebcdeaa50 Author: ArtemBaskal <[email protected]> Date: Mon Oct 19 20:47:22 2020 +0300 Add qq icon to blocked services commit f9c42551bbb442f83c6354314fc42ea174aacf4b Author: ifurther <[email protected]> Date: Sun Jun 7 12:19:05 2020 +0000 Add qq to blocked services
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3
client/src/helpers/constants.js
{"qq", []string{"||qq.com^", "||qqzaixian.com^"}},
<mask> "||tiktokv.com^", <mask> }}, <mask> } <mask> <mask> // convert array to map <mask> func initBlockedServices() { </s> + dnsfilter, client: Add qq to blocked services Squashed commit of the following: commit ffb2a1065fc9edd2b840cccbb96a0a2c1334bf00 Merge: 0f966d5b 3acfaa16 Author: ArtemBaskal <[email protected]> Date: Tue Oct 20 11:19:39 2020 +0300 Merge branch 'master' into dnsfilter/update_blocked_services commit 0f966d5b00f96c93bf778e944d68f62ebcdeaa50 Author: ArtemBaskal <[email protected]> Date: Mon Oct 19 20:47:22 2020 +0300 Add qq icon to blocked services commit f9c42551bbb442f83c6354314fc42ea174aacf4b Author: ifurther <[email protected]> Date: Sun Jun 7 12:19:05 2020 +0000 Add qq to blocked services
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3
dnsfilter/blocked_services.go
QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats
<mask> <mask> // time interval for statistics (in days) <mask> StatsInterval uint32 `yaml:"statistics_interval"` <mask> <mask> QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled <mask> QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) <mask> QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk <mask> AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats <mask> <mask> dnsforward.FilteringConfig `yaml:",inline"` <mask> <mask> FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists <mask> FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled bool </s> add Enabled bool // enable the module FileEnabled bool // write logs to file </s> remove // DiskConfig - configuration settings that are stored on disk type DiskConfig struct { Enabled bool Interval uint32 MemSize uint32 AnonymizeClientIP bool } </s> add </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }() </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove WriteDiskConfig(dc *DiskConfig) </s> add WriteDiskConfig(c *Config)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
home/config.go
config.DNS.QueryLogFileEnabled = true
<mask> func initConfig() { <mask> config.WebSessionTTLHours = 30 * 24 <mask> <mask> config.DNS.QueryLogEnabled = true <mask> config.DNS.QueryLogInterval = 90 <mask> config.DNS.QueryLogMemSize = 1000 <mask> <mask> config.DNS.CacheSize = 4 * 1024 * 1024 <mask> config.DNS.DnsfilterConf.SafeBrowsingCacheSize = 1 * 1024 * 1024 </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove dc := querylog.DiskConfig{} </s> add dc := querylog.Config{} </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
home/config.go
dc := querylog.Config{}
<mask> config.DNS.StatsInterval = sdc.Interval <mask> } <mask> <mask> if Context.queryLog != nil { <mask> dc := querylog.DiskConfig{} <mask> Context.queryLog.WriteDiskConfig(&dc) <mask> config.DNS.QueryLogEnabled = dc.Enabled <mask> config.DNS.QueryLogInterval = dc.Interval <mask> config.DNS.QueryLogMemSize = dc.MemSize <mask> config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
home/config.go
config.DNS.QueryLogFileEnabled = dc.FileEnabled
<mask> dc := querylog.Config{} <mask> Context.queryLog.WriteDiskConfig(&dc) <mask> config.DNS.QueryLogEnabled = dc.Enabled <mask> config.DNS.QueryLogInterval = dc.Interval <mask> config.DNS.QueryLogMemSize = dc.MemSize <mask> config.DNS.AnonymizeClientIP = dc.AnonymizeClientIP <mask> } </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove dc := querylog.DiskConfig{} </s> add dc := querylog.Config{} </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
home/config.go
FileEnabled: config.DNS.QueryLogFileEnabled,
<mask> } <mask> conf := querylog.Config{ <mask> Enabled: config.DNS.QueryLogEnabled, <mask> BaseDir: baseDir, <mask> Interval: config.DNS.QueryLogInterval, <mask> MemSize: config.DNS.QueryLogMemSize, <mask> AnonymizeClientIP: config.DNS.AnonymizeClientIP, <mask> ConfigModified: onConfigModified, </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove dc := querylog.DiskConfig{} </s> add dc := querylog.Config{}
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
home/dns.go
func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf
<mask> func checkInterval(days uint32) bool { <mask> return days == 1 || days == 7 || days == 30 || days == 90 <mask> } <mask> <mask> func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { <mask> dc.Enabled = l.conf.Enabled <mask> dc.Interval = l.conf.Interval <mask> dc.MemSize = l.conf.MemSize <mask> dc.AnonymizeClientIP = l.conf.AnonymizeClientIP <mask> } <mask> <mask> // Clear memory buffer and remove log files <mask> func (l *queryLog) clear() { <mask> l.fileFlushLock.Lock() </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove dc := querylog.DiskConfig{} </s> add dc := querylog.Config{} </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/qlog.go
if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending {
<mask> <mask> l.bufferLock.Lock() <mask> l.buffer = append(l.buffer, &entry) <mask> needFlush := false <mask> if !l.flushPending { <mask> needFlush = len(l.buffer) >= int(l.conf.MemSize) <mask> if needFlush { <mask> l.flushPending = true <mask> } <mask> } </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }() </s> remove dc := querylog.DiskConfig{} </s> add dc := querylog.Config{} </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/qlog.go
go func() { _ = l.flushLogBuffer(false) }()
<mask> l.bufferLock.Unlock() <mask> <mask> // if buffer needs to be flushed to disk, do it now <mask> if needFlush { <mask> // write to file <mask> // do it in separate goroutine -- we are stalling DNS response this whole time <mask> go l.flushLogBuffer(false) // nolint <mask> } <mask> } </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> add QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> remove Enabled bool </s> add Enabled bool // enable the module FileEnabled bool // write logs to file </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove WriteDiskConfig(dc *DiskConfig) </s> add WriteDiskConfig(c *Config)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/qlog.go
Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
<mask> <mask> // Check adding and loading (with filtering) entries from disk and memory <mask> func TestQueryLog(t *testing.T) { <mask> conf := Config{ <mask> Enabled: true, <mask> Interval: 1, <mask> MemSize: 100, <mask> } <mask> conf.BaseDir = prepareTestDir() <mask> defer func() { _ = os.RemoveAll(conf.BaseDir) }() <mask> l := newQueryLog(conf) <mask> </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }() </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/qlog_test.go
Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
<mask> } <mask> <mask> func TestQueryLogMaxFileScanEntries(t *testing.T) { <mask> conf := Config{ <mask> Enabled: true, <mask> Interval: 1, <mask> MemSize: 100, <mask> } <mask> conf.BaseDir = prepareTestDir() <mask> defer func() { _ = os.RemoveAll(conf.BaseDir) }() <mask> l := newQueryLog(conf) <mask> </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100, </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }() </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/qlog_test.go
<mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> // DiskConfig - configuration settings that are stored on disk <mask> type DiskConfig struct { <mask> Enabled bool <mask> Interval uint32 <mask> MemSize uint32 <mask> AnonymizeClientIP bool <mask> } <mask> <mask> // QueryLog - main interface <mask> type QueryLog interface { <mask> Start() <mask> <mask> // Close query log object </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled bool </s> add Enabled bool // enable the module FileEnabled bool // write logs to file </s> remove WriteDiskConfig(dc *DiskConfig) </s> add WriteDiskConfig(c *Config) </s> remove QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> add QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/querylog.go
WriteDiskConfig(c *Config)
<mask> // Add a log entry <mask> Add(params AddParams) <mask> <mask> // WriteDiskConfig - write configuration <mask> WriteDiskConfig(dc *DiskConfig) <mask> } <mask> <mask> // Config - configuration object <mask> type Config struct { <mask> Enabled bool </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove Enabled bool </s> add Enabled bool // enable the module FileEnabled bool // write logs to file </s> remove // DiskConfig - configuration settings that are stored on disk type DiskConfig struct { Enabled bool Interval uint32 MemSize uint32 AnonymizeClientIP bool } </s> add </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> add QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/querylog.go
Enabled bool // enable the module FileEnabled bool // write logs to file
<mask> } <mask> <mask> // Config - configuration object <mask> type Config struct { <mask> Enabled bool <mask> BaseDir string // directory where log file is stored <mask> Interval uint32 // interval to rotate logs (in days) <mask> MemSize uint32 // number of entries kept in memory before they are flushed to disk <mask> AnonymizeClientIP bool // anonymize clients' IP addresses <mask> </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> add QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled QueryLogFileEnabled bool `yaml:"querylog_file_enabled"` // if true, query log will be written to a file QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) QueryLogMemSize uint32 `yaml:"querylog_size_memory"` // number of entries kept in memory before they are flushed to disk AnonymizeClientIP bool `yaml:"anonymize_client_ip"` // anonymize clients' IP addresses in logs and stats </s> remove // DiskConfig - configuration settings that are stored on disk type DiskConfig struct { Enabled bool Interval uint32 MemSize uint32 AnonymizeClientIP bool } </s> add </s> remove WriteDiskConfig(dc *DiskConfig) </s> add WriteDiskConfig(c *Config) </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/querylog.go
if !l.conf.FileEnabled { return nil }
<mask> ) <mask> <mask> // flushLogBuffer flushes the current buffer to file and resets the current buffer <mask> func (l *queryLog) flushLogBuffer(fullFlush bool) error { <mask> l.fileFlushLock.Lock() <mask> defer l.fileFlushLock.Unlock() <mask> <mask> // flush remainder to file </s> + config: new setting "querylog_file_enabled" Close #876 Squashed commit of the following: commit f83f60a7340d8a3f6de7ecfebb426e47d19e83d8 Merge: cfb72869 391e6199 Author: Simon Zolin <[email protected]> Date: Thu May 28 15:17:21 2020 +0300 Merge remote-tracking branch 'origin/master' into 876-logs commit cfb72869f7cf0bf59a478ab8c7920c273e2fa5f9 Author: Simon Zolin <[email protected]> Date: Thu May 28 12:50:02 2020 +0300 tests commit 35376e4f450cf66507d733c931b7ed27eff1f36c Author: Simon Zolin <[email protected]> Date: Wed May 27 18:15:12 2020 +0300 fix commit 0cfb802d73db52a4b09c459a68a8a18918447b76 Author: Simon Zolin <[email protected]> Date: Wed May 27 16:49:52 2020 +0300 tests commit 03ca280b6aed3a4880a9d4f4cd18bf47b1c742f6 Author: Simon Zolin <[email protected]> Date: Wed May 27 15:32:27 2020 +0300 + config: new setting "querylog_file_enabled" - query log will be written to a file </s> remove func (l *queryLog) WriteDiskConfig(dc *DiskConfig) { dc.Enabled = l.conf.Enabled dc.Interval = l.conf.Interval dc.MemSize = l.conf.MemSize dc.AnonymizeClientIP = l.conf.AnonymizeClientIP </s> add func (l *queryLog) WriteDiskConfig(c *Config) { *c = *l.conf </s> remove // write to file // do it in separate goroutine -- we are stalling DNS response this whole time go l.flushLogBuffer(false) // nolint </s> add go func() { _ = l.flushLogBuffer(false) }() </s> remove Enabled bool </s> add Enabled bool // enable the module FileEnabled bool // write logs to file </s> remove if !l.flushPending { </s> add if !l.conf.FileEnabled { if len(l.buffer) > int(l.conf.MemSize) { // writing to file is disabled - just remove the oldest entry from array l.buffer = l.buffer[1:] } } else if !l.flushPending { </s> remove Enabled: true, Interval: 1, MemSize: 100, </s> add Enabled: true, FileEnabled: true, Interval: 1, MemSize: 100,
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451
querylog/querylog_file.go
/data/
<mask> /AdGuardHome <mask> /AdGuardHome.yaml <mask> /build/ <mask> /client/node_modules/ <mask> /coredns <mask> /Corefile <mask> /dnsfilter.txt <mask> /querylog.json </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) </s> add // fill the list of filters filters := make([]coreDnsFilter, 0) // first of all, append the user filter userFilter := getUserFilter() // TODO: Don't add if empty //if len(userFilter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) //} // then go through other filters for i := range config.Filters { filter := &config.Filters[i] if filter.Enabled && len(filter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: filter.ID, Path: filter.getFilterFilePath()}) } } temporaryConfig.Filters = filters </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err) </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext))
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
.gitignore
<mask> executable, err := os.Executable() <mask> if err != nil { <mask> panic(err) <mask> } <mask> config.ourBinaryDir = filepath.Dir(executable) <mask> } <mask> <mask> doConfigRename := true <mask> <mask> // config can be specified, which reads options from there, but other command line flags have to override config values <mask> // therefore, we must do it manually instead of using a lib </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove doConfigRename := true </s> add executableName := filepath.Base(executable) if executableName == "AdGuardHome" { // Binary build config.ourBinaryDir = filepath.Dir(executable) } else { // Most likely we're debugging -- using current working directory in this case workDir, _ := os.Getwd() config.ourBinaryDir = workDir } log.Printf("Current working directory is %s", config.ourBinaryDir) } </s> remove // config was manually specified, don't do anything doConfigRename = false </s> add </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion) </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
executableName := filepath.Base(executable) if executableName == "AdGuardHome" { // Binary build config.ourBinaryDir = filepath.Dir(executable) } else { // Most likely we're debugging -- using current working directory in this case workDir, _ := os.Getwd() config.ourBinaryDir = workDir } log.Printf("Current working directory is %s", config.ourBinaryDir) }
<mask> } <mask> config.ourBinaryDir = filepath.Dir(executable) <mask> } <mask> <mask> doConfigRename := true <mask> <mask> // config can be specified, which reads options from there, but other command line flags have to override config values <mask> // therefore, we must do it manually instead of using a lib <mask> { <mask> var configFilename *string </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove config.ourBinaryDir = filepath.Dir(executable) } </s> add </s> remove // config was manually specified, don't do anything doConfigRename = false </s> add </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion) </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
<mask> os.Exit(64) <mask> } <mask> } <mask> if configFilename != nil { <mask> // config was manually specified, don't do anything <mask> doConfigRename = false <mask> config.ourConfigFilename = *configFilename <mask> } <mask> <mask> if doConfigRename { <mask> err := renameOldConfigIfNeccessary() </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add </s> remove config.ourBinaryDir = filepath.Dir(executable) } </s> add </s> remove doConfigRename := true </s> add executableName := filepath.Base(executable) if executableName == "AdGuardHome" { // Binary build config.ourBinaryDir = filepath.Dir(executable) } else { // Most likely we're debugging -- using current working directory in this case workDir, _ := os.Getwd() config.ourBinaryDir = workDir } log.Printf("Current working directory is %s", config.ourBinaryDir) } </s> remove err := writeConfig() </s> add // Do the upgrade if necessary err := upgradeConfig() if err != nil { log.Fatal(err) } // Save the updated config err = writeConfig() </s> remove func renameOldConfigIfNeccessary() error { oldConfigFile := filepath.Join(config.ourBinaryDir, "AdguardDNS.yaml") _, err := os.Stat(oldConfigFile) if os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s doesn't exist, nothing to do", oldConfigFile) </s> add // Performs necessary upgrade operations if needed func upgradeConfig() error { if config.SchemaVersion == SchemaVersion { // No upgrade, do nothing
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
<mask> doConfigRename = false <mask> config.ourConfigFilename = *configFilename <mask> } <mask> <mask> if doConfigRename { <mask> err := renameOldConfigIfNeccessary() <mask> if err != nil { <mask> panic(err) <mask> } <mask> } <mask> <mask> err := askUsernamePasswordIfPossible() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove // config was manually specified, don't do anything doConfigRename = false </s> add </s> remove err := writeConfig() </s> add // Do the upgrade if necessary err := upgradeConfig() if err != nil { log.Fatal(err) } // Save the updated config err = writeConfig() </s> remove return err </s> add return nil </s> remove config.ourBinaryDir = filepath.Dir(executable) } </s> add </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
// Eat all args so that coredns can start happily
<mask> config.BindPort = *bindPort <mask> } <mask> } <mask> <mask> // eat all args so that coredns can start happily <mask> if len(os.Args) > 1 { <mask> os.Args = os.Args[:1] <mask> } <mask> <mask> err := writeConfig() </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err := writeConfig() </s> add // Do the upgrade if necessary err := upgradeConfig() if err != nil { log.Fatal(err) } // Save the updated config err = writeConfig() </s> remove args := c.RemainingArgs() if len(args) > 0 { filterFileNames = append(filterFileNames, args...) } </s> add </s> remove filterFileNames := []string{} </s> add log.Println("Initializing the CoreDNS plugin") </s> remove return err </s> add return nil </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
// Do the upgrade if necessary err := upgradeConfig() if err != nil { log.Fatal(err) } // Save the updated config err = writeConfig()
<mask> if len(os.Args) > 1 { <mask> os.Args = os.Args[:1] <mask> } <mask> <mask> err := writeConfig() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove // eat all args so that coredns can start happily </s> add // Eat all args so that coredns can start happily </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add </s> remove return err </s> add return nil </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
// Load filters from the disk for i := range config.Filters { filter := &config.Filters[i] err = filter.load() if err != nil { log.Printf("Couldn't load filter %d contents due to %s", filter.ID, err) } }
<mask> log.Fatal(err) <mask> } <mask> <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) <mask> <mask> runFilterRefreshers() <mask> <mask> http.Handle("/", optionalAuthHandler(http.FileServer(box))) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err := writeConfig() </s> add // Do the upgrade if necessary err := upgradeConfig() if err != nil { log.Fatal(err) } // Save the updated config err = writeConfig() </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add </s> remove log.Printf("filterFileNames = %+v", filterFileNames) </s> add for _, filter := range p.settings.Filters { log.Printf("Loading rules from %s", filter.Path)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
// Performs necessary upgrade operations if needed func upgradeConfig() error { if config.SchemaVersion == SchemaVersion { // No upgrade, do nothing
<mask> config.AuthPass = password <mask> return nil <mask> } <mask> <mask> func renameOldConfigIfNeccessary() error { <mask> oldConfigFile := filepath.Join(config.ourBinaryDir, "AdguardDNS.yaml") <mask> _, err := os.Stat(oldConfigFile) <mask> if os.IsNotExist(err) { <mask> // do nothing, file doesn't exist <mask> trace("File %s doesn't exist, nothing to do", oldConfigFile) <mask> return nil <mask> } <mask> <mask> newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) <mask> _, err = os.Stat(newConfigFile) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion) </s> remove config.RUnlock() err := ioutil.WriteFile(filterpath+".tmp", data, 0644) if err != nil { log.Printf("Couldn't write filter file: %s", err) </s> add filterFilePath := filter.getFilterFilePath() log.Printf("Loading filter %d contents to: %s", filter.ID, filterFilePath) if _, err := os.Stat(filterFilePath); os.IsNotExist(err) { // do nothing, file doesn't exist </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion)
<mask> trace("File %s doesn't exist, nothing to do", oldConfigFile) <mask> return nil <mask> } <mask> <mask> newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) <mask> _, err = os.Stat(newConfigFile) <mask> if !os.IsNotExist(err) { <mask> // do nothing, file doesn't exist <mask> trace("File %s already exists, will not overwrite", newConfigFile) <mask> return nil <mask> } <mask> <mask> err = os.Rename(oldConfigFile, newConfigFile) <mask> if err != nil { <mask> log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove func renameOldConfigIfNeccessary() error { oldConfigFile := filepath.Join(config.ourBinaryDir, "AdguardDNS.yaml") _, err := os.Stat(oldConfigFile) if os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s doesn't exist, nothing to do", oldConfigFile) </s> add // Performs necessary upgrade operations if needed func upgradeConfig() error { if config.SchemaVersion == SchemaVersion { // No upgrade, do nothing </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove config.RUnlock() err := ioutil.WriteFile(filterpath+".tmp", data, 0644) if err != nil { log.Printf("Couldn't write filter file: %s", err) </s> add filterFilePath := filter.getFilterFilePath() log.Printf("Loading filter %d contents to: %s", filter.ID, filterFilePath) if _, err := os.Stat(filterFilePath); os.IsNotExist(err) { // do nothing, file doesn't exist </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
// Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } }
<mask> trace("File %s already exists, will not overwrite", newConfigFile) <mask> return nil <mask> } <mask> <mask> err = os.Rename(oldConfigFile, newConfigFile) <mask> if err != nil { <mask> log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) <mask> return err <mask> } <mask> <mask> return nil <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion) </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add </s> remove log.Printf("Couldn't rename filter file: %s", err) </s> add </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove return err </s> add return nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
app.go
"gopkg.in/yaml.v2"
<mask> <mask> import ( <mask> "bytes" <mask> "io/ioutil" <mask> "log" <mask> "os" <mask> "path/filepath" <mask> "regexp" </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove "gopkg.in/yaml.v2" </s> add </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
<mask> "regexp" <mask> "sync" <mask> "text/template" <mask> "time" <mask> <mask> "gopkg.in/yaml.v2" <mask> ) <mask> <mask> // configuration is loaded from YAML <mask> type configuration struct { <mask> ourConfigFilename string </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
// Current schema version. We compare it with the value from // the configuration file and perform necessary upgrade operations if needed const SchemaVersion = 1 // Directory where we'll store all downloaded filters contents const FiltersDir = "filters"
<mask> "text/template" <mask> "time" <mask> ) <mask> <mask> // configuration is loaded from YAML <mask> type configuration struct { <mask> ourConfigFilename string <mask> ourBinaryDir string <mask> // Directory to store data (i.e. filters contents) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove "gopkg.in/yaml.v2" </s> add </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
// Directory to store data (i.e. filters contents) ourDataDir string
<mask> // configuration is loaded from YAML <mask> type configuration struct { <mask> ourConfigFilename string <mask> ourBinaryDir string <mask> <mask> // Schema version of the config file. This value is used when performing the app updates. <mask> SchemaVersion int `yaml:"schema_version"` <mask> BindHost string `yaml:"bind_host"` <mask> BindPort int `yaml:"bind_port"` </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> remove "gopkg.in/yaml.v2" </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
// Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
<mask> type configuration struct { <mask> ourConfigFilename string <mask> ourBinaryDir string <mask> <mask> BindHost string `yaml:"bind_host"` <mask> BindPort int `yaml:"bind_port"` <mask> AuthName string `yaml:"auth_name"` <mask> AuthPass string `yaml:"auth_pass"` <mask> CoreDNS coreDNSConfig `yaml:"coredns"` <mask> Filters []filter `yaml:"filters"` <mask> UserRules []string `yaml:"user_rules"` <mask> <mask> sync.RWMutex `yaml:"-"` <mask> } <mask> <mask> type coreDNSConfig struct { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove FilterFile string `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> add Filters []coreDnsFilter `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> remove "gopkg.in/yaml.v2" </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
type coreDnsFilter struct { ID int `yaml:"-"` Path string `yaml:"-"` }
<mask> <mask> sync.RWMutex `yaml:"-"` <mask> } <mask> <mask> type coreDNSConfig struct { <mask> binaryFile string <mask> coreFile string <mask> Filters []coreDnsFilter `yaml:"-"` <mask> Port int `yaml:"port"` <mask> ProtectionEnabled bool `yaml:"protection_enabled"` </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove FilterFile string `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> add Filters []coreDnsFilter `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
Filters []coreDnsFilter `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"`
<mask> <mask> type coreDNSConfig struct { <mask> binaryFile string <mask> coreFile string <mask> FilterFile string `yaml:"-"` <mask> Port int `yaml:"port"` <mask> ProtectionEnabled bool `yaml:"protection_enabled"` <mask> FilteringEnabled bool `yaml:"filtering_enabled"` <mask> SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` <mask> SafeSearchEnabled bool `yaml:"safesearch_enabled"` <mask> ParentalEnabled bool `yaml:"parental_enabled"` <mask> ParentalSensitivity int `yaml:"parental_sensitivity"` <mask> BlockedResponseTTL int `yaml:"blocked_response_ttl"` <mask> QueryLogEnabled bool `yaml:"querylog_enabled"` <mask> Pprof string `yaml:"-"` <mask> Cache string `yaml:"-"` <mask> Prometheus string `yaml:"-"` <mask> UpstreamDNS []string `yaml:"upstream_dns"` <mask> } <mask> <mask> type filter struct { <mask> URL string `json:"url"` <mask> Name string `json:"name" yaml:"name"` </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
ID int `json:"ID"` // auto-assigned when filter is added
<mask> UpstreamDNS []string `yaml:"upstream_dns"` <mask> } <mask> <mask> type filter struct { <mask> URL string `json:"url"` <mask> Name string `json:"name" yaml:"name"` <mask> Enabled bool `json:"enabled"` <mask> RulesCount int `json:"rules_count" yaml:"-"` <mask> contents []byte </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove FilterFile string `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> add Filters []coreDnsFilter `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"`
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
ourDataDir: "data",
<mask> // initialize to default values, will be changed later when reading config or parsing command line <mask> var config = configuration{ <mask> ourConfigFilename: "AdGuardHome.yaml", <mask> BindPort: 3000, <mask> BindHost: "127.0.0.1", <mask> CoreDNS: coreDNSConfig{ <mask> Port: 53, <mask> binaryFile: "coredns", // only filename, no path </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove binaryFile: "coredns", // only filename, no path coreFile: "Corefile", // only filename, no path FilterFile: "dnsfilter.txt", // only filename, no path </s> add binaryFile: "coredns", // only filename, no path coreFile: "Corefile", // only filename, no path </s> remove config.ourBinaryDir = filepath.Dir(executable) } </s> add </s> remove doConfigRename := true </s> add executableName := filepath.Base(executable) if executableName == "AdGuardHome" { // Binary build config.ourBinaryDir = filepath.Dir(executable) } else { // Most likely we're debugging -- using current working directory in this case workDir, _ := os.Getwd() config.ourBinaryDir = workDir } log.Printf("Current working directory is %s", config.ourBinaryDir) } </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
binaryFile: "coredns", // only filename, no path coreFile: "Corefile", // only filename, no path
<mask> BindPort: 3000, <mask> BindHost: "127.0.0.1", <mask> CoreDNS: coreDNSConfig{ <mask> Port: 53, <mask> binaryFile: "coredns", // only filename, no path <mask> coreFile: "Corefile", // only filename, no path <mask> FilterFile: "dnsfilter.txt", // only filename, no path <mask> ProtectionEnabled: true, <mask> FilteringEnabled: true, <mask> SafeBrowsingEnabled: false, <mask> BlockedResponseTTL: 10, // in seconds <mask> QueryLogEnabled: true, </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err </s> remove {Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt"}, {Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, {Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, {Enabled: false, URL: "http://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"}, </s> add {ID: 1, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard Simplified Domain Names filter"}, {ID: 2, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, {ID: 3, Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, {ID: 4, Enabled: false, URL: "http://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
{ID: 1, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard Simplified Domain Names filter"}, {ID: 2, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, {ID: 3, Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, {ID: 4, Enabled: false, URL: "http://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"},
<mask> Cache: "cache", <mask> Prometheus: "prometheus :9153", <mask> }, <mask> Filters: []filter{ <mask> {Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt"}, <mask> {Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, <mask> {Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, <mask> {Enabled: false, URL: "http://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"}, <mask> }, <mask> } <mask> <mask> func parseConfig() error { <mask> configfile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove func renameOldConfigIfNeccessary() error { oldConfigFile := filepath.Join(config.ourBinaryDir, "AdguardDNS.yaml") _, err := os.Stat(oldConfigFile) if os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s doesn't exist, nothing to do", oldConfigFile) </s> add // Performs necessary upgrade operations if needed func upgradeConfig() error { if config.SchemaVersion == SchemaVersion { // No upgrade, do nothing </s> remove elapsed := time.Since(filter.LastUpdated) if elapsed <= updatePeriod { </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </s> remove // extract filter name and count number of rules </s> add // Extract filter name and count number of rules </s> remove return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) </s> add return false, fmt.Errorf("got status code != 200: %d", resp.StatusCode) } contentType := strings.ToLower(resp.Header.Get("content-type")) if !strings.HasPrefix(contentType, "text/plain") { log.Printf("Non-text response %s from %s, skipping", contentType, filter.URL) return false, fmt.Errorf("non-text response %s", contentType) </s> remove if resp.StatusCode >= 400 { </s> add if resp.StatusCode != 200 {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
err = writeFileSafe(configfile, yamlText)
<mask> if err != nil { <mask> log.Printf("Couldn't generate YAML file: %s", err) <mask> return err <mask> } <mask> err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write YAML config: %s", err) <mask> return err <mask> } <mask> err = os.Rename(configfile+".tmp", configfile) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err) </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext)) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
log.Printf("Couldn't save YAML config: %s", err)
<mask> return err <mask> } <mask> err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write YAML config: %s", err) <mask> return err <mask> } <mask> err = os.Rename(configfile+".tmp", configfile) <mask> if err != nil { <mask> log.Printf("Couldn't rename YAML config: %s", err) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
userFilter := getUserFilter() err = userFilter.save()
<mask> if err != nil { <mask> log.Printf("Couldn't write YAML config: %s", err) <mask> return err <mask> } <mask> err = os.Rename(configfile+".tmp", configfile) <mask> if err != nil { <mask> log.Printf("Couldn't rename YAML config: %s", err) <mask> return err <mask> } <mask> return nil </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err) </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
log.Printf("Couldn't save the user filter: %s", err)
<mask> return err <mask> } <mask> err = os.Rename(configfile+".tmp", configfile) <mask> if err != nil { <mask> log.Printf("Couldn't rename YAML config: %s", err) <mask> return err <mask> } <mask> return nil <mask> } <mask> </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove return err </s> add return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
err = writeFileSafe(corefile, []byte(configtext))
<mask> if err != nil { <mask> log.Printf("Couldn't generate DNS config: %s", err) <mask> return err <mask> } <mask> err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write DNS config: %s", err) <mask> } <mask> err = os.Rename(corefile+".tmp", corefile) <mask> if err != nil { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove return err </s> add return nil </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
log.Printf("Couldn't save DNS config: %s", err) return err
<mask> return err <mask> } <mask> err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write DNS config: %s", err) <mask> } <mask> err = os.Rename(corefile+".tmp", corefile) <mask> if err != nil { <mask> log.Printf("Couldn't rename DNS config: %s", err) <mask> } <mask> return err <mask> } <mask> <mask> func writeAllConfigs() error { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext)) </s> remove return err </s> add return nil </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
return nil
<mask> err = os.Rename(corefile+".tmp", corefile) <mask> if err != nil { <mask> log.Printf("Couldn't rename DNS config: %s", err) <mask> } <mask> return err <mask> } <mask> <mask> func writeAllConfigs() error { <mask> err := writeConfig() <mask> if err != nil { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext)) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err) </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
{{if .ProtectionEnabled}}dnsfilter {
<mask> return nil <mask> } <mask> <mask> const coreDNSConfigTemplate = `.:{{.Port}} { <mask> {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { <mask> {{if .SafeBrowsingEnabled}}safebrowsing{{end}} <mask> {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}} <mask> {{if .SafeSearchEnabled}}safesearch{{end}} <mask> {{if .QueryLogEnabled}}querylog{{end}} <mask> blocked_ttl {{.BlockedResponseTTL}} </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove return err </s> add return nil </s> remove if value > high { return high </s> add err = os.Rename(tmpPath, path) if err != nil { return err </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
{{if .FilteringEnabled}} {{range .Filters}} filter {{.ID}} "{{.Path}}" {{end}} {{end}}
<mask> {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}} <mask> {{if .SafeSearchEnabled}}safesearch{{end}} <mask> {{if .QueryLogEnabled}}querylog{{end}} <mask> blocked_ttl {{.BlockedResponseTTL}} <mask> }{{end}} <mask> {{.Pprof}} <mask> hosts { <mask> fallthrough <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> add {{if .ProtectionEnabled}}dnsfilter { </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add </s> remove args := c.RemainingArgs() if len(args) > 0 { filterFileNames = append(filterFileNames, args...) } </s> add </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add </s> remove if value > high { return high </s> add err = os.Rename(tmpPath, path) if err != nil { return err
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
// fill the list of filters filters := make([]coreDnsFilter, 0) // first of all, append the user filter userFilter := getUserFilter() // TODO: Don't add if empty //if len(userFilter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) //} // then go through other filters for i := range config.Filters { filter := &config.Filters[i] if filter.Enabled && len(filter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: filter.ID, Path: filter.getFilterFilePath()}) } } temporaryConfig.Filters = filters
<mask> } <mask> <mask> var configBytes bytes.Buffer <mask> temporaryConfig := config.CoreDNS <mask> temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) <mask> // run the template <mask> err = t.Execute(&configBytes, &temporaryConfig) <mask> if err != nil { <mask> log.Printf("Couldn't generate DNS config: %s", err) <mask> return "", err </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644) </s> add err = writeFileSafe(corefile, []byte(configtext)) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove return err </s> add return nil </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
config.go
<mask> "strings" <mask> "time" <mask> <mask> coredns_plugin "github.com/AdguardTeam/AdGuardHome/coredns_plugin" <mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" <mask> "github.com/miekg/dns" <mask> "gopkg.in/asaskevich/govalidator.v4" <mask> ) <mask> <mask> const updatePeriod = time.Minute * 30 </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove "gopkg.in/yaml.v2" </s> add </s> remove elapsed := time.Since(filter.LastUpdated) if elapsed <= updatePeriod { </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </s> remove {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> add {{if .ProtectionEnabled}}dnsfilter {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
ok, err := filter.update(true)
<mask> return <mask> } <mask> } <mask> <mask> ok, err := filter.update(time.Now()) <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> tellCoreDNSToReload() <mask> _, err = fmt.Fprintf(w, "OK %d rules\n", filter.RulesCount) <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write body: %s", err) <mask> log.Println(errortext) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// TODO: Start using filter ID
<mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> } <mask> } <mask> <mask> func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) <mask> log.Println(errortext) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
} else { // Remove the filter file err := os.Remove(filter.getFilterFilePath()) if err != nil { errortext := fmt.Sprintf("Couldn't remove the filter file: %s", err) http.Error(w, errortext, http.StatusInternalServerError) return }
<mask> for _, filter := range config.Filters { <mask> if filter.URL != url { <mask> newFilters = append(newFilters, filter) <mask> } <mask> } <mask> // Update the configuration after removing filter files <mask> config.Filters = newFilters <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove log.Printf("filterFileNames = %+v", filterFileNames) </s> add for _, filter := range p.settings.Filters { log.Printf("Loading rules from %s", filter.Path)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Update the configuration after removing filter files
<mask> return <mask> } <mask> } <mask> } <mask> config.Filters = newFilters <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> // TODO: Start using filter ID <mask> func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> newFilters = append(newFilters, filter) <mask> } <mask> } <mask> config.Filters = newFilters <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// TODO: Start using filter ID
<mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) <mask> log.Println(errortext) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> } <mask> <mask> // kick off refresh of rules from new URLs <mask> refreshFiltersIfNeccessary() <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// TODO: Start using filter ID
<mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) <mask> log.Println(errortext) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove ok, err := filter.update(time.Now()) </s> add ok, err := filter.update(true)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> return <mask> } <mask> <mask> config.UserRules = strings.Split(string(body), "\n") <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { <mask> force := r.URL.Query().Get("force") </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> }() <mask> } <mask> <mask> func refreshFiltersIfNeccessary() int { <mask> now := time.Now() <mask> config.Lock() <mask> <mask> // deduplicate <mask> // TODO: move it somewhere else <mask> { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove filter.LastUpdated = now </s> add filter.LastUpdated = time.Now() </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove doConfigRename := true </s> add executableName := filepath.Base(executable) if executableName == "AdGuardHome" { // Binary build config.ourBinaryDir = filepath.Dir(executable) } else { // Most likely we're debugging -- using current working directory in this case workDir, _ := os.Getwd() config.ourBinaryDir = workDir } log.Printf("Current working directory is %s", config.ourBinaryDir) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
updated, err := filter.update(false)
<mask> // fetch URLs <mask> updateCount := 0 <mask> for i := range config.Filters { <mask> filter := &config.Filters[i] // otherwise we will be operating on a copy <mask> updated, err := filter.update(now) <mask> if err != nil { <mask> log.Printf("Failed to update filter %s: %s\n", filter.URL, err) <mask> continue <mask> } <mask> if updated { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove ok, err := filter.update(time.Now()) </s> add ok, err := filter.update(true) </s> remove temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) </s> add // fill the list of filters filters := make([]coreDnsFilter, 0) // first of all, append the user filter userFilter := getUserFilter() // TODO: Don't add if empty //if len(userFilter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) //} // then go through other filters for i := range config.Filters { filter := &config.Filters[i] if filter.Enabled && len(filter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: filter.ID, Path: filter.getFilterFilePath()}) } } temporaryConfig.Filters = filters </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> } <mask> config.Unlock() <mask> <mask> if updateCount > 0 { <mask> err := writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> } <mask> tellCoreDNSToReload() <mask> } <mask> return updateCount <mask> } <mask> </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Errorf("Couldn't write filter file: %s", err) log.Println(errortext) return errortext } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field func (filter *filter) update(force bool) (bool, error) {
<mask> } <mask> return updateCount <mask> } <mask> <mask> func (filter *filter) update(now time.Time) (bool, error) { <mask> if !filter.Enabled { <mask> return false, nil <mask> } <mask> elapsed := time.Since(filter.LastUpdated) <mask> if elapsed <= updatePeriod { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove elapsed := time.Since(filter.LastUpdated) if elapsed <= updatePeriod { </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
if !force && time.Since(filter.LastUpdated) <= updatePeriod {
<mask> func (filter *filter) update(now time.Time) (bool, error) { <mask> if !filter.Enabled { <mask> return false, nil <mask> } <mask> elapsed := time.Since(filter.LastUpdated) <mask> if elapsed <= updatePeriod { <mask> return false, nil <mask> } <mask> <mask> // use same update period for failed filter downloads to avoid flooding with requests <mask> filter.LastUpdated = now </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove func (filter *filter) update(now time.Time) (bool, error) { </s> add // Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field func (filter *filter) update(force bool) (bool, error) { </s> remove filter.LastUpdated = now </s> add filter.LastUpdated = time.Now() </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
log.Printf("Downloading update for filter %d", filter.ID)
<mask> } <mask> <mask> // use same update period for failed filter downloads to avoid flooding with requests <mask> filter.LastUpdated = time.Now() <mask> <mask> resp, err := client.Get(filter.URL) <mask> if resp != nil && resp.Body != nil { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove filter.LastUpdated = now </s> add filter.LastUpdated = time.Now() </s> remove elapsed := time.Since(filter.LastUpdated) if elapsed <= updatePeriod { </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove updated, err := filter.update(now) </s> add updated, err := filter.update(false) </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
filter.LastUpdated = time.Now()
<mask> return false, nil <mask> } <mask> <mask> // use same update period for failed filter downloads to avoid flooding with requests <mask> filter.LastUpdated = now <mask> <mask> resp, err := client.Get(filter.URL) <mask> if resp != nil && resp.Body != nil { <mask> defer resp.Body.Close() <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove elapsed := time.Since(filter.LastUpdated) if elapsed <= updatePeriod { </s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove for i, filterFileName := range filterFileNames { file, err := os.Open(filterFileName) </s> add file, err := os.Open(filter.Path)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
if resp.StatusCode != 200 {
<mask> log.Printf("Couldn't request filter from URL %s, skipping: %s", filter.URL, err) <mask> return false, err <mask> } <mask> <mask> if resp.StatusCode >= 400 { <mask> log.Printf("Got status code %d from URL %s, skipping", resp.StatusCode, filter.URL) <mask> return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) <mask> } <mask> <mask> body, err := ioutil.ReadAll(resp.Body) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) </s> add return false, fmt.Errorf("got status code != 200: %d", resp.StatusCode) } contentType := strings.ToLower(resp.Header.Get("content-type")) if !strings.HasPrefix(contentType, "text/plain") { log.Printf("Non-text response %s from %s, skipping", contentType, filter.URL) return false, fmt.Errorf("non-text response %s", contentType) </s> remove // extract filter name and count number of rules </s> add // Extract filter name and count number of rules </s> remove log.Printf("Added %d rules from %s", count, filterFileName) </s> add log.Printf("Added %d rules from %d", count, filter.ID) </s> remove ok, err := filter.update(time.Now()) </s> add ok, err := filter.update(true) </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
return false, fmt.Errorf("got status code != 200: %d", resp.StatusCode) } contentType := strings.ToLower(resp.Header.Get("content-type")) if !strings.HasPrefix(contentType, "text/plain") { log.Printf("Non-text response %s from %s, skipping", contentType, filter.URL) return false, fmt.Errorf("non-text response %s", contentType)
<mask> } <mask> <mask> if resp.StatusCode >= 400 { <mask> log.Printf("Got status code %d from URL %s, skipping", resp.StatusCode, filter.URL) <mask> return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) <mask> } <mask> <mask> body, err := ioutil.ReadAll(resp.Body) <mask> if err != nil { <mask> log.Printf("Couldn't fetch filter contents from URL %s, skipping: %s", filter.URL, err) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove if resp.StatusCode >= 400 { </s> add if resp.StatusCode != 200 { </s> remove // extract filter name and count number of rules </s> add // Extract filter name and count number of rules </s> remove ok, err := filter.update(time.Now()) </s> add ok, err := filter.update(true) </s> remove log.Printf("Added %d rules from %s", count, filterFileName) </s> add log.Printf("Added %d rules from %d", count, filter.ID)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Extract filter name and count number of rules
<mask> log.Printf("Couldn't fetch filter contents from URL %s, skipping: %s", filter.URL, err) <mask> return false, err <mask> } <mask> <mask> // extract filter name and count number of rules <mask> lines := strings.Split(string(body), "\n") <mask> rulesCount := 0 <mask> seenTitle := false <mask> d := dnsfilter.New() <mask> for _, line := range lines { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove d := dnsfilter.New() </s> add // Count lines in the filter </s> remove return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) </s> add return false, fmt.Errorf("got status code != 200: %d", resp.StatusCode) } contentType := strings.ToLower(resp.Header.Get("content-type")) if !strings.HasPrefix(contentType, "text/plain") { log.Printf("Non-text response %s from %s, skipping", contentType, filter.URL) return false, fmt.Errorf("non-text response %s", contentType) </s> remove if resp.StatusCode >= 400 { </s> add if resp.StatusCode != 200 { </s> remove log.Printf("filterFileNames = %+v", filterFileNames) </s> add for _, filter := range p.settings.Filters { log.Printf("Loading rules from %s", filter.Path) </s> remove updated, err := filter.update(now) </s> add updated, err := filter.update(false)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Count lines in the filter
<mask> // extract filter name and count number of rules <mask> lines := strings.Split(string(body), "\n") <mask> rulesCount := 0 <mask> seenTitle := false <mask> d := dnsfilter.New() <mask> for _, line := range lines { <mask> line = strings.TrimSpace(line) <mask> if len(line) > 0 && line[0] == '!' { <mask> if m := filterTitle.FindAllStringSubmatch(line, -1); len(m) > 0 && len(m[0]) >= 2 && !seenTitle { <mask> filter.Name = m[0][1] </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove // extract filter name and count number of rules </s> add // Extract filter name and count number of rules </s> remove temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) </s> add // fill the list of filters filters := make([]coreDnsFilter, 0) // first of all, append the user filter userFilter := getUserFilter() // TODO: Don't add if empty //if len(userFilter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) //} // then go through other filters for i := range config.Filters { filter := &config.Filters[i] if filter.Enabled && len(filter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: filter.ID, Path: filter.getFilterFilePath()}) } } temporaryConfig.Filters = filters </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add </s> remove switch c.Val() { </s> add blockValue := c.Val() switch blockValue { </s> remove args := c.RemainingArgs() if len(args) > 0 { filterFileNames = append(filterFileNames, args...) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> filter.Name = m[0][1] <mask> seenTitle = true <mask> } <mask> } else if len(line) != 0 { <mask> err = d.AddRule(line, 0) <mask> if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { <mask> continue <mask> } <mask> if err != nil { <mask> log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) <mask> // Just ignore invalid rules <mask> continue <mask> } <mask> rulesCount++ <mask> } <mask> } <mask> if bytes.Equal(filter.contents, body) { <mask> return false, nil </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = p.d.AddRule(text, uint32(i)) </s> add err = p.d.AddRule(text, filter.ID) </s> remove log.Printf("Added %d rules from %s", count, filterFileName) </s> add log.Printf("Added %d rules from %d", count, filter.ID) </s> remove err = os.Rename(oldConfigFile, newConfigFile) if err != nil { log.Printf("Failed to rename %s to %s: %s", oldConfigFile, newConfigFile, err) return err </s> add // Perform upgrade operations for each consecutive version upgrade for oldVersion, newVersion := config.SchemaVersion, config.SchemaVersion+1; newVersion <= SchemaVersion; { err := upgradeConfigSchema(oldVersion, newVersion) if err != nil { log.Fatal(err) } // Increment old and new versions oldVersion++ newVersion++ } // Save the current schema version config.SchemaVersion = SchemaVersion return nil } // Upgrade from oldVersion to newVersion func upgradeConfigSchema(oldVersion int, newVersion int) error { if oldVersion == 0 && newVersion == 1 { log.Printf("Updating schema from %d to %d", oldVersion, newVersion) // The first schema upgrade: // Added "ID" field to "filter" -- we need to populate this field now // Added "config.ourDataDir" -- where we will now store filters contents for i := range config.Filters { filter := &config.Filters[i] // otherwise we will be operating on a copy log.Printf("Seting ID=%d for filter %s", i, filter.URL) filter.ID = i + 1 // start with ID=1 // Forcibly update the filter _, err := filter.update(true) if err != nil { log.Fatal(err) } } // No more "dnsfilter.txt", filters are now loaded from config.ourDataDir/filters/ dnsFilterPath := filepath.Join(config.ourBinaryDir, "dnsfilter.txt") _, err := os.Stat(dnsFilterPath) if !os.IsNotExist(err) { log.Printf("Deleting %s as we don't need it anymore", dnsFilterPath) err = os.Remove(dnsFilterPath) if err != nil { log.Printf("Cannot remove %s due to %s", dnsFilterPath, err) } } </s> remove if doConfigRename { err := renameOldConfigIfNeccessary() if err != nil { panic(err) } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Check if the filter was really changed
<mask> } else if len(line) != 0 { <mask> rulesCount++ <mask> } <mask> } <mask> if bytes.Equal(filter.contents, body) { <mask> return false, nil <mask> } <mask> <mask> log.Printf("Filter %s updated: %d bytes, %d rules", filter.URL, len(body), rulesCount) <mask> filter.RulesCount = rulesCount </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = d.AddRule(line, 0) if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax { continue } if err != nil { log.Printf("Cannot add rule %s from %s: %s", line, filter.URL, err) // Just ignore invalid rules continue } </s> add </s> remove return false, fmt.Errorf("Got status code >= 400: %d", resp.StatusCode) </s> add return false, fmt.Errorf("got status code != 200: %d", resp.StatusCode) } contentType := strings.ToLower(resp.Header.Get("content-type")) if !strings.HasPrefix(contentType, "text/plain") { log.Printf("Non-text response %s from %s, skipping", contentType, filter.URL) return false, fmt.Errorf("non-text response %s", contentType) </s> remove log.Printf("Added %d rules from %s", count, filterFileName) </s> add log.Printf("Added %d rules from %d", count, filter.ID)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Saving it to the filters dir now err = filter.save() if err != nil { return false, nil }
<mask> <mask> log.Printf("Filter %s updated: %d bytes, %d rules", filter.URL, len(body), rulesCount) <mask> filter.RulesCount = rulesCount <mask> filter.contents = body <mask> return true, nil <mask> } <mask> <mask> // saves filter contents to the file in config.ourDataDir </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove newConfigFile := filepath.Join(config.ourBinaryDir, config.ourConfigFilename) _, err = os.Stat(newConfigFile) if !os.IsNotExist(err) { // do nothing, file doesn't exist trace("File %s already exists, will not overwrite", newConfigFile) return nil </s> add if config.SchemaVersion > SchemaVersion { // Unexpected -- config file is newer than the return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err
<mask> filter.contents = body <mask> return true, nil <mask> } <mask> <mask> // write filter file <mask> func writeFilterFile() error { <mask> filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) <mask> log.Printf("Writing filter file: %s", filterpath) <mask> // TODO: check if file contents have modified <mask> data := []byte{} <mask> config.RLock() <mask> filters := config.Filters <mask> for _, filter := range filters { <mask> if !filter.Enabled { <mask> continue <mask> } <mask> data = append(data, filter.contents...) <mask> data = append(data, '\n') <mask> } <mask> for _, rule := range config.UserRules { <mask> data = append(data, []byte(rule)...) <mask> data = append(data, '\n') <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove config.RUnlock() err := ioutil.WriteFile(filterpath+".tmp", data, 0644) if err != nil { log.Printf("Couldn't write filter file: %s", err) </s> add filterFilePath := filter.getFilterFilePath() log.Printf("Loading filter %d contents to: %s", filter.ID, filterFilePath) if _, err := os.Stat(filterFilePath); os.IsNotExist(err) { // do nothing, file doesn't exist </s> remove temporaryConfig.FilterFile = filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) </s> add // fill the list of filters filters := make([]coreDnsFilter, 0) // first of all, append the user filter userFilter := getUserFilter() // TODO: Don't add if empty //if len(userFilter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) //} // then go through other filters for i := range config.Filters { filter := &config.Filters[i] if filter.Enabled && len(filter.contents) > 0 { filters = append(filters, coreDnsFilter{ID: filter.ID, Path: filter.getFilterFilePath()}) } } temporaryConfig.Filters = filters </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil
<mask> } <mask> data = append(data, filter.contents...) <mask> data = append(data, '\n') <mask> } <mask> for _, rule := range config.UserRules { <mask> data = append(data, []byte(rule)...) <mask> data = append(data, '\n') <mask> } <mask> config.RUnlock() <mask> err := ioutil.WriteFile(filterpath+".tmp", data, 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write filter file: %s", err) </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove config.RUnlock() err := ioutil.WriteFile(filterpath+".tmp", data, 0644) if err != nil { log.Printf("Couldn't write filter file: %s", err) </s> add filterFilePath := filter.getFilterFilePath() log.Printf("Loading filter %d contents to: %s", filter.ID, filterFilePath) if _, err := os.Stat(filterFilePath); os.IsNotExist(err) { // do nothing, file doesn't exist </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
filterFilePath := filter.getFilterFilePath() log.Printf("Loading filter %d contents to: %s", filter.ID, filterFilePath) if _, err := os.Stat(filterFilePath); os.IsNotExist(err) { // do nothing, file doesn't exist
<mask> for _, rule := range config.UserRules { <mask> data = append(data, []byte(rule)...) <mask> data = append(data, '\n') <mask> } <mask> config.RUnlock() <mask> err := ioutil.WriteFile(filterpath+".tmp", data, 0644) <mask> if err != nil { <mask> log.Printf("Couldn't write filter file: %s", err) <mask> return err <mask> } <mask> <mask> err = os.Rename(filterpath+".tmp", filterpath) <mask> if err != nil { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove err = os.Rename(filterpath+".tmp", filterpath) </s> add filterFile, err := ioutil.ReadFile(filterFilePath) </s> remove log.Printf("Couldn't rename filter file: %s", err) </s> add </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
filterFile, err := ioutil.ReadFile(filterFilePath)
<mask> log.Printf("Couldn't write filter file: %s", err) <mask> return err <mask> } <mask> <mask> err = os.Rename(filterpath+".tmp", filterpath) <mask> if err != nil { <mask> log.Printf("Couldn't rename filter file: %s", err) <mask> return err <mask> } <mask> return nil </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove log.Printf("Couldn't rename filter file: %s", err) </s> add </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644) </s> add err = writeFileSafe(configfile, yamlText) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove log.Printf("Couldn't write YAML config: %s", err) </s> add log.Printf("Couldn't save YAML config: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> } <mask> <mask> err = os.Rename(filterpath+".tmp", filterpath) <mask> if err != nil { <mask> log.Printf("Couldn't rename filter file: %s", err) <mask> return err <mask> } <mask> return nil <mask> } <mask> </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = os.Rename(filterpath+".tmp", filterpath) </s> add filterFile, err := ioutil.ReadFile(filterFilePath) </s> remove err = os.Rename(configfile+".tmp", configfile) </s> add userFilter := getUserFilter() err = userFilter.save() </s> remove log.Printf("Couldn't rename YAML config: %s", err) </s> add log.Printf("Couldn't save the user filter: %s", err) </s> remove log.Printf("Couldn't write DNS config: %s", err) } err = os.Rename(corefile+".tmp", corefile) if err != nil { log.Printf("Couldn't rename DNS config: %s", err) </s> add log.Printf("Couldn't save DNS config: %s", err) return err </s> remove return err </s> add return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
log.Printf("Filter %d length is %d", filter.ID, len(filterFile)) filter.contents = filterFile
<mask> if err != nil { <mask> return err <mask> } <mask> return nil <mask> } <mask> <mask> // Path to the filter contents <mask> func (filter *filter) getFilterFilePath() string { <mask> return filepath.Join(config.ourBinaryDir, config.ourDataDir, FiltersDir, strconv.Itoa(filter.ID) + ".txt") </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove // write filter file func writeFilterFile() error { filterpath := filepath.Join(config.ourBinaryDir, config.CoreDNS.FilterFile) log.Printf("Writing filter file: %s", filterpath) // TODO: check if file contents have modified data := []byte{} config.RLock() filters := config.Filters for _, filter := range filters { if !filter.Enabled { continue } data = append(data, filter.contents...) data = append(data, '\n') </s> add // saves filter contents to the file in config.ourDataDir func (filter *filter) save() error { filterFilePath := filter.getFilterFilePath() log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath) err := writeFileSafe(filterFilePath, filter.contents) if err != nil { return err </s> remove for _, rule := range config.UserRules { data = append(data, []byte(rule)...) data = append(data, '\n') </s> add return nil; } // loads filter contents from the file in config.ourDataDir func (filter *filter) load() error { if !filter.Enabled { // No need to load a filter that is not enabled return nil </s> remove func (filter *filter) update(now time.Time) (bool, error) { </s> add // Checks for filters updates // If "force" is true -- does not check the filter's LastUpdated field func (filter *filter) update(force bool) (bool, error) { </s> remove func clamp(value, low, high int) int { if value < low { return low </s> add // ---------------------------------- // helper functions for working with files // ---------------------------------- // Writes data first to a temporary file and then renames it to what's specified in path func writeFileSafe(path string, data []byte) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, 0755) if err != nil { return err } tmpPath := path + ".tmp" err = ioutil.WriteFile(tmpPath, data, 0644) if err != nil { return err
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
// Path to the filter contents func (filter *filter) getFilterFilePath() string { return filepath.Join(config.ourBinaryDir, config.ourDataDir, FiltersDir, strconv.Itoa(filter.ID) + ".txt") }
<mask> return nil <mask> } <mask> <mask> // ------------ <mask> // safebrowsing <mask> // ------------ <mask> <mask> func handleSafeBrowsingEnable(w http.ResponseWriter, r *http.Request) { </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
control.go
<mask> errortext := fmt.Errorf("Unable to write coredns config: %s", err) <mask> log.Println(errortext) <mask> return errortext <mask> } <mask> err = writeFilterFile() <mask> if err != nil { <mask> errortext := fmt.Errorf("Couldn't write filter file: %s", err) <mask> log.Println(errortext) <mask> return errortext <mask> } <mask> <mask> go coremain.Run() <mask> return nil <mask> } </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err := writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err = writeFilterFile() if err != nil { errortext := fmt.Sprintf("Couldn't write filter file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
coredns.go
type plugFilter struct { ID uint32 Path string }
<mask> ) <mask> <mask> type plugSettings struct { <mask> SafeBrowsingBlockHost string <mask> ParentalBlockHost string <mask> QueryLogEnabled bool <mask> BlockedTTL uint32 // in seconds, default 3600 <mask> Filters []plugFilter </s> Fix #371 #421 Filters are now saved to a file Also, they're loaded from the file on startup Filter ID is not passed to the CoreDNS plugin config (server-side AG DNS must be changed accordingly) Some minor refactoring, unused functions removed </s> remove FilterFile string `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> add Filters []coreDnsFilter `yaml:"-"` Port int `yaml:"port"` ProtectionEnabled bool `yaml:"protection_enabled"` FilteringEnabled bool `yaml:"filtering_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"` ParentalEnabled bool `yaml:"parental_enabled"` ParentalSensitivity int `yaml:"parental_sensitivity"` BlockedResponseTTL int `yaml:"blocked_response_ttl"` QueryLogEnabled bool `yaml:"querylog_enabled"` Pprof string `yaml:"-"` Cache string `yaml:"-"` Prometheus string `yaml:"-"` UpstreamDNS []string `yaml:"upstream_dns"` </s> remove BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> add // Schema version of the config file. This value is used when performing the app updates. SchemaVersion int `yaml:"schema_version"` BindHost string `yaml:"bind_host"` BindPort int `yaml:"bind_port"` AuthName string `yaml:"auth_name"` AuthPass string `yaml:"auth_pass"` CoreDNS coreDNSConfig `yaml:"coredns"` Filters []filter `yaml:"filters"` UserRules []string `yaml:"user_rules"` </s> remove "gopkg.in/yaml.v2" </s> add
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913
coredns_plugin/coredns_plugin.go