docstring_tokens stringlengths 0 76.5k | code_tokens stringlengths 75 1.81M | label_window listlengths 4 2.12k | html_url stringlengths 74 116 | file_name stringlengths 3 311 |
|---|---|---|---|---|
if len(url.Scheme) == 0 {
return false //No Scheme found | <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>
<mask> func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) {
<mask> f := filter{}
</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.StatusInternalServerError, "Unable to marshal status json: %s", err)
return
</s> add return false //Couldn't even parse the rawurl </s> remove f := filter{}
err := json.NewDecoder(r.Body).Decode(&f)
</s> add fj := filterAddJSON{}
err := json.NewDecoder(r.Body).Decode(&fj) </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> 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
return true
}
type filterAddJSON struct {
Name string `json:"name"`
URL string `json:"url"` | <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) | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
fj := filterAddJSON{}
err := json.NewDecoder(r.Body).Decode(&fj) | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
if !IsValidURL(fj.URL) {
http.Error(w, "Invalid URL", http.StatusBadRequest) | <mask> httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err)
<mask> return
<mask> }
<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) {
</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(req.URL); !valid {
</s> add if !IsValidURL(req.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 found := filterEnable(url, true)
</s> add found := filterEnable(fj.URL, fj.Enabled) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
if filterExists(fj.URL) {
httpError(w, http.StatusBadRequest, "Filter URL already added -- %s", fj.URL) | <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
<mask> f.ID = assignUniqueFilterID()
</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 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 for range time.Tick(time.Minute) {
</s> add for {
time.Sleep(1 * time.Hour)
if config.DNS.FiltersUpdateIntervalHours == 0 {
continue
}
</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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
f := filter{
Enabled: true,
URL: fj.URL,
Name: fj.Name,
} | <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() { | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
<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> 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go | |
if !IsValidURL(req.URL) { | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
type filterURLJSON struct {
URL string `json:"url"`
Enabled bool `json:"enabled"`
} | <mask> config.Unlock()
<mask> httpUpdateConfigReloadDNSReturnOK(w, r)
<mask> }
<mask>
<mask> func handleFilteringEnableURL(w http.ResponseWriter, r *http.Request) {
<mask> parameters, err := parseParametersFromBody(r.Body)
<mask> if err != nil {
<mask> 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 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 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
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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
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) | <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
<mask> }
<mask>
<mask> if valid := govalidator.IsRequestURL(url); !valid {
<mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest)
</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 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 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 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(req.URL); !valid {
</s> add if !IsValidURL(req.URL) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
if !IsValidURL(fj.URL) {
http.Error(w, "invalid URL", http.StatusBadRequest) | <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> }
<mask>
<mask> found := filterEnable(url, true)
<mask> if !found {
</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 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 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 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 http.Error(w, "URL parameter was not previously added", http.StatusBadRequest)
</s> add http.Error(w, "URL doesn't exist", http.StatusBadRequest) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
found := filterEnable(fj.URL, fj.Enabled) | <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> }
<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)
</s> add if !IsValidURL(fj.URL) {
http.Error(w, "invalid URL", http.StatusBadRequest) </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, 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 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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
http.Error(w, "URL doesn't exist", http.StatusBadRequest) | <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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
func handleFilteringSetRules(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body) | <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>
</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 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) | <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> url, ok := parameters["url"]
<mask> if !ok {
</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 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 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 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
config.UserRules = strings.Split(string(body), "\n")
httpUpdateConfigReloadDNSReturnOK(w, r)
} | <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
<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 </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(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 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 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(req.URL); !valid {
</s> add if !IsValidURL(req.URL) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
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) | <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> }
<mask>
<mask> found := filterEnable(url, false)
<mask> if !found {
<mask> http.Error(w, "URL parameter was not previously added", http.StatusBadRequest)
</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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
resp.UserRules = config.UserRules
config.RUnlock() | <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)
} | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
jsonVal, err := json.Marshal(resp)
if err != nil {
httpError(w, http.StatusInternalServerError, "json encode: %s", err) | <mask> http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest)
<mask> return
<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> }
</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 http.Error(w, "URL parameter was not previously added", http.StatusBadRequest)
</s> add http.Error(w, "URL doesn't exist", http.StatusBadRequest) </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 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(jsonVal)
if err != nil {
httpError(w, http.StatusInternalServerError, "http write: %s", err)
} | <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)
<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 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, 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 found := filterEnable(url, true)
</s> add found := filterEnable(fj.URL, fj.Enabled) </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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
// Set filtering configuration
func handleFilteringConfig(w http.ResponseWriter, r *http.Request) {
req := filteringConfig{}
err := json.NewDecoder(r.Body).Decode(&req) | <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>
</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 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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
httpError(w, http.StatusBadRequest, "json decode: %s", err) | <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> config.UserRules = strings.Split(string(body), "\n")
<mask> httpUpdateConfigReloadDNSReturnOK(w, r)
</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 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 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 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
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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
if !checkFiltersUpdateIntervalHours(req.Interval) {
httpError(w, http.StatusBadRequest, "Unsupported interval")
return
}
config.DNS.FilteringEnabled = req.Enabled
config.DNS.FiltersUpdateIntervalHours = req.Interval | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
returnOK(w) | <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
}
| [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
// 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 | <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)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_filtering.go |
"path/filepath" | <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> remove "github.com/asaskevich/govalidator"
</s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_install.go |
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
initDNSServer(dnsBaseDir)
| <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> 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) | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_install.go |
<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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/control_install.go | |
initFiltering() | <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) | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/dns.go |
if !config.filteringStarted {
config.filteringStarted = true
startRefreshFilters()
}
| <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> 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 | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/dns.go |
Enabled bool
URL string
Name string `yaml:"name"`
RulesCount int `yaml:"-"`
LastUpdated time.Time `yaml:"-"` | <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)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
log.Error("Couldn't load filter %d contents due to %s", filter.ID, err) | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
for {
time.Sleep(1 * time.Hour)
if config.DNS.FiltersUpdateIntervalHours == 0 {
continue
}
| <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
now := time.Now() | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
expireTime := f.LastUpdated.Unix() + int64(config.DNS.FiltersUpdateIntervalHours)*60*60
if !force && expireTime > now.Unix() { | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
uf.LastUpdated = now | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/filter.go |
<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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/home.go | |
<mask> err := config.write()
<mask> if err != nil {
<mask> log.Fatal(err)
<mask> }
<mask> }
<mask>
<mask> // Init the DNS server instance before registering HTTP handlers
<mask> dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
<mask> initDNSServer(dnsBaseDir)
<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 // 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 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/home.go | |
dnsBaseDir := filepath.Join(config.ourWorkingDir, dataDir)
initDNSServer(dnsBaseDir) | <mask> log.Fatal(err)
<mask> }
<mask> }
<mask>
<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)
</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 }
</s> add </s> remove loadFilters()
</s> add </s> remove f := filter{}
err := json.NewDecoder(r.Body).Decode(&f)
</s> add fj := filterAddJSON{}
err := json.NewDecoder(r.Body).Decode(&fj) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/home.go |
err = startDNSServer() | <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> 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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/home.go |
<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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | home/home.go | |
// create a new instance of the query log | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/qlog.go |
<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> 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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/qlog.go | |
<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> remove // New - create instance
</s> add // New - create a new instance of the query log </s> remove go refreshFiltersIfNecessary(false)
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/qlog.go | |
// Close query log object | <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> 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 // 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 | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/querylog.go |
// Add a log entry | <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> 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 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/querylog.go |
// Get log entries | <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> 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 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/querylog.go |
// Clear memory buffer and remove log files | <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> 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 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/querylog.go |
// New - create a new instance of the query log | <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> 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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb422fedf64a2fc87bd296c9dc3d12c5e3a4d72 | querylog/querylog.go |
- 'last_updated' | <mask> 'description': 'Filter subscription info'
<mask> 'required':
<mask> - 'enabled'
<mask> - 'id'
<mask> - 'lastUpdated'
<mask> - 'name'
<mask> - 'rulesCount'
<mask> - 'url'
<mask> 'properties':
<mask> 'enabled':
</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'
</s> add - 'rules_count' </s> remove 'type': 'integer'
</s> add </s> remove 'rulesCount':
'type': 'integer'
</s> add 'type': 'string'
'rules_count': | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
- 'rules_count' | <mask> - 'enabled'
<mask> - 'id'
<mask> - 'lastUpdated'
<mask> - 'name'
<mask> - 'rulesCount'
<mask> - 'url'
<mask> 'properties':
<mask> 'enabled':
<mask> 'type': 'boolean'
<mask> 'id':
</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'
</s> add - 'last_updated' </s> remove 'type': 'integer'
</s> add </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': | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
<mask> 'properties':
<mask> 'enabled':
<mask> 'type': 'boolean'
<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 'lastUpdated':
'type': 'string'
'format': 'date-time'
</s> add 'format': 'int64'
'type': 'integer'
'last_updated': </s> remove 'name':
</s> add 'format': 'date-time' </s> remove - 'rulesCount'
</s> add - 'rules_count' </s> remove 'rulesCount':
'type': 'integer'
</s> add 'type': 'string'
'rules_count': | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml | |
'format': 'int64'
'type': 'integer'
'last_updated': | <mask> 'type': 'boolean'
<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'
<mask> 'name':
<mask> 'type': 'string'
<mask> 'example': 'AdGuard Simplified Domain Names filter'
<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> remove 'type': 'integer'
</s> add </s> remove 'name':
</s> add 'format': 'date-time' </s> remove 'rulesCount':
'type': 'integer'
</s> add 'type': 'string'
'rules_count': | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
'format': 'date-time' | <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': | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
'name': | <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> 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 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
'type': 'string'
'rules_count': | <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> 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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
'format': 'uint32'
'type': 'integer' | <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> 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 | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/adb76aa9b88c2383f2c80cb1934b664439cccb8b | openapi/openapi.yaml |
cookie := Context.auth.httpCookie(req) | <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> 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
Context.auth.RemoveSession(sess) | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
authRequired := Context.auth != nil && Context.auth.AuthRequired() | <mask> return func(w http.ResponseWriter, r *http.Request) {
<mask>
<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 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 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 if config.disableUpdate {
</s> add if Context.disableUpdate { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
r := Context.auth.CheckSession(cookie.Value) | <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", "/")
<mask> w.WriteHeader(http.StatusFound)
<mask> return
<mask> } else if r < 0 {
</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 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 config.controlLock.Lock()
</s> add Context.controlLock.Lock() </s> remove config.controlLock.Unlock()
</s> add Context.controlLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
} else if Context.auth != nil && Context.auth.AuthRequired() { | <mask> strings.HasPrefix(r.URL.Path, "/login.") ||
<mask> strings.HasPrefix(r.URL.Path, "/__locales/") {
<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)
</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 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
r := Context.auth.CheckSession(cookie.Value) | <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 {
<mask> log.Info("Auth: invalid cookie value: %s", cookie)
<mask> }
</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 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 cookie := config.auth.httpCookie(req)
</s> add cookie := Context.auth.httpCookie(req) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
u := Context.auth.UserFind(user, pass) | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
u := Context.auth.UserFind(user, pass) | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth.go |
Context.auth = InitAuth(fn, users, 60) | <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 { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth_test.go |
cookie := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}) | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth_test.go |
Context.auth.Close() | <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() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/auth_test.go |
<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> 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") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go | |
BindPort: 3000,
BindHost: "0.0.0.0", | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go |
<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> 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/") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go | |
configFile, err := filepath.EvalSymlinks(Context.configFilename) | <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 {
<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 configFile = config.ourConfigFilename
</s> add configFile = Context.configFilename </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 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 configFile = filepath.Join(config.ourWorkingDir, configFile)
</s> add configFile = filepath.Join(Context.workDir, configFile) </s> remove // run is a blocking method and it won't exit until the service is stopped!
</s> add // run is a blocking method! | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go |
configFile = Context.configFilename | <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
<mask> }
<mask> if !filepath.IsAbs(configFile) {
<mask> configFile = filepath.Join(config.ourWorkingDir, configFile)
<mask> }
<mask> return configFile
</s> *(global): refactoring - moved runtime properties to Context </s> remove configFile, err := filepath.EvalSymlinks(config.ourConfigFilename)
</s> add configFile, err := filepath.EvalSymlinks(Context.configFilename) </s> remove configFile = filepath.Join(config.ourWorkingDir, configFile)
</s> add configFile = filepath.Join(Context.workDir, configFile) </s> remove configfile = filepath.Join(config.ourWorkingDir, config.ourConfigFilename)
</s> add configfile = filepath.Join(Context.workDir, Context.configFilename) </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 configfile := config.ourConfigFilename
</s> add configfile := Context.configFilename | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go |
configFile = filepath.Join(Context.workDir, configFile) | <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
</s> *(global): refactoring - moved runtime properties to Context </s> remove configFile = config.ourConfigFilename
</s> add configFile = Context.configFilename </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 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 // initWorkingDir initializes the ourWorkingDir
</s> add // initWorkingDir initializes the workDir | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go |
<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 {
<mask> l := logSettings{}
<mask> yamlFile, err := readConfigFile()
</s> *(global): refactoring - moved runtime properties to Context </s> remove configFile = filepath.Join(config.ourWorkingDir, configFile)
</s> add configFile = filepath.Join(Context.workDir, configFile) </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 baseDir := config.getDataDir()
</s> add baseDir := Context.getDataDir() </s> remove // initWorkingDir initializes the ourWorkingDir
</s> add // initWorkingDir initializes the workDir | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go | |
if Context.auth != nil {
config.Users = Context.auth.GetUsers() | <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 { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/config.go |
u := Context.auth.GetCurrentUser(r) | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control.go |
Context.controlLock.Unlock() | <mask> enableFilters(true)
<mask> }
<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 config.controlLock.Lock()
</s> add Context.controlLock.Lock() </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 if config.disableUpdate {
</s> add if Context.disableUpdate { </s> remove config.firstRun = true
</s> add Context.firstRun = true | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_filtering.go |
Context.controlLock.Lock() | <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
<mask> }
<mask> fmt.Fprintf(w, "OK %d filters updated\n", nUpdated)
</s> *(global): refactoring - moved runtime properties to Context </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 config.controlLock.Unlock()
</s> add Context.controlLock.Unlock() </s> remove if config.disableUpdate {
</s> add if Context.disableUpdate { </s> remove config.firstRun = true
</s> add Context.firstRun = true | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_filtering.go |
Context.firstRun = false | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_install.go |
Context.firstRun = true | <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() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_install.go |
Context.auth.UserAdd(&u, newSettings.Password) | <mask> }
<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)
</s> *(global): refactoring - moved runtime properties to Context </s> remove config.firstRun = true
</s> add Context.firstRun = true </s> remove config.firstRun = true
</s> add Context.firstRun = true </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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_install.go |
Context.firstRun = true | <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)
<mask> return
<mask> }
<mask>
</s> *(global): refactoring - moved runtime properties to Context </s> remove config.auth.UserAdd(&u, newSettings.Password)
</s> add Context.auth.UserAdd(&u, newSettings.Password) </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 config.controlLock.Lock()
</s> add Context.controlLock.Lock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_install.go |
if Context.disableUpdate { | <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() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.controlLock.Lock() | <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()
<mask>
<mask> if cached {
</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 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 config.controlLock.Unlock()
</s> add Context.controlLock.Unlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.controlLock.Unlock() | <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()
<mask>
<mask> if cached {
<mask> log.Tracef("Returning cached data")
<mask> w.Header().Set("Content-Type", "application/json")
<mask> w.Write(getVersionResp(data))
</s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Lock()
</s> add Context.controlLock.Lock() </s> remove config.controlLock.Unlock()
</s> add Context.controlLock.Unlock() </s> remove config.controlLock.Lock()
</s> add Context.controlLock.Lock() </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() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
resp, err = Context.client.Get(versionCheckURL) | <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> 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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.controlLock.Lock() | <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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.controlLock.Unlock() | <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() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
workDir := Context.workDir | <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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
resp, err := Context.client.Get(u.pkgURL) | <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 && | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
err = copySupportingFiles(files, Context.workDir, u.backupDir, true, true) | <mask> return fmt.Errorf("copyFile() failed: %s", err)
<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 config.ourWorkingDir, u.backupDir, err)
</s> add Context.workDir, u.backupDir, err) </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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.workDir, u.backupDir, err) | <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>
<mask> // update/[AdGuardHome/]README.md -> ./README.md
<mask> err = copySupportingFiles(files, u.updateDir, config.ourWorkingDir, false, true)
<mask> if err != nil {
</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 err = copySupportingFiles(files, config.ourWorkingDir, u.backupDir, true, true)
</s> add err = copySupportingFiles(files, Context.workDir, u.backupDir, true, 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 if !config.firstRun {
</s> add if !Context.firstRun { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
err = copySupportingFiles(files, u.updateDir, Context.workDir, false, true) | <mask> config.ourWorkingDir, u.backupDir, err)
<mask> }
<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 u.updateDir, config.ourWorkingDir, err)
</s> add u.updateDir, Context.workDir, 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 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
u.updateDir, Context.workDir, err) | <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>
<mask> log.Tracef("Renaming: %s -> %s", u.curBinName, u.bkpBinName)
<mask> err = os.Rename(u.curBinName, u.bkpBinName)
<mask> if err != nil {
</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 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 configFile = config.ourConfigFilename
</s> add configFile = Context.configFilename </s> remove resp, err := config.client.Get(u.pkgURL)
</s> add resp, err := Context.client.Get(u.pkgURL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
if Context.runningAsService { | <mask> stopHTTPServer()
<mask> cleanupAlways()
<mask>
<mask> if runtime.GOOS == "windows" {
<mask>
<mask> if config.runningAsService {
<mask> // Note:
<mask> // we can't restart the service via "kardianos/service" package - it kills the process first
<mask> // we can't start a new instance - Windows doesn't allow it
<mask> cmd := exec.Command("cmd", "/c", "net stop AdGuardHome & net start AdGuardHome")
<mask> err := cmd.Start()
</s> *(global): refactoring - moved runtime properties to Context </s> remove baseDir := config.getDataDir()
</s> add baseDir := Context.getDataDir() </s> remove config.appSignalChannel <- syscall.SIGINT
</s> add Context.appSignalChannel <- syscall.SIGINT </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 // run is a blocking method and it won't exit until the service is stopped!
</s> add // run is a blocking method! </s> remove coreFilePath := filepath.Join(config.ourWorkingDir, "Corefile")
</s> add coreFilePath := filepath.Join(Context.workDir, "Corefile") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update.go |
Context.workDir = "..." // set absolute path | <mask>
<mask> func TestDoUpdate(t *testing.T) {
<mask>
<mask> config.DNS.Port = 0
<mask> config.ourWorkingDir = "..." // set absolute path
<mask> newver := "v0.96"
<mask>
<mask> data := `{
<mask> "version": "v0.96",
<mask> "announcement": "AdGuard Home v0.96 is now available!",
</s> *(global): refactoring - moved runtime properties to Context </s> remove config.controlLock.Lock()
</s> add Context.controlLock.Lock() </s> remove config.client = &http.Client{
</s> add Context.client = &http.Client{ </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 pkgName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
</s> add pkgName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz", </s> remove config.ourWorkingDir = filepath.Dir(exec)
</s> add Context.workDir = filepath.Dir(execPath) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update_test.go |
pkgName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz", | <mask> }
<mask>
<mask> u := updateInfo{
<mask> pkgURL: "https://github.com/AdguardTeam/AdGuardHome/releases/download/" + newver + "/AdGuardHome_linux_amd64.tar.gz",
<mask> pkgName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
<mask> newVer: newver,
<mask> updateDir: config.ourWorkingDir + "/agh-update-" + newver,
<mask> backupDir: config.ourWorkingDir + "/agh-backup",
<mask> configName: config.ourWorkingDir + "/AdGuardHome.yaml",
<mask> updateConfigName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
</s> *(global): refactoring - moved runtime properties to Context </s> remove updateDir: config.ourWorkingDir + "/agh-update-" + newver,
backupDir: config.ourWorkingDir + "/agh-backup",
configName: config.ourWorkingDir + "/AdGuardHome.yaml",
updateConfigName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
curBinName: config.ourWorkingDir + "/AdGuardHome",
bkpBinName: config.ourWorkingDir + "/agh-backup/AdGuardHome",
newBinName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome",
</s> add updateDir: Context.workDir + "/agh-update-" + newver,
backupDir: Context.workDir + "/agh-backup",
configName: Context.workDir + "/AdGuardHome.yaml",
updateConfigName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
curBinName: Context.workDir + "/AdGuardHome",
bkpBinName: Context.workDir + "/agh-backup/AdGuardHome",
newBinName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome", </s> remove log.Debug("Current working directory is %s", config.ourWorkingDir)
</s> add log.Debug("Current working directory is %s", Context.workDir) </s> remove config.ourWorkingDir = "..." // set absolute path
</s> add Context.workDir = "..." // set absolute path </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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update_test.go |
updateDir: Context.workDir + "/agh-update-" + newver,
backupDir: Context.workDir + "/agh-backup",
configName: Context.workDir + "/AdGuardHome.yaml",
updateConfigName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
curBinName: Context.workDir + "/AdGuardHome",
bkpBinName: Context.workDir + "/agh-backup/AdGuardHome",
newBinName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome", | <mask> u := updateInfo{
<mask> pkgURL: "https://github.com/AdguardTeam/AdGuardHome/releases/download/" + newver + "/AdGuardHome_linux_amd64.tar.gz",
<mask> pkgName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
<mask> newVer: newver,
<mask> updateDir: config.ourWorkingDir + "/agh-update-" + newver,
<mask> backupDir: config.ourWorkingDir + "/agh-backup",
<mask> configName: config.ourWorkingDir + "/AdGuardHome.yaml",
<mask> updateConfigName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
<mask> curBinName: config.ourWorkingDir + "/AdGuardHome",
<mask> bkpBinName: config.ourWorkingDir + "/agh-backup/AdGuardHome",
<mask> newBinName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome",
<mask> }
<mask>
<mask> if uu.pkgURL != u.pkgURL ||
<mask> uu.pkgName != u.pkgName ||
<mask> uu.newVer != u.newVer ||
</s> *(global): refactoring - moved runtime properties to Context </s> remove pkgName: config.ourWorkingDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
</s> add pkgName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz", </s> remove log.Debug("Current working directory is %s", config.ourWorkingDir)
</s> add log.Debug("Current working directory is %s", Context.workDir) </s> remove config.ourWorkingDir = "..." // set absolute path
</s> add Context.workDir = "..." // set absolute path </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) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/control_update_test.go |
baseDir := Context.getDataDir() | <mask> // initDNSServer creates an instance of the dnsforward.Server
<mask> // Please note that we must do it even if we don't start it
<mask> // so that we had access to the query log and the stats
<mask> func initDNSServer() error {
<mask> baseDir := config.getDataDir()
<mask>
<mask> err := os.MkdirAll(baseDir, 0755)
<mask> if err != nil {
<mask> return fmt.Errorf("Cannot create DNS data dir at %s: %s", baseDir, err)
<mask> }
</s> *(global): refactoring - moved runtime properties to Context </s> remove coreFilePath := filepath.Join(config.ourWorkingDir, "Corefile")
</s> add coreFilePath := filepath.Join(Context.workDir, "Corefile") </s> remove
if config.runningAsService {
</s> add if Context.runningAsService { </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 dnsFilterPath := filepath.Join(config.ourWorkingDir, "dnsfilter.txt")
</s> add dnsFilterPath := filepath.Join(Context.workDir, "dnsfilter.txt") </s> remove resp, err := config.client.Get(u.pkgURL)
</s> add resp, err := Context.client.Get(u.pkgURL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/ae2990582defd8062b99c546b2a932a8ba06c35d | home/dns.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.