* querylog: refactor: move HTTP handlers to querylog/

This commit is contained in:
Simon Zolin
2019-09-27 18:58:57 +03:00
parent f4451dca7b
commit 90db91b0fd
11 changed files with 276 additions and 246 deletions

View File

@@ -2,58 +2,45 @@ package querylog
import (
"net"
"net/http"
"time"
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/miekg/dns"
)
// DiskConfig - configuration settings that are stored on disk
type DiskConfig struct {
Enabled bool
Interval uint32
}
// QueryLog - main interface
type QueryLog interface {
// Close query log object
Close()
// Set new configuration at runtime
// Currently only 'Interval' field is supported.
Configure(conf Config)
// Add a log entry
Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string)
// Get log entries
GetData(params GetDataParams) []map[string]interface{}
// Clear memory buffer and remove log files
Clear()
// WriteDiskConfig - write configuration
WriteDiskConfig(dc *DiskConfig)
}
// Config - configuration object
type Config struct {
Enabled bool
BaseDir string // directory where log file is stored
Interval uint32 // interval to rotate logs (in hours)
Interval uint32 // interval to rotate logs (in days)
// Called when the configuration is changed by HTTP request
ConfigModified func()
// Register an HTTP handler
HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request))
}
// New - create a new instance of the query log
func New(conf Config) QueryLog {
return newQueryLog(conf)
}
// GetDataParams - parameters for GetData()
type GetDataParams struct {
OlderThan time.Time // return entries that are older than this value
Domain string // filter by domain name in question
Client string // filter by client IP
QuestionType uint16 // filter by question type
ResponseStatus ResponseStatusType // filter by response status
StrictMatchDomain bool // if Domain value must be matched strictly
StrictMatchClient bool // if Client value must be matched strictly
}
// ResponseStatusType - response status
type ResponseStatusType int32
// Response status constants
const (
ResponseStatusAll ResponseStatusType = iota + 1
ResponseStatusFiltered
)