2019-08-26 11:54:38 +03:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2019-09-27 18:58:57 +03:00
|
|
|
"net/http"
|
2019-08-26 11:54:38 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
// QueryLog - main interface
|
|
|
|
type QueryLog interface {
|
2020-01-16 14:25:40 +03:00
|
|
|
Start()
|
|
|
|
|
2019-09-04 14:12:00 +03:00
|
|
|
// Close query log object
|
2019-08-26 11:54:38 +03:00
|
|
|
Close()
|
|
|
|
|
2019-09-04 14:12:00 +03:00
|
|
|
// Add a log entry
|
2019-11-21 16:13:19 +03:00
|
|
|
Add(params AddParams)
|
2019-09-04 14:12:00 +03:00
|
|
|
|
2019-09-27 18:58:57 +03:00
|
|
|
// WriteDiskConfig - write configuration
|
2020-05-28 15:29:36 +03:00
|
|
|
WriteDiskConfig(c *Config)
|
2019-08-26 11:54:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config - configuration object
|
|
|
|
type Config struct {
|
2020-05-28 15:29:36 +03:00
|
|
|
Enabled bool // enable the module
|
|
|
|
FileEnabled bool // write logs to file
|
2020-03-03 20:21:53 +03:00
|
|
|
BaseDir string // directory where log file is stored
|
|
|
|
Interval uint32 // interval to rotate logs (in days)
|
|
|
|
MemSize uint32 // number of entries kept in memory before they are flushed to disk
|
|
|
|
AnonymizeClientIP bool // anonymize clients' IP addresses
|
2019-09-27 18:58:57 +03:00
|
|
|
|
|
|
|
// Called when the configuration is changed by HTTP request
|
|
|
|
ConfigModified func()
|
|
|
|
|
|
|
|
// Register an HTTP handler
|
|
|
|
HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request))
|
2019-08-26 11:54:38 +03:00
|
|
|
}
|
|
|
|
|
2019-11-21 16:13:19 +03:00
|
|
|
// AddParams - parameters for Add()
|
|
|
|
type AddParams struct {
|
2020-05-29 11:15:22 +03:00
|
|
|
Question *dns.Msg
|
|
|
|
Answer *dns.Msg // The response we sent to the client (optional)
|
|
|
|
OrigAnswer *dns.Msg // The response from an upstream server (optional)
|
|
|
|
Result *dnsfilter.Result // Filtering result (optional)
|
|
|
|
Elapsed time.Duration // Time spent for processing the request
|
|
|
|
ClientIP net.IP
|
|
|
|
Upstream string // Upstream server URL
|
2020-05-29 11:46:37 +03:00
|
|
|
ClientProto string // Protocol for the client connection: "" (plain), "doh", "dot"
|
2019-11-21 16:13:19 +03:00
|
|
|
}
|
|
|
|
|
2019-09-04 14:12:00 +03:00
|
|
|
// New - create a new instance of the query log
|
2019-08-26 11:54:38 +03:00
|
|
|
func New(conf Config) QueryLog {
|
|
|
|
return newQueryLog(conf)
|
|
|
|
}
|