docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
sequencelengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
if lease.Expiry.Unix() <= now && lease.Expiry.Unix() != leaseExpireStatic {
<mask> // Find an expired lease and return its index or -1 <mask> func (s *Server) findExpiredLease() int { <mask> now := time.Now().Unix() <mask> for i, lease := range s.leases { <mask> if lease.Expiry.Unix() <= now { <mask> return i <mask> } <mask> } <mask> return -1 <mask> } </s> + dhcp: /dhcp/add_static_lease, /dhcp/remove_static_lease: control static lease table </s> remove Expiry time.Time `json:"expires"` </s> add // Lease expiration time // 1: static lease Expiry time.Time `json:"expires"`
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
dhcpd/dhcpd.go
github.com/AdguardTeam/urlfilter v0.15.1
<mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.39.13 <mask> github.com/AdguardTeam/golibs v0.10.3 <mask> github.com/AdguardTeam/urlfilter v0.15.0 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.2.2 <mask> github.com/digineo/go-ipset/v2 v2.2.1 <mask> github.com/fsnotify/fsnotify v1.4.9 <mask> github.com/go-ping/ping v0.0.0-20210506233800-ff8be3320020 </s> Pull request: all: do not apply $denyallow to ip addrs Closes #3175. Squashed commit of the following: commit e80e4610a1ce70787d758c718cc7171570bcdd72 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 18:03:26 2021 +0300 all: imp docs commit 3c73a727e91f7da3d4bbbbf9c019997af4bebd33 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 17:57:01 2021 +0300 all: do not apply $denyallow to ip addrs </s> remove github.com/AdguardTeam/urlfilter v0.15.0 h1:K3WWZE0K5nPTHe2l+TRXDFpYWJJnvkHdlWidt6NQUTk= github.com/AdguardTeam/urlfilter v0.15.0/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> add github.com/AdguardTeam/urlfilter v0.15.1 h1:dP6S7J6eFAk8MN4IDpUq2fZoBo8K8fmc6pXpxNIv84M= github.com/AdguardTeam/urlfilter v0.15.1/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> remove github.com/stretchr/objx v0.1.1 // indirect </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72a160ac59395cd700d270eaf7234c95c62533ea
go.mod
<mask> github.com/mdlayher/netlink v1.4.0 <mask> github.com/mdlayher/raw v0.0.0-20210412142147-51b895745faf <mask> github.com/miekg/dns v1.1.43 <mask> github.com/satori/go.uuid v1.2.0 <mask> github.com/stretchr/objx v0.1.1 // indirect <mask> github.com/stretchr/testify v1.7.0 <mask> github.com/ti-mo/netfilter v0.4.0 <mask> go.etcd.io/bbolt v1.3.6 <mask> golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 <mask> golang.org/x/net v0.0.0-20210929193557-e81a3d93ecf6 </s> Pull request: all: do not apply $denyallow to ip addrs Closes #3175. Squashed commit of the following: commit e80e4610a1ce70787d758c718cc7171570bcdd72 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 18:03:26 2021 +0300 all: imp docs commit 3c73a727e91f7da3d4bbbbf9c019997af4bebd33 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 17:57:01 2021 +0300 all: do not apply $denyallow to ip addrs </s> remove github.com/AdguardTeam/urlfilter v0.15.0 h1:K3WWZE0K5nPTHe2l+TRXDFpYWJJnvkHdlWidt6NQUTk= github.com/AdguardTeam/urlfilter v0.15.0/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> add github.com/AdguardTeam/urlfilter v0.15.1 h1:dP6S7J6eFAk8MN4IDpUq2fZoBo8K8fmc6pXpxNIv84M= github.com/AdguardTeam/urlfilter v0.15.1/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> remove github.com/AdguardTeam/urlfilter v0.15.0 </s> add github.com/AdguardTeam/urlfilter v0.15.1
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72a160ac59395cd700d270eaf7234c95c62533ea
go.mod
require github.com/stretchr/objx v0.1.1 // indirect
<mask> ) <mask> <mask> // TODO(e.burkov): Get rid of the fork in v0.108.0. <mask> replace github.com/insomniacslk/dhcp => github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf </s> Pull request: all: do not apply $denyallow to ip addrs Closes #3175. Squashed commit of the following: commit e80e4610a1ce70787d758c718cc7171570bcdd72 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 18:03:26 2021 +0300 all: imp docs commit 3c73a727e91f7da3d4bbbbf9c019997af4bebd33 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 17:57:01 2021 +0300 all: do not apply $denyallow to ip addrs </s> remove github.com/AdguardTeam/urlfilter v0.15.0 h1:K3WWZE0K5nPTHe2l+TRXDFpYWJJnvkHdlWidt6NQUTk= github.com/AdguardTeam/urlfilter v0.15.0/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> add github.com/AdguardTeam/urlfilter v0.15.1 h1:dP6S7J6eFAk8MN4IDpUq2fZoBo8K8fmc6pXpxNIv84M= github.com/AdguardTeam/urlfilter v0.15.1/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= </s> remove github.com/stretchr/objx v0.1.1 // indirect </s> add </s> remove github.com/AdguardTeam/urlfilter v0.15.0 </s> add github.com/AdguardTeam/urlfilter v0.15.1
[ "keep", "add", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72a160ac59395cd700d270eaf7234c95c62533ea
go.mod
github.com/AdguardTeam/urlfilter v0.15.1 h1:dP6S7J6eFAk8MN4IDpUq2fZoBo8K8fmc6pXpxNIv84M= github.com/AdguardTeam/urlfilter v0.15.1/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU=
<mask> github.com/AdguardTeam/golibs v0.9.2/go.mod h1:fCAMwPBJ8S7YMYbTWvYS+eeTLblP5E04IDtNAo7y7IY= <mask> github.com/AdguardTeam/golibs v0.10.3 h1:FBgk17zf35ESVWQKIqEUiqqB2bDaCBC8X5vMU760yB4= <mask> github.com/AdguardTeam/golibs v0.10.3/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= <mask> github.com/AdguardTeam/urlfilter v0.15.0 h1:K3WWZE0K5nPTHe2l+TRXDFpYWJJnvkHdlWidt6NQUTk= <mask> github.com/AdguardTeam/urlfilter v0.15.0/go.mod h1:EwXwrYhowP7bedqmOrmKKmQtpBYFyDNEBFQ+lxdUgQU= <mask> github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= <mask> github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= <mask> github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= <mask> github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= <mask> github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= </s> Pull request: all: do not apply $denyallow to ip addrs Closes #3175. Squashed commit of the following: commit e80e4610a1ce70787d758c718cc7171570bcdd72 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 18:03:26 2021 +0300 all: imp docs commit 3c73a727e91f7da3d4bbbbf9c019997af4bebd33 Author: Ainar Garipov <[email protected]> Date: Tue Dec 14 17:57:01 2021 +0300 all: do not apply $denyallow to ip addrs </s> remove github.com/stretchr/objx v0.1.1 // indirect </s> add </s> remove github.com/AdguardTeam/urlfilter v0.15.0 </s> add github.com/AdguardTeam/urlfilter v0.15.1
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72a160ac59395cd700d270eaf7234c95c62533ea
go.sum
<mask> .logs__row:hover .button-action, <mask> .button-action--active { <mask> visibility: visible; <mask> } <mask> <mask> @media (max-width: 500px) { <mask> .dashboard .button-action { <mask> visibility: visible; <mask> } <mask> } </s> - client: 2152 Do not show dashboard buttons on mobile screen, fix buttons on DNS block/allow lists pages </s> remove > <Trans>check_updates_btn</Trans> </button> </div> ); </s> add > <Trans>check_updates_btn</Trans> </button> </div>; </s> remove }) => ( <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large" </s> add }) => <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large mb-2" </s> remove > {whitelist ? ( <Trans>add_allowlist</Trans> ) : ( <Trans>add_blocklist</Trans> )} </button> <button className="btn btn-primary btn-standard" </s> add > {whitelist ? <Trans>add_allowlist</Trans> : <Trans>add_blocklist</Trans>} </button> <button className="btn btn-primary btn-standard mb-2"
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72ab51bce0dd0b892acc797689f0cd32d779fd9f
client/src/components/App/index.css
}) => <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large mb-2"
<mask> import { withTranslation, Trans } from 'react-i18next'; <mask> <mask> const Actions = ({ <mask> handleAdd, handleRefresh, processingRefreshFilters, whitelist, <mask> }) => ( <mask> <div className="card-actions"> <mask> <button <mask> className="btn btn-success btn-standard mr-2 btn-large" <mask> type="submit" <mask> onClick={handleAdd} <mask> > <mask> {whitelist ? ( <mask> <Trans>add_allowlist</Trans> </s> - client: 2152 Do not show dashboard buttons on mobile screen, fix buttons on DNS block/allow lists pages </s> remove > <Trans>check_updates_btn</Trans> </button> </div> ); </s> add > <Trans>check_updates_btn</Trans> </button> </div>; </s> remove > {whitelist ? ( <Trans>add_allowlist</Trans> ) : ( <Trans>add_blocklist</Trans> )} </button> <button className="btn btn-primary btn-standard" </s> add > {whitelist ? <Trans>add_allowlist</Trans> : <Trans>add_blocklist</Trans>} </button> <button className="btn btn-primary btn-standard mb-2" </s> remove @media (max-width: 500px) { .dashboard .button-action { visibility: visible; } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72ab51bce0dd0b892acc797689f0cd32d779fd9f
client/src/components/Filters/Actions.js
> {whitelist ? <Trans>add_allowlist</Trans> : <Trans>add_blocklist</Trans>} </button> <button className="btn btn-primary btn-standard mb-2"
<mask> <button <mask> className="btn btn-success btn-standard mr-2 btn-large" <mask> type="submit" <mask> onClick={handleAdd} <mask> > <mask> {whitelist ? ( <mask> <Trans>add_allowlist</Trans> <mask> ) : ( <mask> <Trans>add_blocklist</Trans> <mask> )} <mask> </button> <mask> <button <mask> className="btn btn-primary btn-standard" <mask> type="submit" <mask> onClick={handleRefresh} <mask> disabled={processingRefreshFilters} <mask> > <mask> <Trans>check_updates_btn</Trans> </s> - client: 2152 Do not show dashboard buttons on mobile screen, fix buttons on DNS block/allow lists pages </s> remove > <Trans>check_updates_btn</Trans> </button> </div> ); </s> add > <Trans>check_updates_btn</Trans> </button> </div>; </s> remove }) => ( <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large" </s> add }) => <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large mb-2" </s> remove @media (max-width: 500px) { .dashboard .button-action { visibility: visible; } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72ab51bce0dd0b892acc797689f0cd32d779fd9f
client/src/components/Filters/Actions.js
> <Trans>check_updates_btn</Trans> </button> </div>;
<mask> className="btn btn-primary btn-standard" <mask> type="submit" <mask> onClick={handleRefresh} <mask> disabled={processingRefreshFilters} <mask> > <mask> <Trans>check_updates_btn</Trans> <mask> </button> <mask> </div> <mask> ); <mask> <mask> Actions.propTypes = { <mask> handleAdd: PropTypes.func.isRequired, <mask> handleRefresh: PropTypes.func.isRequired, <mask> processingRefreshFilters: PropTypes.bool.isRequired, </s> - client: 2152 Do not show dashboard buttons on mobile screen, fix buttons on DNS block/allow lists pages </s> remove > {whitelist ? ( <Trans>add_allowlist</Trans> ) : ( <Trans>add_blocklist</Trans> )} </button> <button className="btn btn-primary btn-standard" </s> add > {whitelist ? <Trans>add_allowlist</Trans> : <Trans>add_blocklist</Trans>} </button> <button className="btn btn-primary btn-standard mb-2" </s> remove }) => ( <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large" </s> add }) => <div className="card-actions"> <button className="btn btn-success btn-standard mr-2 btn-large mb-2" </s> remove @media (max-width: 500px) { .dashboard .button-action { visibility: visible; } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72ab51bce0dd0b892acc797689f0cd32d779fd9f
client/src/components/Filters/Actions.js
// This callback function returns the list of upstream servers for a client specified by IP address GetUpstreamsByClient func(clientAddr string) []string `yaml:"-"`
<mask> type FilteringConfig struct { <mask> // Filtering callback function <mask> FilterHandler func(clientAddr string, settings *dnsfilter.RequestFilteringSettings) `yaml:"-"` <mask> <mask> ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features <mask> <mask> BlockingMode string `yaml:"blocking_mode"` // mode how to answer filtered requests <mask> BlockedResponseTTL uint32 `yaml:"blocked_response_ttl"` // if 0, then default is used (3600) <mask> Ratelimit int `yaml:"ratelimit"` // max number of requests per second from a given IP (0 to disable) </s> + use per-client DNS servers </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward.go
if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP, _, _ := net.SplitHostPort(d.Addr.String()) upstreams := s.conf.GetUpstreamsByClient(clientIP) for _, us := range upstreams { u, err := upstream.AddressToUpstream(us, upstream.Options{Timeout: 30 * time.Second}) if err != nil { log.Error("upstream.AddressToUpstream: %s: %s", us, err) continue } d.Upstreams = append(d.Upstreams, u) } }
<mask> // resolve canonical name, not the original host name <mask> d.Req.Question[0].Name = dns.Fqdn(res.CanonName) <mask> } <mask> <mask> // request was not filtered so let it be processed further <mask> err = p.Resolve(d) <mask> if err != nil { <mask> return err <mask> } </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err = validateUpstreams(req.Upstreams) </s> add err = ValidateUpstreams(req.Upstreams)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward.go
err = ValidateUpstreams(req.Upstreams)
<mask> httpError(r, w, http.StatusBadRequest, "Failed to parse new upstreams config json: %s", err) <mask> return <mask> } <mask> <mask> err = validateUpstreams(req.Upstreams) <mask> if err != nil { <mask> httpError(r, w, http.StatusBadRequest, "wrong upstreams specification: %s", err) <mask> return <mask> } <mask> </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward_http.go
// ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
<mask> return <mask> } <mask> } <mask> <mask> // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified <mask> func validateUpstreams(upstreams []string) error { <mask> var defaultUpstreamFound bool <mask> for _, u := range upstreams { <mask> d, err := validateUpstream(u) <mask> if err != nil { <mask> return err </s> + use per-client DNS servers </s> remove err := validateUpstreams(upstreamsSet) </s> add err := ValidateUpstreams(upstreamsSet) </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward_http.go
err := ValidateUpstreams(upstreamsSet)
<mask> "[/www.host.com/]#", <mask> "[/host.com/google.com/]8.8.8.8", <mask> "[/host/]sdns://AQMAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20", <mask> } <mask> err := validateUpstreams(upstreamsSet) <mask> if err == nil { <mask> t.Fatalf("there is no default upstream") <mask> } <mask> <mask> // Let's add default upstream </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward_test.go
err = ValidateUpstreams(upstreamsSet)
<mask> } <mask> <mask> // Let's add default upstream <mask> upstreamsSet = append(upstreamsSet, "8.8.8.8") <mask> err = validateUpstreams(upstreamsSet) <mask> if err != nil { <mask> t.Fatalf("upstreams set is valid, but doesn't pass through validation cause: %s", err) <mask> } <mask> <mask> // Let's add invalid upstream </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err := validateUpstreams(upstreamsSet) </s> add err := ValidateUpstreams(upstreamsSet) </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward_test.go
err = ValidateUpstreams(upstreamsSet)
<mask> } <mask> <mask> // Let's add invalid upstream <mask> upstreamsSet = append(upstreamsSet, "dhcp://fake.dns") <mask> err = validateUpstreams(upstreamsSet) <mask> if err == nil { <mask> t.Fatalf("there is an invalid upstream in set, but it pass through validation") <mask> } <mask> } </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet) </s> remove err := validateUpstreams(upstreamsSet) </s> add err := ValidateUpstreams(upstreamsSet) </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
dnsforward/dnsforward_test.go
"github.com/AdguardTeam/AdGuardHome/dnsforward"
<mask> "sync" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dhcpd" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/utils" <mask> ) <mask> </s> + use per-client DNS servers </s> remove err = validateUpstreams(req.Upstreams) </s> add err = ValidateUpstreams(req.Upstreams) </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
Upstreams []string // list of upstream servers to be used for the client's requests
<mask> WhoisInfo [][]string // [[key,value], ...] <mask> <mask> UseOwnBlockedServices bool // false: use global settings <mask> BlockedServices []string <mask> } <mask> <mask> type clientSource uint <mask> <mask> // Client sources </s> + use per-client DNS servers </s> remove err = validateUpstreams(upstreamsSet) </s> add err = ValidateUpstreams(upstreamsSet)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
Upstreams []string `yaml:"upstreams"`
<mask> SafeBrowsingEnabled bool `yaml:"safesearch_enabled"` <mask> <mask> UseGlobalBlockedServices bool `yaml:"use_global_blocked_services"` <mask> BlockedServices []string `yaml:"blocked_services"` <mask> } <mask> <mask> func (clients *clientsContainer) addFromConfig(objects []clientObject) { <mask> for _, cy := range objects { </s> + use per-client DNS servers </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
Upstreams: cy.Upstreams,
<mask> SafeBrowsingEnabled: cy.SafeBrowsingEnabled, <mask> <mask> UseOwnBlockedServices: !cy.UseGlobalBlockedServices, <mask> BlockedServices: cy.BlockedServices, <mask> } <mask> _, err := clients.Add(cli) <mask> if err != nil { <mask> log.Tracef("clientAdd: %s", err) <mask> } </s> + use per-client DNS servers </s> remove err = validateUpstreams(req.Upstreams) </s> add err = ValidateUpstreams(req.Upstreams)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
Upstreams: cli.Upstreams,
<mask> SafeBrowsingEnabled: cli.SafeBrowsingEnabled, <mask> <mask> UseGlobalBlockedServices: !cli.UseOwnBlockedServices, <mask> BlockedServices: cli.BlockedServices, <mask> } <mask> *objects = append(*objects, cy) <mask> } <mask> } <mask> <mask> func (clients *clientsContainer) periodicUpdate() { </s> + use per-client DNS servers
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
if len(c.Upstreams) != 0 { err := dnsforward.ValidateUpstreams(c.Upstreams) if err != nil { return fmt.Errorf("Invalid upstream servers: %s", err) } }
<mask> return fmt.Errorf("Invalid ID: %s", id) <mask> } <mask> return nil <mask> } <mask> <mask> // Add a new client object </s> + use per-client DNS servers </s> remove err = validateUpstreams(req.Upstreams) </s> add err = ValidateUpstreams(req.Upstreams)
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients.go
Upstreams []string `json:"upstreams"`
<mask> <mask> UseGlobalBlockedServices bool `json:"use_global_blocked_services"` <mask> BlockedServices []string `json:"blocked_services"` <mask> } <mask> <mask> type clientHostJSON struct { <mask> IP string `json:"ip"` </s> + use per-client DNS servers
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients_http.go
Upstreams: cj.Upstreams,
<mask> <mask> UseOwnBlockedServices: !cj.UseGlobalBlockedServices, <mask> BlockedServices: cj.BlockedServices, <mask> } <mask> return &c, nil <mask> } <mask> <mask> // Convert Client object to JSON <mask> func clientToJSON(c *Client) clientJSON { </s> + use per-client DNS servers
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients_http.go
Upstreams: c.Upstreams,
<mask> SafeBrowsingEnabled: c.SafeBrowsingEnabled, <mask> <mask> UseGlobalBlockedServices: !c.UseOwnBlockedServices, <mask> BlockedServices: c.BlockedServices, <mask> } <mask> <mask> cj.WhoisInfo = make(map[string]interface{}) <mask> for _, wi := range c.WhoisInfo { <mask> cj.WhoisInfo[wi[0]] = wi[1] <mask> } </s> + use per-client DNS servers
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/clients_http.go
newconfig.GetUpstreamsByClient = getUpstreamsByClient
<mask> } <mask> } <mask> <mask> newconfig.FilterHandler = applyAdditionalFiltering <mask> return newconfig, nil <mask> } <mask> <mask> func getUpstreamsByClient(clientAddr string) []string { <mask> c, ok := config.clients.Find(clientAddr) </s> + use per-client DNS servers
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/dns.go
func getUpstreamsByClient(clientAddr string) []string { c, ok := config.clients.Find(clientAddr) if !ok { return []string{} } log.Debug("Using upstreams %v for client %s (IP: %s)", c.Upstreams, c.Name, clientAddr) return c.Upstreams }
<mask> return newconfig, nil <mask> } <mask> <mask> // If a client has his own settings, apply them <mask> func applyAdditionalFiltering(clientAddr string, setts *dnsfilter.RequestFilteringSettings) { <mask> <mask> ApplyBlockedServices(setts, config.DNS.BlockedServices) <mask> </s> + use per-client DNS servers </s> remove // validateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func validateUpstreams(upstreams []string) error { </s> add // ValidateUpstreams validates each upstream and returns an error if any upstream is invalid or if there are no default upstreams specified func ValidateUpstreams(upstreams []string) error {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/7313c3bc5387cdc77f9f688e846a4a4aca5b1ec8
home/dns.go
var _ wrapper = &manyError{}
<mask> } <mask> <mask> func TestError_Unwrap(t *testing.T) { <mask> const ( <mask> errSimple = iota <mask> errWrapped <mask> errNil </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove // // stats // // GetStats return dns filtering stats since startup. func (d *Dnsfilter) GetStats() Stats { return gctx.stats } </s> add </s> remove // NotFilteredError - there was a transitive error during check NotFilteredError </s> add </s> remove func FuncName() 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 "log" </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/agherr/agherr_test.go
<mask> // NotFilteredNotFound - host was not find in any checks, default value for result <mask> NotFilteredNotFound Reason = iota <mask> // NotFilteredWhiteList - the host is explicitly whitelisted <mask> NotFilteredWhiteList <mask> // NotFilteredError - there was a transitive error during check <mask> NotFilteredError <mask> <mask> // reasons for filtering <mask> <mask> // FilteredBlackList - the host was matched to be advertising host <mask> FilteredBlackList </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove func FuncName() 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 "path" </s> add </s> remove // // stats // // GetStats return dns filtering stats since startup. func (d *Dnsfilter) GetStats() Stats { return gctx.stats } </s> add </s> remove "log" </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/dnsfilter/dnsfilter.go
<mask> d.registerRewritesHandlers() <mask> d.registerBlockedServicesHandlers() <mask> } <mask> } <mask> <mask> // <mask> // stats <mask> // <mask> <mask> // GetStats return dns filtering stats since startup. <mask> func (d *Dnsfilter) GetStats() Stats { <mask> return gctx.stats <mask> } </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove func FuncName() 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 // NotFilteredError - there was a transitive error during check NotFilteredError </s> add </s> remove "path" </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/dnsfilter/dnsfilter.go
<mask> <mask> package sysutil <mask> <mask> import ( <mask> "log" <mask> "log/syslog" <mask> ) <mask> <mask> func configureSyslog(serviceName string) error { <mask> w, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_USER, serviceName) </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove "log" </s> add </s> remove func FuncName() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/sysutil/syslog_others.go
"github.com/AdguardTeam/golibs/log"
<mask> package sysutil <mask> <mask> import ( <mask> "log/syslog" <mask> ) <mask> <mask> func configureSyslog(serviceName string) error { <mask> w, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_USER, serviceName) <mask> if err != nil { </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove "log" </s> add </s> remove "log" </s> add </s> remove func FuncName() 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 "path" </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/sysutil/syslog_others.go
<mask> <mask> package sysutil <mask> <mask> import ( <mask> "log" <mask> "strings" <mask> <mask> "golang.org/x/sys/windows" <mask> "golang.org/x/sys/windows/svc/eventlog" <mask> ) </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove "log" </s> add </s> remove "path" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/sysutil/syslog_windows.go
"github.com/AdguardTeam/golibs/log"
<mask> <mask> import ( <mask> "strings" <mask> <mask> "golang.org/x/sys/windows" <mask> "golang.org/x/sys/windows/svc/eventlog" <mask> ) <mask> </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove "log" </s> add </s> remove "path" </s> add </s> remove "log" </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/sysutil/syslog_windows.go
<mask> "fmt" <mask> "io/ioutil" <mask> "os" <mask> "os/exec" <mask> "path" <mask> "runtime" <mask> "strings" <mask> ) <mask> <mask> // ContainsString checks if string is in the slice of strings. </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove func FuncName() 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 // NotFilteredError - there was a transitive error during check NotFilteredError </s> add </s> remove "log" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/util/helpers.go
<mask> <mask> return cmd.ProcessState.ExitCode(), string(out), nil <mask> } <mask> <mask> func FuncName() 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> // SplitNext - split string by a byte and return the first chunk <mask> // Skip empty chunks <mask> // Whitespace is trimmed <mask> func SplitNext(str *string, splitBy byte) string { <mask> i := strings.IndexByte(*str, splitBy) </s> Pull request: all: fix lint and naming issues vol. 4 Merge in DNS/adguard-home from 2276-fix-lint-4 to master Updates #2276. Squashed commit of the following: commit 15d49184cd8ce1f8701bf3221e69418ca1778b36 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:51:34 2020 +0300 util: fix naming commit 3b9a86a0feb8c6e0b167e6e23105e8137b0dda76 Author: Ainar Garipov <[email protected]> Date: Tue Dec 8 15:41:10 2020 +0300 all: fix lint and naming issues vol. 4 </s> remove // // stats // // GetStats return dns filtering stats since startup. func (d *Dnsfilter) GetStats() Stats { return gctx.stats } </s> add </s> remove "path" </s> add </s> remove // NotFilteredError - there was a transitive error during check NotFilteredError </s> add </s> remove "log" </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73c30590e015f55e3de0a01f98a3c79761dce3b7
internal/util/helpers.go
// Copy installation parameters between two configuration objects func copyInstallSettings(dst *configuration, src *configuration) { dst.BindHost = src.BindHost dst.BindPort = src.BindPort dst.DNS.BindHost = src.DNS.BindHost dst.DNS.Port = src.DNS.Port dst.AuthName = src.AuthName dst.AuthPass = src.AuthPass }
<mask> } <mask> <mask> // Apply new configuration, start DNS server, restart Web server <mask> func handleInstallConfigure(w http.ResponseWriter, r *http.Request) { <mask> log.Tracef("%s %v", r.Method, r.URL) <mask> newSettings := applyConfigReq{} </s> * control: /install/configure: reset configuration back to its current state on error </s> remove if config.DNS.Port != 0 { err = startDNSServer() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } </s> add err = startDNSServer() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } err = config.write() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) return </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73fbe8b95aca6092b0beb7327a9c811a32464bcc
control.go
var curConfig configuration copyInstallSettings(&curConfig, &config)
<mask> return <mask> } <mask> <mask> config.firstRun = false <mask> config.BindHost = newSettings.Web.IP <mask> config.BindPort = newSettings.Web.Port <mask> config.DNS.BindHost = newSettings.DNS.IP <mask> config.DNS.Port = newSettings.DNS.Port </s> * control: /install/configure: reset configuration back to its current state on error </s> remove if config.DNS.Port != 0 { err = startDNSServer() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } </s> add err = startDNSServer() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } err = config.write() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) return </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73fbe8b95aca6092b0beb7327a9c811a32464bcc
control.go
err = startDNSServer() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } err = config.write() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) return
<mask> config.DNS.Port = newSettings.DNS.Port <mask> config.AuthName = newSettings.Username <mask> config.AuthPass = newSettings.Password <mask> <mask> if config.DNS.Port != 0 { <mask> err = startDNSServer() <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) <mask> return <mask> } <mask> } <mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> // this needs to be done in a goroutine because Shutdown() is a blocking call, and it will block <mask> // until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely </s> * control: /install/configure: reset configuration back to its current state on error </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73fbe8b95aca6092b0beb7327a9c811a32464bcc
control.go
<mask> return <mask> } <mask> } <mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> // this needs to be done in a goroutine because Shutdown() is a blocking call, and it will block <mask> // until all requests are finished, and _we_ are inside a request right now, so it will block indefinitely <mask> if restartHTTP { <mask> go func() { <mask> httpServer.Shutdown(context.TODO()) </s> * control: /install/configure: reset configuration back to its current state on error </s> remove if config.DNS.Port != 0 { err = startDNSServer() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } </s> add err = startDNSServer() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } err = config.write() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) return
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73fbe8b95aca6092b0beb7327a9c811a32464bcc
control.go
returnOK(w)
<mask> }() <mask> } <mask> } <mask> <mask> // -------------- <mask> // DNS-over-HTTPS <mask> // -------------- <mask> func handleDOH(w http.ResponseWriter, r *http.Request) { </s> * control: /install/configure: reset configuration back to its current state on error </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add </s> remove if config.DNS.Port != 0 { err = startDNSServer() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } </s> add err = startDNSServer() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err) return } err = config.write() if err != nil { config.firstRun = true copyInstallSettings(&config, &curConfig) httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) return
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/73fbe8b95aca6092b0beb7327a9c811a32464bcc
control.go
"encoding/json"
<mask> package querylog <mask> <mask> import ( <mask> "fmt" <mask> "math" <mask> "net" <mask> "net/http" </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove type qlogConfig struct { // Use float64 here to support fractional numbers and not mess the API // users by changing the units. Interval float64 `json:"interval"` Enabled bool `json:"enabled"` AnonymizeClientIP bool `json:"anonymize_client_ip"` </s> add // configJSON is the JSON structure for the querylog configuration. type configJSON struct { // Interval is the querylog rotation interval. Use float64 here to support // fractional numbers and not mess the API users by changing the units. Interval float64 `json:"interval"` // Enabled shows if the querylog is enabled. It is an [aghalg.NullBool] // to be able to tell when it's set without using pointers. Enabled aghalg.NullBool `json:"enabled"` // AnonymizeClientIP shows if the clients' IP addresses must be anonymized. // It is an [aghalg.NullBool] to be able to tell when it's set without using // pointers. AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"` </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("interval") { </s> add if hasIvl { </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
"math"
<mask> <mask> import ( <mask> "encoding/json" <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "net/url" <mask> "strconv" <mask> "strings" <mask> "time" </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove "github.com/AdguardTeam/golibs/jsonutil" </s> add </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("interval") { </s> add if hasIvl {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
<mask> "strconv" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> "github.com/AdguardTeam/golibs/timeutil" </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove "github.com/AdguardTeam/golibs/jsonutil" </s> add </s> remove type qlogConfig struct { // Use float64 here to support fractional numbers and not mess the API // users by changing the units. Interval float64 `json:"interval"` Enabled bool `json:"enabled"` AnonymizeClientIP bool `json:"anonymize_client_ip"` </s> add // configJSON is the JSON structure for the querylog configuration. type configJSON struct { // Interval is the querylog rotation interval. Use float64 here to support // fractional numbers and not mess the API users by changing the units. Interval float64 `json:"interval"` // Enabled shows if the querylog is enabled. It is an [aghalg.NullBool] // to be able to tell when it's set without using pointers. Enabled aghalg.NullBool `json:"enabled"` // AnonymizeClientIP shows if the clients' IP addresses must be anonymized. // It is an [aghalg.NullBool] to be able to tell when it's set without using // pointers. AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"` </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("interval") { </s> add if hasIvl {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
<mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/jsonutil" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> "github.com/AdguardTeam/golibs/timeutil" <mask> "golang.org/x/net/idna" <mask> ) </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove type qlogConfig struct { // Use float64 here to support fractional numbers and not mess the API // users by changing the units. Interval float64 `json:"interval"` Enabled bool `json:"enabled"` AnonymizeClientIP bool `json:"anonymize_client_ip"` </s> add // configJSON is the JSON structure for the querylog configuration. type configJSON struct { // Interval is the querylog rotation interval. Use float64 here to support // fractional numbers and not mess the API users by changing the units. Interval float64 `json:"interval"` // Enabled shows if the querylog is enabled. It is an [aghalg.NullBool] // to be able to tell when it's set without using pointers. Enabled aghalg.NullBool `json:"enabled"` // AnonymizeClientIP shows if the clients' IP addresses must be anonymized. // It is an [aghalg.NullBool] to be able to tell when it's set without using // pointers. AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"` </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("interval") { </s> add if hasIvl {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
// configJSON is the JSON structure for the querylog configuration. type configJSON struct { // Interval is the querylog rotation interval. Use float64 here to support // fractional numbers and not mess the API users by changing the units. Interval float64 `json:"interval"` // Enabled shows if the querylog is enabled. It is an [aghalg.NullBool] // to be able to tell when it's set without using pointers. Enabled aghalg.NullBool `json:"enabled"` // AnonymizeClientIP shows if the clients' IP addresses must be anonymized. // It is an [aghalg.NullBool] to be able to tell when it's set without using // pointers. AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"`
<mask> "github.com/AdguardTeam/golibs/timeutil" <mask> "golang.org/x/net/idna" <mask> ) <mask> <mask> type qlogConfig struct { <mask> // Use float64 here to support fractional numbers and not mess the API <mask> // users by changing the units. <mask> Interval float64 `json:"interval"` <mask> Enabled bool `json:"enabled"` <mask> AnonymizeClientIP bool `json:"anonymize_client_ip"` <mask> } <mask> <mask> // Register web handlers <mask> func (l *queryLog) initWeb() { <mask> l.conf.HTTPRegister(http.MethodGet, "/control/querylog", l.handleQueryLog) </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove AnonymizeClientIP: l.conf.AnonymizeClientIP, } _ = aghhttp.WriteJSONResponse(w, r, resp) </s> add AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), }) </s> remove "github.com/AdguardTeam/golibs/jsonutil" </s> add </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
_ = aghhttp.WriteJSONResponse(w, r, configJSON{ Enabled: aghalg.BoolToNullBool(l.conf.Enabled),
<mask> } <mask> <mask> // Get configuration <mask> func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) { <mask> resp := qlogConfig{ <mask> Enabled: l.conf.Enabled, <mask> Interval: l.conf.RotationIvl.Hours() / 24, <mask> AnonymizeClientIP: l.conf.AnonymizeClientIP, <mask> } <mask> <mask> _ = aghhttp.WriteJSONResponse(w, r, resp) </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove AnonymizeClientIP: l.conf.AnonymizeClientIP, } _ = aghhttp.WriteJSONResponse(w, r, resp) </s> add AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), }) </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove if req.Exists("interval") { </s> add if hasIvl { </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), })
<mask> func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) { <mask> resp := qlogConfig{ <mask> Enabled: l.conf.Enabled, <mask> Interval: l.conf.RotationIvl.Hours() / 24, <mask> AnonymizeClientIP: l.conf.AnonymizeClientIP, <mask> } <mask> <mask> _ = aghhttp.WriteJSONResponse(w, r, resp) <mask> } <mask> <mask> // AnonymizeIP masks ip to anonymize the client if the ip is a valid one. <mask> func AnonymizeIP(ip net.IP) { <mask> // zeroes is a slice of zero bytes from which the IP address tail is copied. </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove resp := qlogConfig{ Enabled: l.conf.Enabled, </s> add _ = aghhttp.WriteJSONResponse(w, r, configJSON{ Enabled: aghalg.BoolToNullBool(l.conf.Enabled), </s> remove type qlogConfig struct { // Use float64 here to support fractional numbers and not mess the API // users by changing the units. Interval float64 `json:"interval"` Enabled bool `json:"enabled"` AnonymizeClientIP bool `json:"anonymize_client_ip"` </s> add // configJSON is the JSON structure for the querylog configuration. type configJSON struct { // Interval is the querylog rotation interval. Use float64 here to support // fractional numbers and not mess the API users by changing the units. Interval float64 `json:"interval"` // Enabled shows if the querylog is enabled. It is an [aghalg.NullBool] // to be able to tell when it's set without using pointers. Enabled aghalg.NullBool `json:"enabled"` // AnonymizeClientIP shows if the clients' IP addresses must be anonymized. // It is an [aghalg.NullBool] to be able to tell when it's set without using // pointers. AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"` </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
// handleQueryLogConfig handles the POST /control/querylog_config queries.
<mask> copy(ip[net.IPv6len-10:net.IPv6len], zeroes) <mask> } <mask> } <mask> <mask> // Set configuration <mask> func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request) { <mask> d := &qlogConfig{} <mask> req, err := jsonutil.DecodeObject(d, r.Body) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove ivl := time.Duration(float64(timeutil.Day) * d.Interval) if req.Exists("interval") && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") </s> add ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval") </s> remove resp := qlogConfig{ Enabled: l.conf.Enabled, </s> add _ = aghhttp.WriteJSONResponse(w, r, configJSON{ Enabled: aghalg.BoolToNullBool(l.conf.Enabled), </s> remove AnonymizeClientIP: l.conf.AnonymizeClientIP, } _ = aghhttp.WriteJSONResponse(w, r, resp) </s> add AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), }) </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
// Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf)
<mask> } <mask> <mask> // Set configuration <mask> func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request) { <mask> d := &qlogConfig{} <mask> req, err := jsonutil.DecodeObject(d, r.Body) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) <mask> <mask> return <mask> } </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove ivl := time.Duration(float64(timeutil.Day) * d.Interval) if req.Exists("interval") && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") </s> add ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval") </s> remove resp := qlogConfig{ Enabled: l.conf.Enabled, </s> add _ = aghhttp.WriteJSONResponse(w, r, configJSON{ Enabled: aghalg.BoolToNullBool(l.conf.Enabled), </s> remove AnonymizeClientIP: l.conf.AnonymizeClientIP, } _ = aghhttp.WriteJSONResponse(w, r, resp) </s> add AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), }) </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval")
<mask> <mask> return <mask> } <mask> <mask> ivl := time.Duration(float64(timeutil.Day) * d.Interval) <mask> if req.Exists("interval") && !checkInterval(ivl) { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") <mask> <mask> return <mask> } <mask> <mask> defer l.conf.ConfigModified() </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove if req.Exists("interval") { </s> add if hasIvl { </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue
<mask> <mask> // Copy data, modify it, then activate. Other threads (readers) don't need <mask> // to use this lock. <mask> conf := *l.conf <mask> if req.Exists("enabled") { <mask> conf.Enabled = d.Enabled <mask> } <mask> if req.Exists("interval") { <mask> conf.RotationIvl = ivl <mask> } <mask> if req.Exists("anonymize_client_ip") { </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove if req.Exists("interval") { </s> add if hasIvl { </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove ivl := time.Duration(float64(timeutil.Day) * d.Interval) if req.Exists("interval") && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") </s> add ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval") </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove AnonymizeClientIP: l.conf.AnonymizeClientIP, } _ = aghhttp.WriteJSONResponse(w, r, resp) </s> add AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP), })
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
if hasIvl {
<mask> conf := *l.conf <mask> if req.Exists("enabled") { <mask> conf.Enabled = d.Enabled <mask> } <mask> if req.Exists("interval") { <mask> conf.RotationIvl = ivl <mask> } <mask> if req.Exists("anonymize_client_ip") { <mask> if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { <mask> l.anonymizer.Store(AnonymizeIP) </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove if req.Exists("anonymize_client_ip") { if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { </s> add if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP { </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue </s> remove ivl := time.Duration(float64(timeutil.Day) * d.Interval) if req.Exists("interval") && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") </s> add ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval") </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf) </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
if newConf.AnonymizeClientIP != aghalg.NBNull { conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue if conf.AnonymizeClientIP {
<mask> } <mask> if req.Exists("interval") { <mask> conf.RotationIvl = ivl <mask> } <mask> if req.Exists("anonymize_client_ip") { <mask> if conf.AnonymizeClientIP = d.AnonymizeClientIP; conf.AnonymizeClientIP { <mask> l.anonymizer.Store(AnonymizeIP) <mask> } else { <mask> l.anonymizer.Store(nil) <mask> } <mask> } </s> Pull request: rm-jsonutil Merge in DNS/adguard-home from rm-jsonutil to master Squashed commit of the following: commit dec746d321adbeb41bfd0c44e71d198809c4731e Author: Ainar Garipov <[email protected]> Date: Fri Oct 28 18:41:39 2022 +0300 querylog: rm jsonutil </s> remove if req.Exists("interval") { </s> add if hasIvl { </s> remove if req.Exists("enabled") { conf.Enabled = d.Enabled </s> add if newConf.Enabled != aghalg.NBNull { conf.Enabled = newConf.Enabled == aghalg.NBTrue </s> remove ivl := time.Duration(float64(timeutil.Day) * d.Interval) if req.Exists("interval") && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "Unsupported interval") </s> add ivl := time.Duration(float64(timeutil.Day) * newConf.Interval) hasIvl := !math.IsNaN(newConf.Interval) if hasIvl && !checkInterval(ivl) { aghhttp.Error(r, w, http.StatusBadRequest, "unsupported interval") </s> remove // Set configuration </s> add // handleQueryLogConfig handles the POST /control/querylog_config queries. </s> remove d := &qlogConfig{} req, err := jsonutil.DecodeObject(d, r.Body) </s> add // Set NaN as initial value to be able to know if it changed later by // comparing it to NaN. newConf := &configJSON{ Interval: math.NaN(), } err := json.NewDecoder(r.Body).Decode(newConf)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/746e9df727866a2ae90f1533fd2ee92f4d914de2
internal/querylog/http.go
log.Println(text)
<mask> } <mask> <mask> func httpError(w http.ResponseWriter, code int, format string, args ...interface{}) { <mask> text := fmt.Sprintf(format, args...) <mask> http.Error(w, text, code) <mask> } <mask> <mask> func handleSetUpstreamDNS(w http.ResponseWriter, r *http.Request) { </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter) </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove filter := &config.Filters[i] if filter.URL == url { errortext := fmt.Sprintf("Filter URL already added -- %s", url) </s> add if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL) </s> remove if valid := govalidator.IsRequestURL(url); !valid { </s> add if valid := govalidator.IsRequestURL(filter.URL); !valid {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter)
<mask> } <mask> } <mask> <mask> func handleFilteringAddURL(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) <mask> http.Error(w, errortext, 400) <mask> return </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) </s> add errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) </s> remove var filter = filter{ Enabled: true, URL: url, } ok, err = filter.update(time.Now()) </s> add ok, err := filter.update(time.Now()) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err)
<mask> <mask> func handleFilteringAddURL(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) <mask> http.Error(w, errortext, 400) <mask> return <mask> } <mask> <mask> url, ok := parameters["url"] <mask> if !ok { </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) </s> add errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) </s> remove var filter = filter{ Enabled: true, URL: url, } ok, err = filter.update(time.Now()) </s> add ok, err := filter.update(time.Now())
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
filter.Enabled = true if len(filter.URL) == 0 {
<mask> http.Error(w, errortext, 400) <mask> return <mask> } <mask> <mask> url, ok := parameters["url"] <mask> if !ok { <mask> http.Error(w, "URL parameter was not specified", 400) <mask> return <mask> } <mask> <mask> if valid := govalidator.IsRequestURL(url); !valid { </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove if valid := govalidator.IsRequestURL(url); !valid { </s> add if valid := govalidator.IsRequestURL(filter.URL); !valid { </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter) </s> remove errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL) </s> remove var filter = filter{ Enabled: true, URL: url, } ok, err = filter.update(time.Now()) </s> add ok, err := filter.update(time.Now())
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
if valid := govalidator.IsRequestURL(filter.URL); !valid {
<mask> http.Error(w, "URL parameter was not specified", 400) <mask> return <mask> } <mask> <mask> if valid := govalidator.IsRequestURL(url); !valid { <mask> http.Error(w, "URL parameter is not valid request URL", 400) <mask> return <mask> } <mask> <mask> // check for duplicates </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove filter := &config.Filters[i] if filter.URL == url { errortext := fmt.Sprintf("Filter URL already added -- %s", url) </s> add if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL) </s> remove errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", filter.URL) </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL)
<mask> } <mask> <mask> // check for duplicates <mask> for i := range config.Filters { <mask> filter := &config.Filters[i] <mask> if filter.URL == url { <mask> errortext := fmt.Sprintf("Filter URL already added -- %s", url) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> } </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove if valid := govalidator.IsRequestURL(url); !valid { </s> add if valid := govalidator.IsRequestURL(filter.URL); !valid { </s> remove errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL) </s> remove errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", filter.URL) </s> remove errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) </s> add errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
ok, err := filter.update(time.Now())
<mask> return <mask> } <mask> } <mask> <mask> var filter = filter{ <mask> Enabled: true, <mask> URL: url, <mask> } <mask> ok, err = filter.update(time.Now()) <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) </s> add errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter) </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove filter := &config.Filters[i] if filter.URL == url { errortext := fmt.Sprintf("Filter URL already added -- %s", url) </s> add if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err)
<mask> URL: url, <mask> } <mask> ok, err = filter.update(time.Now()) <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> if filter.RulesCount == 0 { </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove var filter = filter{ Enabled: true, URL: url, } ok, err = filter.update(time.Now()) </s> add ok, err := filter.update(time.Now()) </s> remove parameters, err := parseParametersFromBody(r.Body) </s> add filter := filter{} err := json.NewDecoder(r.Body).Decode(&filter) </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL)
<mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> if filter.RulesCount == 0 { <mask> errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> if !ok { </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", filter.URL) </s> remove filter := &config.Filters[i] if filter.URL == url { errortext := fmt.Sprintf("Filter URL already added -- %s", url) </s> add if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL) </s> remove errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) </s> add errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", filter.URL)
<mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> if !ok { <mask> errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", url) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusBadRequest) <mask> return <mask> } <mask> </s> API filtering/add_url -- accept JSON instead of name=value lines </s> remove errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) </s> add errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL) </s> remove filter := &config.Filters[i] if filter.URL == url { errortext := fmt.Sprintf("Filter URL already added -- %s", url) </s> add if config.Filters[i].URL == filter.URL { errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL) </s> remove if valid := govalidator.IsRequestURL(url); !valid { </s> add if valid := govalidator.IsRequestURL(filter.URL); !valid { </s> remove url, ok := parameters["url"] if !ok { </s> add filter.Enabled = true if len(filter.URL) == 0 { </s> remove errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) log.Println(errortext) http.Error(w, errortext, 400) </s> add httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/751be05a31e8479fb0e8ca318260264466871b16
control.go
const normalizedRules = { rules: normalizeRulesTextarea(rules)?.split('\n'), };
<mask> <mask> export const setRules = (rules) => async (dispatch) => { <mask> dispatch(setRulesRequest()); <mask> try { <mask> const normalizedRules = normalizeRulesTextarea(rules); <mask> await apiClient.setRules(normalizedRules); <mask> dispatch(addSuccessToast('updated_custom_filtering_toast')); <mask> dispatch(setRulesSuccess()); <mask> } catch (error) { <mask> dispatch(addErrorToast({ error })); </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove await apiClient.changeLanguage(lang); </s> add await apiClient.changeLanguage({ language: lang }); </s> remove const language = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(language)); </s> add const langSettings = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(langSettings.language)); </s> remove const activeDhcp = await apiClient.findActiveDhcp(name); </s> add const req = { interface: name, }; const activeDhcp = await apiClient.findActiveDhcp(req); </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/actions/filtering.js
await apiClient.changeLanguage({ language: lang });
<mask> <mask> export const changeLanguage = (lang) => async (dispatch) => { <mask> dispatch(changeLanguageRequest()); <mask> try { <mask> await apiClient.changeLanguage(lang); <mask> dispatch(changeLanguageSuccess()); <mask> } catch (error) { <mask> dispatch(addErrorToast({ error })); <mask> dispatch(changeLanguageFailure()); <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove const language = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(language)); </s> add const langSettings = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(langSettings.language)); </s> remove const normalizedRules = normalizeRulesTextarea(rules); </s> add const normalizedRules = { rules: normalizeRulesTextarea(rules)?.split('\n'), }; </s> remove const activeDhcp = await apiClient.findActiveDhcp(name); </s> add const req = { interface: name, }; const activeDhcp = await apiClient.findActiveDhcp(req); </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/actions/index.js
const langSettings = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(langSettings.language));
<mask> <mask> export const getLanguage = () => async (dispatch) => { <mask> dispatch(getLanguageRequest()); <mask> try { <mask> const language = await apiClient.getCurrentLanguage(); <mask> dispatch(getLanguageSuccess(language)); <mask> } catch (error) { <mask> dispatch(addErrorToast({ error })); <mask> dispatch(getLanguageFailure()); <mask> } <mask> }; </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove const normalizedRules = normalizeRulesTextarea(rules); </s> add const normalizedRules = { rules: normalizeRulesTextarea(rules)?.split('\n'), }; </s> remove await apiClient.changeLanguage(lang); </s> add await apiClient.changeLanguage({ language: lang }); </s> remove const activeDhcp = await apiClient.findActiveDhcp(name); </s> add const req = { interface: name, }; const activeDhcp = await apiClient.findActiveDhcp(req); </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove changeLanguage(lang) { </s> add changeLanguage(config) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/actions/index.js
const req = { interface: name, }; const activeDhcp = await apiClient.findActiveDhcp(req);
<mask> <mask> export const findActiveDhcp = (name) => async (dispatch, getState) => { <mask> dispatch(findActiveDhcpRequest()); <mask> try { <mask> const activeDhcp = await apiClient.findActiveDhcp(name); <mask> dispatch(findActiveDhcpSuccess(activeDhcp)); <mask> const { check, interface_name, interfaces } = getState().dhcp; <mask> const selectedInterface = getState().form[FORM_NAME.DHCP_INTERFACES].values.interface_name; <mask> const v4 = check?.v4 ?? { static_ip: {}, other_server: {} }; <mask> const v6 = check?.v6 ?? { other_server: {} }; </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove const language = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(language)); </s> add const langSettings = await apiClient.getCurrentLanguage(); dispatch(getLanguageSuccess(langSettings.language)); </s> remove const normalizedRules = normalizeRulesTextarea(rules); </s> add const normalizedRules = { rules: normalizeRulesTextarea(rules)?.split('\n'), }; </s> remove await apiClient.changeLanguage(lang); </s> add await apiClient.changeLanguage({ language: lang }); </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove changeLanguage(lang) { </s> add changeLanguage(config) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/actions/index.js
headers: { 'Content-Type': 'application/json' },
<mask> setRules(rules) { <mask> const { path, method } = this.FILTERING_SET_RULES; <mask> const parameters = { <mask> data: rules, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; <mask> return this.makeRequest(path, method, parameters); <mask> } <mask> <mask> setFiltersConfig(config) { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' }, </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
return this.makeRequest(path, method);
<mask> } <mask> <mask> enableParentalControl() { <mask> const { path, method } = this.PARENTAL_ENABLE; <mask> const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded <mask> const config = { <mask> data: parameter, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; <mask> return this.makeRequest(path, method, config); <mask> } <mask> <mask> disableParentalControl() { <mask> const { path, method } = this.PARENTAL_DISABLE; <mask> return this.makeRequest(path, method); </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' },
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
changeLanguage(config) {
<mask> const { path, method } = this.CURRENT_LANGUAGE; <mask> return this.makeRequest(path, method); <mask> } <mask> <mask> changeLanguage(lang) { <mask> const { path, method } = this.CHANGE_LANGUAGE; <mask> const parameters = { <mask> data: lang, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' }, </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method); </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
data: config, headers: { 'Content-Type': 'application/json' },
<mask> <mask> changeLanguage(lang) { <mask> const { path, method } = this.CHANGE_LANGUAGE; <mask> const parameters = { <mask> data: lang, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; <mask> return this.makeRequest(path, method, parameters); <mask> } <mask> <mask> // DHCP </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
findActiveDhcp(req) {
<mask> }; <mask> return this.makeRequest(path, method, parameters); <mask> } <mask> <mask> findActiveDhcp(name) { <mask> const { path, method } = this.DHCP_FIND_ACTIVE; <mask> const parameters = { <mask> data: name, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' }, </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
data: req, headers: { 'Content-Type': 'application/json' },
<mask> <mask> findActiveDhcp(name) { <mask> const { path, method } = this.DHCP_FIND_ACTIVE; <mask> const parameters = { <mask> data: name, <mask> headers: { 'Content-Type': 'text/plain' }, <mask> }; <mask> return this.makeRequest(path, method, parameters); <mask> } <mask> <mask> addStaticLease(config) { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) { </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' }, </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
client/src/api/Api.js
"encoding/json"
<mask> // Package aghhttp provides some common methods to work with HTTP. <mask> package aghhttp <mask> <mask> import ( <mask> "fmt" <mask> "io" <mask> "net/http" <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "fmt" "io" </s> add "encoding/json" </s> remove "io" </s> add </s> remove "strings" </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/aghhttp/aghhttp.go
"github.com/AdguardTeam/AdGuardHome/internal/version"
<mask> "io" <mask> "net/http" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> // HTTP scheme constants. <mask> const ( </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "strings" </s> add </s> remove "fmt" "io" </s> add "encoding/json" </s> remove "io" </s> add </s> remove "strings" </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/aghhttp/aghhttp.go
<mask> <mask> import ( <mask> "encoding/json" <mask> "fmt" <mask> "io" <mask> "net" <mask> "net/http" <mask> "os" <mask> "strings" <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "fmt" "io" </s> add "encoding/json" </s> remove "strings" </s> add </s> remove "strings" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
<mask> "io" <mask> "net" <mask> "net/http" <mask> "os" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghalg" <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet" <mask> "github.com/AdguardTeam/golibs/errors" </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "io" </s> add </s> remove "strings" </s> add </s> remove "fmt" "io" </s> add "encoding/json"
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
// findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results.
<mask> V4 dhcpSearchV4Result `json:"v4"` <mask> V6 dhcpSearchV6Result `json:"v6"` <mask> } <mask> <mask> // Perform the following tasks: <mask> // . Search for another DHCP server running <mask> // . Check if a static IP is configured for the network interface <mask> // Respond with results <mask> func (s *server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { <mask> // This use of ReadAll is safe, because request's body is now limited. <mask> body, err := io.ReadAll(r.Body) <mask> if err != nil { <mask> msg := fmt.Sprintf("failed to read request body: %s", err) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove return } </s> add func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, }) </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req)
<mask> // . Search for another DHCP server running <mask> // . Check if a static IP is configured for the network interface <mask> // Respond with results <mask> func (s *server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { <mask> // This use of ReadAll is safe, because request's body is now limited. <mask> body, err := io.ReadAll(r.Body) <mask> if err != nil { <mask> msg := fmt.Sprintf("failed to read request body: %s", err) <mask> log.Error(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results. </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove return } </s> add func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, }) </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err)
<mask> func (s *server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { <mask> // This use of ReadAll is safe, because request's body is now limited. <mask> body, err := io.ReadAll(r.Body) <mask> if err != nil { <mask> msg := fmt.Sprintf("failed to read request body: %s", err) <mask> log.Error(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> ifaceName := strings.TrimSpace(string(body)) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return } </s> add func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, }) </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results. </s> remove ifaceName := strings.TrimSpace(string(body)) </s> add ifaceName := req.Interface
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
ifaceName := req.Interface
<mask> <mask> return <mask> } <mask> <mask> ifaceName := strings.TrimSpace(string(body)) <mask> if ifaceName == "" { <mask> msg := "empty interface name specified" <mask> log.Error(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "empty interface name") </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
aghhttp.Error(r, w, http.StatusBadRequest, "empty interface name")
<mask> } <mask> <mask> ifaceName := strings.TrimSpace(string(body)) <mask> if ifaceName == "" { <mask> msg := "empty interface name specified" <mask> log.Error(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> result := dhcpSearchResult{ </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove ifaceName := strings.TrimSpace(string(body)) </s> add ifaceName := req.Interface </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
result := &dhcpSearchResult{
<mask> <mask> return <mask> } <mask> <mask> result := dhcpSearchResult{ <mask> V4: dhcpSearchV4Result{ <mask> OtherServer: dhcpSearchOtherResult{ <mask> Found: "no", <mask> }, <mask> StaticIP: dhcpStaticIPStatus{ </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "empty interface name") </s> remove headers: { 'Content-Type': 'text/plain' }, </s> add headers: { 'Content-Type': 'application/json' }, </s> remove data: lang, headers: { 'Content-Type': 'text/plain' }, </s> add data: config, headers: { 'Content-Type': 'application/json' }, </s> remove data: name, headers: { 'Content-Type': 'text/plain' }, </s> add data: req, headers: { 'Content-Type': 'application/json' }, </s> remove findActiveDhcp(name) { </s> add findActiveDhcp(req) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
setOtherDHCPResult(ifaceName, result) _ = aghhttp.WriteJSONResponse(w, r, result) } // setOtherDHCPResult sets the results of the check for another DHCP server in // result. func setOtherDHCPResult(ifaceName string, result *dhcpSearchResult) {
<mask> // TODO(e.burkov): The returned IP should only be of version 4. <mask> result.V4.StaticIP.IP = aghnet.GetSubnet(ifaceName).String() <mask> } <mask> <mask> found4, found6, err4, err6 := aghnet.CheckOtherDHCP(ifaceName) <mask> if err4 != nil { <mask> result.V4.OtherServer.Found = "error" <mask> result.V4.OtherServer.Error = err4.Error() <mask> } else if found4 { <mask> result.V4.OtherServer.Found = "yes" </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove w.Header().Set("Content-Type", "application/json") </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
<mask> result.V6.OtherServer.Error = err6.Error() <mask> } else if found6 { <mask> result.V6.OtherServer.Found = "yes" <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err = json.NewEncoder(w).Encode(result) <mask> if err != nil { <mask> aghhttp.Error( <mask> r, <mask> w, <mask> http.StatusInternalServerError, <mask> "Failed to marshal DHCP found json: %s", <mask> err, <mask> ) <mask> } <mask> } <mask> <mask> func (s *server) handleDHCPAddStaticLease(w http.ResponseWriter, r *http.Request) { <mask> l := &Lease{} <mask> err := json.NewDecoder(r.Body).Decode(l) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with TLS status: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/dhcpd/http_unix.go
"path"
<mask> "fmt" <mask> "net" <mask> "net/http" <mask> "strconv" <mask> "strings" <mask> "sync" <mask> "time" <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "io" </s> add </s> remove "strings" </s> add </s> remove "strings" </s> add </s> remove "fmt" "io" </s> add "encoding/json"
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
"github.com/AdguardTeam/golibs/errors"
<mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" <mask> "github.com/AdguardTeam/golibs/timeutil" <mask> "go.etcd.io/bbolt" </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "strings" </s> add </s> remove "fmt" "io" </s> add "encoding/json" </s> remove "strings" </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// expire is the expiration time, in seconds. expire uint32
<mask> const sessionTokenSize = 16 <mask> <mask> type session struct { <mask> userName string <mask> expire uint32 // expiration time (in seconds) <mask> } <mask> <mask> func (s *session) serialize() []byte { <mask> const ( <mask> expireLen = 4 </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove // User object type User struct { </s> add // webUser represents a user of the Web UI. type webUser struct { </s> remove PasswordHash string `yaml:"password"` // bcrypt hash </s> add PasswordHash string `yaml:"password"` </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove const parameter = 'sensitivity=TEEN'; // this parameter TEEN is hardcoded const config = { data: parameter, headers: { 'Content-Type': 'text/plain' }, }; return this.makeRequest(path, method, config); </s> add return this.makeRequest(path, method);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32
<mask> } <mask> <mask> // Auth - global object <mask> type Auth struct { <mask> db *bbolt.DB <mask> blocker *authRateLimiter <mask> sessions map[string]*session <mask> users []User <mask> lock sync.Mutex <mask> sessionTTL uint32 <mask> } <mask> <mask> // User object <mask> type User struct { <mask> Name string `yaml:"name"` </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // User object type User struct { </s> add // webUser represents a user of the Web UI. type webUser struct { </s> remove PasswordHash string `yaml:"password"` // bcrypt hash </s> add PasswordHash string `yaml:"password"` </s> remove func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { </s> add func InitAuth(dbFilename string, users []webUser, sessionTTL uint32, rateLimiter *authRateLimiter) *Auth { </s> remove expire uint32 // expiration time (in seconds) </s> add // expire is the expiration time, in seconds. expire uint32 </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// webUser represents a user of the Web UI. type webUser struct {
<mask> lock sync.Mutex <mask> sessionTTL uint32 <mask> } <mask> <mask> // User object <mask> type User struct { <mask> Name string `yaml:"name"` <mask> PasswordHash string `yaml:"password"` // bcrypt hash <mask> } <mask> <mask> // InitAuth - create a global object </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove PasswordHash string `yaml:"password"` // bcrypt hash </s> add PasswordHash string `yaml:"password"` </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { </s> add func InitAuth(dbFilename string, users []webUser, sessionTTL uint32, rateLimiter *authRateLimiter) *Auth { </s> remove expire uint32 // expiration time (in seconds) </s> add // expire is the expiration time, in seconds. expire uint32 </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
PasswordHash string `yaml:"password"`
<mask> <mask> // User object <mask> type User struct { <mask> Name string `yaml:"name"` <mask> PasswordHash string `yaml:"password"` // bcrypt hash <mask> } <mask> <mask> // InitAuth - create a global object <mask> func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { <mask> log.Info("Initializing auth module: %s", dbFilename) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { </s> add func InitAuth(dbFilename string, users []webUser, sessionTTL uint32, rateLimiter *authRateLimiter) *Auth { </s> remove // User object type User struct { </s> add // webUser represents a user of the Web UI. type webUser struct { </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove sessionTTL: sessionTTL, blocker: blocker, sessions: make(map[string]*session), users: users, </s> add sessionTTL: sessionTTL, raleLimiter: rateLimiter, sessions: make(map[string]*session), users: users, </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
func InitAuth(dbFilename string, users []webUser, sessionTTL uint32, rateLimiter *authRateLimiter) *Auth {
<mask> PasswordHash string `yaml:"password"` // bcrypt hash <mask> } <mask> <mask> // InitAuth - create a global object <mask> func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { <mask> log.Info("Initializing auth module: %s", dbFilename) <mask> <mask> a := &Auth{ <mask> sessionTTL: sessionTTL, <mask> blocker: blocker, </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove PasswordHash string `yaml:"password"` // bcrypt hash </s> add PasswordHash string `yaml:"password"` </s> remove sessionTTL: sessionTTL, blocker: blocker, sessions: make(map[string]*session), users: users, </s> add sessionTTL: sessionTTL, raleLimiter: rateLimiter, sessions: make(map[string]*session), users: users, </s> remove // User object type User struct { </s> add // webUser represents a user of the Web UI. type webUser struct { </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
sessionTTL: sessionTTL, raleLimiter: rateLimiter, sessions: make(map[string]*session), users: users,
<mask> func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { <mask> log.Info("Initializing auth module: %s", dbFilename) <mask> <mask> a := &Auth{ <mask> sessionTTL: sessionTTL, <mask> blocker: blocker, <mask> sessions: make(map[string]*session), <mask> users: users, <mask> } <mask> var err error <mask> a.db, err = bbolt.Open(dbFilename, 0o644, nil) <mask> if err != nil { <mask> log.Error("auth: open DB: %s: %s", dbFilename, err) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func InitAuth(dbFilename string, users []User, sessionTTL uint32, blocker *authRateLimiter) *Auth { </s> add func InitAuth(dbFilename string, users []webUser, sessionTTL uint32, rateLimiter *authRateLimiter) *Auth { </s> remove PasswordHash string `yaml:"password"` // bcrypt hash </s> add PasswordHash string `yaml:"password"` </s> remove var sess []byte sess, err = newSessionToken() </s> add sess, err := newSessionToken() </s> remove if blocker != nil { blocker.remove(addr) </s> add if rateLimiter != nil { rateLimiter.remove(addr) </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// newCookie creates a new authentication cookie. func (a *Auth) newCookie(req loginJSON, addr string) (c *http.Cookie, err error) { rateLimiter := a.raleLimiter u, ok := a.findUser(req.Name, req.Password) if !ok { if rateLimiter != nil { rateLimiter.inc(addr)
<mask> <mask> return randData, nil <mask> } <mask> <mask> // cookieTimeFormat is the format to be used in (time.Time).Format for cookie's <mask> // expiry field. <mask> const cookieTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" <mask> <mask> // cookieExpiryFormat returns the formatted exp to be used in cookie string. <mask> // It's quite simple for now, but probably will be expanded in the future. <mask> func cookieExpiryFormat(exp time.Time) (formatted string) { <mask> return exp.Format(cookieTimeFormat) <mask> } <mask> <mask> func (a *Auth) httpCookie(req loginJSON, addr string) (cookie string, err error) { <mask> blocker := a.blocker <mask> u := a.UserFind(req.Name, req.Password) <mask> if len(u.Name) == 0 { <mask> if blocker != nil { <mask> blocker.inc(addr) <mask> } <mask> <mask> return "", err <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) { </s> remove return User{} </s> add return webUser{}, false </s> remove return "", err </s> add return nil, errors.Error("invalid username or password") </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return nil, errors.Error("invalid username or password")
<mask> if blocker != nil { <mask> blocker.inc(addr) <mask> } <mask> <mask> return "", err <mask> } <mask> <mask> if blocker != nil { <mask> blocker.remove(addr) <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if blocker != nil { blocker.remove(addr) </s> add if rateLimiter != nil { rateLimiter.remove(addr) </s> remove var sess []byte sess, err = newSessionToken() </s> add sess, err := newSessionToken() </s> remove if blocker := Context.auth.blocker; blocker != nil { if left := blocker.check(remoteAddr); left > 0 { </s> add if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 { </s> remove // cookieTimeFormat is the format to be used in (time.Time).Format for cookie's // expiry field. const cookieTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // cookieExpiryFormat returns the formatted exp to be used in cookie string. // It's quite simple for now, but probably will be expanded in the future. func cookieExpiryFormat(exp time.Time) (formatted string) { return exp.Format(cookieTimeFormat) } func (a *Auth) httpCookie(req loginJSON, addr string) (cookie string, err error) { blocker := a.blocker u := a.UserFind(req.Name, req.Password) if len(u.Name) == 0 { if blocker != nil { blocker.inc(addr) </s> add // newCookie creates a new authentication cookie. func (a *Auth) newCookie(req loginJSON, addr string) (c *http.Cookie, err error) { rateLimiter := a.raleLimiter u, ok := a.findUser(req.Name, req.Password) if !ok { if rateLimiter != nil { rateLimiter.inc(addr) </s> remove return "", err </s> add return nil, fmt.Errorf("generating token: %w", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
if rateLimiter != nil { rateLimiter.remove(addr)
<mask> <mask> return "", err <mask> } <mask> <mask> if blocker != nil { <mask> blocker.remove(addr) <mask> } <mask> <mask> var sess []byte <mask> sess, err = newSessionToken() <mask> if err != nil { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove var sess []byte sess, err = newSessionToken() </s> add sess, err := newSessionToken() </s> remove return "", err </s> add return nil, fmt.Errorf("generating token: %w", err) </s> remove return "", err </s> add return nil, errors.Error("invalid username or password") </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr) </s> remove if blocker := Context.auth.blocker; blocker != nil { if left := blocker.check(remoteAddr); left > 0 { </s> add if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
sess, err := newSessionToken()
<mask> if blocker != nil { <mask> blocker.remove(addr) <mask> } <mask> <mask> var sess []byte <mask> sess, err = newSessionToken() <mask> if err != nil { <mask> return "", err <mask> } <mask> <mask> now := time.Now().UTC() </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if blocker != nil { blocker.remove(addr) </s> add if rateLimiter != nil { rateLimiter.remove(addr) </s> remove return "", err </s> add return nil, fmt.Errorf("generating token: %w", err) </s> remove return "", err </s> add return nil, errors.Error("invalid username or password") </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr) </s> remove if blocker := Context.auth.blocker; blocker != nil { if left := blocker.check(remoteAddr); left > 0 { </s> add if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return nil, fmt.Errorf("generating token: %w", err)
<mask> <mask> var sess []byte <mask> sess, err = newSessionToken() <mask> if err != nil { <mask> return "", err <mask> } <mask> <mask> now := time.Now().UTC() <mask> <mask> a.addSession(sess, &session{ </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove var sess []byte sess, err = newSessionToken() </s> add sess, err := newSessionToken() </s> remove if blocker != nil { blocker.remove(addr) </s> add if rateLimiter != nil { rateLimiter.remove(addr) </s> remove return "", err </s> add return nil, errors.Error("invalid username or password") </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return &http.Cookie{ Name: sessionCookieName, Value: hex.EncodeToString(sess), Path: "/", Expires: now.Add(cookieTTL), HttpOnly: true, SameSite: http.SameSiteLaxMode, }, nil
<mask> userName: u.Name, <mask> expire: uint32(now.Unix()) + a.sessionTTL, <mask> }) <mask> <mask> return fmt.Sprintf( <mask> "%s=%s; Path=/; HttpOnly; Expires=%s", <mask> sessionCookieName, hex.EncodeToString(sess), <mask> cookieExpiryFormat(now.Add(cookieTTL)), <mask> ), nil <mask> } <mask> <mask> // realIP extracts the real IP address of the client from an HTTP request using <mask> // the known HTTP headers. <mask> // </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client Users []User `yaml:"users"` // Users that can access HTTP server </s> add BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client Users []webUser `yaml:"users"` // Users that can access HTTP server </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results. </s> remove return User{} </s> add return webUser{}, false </s> remove aghhttp.Error(r, w, http.StatusBadRequest, "crypto rand reader: %s", err) </s> add aghhttp.Error(r, w, http.StatusForbidden, "%s", err) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go