Merge branch 'master' into fix/596

This commit is contained in:
Aleksey Dmitrevskiy 2019-02-27 18:56:36 +03:00
commit 967a1e6b87
24 changed files with 83 additions and 81 deletions

View File

@ -64,7 +64,7 @@ matrix:
skip_cleanup: true
- name: docker
if: type != pull_request AND (branch = master OR tag = true)
if: type != pull_request AND (branch = master OR tag IS present)
go:
- 1.11.x
os:

30
app.go
View File

@ -3,7 +3,6 @@ package main
import (
"crypto/tls"
"fmt"
stdlog "log"
"net"
"net/http"
"os"
@ -15,9 +14,8 @@ import (
"syscall"
"time"
"github.com/AdguardTeam/golibs/log"
"github.com/gobuffalo/packr"
"github.com/hmage/golibs/log"
)
// VersionString will be set through ldflags, contains current version
@ -73,9 +71,9 @@ func run(args options) {
// print the first message after logger is configured
log.Printf("AdGuard Home, version %s\n", VersionString)
log.Tracef("Current working directory is %s", config.ourWorkingDir)
log.Debug("Current working directory is %s", config.ourWorkingDir)
if args.runningAsService {
log.Printf("AdGuard Home is running as a service")
log.Info("AdGuard Home is running as a service")
}
config.firstRun = detectFirstRun()
@ -110,7 +108,7 @@ func run(args options) {
err = filter.load()
if err != nil {
// This is okay for the first start, the filter will be loaded later
log.Printf("Couldn't load filter %d contents due to %s", filter.ID, err)
log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err)
// clear LastUpdated so it gets fetched right away
}
@ -161,7 +159,7 @@ func run(args options) {
// add handlers for /install paths, we only need them when we're not configured yet
if config.firstRun {
log.Printf("This is the first launch of AdGuard Home, redirecting everything to /install.html ")
log.Info("This is the first launch of AdGuard Home, redirecting everything to /install.html ")
http.Handle("/install.html", preInstallHandler(http.FileServer(box)))
registerInstallHandlers()
}
@ -263,7 +261,11 @@ func configureLogger(args options) {
ls.LogFile = args.logFile
}
log.Verbose = ls.Verbose
level := log.INFO
if ls.Verbose {
level = log.DEBUG
}
log.SetLevel(level)
if args.runningAsService && ls.LogFile == "" && runtime.GOOS == "windows" {
// When running as a Windows service, use eventlog by default if nothing else is configured
@ -287,20 +289,20 @@ func configureLogger(args options) {
if err != nil {
log.Fatalf("cannot create a log file: %s", err)
}
stdlog.SetOutput(file)
log.SetOutput(file)
}
}
func cleanup() {
log.Printf("Stopping AdGuard Home")
log.Info("Stopping AdGuard Home")
err := stopDNSServer()
if err != nil {
log.Printf("Couldn't stop DNS server: %s", err)
log.Error("Couldn't stop DNS server: %s", err)
}
err = stopDHCPServer()
if err != nil {
log.Printf("Couldn't stop DHCP server: %s", err)
log.Error("Couldn't stop DHCP server: %s", err)
}
}
@ -373,7 +375,7 @@ func loadOptions() options {
if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) {
if opt.callbackWithValue != nil {
if i+1 >= len(os.Args) {
log.Printf("ERROR: Got %s without argument\n", v)
log.Error("Got %s without argument\n", v)
os.Exit(64)
}
i++
@ -386,7 +388,7 @@ func loadOptions() options {
}
}
if !knownParam {
log.Printf("ERROR: unknown option %v\n", v)
log.Error("unknown option %v\n", v)
printHelp()
os.Exit(64)
}

View File

@ -215,7 +215,7 @@
"encryption_config_saved": "Encryption config saved",
"encryption_server": "Server name",
"encryption_server_enter": "Enter your domain name",
"encryption_server_desc": "In order to use HTTPS, you need yo enter the server name that matches your SSL certificate.",
"encryption_server_desc": "In order to use HTTPS, you need to enter the server name that matches your SSL certificate.",
"encryption_redirect": "Redirect to HTTPS automatically",
"encryption_redirect_desc": "If checked, AdGuard Home will automatically redirect you from HTTP to HTTPS addresses.",
"encryption_https": "HTTPS port",
@ -247,4 +247,4 @@
"form_error_password": "Password mismatched",
"reset_settings": "Reset settings",
"update_announcement": "AdGuard Home {{version}} is now available! <0>Click here</0> for more info."
}
}

View File

@ -10,7 +10,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/dhcpd"
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
yaml "gopkg.in/yaml.v2"
)
@ -153,7 +153,7 @@ func getLogSettings() logSettings {
}
err = yaml.Unmarshal(yamlFile, &l)
if err != nil {
log.Printf("Couldn't get logging settings from the configuration: %s", err)
log.Error("Couldn't get logging settings from the configuration: %s", err)
}
return l
}
@ -161,19 +161,19 @@ func getLogSettings() logSettings {
// parseConfig loads configuration from the YAML file
func parseConfig() error {
configFile := config.getConfigFilename()
log.Printf("Reading config file: %s", configFile)
log.Debug("Reading config file: %s", configFile)
yamlFile, err := readConfigFile()
if err != nil {
log.Printf("Couldn't read config file: %s", err)
log.Error("Couldn't read config file: %s", err)
return err
}
if yamlFile == nil {
log.Printf("YAML file doesn't exist, skipping it")
log.Error("YAML file doesn't exist, skipping it")
return nil
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
log.Printf("Couldn't parse config file: %s", err)
log.Error("Couldn't parse config file: %s", err)
return err
}
@ -200,19 +200,19 @@ func (c *configuration) write() error {
c.Lock()
defer c.Unlock()
if config.firstRun {
log.Tracef("Silently refusing to write config because first run and not configured yet")
log.Debug("Silently refusing to write config because first run and not configured yet")
return nil
}
configFile := config.getConfigFilename()
log.Tracef("Writing YAML file: %s", configFile)
log.Debug("Writing YAML file: %s", configFile)
yamlText, err := yaml.Marshal(&config)
if err != nil {
log.Printf("Couldn't generate YAML file: %s", err)
log.Error("Couldn't generate YAML file: %s", err)
return err
}
err = safeWriteFile(configFile, yamlText)
if err != nil {
log.Printf("Couldn't save YAML config: %s", err)
log.Error("Couldn't save YAML config: %s", err)
return err
}
@ -222,14 +222,14 @@ func (c *configuration) write() error {
func writeAllConfigs() error {
err := config.write()
if err != nil {
log.Printf("Couldn't write config: %s", err)
log.Error("Couldn't write config: %s", err)
return err
}
userFilter := userFilter()
err = userFilter.save()
if err != nil {
log.Printf("Couldn't save the user filter: %s", err)
log.Error("Couldn't save the user filter: %s", err)
return err
}

View File

@ -25,7 +25,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/joomcode/errorx"
"github.com/miekg/dns"
govalidator "gopkg.in/asaskevich/govalidator.v4"
@ -57,7 +57,7 @@ func returnOK(w http.ResponseWriter) {
func httpError(w http.ResponseWriter, code int, format string, args ...interface{}) {
text := fmt.Sprintf(format, args...)
log.Println(text)
log.Info(text)
http.Error(w, text, code)
}
@ -67,7 +67,7 @@ func httpError(w http.ResponseWriter, code int, format string, args ...interface
func writeAllConfigsAndReloadDNS() error {
err := writeAllConfigs()
if err != nil {
log.Printf("Couldn't write all configs: %s", err)
log.Error("Couldn't write all configs: %s", err)
return err
}
return reconfigureDNSServer()
@ -388,7 +388,7 @@ func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
for _, host := range hosts {
err = checkDNS(host)
if err != nil {
log.Println(err)
log.Info("%v", err)
result[host] = err.Error()
} else {
result[host] = "OK"
@ -409,7 +409,7 @@ func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
}
func checkDNS(input string) error {
log.Printf("Checking if DNS %s works...", input)
log.Debug("Checking if DNS %s works...", input)
u, err := upstream.AddressToUpstream(input, upstream.Options{Timeout: dnsforward.DefaultTimeout})
if err != nil {
return fmt.Errorf("failed to choose upstream for %s: %s", input, err)
@ -434,7 +434,7 @@ func checkDNS(input string) error {
}
}
log.Printf("DNS %s works OK", input)
log.Debug("DNS %s works OK", input)
return nil
}

View File

@ -10,7 +10,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/dhcpd"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/joomcode/errorx"
)
@ -60,7 +60,7 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
if !newconfig.Enabled {
err := dhcpServer.Stop()
if err != nil {
log.Printf("failed to stop the DHCP server: %s", err)
log.Error("failed to stop the DHCP server: %s", err)
}
}
config.DHCP = newconfig
@ -131,7 +131,7 @@ func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
errorText := fmt.Sprintf("failed to read request body: %s", err)
log.Println(errorText)
log.Error(errorText)
http.Error(w, errorText, http.StatusBadRequest)
return
}
@ -139,7 +139,7 @@ func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
interfaceName := strings.TrimSpace(string(body))
if interfaceName == "" {
errorText := fmt.Sprintf("empty interface name specified")
log.Println(errorText)
log.Error(errorText)
http.Error(w, errorText, http.StatusBadRequest)
return
}

View File

@ -9,7 +9,7 @@ import (
"os"
"time"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/krolaw/dhcp4"
)

View File

@ -7,7 +7,7 @@ import (
"sync"
"time"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/krolaw/dhcp4"
)

View File

@ -4,7 +4,7 @@ import (
"fmt"
"net"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/joomcode/errorx"
)

View File

@ -8,7 +8,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/dhcpd"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/krolaw/dhcp4"
)

2
dns.go
View File

@ -8,7 +8,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/dnsforward"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/joomcode/errorx"
)

View File

@ -17,7 +17,7 @@ import (
"time"
"github.com/bluele/gcache"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/net/publicsuffix"
)

View File

@ -18,7 +18,7 @@ import (
"os"
"runtime"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/shirou/gopsutil/process"
"go.uber.org/goleak"
)

View File

@ -13,7 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/joomcode/errorx"
"github.com/miekg/dns"
)

View File

@ -10,7 +10,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
)

View File

@ -9,8 +9,8 @@ import (
"sync"
"time"
"github.com/AdguardTeam/golibs/log"
"github.com/go-test/deep"
"github.com/hmage/golibs/log"
)
var (
@ -28,7 +28,7 @@ func (l *queryLog) flushLogBuffer() error {
l.logBufferLock.Unlock()
err := l.flushToFile(flushBuffer)
if err != nil {
log.Printf("Saving querylog to file failed: %s", err)
log.Error("Saving querylog to file failed: %s", err)
return err
}
return nil
@ -46,17 +46,17 @@ func (l *queryLog) flushToFile(buffer []*logEntry) error {
for _, entry := range buffer {
err := e.Encode(entry)
if err != nil {
log.Printf("Failed to marshal entry: %s", err)
log.Error("Failed to marshal entry: %s", err)
return err
}
}
elapsed := time.Since(start)
log.Printf("%d elements serialized via json in %v: %d kB, %v/entry, %v/entry", len(buffer), elapsed, b.Len()/1024, float64(b.Len())/float64(len(buffer)), elapsed/time.Duration(len(buffer)))
log.Debug("%d elements serialized via json in %v: %d kB, %v/entry, %v/entry", len(buffer), elapsed, b.Len()/1024, float64(b.Len())/float64(len(buffer)), elapsed/time.Duration(len(buffer)))
err := checkBuffer(buffer, b)
if err != nil {
log.Printf("failed to check buffer: %s", err)
log.Error("failed to check buffer: %s", err)
return err
}
@ -73,13 +73,13 @@ func (l *queryLog) flushToFile(buffer []*logEntry) error {
_, err = zw.Write(b.Bytes())
if err != nil {
log.Printf("Couldn't compress to gzip: %s", err)
log.Error("Couldn't compress to gzip: %s", err)
zw.Close()
return err
}
if err = zw.Close(); err != nil {
log.Printf("Couldn't close gzip writer: %s", err)
log.Error("Couldn't close gzip writer: %s", err)
return err
}
} else {
@ -90,18 +90,18 @@ func (l *queryLog) flushToFile(buffer []*logEntry) error {
defer fileWriteLock.Unlock()
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Printf("failed to create file \"%s\": %s", filename, err)
log.Error("failed to create file \"%s\": %s", filename, err)
return err
}
defer f.Close()
n, err := f.Write(zb.Bytes())
if err != nil {
log.Printf("Couldn't write to file: %s", err)
log.Error("Couldn't write to file: %s", err)
return err
}
log.Printf("ok \"%s\": %v bytes written", filename, n)
log.Debug("ok \"%s\": %v bytes written", filename, n)
return nil
}
@ -115,21 +115,21 @@ func checkBuffer(buffer []*logEntry, b bytes.Buffer) error {
entry := &logEntry{}
err := d.Decode(entry)
if err != nil {
log.Printf("Failed to decode: %s", err)
log.Error("Failed to decode: %s", err)
return err
}
if diff := deep.Equal(entry, buffer[i]); diff != nil {
log.Printf("decoded buffer differs: %s", diff)
log.Error("decoded buffer differs: %s", diff)
return fmt.Errorf("decoded buffer differs: %s", diff)
}
i++
}
if i != l {
err := fmt.Errorf("check fail: %d vs %d entries", l, i)
log.Print(err)
log.Error("%v", err)
return err
}
log.Printf("check ok: %d entries", i)
log.Debug("check ok: %d entries", i)
return nil
}
@ -150,11 +150,11 @@ func (l *queryLog) rotateQueryLog() error {
err := os.Rename(from, to)
if err != nil {
log.Printf("Failed to rename querylog: %s", err)
log.Error("Failed to rename querylog: %s", err)
return err
}
log.Printf("Rotated from %s to %s successfully", from, to)
log.Debug("Rotated from %s to %s successfully", from, to)
return nil
}
@ -163,7 +163,7 @@ func (l *queryLog) periodicQueryLogRotate() {
for range time.Tick(queryLogRotationPeriod) {
err := l.rotateQueryLog()
if err != nil {
log.Printf("Failed to rotate querylog: %s", err)
log.Error("Failed to rotate querylog: %s", err)
// do nothing, continue rotating
}
}
@ -198,7 +198,7 @@ func (l *queryLog) genericLoader(onEntry func(entry *logEntry) error, needMore f
f, err := os.Open(file)
if err != nil {
log.Printf("Failed to open file \"%s\": %s", file, err)
log.Error("Failed to open file \"%s\": %s", file, err)
// try next file
continue
}
@ -209,7 +209,7 @@ func (l *queryLog) genericLoader(onEntry func(entry *logEntry) error, needMore f
if enableGzip {
zr, err := gzip.NewReader(f)
if err != nil {
log.Printf("Failed to create gzip reader: %s", err)
log.Error("Failed to create gzip reader: %s", err)
continue
}
defer zr.Close()
@ -231,7 +231,7 @@ func (l *queryLog) genericLoader(onEntry func(entry *logEntry) error, needMore f
var entry logEntry
err := d.Decode(&entry)
if err != nil {
log.Printf("Failed to decode: %s", err)
log.Error("Failed to decode: %s", err)
// next entry can be fine, try more
continue
}
@ -260,7 +260,7 @@ func (l *queryLog) genericLoader(onEntry func(entry *logEntry) error, needMore f
perunit = elapsed / time.Duration(i)
avg = sum / time.Duration(i)
}
log.Printf("file \"%s\": read %d entries in %v, %v/entry, %v over %v, %v avg", file, i, elapsed, perunit, over, max, avg)
log.Debug("file \"%s\": read %d entries in %v, %v/entry, %v over %v, %v avg", file, i, elapsed, perunit, over, max, avg)
}
return nil
}

View File

@ -10,7 +10,7 @@ import (
"time"
"github.com/bluele/gcache"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
)

View File

@ -12,7 +12,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
)
var (

4
go.mod
View File

@ -1,13 +1,13 @@
module github.com/AdguardTeam/AdGuardHome
require (
github.com/AdguardTeam/dnsproxy v0.11.1
github.com/AdguardTeam/dnsproxy v0.11.2
github.com/AdguardTeam/golibs v0.1.0
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect
github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-test/deep v1.0.1
github.com/gobuffalo/packr v1.19.0
github.com/hmage/golibs v0.0.0-20190121112702-20153bd03c24
github.com/joomcode/errorx v0.1.0
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b

8
go.sum
View File

@ -1,5 +1,7 @@
github.com/AdguardTeam/dnsproxy v0.11.1 h1:qO5VH0GYF9vdksQRG8frEfJ+CJjsPBwuct8FH6Mij7o=
github.com/AdguardTeam/dnsproxy v0.11.1/go.mod h1:lEi2srAWwfSQWoy8GeZR6lwS+FSMoiZid8bQPreOLb0=
github.com/AdguardTeam/dnsproxy v0.11.2 h1:S/Ag2q9qoZsmW1fvMohPZP7/5amEtz8NmFCp8kxUalQ=
github.com/AdguardTeam/dnsproxy v0.11.2/go.mod h1:EPp92b5cYR7HZpO+OQu6xC7AyhUoBaXW3sfa3exq/0I=
github.com/AdguardTeam/golibs v0.1.0 h1:Mo1QNKC8eSbqczhxfdBXYCrUMwvgCyCwZFyWv+2Gdng=
github.com/AdguardTeam/golibs v0.1.0/go.mod h1:zhi6xGwK4cMpjDocybhhLgvcGkstiSIjlpKbvyxC5Yc=
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f h1:5ZfJxyXo8KyX8DgGXC5B7ILL8y51fci/qYz2B4j8iLY=
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
@ -26,8 +28,6 @@ github.com/gobuffalo/packd v0.0.0-20181031195726-c82734870264 h1:roWyi0eEdiFreSq
github.com/gobuffalo/packd v0.0.0-20181031195726-c82734870264/go.mod h1:Yf2toFaISlyQrr5TfO3h6DB9pl9mZRmyvBGQb/aQ/pI=
github.com/gobuffalo/packr v1.19.0 h1:3UDmBDxesCOPF8iZdMDBBWKfkBoYujIMIZePnobqIUI=
github.com/gobuffalo/packr v1.19.0/go.mod h1:MstrNkfCQhd5o+Ct4IJ0skWlxN8emOq8DsoT1G98VIU=
github.com/hmage/golibs v0.0.0-20190121112702-20153bd03c24 h1:yyDtaSMcAZdm1I6uL8YLghpWiJljfBHs8NC/P86PYQk=
github.com/hmage/golibs v0.0.0-20190121112702-20153bd03c24/go.mod h1:H6Ev6svFxUVPFThxLtdnFfcE9e3GWufpfmcVFpqV6HM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=

View File

@ -3,7 +3,7 @@ package main
import (
"testing"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
)
func TestGetValidNetInterfacesForWeb(t *testing.T) {

View File

@ -6,7 +6,7 @@ import (
"net/http"
"strings"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
)
// --------------------

View File

@ -4,7 +4,7 @@ import (
"os"
"runtime"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
"github.com/kardianos/service"
)

View File

@ -6,7 +6,7 @@ import (
"os"
"path/filepath"
"github.com/hmage/golibs/log"
"github.com/AdguardTeam/golibs/log"
yaml "gopkg.in/yaml.v2"
)