docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep keep keep keep replace keep keep keep keep keep
<mask> serialize: func(o options) []string { return nil }, <mask> } <mask> <mask> var helpArg = arg{ <mask> "Print this help", <mask> "help", "", <mask> nil, nil, func(o options, exec string) (effect, error) { <mask> return func() error { _ = printHelp(exec); os.Exit(64); return nil }, nil <mask> }, <mask> func(o options) []string { return nil }, </s> Pull request: home: fix help Merge in DNS/adguard-home from fix-help to master Updates #2893. Squashed commit of the following: commit df84e0968c036ad0d1978dc6170214058ef07255 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Apr 13 14:51:53 2021 +0300 home: fix help </s> remove "Enable verbose output", </s> add "Enable verbose output.", </s> remove "Disable memory optimization", </s> add "Disable memory optimization.", </s> remove "Path to the working directory", </s> add "Path to the working directory.", </s> remove "Don't check for updates", </s> add "Don't check for updates.", </s> remove "Check configuration and exit", </s> add "Check configuration and exit.", </s> remove "Run in GL-Inet compatibility mode", </s> add "Run in GL-Inet compatibility mode.",
https://github.com/AdguardTeam/AdGuardHome/commit/ab85ad5a55a33093a80bf61bafde5e2dfba2b92f
internal/home/options.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } <mask> returnOK(w) <mask> } <mask> <mask> func handleStatus(w http.ResponseWriter, r *http.Request) { <mask> log.Tracef("%s %v", r.Method, r.URL) <mask> <mask> dnsAddresses := []string{} <mask> if config.DNS.BindHost == "0.0.0.0" { <mask> ifaces, e := getValidNetInterfacesForWeb() <mask> if e != nil { </s> * /status: "dns_addresses": add port if not 53 </s> remove if len(dnsAddresses) == 0 { dnsAddresses = append(dnsAddresses, config.DNS.BindHost) } </s> add return dnsAddresses } func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add // Get the list of DNS addresses the server is listening on func getDNSAddresses() []string { </s> add return []string{} </s> remove dnsAddresses = append(dnsAddresses, addr) </s> add addDNSAddress(&dnsAddresses, addr) </s> add } else { addDNSAddress(&dnsAddresses, config.DNS.BindHost) </s> remove "dns_addresses": dnsAddresses, </s> add "dns_addresses": getDNSAddresses(),
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep keep keep add keep keep keep keep keep
<mask> } <mask> *dnsAddresses = append(*dnsAddresses, addr) <mask> } <mask> <mask> dnsAddresses := []string{} <mask> <mask> if config.DNS.BindHost == "0.0.0.0" { <mask> <mask> ifaces, e := getValidNetInterfacesForWeb() </s> * /status: "dns_addresses": add port if not 53 </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add func addDNSAddress(dnsAddresses *[]string, addr string) { if config.DNS.Port != 53 { addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port) } *dnsAddresses = append(*dnsAddresses, addr) } </s> add return []string{} </s> remove dnsAddresses = append(dnsAddresses, addr) </s> add addDNSAddress(&dnsAddresses, addr) </s> remove if len(dnsAddresses) == 0 { dnsAddresses = append(dnsAddresses, config.DNS.BindHost) } </s> add return dnsAddresses } func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add } else { addDNSAddress(&dnsAddresses, config.DNS.BindHost) </s> remove "dns_addresses": dnsAddresses, </s> add "dns_addresses": getDNSAddresses(),
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep keep add keep keep keep keep
<mask> ifaces, e := getValidNetInterfacesForWeb() <mask> if e != nil { <mask> log.Error("Couldn't get network interfaces: %v", e) <mask> } <mask> <mask> for _, iface := range ifaces { <mask> for _, addr := range iface.Addresses { </s> * /status: "dns_addresses": add port if not 53 </s> remove dnsAddresses = append(dnsAddresses, addr) </s> add addDNSAddress(&dnsAddresses, addr) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add func addDNSAddress(dnsAddresses *[]string, addr string) { if config.DNS.Port != 53 { addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port) } *dnsAddresses = append(*dnsAddresses, addr) } </s> add // Get the list of DNS addresses the server is listening on func getDNSAddresses() []string { </s> remove if len(dnsAddresses) == 0 { dnsAddresses = append(dnsAddresses, config.DNS.BindHost) } </s> add return dnsAddresses } func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add } else { addDNSAddress(&dnsAddresses, config.DNS.BindHost) </s> remove "dns_addresses": dnsAddresses, </s> add "dns_addresses": getDNSAddresses(),
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep keep keep keep replace keep keep keep keep keep
<mask> log.Error("Couldn't get network interfaces: %v", e) <mask> } <mask> for _, iface := range ifaces { <mask> for _, addr := range iface.Addresses { <mask> dnsAddresses = append(dnsAddresses, addr) <mask> } <mask> } <mask> } <mask> if len(dnsAddresses) == 0 { <mask> dnsAddresses = append(dnsAddresses, config.DNS.BindHost) </s> * /status: "dns_addresses": add port if not 53 </s> add return []string{} </s> remove if len(dnsAddresses) == 0 { dnsAddresses = append(dnsAddresses, config.DNS.BindHost) } </s> add return dnsAddresses } func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add func addDNSAddress(dnsAddresses *[]string, addr string) { if config.DNS.Port != 53 { addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port) } *dnsAddresses = append(*dnsAddresses, addr) } </s> add // Get the list of DNS addresses the server is listening on func getDNSAddresses() []string { </s> add } else { addDNSAddress(&dnsAddresses, config.DNS.BindHost) </s> remove "dns_addresses": dnsAddresses, </s> add "dns_addresses": getDNSAddresses(),
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep add keep keep keep keep keep
<mask> } <mask> } <mask> } <mask> <mask> return dnsAddresses <mask> } <mask> </s> * /status: "dns_addresses": add port if not 53 </s> remove if len(dnsAddresses) == 0 { dnsAddresses = append(dnsAddresses, config.DNS.BindHost) } </s> add return dnsAddresses } func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> remove dnsAddresses = append(dnsAddresses, addr) </s> add addDNSAddress(&dnsAddresses, addr) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add func addDNSAddress(dnsAddresses *[]string, addr string) { if config.DNS.Port != 53 { addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port) } *dnsAddresses = append(*dnsAddresses, addr) } </s> add // Get the list of DNS addresses the server is listening on func getDNSAddresses() []string { </s> remove "dns_addresses": dnsAddresses, </s> add "dns_addresses": getDNSAddresses(), </s> add return []string{}
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep keep keep replace replace replace keep keep replace keep keep keep
<mask> } <mask> } <mask> } <mask> if len(dnsAddresses) == 0 { <mask> dnsAddresses = append(dnsAddresses, config.DNS.BindHost) <mask> } <mask> <mask> data := map[string]interface{}{ <mask> "dns_addresses": dnsAddresses, <mask> "http_port": config.BindPort, <mask> "dns_port": config.DNS.Port, <mask> "protection_enabled": config.DNS.ProtectionEnabled, </s> * /status: "dns_addresses": add port if not 53 </s> remove dnsAddresses = append(dnsAddresses, addr) </s> add addDNSAddress(&dnsAddresses, addr) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) </s> add func addDNSAddress(dnsAddresses *[]string, addr string) { if config.DNS.Port != 53 { addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port) } *dnsAddresses = append(*dnsAddresses, addr) } </s> add } else { addDNSAddress(&dnsAddresses, config.DNS.BindHost) </s> add // Get the list of DNS addresses the server is listening on func getDNSAddresses() []string { </s> add return []string{}
https://github.com/AdguardTeam/AdGuardHome/commit/ad7c5cb9dc052f6c6d53ef75824bd9cebbd8baff
home/control.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> // Filter represents a filter list <mask> type Filter struct { <mask> ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase <mask> Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' <mask> FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file <mask> } <mask> <mask> //go:generate stringer -type=Reason <mask> <mask> // Reason holds an enum detailing why it was filtered or not filtered </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> remove Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name" yaml:"name"` RulesCount int `json:"rulesCount" yaml:"-"` LastUpdated time.Time `json:"lastUpdated,omitempty" yaml:"-"` </s> add Enabled bool URL string Name string `yaml:"name"` RulesCount int `yaml:"-"` LastUpdated time.Time `yaml:"-"` </s> remove ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> add ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists FiltersUpdateIntervalHours: 24, BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove go refreshFiltersIfNecessary(false) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
dnsfilter/dnsfilter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> <mask> // FilteringConfig represents the DNS filtering configuration of AdGuard Home <mask> // The zero FilteringConfig is empty and ready for use. <mask> type FilteringConfig struct { <mask> ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features <mask> FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists <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> QueryLogEnabled bool `yaml:"querylog_enabled"` // if true, query log is enabled <mask> QueryLogInterval uint32 `yaml:"querylog_interval"` // time interval for query log (in days) <mask> Ratelimit int `yaml:"ratelimit"` // max number of requests per second from a given IP (0 to disable) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> add ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists FiltersUpdateIntervalHours: 24, BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file </s> add ID int64 // auto-assigned when filter is added (see nextFilterID) Data []byte `yaml:"-"` // List of rules divided by '\n' FilePath string `yaml:"-"` // Path to a filtering rules file </s> remove Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name" yaml:"name"` RulesCount int `json:"rulesCount" yaml:"-"` LastUpdated time.Time `json:"lastUpdated,omitempty" yaml:"-"` </s> add Enabled bool URL string Name string `yaml:"name"` RulesCount int `yaml:"-"` LastUpdated time.Time `yaml:"-"` </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> add // Close query log object
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
dnsforward/dnsforward.go
keep keep keep keep replace keep keep keep keep keep
<mask> github.com/AdguardTeam/dnsproxy v0.19.1 <mask> github.com/AdguardTeam/golibs v0.2.1 <mask> github.com/AdguardTeam/urlfilter v0.5.0 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf <mask> github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833 <mask> github.com/etcd-io/bbolt v1.3.3 <mask> github.com/go-test/deep v1.0.1 <mask> github.com/gobuffalo/packr v1.19.0 <mask> github.com/joomcode/errorx v0.8.0 </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove f.Enabled = true </s> add </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"` </s> remove f := filter{} err := json.NewDecoder(r.Body).Decode(&f) </s> add fj := filterAddJSON{} err := json.NewDecoder(r.Body).Decode(&fj) </s> remove if len(f.URL) == 0 { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } if valid := govalidator.IsRequestURL(f.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "Invalid URL", http.StatusBadRequest)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
go.mod
keep keep keep keep replace keep keep keep keep keep
<mask> "sync" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dhcpd" <mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" <mask> "github.com/AdguardTeam/AdGuardHome/dnsforward" <mask> "github.com/AdguardTeam/AdGuardHome/querylog" <mask> "github.com/AdguardTeam/AdGuardHome/stats" <mask> "github.com/AdguardTeam/golibs/file" <mask> "github.com/AdguardTeam/golibs/log" </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove "time" </s> add </s> add "time" </s> add "net/url" </s> add "path/filepath" </s> remove "github.com/asaskevich/govalidator" </s> add </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep keep add keep keep keep keep
<mask> transport *http.Transport <mask> client *http.Client <mask> stats stats.Stats <mask> queryLog querylog.QueryLog <mask> <mask> // cached version.json to avoid hammering github.io for each page reload <mask> versionCheckJSON []byte <mask> versionCheckLastTime time.Time </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file </s> add ID int64 // auto-assigned when filter is added (see nextFilterID) Data []byte `yaml:"-"` // List of rules divided by '\n' FilePath string `yaml:"-"` // Path to a filtering rules file </s> remove Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name" yaml:"name"` RulesCount int `json:"rulesCount" yaml:"-"` LastUpdated time.Time `json:"lastUpdated,omitempty" yaml:"-"` </s> add Enabled bool URL string Name string `yaml:"name"` RulesCount int `yaml:"-"` LastUpdated time.Time `yaml:"-"` </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> remove // Update filters we've just loaded right away, don't wait for periodic update timer go func() { refreshFiltersIfNecessary(false) }() // Schedule automatic filters updates go periodicallyRefreshFilters() </s> add </s> remove if filterExists(f.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) </s> add if filterExists(fj.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> BindHost: "0.0.0.0", <mask> Port: 53, <mask> StatsInterval: 1, <mask> FilteringConfig: dnsforward.FilteringConfig{ <mask> ProtectionEnabled: true, // whether or not use any of dnsfilter features <mask> FilteringEnabled: true, // whether or not use filter lists <mask> BlockingMode: "nxdomain", // mode how to answer filtered requests <mask> BlockedResponseTTL: 10, // in seconds <mask> QueryLogEnabled: true, <mask> QueryLogInterval: 1, <mask> Ratelimit: 20, <mask> RefuseAny: true, <mask> BootstrapDNS: defaultBootstrap, <mask> AllServers: false, <mask> }, <mask> UpstreamDNS: defaultDNS, <mask> }, <mask> TLS: tlsConfig{ <mask> tlsConfigSettings: tlsConfigSettings{ </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> remove Filters: []filter{ {Filter: dnsfilter.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard Simplified Domain Names filter"}, {Filter: dnsfilter.Filter{ID: 2}, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, {Filter: dnsfilter.Filter{ID: 3}, Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, {Filter: dnsfilter.Filter{ID: 4}, Enabled: false, URL: "https://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"}, }, </s> add </s> add f := filter{ Enabled: true, URL: fj.URL, Name: fj.Name, } </s> remove ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file </s> add ID int64 // auto-assigned when filter is added (see nextFilterID) Data []byte `yaml:"-"` // List of rules divided by '\n' FilePath string `yaml:"-"` // Path to a filtering rules file </s> remove go refreshFiltersIfNecessary(false) </s> add </s> add // Add a log entry
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
<mask> PortHTTPS: 443, <mask> PortDNSOverTLS: 853, // needs to be passed through to dnsproxy <mask> }, <mask> }, <mask> Filters: []filter{ <mask> {Filter: dnsfilter.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard Simplified Domain Names filter"}, <mask> {Filter: dnsfilter.Filter{ID: 2}, Enabled: false, URL: "https://adaway.org/hosts.txt", Name: "AdAway"}, <mask> {Filter: dnsfilter.Filter{ID: 3}, Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, <mask> {Filter: dnsfilter.Filter{ID: 4}, Enabled: false, URL: "https://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"}, <mask> }, <mask> DHCP: dhcpd.ServerConfig{ <mask> LeaseDuration: 86400, <mask> ICMPTimeout: 1000, <mask> }, <mask> SchemaVersion: currentSchemaVersion, </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add f := filter{ Enabled: true, URL: fj.URL, Name: fj.Name, } </s> remove ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> add ProtectionEnabled: true, // whether or not use any of dnsfilter features FilteringEnabled: true, // whether or not use filter lists FiltersUpdateIntervalHours: 24, BlockingMode: "nxdomain", // mode how to answer filtered requests BlockedResponseTTL: 10, // in seconds QueryLogEnabled: true, QueryLogInterval: 1, Ratelimit: 20, RefuseAny: true, BootstrapDNS: defaultBootstrap, AllServers: false, </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove go refreshFiltersIfNecessary(false) </s> add </s> add // Clear memory buffer and remove log files </s> remove // New - create instance </s> add // New - create a new instance of the query log
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep add keep keep keep keep keep keep
<mask> config.DNS.SafeSearchCacheSize = 1 * 1024 * 1024 <mask> config.DNS.ParentalCacheSize = 1 * 1024 * 1024 <mask> config.DNS.CacheTime = 30 <mask> } <mask> <mask> // getConfigFilename returns path to the current config file <mask> func (c *configuration) getConfigFilename() string { <mask> configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) <mask> if err != nil { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> add if !checkFiltersUpdateIntervalHours(config.DNS.FiltersUpdateIntervalHours) { config.DNS.FiltersUpdateIntervalHours = 24 } </s> remove const updatePeriod = time.Hour * 24 </s> add </s> remove loadFilters() </s> add </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> remove // Deduplicate filters deduplicateFilters() updateUniqueFilterID(config.Filters) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep add keep keep keep keep
<mask> if !checkStatsInterval(config.DNS.StatsInterval) { <mask> config.DNS.StatsInterval = 1 <mask> } <mask> <mask> if !checkQueryLogInterval(config.DNS.QueryLogInterval) { <mask> config.DNS.QueryLogInterval = 1 <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add config.Filters = defaultFilters() </s> remove uf.LastUpdated = time.Now() </s> add uf.LastUpdated = now </s> add if !config.filteringStarted { config.filteringStarted = true startRefreshFilters() } </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) </s> add // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) } func checkFiltersUpdateIntervalHours(i uint32) bool { return i == 0 || i == 1 || i == 12 || i == 1*24 || i == 3*24 || i == 7*24 </s> remove loadFilters() </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> log.Error("%s", status.WarningValidation) <mask> return err <mask> } <mask> <mask> // Deduplicate filters <mask> deduplicateFilters() <mask> <mask> updateUniqueFilterID(config.Filters) <mask> <mask> return nil <mask> } <mask> <mask> // readConfigFile reads config file contents if it exists <mask> func readConfigFile() ([]byte, error) { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove loadFilters() </s> add </s> add config.Filters = defaultFilters() </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove f.Enabled = true </s> add </s> remove go refreshFiltersIfNecessary(false) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/config.go
keep keep keep keep replace keep keep keep keep keep
<mask> "net" <mask> "net/http" <mask> "strconv" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dnsforward" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/utils" </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add "path/filepath" </s> add "net/url" </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> add "time" </s> remove "github.com/asaskevich/govalidator" </s> add </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> "github.com/NYTimes/gziphandler" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> const updatePeriod = time.Hour * 24 <mask> <mask> var protocols = []string{"tls://", "https://", "tcp://", "sdns://"} <mask> <mask> // ---------------- <mask> // helper functions <mask> // ---------------- </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add config.Filters = defaultFilters() </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> add if !checkFiltersUpdateIntervalHours(config.DNS.FiltersUpdateIntervalHours) { config.DNS.FiltersUpdateIntervalHours = 24 } </s> add f := filter{ Enabled: true, URL: fj.URL, Name: fj.Name, }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control.go
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> httpRegister(http.MethodPost, "/control/i18n/change_language", handleI18nChangeLanguage) <mask> httpRegister(http.MethodGet, "/control/i18n/current_language", handleI18nCurrentLanguage) <mask> http.HandleFunc("/control/version.json", postInstall(optionalAuth(handleGetVersionJSON))) <mask> httpRegister(http.MethodPost, "/control/update", handleUpdate) <mask> httpRegister(http.MethodPost, "/control/filtering/enable", handleFilteringEnable) <mask> httpRegister(http.MethodPost, "/control/filtering/disable", handleFilteringDisable) <mask> httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) <mask> httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) <mask> httpRegister(http.MethodPost, "/control/filtering/enable_url", handleFilteringEnableURL) <mask> httpRegister(http.MethodPost, "/control/filtering/disable_url", handleFilteringDisableURL) <mask> httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) <mask> httpRegister(http.MethodGet, "/control/filtering/status", handleFilteringStatus) <mask> httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) <mask> httpRegister(http.MethodPost, "/control/safebrowsing/enable", handleSafeBrowsingEnable) <mask> httpRegister(http.MethodPost, "/control/safebrowsing/disable", handleSafeBrowsingDisable) <mask> httpRegister(http.MethodGet, "/control/safebrowsing/status", handleSafeBrowsingStatus) <mask> httpRegister(http.MethodPost, "/control/parental/enable", handleParentalEnable) <mask> httpRegister(http.MethodPost, "/control/parental/disable", handleParentalDisable) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) </s> add // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) } func checkFiltersUpdateIntervalHours(i uint32) bool { return i == 0 || i == 1 || i == 12 || i == 1*24 || i == 3*24 || i == 7*24 </s> add RegisterFilteringHandlers() </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"`
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control.go
keep keep keep add keep keep keep keep keep keep
<mask> <mask> httpRegister(http.MethodGet, "/control/access/list", handleAccessList) <mask> httpRegister(http.MethodPost, "/control/access/set", handleAccessSet) <mask> <mask> RegisterTLSHandlers() <mask> RegisterClientsHandlers() <mask> registerRewritesHandlers() <mask> RegisterBlockedServicesHandlers() <mask> RegisterQueryLogHandlers() <mask> RegisterStatsHandlers() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove httpRegister(http.MethodPost, "/control/filtering/enable", handleFilteringEnable) httpRegister(http.MethodPost, "/control/filtering/disable", handleFilteringDisable) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/enable_url", handleFilteringEnableURL) httpRegister(http.MethodPost, "/control/filtering/disable_url", handleFilteringDisableURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodGet, "/control/filtering/status", handleFilteringStatus) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) </s> add </s> remove func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) </s> add // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) } func checkFiltersUpdateIntervalHours(i uint32) bool { return i == 0 || i == 1 || i == 12 || i == 1*24 || i == 3*24 || i == 7*24 </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"`
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control.go
keep keep keep add keep keep keep keep keep keep
<mask> "encoding/json" <mask> "fmt" <mask> "io/ioutil" <mask> "net/http" <mask> "os" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> ) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add "time" </s> add "path/filepath" </s> remove "time" </s> add </s> remove "github.com/asaskevich/govalidator" </s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep add keep keep keep keep
<mask> "net/url" <mask> "os" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add "net/url" </s> remove "github.com/asaskevich/govalidator" </s> add </s> remove "time" </s> add </s> add "path/filepath" </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep replace keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep
<mask> "strings" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/asaskevich/govalidator" <mask> ) <mask> <mask> func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { <mask> config.DNS.FilteringEnabled = true <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { <mask> config.DNS.FilteringEnabled = false <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { <mask> data := map[string]interface{}{ <mask> "enabled": config.DNS.FilteringEnabled, <mask> } <mask> <mask> config.RLock() <mask> data["filters"] = config.Filters <mask> data["user_rules"] = config.UserRules <mask> jsonVal, err := json.Marshal(data) <mask> config.RUnlock() <mask> <mask> if err != nil { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove config.UserRules = strings.Split(string(body), "\n") </s> add if !checkFiltersUpdateIntervalHours(req.Interval) { httpError(w, http.StatusBadRequest, "Unsupported interval") return } config.DNS.FilteringEnabled = req.Enabled config.DNS.FiltersUpdateIntervalHours = req.Interval </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"`
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep replace replace keep keep keep keep keep keep keep keep replace replace replace replace replace replace keep keep keep
<mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Unable to marshal status json: %s", err) <mask> return <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(jsonVal) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Unable to marshal status json: %s", err) <mask> return <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(jsonVal) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) <mask> return <mask> } <mask> } <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) } </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> add resp.UserRules = config.UserRules config.RUnlock() </s> remove f := filter{} err := json.NewDecoder(r.Body).Decode(&f) </s> add fj := filterAddJSON{} err := json.NewDecoder(r.Body).Decode(&fj) </s> remove found := filterEnable(url, false) if !found { http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add jsonVal, err := json.Marshal(resp) if err != nil { httpError(w, http.StatusInternalServerError, "json encode: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep add keep keep keep keep keep keep
<mask> return false //No Scheme found <mask> } <mask> } <mask> <mask> func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { <mask> fj := filterAddJSON{} <mask> err := json.NewDecoder(r.Body).Decode(&fj) <mask> if err != nil { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove f := filter{} err := json.NewDecoder(r.Body).Decode(&f) </s> add fj := filterAddJSON{} err := json.NewDecoder(r.Body).Decode(&fj) </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) </s> add func handleFilteringSetURL(w http.ResponseWriter, r *http.Request) { fj := filterURLJSON{} err := json.NewDecoder(r.Body).Decode(&fj) if err != nil { httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } <mask> } <mask> <mask> func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { <mask> f := filter{} <mask> err := json.NewDecoder(r.Body).Decode(&f) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) <mask> return <mask> } <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> remove httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) </s> add httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> remove if valid := govalidator.IsRequestURL(req.URL); !valid { </s> add if !IsValidURL(req.URL) { </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep replace replace replace replace replace replace replace keep keep keep keep replace replace keep keep keep keep
<mask> <mask> if len(f.URL) == 0 { <mask> http.Error(w, "URL parameter was not specified", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> if valid := govalidator.IsRequestURL(f.URL); !valid { <mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> // Check for duplicates <mask> if filterExists(f.URL) { <mask> httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) <mask> return <mask> } <mask> <mask> // Set necessary properties </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "invalid URL", http.StatusBadRequest) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) </s> add func handleFilteringSetURL(w http.ResponseWriter, r *http.Request) { fj := filterURLJSON{} err := json.NewDecoder(r.Body).Decode(&fj) if err != nil { httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove if valid := govalidator.IsRequestURL(req.URL); !valid { </s> add if !IsValidURL(req.URL) { </s> remove found := filterEnable(url, true) </s> add found := filterEnable(fj.URL, fj.Enabled)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep add keep keep keep keep
<mask> <mask> // Set necessary properties <mask> f.ID = assignUniqueFilterID() <mask> <mask> // Download the filter contents <mask> ok, err := f.update() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove f.Enabled = true </s> add </s> remove if filterExists(f.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) </s> add if filterExists(fj.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL) </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove // Deduplicate filters deduplicateFilters() updateUniqueFilterID(config.Filters) </s> add </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // Set necessary properties <mask> f.ID = assignUniqueFilterID() <mask> f.Enabled = true <mask> <mask> // Download the filter contents <mask> ok, err := f.update() <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Couldn't fetch filter from url %s: %s", f.URL, err) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add f := filter{ Enabled: true, URL: fj.URL, Name: fj.Name, } </s> remove if filterExists(f.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) </s> add if filterExists(fj.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL) </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove uf.LastUpdated = time.Now() </s> add uf.LastUpdated = now </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> remove httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) </s> add httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) <mask> return <mask> } <mask> <mask> if valid := govalidator.IsRequestURL(req.URL); !valid { <mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> // Stop DNS server: </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if len(f.URL) == 0 { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } if valid := govalidator.IsRequestURL(f.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "Invalid URL", http.StatusBadRequest) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "invalid URL", http.StatusBadRequest) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) </s> add func handleFilteringSetURL(w http.ResponseWriter, r *http.Request) { fj := filterURLJSON{} err := json.NewDecoder(r.Body).Decode(&fj) if err != nil { httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove found := filterEnable(url, true) </s> add found := filterEnable(fj.URL, fj.Enabled) </s> remove found := filterEnable(url, false) if !found { http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add jsonVal, err := json.Marshal(resp) if err != nil { httpError(w, http.StatusInternalServerError, "json encode: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep replace replace replace replace replace replace keep replace replace replace keep
<mask> <mask> func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) <mask> return <mask> } <mask> <mask> url, ok := parameters["url"] <mask> if !ok { <mask> http.Error(w, "URL parameter was not specified", http.StatusBadRequest) <mask> return </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) </s> add httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove if len(f.URL) == 0 { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } if valid := govalidator.IsRequestURL(f.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "Invalid URL", http.StatusBadRequest) </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep replace replace keep keep keep replace keep keep keep keep
<mask> } <mask> <mask> if valid := govalidator.IsRequestURL(url); !valid { <mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> found := filterEnable(url, true) <mask> if !found { <mask> http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) <mask> return <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove found := filterEnable(url, false) if !found { http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add jsonVal, err := json.Marshal(resp) if err != nil { httpError(w, http.StatusInternalServerError, "json encode: %s", err) </s> remove http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add http.Error(w, "URL doesn't exist", http.StatusBadRequest) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove if len(f.URL) == 0 { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } if valid := govalidator.IsRequestURL(f.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "Invalid URL", http.StatusBadRequest) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) </s> add func handleFilteringSetURL(w http.ResponseWriter, r *http.Request) { fj := filterURLJSON{} err := json.NewDecoder(r.Body).Decode(&fj) if err != nil { httpError(w, http.StatusBadRequest, "json decode: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> found := filterEnable(url, true) <mask> if !found { <mask> http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove found := filterEnable(url, true) </s> add found := filterEnable(fj.URL, fj.Enabled) </s> remove found := filterEnable(url, false) if !found { http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add jsonVal, err := json.Marshal(resp) if err != nil { httpError(w, http.StatusInternalServerError, "json encode: %s", err) </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "invalid URL", http.StatusBadRequest) </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) } </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace replace keep keep keep keep keep keep keep keep replace keep
<mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) <mask> return <mask> } <mask> <mask> func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { <mask> parameters, err := parseParametersFromBody(r.Body) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) <mask> return </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) if err != nil { httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) return } </s> add type filterURLJSON struct { URL string `json:"url"` Enabled bool `json:"enabled"` } </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) </s> add func handleFilteringSetURL(w http.ResponseWriter, r *http.Request) { fj := filterURLJSON{} err := json.NewDecoder(r.Body).Decode(&fj) if err != nil { httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep replace replace replace replace replace keep replace replace replace keep
<mask> } <mask> <mask> url, ok := parameters["url"] <mask> if !ok { <mask> http.Error(w, "URL parameter was not specified", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> if valid := govalidator.IsRequestURL(url); !valid { <mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) <mask> return <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep add keep keep keep keep
<mask> } <mask> <mask> resp.Filters = append(resp.Filters, fj) <mask> } <mask> <mask> jsonVal, err := json.Marshal(resp) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "json encode: %s", err) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove found := filterEnable(url, false) if !found { http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add jsonVal, err := json.Marshal(resp) if err != nil { httpError(w, http.StatusInternalServerError, "json encode: %s", err) </s> remove httpError(w, http.StatusInternalServerError, "Unable to marshal status json: %s", err) return </s> add return false //Couldn't even parse the rawurl </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) } </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep replace replace replace keep keep replace replace keep keep keep keep
<mask> } <mask> <mask> found := filterEnable(url, false) <mask> if !found { <mask> http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) <mask> return <mask> } <mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove http.Error(w, "URL parameter was not previously added", http.StatusBadRequest) </s> add http.Error(w, "URL doesn't exist", http.StatusBadRequest) </s> remove found := filterEnable(url, true) </s> add found := filterEnable(fj.URL, fj.Enabled) </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) </s> add if !IsValidURL(fj.URL) { http.Error(w, "invalid URL", http.StatusBadRequest) </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace replace keep keep keep keep keep keep keep keep replace keep
<mask> <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) <mask> return <mask> } <mask> <mask> func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) <mask> return </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) </s> add httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> remove config.UserRules = strings.Split(string(body), "\n") </s> add if !checkFiltersUpdateIntervalHours(req.Interval) { httpError(w, http.StatusBadRequest, "Unsupported interval") return } config.DNS.FilteringEnabled = req.Enabled config.DNS.FiltersUpdateIntervalHours = req.Interval </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) } </s> remove f := filter{} err := json.NewDecoder(r.Body).Decode(&f) </s> add fj := filterAddJSON{} err := json.NewDecoder(r.Body).Decode(&fj)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) <mask> return <mask> } <mask> <mask> config.UserRules = strings.Split(string(body), "\n") <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { <mask> updated := refreshFiltersIfNecessary(true) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> add // Set filtering configuration func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { req := filteringConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> remove httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) </s> add httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) </s> remove func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) </s> add // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) } func checkFiltersUpdateIntervalHours(i uint32) bool { return i == 0 || i == 1 || i == 12 || i == 1*24 || i == 3*24 || i == 7*24
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep add keep keep keep keep
<mask> config.DNS.FiltersUpdateIntervalHours = req.Interval <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> // RegisterFilteringHandlers - register handlers <mask> func RegisterFilteringHandlers() { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) </s> add // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/refresh", handleFilteringRefresh) httpRegister(http.MethodPost, "/control/filtering/set_rules", handleFilteringSetRules) } func checkFiltersUpdateIntervalHours(i uint32) bool { return i == 0 || i == 1 || i == 12 || i == 1*24 || i == 3*24 || i == 7*24 </s> remove config.UserRules = strings.Split(string(body), "\n") </s> add if !checkFiltersUpdateIntervalHours(req.Interval) { httpError(w, http.StatusBadRequest, "Unsupported interval") return } config.DNS.FilteringEnabled = req.Enabled config.DNS.FiltersUpdateIntervalHours = req.Interval </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> add if !checkFiltersUpdateIntervalHours(config.DNS.FiltersUpdateIntervalHours) { config.DNS.FiltersUpdateIntervalHours = 24 } </s> remove // New - create instance </s> add // New - create a new instance of the query log
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep keep replace replace replace keep
<mask> config.UserRules = strings.Split(string(body), "\n") <mask> httpUpdateConfigReloadDNSReturnOK(w, r) <mask> } <mask> <mask> func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { <mask> updated := refreshFiltersIfNecessary(true) <mask> fmt.Fprintf(w, "OK %d filters updated\n", updated) <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove config.UserRules = strings.Split(string(body), "\n") </s> add if !checkFiltersUpdateIntervalHours(req.Interval) { httpError(w, http.StatusBadRequest, "Unsupported interval") return } config.DNS.FilteringEnabled = req.Enabled config.DNS.FiltersUpdateIntervalHours = req.Interval </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) </s> add httpError(w, http.StatusBadRequest, "json decode: %s", err) </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove url, ok := parameters["url"] if !ok { http.Error(w, "URL parameter was not specified", http.StatusBadRequest) return } </s> add config.UserRules = strings.Split(string(body), "\n") httpUpdateConfigReloadDNSReturnOK(w, r) } </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_filtering.go
keep keep keep add keep keep keep keep
<mask> "fmt" <mask> "net" <mask> "net/http" <mask> "os/exec" <mask> "strconv" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> ) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove "time" </s> add </s> add "net/url" </s> add "time" </s> remove "github.com/asaskevich/govalidator" </s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_install.go
keep keep keep add keep keep keep keep
<mask> config.DNS.Port = newSettings.DNS.Port <mask> config.AuthName = newSettings.Username <mask> config.AuthPass = newSettings.Password <mask> <mask> err = startDNSServer() <mask> if err != nil { <mask> config.firstRun = true <mask> copyInstallSettings(&config, &curConfig) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if !config.firstRun { err := startDNSServer() </s> add err = startDNSServer() </s> remove f.Enabled = true </s> add </s> add if !config.filteringStarted { config.filteringStarted = true startRefreshFilters() } </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove // Init the DNS server instance before registering HTTP handlers dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> add dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> remove loadFilters() </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_install.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) <mask> return <mask> } <mask> <mask> go refreshFiltersIfNecessary(false) <mask> <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> config.httpServer.Shutdown(context.TODO()) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // Update filters we've just loaded right away, don't wait for periodic update timer go func() { refreshFiltersIfNecessary(false) }() // Schedule automatic filters updates go periodicallyRefreshFilters() </s> add </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/control_install.go
keep keep add keep keep keep keep
<mask> config.dnsServer = dnsforward.NewServer(config.stats, config.queryLog) <mask> <mask> initRDNS() <mask> } <mask> <mask> func isRunning() bool { <mask> return config.dnsServer != nil && config.dnsServer.IsRunning() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) if err != nil { httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) return } </s> add type filterURLJSON struct { URL string `json:"url"` Enabled bool `json:"enabled"` } </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> add if !config.filteringStarted { config.filteringStarted = true startRefreshFilters() } </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/dns.go
keep add keep keep keep keep
<mask> } <mask> <mask> return nil <mask> } <mask> <mask> func reconfigureDNSServer() error { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"` </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) } </s> remove f := filter{} err := json.NewDecoder(r.Body).Decode(&f) </s> add fj := filterAddJSON{} err := json.NewDecoder(r.Body).Decode(&fj) </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> remove // Deduplicate filters deduplicateFilters() updateUniqueFilterID(config.Filters) </s> add </s> remove func handleFilteringDisableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) </s> add func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/dns.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> ) <mask> <mask> // field ordering is important -- yaml fields will mirror ordering from here <mask> type filter struct { <mask> Enabled bool `json:"enabled"` <mask> URL string `json:"url"` <mask> Name string `json:"name" yaml:"name"` <mask> RulesCount int `json:"rulesCount" yaml:"-"` <mask> LastUpdated time.Time `json:"lastUpdated,omitempty" yaml:"-"` <mask> checksum uint32 // checksum of the file data <mask> <mask> dnsfilter.Filter `yaml:",inline"` <mask> } <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file </s> add ID int64 // auto-assigned when filter is added (see nextFilterID) Data []byte `yaml:"-"` // List of rules divided by '\n' FilePath string `yaml:"-"` // Path to a filtering rules file </s> remove func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) { parameters, err := parseParametersFromBody(r.Body) if err != nil { httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) return } </s> add type filterURLJSON struct { URL string `json:"url"` Enabled bool `json:"enabled"` } </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> add return true } type filterAddJSON struct { Name string `json:"name"` URL string `json:"url"` </s> remove // New - create instance </s> add // New - create a new instance of the query log
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } <mask> <mask> err := filter.load() <mask> if err != nil { <mask> // This is okay for the first start, the filter will be loaded later <mask> log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) <mask> } <mask> } <mask> } <mask> <mask> func deduplicateFilters() { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove f.Enabled = true </s> add </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove // Deduplicate filters deduplicateFilters() updateUniqueFilterID(config.Filters) </s> add </s> remove uf.LastUpdated = time.Now() </s> add uf.LastUpdated = now </s> add f := filter{ Enabled: true, URL: fj.URL, Name: fj.Name, }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // Sets up a timer that will be checking for filters updates periodically <mask> func periodicallyRefreshFilters() { <mask> for range time.Tick(time.Minute) { <mask> refreshFiltersIfNecessary(false) <mask> } <mask> } <mask> <mask> // Checks filters updates if necessary </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // Update filters we've just loaded right away, don't wait for periodic update timer go func() { refreshFiltersIfNecessary(false) }() // Schedule automatic filters updates go periodicallyRefreshFilters() </s> add </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove go refreshFiltersIfNecessary(false) </s> add </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove if filterExists(f.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) </s> add if filterExists(fj.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL) </s> remove // Deduplicate filters deduplicateFilters() updateUniqueFilterID(config.Filters) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> func refreshFiltersIfNecessary(force bool) int { <mask> var updateFilters []filter <mask> var updateFlags []bool // 'true' if filter data has changed <mask> <mask> if config.firstRun { <mask> return 0 <mask> } <mask> <mask> config.RLock() <mask> for i := range config.Filters { <mask> f := &config.Filters[i] // otherwise we will be operating on a copy <mask> <mask> if !f.Enabled { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove if valid := govalidator.IsRequestURL(url); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return </s> add func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { updated := refreshFiltersIfNecessary(true) fmt.Fprintf(w, "OK %d filters updated\n", updated) } type filterJSON struct { ID int64 `json:"id"` Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name"` RulesCount uint32 `json:"rules_count"` LastUpdated string `json:"last_updated"` } type filteringConfig struct { Enabled bool `json:"enabled"` Interval uint32 `json:"interval"` // in hours Filters []filterJSON `json:"filters"` UserRules []string `json:"user_rules"` } // Get filtering configuration func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled resp.Interval = config.DNS.FiltersUpdateIntervalHours for _, f := range config.Filters { fj := filterJSON{ ID: f.ID, Enabled: f.Enabled, URL: f.URL, Name: f.Name, RulesCount: uint32(f.RulesCount), } if f.LastUpdated.Second() != 0 { fj.LastUpdated = f.LastUpdated.Format(time.RFC3339) } resp.Filters = append(resp.Filters, fj) </s> remove func handleFilteringEnable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringDisable(w http.ResponseWriter, r *http.Request) { config.DNS.FilteringEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) } func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{ "enabled": config.DNS.FilteringEnabled, } config.RLock() data["filters"] = config.Filters data["user_rules"] = config.UserRules jsonVal, err := json.Marshal(data) config.RUnlock() </s> add // IsValidURL - return TRUE if URL is valid func IsValidURL(rawurl string) bool { url, err := url.ParseRequestURI(rawurl) </s> remove loadFilters() </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace keep keep keep keep keep
<mask> if !f.Enabled { <mask> continue <mask> } <mask> <mask> if !force && time.Since(f.LastUpdated) <= updatePeriod { <mask> continue <mask> } <mask> <mask> var uf filter <mask> uf.ID = f.ID </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove uf.LastUpdated = time.Now() </s> add uf.LastUpdated = now </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove f.Enabled = true </s> add </s> remove if filterExists(f.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", f.URL) </s> add if filterExists(fj.URL) { httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL) </s> add if !checkFiltersUpdateIntervalHours(config.DNS.FiltersUpdateIntervalHours) { config.DNS.FiltersUpdateIntervalHours = 24 }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace keep keep keep keep keep
<mask> if err != nil { <mask> log.Printf("Failed to update filter %s: %s\n", uf.URL, err) <mask> continue <mask> } <mask> uf.LastUpdated = time.Now() <mask> if updated { <mask> updateCount++ <mask> } <mask> } <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if !force && time.Since(f.LastUpdated) <= updatePeriod { </s> add expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60 if !force && expireTime > now.Unix() { </s> remove f.Enabled = true </s> add </s> remove loadFilters() </s> add </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/filter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> if args.bindPort != 0 { <mask> config.BindPort = args.bindPort <mask> } <mask> <mask> loadFilters() <mask> <mask> if !config.firstRun { <mask> // Save the updated config <mask> err := config.write() <mask> if err != nil { <mask> log.Fatal(err) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // Init the DNS server instance before registering HTTP handlers dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> add dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> remove if !config.firstRun { err := startDNSServer() </s> add err = startDNSServer() </s> remove } </s> add </s> remove uf.LastUpdated = time.Now() </s> add uf.LastUpdated = now </s> add config.Filters = defaultFilters() </s> remove w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "Unable to write response json: %s", err) return </s> add if len(url.Scheme) == 0 { return false //No Scheme found
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/home.go
keep replace keep replace replace replace
<mask> } <mask> } <mask> <mask> // Init the DNS server instance before registering HTTP handlers <mask> dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) <mask> initDNSServer(dnsBaseDir) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove if !config.firstRun { err := startDNSServer() </s> add err = startDNSServer() </s> add dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> add returnOK(w)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/home.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> // Init the DNS server instance before registering HTTP handlers <mask> dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) <mask> initDNSServer(dnsBaseDir) <mask> <mask> if !config.firstRun { <mask> err := startDNSServer() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> err = startDHCPServer() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // Init the DNS server instance before registering HTTP handlers dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> add dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> remove } </s> add </s> add dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir) initDNSServer(dnsBaseDir) </s> remove loadFilters() </s> add </s> remove httpError(w, http.StatusInternalServerError, "Unable to marshal status json: %s", err) return </s> add return false //Couldn't even parse the rawurl </s> remove httpUpdateConfigReloadDNSReturnOK(w, r) </s> add w.Header().Set("Content-Type", "application/json") _, err = w.Write(jsonVal) if err != nil { httpError(w, http.StatusInternalServerError, "http write: %s", err) }
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/home.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> if len(args.pidFile) != 0 && writePIDFile(args.pidFile) { <mask> config.pidFileName = args.pidFile <mask> } <mask> <mask> // Update filters we've just loaded right away, don't wait for periodic update timer <mask> go func() { <mask> refreshFiltersIfNecessary(false) <mask> }() <mask> // Schedule automatic filters updates <mask> go periodicallyRefreshFilters() <mask> <mask> // Initialize and run the admin Web interface <mask> box := packr.NewBox("../build/static") <mask> <mask> // if not configured, redirect / to /install.html, otherwise redirect /install.html to / <mask> http.Handle("/", postInstallHandler(optionalAuthHandler(gziphandler.GzipHandler(http.FileServer(box))))) </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove for range time.Tick(time.Minute) { </s> add for { time.Sleep(1 * time.Hour) if config.DNS.FiltersUpdateIntervalHours == 0 { continue } </s> remove go refreshFiltersIfNecessary(false) </s> add </s> remove if config.firstRun { return 0 } </s> add now := time.Now() </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> remove // This is okay for the first start, the filter will be loaded later log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) </s> add log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> cache []*logEntry <mask> lock sync.RWMutex <mask> } <mask> <mask> // newQueryLog creates a new instance of the query log <mask> func newQueryLog(conf Config) *queryLog { <mask> l := queryLog{} <mask> l.logFile = filepath.Join(conf.BaseDir, queryLogFileName) <mask> l.conf = conf <mask> go l.periodicQueryLogRotate() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove // Clear memory buffer and remove the file </s> add </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> add // Close query log object </s> add // Add a log entry </s> add // Get log entries
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> func (l *queryLog) Configure(conf Config) { <mask> l.conf = conf <mask> } <mask> <mask> // Clear memory buffer and remove the file <mask> func (l *queryLog) Clear() { <mask> l.fileFlushLock.Lock() <mask> defer l.fileFlushLock.Unlock() <mask> <mask> l.logBufferLock.Lock() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Get log entries </s> add // Clear memory buffer and remove log files </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> add // Close query log object
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> go l.flushLogBuffer(false) // nolint <mask> } <mask> } <mask> <mask> // getQueryLogJson returns a map with the current query log ready to be converted to a JSON <mask> func (l *queryLog) GetData() []map[string]interface{} { <mask> l.lock.RLock() <mask> values := make([]*logEntry, len(l.cache)) <mask> copy(values, l.cache) <mask> l.lock.RUnlock() </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // Clear memory buffer and remove the file </s> add </s> add // Get log entries </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove go refreshFiltersIfNecessary(false) </s> add </s> add // Add a log entry
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/qlog.go
keep keep add keep keep keep keep keep keep
<mask> <mask> // QueryLog - main interface <mask> type QueryLog interface { <mask> Close() <mask> <mask> // Set new configuration at runtime <mask> // Currently only 'Interval' field is supported. <mask> Configure(conf Config) <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Add a log entry </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> add // Clear memory buffer and remove log files </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // Update filters we've just loaded right away, don't wait for periodic update timer go func() { refreshFiltersIfNecessary(false) }() // Schedule automatic filters updates go periodicallyRefreshFilters() </s> add </s> remove // Clear memory buffer and remove the file </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/querylog.go
keep keep keep add keep keep keep keep keep
<mask> // Set new configuration at runtime <mask> // Currently only 'Interval' field is supported. <mask> Configure(conf Config) <mask> <mask> Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) <mask> <mask> // Get log entries <mask> GetData() []map[string]interface{} <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Get log entries </s> add // Clear memory buffer and remove log files </s> add // Close query log object </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/querylog.go
keep keep keep add keep keep keep keep keep keep
<mask> Configure(conf Config) <mask> <mask> // Add a log entry <mask> Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) <mask> GetData() []map[string]interface{} <mask> <mask> // Clear memory buffer and remove log files <mask> Clear() <mask> } <mask> </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Clear memory buffer and remove log files </s> add // Add a log entry </s> remove // Clear memory buffer and remove the file </s> add </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/querylog.go
keep keep keep add keep keep keep keep keep
<mask> Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) <mask> <mask> // Get log entries <mask> GetData() []map[string]interface{} <mask> Clear() <mask> } <mask> <mask> // Config - configuration object <mask> type Config struct { </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Get log entries </s> add // Add a log entry </s> add // Close query log object </s> remove // getQueryLogJson returns a map with the current query log ready to be converted to a JSON </s> add </s> remove // New - create instance </s> add // New - create a new instance of the query log </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours)
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/querylog.go
keep keep keep keep replace keep keep keep
<mask> BaseDir string // directory where log file is stored <mask> Interval uint32 // interval to rotate logs (in hours) <mask> } <mask> <mask> // New - create instance <mask> func New(conf Config) QueryLog { <mask> return newQueryLog(conf) <mask> } </s> filtering: refactor; change API; add "filters_update_interval" setting + config: "filters_update_interval" * add /control/filtering_info * remove /control/filtering/enable * remove /control/filtering/disable * add /control/filtering_config * remove /control/filtering/status * add /control/filtering/set_url * remove /control/filtering/enable_url * remove /control/filtering/disable_url </s> add // Close query log object </s> remove // newQueryLog creates a new instance of the query log </s> add // create a new instance of the query log </s> remove ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists </s> add ProtectionEnabled bool `yaml:"protection_enabled"` // whether or not use any of dnsfilter features FilteringEnabled bool `yaml:"filtering_enabled"` // whether or not use filter lists FiltersUpdateIntervalHours uint32 `yaml:"filters_update_interval"` // time period to update filters (in hours) </s> remove Enabled bool `json:"enabled"` URL string `json:"url"` Name string `json:"name" yaml:"name"` RulesCount int `json:"rulesCount" yaml:"-"` LastUpdated time.Time `json:"lastUpdated,omitempty" yaml:"-"` </s> add Enabled bool URL string Name string `yaml:"name"` RulesCount int `yaml:"-"` LastUpdated time.Time `yaml:"-"` </s> remove // Clear memory buffer and remove the file </s> add </s> remove ID int64 `json:"id"` // auto-assigned when filter is added (see nextFilterID), json by default keeps ID uppercase but we need lowercase Data []byte `json:"-" yaml:"-"` // List of rules divided by '\n' FilePath string `json:"-" yaml:"-"` // Path to a filtering rules file </s> add ID int64 // auto-assigned when filter is added (see nextFilterID) Data []byte `yaml:"-"` // List of rules divided by '\n' FilePath string `yaml:"-"` // Path to a filtering rules file
https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72
querylog/querylog.go
keep replace keep replace
<mask> - 'id' <mask> - 'lastUpdated' <mask> - 'name' <mask> - 'rulesCount' </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> add 'format': 'uint32' 'type': 'integer' </s> remove 'rulesCount': 'type': 'integer' </s> add 'type': 'string' 'rules_count': </s> add 'name': </s> remove 'name': </s> add 'format': 'date-time' </s> remove 'lastUpdated': 'type': 'string' 'format': 'date-time' </s> add 'format': 'int64' 'type': 'integer' 'last_updated':
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep replace keep replace replace replace keep
<mask> 'id': <mask> 'type': 'integer' <mask> 'example': 1234 <mask> 'lastUpdated': <mask> 'type': 'string' <mask> 'format': 'date-time' <mask> 'example': '2018-10-30T12:18:57+03:00' </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> remove 'name': </s> add 'format': 'date-time' </s> remove 'rulesCount': 'type': 'integer' </s> add 'type': 'string' 'rules_count': </s> add 'format': 'uint32' 'type': 'integer' </s> add 'name': </s> remove - 'rulesCount' </s> add - 'rules_count'
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep keep keep keep replace keep keep keep keep keep
<mask> 'lastUpdated': <mask> 'type': 'string' <mask> 'format': 'date-time' <mask> 'example': '2018-10-30T12:18:57+03:00' <mask> 'name': <mask> 'type': 'string' <mask> 'example': 'AdGuard Simplified Domain Names filter' <mask> 'rulesCount': <mask> 'type': 'integer' <mask> 'example': 5912 </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> remove 'lastUpdated': 'type': 'string' 'format': 'date-time' </s> add 'format': 'int64' 'type': 'integer' 'last_updated': </s> remove 'type': 'integer' </s> add </s> remove 'rulesCount': 'type': 'integer' </s> add 'type': 'string' 'rules_count': </s> add 'format': 'uint32' 'type': 'integer' </s> add 'name': </s> remove - 'rulesCount' </s> add - 'rules_count'
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep keep keep add keep keep keep keep keep
<mask> 'last_updated': <mask> 'example': '2018-10-30T12:18:57+03:00' <mask> 'format': 'date-time' <mask> 'type': 'string' <mask> 'example': 'AdGuard Simplified Domain Names filter' <mask> 'type': 'string' <mask> 'rules_count': <mask> 'example': 5912 <mask> 'format': 'uint32' </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> add 'format': 'uint32' 'type': 'integer' </s> remove 'lastUpdated': 'type': 'string' 'format': 'date-time' </s> add 'format': 'int64' 'type': 'integer' 'last_updated': </s> remove 'rulesCount': 'type': 'integer' </s> add 'type': 'string' 'rules_count': </s> remove 'name': </s> add 'format': 'date-time' </s> remove 'type': 'integer' </s> add </s> remove - 'rulesCount' </s> add - 'rules_count'
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep keep keep keep replace replace keep keep keep keep keep
<mask> 'example': '2018-10-30T12:18:57+03:00' <mask> 'name': <mask> 'type': 'string' <mask> 'example': 'AdGuard Simplified Domain Names filter' <mask> 'rulesCount': <mask> 'type': 'integer' <mask> 'example': 5912 <mask> 'url': <mask> 'type': 'string' <mask> 'example': > <mask> https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> add 'format': 'uint32' 'type': 'integer' </s> remove 'name': </s> add 'format': 'date-time' </s> remove 'lastUpdated': 'type': 'string' 'format': 'date-time' </s> add 'format': 'int64' 'type': 'integer' 'last_updated': </s> remove 'type': 'integer' </s> add </s> add 'name': </s> remove - 'rulesCount' </s> add - 'rules_count'
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep keep add keep keep keep keep keep keep
<mask> 'type': 'string' <mask> 'rules_count': <mask> 'example': 5912 <mask> 'url': <mask> 'type': 'string' <mask> 'example': > <mask> https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt <mask> 'FilterStatus': <mask> 'type': 'object' </s> Pull request: openapi: fix naming in filter object Merge in DNS/adguard-home from fix-openapi-filter to master Squashed commit of the following: commit 12c431b656804a27d00c9e016d290a1e90bf48ef Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 1 15:43:33 2021 +0300 openapi: fix naming in filter object </s> remove 'rulesCount': 'type': 'integer' </s> add 'type': 'string' 'rules_count': </s> add 'name': </s> remove 'lastUpdated': 'type': 'string' 'format': 'date-time' </s> add 'format': 'int64' 'type': 'integer' 'last_updated': </s> remove 'name': </s> add 'format': 'date-time' </s> remove 'type': 'integer' </s> add </s> remove - 'rulesCount' </s> add - 'rules_count'
https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b
openapi/openapi.yaml
keep keep keep keep replace keep keep keep keep keep
<mask> httpError(w, http.StatusBadRequest, "json decode: %s", err) <mask> return <mask> } <mask> <mask> cookie := config.auth.httpCookie(req) <mask> if len(cookie) == 0 { <mask> log.Info("Auth: invalid user name or password: name='%s'", req.Name) <mask> time.Sleep(1 * time.Second) <mask> http.Error(w, "invalid user name or password", http.StatusBadRequest) <mask> return </s> *(global): refactoring - moved runtime properties to Context </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> add for i := 0; i < 5; i++ { // Waiting until the DNS server is up and running if !isRunning() { time.Sleep(1 * time.Second) } } </s> remove for i := 0; i != 5; i++ { resp, err = h.Get("http://127.0.0.1:3000/") if err == nil && resp.StatusCode != 404 { break } time.Sleep(1 * time.Second) } </s> add resp, err = h.Get("http://127.0.0.1:3000/") </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if config.auth == nil { </s> add Context.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if Context.auth == nil {
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> func handleLogout(w http.ResponseWriter, r *http.Request) { <mask> cookie := r.Header.Get("Cookie") <mask> sess := parseCookie(cookie) <mask> <mask> config.auth.RemoveSession(sess) <mask> <mask> w.Header().Set("Location", "/login.html") <mask> <mask> s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", <mask> sessionCookieName) </s> *(global): refactoring - moved runtime properties to Context </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove if config.disableUpdate { </s> add if Context.disableUpdate { </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.auth = InitAuth(fn, users, 60) </s> add Context.auth = InitAuth(fn, users, 60) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep replace keep keep replace keep keep
<mask> if r.URL.Path == "/login.html" { <mask> // redirect to dashboard if already authenticated <mask> authRequired := config.auth != nil && config.auth.AuthRequired() <mask> cookie, err := r.Cookie(sessionCookieName) <mask> if authRequired && err == nil { <mask> r := config.auth.CheckSession(cookie.Value) <mask> if r == 0 { <mask> w.Header().Set("Location", "/") </s> *(global): refactoring - moved runtime properties to Context </s> remove } else if config.auth != nil && config.auth.AuthRequired() { </s> add } else if Context.auth != nil && Context.auth.AuthRequired() { </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove if config.firstRun && </s> add if Context.firstRun && </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if config.auth == nil { </s> add Context.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if Context.auth == nil {
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep replace keep keep keep keep replace keep keep keep
<mask> // process as usual <mask> <mask> } else if config.auth != nil && config.auth.AuthRequired() { <mask> // redirect to login page if not authenticated <mask> ok := false <mask> cookie, err := r.Cookie(sessionCookieName) <mask> if err == nil { <mask> r := config.auth.CheckSession(cookie.Value) <mask> if r == 0 { <mask> ok = true <mask> } else if r < 0 { </s> *(global): refactoring - moved runtime properties to Context </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove if !config.firstRun { </s> add if !Context.firstRun {
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> } else { <mask> // there's no Cookie, check Basic authentication <mask> user, pass, ok2 := r.BasicAuth() <mask> if ok2 { <mask> u := config.auth.UserFind(user, pass) <mask> if len(u.Name) != 0 { <mask> ok = true <mask> } else { <mask> log.Info("Auth: invalid Basic Authorization value") <mask> } </s> *(global): refactoring - moved runtime properties to Context </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove } else if config.auth != nil && config.auth.AuthRequired() { </s> add } else if Context.auth != nil && Context.auth.AuthRequired() { </s> remove logFilePath := filepath.Join(config.ourWorkingDir, ls.LogFile) </s> add logFilePath := filepath.Join(Context.workDir, ls.LogFile) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove config.firstRun = true </s> add Context.firstRun = true
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> if err != nil { <mask> // there's no Cookie, check Basic authentication <mask> user, pass, ok := r.BasicAuth() <mask> if ok { <mask> u := config.auth.UserFind(user, pass) <mask> return u <mask> } <mask> return User{} <mask> } <mask> </s> *(global): refactoring - moved runtime properties to Context </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove config.auth.UserAdd(&u, newSettings.Password) </s> add Context.auth.UserAdd(&u, newSettings.Password) </s> remove } else if config.auth != nil && config.auth.AuthRequired() { </s> add } else if Context.auth != nil && Context.auth.AuthRequired() { </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove workDir := config.ourWorkingDir </s> add workDir := Context.workDir
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> users := []User{ <mask> User{Name: "name", PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2"}, <mask> } <mask> config.auth = InitAuth(fn, users, 60) <mask> <mask> handlerCalled := false <mask> handler := func(w http.ResponseWriter, r *http.Request) { <mask> handlerCalled = true <mask> } </s> *(global): refactoring - moved runtime properties to Context </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> remove if !config.firstRun { </s> add if !Context.firstRun { </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove if config.disableUpdate { </s> add if Context.disableUpdate { </s> remove } else if config.auth != nil && config.auth.AuthRequired() { </s> add } else if Context.auth != nil && Context.auth.AuthRequired() {
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> handler2(&w, &r) <mask> assert.True(t, handlerCalled) <mask> <mask> // perform login <mask> cookie := config.auth.httpCookie(loginJSON{Name: "name", Password: "password"}) <mask> assert.True(t, cookie != "") <mask> <mask> // get / <mask> handler2 = optionalAuth(handler) <mask> w.hdr = make(http.Header) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.auth.Close() </s> add Context.auth.Close() </s> remove assert.True(t, err == nil, "%s", err) </s> add assert.Nil(t, err) </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove assert.Truef(t, err == nil, "%s", err) </s> add assert.Nil(t, err) </s> remove configfile := config.ourConfigFilename </s> add configfile := Context.configFilename </s> remove cookie := config.auth.httpCookie(req) </s> add cookie := Context.auth.httpCookie(req)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth_test.go
keep keep keep keep replace keep
<mask> handler2(&w, &r) <mask> assert.True(t, handlerCalled) <mask> r.Header.Del("Cookie") <mask> <mask> config.auth.Close() <mask> } </s> *(global): refactoring - moved runtime properties to Context </s> remove cookie := config.auth.httpCookie(loginJSON{Name: "name", Password: "password"}) </s> add cookie := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}) </s> remove if config.auth != nil { config.auth.Close() config.auth = nil </s> add if Context.auth != nil { Context.auth.Close() Context.auth = nil </s> remove assert.True(t, err == nil, "%s", err) </s> add assert.Nil(t, err) </s> remove assert.Truef(t, err == nil, "%s", err) </s> add assert.Nil(t, err) </s> remove config.controlLock.Lock() defer config.controlLock.Unlock() </s> add Context.controlLock.Lock() defer Context.controlLock.Unlock() </s> remove configFile = filepath.Join(config.ourWorkingDir, configFile) </s> add configFile = filepath.Join(Context.workDir, configFile)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/auth_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> // Raw file data to avoid re-reading of configuration file <mask> // It's reset after config is parsed <mask> fileData []byte <mask> <mask> ourConfigFilename string // Config filename (can be overridden via the command line arguments) <mask> ourWorkingDir string // Location of our directory, used to protect against CWD being somewhere else <mask> firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html <mask> pidFileName string // PID file name. Empty if no PID file was created. <mask> // runningAsService flag is set to true when options are passed from the service runner <mask> runningAsService bool <mask> disableUpdate bool // If set, don't check for updates <mask> appSignalChannel chan os.Signal <mask> controlLock sync.Mutex <mask> transport *http.Transport <mask> client *http.Client <mask> auth *Auth // HTTP authentication module <mask> <mask> // cached version.json to avoid hammering github.io for each page reload <mask> versionCheckJSON []byte <mask> versionCheckLastTime time.Time <mask> <mask> BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to </s> *(global): refactoring - moved runtime properties to Context </s> remove // run is a blocking method and it won't exit until the service is stopped! </s> add // run is a blocking method! </s> add auth *Auth // HTTP authentication module </s> remove // getDataDir returns path to the directory where we store databases and filters func (c *configuration) getDataDir() string { return filepath.Join(c.ourWorkingDir, dataDir) } </s> add </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) </s> add configFile, err := filepath.EvalSymlinks(Context.configFilename) </s> remove return filepath.Join(config.getDataDir(), filterDir, strconv.FormatInt(filter.ID, 10)+".txt") </s> add return filepath.Join(Context.getDataDir(), filterDir, strconv.FormatInt(filter.ID, 10)+".txt") </s> remove if config.firstRun { </s> add if Context.firstRun {
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> // initialize to default values, will be changed later when reading config or parsing command line <mask> var config = configuration{ <mask> ourConfigFilename: "AdGuardHome.yaml", <mask> BindPort: 3000, <mask> BindHost: "0.0.0.0", <mask> DNS: dnsConfig{ <mask> BindHost: "0.0.0.0", <mask> Port: 53, <mask> StatsInterval: 1, <mask> FilteringConfig: dnsforward.FilteringConfig{ </s> *(global): refactoring - moved runtime properties to Context </s> remove config.ourConfigFilename = args.configFilename </s> add Context.configFilename = args.configFilename } else { // Default config file name Context.configFilename = "AdGuardHome.yaml" } // Init some of the Context fields right away Context.transport = &http.Transport{ DialContext: customDialContext, } Context.client = &http.Client{ Timeout: time.Minute * 5, Transport: Context.transport, </s> remove ourConfigFilename string // Config filename (can be overridden via the command line arguments) ourWorkingDir string // Location of our directory, used to protect against CWD being somewhere else firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html pidFileName string // PID file name. Empty if no PID file was created. // runningAsService flag is set to true when options are passed from the service runner runningAsService bool disableUpdate bool // If set, don't check for updates appSignalChannel chan os.Signal controlLock sync.Mutex transport *http.Transport client *http.Client auth *Auth // HTTP authentication module </s> add </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) </s> add configFile, err := filepath.EvalSymlinks(Context.configFilename) </s> remove // run is a blocking method and it won't exit until the service is stopped! </s> add // run is a blocking method! </s> remove config.ourWorkingDir = args.workDir </s> add Context.workDir = args.workDir </s> remove config.ourWorkingDir = filepath.Dir(exec) </s> add Context.workDir = filepath.Dir(execPath)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> // initConfig initializes default configuration for the current OS&ARCH <mask> func initConfig() { <mask> config.transport = &http.Transport{ <mask> DialContext: customDialContext, <mask> } <mask> config.client = &http.Client{ <mask> Timeout: time.Minute * 5, <mask> Transport: config.transport, <mask> } <mask> <mask> config.WebSessionTTLHours = 30 * 24 <mask> <mask> config.DNS.QueryLogEnabled = true <mask> config.DNS.QueryLogInterval = 90 <mask> config.DNS.QueryLogMemSize = 1000 </s> *(global): refactoring - moved runtime properties to Context </s> remove config.client = &http.Client{ </s> add Context.client = &http.Client{ </s> remove config.ourConfigFilename = args.configFilename </s> add Context.configFilename = args.configFilename } else { // Default config file name Context.configFilename = "AdGuardHome.yaml" } // Init some of the Context fields right away Context.transport = &http.Transport{ DialContext: customDialContext, } Context.client = &http.Client{ Timeout: time.Minute * 5, Transport: Context.transport, </s> add Context.appSignalChannel = make(chan os.Signal) signal.Notify(Context.appSignalChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT) go func() { <-Context.appSignalChannel cleanup() cleanupAlways() os.Exit(0) }() </s> remove for i := 0; i != 5; i++ { resp, err = h.Get("http://127.0.0.1:3000/") if err == nil && resp.StatusCode != 404 { break } time.Sleep(1 * time.Second) } </s> add resp, err = h.Get("http://127.0.0.1:3000/") </s> add for i := 0; i < 5; i++ { // Waiting until the DNS server is up and running if !isRunning() { time.Sleep(1 * time.Second) } } </s> remove configFile = filepath.Join(config.ourWorkingDir, configFile) </s> add configFile = filepath.Join(Context.workDir, configFile)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep replace keep keep keep keep replace
<mask> func (c *configuration) getConfigFilename() string { <mask> configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) <mask> if err != nil { <mask> if !os.IsNotExist(err) { <mask> log.Error("unexpected error while config file path evaluation: %s", err) <mask> } <mask> configFile = config.ourConfigFilename </s> *(global): refactoring - moved runtime properties to Context </s> remove // getDataDir returns path to the directory where we store databases and filters func (c *configuration) getDataDir() string { return filepath.Join(c.ourWorkingDir, dataDir) } </s> add </s> remove configfile = filepath.Join(config.ourWorkingDir, config.ourConfigFilename) </s> add configfile = filepath.Join(Context.workDir, Context.configFilename) </s> remove configFile = filepath.Join(config.ourWorkingDir, configFile) </s> add configFile = filepath.Join(Context.workDir, configFile) </s> remove config.ourConfigFilename = args.configFilename </s> add Context.configFilename = args.configFilename } else { // Default config file name Context.configFilename = "AdGuardHome.yaml" } // Init some of the Context fields right away Context.transport = &http.Transport{ DialContext: customDialContext, } Context.client = &http.Client{ Timeout: time.Minute * 5, Transport: Context.transport, </s> remove resp, err := config.client.Get(u.pkgURL) </s> add resp, err := Context.client.Get(u.pkgURL)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep keep keep keep replace keep keep keep keep replace replace replace replace replace keep keep keep
<mask> } <mask> configFile = config.ourConfigFilename <mask> } <mask> if !filepath.IsAbs(configFile) { <mask> configFile = filepath.Join(config.ourWorkingDir, configFile) <mask> } <mask> return configFile <mask> } <mask> <mask> // getDataDir returns path to the directory where we store databases and filters <mask> func (c *configuration) getDataDir() string { <mask> return filepath.Join(c.ourWorkingDir, dataDir) <mask> } <mask> <mask> // getLogSettings reads logging settings from the config file. <mask> // we do it in a separate method in order to configure logger before the actual configuration is parsed and applied. <mask> func getLogSettings() logSettings { </s> *(global): refactoring - moved runtime properties to Context </s> remove configFile = config.ourConfigFilename </s> add configFile = Context.configFilename </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) </s> add configFile, err := filepath.EvalSymlinks(Context.configFilename) </s> remove // run is a blocking method and it won't exit until the service is stopped! </s> add // run is a blocking method! </s> remove config.ourConfigFilename = args.configFilename </s> add Context.configFilename = args.configFilename } else { // Default config file name Context.configFilename = "AdGuardHome.yaml" } // Init some of the Context fields right away Context.transport = &http.Transport{ DialContext: customDialContext, } Context.client = &http.Client{ Timeout: time.Minute * 5, Transport: Context.transport, </s> remove config.ourWorkingDir = filepath.Dir(exec) </s> add Context.workDir = filepath.Dir(execPath)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> defer c.Unlock() <mask> <mask> Context.clients.WriteDiskConfig(&config.Clients) <mask> <mask> if config.auth != nil { <mask> config.Users = config.auth.GetUsers() <mask> } <mask> <mask> if Context.stats != nil { <mask> sdc := stats.DiskConfig{} <mask> Context.stats.WriteDiskConfig(&sdc) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if config.auth == nil { </s> add Context.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60) if Context.auth == nil { </s> remove if config.auth != nil { config.auth.Close() config.auth = nil </s> add if Context.auth != nil { Context.auth.Close() Context.auth = nil </s> remove resp, err := config.client.Get(u.pkgURL) </s> add resp, err := Context.client.Get(u.pkgURL) </s> remove } else if config.auth != nil && config.auth.AuthRequired() { </s> add } else if Context.auth != nil && Context.auth.AuthRequired() { </s> remove if !config.firstRun { </s> add if !Context.firstRun { </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/config.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> func handleGetProfile(w http.ResponseWriter, r *http.Request) { <mask> pj := profileJSON{} <mask> u := config.auth.GetCurrentUser(r) <mask> pj.Name = u.Name <mask> <mask> data, err := json.Marshal(pj) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "json.Marshal: %s", err) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove config.auth.UserAdd(&u, newSettings.Password) </s> add Context.auth.UserAdd(&u, newSettings.Password) </s> remove if config.disableUpdate { </s> add if Context.disableUpdate { </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired()
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control.go
keep keep replace keep replace keep keep keep
<mask> <mask> func handleFilteringRefresh(w http.ResponseWriter, r *http.Request) { <mask> config.controlLock.Unlock() <mask> nUpdated, err := refreshFilters() <mask> config.controlLock.Lock() <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "%s", err) <mask> return </s> *(global): refactoring - moved runtime properties to Context </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> remove if config.disableUpdate { </s> add if Context.disableUpdate { </s> remove config.firstRun = true </s> add Context.firstRun = true
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_filtering.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> var curConfig configuration <mask> copyInstallSettings(&curConfig, &config) <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 <mask> </s> *(global): refactoring - moved runtime properties to Context </s> remove config.firstRun = detectFirstRun() if config.firstRun { </s> add Context.firstRun = detectFirstRun() if Context.firstRun { </s> remove config.runningAsService = args.runningAsService config.disableUpdate = args.disableUpdate </s> add Context.runningAsService = args.runningAsService Context.disableUpdate = args.disableUpdate </s> remove config.ourWorkingDir = "..." // set absolute path </s> add Context.workDir = "..." // set absolute path </s> remove config.transport = &http.Transport{ DialContext: customDialContext, } config.client = &http.Client{ Timeout: time.Minute * 5, Transport: config.transport, } </s> add </s> remove config.auth.UserAdd(&u, newSettings.Password) </s> add Context.auth.UserAdd(&u, newSettings.Password) </s> remove config.auth = InitAuth(fn, users, 60) </s> add Context.auth = InitAuth(fn, users, 60)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_install.go
keep keep keep keep replace keep keep keep keep keep
<mask> closeDNSServer() <mask> } <mask> } <mask> if err != nil || err2 != nil { <mask> config.firstRun = true <mask> copyInstallSettings(&config, &curConfig) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't initialize DNS server: %s", err) <mask> } else { <mask> httpError(w, http.StatusInternalServerError, "Couldn't start DNS server: %s", err2) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.auth.UserAdd(&u, newSettings.Password) </s> add Context.auth.UserAdd(&u, newSettings.Password) </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock()
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_install.go
keep keep keep replace keep keep keep replace keep keep
<mask> <mask> u := User{} <mask> u.Name = newSettings.Username <mask> config.auth.UserAdd(&u, newSettings.Password) <mask> <mask> err = config.write() <mask> if err != nil { <mask> config.firstRun = true <mask> copyInstallSettings(&config, &curConfig) <mask> httpError(w, http.StatusInternalServerError, "Couldn't write config: %s", err) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_install.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // Get the latest available version from the Internet <mask> func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { <mask> <mask> if config.disableUpdate { <mask> return <mask> } <mask> <mask> req := getVersionJSONRequest{} <mask> err := json.NewDecoder(r.Body).Decode(&req) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove if !config.firstRun { </s> add if !Context.firstRun { </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove if config.firstRun && </s> add if Context.firstRun &&
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep replace
<mask> } <mask> <mask> now := time.Now() <mask> if !req.RecheckNow { <mask> config.controlLock.Lock() <mask> cached := now.Sub(config.versionCheckLastTime) <= versionCheckPeriod && len(config.versionCheckJSON) != 0 <mask> data := config.versionCheckJSON <mask> config.controlLock.Unlock() </s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove r := config.auth.CheckSession(cookie.Value) </s> add r := Context.auth.CheckSession(cookie.Value) </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove authRequired := config.auth != nil && config.auth.AuthRequired() </s> add authRequired := Context.auth != nil && Context.auth.AuthRequired()
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> var resp *http.Response <mask> for i := 0; i != 3; i++ { <mask> log.Tracef("Downloading data from %s", versionCheckURL) <mask> resp, err = config.client.Get(versionCheckURL) <mask> if err != nil && strings.HasSuffix(err.Error(), "i/o timeout") { <mask> // This case may happen while we're restarting DNS server <mask> // https://github.com/AdguardTeam/AdGuardHome/issues/934 <mask> continue <mask> } </s> *(global): refactoring - moved runtime properties to Context </s> add for i := 0; i < 5; i++ { // Waiting until the DNS server is up and running if !isRunning() { time.Sleep(1 * time.Second) } } </s> remove for i := 0; i != 5; i++ { resp, err = h.Get("http://127.0.0.1:3000/") if err == nil && resp.StatusCode != 404 { break } time.Sleep(1 * time.Second) } </s> add resp, err = h.Get("http://127.0.0.1:3000/") </s> remove resp, err := config.client.Get(filter.URL) </s> add resp, err := Context.client.Get(filter.URL) </s> remove resp, err := config.client.Get(u.pkgURL) </s> add resp, err := Context.client.Get(u.pkgURL) </s> remove if len(config.pidFileName) != 0 { os.Remove(config.pidFileName) </s> add if len(Context.pidFileName) != 0 { _ = os.Remove(Context.pidFileName) </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) </s> add configFile, err := filepath.EvalSymlinks(Context.configFilename)
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep keep keep keep
<mask> httpError(w, http.StatusBadGateway, "Couldn't read response body from %s: %s", versionCheckURL, err) <mask> return <mask> } <mask> <mask> config.controlLock.Lock() <mask> config.versionCheckLastTime = now <mask> config.versionCheckJSON = body <mask> config.controlLock.Unlock() <mask> <mask> w.Header().Set("Content-Type", "application/json") </s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock()
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> config.controlLock.Lock() <mask> config.versionCheckLastTime = now <mask> config.versionCheckJSON = body <mask> config.controlLock.Unlock() <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(getVersionResp(body)) <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't write body: %s", err) </s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.firstRun = true </s> add Context.firstRun = true </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock() </s> add Context.controlLock.Lock() </s> remove config.controlLock.Unlock() </s> add Context.controlLock.Unlock()
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep keep keep keep
<mask> // Fill in updateInfo object <mask> func getUpdateInfo(jsonData []byte) (*updateInfo, error) { <mask> var u updateInfo <mask> <mask> workDir := config.ourWorkingDir <mask> <mask> versionJSON := make(map[string]interface{}) <mask> err := json.Unmarshal(jsonData, &versionJSON) <mask> if err != nil { <mask> return nil, fmt.Errorf("JSON parse: %s", err) </s> *(global): refactoring - moved runtime properties to Context </s> remove u := config.auth.GetCurrentUser(r) </s> add u := Context.auth.GetCurrentUser(r) </s> remove u := config.auth.UserFind(user, pass) </s> add u := Context.auth.UserFind(user, pass) </s> remove for i := 0; i != 5; i++ { resp, err = h.Get("http://127.0.0.1:3000/") if err == nil && resp.StatusCode != 404 { break } time.Sleep(1 * time.Second) } </s> add resp, err = h.Get("http://127.0.0.1:3000/") </s> remove resp, err := config.client.Get(filter.URL) </s> add resp, err := Context.client.Get(filter.URL) </s> add for i := 0; i < 5; i++ { // Waiting until the DNS server is up and running if !isRunning() { time.Sleep(1 * time.Second) } } </s> remove dnsFilterPath := filepath.Join(config.ourWorkingDir, "dnsfilter.txt") </s> add dnsFilterPath := filepath.Join(Context.workDir, "dnsfilter.txt")
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // Download package file and save it to disk <mask> func getPackageFile(u *updateInfo) error { <mask> resp, err := config.client.Get(u.pkgURL) <mask> if err != nil { <mask> return fmt.Errorf("HTTP request failed: %s", err) <mask> } <mask> if resp != nil && resp.Body != nil { <mask> defer resp.Body.Close() </s> *(global): refactoring - moved runtime properties to Context </s> remove resp, err := config.client.Get(filter.URL) </s> add resp, err := Context.client.Get(filter.URL) </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) </s> add configFile, err := filepath.EvalSymlinks(Context.configFilename) </s> remove for i := 0; i != 5; i++ { resp, err = h.Get("http://127.0.0.1:3000/") if err == nil && resp.StatusCode != 404 { break } time.Sleep(1 * time.Second) } </s> add resp, err = h.Get("http://127.0.0.1:3000/") </s> remove resp, err = config.client.Get(versionCheckURL) </s> add resp, err = Context.client.Get(versionCheckURL) </s> remove if config.firstRun && </s> add if Context.firstRun && </s> remove configFile = config.ourConfigFilename </s> add configFile = Context.configFilename
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep keep replace keep keep replace keep keep
<mask> } <mask> <mask> // ./README.md -> backup/README.md <mask> err = copySupportingFiles(files, config.ourWorkingDir, u.backupDir, true, true) <mask> if err != nil { <mask> return fmt.Errorf("copySupportingFiles(%s, %s) failed: %s", <mask> config.ourWorkingDir, u.backupDir, err) <mask> } <mask> </s> *(global): refactoring - moved runtime properties to Context </s> remove err = copySupportingFiles(files, u.updateDir, config.ourWorkingDir, false, true) </s> add err = copySupportingFiles(files, u.updateDir, Context.workDir, false, true) </s> remove u.updateDir, config.ourWorkingDir, err) </s> add u.updateDir, Context.workDir, err) </s> remove resp, err := config.client.Get(u.pkgURL) </s> add resp, err := Context.client.Get(u.pkgURL) </s> remove configFile = config.ourConfigFilename </s> add configFile = Context.configFilename </s> remove config.firstRun = true </s> add Context.firstRun = true
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go
keep keep replace keep keep replace keep keep
<mask> <mask> // update/[AdGuardHome/]README.md -> ./README.md <mask> err = copySupportingFiles(files, u.updateDir, config.ourWorkingDir, false, true) <mask> if err != nil { <mask> return fmt.Errorf("copySupportingFiles(%s, %s) failed: %s", <mask> u.updateDir, config.ourWorkingDir, err) <mask> } <mask> </s> *(global): refactoring - moved runtime properties to Context </s> remove config.ourWorkingDir, u.backupDir, err) </s> add Context.workDir, u.backupDir, err) </s> remove err = copySupportingFiles(files, config.ourWorkingDir, u.backupDir, true, true) </s> add err = copySupportingFiles(files, Context.workDir, u.backupDir, true, true) </s> remove resp, err := config.client.Get(u.pkgURL) </s> add resp, err := Context.client.Get(u.pkgURL) </s> remove configFile = config.ourConfigFilename </s> add configFile = Context.configFilename </s> remove config.firstRun = true </s> add Context.firstRun = true
https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d
home/control_update.go