docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep replace keep replace replace replace keep
<mask> if r == nil { <mask> return entries, 0 <mask> } <mask> r.BeginRead(olderThan, getDataLimit) <mask> for totalChunks < maxFilteringChunks { <mask> first := true <mask> newEntries := []*logEntry{} </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove olderThan := params.OlderThan totalChunks := 0 total := 0 </s> add oldest := time.Time{} </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove if first || len(entries) == getDataLimit { </s> add if r.Total() == 0 || len(entries) == getDataLimit { </s> remove return entries, total </s> add return entries, oldest, int(total) </s> remove total++ if first { first = false olderThan = entry.Time } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
<mask> entry := r.Next() <mask> if entry == nil { <mask> break <mask> } <mask> total++ <mask> <mask> if first { <mask> first = false <mask> olderThan = entry.Time <mask> } <mask> <mask> if !isNeeded(entry, params) { <mask> continue <mask> } <mask> if len(newEntries) == getDataLimit { </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if first || len(entries) == getDataLimit { </s> add if r.Total() == 0 || len(entries) == getDataLimit { </s> remove r.BeginRead(olderThan, getDataLimit) for totalChunks < maxFilteringChunks { first := true </s> add r.BeginRead(params.OlderThan, getDataLimit, &params) total := uint64(0) for total <= maxSearchEntries { </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> newEntries = append(newEntries, entry) <mask> } <mask> <mask> log.Debug("entries: +%d (%d) older-than:%s", len(newEntries), len(entries), olderThan) <mask> <mask> entries = append(newEntries, entries...) <mask> if len(entries) > getDataLimit { <mask> toremove := len(entries) - getDataLimit <mask> entries = entries[toremove:] </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if first || len(entries) == getDataLimit { </s> add if r.Total() == 0 || len(entries) == getDataLimit { </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove total++ if first { first = false olderThan = entry.Time } </s> add </s> remove log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", r.count, elapsed, perunit, r.nSeekRequests) </s> add log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d time:%dus (%d%%)", r.count, elapsed, perunit, r.nSeekRequests, r.timecnt/1000, r.timecnt*100/uint64(elapsed.Nanoseconds())) </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> toremove := len(entries) - getDataLimit <mask> entries = entries[toremove:] <mask> break <mask> } <mask> if first || len(entries) == getDataLimit { <mask> break <mask> } <mask> totalChunks++ <mask> r.BeginReadPrev(olderThan, getDataLimit) <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove log.Debug("entries: +%d (%d) older-than:%s", len(newEntries), len(entries), olderThan) </s> add log.Debug("entries: +%d (%d) [%d]", len(newEntries), len(entries), r.Total()) </s> remove total++ if first { first = false olderThan = entry.Time } </s> add </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result </s> remove r.BeginRead(olderThan, getDataLimit) for totalChunks < maxFilteringChunks { first := true </s> add r.BeginRead(params.OlderThan, getDataLimit, &params) total := uint64(0) for total <= maxSearchEntries { </s> remove var q *dns.Msg </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace replace keep keep keep replace keep keep
<mask> } <mask> if first || len(entries) == getDataLimit { <mask> break <mask> } <mask> totalChunks++ <mask> r.BeginReadPrev(olderThan, getDataLimit) <mask> } <mask> <mask> r.Close() <mask> return entries, total <mask> } <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if first || len(entries) == getDataLimit { </s> add if r.Total() == 0 || len(entries) == getDataLimit { </s> remove total++ if first { first = false olderThan = entry.Time } </s> add </s> remove r.BeginRead(olderThan, getDataLimit) for totalChunks < maxFilteringChunks { first := true </s> add r.BeginRead(params.OlderThan, getDataLimit, &params) total := uint64(0) for total <= maxSearchEntries { </s> remove return entries, 0 </s> add return entries, time.Time{}, 0 </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> type getDataParams struct { <mask> OlderThan time.Time // return entries that are older than this value <mask> Domain string // filter by domain name in question <mask> Client string // filter by client IP <mask> QuestionType uint16 // filter by question type <mask> ResponseStatus responseStatusType // filter by response status <mask> StrictMatchDomain bool // if Domain value must be matched strictly <mask> StrictMatchClient bool // if Client value must be matched strictly <mask> } <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove return entries, total </s> add return entries, oldest, int(total) </s> add timecnt uint64 </s> remove Question []byte </s> add IP string `json:"IP"` Time time.Time `json:"T"` QHost string `json:"QH"` QType string `json:"QT"` QClass string `json:"QC"` </s> remove ql *queryLog </s> add ql *queryLog search *getDataParams </s> remove Time time.Time </s> add </s> remove IP string </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep replace keep keep replace replace replace replace keep keep
<mask> ) <mask> <mask> // Get log entries <mask> func (l *queryLog) getData(params getDataParams) []map[string]interface{} { <mask> var data = []map[string]interface{}{} <mask> <mask> if len(params.Domain) != 0 && params.StrictMatchDomain { <mask> params.Domain = params.Domain + "." <mask> } <mask> <mask> now := time.Now() <mask> entries := []*logEntry{} </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove func (l *queryLog) readFromFile(params getDataParams) ([]*logEntry, int) { </s> add func (l *queryLog) readFromFile(params getDataParams) ([]*logEntry, time.Time, int) { </s> remove if len(params.Domain) != 0 || params.QuestionType != 0 { m := dns.Msg{} _ = m.Unpack(entry.Question) if params.QuestionType != 0 { if m.Question[0].Qtype != params.QuestionType { return false } } if len(params.Domain) != 0 && params.StrictMatchDomain { if m.Question[0].Name != params.Domain { return false } } else if len(params.Domain) != 0 { if strings.Index(m.Question[0].Name, params.Domain) == -1 { return false } </s> add if len(params.QuestionType) != 0 { if entry.QType != params.QuestionType { return false </s> remove olderThan := params.OlderThan totalChunks := 0 total := 0 </s> add oldest := time.Time{} </s> remove entries, total = l.readFromFile(params) </s> add entries, oldest, total = l.readFromFile(params) </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> entries := []*logEntry{} <mask> total := 0 <mask> <mask> // add from file <mask> entries, total = l.readFromFile(params) <mask> <mask> if params.OlderThan.IsZero() { <mask> params.OlderThan = now <mask> } <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if len(params.Domain) != 0 && params.StrictMatchDomain { params.Domain = params.Domain + "." } </s> add var oldest time.Time </s> remove olderThan := params.OlderThan totalChunks := 0 total := 0 </s> add oldest := time.Time{} </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove func (l *queryLog) readFromFile(params getDataParams) ([]*logEntry, int) { </s> add func (l *queryLog) readFromFile(params getDataParams) ([]*logEntry, time.Time, int) { </s> remove return entries, 0 </s> add return entries, time.Time{}, 0 </s> remove r.BeginRead(olderThan, getDataLimit) for totalChunks < maxFilteringChunks { first := true </s> add r.BeginRead(params.OlderThan, getDataLimit, &params) total := uint64(0) for total <= maxSearchEntries {
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep replace keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep
<mask> for i := len(entries) - 1; i >= 0; i-- { <mask> entry := entries[i] <mask> var q *dns.Msg <mask> var a *dns.Msg <mask> <mask> if len(entry.Question) == 0 { <mask> continue <mask> } <mask> q = new(dns.Msg) <mask> if err := q.Unpack(entry.Question); err != nil { <mask> log.Tracef("q.Unpack(): %s", err) <mask> continue <mask> } <mask> if len(q.Question) != 1 { <mask> log.Tracef("len(q.Question) != 1") <mask> continue <mask> } <mask> <mask> if len(entry.Answer) > 0 { <mask> a = new(dns.Msg) <mask> if err := a.Unpack(entry.Answer); err != nil { <mask> log.Debug("Failed to unpack dns message answer: %s", err) </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove log.Debug("Failed to unpack dns message answer: %s", err) </s> add log.Debug("Failed to unpack dns message answer: %s: %s", err, string(entry.Answer)) </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val)
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> if len(entry.Answer) > 0 { <mask> a = new(dns.Msg) <mask> if err := a.Unpack(entry.Answer); err != nil { <mask> log.Debug("Failed to unpack dns message answer: %s", err) <mask> a = nil <mask> } <mask> } <mask> <mask> jsonEntry := map[string]interface{}{ </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove strReader := strings.NewReader(string(b)) jd := json.NewDecoder(strReader) </s> add str := string(b)
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> "time": entry.Time.Format(time.RFC3339Nano), <mask> "client": entry.IP, <mask> } <mask> jsonEntry["question"] = map[string]interface{}{ <mask> "host": strings.ToLower(strings.TrimSuffix(q.Question[0].Name, ".")), <mask> "type": dns.Type(q.Question[0].Qtype).String(), <mask> "class": dns.Class(q.Question[0].Qclass).String(), <mask> } <mask> <mask> if a != nil { <mask> jsonEntry["status"] = dns.RcodeToString[a.Rcode] <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove log.Debug("Failed to unpack dns message answer: %s", err) </s> add log.Debug("Failed to unpack dns message answer: %s: %s", err, string(entry.Answer)) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove // open decoder </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> log.Debug("QueryLog: prepared data (%d/%d) older than %s in %s", <mask> len(entries), total, params.OlderThan, time.Since(now)) <mask> return data <mask> } <mask> <mask> func answerToMap(a *dns.Msg) []map[string]interface{} { <mask> if a == nil || len(a.Answer) == 0 { <mask> return nil </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove func (l *queryLog) getData(params getDataParams) []map[string]interface{} { </s> add func (l *queryLog) getData(params getDataParams) map[string]interface{} {
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog.go
keep keep keep replace keep keep keep keep replace keep
<mask> } <mask> <mask> if len(req.filterQuestionType) != 0 { <mask> qtype, ok := dns.StringToType[req.filterQuestionType] <mask> if !ok { <mask> httpError(r, w, http.StatusBadRequest, "invalid question_type") <mask> return <mask> } <mask> params.QuestionType = qtype <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if len(params.Domain) != 0 || params.QuestionType != 0 { m := dns.Msg{} _ = m.Unpack(entry.Question) if params.QuestionType != 0 { if m.Question[0].Qtype != params.QuestionType { return false } } if len(params.Domain) != 0 && params.StrictMatchDomain { if m.Question[0].Name != params.Domain { return false } } else if len(params.Domain) != 0 { if strings.Index(m.Question[0].Name, params.Domain) == -1 { return false } </s> add if len(params.QuestionType) != 0 { if entry.QType != params.QuestionType { return false </s> remove if len(params.Client) != 0 && params.StrictMatchClient { if entry.IP != params.Client { </s> add if len(params.Domain) != 0 { if (params.StrictMatchDomain && entry.QHost != params.Domain) || (!params.StrictMatchDomain && strings.Index(entry.QHost, params.Domain) == -1) { </s> remove } else if len(params.Client) != 0 { if strings.Index(entry.IP, params.Client) == -1 { </s> add } if len(params.Client) != 0 { if (params.StrictMatchClient && entry.IP != params.Client) || (!params.StrictMatchClient && strings.Index(entry.IP, params.Client) == -1) { </s> add if r.oldest.IsZero() { r.oldest = tm } </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/qlog_http.go
keep keep add keep keep keep keep keep keep
<mask> "bufio" <mask> "bytes" <mask> "compress/gzip" <mask> "encoding/json" <mask> "io" <mask> "os" <mask> "strconv" <mask> "strings" <mask> "time" </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add "strconv" </s> add "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> remove m := d[0] </s> add mdata := d["data"].([]map[string]interface{}) m := mdata[0] </s> remove return entries, 0 </s> add return entries, time.Time{}, 0 </s> remove entries, total = l.readFromFile(params) </s> add entries, oldest, total = l.readFromFile(params) </s> remove if len(params.Domain) != 0 && params.StrictMatchDomain { params.Domain = params.Domain + "." } </s> add var oldest time.Time
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep add keep keep keep keep
<mask> "encoding/base64" <mask> "encoding/json" <mask> "io" <mask> "os" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add "encoding/base64" </s> add "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add "github.com/miekg/dns" </s> remove m := d[0] </s> add mdata := d["data"].([]map[string]interface{}) m := mdata[0] </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove entries, total = l.readFromFile(params) </s> add entries, oldest, total = l.readFromFile(params)
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep add keep keep keep keep keep keep
<mask> "time" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> const enableGzip = false <mask> const maxEntrySize = 1000 </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add "github.com/miekg/dns" </s> remove r.searching = false </s> add r.seeking = false </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false </s> remove func (l *queryLog) getData(params getDataParams) []map[string]interface{} { </s> add func (l *queryLog) getData(params getDataParams) map[string]interface{} { </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep add keep keep keep keep keep
<mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> const enableGzip = false <mask> const maxEntrySize = 1000 <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> remove r.searching = false </s> add r.seeking = false </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false </s> remove func (l *queryLog) getData(params getDataParams) []map[string]interface{} { </s> add func (l *queryLog) getData(params getDataParams) map[string]interface{} { </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // Reader is the DB reader context <mask> type Reader struct { <mask> ql *queryLog <mask> <mask> f *os.File <mask> reader *bufio.Reader // reads file line by line <mask> now time.Time <mask> validFrom int64 // UNIX time (ns) </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add oldest time.Time </s> add timecnt uint64 </s> remove QuestionType uint16 // filter by question type </s> add QuestionType string // filter by question type </s> remove searching bool // we're seaching for an entry with exact time stamp </s> add seeking bool // we're seaching for an entry with exact time stamp </s> remove // maximum data chunks to parse when filtering entries maxFilteringChunks = 10 </s> add // maximum entries to parse when searching maxSearchEntries = 50000 </s> remove return entries, total </s> add return entries, oldest, int(total)
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep add keep keep keep keep
<mask> now time.Time <mask> validFrom int64 // UNIX time (ns) <mask> olderThan int64 // UNIX time (ns) <mask> <mask> files []string <mask> ifile int <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove ql *queryLog </s> add ql *queryLog search *getDataParams </s> remove // Total returns the total number of items func (r *Reader) Total() int { return 0 </s> add // Total returns the total number of processed items func (r *Reader) Total() uint64 { return r.count } // Oldest returns the time of the oldest processed entry func (r *Reader) Oldest() time.Time { return r.oldest </s> remove searching bool // we're seaching for an entry with exact time stamp </s> add seeking bool // we're seaching for an entry with exact time stamp </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> remove if len(params.Domain) != 0 && params.StrictMatchDomain { params.Domain = params.Domain + "." } </s> add var oldest time.Time </s> remove entries, total = l.readFromFile(params) </s> add entries, oldest, total = l.readFromFile(params)
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> count uint64 // counter for returned elements <mask> latest bool // return the latest entries <mask> filePrepared bool <mask> <mask> searching bool // we're seaching for an entry with exact time stamp <mask> fseeker fileSeeker // file seeker object <mask> fpos uint64 // current file offset <mask> nSeekRequests uint32 // number of Seek() requests made (finding a new line doesn't count) <mask> } <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add timecnt uint64 </s> remove var q *dns.Msg </s> add </s> remove // Total returns the total number of items func (r *Reader) Total() int { return 0 </s> add // Total returns the total number of processed items func (r *Reader) Total() uint64 { return r.count } // Oldest returns the time of the oldest processed entry func (r *Reader) Oldest() time.Time { return r.oldest </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> remove ql *queryLog </s> add ql *queryLog search *getDataParams </s> remove QuestionType uint16 // filter by question type </s> add QuestionType string // filter by question type
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep add keep keep keep keep keep keep
<mask> fpos uint64 // current file offset <mask> nSeekRequests uint32 // number of Seek() requests made (finding a new line doesn't count) <mask> } <mask> <mask> type fileSeeker struct { <mask> target uint64 // target value <mask> <mask> pos uint64 // current offset, may be adjusted by user for increased accuracy </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove searching bool // we're seaching for an entry with exact time stamp </s> add seeking bool // we're seaching for an entry with exact time stamp </s> remove QuestionType uint16 // filter by question type </s> add QuestionType string // filter by question type </s> remove ql *queryLog </s> add ql *queryLog search *getDataParams </s> remove // Total returns the total number of items func (r *Reader) Total() int { return 0 </s> add // Total returns the total number of processed items func (r *Reader) Total() uint64 { return r.count } // Oldest returns the time of the oldest processed entry func (r *Reader) Oldest() time.Time { return r.oldest </s> remove return entries, total </s> add return entries, oldest, int(total) </s> remove r.searching = false </s> add r.seeking = false
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> var perunit time.Duration <mask> if r.count > 0 { <mask> perunit = elapsed / time.Duration(r.count) <mask> } <mask> log.Debug("querylog: read %d entries in %v, %v/entry, seek-reqs:%d", <mask> r.count, elapsed, perunit, r.nSeekRequests) <mask> <mask> if r.f != nil { <mask> r.f.Close() <mask> } <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result </s> remove strReader := strings.NewReader(string(b)) jd := json.NewDecoder(strReader) </s> add str := string(b) </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode")
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // BeginRead - start reading <mask> // olderThan: stop returning entries when an entry with this time is reached <mask> // count: minimum number of entries to return <mask> func (r *Reader) BeginRead(olderThan time.Time, count uint64) { <mask> r.olderThan = olderThan.UnixNano() <mask> r.latest = olderThan.IsZero() <mask> r.limit = count <mask> if r.latest { <mask> r.olderThan = r.now.UnixNano() </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add r.oldest = time.Time{} r.search = search </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false </s> remove searching bool // we're seaching for an entry with exact time stamp </s> add seeking bool // we're seaching for an entry with exact time stamp </s> remove // maximum data chunks to parse when filtering entries maxFilteringChunks = 10 </s> add // maximum entries to parse when searching maxSearchEntries = 50000
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep add keep keep keep keep keep
<mask> // count: minimum number of entries to return <mask> func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { <mask> r.olderThan = olderThan.UnixNano() <mask> r.latest = olderThan.IsZero() <mask> r.limit = count <mask> if r.latest { <mask> r.olderThan = r.now.UnixNano() <mask> } <mask> r.filePrepared = false </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false </s> remove // Total returns the total number of items func (r *Reader) Total() int { return 0 </s> add // Total returns the total number of processed items func (r *Reader) Total() uint64 { return r.count } // Oldest returns the time of the oldest processed entry func (r *Reader) Oldest() time.Time { return r.oldest </s> add if r.oldest.IsZero() { r.oldest = tm }
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep replace keep keep keep replace replace replace
<mask> r.filePrepared = false <mask> r.searching = false <mask> } <mask> <mask> // BeginReadPrev - start reading the previous data chunk <mask> func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { <mask> r.olderThan = olderThan.UnixNano() <mask> r.latest = olderThan.IsZero() </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> add r.oldest = time.Time{} r.search = search </s> remove r.searching = false </s> add r.seeking = false </s> remove r.searching = true </s> add r.seeking = true
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { <mask> r.olderThan = olderThan.UnixNano() <mask> r.latest = olderThan.IsZero() <mask> r.limit = count <mask> if r.latest { <mask> r.olderThan = r.now.UnixNano() <mask> } <mask> <mask> off := r.fpos - maxEntrySize*(r.limit+1) <mask> if int64(off) < maxEntrySize { <mask> off = 0 <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove r.searching = false </s> add r.seeking = false </s> add r.oldest = time.Time{} r.search = search </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> remove r.searching = false </s> add r.seeking = false </s> add if r.oldest.IsZero() { r.oldest = tm }
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> r.seekToNewLine() <mask> r.fseeker.pos = r.fpos <mask> <mask> r.filePrepared = true <mask> r.searching = false <mask> } <mask> <mask> // Perform binary seek <mask> // Return 0: success; 1: seek reqiured; -1: error <mask> func (fs *fileSeeker) seekBinary(cur uint64) int32 { </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove r.searching = false </s> add r.seeking = false </s> remove r.searching = true </s> add r.seeking = true </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> return false <mask> } <mask> } else { <mask> // start searching in file: we'll read the first chunk of data from the middle of file <mask> r.searching = true <mask> r.fseeker = fileSeeker{} <mask> r.fseeker.target = uint64(r.olderThan) <mask> r.fseeker.hi = fsize <mask> rc := r.fseeker.seekBinary(0) <mask> r.fpos = r.fseeker.pos </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove r.searching = false </s> add r.seeking = false </s> remove r.searching = false </s> add r.seeking = false </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove r.searching = false </s> add r.seeking = false </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> remove return data </s> add var result = map[string]interface{}{} if len(entries) == getDataLimit { oldest = entries[0].Time } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) } result["data"] = data return result
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep replace replace keep
<mask> } <mask> r.filePrepared = true <mask> } <mask> <mask> // open decoder <mask> b, err := r.reader.ReadBytes('\n') <mask> if err != nil { <mask> return nil <mask> } <mask> strReader := strings.NewReader(string(b)) <mask> jd := json.NewDecoder(strReader) <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove var q []byte var a []byte var err error ip := getIPString(addr) if question == nil { </s> add if question == nil || len(question.Question) != 1 || len(question.Question[0].Name) == 0 || ip == nil { </s> remove log.Debug("Failed to unpack dns message answer: %s", err) </s> add log.Debug("Failed to unpack dns message answer: %s: %s", err, string(entry.Answer))
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace replace replace keep replace keep keep keep
<mask> } <mask> strReader := strings.NewReader(string(b)) <mask> jd := json.NewDecoder(strReader) <mask> <mask> // read data <mask> var entry logEntry <mask> err = jd.Decode(&entry) <mask> if err != nil { <mask> log.Debug("QueryLog: Failed to decode: %s", err) <mask> continue <mask> } <mask> </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove strReader := strings.NewReader(string(b)) jd := json.NewDecoder(strReader) </s> add str := string(b) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> remove q, err = question.Pack() if err != nil { log.Printf("failed to pack question for querylog: %s", err) return } </s> add var a []byte var err error ip := getIPString(addr) </s> remove // open decoder </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep add keep keep keep keep
<mask> log.Debug("QueryLog: failed to decode") <mask> continue <mask> } <mask> <mask> if r.seeking { <mask> <mask> r.reader = nil </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add </s> add if r.oldest.IsZero() { r.oldest = tm } </s> remove total++ if first { first = false olderThan = entry.Time } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> log.Debug("QueryLog: Failed to decode: %s", err) <mask> continue <mask> } <mask> <mask> t := entry.Time.UnixNano() <mask> if r.searching { <mask> <mask> r.reader = nil <mask> rr := r.fseeker.seekBinary(uint64(t)) <mask> r.fpos = r.fseeker.pos <mask> if rr < 0 { </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> add t := tm.UnixNano() </s> remove // read data var entry logEntry err = jd.Decode(&entry) </s> add val := readJSONValue(str, "T") if len(val) == 0 { val = readJSONValue(str, "Time") } if len(val) == 0 { log.Debug("QueryLog: failed to decode") continue } tm, err := time.Parse(time.RFC3339, val) </s> remove r.searching = false </s> add r.seeking = false </s> add if r.oldest.IsZero() { r.oldest = tm } </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep keep keep
<mask> return nil <mask> } else if rr == 0 { <mask> // We found the target entry. <mask> // We'll start reading the previous chunk of data. <mask> r.searching = false <mask> <mask> off := r.fpos - (maxEntrySize * (r.limit + 1)) <mask> if int64(off) < maxEntrySize { <mask> off = 0 <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove r.searching = false </s> add r.seeking = false </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove r.searching = true </s> add r.seeking = true </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> remove if len(params.Domain) != 0 || params.QuestionType != 0 { m := dns.Msg{} _ = m.Unpack(entry.Question) if params.QuestionType != 0 { if m.Question[0].Qtype != params.QuestionType { return false } } if len(params.Domain) != 0 && params.StrictMatchDomain { if m.Question[0].Name != params.Domain { return false } } else if len(params.Domain) != 0 { if strings.Index(m.Question[0].Name, params.Domain) == -1 { return false } </s> add if len(params.QuestionType) != 0 { if entry.QType != params.QuestionType { return false
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep add keep keep keep keep keep keep
<mask> } <mask> <mask> if t < r.validFrom { <mask> continue <mask> } <mask> if t >= r.olderThan { <mask> return nil <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove t := entry.Time.UnixNano() if r.searching { </s> add if r.seeking { </s> add t := tm.UnixNano() </s> remove log.Debug("QueryLog: Failed to decode: %s", err) </s> add log.Debug("QueryLog: failed to decode") </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0 </s> remove total++ if first { first = false olderThan = entry.Time } </s> add </s> remove if len(entry.Question) == 0 { continue } q = new(dns.Msg) if err := q.Unpack(entry.Question); err != nil { log.Tracef("q.Unpack(): %s", err) continue } if len(q.Question) != 1 { log.Tracef("len(q.Question) != 1") continue } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep replace replace replace
<mask> return nil <mask> } <mask> <mask> r.count++ <mask> return &entry <mask> } <mask> } <mask> <mask> // Total returns the total number of items <mask> func (r *Reader) Total() int { <mask> return 0 </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> add r.oldest = time.Time{} r.search = search </s> remove func (r *Reader) BeginReadPrev(olderThan time.Time, count uint64) { r.olderThan = olderThan.UnixNano() r.latest = olderThan.IsZero() </s> add func (r *Reader) BeginReadPrev(count uint64) { r.olderThan = r.oldest.UnixNano() r.oldest = time.Time{} r.latest = false </s> remove r.searching = false </s> add r.seeking = false </s> remove func (r *Reader) BeginRead(olderThan time.Time, count uint64) { </s> add func (r *Reader) BeginRead(olderThan time.Time, count uint64, search *getDataParams) { </s> remove if r.latest { r.olderThan = r.now.UnixNano() } </s> add r.count = 0
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_file.go
keep keep keep keep replace keep keep keep
<mask> params := getDataParams{ <mask> OlderThan: time.Now(), <mask> } <mask> d := l.getData(params) <mask> m := d[0] <mask> mq := m["question"].(map[string]interface{}) <mask> assert.True(t, mq["host"].(string) == "example.org") <mask> } </s> * querylog: major refactor: change on-disk format and API speed up decoding speed up search compatible with previous format (when not searching) </s> remove if len(params.Domain) != 0 || params.QuestionType != 0 { m := dns.Msg{} _ = m.Unpack(entry.Question) if params.QuestionType != 0 { if m.Question[0].Qtype != params.QuestionType { return false } } if len(params.Domain) != 0 && params.StrictMatchDomain { if m.Question[0].Name != params.Domain { return false } } else if len(params.Domain) != 0 { if strings.Index(m.Question[0].Name, params.Domain) == -1 { return false } </s> add if len(params.QuestionType) != 0 { if entry.QType != params.QuestionType { return false </s> remove if first || len(entries) == getDataLimit { </s> add if r.Total() == 0 || len(entries) == getDataLimit { </s> remove totalChunks++ r.BeginReadPrev(olderThan, getDataLimit) </s> add total += r.Total() oldest = r.Oldest() r.BeginReadPrev(getDataLimit) </s> remove total++ if first { first = false olderThan = entry.Time } </s> add </s> remove if len(params.Client) != 0 && params.StrictMatchClient { if entry.IP != params.Client { </s> add if len(params.Domain) != 0 { if (params.StrictMatchDomain && entry.QHost != params.Domain) || (!params.StrictMatchDomain && strings.Index(entry.QHost, params.Domain) == -1) { </s> remove } else if len(params.Client) != 0 { if strings.Index(entry.IP, params.Client) == -1 { </s> add } if len(params.Client) != 0 { if (params.StrictMatchClient && entry.IP != params.Client) || (!params.StrictMatchClient && strings.Index(entry.IP, params.Client) == -1) {
https://github.com/AdguardTeam/AdGuardHome/commit/2f5d6593f2d9841f9c18b9ac60a554af60a34a6b
querylog/querylog_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> go 1.16 <mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.38.3 <mask> github.com/AdguardTeam/golibs v0.8.0 <mask> github.com/AdguardTeam/urlfilter v0.14.6 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.1.3 <mask> github.com/digineo/go-ipset/v2 v2.2.1 </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add TrustedProxies: s.conf.TrustedProxies, </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
go.mod
keep keep keep add keep keep keep keep keep
<mask> github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf h1:gc042VRSIRSUzZ+Px6xQCRWNJZTaPkomisDfUZmoFNk= <mask> github.com/AdguardTeam/dhcp v0.0.0-20210519141215-51808c73c0bf/go.mod h1:TKl4jN3Voofo4UJIicyNhWGp/nlQqQkFxmwIFTvBkKI= <mask> github.com/AdguardTeam/dnsproxy v0.38.3 h1:DvycTEOn2wuHmY+HE5XL4EnCV2EVbpREpbgZB06IJ0I= <mask> github.com/AdguardTeam/dnsproxy v0.38.3/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= <mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.8.0 h1:rHo+yIgT2fivFG0yW2Cwk/DPc2+t/Aw6QvzPpiIFre0= <mask> github.com/AdguardTeam/golibs v0.8.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0 </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add TrustedProxies: s.conf.TrustedProxies, </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
go.sum
keep keep keep add keep keep keep keep keep
<mask> github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= <mask> github.com/hugelgupf/socketpair v0.0.0-20190730060125-05d35a94e714 h1:/jC7qQFrv8CrSJVmaolDVOxTfS9kc36uB6H40kdbQq8= <mask> github.com/hugelgupf/socketpair v0.0.0-20190730060125-05d35a94e714/go.mod h1:2Goc3h8EklBH5mspfHFxBnEoURQCGzQQH1ga9Myjvis= <mask> github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= <mask> github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= <mask> github.com/joomcode/errorx v1.0.1/go.mod h1:kgco15ekB6cs+4Xjzo7SPeXzx38PbJzBwbnu9qfVNHQ= <mask> github.com/joomcode/errorx v1.0.3 h1:3e1mi0u7/HTPNdg6d6DYyKGBhA5l9XpsfuVE29NxnWw= <mask> github.com/joomcode/errorx v1.0.3/go.mod h1:eQzdtdlNyN7etw6YCS4W4+lu442waxZYw5yvz0ULrRo= <mask> github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 h1:uhL5Gw7BINiiPAo24A2sxkcDI0Jt/sqp1v5xQCniEFA= </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add TrustedProxies: s.conf.TrustedProxies, </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
go.sum
keep add keep keep keep keep keep
<mask> DisallowedClients []string `yaml:"disallowed_clients"` // IP addresses of clients that should be blocked <mask> BlockedHosts []string `yaml:"blocked_hosts"` // hosts that should be blocked <mask> <mask> // DNS cache settings <mask> // -- <mask> <mask> CacheSize uint32 `yaml:"cache_size"` // DNS cache size (in bytes) </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add TrustedProxies: s.conf.TrustedProxies, </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
internal/dnsforward/config.go
keep add keep keep keep keep
<mask> RatelimitWhitelist: s.conf.RatelimitWhitelist, <mask> RefuseAny: s.conf.RefuseAny, <mask> CacheMinTTL: s.conf.CacheMinTTL, <mask> CacheMaxTTL: s.conf.CacheMaxTTL, <mask> CacheOptimistic: s.conf.CacheOptimistic, <mask> UpstreamConfig: s.conf.UpstreamConfig, </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
internal/dnsforward/config.go
keep keep keep add keep keep keep keep keep
<mask> c.BootstrapDNS = aghstrings.CloneSlice(sc.BootstrapDNS) <mask> c.AllowedClients = aghstrings.CloneSlice(sc.AllowedClients) <mask> c.DisallowedClients = aghstrings.CloneSlice(sc.DisallowedClients) <mask> c.BlockedHosts = aghstrings.CloneSlice(sc.BlockedHosts) <mask> c.UpstreamDNS = aghstrings.CloneSlice(sc.UpstreamDNS) <mask> } <mask> <mask> // RDNSSettings returns the copy of actual RDNS configuration. <mask> func (s *Server) RDNSSettings() (localPTRResolvers []string, resolveClients, resolvePTR bool) { </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add TrustedProxies: []string{"127.0.0.0/8", "::1/128"}, </s> add TrustedProxies: s.conf.TrustedProxies, </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
internal/dnsforward/dnsforward.go
keep keep keep add keep keep keep keep keep keep
<mask> Ratelimit: 20, <mask> RefuseAny: true, <mask> AllServers: false, <mask> <mask> // set default maximum concurrent queries to 300 <mask> // we introduced a default limit due to this: <mask> // https://github.com/AdguardTeam/AdGuardHome/issues/2015#issuecomment-674041912 <mask> // was later increased to 300 due to https://github.com/AdguardTeam/AdGuardHome/issues/2257 <mask> MaxGoroutines: 300, <mask> }, </s> Pull request: 2799 trusted proxy Merge in DNS/adguard-home from 2799-trusted-proxy to master Updates #2799. Squashed commit of the following: commit 708a06b30116126a575767ea70865a6de90de774 Author: Eugene Burkov <[email protected]> Date: Fri Jul 23 18:56:16 2021 +0300 all: add trusted proxy mechanism </s> add // TrustedProxies is the list of IP addresses and CIDR networks to // detect proxy servers addresses the DoH requests from which should be // handled. The value of nil or an empty slice for this field makes // Proxy not trust any address. TrustedProxies []string `yaml:"trusted_proxies"` </s> add TrustedProxies: s.conf.TrustedProxies, </s> add c.TrustedProxies = aghstrings.CloneSlice(sc.TrustedProxies) </s> add github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= </s> add github.com/AdguardTeam/dnsproxy v0.39.0 h1:5/PN2mpUeCTWtvqXUbSPTMJSOad4lJscPzm+C2f4jB4= github.com/AdguardTeam/dnsproxy v0.39.0/go.mod h1:aNXKNdTyKfgAG2OS712SYSaGIM9AasZsZxfiY4YiR/0= </s> remove github.com/AdguardTeam/dnsproxy v0.38.3 </s> add github.com/AdguardTeam/dnsproxy v0.39.0
https://github.com/AdguardTeam/AdGuardHome/commit/2f661df88cf4a11a86c1fbfb8dae9b2cd79ada09
internal/home/config.go
replace keep keep keep keep keep
<mask> import { getIpMatchListStatus } from '../helpers/helpers'; <mask> import { IP_MATCH_LIST_STATUS } from '../helpers/constants'; <mask> <mask> describe('getIpMatchListStatus', () => { <mask> describe('IPv4', () => { <mask> test('should return EXACT on find the exact ip match', () => { </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> remove </s> add import { sortIp } from '../../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/__tests__/helpers.test.js
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> import Card from '../ui/Card'; <mask> import Cell from '../ui/Cell'; <mask> <mask> import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; <mask> import { IP_MATCH_LIST_STATUS, STATUS_COLORS } from '../../helpers/constants'; <mask> import { formatClientCell } from '../../helpers/formatClientCell'; <mask> <mask> const getClientsPercentColor = (percent) => { <mask> if (percent > 50) { </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> remove </s> add import { sortIp } from '../../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> add sortMethod: sortIp, </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Dashboard/Clients.js
keep keep keep keep replace keep keep keep keep keep
<mask> columns={[ <mask> { <mask> Header: 'IP', <mask> accessor: 'ip', <mask> sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), <mask> Cell: clientCell(t, toggleClientStatus, processingAccessSet, disallowedClients), <mask> }, <mask> { <mask> Header: <Trans>requests_count</Trans>, <mask> accessor: 'count', </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> add sortMethod: sortIp, </s> add sortMethod: sortIp, </s> add sortMethod: sortIp, </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers';
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Dashboard/Clients.js
keep add keep keep keep keep
<mask> import whoisCell from './whoisCell'; <mask> import LogsSearchLink from '../../ui/LogsSearchLink'; <mask> <mask> const COLUMN_MIN_WIDTH = 200; <mask> <mask> class AutoClients extends Component { </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> remove </s> add import { sortIp } from '../../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> add sortMethod: sortIp, </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Clients/AutoClients.js
keep keep add keep keep keep keep
<mask> accessor: 'ip', <mask> minWidth: COLUMN_MIN_WIDTH, <mask> Cell: CellWrap, <mask> }, <mask> { <mask> Header: this.props.t('table_name'), <mask> accessor: 'name', </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> add sortMethod: sortIp, </s> add sortMethod: sortIp, </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers';
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Clients/AutoClients.js
keep keep add keep keep keep keep keep keep
<mask> import ReactTable from 'react-table'; <mask> import { Trans, withTranslation } from 'react-i18next'; <mask> import { LEASES_TABLE_DEFAULT_PAGE_SIZE } from '../../../helpers/constants'; <mask> <mask> class Leases extends Component { <mask> cellWrap = ({ value }) => ( <mask> <div className="logs__row o-hidden"> <mask> <span className="logs__text" title={value}> <mask> {value} </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> remove </s> add import { sortIp } from '../../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Dhcp/Leases.js
keep keep add keep keep keep keep keep
<mask> Header: 'IP', <mask> accessor: 'ip', <mask> Cell: this.cellWrap, <mask> }, { <mask> Header: <Trans>dhcp_table_hostname</Trans>, <mask> accessor: 'hostname', <mask> Cell: this.cellWrap, <mask> }, { </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> add sortMethod: sortIp, </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> add sortMethod: sortIp, </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers';
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Dhcp/Leases.js
keep keep keep keep replace keep keep keep keep keep
<mask> import PropTypes from 'prop-types'; <mask> import ReactTable from 'react-table'; <mask> import { Trans, withTranslation } from 'react-i18next'; <mask> import { LEASES_TABLE_DEFAULT_PAGE_SIZE } from '../../../../helpers/constants'; <mask> <mask> import Modal from './Modal'; <mask> <mask> class StaticLeases extends Component { <mask> cellWrap = ({ value }) => ( <mask> <div className="logs__row o-hidden"> </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> add import { sortIp } from '../../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Dhcp/StaticLeases/index.js
keep add keep keep keep keep keep
<mask> Header: 'IP', <mask> accessor: 'ip', <mask> Cell: this.cellWrap, <mask> }, <mask> { <mask> Header: <Trans>dhcp_table_hostname</Trans>, <mask> accessor: 'hostname', </s> Pull request 734: + client: 1778 Add ip sort function, write unit tests Close #1778 Squashed commit of the following: commit ba63e147311799b17deaa97d7a12c2e0ec44a2ed Merge: 143ba427 705a9d90 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 12:00:10 2020 +0300 Merge branch 'master' into feature/1778 commit 143ba42707da3d7eece9f3e137a8b245f7f7888f Merge: 483d2ff9 97df1989 Author: ArtemBaskal <[email protected]> Date: Thu Aug 13 11:16:46 2020 +0300 Merge branch 'master' into feature/1778 commit 483d2ff9fa3de706d94a647701f1d26a3bcbb217 Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 13:34:21 2020 +0300 Always put ipv4 before ipv6 in sort, add invalid input unit tests commit 26eb41b313785fe7ffaf98a7573cc5eef0dca14f Author: ArtemBaskal <[email protected]> Date: Wed Aug 12 11:27:46 2020 +0300 Rewrite tests: replace ipv4-mapped adresses commit 4ecf287fd46945effe9ff11cfc9ae49217b9c796 Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:05:15 2020 +0300 Minor fix commit 3e5e2a6bb1f2f166619da54e5ade0904fe22a20d Author: ArtemBaskal <[email protected]> Date: Tue Aug 11 19:01:26 2020 +0300 + client: 1778 Add ip sort function, write unit tests </s> add sortMethod: sortIp, </s> remove sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), </s> add sortMethod: sortIp, </s> add sortMethod: sortIp, </s> remove import { getIpMatchListStatus } from '../helpers/helpers'; </s> add import { getIpMatchListStatus, sortIp } from '../helpers/helpers'; </s> remove import { getPercent, getIpMatchListStatus } from '../../helpers/helpers'; </s> add import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; </s> add import { sortIp } from '../../../helpers/helpers';
https://github.com/AdguardTeam/AdGuardHome/commit/2f8e34e73b75a18cba70ae81e455c9e979642f52
client/src/components/Settings/Dhcp/StaticLeases/index.js
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> // TLSConfig is the TLS configuration for HTTPS, DNS-over-HTTPS, and DNS-over-TLS <mask> type TLSConfig struct { <mask> TLSListenAddr *net.TCPAddr `yaml:"-" json:"-"` <mask> StrictSNICheck bool `yaml:"strict_sni_check" json:"-"` // Reject connection if the client uses server name (in SNI) that doesn't match the certificate <mask> CertificateChain string `yaml:"certificate_chain" json:"certificate_chain"` // PEM-encoded certificates chain <mask> PrivateKey string `yaml:"private_key" json:"private_key"` // PEM-encoded private key <mask> <mask> CertificatePath string `yaml:"certificate_path" json:"certificate_path"` // certificate file name <mask> PrivateKeyPath string `yaml:"private_key_path" json:"private_key_path"` // private key file name <mask> <mask> CertificateChainData []byte `yaml:"-" json:"-"` </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation) </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }} </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) }
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
dnsforward/config.go
keep add keep keep keep keep keep
<mask> Context.tls.WriteDiskConfig(&tlsConf) <mask> } <mask> if proto == "https" && tlsConf.ServerName != "" { <mask> if tlsConf.PortHTTPS == 443 { <mask> log.Printf("Go to https://%s", tlsConf.ServerName) <mask> } else { <mask> log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> remove address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(iface.Addresses[0], port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation) </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }}
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> if proto == "https" && tlsConf.ServerName != "" { <mask> if tlsConf.PortHTTPS == 443 { <mask> log.Printf("Go to https://%s", tlsConf.ServerName) <mask> } else { <mask> log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) <mask> } <mask> } else if config.BindHost == "0.0.0.0" { <mask> log.Println("AdGuard Home is available on the following addresses:") <mask> ifaces, err := util.GetValidNetInterfacesForWeb() <mask> if err != nil { </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) } </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }} </s> remove address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(iface.Addresses[0], port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation)
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> log.Println("AdGuard Home is available on the following addresses:") <mask> ifaces, err := util.GetValidNetInterfacesForWeb() <mask> if err != nil { <mask> // That's weird, but we'll ignore it <mask> address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) <mask> log.Printf("Go to %s://%s", proto, address) <mask> return <mask> } <mask> <mask> for _, iface := range ifaces { </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> remove address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(iface.Addresses[0], port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) } </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }} </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation)
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/home.go
keep keep keep replace keep keep keep replace keep keep keep
<mask> } <mask> <mask> for _, iface := range ifaces { <mask> address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) <mask> log.Printf("Go to %s://%s", proto, address) <mask> } <mask> } else { <mask> address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) <mask> log.Printf("Go to %s://%s", proto, address) <mask> } <mask> } </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) } </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation) </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }}
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> t := &TLSMod{} <mask> t.conf = conf <mask> if t.conf.Enabled { <mask> if !t.load() { <mask> return nil <mask> } <mask> t.setCertFileTime() <mask> } <mask> return t <mask> } </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) } </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(iface.Addresses[0], port) </s> remove log.Error(data.WarningValidation) </s> add log.Error("failed to validate certificate: %s", data.WarningValidation) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port)
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/tls.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // validate current TLS config and update warnings (it could have been loaded from file) <mask> data := validateCertificates(string(t.conf.CertificateChainData), string(t.conf.PrivateKeyData), t.conf.ServerName) <mask> if !data.ValidPair { <mask> log.Error(data.WarningValidation) <mask> return false <mask> } <mask> t.status = data <mask> return true <mask> } </s> *(home): fix TLS module initialization Continue to work even when TLS cert-key pair is invalid Closes: https://github.com/AdguardTeam/AdGuardHome/issues/1677 </s> remove return nil </s> add // Something is not valid - return an empty TLS config return &TLSMod{conf: tlsConfigSettings{ Enabled: conf.Enabled, ServerName: conf.ServerName, PortHTTPS: conf.PortHTTPS, PortDNSOverTLS: conf.PortDNSOverTLS, AllowUnencryptedDOH: conf.AllowUnencryptedDOH, }} </s> add port := strconv.Itoa(config.BindPort) if proto == "https" { port = strconv.Itoa(tlsConf.PortHTTPS) } </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove address = net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(config.BindHost, port) </s> remove address = net.JoinHostPort(iface.Addresses[0], strconv.Itoa(config.BindPort)) </s> add address = net.JoinHostPort(iface.Addresses[0], port) </s> remove log.Printf("Go to https://%s:%d", tlsConf.ServerName, tlsConf.PortHTTPS) </s> add log.Printf("Go to https://%s:%s", tlsConf.ServerName, port)
https://github.com/AdguardTeam/AdGuardHome/commit/2fca419c7f2356026c1a9d8bd2ac2be9e9f2f240
home/tls.go
keep keep keep keep replace keep keep keep keep keep
<mask> import { Trans, withTranslation } from 'react-i18next'; <mask> import ReactTable from 'react-table'; <mask> <mask> import { MODAL_TYPE } from '../../../helpers/constants'; <mask> import { splitByNewLine, countClientsStatistics } from '../../../helpers/helpers'; <mask> import Card from '../../ui/Card'; <mask> import Modal from './Modal'; <mask> import CellWrap from '../../ui/CellWrap'; <mask> import LogsSearchLink from '../../ui/LogsSearchLink'; <mask> </s> Pull request: 4143 sort client ids Merge in DNS/adguard-home from 4143-clients-sort to master Updates #4143. Squashed commit of the following: commit a4b547eb46a54bdfdc7d342fab5f8ecfa54f5d06 Merge: d369c11c d82b2902 Author: Ildar Kamalov <[email protected]> Date: Thu Jan 20 11:58:42 2022 +0300 Merge branch 'master' into 4143-clients-sort commit d369c11c69665510043f63e0283e1ca1b2974289 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:53:39 2022 +0300 client: fix sort ip method commit d767a1199c37ad9df7f3bc2d362d840b0226d836 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:23:23 2022 +0300 client: sort client ids </s> add sortMethod: sortIp, </s> remove const comparisonBytesA = getAddressesComparisonBytes(a); const comparisonBytesB = getAddressesComparisonBytes(b); </s> add const comparisonBytesA = Array.isArray(a) ? getAddressesComparisonBytes(a[0]) : getAddressesComparisonBytes(a); const comparisonBytesB = Array.isArray(b) ? getAddressesComparisonBytes(b[0]) : getAddressesComparisonBytes(b);
https://github.com/AdguardTeam/AdGuardHome/commit/2fdda8a22cb46f76c8f92ac2bdcbd9b25acd3e21
client/src/components/Settings/Clients/ClientsTable.js
keep keep add keep keep keep keep
<mask> </div> <mask> ); <mask> }, <mask> }, <mask> { <mask> Header: this.props.t('table_name'), <mask> accessor: 'name', </s> Pull request: 4143 sort client ids Merge in DNS/adguard-home from 4143-clients-sort to master Updates #4143. Squashed commit of the following: commit a4b547eb46a54bdfdc7d342fab5f8ecfa54f5d06 Merge: d369c11c d82b2902 Author: Ildar Kamalov <[email protected]> Date: Thu Jan 20 11:58:42 2022 +0300 Merge branch 'master' into 4143-clients-sort commit d369c11c69665510043f63e0283e1ca1b2974289 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:53:39 2022 +0300 client: fix sort ip method commit d767a1199c37ad9df7f3bc2d362d840b0226d836 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:23:23 2022 +0300 client: sort client ids </s> remove import { splitByNewLine, countClientsStatistics } from '../../../helpers/helpers'; </s> add import { splitByNewLine, countClientsStatistics, sortIp } from '../../../helpers/helpers'; </s> remove const comparisonBytesA = getAddressesComparisonBytes(a); const comparisonBytesB = getAddressesComparisonBytes(b); </s> add const comparisonBytesA = Array.isArray(a) ? getAddressesComparisonBytes(a[0]) : getAddressesComparisonBytes(a); const comparisonBytesB = Array.isArray(b) ? getAddressesComparisonBytes(b[0]) : getAddressesComparisonBytes(b);
https://github.com/AdguardTeam/AdGuardHome/commit/2fdda8a22cb46f76c8f92ac2bdcbd9b25acd3e21
client/src/components/Settings/Clients/ClientsTable.js
keep keep keep keep replace replace keep keep keep keep keep
<mask> * @returns {number} -1 | 0 | 1 <mask> */ <mask> export const sortIp = (a, b) => { <mask> try { <mask> const comparisonBytesA = getAddressesComparisonBytes(a); <mask> const comparisonBytesB = getAddressesComparisonBytes(b); <mask> <mask> for (let i = 0; i < comparisonBytesA.length; i += 1) { <mask> const byteA = comparisonBytesA[i]; <mask> const byteB = comparisonBytesB[i]; <mask> </s> Pull request: 4143 sort client ids Merge in DNS/adguard-home from 4143-clients-sort to master Updates #4143. Squashed commit of the following: commit a4b547eb46a54bdfdc7d342fab5f8ecfa54f5d06 Merge: d369c11c d82b2902 Author: Ildar Kamalov <[email protected]> Date: Thu Jan 20 11:58:42 2022 +0300 Merge branch 'master' into 4143-clients-sort commit d369c11c69665510043f63e0283e1ca1b2974289 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:53:39 2022 +0300 client: fix sort ip method commit d767a1199c37ad9df7f3bc2d362d840b0226d836 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 19 16:23:23 2022 +0300 client: sort client ids </s> remove import { splitByNewLine, countClientsStatistics } from '../../../helpers/helpers'; </s> add import { splitByNewLine, countClientsStatistics, sortIp } from '../../../helpers/helpers'; </s> add sortMethod: sortIp,
https://github.com/AdguardTeam/AdGuardHome/commit/2fdda8a22cb46f76c8f92ac2bdcbd9b25acd3e21
client/src/helpers/helpers.js
add keep keep keep keep keep
<mask> { <mask> "example_upstream_reserved": "you can specify DNS upstream <0>for a specific domain(s)<\/0>", <mask> "upstream_parallel": "Use parallel queries to speed up resolving by simultaneously querying all upstream servers", <mask> "bootstrap_dns": "Bootstrap DNS servers", <mask> "bootstrap_dns_desc": "Bootstrap DNS servers are used to resolve IP addresses of the DoH\/DoT resolvers you specify as upstreams.", <mask> "url_added_successfully": "URL added successfully", </s> - client: fix update now button and notification </s> remove "client_settings": "Client settings", </s> add </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> add import versionCompare from '../helpers/versionCompare'; </s> remove return state; </s> add return { ...state, processingVersion: false, };
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/__locales/en.json
keep keep keep keep replace keep keep keep keep keep
<mask> "settings": "Settings", <mask> "filters": "Filters", <mask> "query_log": "Query Log", <mask> "faq": "FAQ", <mask> "version": "version", <mask> "address": "address", <mask> "on": "ON", <mask> "off": "OFF", <mask> "copyright": "Copyright", <mask> "homepage": "Homepage", </s> - client: fix update now button and notification </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> add import versionCompare from '../helpers/versionCompare'; </s> add "updates_version_equal": "AdGuard Home is up-to-date",
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/__locales/en.json
keep keep keep keep replace keep keep keep keep keep
<mask> "general_settings": "General settings", <mask> "dns_settings": "DNS settings", <mask> "encryption_settings": "Encryption settings", <mask> "dhcp_settings": "DHCP settings", <mask> "client_settings": "Client settings", <mask> "upstream_dns": "Upstream DNS servers", <mask> "upstream_dns_hint": "If you keep this field empty, AdGuard Home will use <a href='https:\/\/1.1.1.1\/' target='_blank'>Cloudflare DNS<\/a> as an upstream.", <mask> "test_upstream_btn": "Test upstreams", <mask> "apply_btn": "Apply", <mask> "disabled_filtering_toast": "Disabled filtering", </s> - client: fix update now button and notification </s> add "client_settings": "Client settings", </s> add "updates_version_equal": "AdGuard Home is up-to-date", </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => {
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/__locales/en.json
keep add keep keep keep keep
<mask> "access_settings_saved": "Access settings successfully saved", <mask> "updates_checked": "Updates successfully checked", <mask> "check_updates_now": "Check for updates now", <mask> "dns_privacy": "DNS Privacy", <mask> "setup_dns_privacy_1": "<0>DNS-over-TLS:</0> Use <1>{{address}}</1> string.", <mask> "setup_dns_privacy_2": "<0>DNS-over-HTTPS:</0> Use <1>{{address}}</1> string.", </s> - client: fix update now button and notification </s> remove "client_settings": "Client settings", </s> add </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> add import versionCompare from '../helpers/versionCompare';
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/__locales/en.json
keep add keep keep keep keep keep keep
<mask> import axios from 'axios'; <mask> <mask> import { normalizeHistory, normalizeFilteringStatus, normalizeLogs, normalizeTextarea, sortClients } from '../helpers/helpers'; <mask> import { SETTINGS_NAMES, CHECK_TIMEOUT } from '../helpers/constants'; <mask> import { getTlsStatus } from './encryption'; <mask> import Api from '../api/Api'; <mask> <mask> const apiClient = new Api(); </s> - client: fix update now button and notification </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> add "client_settings": "Client settings", </s> add "updates_version_equal": "AdGuard Home is up-to-date",
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/actions/index.js
keep keep keep replace keep keep replace replace keep keep keep
<mask> export const getVersionFailure = createAction('GET_VERSION_FAILURE'); <mask> export const getVersionSuccess = createAction('GET_VERSION_SUCCESS'); <mask> <mask> export const getVersion = (recheck = false) => async (dispatch) => { <mask> dispatch(getVersionRequest()); <mask> try { <mask> const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); <mask> dispatch(getVersionSuccess(newVersion)); <mask> if (recheck) { <mask> dispatch(addSuccessToast('updates_checked')); <mask> } </s> - client: fix update now button and notification </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> add import versionCompare from '../helpers/versionCompare'; </s> add "client_settings": "Client settings", </s> add "updates_version_equal": "AdGuard Home is up-to-date",
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/actions/index.js
keep keep keep keep replace keep keep keep keep keep
<mask> try { <mask> const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); <mask> dispatch(getVersionSuccess(newVersion)); <mask> if (recheck) { <mask> dispatch(addSuccessToast('updates_checked')); <mask> } <mask> } catch (error) { <mask> dispatch(addErrorToast({ error })); <mask> dispatch(getVersionFailure()); <mask> } </s> - client: fix update now button and notification </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> add import versionCompare from '../helpers/versionCompare'; </s> remove return state; </s> add return { ...state, processingVersion: false, }; </s> add "client_settings": "Client settings", </s> add "updates_version_equal": "AdGuard Home is up-to-date",
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/actions/index.js
keep keep keep keep replace keep keep keep keep keep
<mask> }; <mask> return newState; <mask> } <mask> <mask> return state; <mask> }, <mask> <mask> [actions.getUpdateRequest]: state => ({ ...state, processingUpdate: true }), <mask> [actions.getUpdateFailure]: state => ({ ...state, processingUpdate: false }), <mask> [actions.getUpdateSuccess]: (state) => { </s> - client: fix update now button and notification </s> remove export const getVersion = (recheck = false) => async (dispatch) => { </s> add export const getVersion = (recheck = false) => async (dispatch, getState) => { </s> remove const newVersion = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(newVersion)); </s> add const data = await apiClient.getGlobalVersion({ recheck_now: recheck }); dispatch(getVersionSuccess(data)); </s> remove dispatch(addSuccessToast('updates_checked')); </s> add const { dnsVersion } = getState().dashboard; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; if (data && versionCompare(currentVersion, data.new_version) === -1) { dispatch(addSuccessToast('updates_checked')); } else { dispatch(addSuccessToast('updates_version_equal')); } </s> add import versionCompare from '../helpers/versionCompare'; </s> add "client_settings": "Client settings", </s> add "updates_version_equal": "AdGuard Home is up-to-date",
https://github.com/AdguardTeam/AdGuardHome/commit/2fe9819150f3a6d5eeeee632879eb85dc632559f
client/src/reducers/index.js
keep keep keep replace keep keep keep keep keep
<mask> package main <mask> <mask> import ( <mask> "bufio" <mask> "fmt" <mask> stdlog "log" <mask> "net" <mask> "net/http" <mask> "os" </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "fmt" </s> remove "net" </s> add </s> add "net" </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> remove "golang.org/x/crypto/ssh/terminal" </s> add </s> remove err := askUsernamePasswordIfPossible() if err != nil { log.Fatal(err) } </s> add config.firstRun = detectFirstRun()
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> "github.com/gobuffalo/packr" <mask> <mask> "github.com/hmage/golibs/log" <mask> "golang.org/x/crypto/ssh/terminal" <mask> ) <mask> <mask> // VersionString will be set through ldflags, contains current version <mask> var VersionString = "undefined" <mask> </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "github.com/hmage/golibs/log" </s> add firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove err = upgradeConfig() </s> add err := upgradeConfig() </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep keep replace replace replace replace keep keep keep keep keep keep keep keep replace keep keep keep
<mask> if args.runningAsService { <mask> log.Printf("AdGuard Home is running as a service") <mask> } <mask> <mask> err := askUsernamePasswordIfPossible() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> // Do the upgrade if necessary <mask> err = upgradeConfig() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> // Do the upgrade if necessary <mask> err = upgradeConfig() <mask> if err != nil { <mask> log.Fatal(err) <mask> } </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i] </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove err := json.NewEncoder(w).Encode(data) </s> add err = json.NewEncoder(w).Encode(data) </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> go periodicallyRefreshFilters() <mask> <mask> // Initialize and run the admin Web interface <mask> box := packr.NewBox("build/static") <mask> http.Handle("/", optionalAuthHandler(http.FileServer(box))) <mask> registerControlHandlers() <mask> <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.BindPort)) <mask> URL := fmt.Sprintf("http://%s", address) <mask> log.Println("Go to " + URL) </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func getInput() (string, error) { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() text := scanner.Text() err := scanner.Err() return text, err } </s> add </s> add if config.firstRun { log.Tracef("Silently refusing to write config because first run and not configured yet") return nil } </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i] </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> add firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> log.Printf("Couldn't stop DHCP server: %s", err) <mask> } <mask> } <mask> <mask> func getInput() (string, error) { <mask> scanner := bufio.NewScanner(os.Stdin) <mask> scanner.Scan() <mask> text := scanner.Text() <mask> err := scanner.Err() <mask> return text, err <mask> } <mask> <mask> // command-line arguments <mask> type options struct { <mask> verbose bool // is verbose logging enabled <mask> configFilename string // path to the config file <mask> bindHost string // host address to bind HTTP server on </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove err = upgradeConfig() </s> add err := upgradeConfig() </s> add firstRun bool // if set to true, don't run any services except HTTP web inteface, and serve only first-run html </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` }
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace
<mask> } <mask> <mask> return o <mask> } <mask> <mask> func promptAndGet(prompt string) (string, error) { <mask> for { <mask> fmt.Print(prompt) <mask> input, err := getInput() <mask> if err != nil { <mask> log.Printf("Failed to get input, aborting: %s", err) <mask> return "", err <mask> } <mask> if len(input) != 0 { <mask> return input, nil <mask> } <mask> // try again <mask> } <mask> } <mask> <mask> func promptAndGetPassword(prompt string) (string, error) { <mask> for { <mask> fmt.Print(prompt) <mask> password, err := terminal.ReadPassword(int(os.Stdin.Fd())) <mask> fmt.Print("\n") <mask> if err != nil { <mask> log.Printf("Failed to get input, aborting: %s", err) <mask> return "", err <mask> } <mask> if len(password) != 0 { <mask> return string(password), nil <mask> } <mask> // try again <mask> } <mask> } <mask> <mask> func askUsernamePasswordIfPossible() error { <mask> configFile := config.getConfigFilename() <mask> _, err := os.Stat(configFile) <mask> if !os.IsNotExist(err) { <mask> // do nothing, file exists <mask> return nil <mask> } <mask> if !terminal.IsTerminal(int(os.Stdin.Fd())) { <mask> return nil // do nothing <mask> } <mask> if !terminal.IsTerminal(int(os.Stdout.Fd())) { <mask> return nil // do nothing <mask> } <mask> fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") <mask> yesno, err := promptAndGet("Please type 'yes' or 'no': ") <mask> if err != nil { <mask> return err <mask> } <mask> if yesno[0] != 'y' && yesno[0] != 'Y' { <mask> return nil <mask> } <mask> username, err := promptAndGet("Please enter the username: ") <mask> if err != nil { <mask> return err <mask> } <mask> <mask> password, err := promptAndGetPassword("Please enter the password: ") <mask> if err != nil { <mask> return err <mask> } <mask> <mask> password2, err := promptAndGetPassword("Please enter password again: ") <mask> if err != nil { <mask> return err <mask> } <mask> if password2 != password { <mask> fmt.Printf("Passwords do not match! Aborting\n") <mask> os.Exit(1) <mask> } <mask> <mask> config.AuthName = username <mask> config.AuthPass = password <mask> return nil <mask> } </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i] </s> remove err := askUsernamePasswordIfPossible() if err != nil { log.Fatal(err) } </s> add config.firstRun = detectFirstRun() </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove err = upgradeConfig() </s> add err := upgradeConfig() </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove if config.AuthName == "" || config.AuthPass == "" { a.handler.ServeHTTP(w, r) return } user, pass, ok := r.BasicAuth() if !ok || user != config.AuthName || pass != config.AuthPass { w.Header().Set("WWW-Authenticate", `Basic realm="dnsfilter"`) w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorised.\n")) return } a.handler.ServeHTTP(w, r) </s> add optionalAuth(a.handler.ServeHTTP)(w, r)
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
app.go
keep keep keep add keep keep keep keep keep keep
<mask> // field ordering is important -- yaml fields will mirror ordering from here <mask> type configuration struct { <mask> ourConfigFilename string // Config filename (can be overridden via the command line arguments) <mask> ourBinaryDir string // Location of our directory, used to protect against CWD being somewhere else <mask> <mask> BindHost string `yaml:"bind_host"` <mask> BindPort int `yaml:"bind_port"` <mask> AuthName string `yaml:"auth_name"` <mask> AuthPass string `yaml:"auth_pass"` <mask> Language string `yaml:"language"` // two-letter ISO 639-1 language code </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func getInput() (string, error) { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() text := scanner.Text() err := scanner.Err() return text, err } </s> add </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err) </s> add httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) </s> remove "golang.org/x/crypto/ssh/terminal" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
config.go
keep add keep keep keep keep keep
<mask> c.Lock() <mask> defer c.Unlock() <mask> configFile := config.getConfigFilename() <mask> log.Printf("Writing YAML file: %s", configFile) <mask> yamlText, err := yaml.Marshal(&config) <mask> if err != nil { <mask> log.Printf("Couldn't generate YAML file: %s", err) </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove ifaces, err := net.Interfaces() </s> add ifaces, err := getValidNetInterfaces() </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err) </s> add httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) </s> remove func getInput() (string, error) { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() text := scanner.Text() err := scanner.Err() return text, err } </s> add </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i]
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
config.go
keep keep add keep keep keep keep keep keep
<mask> } <mask> } <mask> <mask> func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) { <mask> data := firstRunData{} <mask> ifaces, err := getValidNetInterfaces() <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) <mask> return </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove ifaces, err := net.Interfaces() </s> add ifaces, err := getValidNetInterfaces() </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err) </s> add httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add </s> remove if config.AuthName == "" || config.AuthPass == "" { a.handler.ServeHTTP(w, r) return } user, pass, ok := r.BasicAuth() if !ok || user != config.AuthName || pass != config.AuthPass { w.Header().Set("WWW-Authenticate", `Basic realm="dnsfilter"`) w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorised.\n")) return } a.handler.ServeHTTP(w, r) </s> add optionalAuth(a.handler.ServeHTTP)(w, r)
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep keep keep replace replace replace keep replace replace replace replace keep
<mask> } <mask> <mask> func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) { <mask> type ipport struct { <mask> IP string `json:"ip"` <mask> Port int `json:"port"` <mask> } <mask> data := struct { <mask> Web ipport `json:"web"` <mask> DNS ipport `json:"dns"` <mask> }{} <mask> </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add </s> remove ifaces, err := net.Interfaces() </s> add ifaces, err := getValidNetInterfaces()
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep replace replace replace replace replace keep keep replace keep
<mask> <mask> // TODO: replace mockup with actual data <mask> data.Web.IP = "192.168.104.104" <mask> data.Web.Port = 3000 <mask> data.DNS.IP = "192.168.104.104" <mask> data.DNS.Port = 53 <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err := json.NewEncoder(w).Encode(data) <mask> if err != nil { </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i] </s> remove err := askUsernamePasswordIfPossible() if err != nil { log.Fatal(err) } </s> add config.firstRun = detectFirstRun() </s> remove err = upgradeConfig() </s> add err := upgradeConfig() </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> } <mask> <mask> func handleSetAllSettings(w http.ResponseWriter, r *http.Request) { <mask> newSettings := map[string]interface{}{} <mask> err := json.NewDecoder(r.Body).Decode(&newSettings) <mask> if err != nil { <mask> httpError(w, http.StatusBadRequest, "Failed to parse new DHCP config json: %s", err) <mask> return <mask> } </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove ifaces, err := net.Interfaces() </s> add ifaces, err := getValidNetInterfaces() </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove err = upgradeConfig() </s> add err := upgradeConfig() </s> remove if config.AuthName == "" || config.AuthPass == "" { a.handler.ServeHTTP(w, r) return } user, pass, ok := r.BasicAuth() if !ok || user != config.AuthName || pass != config.AuthPass { w.Header().Set("WWW-Authenticate", `Basic realm="dnsfilter"`) w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorised.\n")) return } a.handler.ServeHTTP(w, r) </s> add optionalAuth(a.handler.ServeHTTP)(w, r) </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i]
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep keep add keep keep keep keep
<mask> } <mask> <mask> spew.Dump(newSettings) <mask> } <mask> <mask> func registerControlHandlers() { <mask> http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus)))) </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove http.HandleFunc("/control/status", optionalAuth(ensureGET(handleStatus))) http.HandleFunc("/control/enable_protection", optionalAuth(ensurePOST(handleProtectionEnable))) http.HandleFunc("/control/disable_protection", optionalAuth(ensurePOST(handleProtectionDisable))) http.HandleFunc("/control/querylog", optionalAuth(ensureGET(dnsforward.HandleQueryLog))) http.HandleFunc("/control/querylog_enable", optionalAuth(ensurePOST(handleQueryLogEnable))) http.HandleFunc("/control/querylog_disable", optionalAuth(ensurePOST(handleQueryLogDisable))) http.HandleFunc("/control/set_upstream_dns", optionalAuth(ensurePOST(handleSetUpstreamDNS))) http.HandleFunc("/control/test_upstream_dns", optionalAuth(ensurePOST(handleTestUpstreamDNS))) http.HandleFunc("/control/i18n/change_language", optionalAuth(ensurePOST(handleI18nChangeLanguage))) http.HandleFunc("/control/i18n/current_language", optionalAuth(ensureGET(handleI18nCurrentLanguage))) http.HandleFunc("/control/stats_top", optionalAuth(ensureGET(dnsforward.HandleStatsTop))) http.HandleFunc("/control/stats", optionalAuth(ensureGET(dnsforward.HandleStats))) http.HandleFunc("/control/stats_history", optionalAuth(ensureGET(dnsforward.HandleStatsHistory))) http.HandleFunc("/control/stats_reset", optionalAuth(ensurePOST(dnsforward.HandleStatsReset))) http.HandleFunc("/control/version.json", optionalAuth(handleGetVersionJSON)) http.HandleFunc("/control/filtering/enable", optionalAuth(ensurePOST(handleFilteringEnable))) http.HandleFunc("/control/filtering/disable", optionalAuth(ensurePOST(handleFilteringDisable))) http.HandleFunc("/control/filtering/add_url", optionalAuth(ensurePUT(handleFilteringAddURL))) http.HandleFunc("/control/filtering/remove_url", optionalAuth(ensureDELETE(handleFilteringRemoveURL))) http.HandleFunc("/control/filtering/enable_url", optionalAuth(ensurePOST(handleFilteringEnableURL))) http.HandleFunc("/control/filtering/disable_url", optionalAuth(ensurePOST(handleFilteringDisableURL))) http.HandleFunc("/control/filtering/refresh", optionalAuth(ensurePOST(handleFilteringRefresh))) http.HandleFunc("/control/filtering/status", optionalAuth(ensureGET(handleFilteringStatus))) http.HandleFunc("/control/filtering/set_rules", optionalAuth(ensurePUT(handleFilteringSetRules))) http.HandleFunc("/control/safebrowsing/enable", optionalAuth(ensurePOST(handleSafeBrowsingEnable))) http.HandleFunc("/control/safebrowsing/disable", optionalAuth(ensurePOST(handleSafeBrowsingDisable))) http.HandleFunc("/control/safebrowsing/status", optionalAuth(ensureGET(handleSafeBrowsingStatus))) http.HandleFunc("/control/parental/enable", optionalAuth(ensurePOST(handleParentalEnable))) http.HandleFunc("/control/parental/disable", optionalAuth(ensurePOST(handleParentalDisable))) http.HandleFunc("/control/parental/status", optionalAuth(ensureGET(handleParentalStatus))) http.HandleFunc("/control/safesearch/enable", optionalAuth(ensurePOST(handleSafeSearchEnable))) http.HandleFunc("/control/safesearch/disable", optionalAuth(ensurePOST(handleSafeSearchDisable))) http.HandleFunc("/control/safesearch/status", optionalAuth(ensureGET(handleSafeSearchStatus))) http.HandleFunc("/control/dhcp/status", optionalAuth(ensureGET(handleDHCPStatus))) http.HandleFunc("/control/dhcp/interfaces", optionalAuth(ensureGET(handleDHCPInterfaces))) http.HandleFunc("/control/dhcp/set_config", optionalAuth(ensurePOST(handleDHCPSetConfig))) http.HandleFunc("/control/dhcp/find_active_dhcp", optionalAuth(ensurePOST(handleDHCPFindActiveServer))) </s> add http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus)))) http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable)))) http.HandleFunc("/control/disable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionDisable)))) http.HandleFunc("/control/querylog", postInstall(optionalAuth(ensureGET(dnsforward.HandleQueryLog)))) http.HandleFunc("/control/querylog_enable", postInstall(optionalAuth(ensurePOST(handleQueryLogEnable)))) http.HandleFunc("/control/querylog_disable", postInstall(optionalAuth(ensurePOST(handleQueryLogDisable)))) http.HandleFunc("/control/set_upstream_dns", postInstall(optionalAuth(ensurePOST(handleSetUpstreamDNS)))) http.HandleFunc("/control/test_upstream_dns", postInstall(optionalAuth(ensurePOST(handleTestUpstreamDNS)))) http.HandleFunc("/control/i18n/change_language", postInstall(optionalAuth(ensurePOST(handleI18nChangeLanguage)))) http.HandleFunc("/control/i18n/current_language", postInstall(optionalAuth(ensureGET(handleI18nCurrentLanguage)))) http.HandleFunc("/control/stats_top", postInstall(optionalAuth(ensureGET(dnsforward.HandleStatsTop)))) http.HandleFunc("/control/stats", postInstall(optionalAuth(ensureGET(dnsforward.HandleStats)))) http.HandleFunc("/control/stats_history", postInstall(optionalAuth(ensureGET(dnsforward.HandleStatsHistory)))) http.HandleFunc("/control/stats_reset", postInstall(optionalAuth(ensurePOST(dnsforward.HandleStatsReset)))) http.HandleFunc("/control/version.json", postInstall(optionalAuth(handleGetVersionJSON))) http.HandleFunc("/control/filtering/enable", postInstall(optionalAuth(ensurePOST(handleFilteringEnable)))) http.HandleFunc("/control/filtering/disable", postInstall(optionalAuth(ensurePOST(handleFilteringDisable)))) http.HandleFunc("/control/filtering/add_url", postInstall(optionalAuth(ensurePUT(handleFilteringAddURL)))) http.HandleFunc("/control/filtering/remove_url", postInstall(optionalAuth(ensureDELETE(handleFilteringRemoveURL)))) http.HandleFunc("/control/filtering/enable_url", postInstall(optionalAuth(ensurePOST(handleFilteringEnableURL)))) http.HandleFunc("/control/filtering/disable_url", postInstall(optionalAuth(ensurePOST(handleFilteringDisableURL)))) http.HandleFunc("/control/filtering/refresh", postInstall(optionalAuth(ensurePOST(handleFilteringRefresh)))) http.HandleFunc("/control/filtering/status", postInstall(optionalAuth(ensureGET(handleFilteringStatus)))) http.HandleFunc("/control/filtering/set_rules", postInstall(optionalAuth(ensurePUT(handleFilteringSetRules)))) http.HandleFunc("/control/safebrowsing/enable", postInstall(optionalAuth(ensurePOST(handleSafeBrowsingEnable)))) http.HandleFunc("/control/safebrowsing/disable", postInstall(optionalAuth(ensurePOST(handleSafeBrowsingDisable)))) http.HandleFunc("/control/safebrowsing/status", postInstall(optionalAuth(ensureGET(handleSafeBrowsingStatus)))) http.HandleFunc("/control/parental/enable", postInstall(optionalAuth(ensurePOST(handleParentalEnable)))) http.HandleFunc("/control/parental/disable", postInstall(optionalAuth(ensurePOST(handleParentalDisable)))) http.HandleFunc("/control/parental/status", postInstall(optionalAuth(ensureGET(handleParentalStatus)))) http.HandleFunc("/control/safesearch/enable", postInstall(optionalAuth(ensurePOST(handleSafeSearchEnable)))) http.HandleFunc("/control/safesearch/disable", postInstall(optionalAuth(ensurePOST(handleSafeSearchDisable)))) http.HandleFunc("/control/safesearch/status", postInstall(optionalAuth(ensureGET(handleSafeSearchStatus)))) http.HandleFunc("/control/dhcp/status", postInstall(optionalAuth(ensureGET(handleDHCPStatus)))) http.HandleFunc("/control/dhcp/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces)))) http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSetConfig)))) http.HandleFunc("/control/dhcp/find_active_dhcp", postInstall(optionalAuth(ensurePOST(handleDHCPFindActiveServer)))) </s> remove if config.AuthName == "" || config.AuthPass == "" { a.handler.ServeHTTP(w, r) return } user, pass, ok := r.BasicAuth() if !ok || user != config.AuthName || pass != config.AuthPass { w.Header().Set("WWW-Authenticate", `Basic realm="dnsfilter"`) w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorised.\n")) return } a.handler.ServeHTTP(w, r) </s> add optionalAuth(a.handler.ServeHTTP)(w, r) </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep replace replace
<mask> func registerControlHandlers() { <mask> http.HandleFunc("/control/status", optionalAuth(ensureGET(handleStatus))) <mask> http.HandleFunc("/control/enable_protection", optionalAuth(ensurePOST(handleProtectionEnable))) <mask> http.HandleFunc("/control/disable_protection", optionalAuth(ensurePOST(handleProtectionDisable))) <mask> http.HandleFunc("/control/querylog", optionalAuth(ensureGET(dnsforward.HandleQueryLog))) <mask> http.HandleFunc("/control/querylog_enable", optionalAuth(ensurePOST(handleQueryLogEnable))) <mask> http.HandleFunc("/control/querylog_disable", optionalAuth(ensurePOST(handleQueryLogDisable))) <mask> http.HandleFunc("/control/set_upstream_dns", optionalAuth(ensurePOST(handleSetUpstreamDNS))) <mask> http.HandleFunc("/control/test_upstream_dns", optionalAuth(ensurePOST(handleTestUpstreamDNS))) <mask> http.HandleFunc("/control/i18n/change_language", optionalAuth(ensurePOST(handleI18nChangeLanguage))) <mask> http.HandleFunc("/control/i18n/current_language", optionalAuth(ensureGET(handleI18nCurrentLanguage))) <mask> http.HandleFunc("/control/stats_top", optionalAuth(ensureGET(dnsforward.HandleStatsTop))) <mask> http.HandleFunc("/control/stats", optionalAuth(ensureGET(dnsforward.HandleStats))) <mask> http.HandleFunc("/control/stats_history", optionalAuth(ensureGET(dnsforward.HandleStatsHistory))) <mask> http.HandleFunc("/control/stats_reset", optionalAuth(ensurePOST(dnsforward.HandleStatsReset))) <mask> http.HandleFunc("/control/version.json", optionalAuth(handleGetVersionJSON)) <mask> http.HandleFunc("/control/filtering/enable", optionalAuth(ensurePOST(handleFilteringEnable))) <mask> http.HandleFunc("/control/filtering/disable", optionalAuth(ensurePOST(handleFilteringDisable))) <mask> http.HandleFunc("/control/filtering/add_url", optionalAuth(ensurePUT(handleFilteringAddURL))) <mask> http.HandleFunc("/control/filtering/remove_url", optionalAuth(ensureDELETE(handleFilteringRemoveURL))) <mask> http.HandleFunc("/control/filtering/enable_url", optionalAuth(ensurePOST(handleFilteringEnableURL))) <mask> http.HandleFunc("/control/filtering/disable_url", optionalAuth(ensurePOST(handleFilteringDisableURL))) <mask> http.HandleFunc("/control/filtering/refresh", optionalAuth(ensurePOST(handleFilteringRefresh))) <mask> http.HandleFunc("/control/filtering/status", optionalAuth(ensureGET(handleFilteringStatus))) <mask> http.HandleFunc("/control/filtering/set_rules", optionalAuth(ensurePUT(handleFilteringSetRules))) <mask> http.HandleFunc("/control/safebrowsing/enable", optionalAuth(ensurePOST(handleSafeBrowsingEnable))) <mask> http.HandleFunc("/control/safebrowsing/disable", optionalAuth(ensurePOST(handleSafeBrowsingDisable))) <mask> http.HandleFunc("/control/safebrowsing/status", optionalAuth(ensureGET(handleSafeBrowsingStatus))) <mask> http.HandleFunc("/control/parental/enable", optionalAuth(ensurePOST(handleParentalEnable))) <mask> http.HandleFunc("/control/parental/disable", optionalAuth(ensurePOST(handleParentalDisable))) <mask> http.HandleFunc("/control/parental/status", optionalAuth(ensureGET(handleParentalStatus))) <mask> http.HandleFunc("/control/safesearch/enable", optionalAuth(ensurePOST(handleSafeSearchEnable))) <mask> http.HandleFunc("/control/safesearch/disable", optionalAuth(ensurePOST(handleSafeSearchDisable))) <mask> http.HandleFunc("/control/safesearch/status", optionalAuth(ensureGET(handleSafeSearchStatus))) <mask> http.HandleFunc("/control/dhcp/status", optionalAuth(ensureGET(handleDHCPStatus))) <mask> http.HandleFunc("/control/dhcp/interfaces", optionalAuth(ensureGET(handleDHCPInterfaces))) <mask> http.HandleFunc("/control/dhcp/set_config", optionalAuth(ensurePOST(handleDHCPSetConfig))) <mask> http.HandleFunc("/control/dhcp/find_active_dhcp", optionalAuth(ensurePOST(handleDHCPFindActiveServer))) <mask> <mask> // TODO: move to registerInstallHandlers() <mask> http.HandleFunc("/control/install/get_default_addresses", ensureGET(handleGetDefaultAddresses)) <mask> http.HandleFunc("/control/install/set_all_settings", ensurePOST(handleSetAllSettings)) </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add config.firstRun = false config.BindHost = newSettings.Web.IP config.BindPort = newSettings.Web.Port config.DNS.BindHost = newSettings.DNS.IP config.DNS.Port = newSettings.DNS.Port config.AuthName = newSettings.Username config.AuthPass = newSettings.Password httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove http.Handle("/", optionalAuthHandler(http.FileServer(box))) </s> add // if not configured, redirect / to /install.html, otherwise redirect /install.html to / http.Handle("/", postInstallHandler(optionalAuthHandler(http.FileServer(box)))) http.Handle("/install.html", preInstallHandler(http.FileServer(box))) </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> remove func getInput() (string, error) { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() text := scanner.Text() err := scanner.Err() return text, err } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
control.go
keep keep keep keep replace keep keep keep keep keep
<mask> import ( <mask> "encoding/json" <mask> "fmt" <mask> "io/ioutil" <mask> "net" <mask> "net/http" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dhcpd" </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "fmt" </s> remove "bufio" </s> add </s> add "net" </s> add "github.com/hmage/golibs/log" </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove "golang.org/x/crypto/ssh/terminal" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
dhcp.go
keep keep replace keep replace
<mask> response := map[string]interface{}{} <mask> <mask> ifaces, err := net.Interfaces() <mask> if err != nil { <mask> httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err) </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i]
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
dhcp.go
keep keep keep replace replace replace replace replace replace replace keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep
<mask> return <mask> } <mask> <mask> type responseInterface struct { <mask> Name string `json:"name"` <mask> MTU int `json:"mtu"` <mask> HardwareAddr string `json:"hardware_address"` <mask> Addresses []string `json:"ip_addresses"` <mask> } <mask> <mask> for i := range ifaces { <mask> if ifaces[i].Flags&net.FlagLoopback != 0 { <mask> // it's a loopback, skip it <mask> continue <mask> } <mask> if ifaces[i].Flags&net.FlagBroadcast == 0 { <mask> // this interface doesn't support broadcast, skip it <mask> continue <mask> } <mask> if ifaces[i].Flags&net.FlagPointToPoint != 0 { <mask> // this interface is ppp, don't do dhcp over it <mask> continue <mask> } <mask> iface := responseInterface{ <mask> Name: ifaces[i].Name, <mask> MTU: ifaces[i].MTU, <mask> HardwareAddr: ifaces[i].HardwareAddr.String(), <mask> } <mask> addrs, errAddrs := ifaces[i].Addrs() <mask> if errAddrs != nil { <mask> httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) <mask> return <mask> } <mask> for _, addr := range addrs { <mask> iface.Addresses = append(iface.Addresses, addr.String()) <mask> } <mask> if len(iface.Addresses) == 0 { <mask> // this interface has no addresses, skip it <mask> continue <mask> } <mask> response[ifaces[i].Name] = iface <mask> } <mask> <mask> err = json.NewEncoder(w).Encode(response) <mask> if err != nil { </s> Initial implementation of welcome/firstrun/installer page in go backend </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err) </s> add httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) </s> remove err := askUsernamePasswordIfPossible() if err != nil { log.Fatal(err) } </s> add config.firstRun = detectFirstRun()
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
dhcp.go
keep keep add keep keep keep keep keep
<mask> import ( <mask> "bufio" <mask> "errors" <mask> "io" <mask> "io/ioutil" <mask> "net" <mask> "net/http" <mask> "os" </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "net" </s> remove "bufio" </s> add </s> remove "net" </s> add </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> remove "golang.org/x/crypto/ssh/terminal" </s> add </s> remove err := askUsernamePasswordIfPossible() if err != nil { log.Fatal(err) } </s> add config.firstRun = detectFirstRun()
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
helpers.go
keep keep keep add keep keep keep keep keep keep
<mask> "errors" <mask> "fmt" <mask> "io" <mask> "io/ioutil" <mask> "net/http" <mask> "os" <mask> "path" <mask> "path/filepath" <mask> "runtime" <mask> "strings" </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "fmt" </s> add "github.com/hmage/golibs/log" </s> remove "net" </s> add </s> remove "bufio" </s> add </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove "golang.org/x/crypto/ssh/terminal" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
helpers.go
keep keep keep add keep keep keep keep
<mask> "path" <mask> "path/filepath" <mask> "runtime" <mask> "strings" <mask> ) <mask> <mask> // ---------------------------------- <mask> // helper functions for working with files </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add "net" </s> remove "golang.org/x/crypto/ssh/terminal" </s> add </s> remove if ifaces[i].Flags&net.FlagLoopback != 0 { // it's a loopback, skip it continue } if ifaces[i].Flags&net.FlagBroadcast == 0 { // this interface doesn't support broadcast, skip it continue } if ifaces[i].Flags&net.FlagPointToPoint != 0 { // this interface is ppp, don't do dhcp over it continue } iface := responseInterface{ Name: ifaces[i].Name, MTU: ifaces[i].MTU, HardwareAddr: ifaces[i].HardwareAddr.String(), } addrs, errAddrs := ifaces[i].Addrs() if errAddrs != nil { httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs) return } for _, addr := range addrs { iface.Addresses = append(iface.Addresses, addr.String()) } if len(iface.Addresses) == 0 { // this interface has no addresses, skip it continue } response[ifaces[i].Name] = iface </s> add response[ifaces[i].Name] = ifaces[i] </s> remove // TODO: replace mockup with actual data data.Web.IP = "192.168.104.104" data.Web.Port = 3000 data.DNS.IP = "192.168.104.104" data.DNS.Port = 53 </s> add // find an interface with an ipv4 address addr := findIPv4IfaceAddr(ifaces) if len(addr) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") return } data.Web.IP = addr data.DNS.IP = addr data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000 data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning </s> remove data := struct { Web ipport `json:"web"` DNS ipport `json:"dns"` }{} </s> add </s> remove type responseInterface struct { Name string `json:"name"` MTU int `json:"mtu"` HardwareAddr string `json:"hardware_address"` Addresses []string `json:"ip_addresses"` } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
helpers.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> handler http.Handler <mask> } <mask> <mask> func (a *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { <mask> if config.AuthName == "" || config.AuthPass == "" { <mask> a.handler.ServeHTTP(w, r) <mask> return <mask> } <mask> user, pass, ok := r.BasicAuth() <mask> if !ok || user != config.AuthName || pass != config.AuthPass { <mask> w.Header().Set("WWW-Authenticate", `Basic realm="dnsfilter"`) <mask> w.WriteHeader(http.StatusUnauthorized) <mask> w.Write([]byte("Unauthorised.\n")) <mask> return <mask> } <mask> a.handler.ServeHTTP(w, r) <mask> } <mask> <mask> func optionalAuthHandler(handler http.Handler) http.Handler { <mask> return &authHandler{handler} <mask> } </s> Initial implementation of welcome/firstrun/installer page in go backend </s> add config.firstRun = false config.BindHost = newSettings.Web.IP config.BindPort = newSettings.Web.Port config.DNS.BindHost = newSettings.DNS.IP config.DNS.Port = newSettings.DNS.Port config.AuthName = newSettings.Username config.AuthPass = newSettings.Password httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove type ipport struct { IP string `json:"ip"` Port int `json:"port"` </s> add data := firstRunData{} ifaces, err := getValidNetInterfaces() if err != nil { httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err) return } if len(ifaces) == 0 { httpError(w, http.StatusServiceUnavailable, "Couldn't find any legible interface, plase try again later") return </s> remove func promptAndGet(prompt string) (string, error) { for { fmt.Print(prompt) input, err := getInput() if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(input) != 0 { return input, nil } // try again } } func promptAndGetPassword(prompt string) (string, error) { for { fmt.Print(prompt) password, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Print("\n") if err != nil { log.Printf("Failed to get input, aborting: %s", err) return "", err } if len(password) != 0 { return string(password), nil } // try again } } func askUsernamePasswordIfPossible() error { configFile := config.getConfigFilename() _, err := os.Stat(configFile) if !os.IsNotExist(err) { // do nothing, file exists return nil } if !terminal.IsTerminal(int(os.Stdin.Fd())) { return nil // do nothing } if !terminal.IsTerminal(int(os.Stdout.Fd())) { return nil // do nothing } fmt.Printf("Would you like to set user/password for the web interface authentication (yes/no)?\n") yesno, err := promptAndGet("Please type 'yes' or 'no': ") if err != nil { return err } if yesno[0] != 'y' && yesno[0] != 'Y' { return nil } username, err := promptAndGet("Please enter the username: ") if err != nil { return err } password, err := promptAndGetPassword("Please enter the password: ") if err != nil { return err } password2, err := promptAndGetPassword("Please enter password again: ") if err != nil { return err } if password2 != password { fmt.Printf("Passwords do not match! Aborting\n") os.Exit(1) } config.AuthName = username config.AuthPass = password return nil } </s> add </s> remove newSettings := map[string]interface{}{} </s> add newSettings := firstRunData{} </s> add type ipport struct { IP string `json:"ip"` Port int `json:"port"` } type firstRunData struct { Web ipport `json:"web"` DNS ipport `json:"dns"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } </s> remove ifaces, err := net.Interfaces() </s> add ifaces, err := getValidNetInterfaces()
https://github.com/AdguardTeam/AdGuardHome/commit/302c3a767a4d296d1f8cf5d895be8af2477113ce
helpers.go
keep keep keep keep replace keep keep keep keep keep
<mask> - errcheck <mask> - govet <mask> - ineffassign <mask> - staticcheck <mask> - structcheck <mask> - unused <mask> - varcheck <mask> - bodyclose <mask> - depguard <mask> - dupl </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove // nolint (gocyclo) </s> add </s> remove // nolint(gocyclo) - we need to check each JSON field separately </s> add </s> add // In returns true if reasons include r. func (r Reason) In(reasons ...Reason) bool { for _, reason := range reasons { if r == reason { return true } } return false } </s> remove a := []uint64{} if timeUnit == Hours { for _, u := range units { a = append(a, u.NTotal) } } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := firstDayID - firstID; int(i) != len(units); i++ { sum += units[i].NTotal if id == nextDayID { a = append(a, sum) sum = 0 nextDayID += 24 </s> add statsCollector := func(numsGetter func(u *unitDB) (num uint64)) (nums []uint64) { if timeUnit == Hours { for _, u := range units { nums = append(nums, numsGetter(u)) </s> remove req := dnsConfigJSON{} js, err := jsonutil.DecodeObject(&req, r.Body) if err != nil { httpError(r, w, http.StatusBadRequest, "json.Decode: %s", err) </s> add req := dnsConfig{} dec := json.NewDecoder(r.Body) if err := dec.Decode(&req); err != nil { httpError(r, w, http.StatusBadRequest, "json Encode: %s", err) </s> remove id++ } if id <= nextDayID { a = append(a, sum) } if len(a) != int(limit/24) { log.Fatalf("len(a) != limit: %d %d", len(a), limit) } } d["dns_queries"] = a a = []uint64{} if timeUnit == Hours { for _, u := range units { a = append(a, u.NResult[RFiltered]) } } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := firstDayID - firstID; int(i) != len(units); i++ { sum += units[i].NResult[RFiltered] if id == nextDayID { a = append(a, sum) sum = 0 nextDayID += 24 </s> add } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := int(firstDayID - firstID); i != len(units); i++ { sum += numsGetter(units[i]) if id == nextDayID { nums = append(nums, sum) sum = 0 nextDayID += 24 } id++
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
.golangci.yml
keep add keep keep keep keep
<mask> } <mask> <mask> // GetConfig - get configuration <mask> func (d *Dnsfilter) GetConfig() RequestFilteringSettings { <mask> c := RequestFilteringSettings{} <mask> // d.confLock.RLock() </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove // Disabling "dupl": the algorithm of SB/PC is similar, but it uses different data // nolint:dupl func (d *Dnsfilter) checkParental(host string) (Result, error) { </s> add func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { </s> remove defer timer.LogElapsed("Parental lookup for %s", host) </s> add defer timer.LogElapsed("SafeBrowsing lookup for %s", host) </s> remove // Disabling "dupl": the algorithm of SB/PC is similar, but it uses different data // nolint:dupl func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("SafeBrowsing lookup for %s", host) } result := Result{} hashes := hostnameToHashes(host) c := &sbCtx{ host: host, svc: "SafeBrowsing", hashToHost: hashes, cache: gctx.safebrowsingCache, cacheTime: d.Config.CacheTime, } // check cache match := c.getCached() if match < 0 { return result, nil } else if match > 0 { result.IsFiltered = true result.Reason = FilteredSafeBrowsing result.Rule = "adguard-malware-shavar" return result, nil </s> add func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil </s> add return check(ctx, res, d.safeBrowsingUpstream) } </s> remove return result, nil </s> add return Result{}, nil </s> remove question := c.getQuestion() log.Tracef("Parental: checking %s: %s", host, question) req := dns.Msg{} req.SetQuestion(question, dns.TypeTXT) resp, err := d.parentalUpstream.Exchange(&req) if err != nil { return result, err </s> add func (d *Dnsfilter) checkParental(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("Parental lookup for %s", host)
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/dnsfilter.go
keep add keep keep keep keep
<mask> } <mask> <mask> func (c *sbCtx) getCached() int { <mask> now := time.Now().Unix() <mask> hashesToRequest := map[[32]byte]string{} <mask> for k, v := range c.hashToHost { </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove if val != nil { expire := binary.BigEndian.Uint32(val) if now >= int64(expire) { val = nil } else { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] var hash32 [32]byte copy(hash32[:], hash[0:32]) _, found := c.hashToHost[hash32] if found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } } } if val == nil { </s> add if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { </s> remove const ( jsonTErr = iota jsonTObj jsonTStr jsonTNum jsonTBool ) // Parse JSON key-value pair // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) // Note the limitations: // . doesn't support whitespace // . doesn't support "null" // . doesn't validate boolean or number // . no proper handling of {} braces // . no handling of [] brackets // Return (key, value, type) func readJSON(ps *string) (string, string, int32) { s := *ps k := "" v := "" t := int32(jsonTErr) q1 := strings.IndexByte(s, '"') if q1 == -1 { return k, v, t } q2 := strings.IndexByte(s[q1+1:], '"') if q2 == -1 { return k, v, t } k = s[q1+1 : q1+1+q2] s = s[q1+1+q2+1:] if len(s) < 2 || s[0] != ':' { return k, v, t } if s[1] == '"' { q2 = strings.IndexByte(s[2:], '"') if q2 == -1 { return k, v, t } v = s[2 : 2+q2] t = jsonTStr s = s[2+q2+1:] } else if s[1] == '{' { t = jsonTObj s = s[1+1:] } else { sep := strings.IndexAny(s[1:], ",}") if sep == -1 { return k, v, t } v = s[1 : 1+sep] if s[1] == 't' || s[1] == 'f' { t = jsonTBool } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { t = jsonTNum } s = s[1+sep+1:] } *ps = s return k, v, t } </s> add </s> add continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 </s> remove // decodeLogEntry - decodes query log entry from a line // nolint (gocyclo) func decodeLogEntry(ent *logEntry, str string) { var b bool var i int var err error for { k, v, t := readJSON(&str) if t == jsonTErr { break } switch k { case "IP": if len(ent.IP) == 0 { ent.IP = v } case "T": ent.Time, err = time.Parse(time.RFC3339, v) case "QH": ent.QHost = v case "QT": ent.QType = v case "QC": ent.QClass = v case "CP": ent.ClientProto, err = NewClientProto(v) case "Answer": ent.Answer, err = base64.StdEncoding.DecodeString(v) case "OrigAnswer": ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v) case "IsFiltered": b, err = strconv.ParseBool(v) ent.Result.IsFiltered = b case "Rule": ent.Result.Rule = v case "FilterID": i, err = strconv.Atoi(v) ent.Result.FilterID = int64(i) case "Reason": i, err = strconv.Atoi(v) ent.Result.Reason = dnsfilter.Reason(i) case "ServiceName": ent.Result.ServiceName = v case "Upstream": ent.Upstream = v case "Elapsed": i, err = strconv.Atoi(v) ent.Elapsed = time.Duration(i) // pre-v0.99.3 compatibility: case "Question": var qstr []byte qstr, err = base64.StdEncoding.DecodeString(v) if err != nil { break } q := new(dns.Msg) err = q.Unpack(qstr) if err != nil { break } ent.QHost = q.Question[0].Name if len(ent.QHost) == 0 { break } ent.QHost = ent.QHost[:len(ent.QHost)-1] ent.QType = dns.TypeToString[q.Question[0].Qtype] ent.QClass = dns.ClassToString[q.Question[0].Qclass] case "Time": ent.Time, err = time.Parse(time.RFC3339, v) </s> add var logEntryHandlers = map[string](func(t json.Token, ent *logEntry) error){ "IP": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } if len(ent.IP) == 0 { ent.IP = v } return nil }, "T": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } var err error ent.Time, err = time.Parse(time.RFC3339, v) return err }, "QH": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } ent.QHost = v return nil }, "QT": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } ent.QType = v return nil }, "QC": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } ent.QClass = v return nil }, "CP": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } var err error ent.ClientProto, err = NewClientProto(v) return err }, "Answer": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } var err error ent.Answer, err = base64.StdEncoding.DecodeString(v) return err }, "OrigAnswer": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } var err error ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v) return err }, "IsFiltered": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } b, err := strconv.ParseBool(v) if err != nil { return err } ent.Result.IsFiltered = b return nil }, "Rule": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } ent.Result.Rule = v return nil }, "FilterID": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } i, err := strconv.Atoi(v) if err != nil { return err } ent.Result.FilterID = int64(i) return nil }, "Reason": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } i, err := strconv.Atoi(v) if err != nil { return err } ent.Result.Reason = dnsfilter.Reason(i) return nil }, "ServiceName": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil } ent.Result.ServiceName = v return nil }, "Upstream": func(t json.Token, ent *logEntry) error { v, ok := t.(string) if !ok { return nil </s> remove a2 := convertMapToArray(m, maxDomains) d["top_queried_domains"] = convertTopArray(a2) </s> add </s> remove return "" </s> add return "", nil
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> hashesToRequest := map[[32]byte]string{} <mask> for k, v := range c.hashToHost { <mask> key := k[0:2] <mask> val := c.cache.Get(key) <mask> if val != nil { <mask> expire := binary.BigEndian.Uint32(val) <mask> if now >= int64(expire) { <mask> val = nil <mask> } else { <mask> for i := 4; i < len(val); i += 32 { <mask> hash := val[i : i+32] <mask> var hash32 [32]byte <mask> copy(hash32[:], hash[0:32]) <mask> _, found := c.hashToHost[hash32] <mask> if found { <mask> log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) <mask> return 1 <mask> } <mask> } <mask> } <mask> } <mask> if val == nil { <mask> hashesToRequest[k] = v <mask> } <mask> } <mask> <mask> if len(hashesToRequest) == 0 { </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> add continue } if hash32, found := c.findInHash(val); found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 </s> add // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } </s> remove id++ } if id <= nextDayID { a = append(a, sum) } if len(a) != int(limit/24) { log.Fatalf("len(a) != limit: %d %d", len(a), limit) } } d["dns_queries"] = a a = []uint64{} if timeUnit == Hours { for _, u := range units { a = append(a, u.NResult[RFiltered]) } } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := firstDayID - firstID; int(i) != len(units); i++ { sum += units[i].NResult[RFiltered] if id == nextDayID { a = append(a, sum) sum = 0 nextDayID += 24 </s> add } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := int(firstDayID - firstID); i != len(units); i++ { sum += numsGetter(units[i]) if id == nextDayID { nums = append(nums, sum) sum = 0 nextDayID += 24 } id++ </s> remove a = append(a, u.NResult[RParental]) } } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := firstDayID - firstID; int(i) != len(units); i++ { sum += units[i].NResult[RParental] if id == nextDayID { a = append(a, sum) sum = 0 nextDayID += 24 </s> add for _, it := range pairsGetter(u) { m[it.Name] += it.Count </s> remove const ( jsonTErr = iota jsonTObj jsonTStr jsonTNum jsonTBool ) // Parse JSON key-value pair // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) // Note the limitations: // . doesn't support whitespace // . doesn't support "null" // . doesn't validate boolean or number // . no proper handling of {} braces // . no handling of [] brackets // Return (key, value, type) func readJSON(ps *string) (string, string, int32) { s := *ps k := "" v := "" t := int32(jsonTErr) q1 := strings.IndexByte(s, '"') if q1 == -1 { return k, v, t } q2 := strings.IndexByte(s[q1+1:], '"') if q2 == -1 { return k, v, t } k = s[q1+1 : q1+1+q2] s = s[q1+1+q2+1:] if len(s) < 2 || s[0] != ':' { return k, v, t } if s[1] == '"' { q2 = strings.IndexByte(s[2:], '"') if q2 == -1 { return k, v, t } v = s[2 : 2+q2] t = jsonTStr s = s[2+q2+1:] } else if s[1] == '{' { t = jsonTObj s = s[1+1:] } else { sep := strings.IndexAny(s[1:], ",}") if sep == -1 { return k, v, t } v = s[1 : 1+sep] if s[1] == 't' || s[1] == 'f' { t = jsonTBool } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { t = jsonTNum } s = s[1+sep+1:] } *ps = s return k, v, t } </s> add </s> remove id++ } if id <= nextDayID { a = append(a, sum) } } d["blocked_filtering"] = a a = []uint64{} if timeUnit == Hours { for _, u := range units { a = append(a, u.NResult[RSafeBrowsing]) } } else { var sum uint64 id := firstDayID nextDayID := firstDayID + 24 for i := firstDayID - firstID; int(i) != len(units); i++ { sum += units[i].NResult[RSafeBrowsing] if id == nextDayID { a = append(a, sum) sum = 0 nextDayID += 24 </s> add if id <= nextDayID { nums = append(nums, sum)
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep keep keep add keep keep keep keep keep
<mask> key := k[0:2] <mask> val := c.cache.Get(key) <mask> if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { <mask> hashesToRequest[k] = v <mask> } <mask> } <mask> <mask> if len(hashesToRequest) == 0 { <mask> log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host) </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove if val != nil { expire := binary.BigEndian.Uint32(val) if now >= int64(expire) { val = nil } else { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] var hash32 [32]byte copy(hash32[:], hash[0:32]) _, found := c.hashToHost[hash32] if found { log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32) return 1 } } } } if val == nil { </s> add if val == nil || now >= int64(binary.BigEndian.Uint32(val)) { </s> add // findInHash returns 32-byte hash if it's found in hashToHost. func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) { for i := 4; i < len(val); i += 32 { hash := val[i : i+32] copy(hash32[:], hash[0:32]) _, found = c.hashToHost[hash32] if found { return hash32, found } } return [32]byte{}, false } </s> remove const ( jsonTErr = iota jsonTObj jsonTStr jsonTNum jsonTBool ) // Parse JSON key-value pair // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) // Note the limitations: // . doesn't support whitespace // . doesn't support "null" // . doesn't validate boolean or number // . no proper handling of {} braces // . no handling of [] brackets // Return (key, value, type) func readJSON(ps *string) (string, string, int32) { s := *ps k := "" v := "" t := int32(jsonTErr) q1 := strings.IndexByte(s, '"') if q1 == -1 { return k, v, t } q2 := strings.IndexByte(s[q1+1:], '"') if q2 == -1 { return k, v, t } k = s[q1+1 : q1+1+q2] s = s[q1+1+q2+1:] if len(s) < 2 || s[0] != ':' { return k, v, t } if s[1] == '"' { q2 = strings.IndexByte(s[2:], '"') if q2 == -1 { return k, v, t } v = s[2 : 2+q2] t = jsonTStr s = s[2+q2+1:] } else if s[1] == '{' { t = jsonTObj s = s[1+1:] } else { sep := strings.IndexAny(s[1:], ",}") if sep == -1 { return k, v, t } v = s[1 : 1+sep] if s[1] == 't' || s[1] == 'f' { t = jsonTBool } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { t = jsonTNum } s = s[1+sep+1:] } *ps = s return k, v, t } </s> add </s> remove // redirect to login page if not authenticated ok := false cookie, err := r.Cookie(sessionCookieName) if glProcessCookie(r) { log.Debug("Auth: authentification was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.CheckSession(cookie.Value) if r == 0 { ok = true } else if r < 0 { log.Debug("Auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { log.Info("Auth: invalid Basic Authorization value") } } } if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("Auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } } else { w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) } </s> add if optionalAuthThird(w, r) { </s> remove // nolint(gocyclo) </s> add // optionalAuthThird return true if user should authenticate first. func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false // redirect to login page if not authenticated ok := false cookie, err := r.Cookie(sessionCookieName) if glProcessCookie(r) { log.Debug("Auth: authentification was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.CheckSession(cookie.Value) if r == 0 { ok = true } else if r < 0 { log.Debug("Auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { log.Info("Auth: invalid Basic Authorization value") } } } if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("Auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } } else { w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) } authFirst = true } return authFirst } </s> remove sess := getSession(&u) </s> add sess, err := getSession(&u) if err != nil { return "", err }
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep replace keep keep keep
<mask> } <mask> <mask> // Disabling "dupl": the algorithm of SB/PC is similar, but it uses different data <mask> // nolint:dupl <mask> func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { <mask> if log.GetLevel() >= log.DEBUG { <mask> timer := log.StartTimer() <mask> defer timer.LogElapsed("SafeBrowsing lookup for %s", host) <mask> } <mask> <mask> result := Result{} <mask> hashes := hostnameToHashes(host) <mask> <mask> c := &sbCtx{ <mask> host: host, <mask> svc: "SafeBrowsing", <mask> hashToHost: hashes, <mask> cache: gctx.safebrowsingCache, <mask> cacheTime: d.Config.CacheTime, <mask> } <mask> <mask> // check cache <mask> match := c.getCached() <mask> if match < 0 { <mask> return result, nil <mask> } else if match > 0 { <mask> result.IsFiltered = true <mask> result.Reason = FilteredSafeBrowsing <mask> result.Rule = "adguard-malware-shavar" <mask> return result, nil <mask> } <mask> <mask> question := c.getQuestion() <mask> log.Tracef("SafeBrowsing: checking %s: %s", host, question) <mask> <mask> req := dns.Msg{} <mask> req.SetQuestion(question, dns.TypeTXT) </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271.
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep keep replace replace replace keep replace keep keep keep keep
<mask> log.Tracef("SafeBrowsing: checking %s: %s", host, question) <mask> <mask> req := dns.Msg{} <mask> req.SetQuestion(question, dns.TypeTXT) <mask> resp, err := d.safeBrowsingUpstream.Exchange(&req) <mask> if err != nil { <mask> return result, err <mask> } <mask> <mask> matched, receivedHashes := c.processTXT(resp) <mask> if matched { </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove log.Tracef("SafeBrowsing: checking %s: %s", host, question) </s> add </s> remove question := c.getQuestion() log.Tracef("Parental: checking %s: %s", host, question) req := dns.Msg{} req.SetQuestion(question, dns.TypeTXT) resp, err := d.parentalUpstream.Exchange(&req) if err != nil { return result, err </s> add func (d *Dnsfilter) checkParental(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("Parental lookup for %s", host) </s> remove matched, receivedHashes := c.processTXT(resp) if matched { result.IsFiltered = true result.Reason = FilteredParental result.Rule = "parental CATEGORY_BLACKLISTED" </s> add ctx := &sbCtx{ host: host, svc: "Parental", cache: gctx.parentalCache, cacheTime: d.Config.CacheTime, </s> add c.storeCache(receivedHashes) </s> remove result.IsFiltered = true result.Reason = FilteredSafeBrowsing result.Rule = "adguard-malware-shavar" </s> add return r, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep add keep keep keep keep keep
<mask> <mask> matched, receivedHashes := c.processTXT(resp) <mask> if matched { <mask> return r, nil <mask> } <mask> <mask> return Result{}, nil </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove result.IsFiltered = true result.Reason = FilteredSafeBrowsing result.Rule = "adguard-malware-shavar" </s> add return r, nil </s> remove return result, err </s> add return Result{}, err </s> remove matched, receivedHashes := c.processTXT(resp) if matched { result.IsFiltered = true result.Reason = FilteredParental result.Rule = "parental CATEGORY_BLACKLISTED" </s> add ctx := &sbCtx{ host: host, svc: "Parental", cache: gctx.parentalCache, cacheTime: d.Config.CacheTime, </s> remove question := c.getQuestion() log.Tracef("Parental: checking %s: %s", host, question) req := dns.Msg{} req.SetQuestion(question, dns.TypeTXT) resp, err := d.parentalUpstream.Exchange(&req) if err != nil { return result, err </s> add func (d *Dnsfilter) checkParental(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("Parental lookup for %s", host) </s> remove req := dns.Msg{} req.SetQuestion(question, dns.TypeTXT) resp, err := d.safeBrowsingUpstream.Exchange(&req) </s> add log.Tracef("%s: checking %s: %s", c.svc, c.host, question) req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT) resp, err := u.Exchange(req) </s> remove // Disabling "dupl": the algorithm of SB/PC is similar, but it uses different data // nolint:dupl func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("SafeBrowsing lookup for %s", host) } result := Result{} hashes := hostnameToHashes(host) c := &sbCtx{ host: host, svc: "SafeBrowsing", hashToHost: hashes, cache: gctx.safebrowsingCache, cacheTime: d.Config.CacheTime, } // check cache match := c.getCached() if match < 0 { return result, nil } else if match > 0 { result.IsFiltered = true result.Reason = FilteredSafeBrowsing result.Rule = "adguard-malware-shavar" return result, nil </s> add func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) { c.hashToHost = hostnameToHashes(c.host) switch c.getCached() { case -1: return Result{}, nil case 1: return r, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go
keep keep keep replace replace replace keep replace keep keep keep
<mask> <mask> matched, receivedHashes := c.processTXT(resp) <mask> if matched { <mask> result.IsFiltered = true <mask> result.Reason = FilteredSafeBrowsing <mask> result.Rule = "adguard-malware-shavar" <mask> } <mask> c.storeCache(receivedHashes) <mask> <mask> return result, nil <mask> } </s> Pull request: 2271 handle nolint Merge in DNS/adguard-home from 2271-handle-nolint to master Closes #2271. Squashed commit of the following: commit fde5c8795ac79e1f7d02ba8c8e369b5a724a000e Merge: fc2acd898 642dcd647 Author: Eugene Burkov <[email protected]> Date: Fri Nov 20 17:12:28 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit fc2acd89871de08c39e80ace9e5bb8a7acb7afba Author: Eugene Burkov <[email protected]> Date: Tue Nov 17 11:55:29 2020 +0300 dnsforward: fix test output strings commit c4ebae6ea9c293bad239519c44ca5a6c576bb921 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 22:43:20 2020 +0300 dnsfilter: make package pass tests commit f2d98c6acabd8977f3b1b361987eaa31eb6eb9ad Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 20:05:00 2020 +0300 querylog: make decoding pass tests commit ab5850d24c50d53b8393f2de448cc340241351d7 Merge: 6ed2066bf 8a9c6e8a0 Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 19:48:31 2020 +0300 Merge branch 'master' into 2271-handle-nolint commit 6ed2066bf567e13dd14cfa16fc7b109b59fa39ef Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 18:13:45 2020 +0300 home: fix tests naming commit af691081fb02b7500a746b16492f01f7f9befe9a Author: Eugene Burkov <[email protected]> Date: Mon Nov 16 12:15:49 2020 +0300 home: impove code quality commit 2914cd3cd23ef2a1964116baab9187d89b377f86 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 15:46:39 2020 +0300 * querylog: remove useless check commit 9996840650e784ccc76d1f29964560435ba27dc7 Author: Eugene Burkov <[email protected]> Date: Wed Nov 11 13:18:34 2020 +0300 * all: fix noticed defects commit 2b15293e59337f70302fbc0db81ebb26bee0bed2 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 20:15:53 2020 +0300 * stats: remove last nolint directive commit b2e1ddf7b58196a2fdbf879f084edb41ca1aa1eb Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:35:41 2020 +0300 * all: remove another nolint directive commit c6fc5cfcc9c95ab9e570a95ab41c3e5c0125e62e Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 18:11:28 2020 +0300 * querylog: remove nolint directive commit 226ddbf2c92f737f085b44a4ddf6daec7b602153 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:35:26 2020 +0300 * home: remove nolint directive commit 2ea3086ad41e9003282add7e996ae722d72d878b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 16:13:57 2020 +0300 * home: reduce cyclomatic complexity of run function commit f479b480c48e0bb832ddef8f57586f56b8a55bab Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 15:35:46 2020 +0300 * home: use crypto/rand instead of math/rand commit a28d4a53e3b930136b036606fc7e78404f1d208b Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 14:11:07 2020 +0300 * dnsforward: remove gocyclo nolint directive commit 64a0a324cc2b20614ceec3ccc6505e960fe526e9 Author: Eugene Burkov <[email protected]> Date: Tue Nov 10 11:45:49 2020 +0300 all *: remove some nolint directives Updates #2271. </s> remove matched, receivedHashes := c.processTXT(resp) if matched { result.IsFiltered = true result.Reason = FilteredParental result.Rule = "parental CATEGORY_BLACKLISTED" </s> add ctx := &sbCtx{ host: host, svc: "Parental", cache: gctx.parentalCache, cacheTime: d.Config.CacheTime, </s> remove return result, err </s> add return Result{}, err </s> remove question := c.getQuestion() log.Tracef("Parental: checking %s: %s", host, question) req := dns.Msg{} req.SetQuestion(question, dns.TypeTXT) resp, err := d.parentalUpstream.Exchange(&req) if err != nil { return result, err </s> add func (d *Dnsfilter) checkParental(host string) (Result, error) { if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("Parental lookup for %s", host) </s> add c.storeCache(receivedHashes) </s> remove c.storeCache(receivedHashes) return result, err </s> add res := Result{ IsFiltered: true, Reason: FilteredParental, Rule: "parental CATEGORY_BLACKLISTED", } return check(ctx, res, d.parentalUpstream)
https://github.com/AdguardTeam/AdGuardHome/commit/3045da1742ee0e75392de1623900d7d88b08f0b4
internal/dnsfilter/sb_pc.go