docstring_tokens
stringlengths 18
16.9k
| code_tokens
stringlengths 75
1.81M
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|
keep replace keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace | <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> }
</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> add } </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 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.QUICListenAddr != nil {
proxyConfig.QUICListenAddr = []*net.UDPAddr{s.conf.QUICListenAddr}
}
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | dnsforward/config.go |
keep keep keep add keep keep keep keep keep keep | <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) </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 { | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | dnsforward/config.go |
keep keep keep keep replace replace replace replace keep keep keep keep keep | <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> add } </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) </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 { | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | dnsforward/config.go |
keep keep add keep keep keep keep | <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> add gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= </s> add golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= </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> add } </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 return errorx.Decorate(err, "Failed to parse TLS keypair")
</s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | dnsforward/dnsforward_test.go |
keep keep keep add keep keep keep keep keep keep | <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> add gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= </s> add "fmt" </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> add } </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 return errorx.Decorate(err, "Failed to parse TLS keypair")
</s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | go.sum |
keep keep keep add keep keep keep keep | <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> add golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= </s> add "fmt" </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> add } </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 return errorx.Decorate(err, "Failed to parse TLS keypair")
</s> add return errorx.Decorate(err, "x509.ParseCertificate(): %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/314867734ac60e430143a25060ee6e62e027a9cb | go.sum |
keep add keep keep keep keep | <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 </s> add {"qq", []string{"||qq.com^", "||qqzaixian.com^"}}, </s> add {
id: 'qq',
name: 'QQ',
}, | https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3 | client/src/components/ui/Icons.js |
keep keep add keep keep keep keep keep keep | <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 </s> add {"qq", []string{"||qq.com^", "||qqzaixian.com^"}}, </s> add <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>
| https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3 | client/src/helpers/constants.js |
keep add keep keep keep keep | <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 </s> add {
id: 'qq',
name: 'QQ',
}, </s> add <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>
| https://github.com/AdguardTeam/AdGuardHome/commit/32b24ce0930cbdb9b759f77f2c0773f3e61cb7b3 | dnsfilter/blocked_services.go |
keep keep keep keep replace replace replace replace keep keep keep keep keep | <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) </s> add if !l.conf.FileEnabled {
return nil
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | home/config.go |
keep keep keep add keep keep keep keep keep | <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> add config.DNS.QueryLogFileEnabled = dc.FileEnabled </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, </s> remove Enabled: true,
Interval: 1,
MemSize: 100,
</s> add Enabled: true,
FileEnabled: true,
Interval: 1,
MemSize: 100, | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | home/config.go |
keep keep keep keep replace keep keep keep keep keep | <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> add config.DNS.QueryLogFileEnabled = dc.FileEnabled </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> add config.DNS.QueryLogFileEnabled = true </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, </s> remove Enabled: true,
Interval: 1,
MemSize: 100,
</s> add Enabled: true,
FileEnabled: true,
Interval: 1,
MemSize: 100, | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | home/config.go |
keep keep add keep keep keep keep | <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> add config.DNS.QueryLogFileEnabled = true </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, </s> remove Enabled: true,
Interval: 1,
MemSize: 100,
</s> add Enabled: true,
FileEnabled: true,
Interval: 1,
MemSize: 100, | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | home/config.go |
keep keep add keep keep keep keep keep | <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{} </s> add config.DNS.QueryLogFileEnabled = dc.FileEnabled </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)
}() | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | home/dns.go |
keep keep keep keep replace replace replace replace replace keep keep keep keep keep | <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> add if !l.conf.FileEnabled {
return nil
}
</s> add config.DNS.QueryLogFileEnabled = true </s> remove dc := querylog.DiskConfig{}
</s> add dc := querylog.Config{} </s> add config.DNS.QueryLogFileEnabled = dc.FileEnabled </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 { | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/qlog.go |
keep keep keep keep replace keep keep keep keep keep | <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> add config.DNS.QueryLogFileEnabled = true </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 Enabled: true,
Interval: 1,
MemSize: 100,
</s> add Enabled: true,
FileEnabled: true,
Interval: 1,
MemSize: 100, | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/qlog.go |
keep keep keep keep replace replace replace keep keep | <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> add if !l.conf.FileEnabled {
return nil
}
</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) </s> remove // DiskConfig - configuration settings that are stored on disk
type DiskConfig struct {
Enabled bool
Interval uint32
MemSize uint32
AnonymizeClientIP bool
}
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/qlog.go |
keep keep keep keep replace replace replace keep keep keep keep keep | <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> add FileEnabled: config.DNS.QueryLogFileEnabled, </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 { </s> add if !l.conf.FileEnabled {
return nil
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/qlog_test.go |
keep keep keep keep replace replace replace keep keep keep keep keep | <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> add FileEnabled: config.DNS.QueryLogFileEnabled, </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 </s> remove dc := querylog.DiskConfig{}
</s> add dc := querylog.Config{} | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/qlog_test.go |
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep | <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> add if !l.conf.FileEnabled {
return nil
}
</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 // 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)
}() | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/querylog.go |
keep keep replace keep keep keep keep replace keep keep keep keep | <mask>
<mask> // WriteDiskConfig - write configuration
<mask> WriteDiskConfig(dc *DiskConfig)
<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
</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 // 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 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 { | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/querylog.go |
keep keep keep add keep keep keep keep | <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, </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d1f385ff4252fdda5d81928caaa09052b62451 | querylog/querylog_file.go |
keep add keep keep keep keep keep keep | <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)) </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | .gitignore |
keep keep keep keep replace replace keep replace keep keep | <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
</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 if doConfigRename {
err := renameOldConfigIfNeccessary()
if err != nil {
panic(err)
}
}
</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> add ourDataDir: "data", </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) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep keep keep keep replace replace keep keep keep replace replace replace replace replace replace replace keep keep keep keep | <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()
<mask> if err != nil {
<mask> panic(err)
<mask> }
<mask> }
<mask>
<mask> err := askUsernamePasswordIfPossible()
<mask> if err != nil {
<mask> log.Fatal(err)
<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.ourBinaryDir = filepath.Dir(executable)
}
</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.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 = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644)
</s> add err = writeFileSafe(corefile, []byte(configtext)) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep replace keep keep keep keep replace keep keep keep keep | <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()
<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 if doConfigRename {
err := renameOldConfigIfNeccessary()
if err != nil {
panic(err)
}
}
</s> add </s> remove return err
</s> add return nil </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 value > high {
return high
</s> add err = os.Rename(tmpPath, path)
if err != nil {
return err </s> add // 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)
}
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep keep add keep keep keep keep keep | <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) </s> remove for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep keep keep keep replace replace replace replace replace replace keep keep keep replace replace replace replace replace replace keep keep keep | <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)
<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)
</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 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 // 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 // config was manually specified, don't do anything
doConfigRename = false
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep keep keep keep replace replace replace replace keep keep keep keep | <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 </s> remove log.Printf("Couldn't rename YAML config: %s", err)
</s> add log.Printf("Couldn't save the user filter: %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | app.go |
keep keep add keep keep keep keep keep | <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> add "path/filepath" </s> add "io/ioutil" </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 </s> add {{if .FilteringEnabled}}
{{range .Filters}}
filter {{.ID}} "{{.Path}}"
{{end}}
{{end}} </s> remove log.Printf("Couldn't write YAML config: %s", err)
</s> add log.Printf("Couldn't save YAML config: %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace replace keep keep keep keep keep | <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> add // 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"
</s> add // Directory to store data (i.e. filters contents)
ourDataDir string </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> add type plugFilter struct {
ID uint32
Path string
}
</s> add ID int `json:"ID"` // auto-assigned when filter is added </s> add "gopkg.in/yaml.v2" | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep add keep keep keep keep keep | <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> add // Directory to store data (i.e. filters contents)
ourDataDir string </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"` </s> add type plugFilter struct {
ID uint32
Path string
}
</s> add ID int `json:"ID"` // auto-assigned when filter is added </s> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep add keep keep keep keep keep | <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 </s> add // 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"
</s> add ID int `json:"ID"` // auto-assigned when filter is added </s> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</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"` | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</s> add // Directory to store data (i.e. filters contents)
ourDataDir string </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> add type plugFilter struct {
ID uint32
Path string
}
</s> remove
"gopkg.in/yaml.v2"
</s> add </s> add ID int `json:"ID"` // auto-assigned when filter is added | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep add keep keep keep keep keep keep | <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"` </s> add type plugFilter struct {
ID uint32
Path string
}
</s> add Filters []plugFilter </s> add ID int `json:"ID"` // auto-assigned when filter is added </s> add // Directory to store data (i.e. filters contents)
ourDataDir string | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep | <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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</s> add ID int `json:"ID"` // auto-assigned when filter is added </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> add type plugFilter struct {
ID uint32
Path string
}
</s> add Filters []plugFilter </s> add // Directory to store data (i.e. filters contents)
ourDataDir string | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep add keep keep keep keep keep | <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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</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> add type plugFilter struct {
ID uint32
Path string
}
</s> add Filters []plugFilter </s> add // Directory to store data (i.e. filters contents)
ourDataDir string | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep add keep keep keep keep keep | <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) </s> add // Directory to store data (i.e. filters contents)
ourDataDir string </s> add // TODO: Change tests -- there's new config template now | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace replace replace keep keep keep keep keep | <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> add ourDataDir: "data", </s> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
</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> add Filters: make([]plugFilter, 0), </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"}, </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace replace replace replace keep keep keep keep keep | <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 { </s> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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 </s> remove err = os.Rename(filterpath+".tmp", filterpath)
</s> add filterFile, err := ioutil.ReadFile(filterFilePath) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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)) </s> remove return err
</s> add return nil | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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)) </s> remove return err
</s> add return nil | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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 </s> remove log.Printf("Couldn't rename filter file: %s", err)
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep replace keep replace replace replace replace replace | <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 {
<mask> log.Printf("Couldn't rename DNS 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 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 = 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) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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) </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644)
</s> add err = writeFileSafe(configfile, yamlText) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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> add {{if .FilteringEnabled}}
{{range .Filters}}
filter {{.ID}} "{{.Path}}"
{{end}}
{{end}} </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 </s> remove log.Printf("Couldn't rename filter file: %s", err)
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep add keep keep keep keep keep | <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 </s> remove err := writeFilterFile()
if err != nil {
errortext := fmt.Sprintf("Couldn't write filter file: %s", err)
log.Println(errortext)
}
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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() </s> remove log.Printf("Couldn't write YAML config: %s", err)
</s> add log.Printf("Couldn't save YAML config: %s", err) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | config.go |
keep keep keep keep replace keep keep keep keep keep | <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> add // 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"
</s> add "path/filepath" </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 { </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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 </s> add } 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
} | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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 </s> remove ok, err := filter.update(time.Now())
</s> add ok, err := filter.update(true) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep add keep keep keep keep keep | <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> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep add keep keep keep keep keep keep | <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> add // Update the configuration after removing filter files </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> add // 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)
}
}
</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) </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
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep add keep keep keep keep keep keep | <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> add // TODO: Start using filter ID </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> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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> add } 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
} | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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> add } 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
} </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> add // TODO: Start using filter ID | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep add keep keep keep keep keep | <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> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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 </s> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep add keep keep keep keep keep | <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> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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) </s> add // TODO: Start using filter ID | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <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 </s> add } 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
} </s> add // TODO: Start using filter ID | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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> add // TODO: Change tests -- there's new config template now </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)
} </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)
}
} | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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> add // 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)
}
}
</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 </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() | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace keep keep keep keep keep | <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 </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep replace replace | <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 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> add log.Printf("Filter %d length is %d", filter.ID, len(filterFile))
filter.contents = filterFile </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> add // Path to the filter contents
func (filter *filter) getFilterFilePath() string {
return filepath.Join(config.ourBinaryDir, config.ourDataDir, FiltersDir, strconv.Itoa(filter.ID) + ".txt")
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep add keep keep keep keep keep | <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 </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() | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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> add log.Printf("Downloading update for filter %d", filter.ID)
</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> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
</s> remove for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) </s> add //noinspection GoDeferInLoop | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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 </s> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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) </s> add // 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)
}
}
</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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep replace keep keep keep replace | <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()
</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> add //noinspection GoDeferInLoop </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 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 updated, err := filter.update(now)
</s> add updated, err := filter.update(false) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep | <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> add // Check if the filter was really changed </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 </s> remove err = ioutil.WriteFile(corefile+".tmp", []byte(configtext), 0644)
</s> add err = writeFileSafe(corefile, []byte(configtext)) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep add keep keep keep keep keep keep | <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> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
</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> add log.Printf("Filter %d length is %d", filter.ID, len(filterFile))
filter.contents = filterFile </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 if resp.StatusCode >= 400 {
</s> add if resp.StatusCode != 200 { | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep add keep keep keep keep | <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> add // Check if the filter was really changed </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> add log.Printf("Filter %d length is %d", filter.ID, len(filterFile))
filter.contents = filterFile </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) </s> add // 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)
}
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep replace replace replace | <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')
</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 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> add } 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
} </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 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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep replace replace replace replace keep keep keep replace keep keep keep keep | <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 {
<mask> log.Printf("Couldn't rename filter file: %s", err)
<mask> return err
<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 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 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) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace keep keep keep keep keep | <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 </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep add keep keep keep keep keep keep | <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> add // Path to the filter contents
func (filter *filter) getFilterFilePath() string {
return filepath.Join(config.ourBinaryDir, config.ourDataDir, FiltersDir, strconv.Itoa(filter.ID) + ".txt")
}
</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 </s> add // Saving it to the filters dir now
err = filter.save()
if err != nil {
return false, nil
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep add keep keep keep keep keep | <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> add // Update the configuration after removing filter files </s> add // TODO: Start using filter ID </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> add // TODO: Start using filter ID </s> add // TODO: Start using filter ID </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | control.go |
keep keep keep keep replace replace replace replace replace replace keep keep keep keep | <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 </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns.go |
keep add keep keep keep keep keep keep | <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> add Filters []plugFilter </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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</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 </s> add ID int `json:"ID"` // auto-assigned when filter is added | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep add keep keep keep keep keep | <mask> ParentalBlockHost string
<mask> QueryLogEnabled bool
<mask> BlockedTTL uint32 // in seconds, default 3600
<mask> }
<mask>
<mask> type plug struct {
<mask> d *dnsfilter.Dnsfilter
<mask> Next plugin.Handler
</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> add type plugFilter struct {
ID uint32
Path string
}
</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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</s> add ID int `json:"ID"` // auto-assigned when filter is added </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep add keep keep keep keep keep keep | <mask> ParentalBlockHost: "family.block.dns.adguard.com",
<mask> BlockedTTL: 3600, // in seconds
<mask> }
<mask>
<mask> //
<mask> // coredns handling functions
<mask> //
<mask> func setupPlugin(c *caddy.Controller) (*plug, 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 return value
</s> add 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 // eat all args so that coredns can start happily
</s> add // Eat all args so that coredns can start happily </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 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> add // Path to the filter contents
func (filter *filter) getFilterFilePath() string {
return filepath.Join(config.ourBinaryDir, config.ourDataDir, FiltersDir, strconv.Itoa(filter.ID) + ".txt")
}
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep replace keep replace replace replace replace keep keep keep | <mask>
<mask> filterFileNames := []string{}
<mask> for c.Next() {
<mask> args := c.RemainingArgs()
<mask> if len(args) > 0 {
<mask> filterFileNames = append(filterFileNames, args...)
<mask> }
<mask> for c.NextBlock() {
<mask> switch c.Val() {
<mask> case "safebrowsing":
</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 switch c.Val() {
</s> add blockValue := c.Val()
switch blockValue { </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 for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) </s> remove d := dnsfilter.New()
</s> add // Count lines in the filter </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
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep keep replace keep keep keep keep keep | <mask> if len(args) > 0 {
<mask> filterFileNames = append(filterFileNames, args...)
<mask> }
<mask> for c.NextBlock() {
<mask> switch c.Val() {
<mask> case "safebrowsing":
<mask> p.d.EnableSafeBrowsing()
<mask> if c.NextArg() {
<mask> if len(c.Val()) == 0 {
<mask> return nil, c.ArgErr()
</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 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 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 d := dnsfilter.New()
</s> add // Count lines in the filter </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 for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep replace keep replace replace keep keep keep | <mask> }
<mask> }
<mask>
<mask> log.Printf("filterFileNames = %+v", filterFileNames)
<mask>
<mask> for i, filterFileName := range filterFileNames {
<mask> file, err := os.Open(filterFileName)
<mask> if err != nil {
<mask> return nil, err
<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> add //noinspection GoDeferInLoop </s> remove if doConfigRename {
err := renameOldConfigIfNeccessary()
if err != nil {
panic(err)
}
}
</s> add </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 return err
</s> add return nil </s> add } 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
} | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep add keep keep keep keep | <mask> if err != nil {
<mask> return nil, err
<mask> }
<mask> defer file.Close()
<mask>
<mask> count := 0
<mask> scanner := bufio.NewScanner(file)
</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 i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) </s> remove err = p.d.AddRule(text, uint32(i))
</s> add err = p.d.AddRule(text, filter.ID) </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 err := writeFilterFile()
if err != nil {
errortext := fmt.Sprintf("Couldn't write filter file: %s", err)
log.Println(errortext)
}
</s> add </s> remove return err
</s> add return nil </s> remove filter.LastUpdated = now
</s> add filter.LastUpdated = time.Now() | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep keep replace keep keep keep keep keep | <mask> scanner := bufio.NewScanner(file)
<mask> for scanner.Scan() {
<mask> text := scanner.Text()
<mask>
<mask> err = p.d.AddRule(text, uint32(i))
<mask> if err == dnsfilter.ErrAlreadyExists || err == dnsfilter.ErrInvalidSyntax {
<mask> continue
<mask> }
<mask> if err != nil {
<mask> log.Printf("Cannot add rule %s: %s", text, 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 = 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> add //noinspection GoDeferInLoop </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 updated, err := filter.update(now)
</s> add updated, err := filter.update(false) </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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep keep replace keep keep keep keep keep | <mask> continue
<mask> }
<mask> count++
<mask> }
<mask> log.Printf("Added %d rules from %s", count, filterFileName)
<mask>
<mask> if err = scanner.Err(); err != nil {
<mask> return nil, 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 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("filterFileNames = %+v", filterFileNames)
</s> add for _, filter := range p.settings.Filters {
log.Printf("Loading rules from %s", filter.Path) </s> remove for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) </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 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 rename filter file: %s", err)
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep add keep keep keep keep keep | <mask> }
<mask>
<mask> type statsFunc func(ch interface{}, name string, text string, value float64, valueType prometheus.ValueType)
<mask>
<mask> func doDesc(ch interface{}, name string, text string, value float64, valueType prometheus.ValueType) {
<mask> realch, ok := ch.(chan<- *prometheus.Desc)
<mask> if !ok {
<mask> log.Printf("Couldn't convert ch to chan<- *prometheus.Desc\n")
<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 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 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 </s> remove if value > high {
return high
</s> add err = os.Rename(tmpPath, path)
if err != nil {
return err </s> remove // extract filter name and count number of rules
</s> add // Extract filter name and count number of rules </s> remove return value
</s> add return nil </s> remove err = p.d.AddRule(text, uint32(i))
</s> add err = p.d.AddRule(text, filter.ID) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep keep keep keep replace keep keep keep keep keep | <mask>
<mask> func (p *plug) serveDNSInternal(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, dnsfilter.Result, error) {
<mask> if len(r.Question) != 1 {
<mask> // google DNS, bind and others do the same
<mask> return dns.RcodeFormatError, dnsfilter.Result{}, fmt.Errorf("Got DNS request with != 1 questions")
<mask> }
<mask> for _, question := range r.Question {
<mask> host := strings.ToLower(strings.TrimSuffix(question.Name, "."))
<mask> // is it a safesearch domain?
<mask> p.RLock()
</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 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 := writeConfig()
</s> add // Do the upgrade if necessary
err := upgradeConfig()
if err != nil {
log.Fatal(err)
}
// Save the updated config
err = writeConfig() </s> remove elapsed := time.Since(filter.LastUpdated)
if elapsed <= updatePeriod {
</s> add if !force && time.Since(filter.LastUpdated) <= updatePeriod { </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 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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin.go |
keep add keep keep keep keep keep keep | <mask> )
<mask>
<mask> func TestSetup(t *testing.T) {
<mask> for i, testcase := range []struct {
<mask> config string
<mask> failing bool
<mask> }{
<mask> {`dnsfilter`, false},
</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> add type plugFilter struct {
ID uint32
Path string
}
</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 for i, filterFileName := range filterFileNames {
file, err := os.Open(filterFileName)
</s> add file, err := os.Open(filter.Path) </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> add type coreDnsFilter struct {
ID int `yaml:"-"`
Path string `yaml:"-"`
}
</s> remove
"gopkg.in/yaml.v2"
</s> add | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | coredns_plugin/coredns_plugin_test.go |
keep keep keep add keep keep keep keep keep | <mask> "bufio"
<mask> "errors"
<mask> "fmt"
<mask> "io"
<mask> "net/http"
<mask> "os"
<mask> "path"
<mask> "path/filepath"
<mask> "runtime"
</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> add "path/filepath" </s> add "gopkg.in/yaml.v2" </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 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 </s> remove {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} {
</s> add {{if .ProtectionEnabled}}dnsfilter { </s> remove err = ioutil.WriteFile(configfile+".tmp", yamlText, 0644)
</s> add err = writeFileSafe(configfile, yamlText) | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | helpers.go |
keep keep keep add keep keep keep keep | <mask> "io/ioutil"
<mask> "net/http"
<mask> "os"
<mask> "path"
<mask> "runtime"
<mask> "strings"
<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> add "io/ioutil" </s> add "gopkg.in/yaml.v2" </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add </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
"gopkg.in/yaml.v2"
</s> add </s> add // TODO: Change tests -- there's new config template now | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | helpers.go |
keep keep keep replace replace replace keep replace replace keep | <mask> "strings"
<mask> )
<mask>
<mask> func clamp(value, low, high int) int {
<mask> if value < low {
<mask> return low
<mask> }
<mask> if value > high {
<mask> return high
<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 return value
</s> add return nil </s> add //noinspection GoUnusedParameter </s> remove err := writeFilterFile()
if err != nil {
errortext := fmt.Sprintf("Couldn't write filter file: %s", err)
log.Println(errortext)
}
</s> add </s> remove switch c.Val() {
</s> add blockValue := c.Val()
switch blockValue { </s> remove return err
</s> add return nil | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | helpers.go |
keep keep keep keep replace keep keep keep keep keep | <mask> }
<mask> if value > high {
<mask> return high
<mask> }
<mask> return value
<mask> }
<mask>
<mask> // ----------------------------------
<mask> // helper functions for HTTP handlers
<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 value > high {
return high
</s> add err = os.Rename(tmpPath, path)
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> add Filters: make([]plugFilter, 0), </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> add //noinspection GoUnusedParameter </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
| https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | helpers.go |
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep | <mask>
<mask> // ---------------------
<mask> // debug logging helpers
<mask> // ---------------------
<mask> func _Func() string {
<mask> pc := make([]uintptr, 10) // at least 1 entry needed
<mask> runtime.Callers(2, pc)
<mask> f := runtime.FuncForPC(pc[0])
<mask> return path.Base(f.Name())
<mask> }
<mask>
<mask> func trace(format string, args ...interface{}) {
<mask> pc := make([]uintptr, 10) // at least 1 entry needed
<mask> runtime.Callers(2, pc)
<mask> f := runtime.FuncForPC(pc[0])
<mask> var buf strings.Builder
</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 // eat all args so that coredns can start happily
</s> add // Eat all args so that coredns can start happily </s> remove return dns.RcodeFormatError, dnsfilter.Result{}, fmt.Errorf("Got DNS request with != 1 questions")
</s> add return dns.RcodeFormatError, dnsfilter.Result{}, fmt.Errorf("got a DNS request with more than one Question") </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> add // 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"
</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 | https://github.com/AdguardTeam/AdGuardHome/commit/32d4e80c93cba5b3ef4bb96c79f7256b5cb4d913 | helpers.go |
keep keep keep keep replace keep keep keep keep keep | <mask> // is not one of these, clientID is an empty string and err is nil.
<mask> func (s *Server) clientIDFromDNSContext(pctx *proxy.DNSContext) (clientID string, err error) {
<mask> proto := pctx.Proto
<mask> if proto == proxy.ProtoHTTPS {
<mask> return clientIDFromDNSContextHTTPS(pctx)
<mask> } else if proto != proxy.ProtoTLS && proto != proxy.ProtoQUIC {
<mask> return "", nil
<mask> }
<mask>
<mask> hostSrvName := s.conf.ServerName
</s> Pull request: 3418-clientid-doh
Closes #3418.
Squashed commit of the following:
commit 8a1180f8ef03d30ea3ae6a3e3121ddcac513f45b
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 17:26:22 2022 +0300
all: imp docs, tests
commit 9629c69b39540db119044f2f79c1c4ed39de911f
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 15:34:33 2022 +0300
dnsforward: accept clientids from doh client srvname </s> remove cliSrvName := ""
</s> add cliSrvName, err := clientServerName(pctx, proto)
if err != nil {
return "", err
}
clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
}
return clientID, nil
}
// clientServerName returns the TLS server name based on the protocol.
func clientServerName(pctx *proxy.DNSContext, proto proxy.Proto) (srvName string, err error) { </s> remove case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf(
"proxy ctx conn of proto %s is %T, want *tls.Conn",
proto,
conn,
)
</s> add case proxy.ProtoHTTPS:
if connState := pctx.HTTPRequest.TLS; connState != nil {
srvName = pctx.HTTPRequest.TLS.ServerName </s> remove return clientID, nil
</s> add return srvName, nil </s> remove pctx.QUICConnection,
</s> add qConn, </s> remove cliSrvName = conn.ConnectionState().TLS.ServerName
}
</s> add srvName = conn.ConnectionState().TLS.ServerName
case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf("proxy ctx conn of proto %s is %T, want *tls.Conn", proto, conn)
} </s> remove clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
</s> add srvName = tc.ConnectionState().ServerName | https://github.com/AdguardTeam/AdGuardHome/commit/330ac303242970d79b557e611bec3227b0af5a7b | internal/dnsforward/clientid.go |
keep replace keep replace replace replace replace replace replace replace replace replace keep keep | <mask>
<mask> cliSrvName := ""
<mask> switch proto {
<mask> case proxy.ProtoTLS:
<mask> conn := pctx.Conn
<mask> tc, ok := conn.(tlsConn)
<mask> if !ok {
<mask> return "", fmt.Errorf(
<mask> "proxy ctx conn of proto %s is %T, want *tls.Conn",
<mask> proto,
<mask> conn,
<mask> )
<mask> }
<mask>
</s> Pull request: 3418-clientid-doh
Closes #3418.
Squashed commit of the following:
commit 8a1180f8ef03d30ea3ae6a3e3121ddcac513f45b
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 17:26:22 2022 +0300
all: imp docs, tests
commit 9629c69b39540db119044f2f79c1c4ed39de911f
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 15:34:33 2022 +0300
dnsforward: accept clientids from doh client srvname </s> remove cliSrvName = conn.ConnectionState().TLS.ServerName
}
</s> add srvName = conn.ConnectionState().TLS.ServerName
case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf("proxy ctx conn of proto %s is %T, want *tls.Conn", proto, conn)
} </s> remove
cliSrvName = tc.ConnectionState().ServerName
</s> add </s> remove conn, ok := pctx.QUICConnection.(quicConnection)
</s> add qConn := pctx.QUICConnection
conn, ok := qConn.(quicConnection) </s> remove pctx.QUICConnection,
</s> add qConn, </s> remove return clientIDFromDNSContextHTTPS(pctx)
</s> add clientID, err = clientIDFromDNSContextHTTPS(pctx)
if err != nil {
return "", fmt.Errorf("checking url: %w", err)
} else if clientID != "" {
return clientID, nil
}
// Go on and check the domain name as well. | https://github.com/AdguardTeam/AdGuardHome/commit/330ac303242970d79b557e611bec3227b0af5a7b | internal/dnsforward/clientid.go |
keep keep keep replace replace keep replace keep | <mask> conn,
<mask> )
<mask> }
<mask>
<mask> cliSrvName = tc.ConnectionState().ServerName
<mask> case proxy.ProtoQUIC:
<mask> conn, ok := pctx.QUICConnection.(quicConnection)
<mask> if !ok {
</s> Pull request: 3418-clientid-doh
Closes #3418.
Squashed commit of the following:
commit 8a1180f8ef03d30ea3ae6a3e3121ddcac513f45b
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 17:26:22 2022 +0300
all: imp docs, tests
commit 9629c69b39540db119044f2f79c1c4ed39de911f
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 15:34:33 2022 +0300
dnsforward: accept clientids from doh client srvname </s> remove case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf(
"proxy ctx conn of proto %s is %T, want *tls.Conn",
proto,
conn,
)
</s> add case proxy.ProtoHTTPS:
if connState := pctx.HTTPRequest.TLS; connState != nil {
srvName = pctx.HTTPRequest.TLS.ServerName </s> add case proxy.ProtoTLS:
conn = testTLSConn{
serverName: tc.cliSrvName,
} </s> remove cliSrvName = conn.ConnectionState().TLS.ServerName
}
</s> add srvName = conn.ConnectionState().TLS.ServerName
case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf("proxy ctx conn of proto %s is %T, want *tls.Conn", proto, conn)
} </s> remove clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
</s> add srvName = tc.ConnectionState().ServerName </s> remove cliSrvName := ""
</s> add cliSrvName, err := clientServerName(pctx, proto)
if err != nil {
return "", err
}
clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
}
return clientID, nil
}
// clientServerName returns the TLS server name based on the protocol.
func clientServerName(pctx *proxy.DNSContext, proto proxy.Proto) (srvName string, err error) { | https://github.com/AdguardTeam/AdGuardHome/commit/330ac303242970d79b557e611bec3227b0af5a7b | internal/dnsforward/clientid.go |
keep keep keep keep replace keep keep keep replace replace keep keep | <mask> if !ok {
<mask> return "", fmt.Errorf(
<mask> "proxy ctx quic conn of proto %s is %T, want quic.Connection",
<mask> proto,
<mask> pctx.QUICConnection,
<mask> )
<mask> }
<mask>
<mask> cliSrvName = conn.ConnectionState().TLS.ServerName
<mask> }
<mask>
<mask> clientID, err = clientIDFromClientServerName(
</s> Pull request: 3418-clientid-doh
Closes #3418.
Squashed commit of the following:
commit 8a1180f8ef03d30ea3ae6a3e3121ddcac513f45b
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 17:26:22 2022 +0300
all: imp docs, tests
commit 9629c69b39540db119044f2f79c1c4ed39de911f
Author: Ainar Garipov <[email protected]>
Date: Wed Oct 5 15:34:33 2022 +0300
dnsforward: accept clientids from doh client srvname </s> remove
cliSrvName = tc.ConnectionState().ServerName
</s> add </s> remove conn, ok := pctx.QUICConnection.(quicConnection)
</s> add qConn := pctx.QUICConnection
conn, ok := qConn.(quicConnection) </s> remove case proxy.ProtoTLS:
conn := pctx.Conn
tc, ok := conn.(tlsConn)
if !ok {
return "", fmt.Errorf(
"proxy ctx conn of proto %s is %T, want *tls.Conn",
proto,
conn,
)
</s> add case proxy.ProtoHTTPS:
if connState := pctx.HTTPRequest.TLS; connState != nil {
srvName = pctx.HTTPRequest.TLS.ServerName </s> remove clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
</s> add srvName = tc.ConnectionState().ServerName </s> remove cliSrvName := ""
</s> add cliSrvName, err := clientServerName(pctx, proto)
if err != nil {
return "", err
}
clientID, err = clientIDFromClientServerName(
hostSrvName,
cliSrvName,
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("clientid check: %w", err)
}
return clientID, nil
}
// clientServerName returns the TLS server name based on the protocol.
func clientServerName(pctx *proxy.DNSContext, proto proxy.Proto) (srvName string, err error) { | https://github.com/AdguardTeam/AdGuardHome/commit/330ac303242970d79b557e611bec3227b0af5a7b | internal/dnsforward/clientid.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.