2019-08-26 08:54:38 +00:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2019-09-27 15:58:57 +00:00
|
|
|
"net/http"
|
2019-08-26 08:54:38 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
2019-09-27 15:58:57 +00:00
|
|
|
// DiskConfig - configuration settings that are stored on disk
|
|
|
|
type DiskConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
Interval uint32
|
2019-11-08 09:31:50 +00:00
|
|
|
MemSize uint32
|
2019-09-27 15:58:57 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 08:54:38 +00:00
|
|
|
// QueryLog - main interface
|
|
|
|
type QueryLog interface {
|
2019-09-04 11:12:00 +00:00
|
|
|
// Close query log object
|
2019-08-26 08:54:38 +00:00
|
|
|
Close()
|
|
|
|
|
2019-09-04 11:12:00 +00:00
|
|
|
// Add a log entry
|
2019-11-19 11:09:10 +00:00
|
|
|
Add(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip net.IP, upstream string)
|
2019-09-04 11:12:00 +00:00
|
|
|
|
2019-09-27 15:58:57 +00:00
|
|
|
// WriteDiskConfig - write configuration
|
|
|
|
WriteDiskConfig(dc *DiskConfig)
|
2019-08-26 08:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config - configuration object
|
|
|
|
type Config struct {
|
2019-09-27 15:58:57 +00:00
|
|
|
Enabled bool
|
2019-08-26 08:54:38 +00:00
|
|
|
BaseDir string // directory where log file is stored
|
2019-09-27 15:58:57 +00:00
|
|
|
Interval uint32 // interval to rotate logs (in days)
|
2019-11-08 09:31:50 +00:00
|
|
|
MemSize uint32 // number of entries kept in memory before they are flushed to disk
|
2019-09-27 15:58:57 +00: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 08:54:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 11:12:00 +00:00
|
|
|
// New - create a new instance of the query log
|
2019-08-26 08:54:38 +00:00
|
|
|
func New(conf Config) QueryLog {
|
|
|
|
return newQueryLog(conf)
|
|
|
|
}
|