Pull request: all: update go and backend tools

Closes #2576.
Updates #2275.
Updates #2419.
Updates #2443.

Squashed commit of the following:

commit b1a4809ada298d675de12740051ba26fb9945957
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri May 21 14:01:40 2021 +0300

    all: add --local-frontend, upd docker

commit 619ee7c82f27e3405753003dbec556ffb056d025
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu May 20 15:02:33 2021 +0300

    bamboo-specs: bump docker version

commit 5c2b2fbce80afdcc81fd0cb83674dc3d64facbf1
Merge: 6536b32d 9c60aef6
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu May 20 15:01:47 2021 +0300

    Merge branch 'master' into 2275-upd-go

commit 6536b32dd4580425f7dedde6765463a79b9bd699
Merge: 9bb32bc4 6f7fd33a
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 20:38:48 2021 +0300

    Merge branch 'master' into 2275-upd-go

commit 9bb32bc4c0ac0f3a97195adc75359e48c9c58897
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 18:48:50 2021 +0300

    all: fix build, imp err handling

commit 6868eac7f7d2980fb706881f53e72afe5f7c3447
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 18:09:32 2021 +0300

    all: fix github lint

commit ebbb9c55f32fbd57e34e8b161016aa6b291c097c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed May 19 17:36:56 2021 +0300

    all: update go and backend tools
This commit is contained in:
Ainar Garipov
2021-05-21 14:55:42 +03:00
parent 9c60aef637
commit c6888326b0
79 changed files with 382 additions and 703 deletions

View File

@@ -3,7 +3,6 @@ package aghio
import (
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
@@ -75,7 +74,7 @@ func TestLimitedReadCloser_Read(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
readCloser := ioutil.NopCloser(strings.NewReader(tc.rStr))
readCloser := io.NopCloser(strings.NewReader(tc.rStr))
buf := make([]byte, tc.limit+1)
lreader, err := LimitReadCloser(readCloser, tc.limit)

View File

@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
@@ -345,7 +344,7 @@ func (ehc *EtcHostsContainer) updateHosts() {
ehc.load(table, tableRev, ehc.hostsFn)
for _, dir := range ehc.hostsDirs {
fis, err := ioutil.ReadDir(dir)
des, err := os.ReadDir(dir)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Error("etchostscontainer: Opening directory: %q: %s", dir, err)
@@ -354,8 +353,8 @@ func (ehc *EtcHostsContainer) updateHosts() {
continue
}
for _, fi := range fis {
ehc.load(table, tableRev, filepath.Join(dir, fi.Name()))
for _, de := range des {
ehc.load(table, tableRev, filepath.Join(dir, de.Name()))
}
}

View File

@@ -1,7 +1,6 @@
package aghnet
import (
"io/ioutil"
"net"
"os"
"strings"
@@ -23,7 +22,7 @@ func prepareTestFile(t *testing.T) (f *os.File) {
dir := t.TempDir()
f, err := ioutil.TempFile(dir, "")
f, err := os.CreateTemp(dir, "")
require.Nil(t, err)
require.NotNil(t, f)
t.Cleanup(func() {

View File

@@ -1,11 +1,13 @@
// +build darwin
//go:build darwin
package aghnet
import (
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
@@ -140,7 +142,7 @@ func ifaceSetStaticIP(ifaceName string) (err error) {
// getEtcResolvConfServers returns a list of nameservers configured in
// /etc/resolv.conf.
func getEtcResolvConfServers() ([]string, error) {
body, err := ioutil.ReadFile("/etc/resolv.conf")
body, err := os.ReadFile("/etc/resolv.conf")
if err != nil {
return nil, err
}

View File

@@ -1,5 +1,7 @@
// +build linux
//go:build linux
package aghnet
import (
@@ -7,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
@@ -139,7 +140,7 @@ func ifaceSetStaticIP(ifaceName string) (err error) {
gatewayIP := GatewayIP(ifaceName)
add := updateStaticIPdhcpcdConf(ifaceName, ipNet.String(), gatewayIP, ipNet.IP)
body, err := ioutil.ReadFile("/etc/dhcpcd.conf")
body, err := os.ReadFile("/etc/dhcpcd.conf")
if err != nil {
return err
}

View File

@@ -1,5 +1,7 @@
// +build linux
//go:build linux
package aghnet
import (

View File

@@ -1,5 +1,7 @@
// +build !linux,!darwin
//go:build !(linux || darwin)
package aghnet
import (

View File

@@ -1,5 +1,7 @@
// +build !windows
//go:build !windows
package aghnet
import (

View File

@@ -1,5 +1,7 @@
// +build !windows
//go:build !windows
package aghnet
import (

View File

@@ -1,5 +1,7 @@
// +build windows
//go:build windows
package aghnet
import (

View File

@@ -1,5 +1,7 @@
// +build windows
//go:build windows
package aghnet
// TODO(e.burkov): Write tests for Windows implementation.

View File

@@ -1,5 +1,7 @@
// +build mips mips64
//go:build mips || mips64
// This file is an adapted version of github.com/josharian/native.
package aghos

View File

@@ -1,5 +1,7 @@
// +build amd64 386 arm arm64 mipsle mips64le ppc64le
//go:build amd64 || 386 || arm || arm64 || mipsle || mips64le || ppc64le
// This file is an adapted version of github.com/josharian/native.
package aghos

View File

@@ -1,5 +1,7 @@
// +build darwin netbsd openbsd
//go:build darwin || netbsd || openbsd
package aghos
import (

View File

@@ -1,5 +1,7 @@
// +build freebsd
//go:build freebsd
package aghos
import (

View File

@@ -1,10 +1,11 @@
// +build linux
//go:build linux
package aghos
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -45,9 +46,7 @@ func sendProcessSignal(pid int, sig syscall.Signal) error {
func isOpenWrt() (ok bool) {
const etcDir = "/etc"
// TODO(e.burkov): Take care of dealing with fs package after updating
// Go version to 1.16.
fileInfos, err := ioutil.ReadDir(etcDir)
dirEnts, err := os.ReadDir(etcDir)
if err != nil {
return false
}
@@ -56,18 +55,18 @@ func isOpenWrt() (ok bool) {
const fNameSubstr = "release"
osNameData := []byte("OpenWrt")
for _, fileInfo := range fileInfos {
if fileInfo.IsDir() {
for _, dirEnt := range dirEnts {
if dirEnt.IsDir() {
continue
}
fn := fileInfo.Name()
fn := dirEnt.Name()
if !strings.Contains(fn, fNameSubstr) {
continue
}
var body []byte
body, err = ioutil.ReadFile(filepath.Join(etcDir, fn))
body, err = os.ReadFile(filepath.Join(etcDir, fn))
if err != nil {
continue
}

View File

@@ -1,5 +1,7 @@
// +build windows
//go:build windows
package aghos
import (

View File

@@ -1,5 +1,7 @@
// +build !windows,!plan9
//go:build !(windows || plan9)
package aghos
import (

View File

@@ -1,5 +1,7 @@
// +build windows plan9
//go:build windows || plan9
package aghos
import (

View File

@@ -3,7 +3,6 @@ package aghtest
import (
"io"
"io/ioutil"
"os"
"testing"
@@ -14,7 +13,7 @@ import (
func DiscardLogOutput(m *testing.M) {
// TODO(e.burkov): Refactor code and tests to not use the global mutable
// logger.
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

View File

@@ -1,5 +1,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (

View File

@@ -5,7 +5,6 @@ package dhcpd
import (
"encoding/json"
"errors"
"io/ioutil"
"net"
"os"
"time"
@@ -38,7 +37,7 @@ func (s *Server) dbLoad() {
v6StaticLeases := []*Lease{}
v6DynLeases := []*Lease{}
data, err := ioutil.ReadFile(s.conf.DBFilePath)
data, err := os.ReadFile(s.conf.DBFilePath)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
log.Error("dhcp: can't read file %q: %v", s.conf.DBFilePath, err)

View File

@@ -1,5 +1,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (

View File

@@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
@@ -369,7 +369,7 @@ type dhcpSearchResult struct {
// Respond with results
func (s *Server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
// This use of ReadAll is safe, because request's body is now limited.
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
msg := fmt.Sprintf("failed to read request body: %s", err)
log.Error(msg)

View File

@@ -1,9 +1,12 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (
"bytes"
"errors"
"fmt"
"net"
"strings"
@@ -972,16 +975,11 @@ func (s *v4Server) Start() (err error) {
log.Info("dhcpv4: listening")
go func() {
serr := s.srv.Serve()
// TODO(a.garipov): Uncomment in Go 1.16.
//
// if errors.Is(serr, net.ErrClosed) {
// log.Info("dhcpv4: server is closed")
//
// return
// }
if serr := s.srv.Serve(); errors.Is(serr, net.ErrClosed) {
log.Info("dhcpv4: server is closed")
if serr != nil {
return
} else if serr != nil {
log.Error("dhcpv4: srv.Serve: %s", serr)
}
}()

View File

@@ -1,5 +1,7 @@
// +build windows
//go:build windows
package dhcpd
// 'u-root/u-root' package, a dependency of 'insomniacslk/dhcp' package, doesn't build on Windows

View File

@@ -1,5 +1,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (

View File

@@ -1,5 +1,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (

View File

@@ -1,5 +1,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
package dhcpd
import (

View File

@@ -1,5 +1,7 @@
// +build ignore
//go:build ignore
package dnsfilter
import (

View File

@@ -4,7 +4,6 @@ package dnsfilter
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
@@ -586,16 +585,16 @@ func createFilteringEngine(filters []Filter) (*filterlist.RuleStorage, *urlfilte
// On Windows we don't pass a file to urlfilter because
// it's difficult to update this file while it's being
// used.
data, err := ioutil.ReadFile(f.FilePath)
data, err := os.ReadFile(f.FilePath)
if err != nil {
return nil, nil, fmt.Errorf("ioutil.ReadFile(): %s: %w", f.FilePath, err)
return nil, nil, fmt.Errorf("reading filter content: %w", err)
}
list = &filterlist.StringRuleList{
ID: int(f.ID),
RulesText: string(data),
IgnoreCosmetic: true,
}
} else {
var err error
list, err = filterlist.NewFileRuleList(int(f.ID), f.FilePath, true)

View File

@@ -5,9 +5,9 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"sort"
"github.com/AdguardTeam/AdGuardHome/internal/aghstrings"
@@ -275,7 +275,7 @@ func (s *Server) prepareUpstreamSettings() error {
// Load upstreams either from the file, or from the settings
var upstreams []string
if s.conf.UpstreamDNSFileName != "" {
data, err := ioutil.ReadFile(s.conf.UpstreamDNSFileName)
data, err := os.ReadFile(s.conf.UpstreamDNSFileName)
if err != nil {
return err
}

View File

@@ -9,7 +9,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
@@ -1082,9 +1081,8 @@ func TestPTRResponseFromHosts(t *testing.T) {
}
// Prepare test hosts file.
hf, err := ioutil.TempFile("", "")
hf, err := os.CreateTemp("", "")
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, hf.Close())
assert.NoError(t, os.Remove(hf.Name()))

View File

@@ -3,7 +3,7 @@ package dnsforward
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@@ -207,7 +207,7 @@ func TestDNSForwardHTTTP_handleSetConfig(t *testing.T) {
s.conf = defaultConf
})
rBody := ioutil.NopCloser(bytes.NewReader(caseData.Req))
rBody := io.NopCloser(bytes.NewReader(caseData.Req))
var r *http.Request
r, err = http.NewRequest(http.MethodPost, "http://example.com", rBody)
require.Nil(t, err)

View File

@@ -1,5 +1,7 @@
// +build linux
//go:build linux
package dnsforward
import (

View File

@@ -1,5 +1,7 @@
// +build !linux
//go:build !linux
package dnsforward
import (

View File

@@ -3,7 +3,7 @@ package home
import (
"bytes"
"encoding/binary"
"io/ioutil"
"io"
"net"
"net/http"
"os"
@@ -79,7 +79,8 @@ func glGetTokenDate(file string) uint32 {
fileReadCloser, err := aghio.LimitReadCloser(f, MaxFileSize)
if err != nil {
log.Error("LimitReadCloser: %s", err)
log.Error("creating limited reader: %s", err)
return 0
}
defer fileReadCloser.Close()
@@ -87,16 +88,18 @@ func glGetTokenDate(file string) uint32 {
var dateToken uint32
// This use of ReadAll is now safe, because we limited reader.
bs, err := ioutil.ReadAll(fileReadCloser)
bs, err := io.ReadAll(fileReadCloser)
if err != nil {
log.Error("ioutil.ReadAll: %s", err)
log.Error("reading token: %s", err)
return 0
}
buf := bytes.NewBuffer(bs)
err = binary.Read(buf, aghos.NativeEndian, &dateToken)
if err != nil {
log.Error("binary.Read: %s", err)
log.Error("decoding token: %s", err)
return 0
}

View File

@@ -1,8 +1,8 @@
package home
import (
"io/ioutil"
"net/http"
"os"
"testing"
"time"
@@ -23,13 +23,13 @@ func TestAuthGL(t *testing.T) {
data := make([]byte, 4)
aghos.NativeEndian.PutUint32(data, 1)
require.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644))
require.Nil(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
assert.False(t, glCheckToken("test"))
data = make([]byte, 4)
aghos.NativeEndian.PutUint32(data, uint32(time.Now().UTC().Unix()+60))
require.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644))
require.Nil(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil)
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
assert.True(t, glProcessCookie(r))

View File

@@ -3,7 +3,6 @@ package home
import (
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
@@ -267,7 +266,7 @@ func readConfigFile() ([]byte, error) {
}
configFile := config.getConfigFilename()
d, err := ioutil.ReadFile(configFile)
d, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("couldn't read config file %s: %w", configFile, err)
}

View File

@@ -3,7 +3,7 @@ package home
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
@@ -226,7 +226,7 @@ func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request
func (f *Filtering) handleFilteringSetRules(w http.ResponseWriter, r *http.Request) {
// This use of ReadAll is safe, because request's body is now limited.
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err)
return

View File

@@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
@@ -220,9 +220,9 @@ func disableDNSStubListener() error {
return fmt.Errorf("os.MkdirAll: %s: %w", dir, err)
}
err = ioutil.WriteFile(resolvedConfPath, []byte(resolvedConfData), 0o644)
err = os.WriteFile(resolvedConfPath, []byte(resolvedConfData), 0o644)
if err != nil {
return fmt.Errorf("ioutil.WriteFile: %s: %w", resolvedConfPath, err)
return fmt.Errorf("os.WriteFile: %s: %w", resolvedConfPath, err)
}
_ = os.Rename(resolvConfPath, resolvConfPath+".backup")
@@ -450,7 +450,7 @@ func (web *Web) handleInstallCheckConfigBeta(w http.ResponseWriter, r *http.Requ
return
}
body := nonBetaReqBody.String()
r.Body = ioutil.NopCloser(strings.NewReader(body))
r.Body = io.NopCloser(strings.NewReader(body))
r.ContentLength = int64(len(body))
web.handleInstallCheckConfig(w, r)
@@ -517,7 +517,7 @@ func (web *Web) handleInstallConfigureBeta(w http.ResponseWriter, r *http.Reques
return
}
body := nonBetaReqBody.String()
r.Body = ioutil.NopCloser(strings.NewReader(body))
r.Body = io.NopCloser(strings.NewReader(body))
r.ContentLength = int64(len(body))
web.handleInstallConfigure(w, r)

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"hash/crc32"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -542,7 +541,7 @@ func (f *Filtering) updateIntl(filter *filter) (updated bool, err error) {
updated = false
log.Tracef("Downloading update for filter %d from %s", filter.ID, filter.URL)
tmpFile, err := ioutil.TempFile(filepath.Join(Context.getDataDir(), filterDir), "")
tmpFile, err := os.CreateTemp(filepath.Join(Context.getDataDir(), filterDir), "")
if err != nil {
return updated, err
}

View File

@@ -7,7 +7,7 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"io/fs"
"net"
"net/http"
"net/http/pprof"
@@ -92,7 +92,7 @@ func (c *homeContext) getDataDir() string {
var Context homeContext
// Main is the entry point
func Main() {
func Main(clientBuildFS fs.FS) {
// config can be specified, which reads options from there, but other command line flags have to override config values
// therefore, we must do it manually instead of using a lib
args := loadOptions()
@@ -117,12 +117,12 @@ func Main() {
}()
if args.serviceControlAction != "" {
handleServiceControlAction(args)
handleServiceControlAction(args, clientBuildFS)
return
}
// run the protection
run(args)
run(args, clientBuildFS)
}
func setupContext(args options) {
@@ -227,8 +227,49 @@ func setupConfig(args options) {
}
}
func initWeb(args options, clientBuildFS fs.FS) (web *Web, err error) {
var clientFS, clientBetaFS fs.FS
if args.localFrontend {
log.Info("warning: using local frontend files")
clientFS = os.DirFS("build/static")
clientBetaFS = os.DirFS("build2/static")
} else {
clientFS, err = fs.Sub(clientBuildFS, "build/static")
if err != nil {
return nil, fmt.Errorf("getting embedded client subdir: %w", err)
}
clientBetaFS, err = fs.Sub(clientBuildFS, "build2/static")
if err != nil {
return nil, fmt.Errorf("getting embedded beta client subdir: %w", err)
}
}
webConf := webConfig{
firstRun: Context.firstRun,
BindHost: config.BindHost,
BindPort: config.BindPort,
BetaBindPort: config.BetaBindPort,
ReadTimeout: readTimeout,
ReadHeaderTimeout: readHdrTimeout,
WriteTimeout: writeTimeout,
clientFS: clientFS,
clientBetaFS: clientBetaFS,
}
web = CreateWeb(&webConf)
if web == nil {
return nil, fmt.Errorf("initializing web: %w", err)
}
return web, nil
}
// run performs configurating and starts AdGuard Home.
func run(args options) {
func run(args options, clientBuildFS fs.FS) {
// configure config filename
initConfigFilename(args)
@@ -295,6 +336,7 @@ func run(args options) {
} else {
log.Info("authratelimiter is disabled")
}
Context.auth = InitAuth(
sessFilename,
config.Users,
@@ -311,19 +353,9 @@ func run(args options) {
log.Fatalf("Can't initialize TLS module")
}
webConf := webConfig{
firstRun: Context.firstRun,
BindHost: config.BindHost,
BindPort: config.BindPort,
BetaBindPort: config.BetaBindPort,
ReadTimeout: readTimeout,
ReadHeaderTimeout: readHdrTimeout,
WriteTimeout: writeTimeout,
}
Context.web = CreateWeb(&webConf)
if Context.web == nil {
log.Fatalf("Can't initialize Web module")
Context.web, err = initWeb(args, clientBuildFS)
if err != nil {
log.Fatal(err)
}
Context.subnetDetector, err = aghnet.NewSubnetDetector()
@@ -426,7 +458,7 @@ Please note, that this is crucial for a DNS server to be able to use that port.`
// Write PID to a file
func writePIDFile(fn string) bool {
data := fmt.Sprintf("%d", os.Getpid())
err := ioutil.WriteFile(fn, []byte(data), 0o644)
err := os.WriteFile(fn, []byte(data), 0o644)
if err != nil {
log.Error("Couldn't write PID to file %s: %v", fn, err)
return false

View File

@@ -1,191 +0,0 @@
// +build !race
// TODO(e.burkov): Remove this weird buildtag.
package home
import (
"context"
"encoding/base64"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/AdguardTeam/dnsproxy/proxyutil"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
)
const yamlConf = `bind_host: 127.0.0.1
bind_port: 3000
users: []
language: en
rlimit_nofile: 0
web_session_ttl: 720
dns:
bind_host: 127.0.0.1
port: 5354
statistics_interval: 90
querylog_enabled: true
querylog_interval: 90
querylog_size_memory: 0
protection_enabled: true
blocking_mode: null_ip
blocked_response_ttl: 0
ratelimit: 100
ratelimit_whitelist: []
refuse_any: false
bootstrap_dns:
- 1.1.1.1:53
all_servers: false
allowed_clients: []
disallowed_clients: []
blocked_hosts: []
parental_block_host: family-block.dns.adguard.com
safebrowsing_block_host: standard-block.dns.adguard.com
cache_size: 0
upstream_dns:
- https://1.1.1.1/dns-query
filtering_enabled: true
filters_update_interval: 168
parental_sensitivity: 13
parental_enabled: true
safesearch_enabled: false
safebrowsing_enabled: false
safebrowsing_cache_size: 1048576
safesearch_cache_size: 1048576
parental_cache_size: 1048576
cache_time: 30
rewrites: []
blocked_services: []
tls:
enabled: false
server_name: www.example.com
force_https: false
port_https: 443
port_dns_over_tls: 853
allow_unencrypted_doh: true
certificate_chain: ""
private_key: ""
certificate_path: ""
private_key_path: ""
filters:
- enabled: true
url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
name: AdGuard Simplified Domain Names filter
id: 1
- enabled: false
url: https://hosts-file.net/ad_servers.txt
name: hpHosts - Ad and Tracking servers only
id: 2
- enabled: false
url: https://adaway.org/hosts.txt
name: adaway
id: 3
user_rules:
- ""
dhcp:
enabled: false
interface_name: ""
gateway_ip: ""
subnet_mask: ""
range_start: ""
range_end: ""
lease_duration: 86400
icmp_timeout_msec: 1000
clients: []
log_file: ""
verbose: false
schema_version: 5
`
// . Create a configuration file
// . Start AGH instance
// . Check Web server
// . Check DNS server
// . Check DNS server with DOH
// . Wait until the filters are downloaded
// . Stop and cleanup
func TestHome(t *testing.T) {
// Init new context
Context = homeContext{}
dir := t.TempDir()
fn := filepath.Join(dir, "AdGuardHome.yaml")
// Prepare the test config
assert.Nil(t, ioutil.WriteFile(fn, []byte(yamlConf), 0o644))
fn, _ = filepath.Abs(fn)
config = configuration{} // the global variable is dirty because of the previous tests run
args := options{}
args.configFilename = fn
args.workDir = dir
go run(args)
var err error
var resp *http.Response
h := http.Client{}
for i := 0; i != 50; i++ {
resp, err = h.Get("http://127.0.0.1:3000/")
if err == nil && resp.StatusCode != http.StatusNotFound {
break
}
time.Sleep(100 * time.Millisecond)
}
assert.Nilf(t, err, "%s", err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
resp, err = h.Get("http://127.0.0.1:3000/control/status")
assert.Nilf(t, err, "%s", err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
// test DNS over UDP
r, err := upstream.NewResolver("127.0.0.1:5354", upstream.Options{Timeout: 3 * time.Second})
assert.Nil(t, err)
addrs, err := r.LookupIPAddr(context.TODO(), "static.adguard.com")
assert.Nil(t, err)
haveIP := len(addrs) != 0
assert.True(t, haveIP)
// test DNS over HTTP without encryption
req := dns.Msg{}
req.Id = dns.Id()
req.RecursionDesired = true
req.Question = []dns.Question{{Name: "static.adguard.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET}}
buf, err := req.Pack()
assert.Nil(t, err)
requestURL := "http://127.0.0.1:3000/dns-query?dns=" + base64.RawURLEncoding.EncodeToString(buf)
resp, err = http.DefaultClient.Get(requestURL)
assert.Nil(t, err)
body, err := ioutil.ReadAll(resp.Body)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
response := dns.Msg{}
err = response.Unpack(body)
assert.Nil(t, err)
addrs = nil
proxyutil.AppendIPAddrs(&addrs, response.Answer)
haveIP = len(addrs) != 0
assert.True(t, haveIP)
for i := 1; ; i++ {
var fi os.FileInfo
fi, err = os.Stat(filepath.Join(dir, "data", "filters", "1.txt"))
if err == nil && fi.Size() != 0 {
break
}
if i == 5 {
assert.True(t, false)
break
}
time.Sleep(1 * time.Second)
}
cleanup(context.Background())
cleanupAlways()
}

View File

@@ -2,7 +2,7 @@ package home
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
@@ -61,7 +61,7 @@ func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) {
func handleI18nChangeLanguage(w http.ResponseWriter, r *http.Request) {
// This use of ReadAll is safe, because request's body is now limited.
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
msg := fmt.Sprintf("failed to read request body: %s", err)
log.Println(msg)

View File

@@ -1,7 +1,7 @@
package home
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@@ -44,7 +44,7 @@ func TestLimitRequestBody(t *testing.T) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var b []byte
b, *err = ioutil.ReadAll(r.Body)
b, *err = io.ReadAll(r.Body)
_, werr := w.Write(b)
require.Nil(t, werr)
})

View File

@@ -36,6 +36,10 @@ type options struct {
// noEtcHosts flag should be provided when /etc/hosts file shouldn't be
// used.
noEtcHosts bool
// localFrontend forces AdGuard Home to use the frontend files from disk
// rather than the ones that have been compiled into the binary.
localFrontend bool
}
// functions used for their side-effects
@@ -234,6 +238,16 @@ var noEtcHostsArg = arg{
serialize: func(o options) []string { return boolSliceOrNil(o.noEtcHosts) },
}
var localFrontendArg = arg{
description: "Use local frontend directories.",
longName: "local-frontend",
shortName: "",
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.localFrontend = true; return o, nil },
effect: nil,
serialize: func(o options) []string { return boolSliceOrNil(o.localFrontend) },
}
func init() {
args = []arg{
configArg,
@@ -247,6 +261,7 @@ func init() {
noCheckUpdateArg,
disableMemoryOptimizationArg,
noEtcHostsArg,
localFrontendArg,
verboseArg,
glinetArg,
versionArg,

View File

@@ -3,7 +3,7 @@ package home
import (
"errors"
"fmt"
"io/ioutil"
"io/fs"
"os"
"runtime"
"strconv"
@@ -28,7 +28,8 @@ const (
// Represents the program that will be launched by a service or daemon
type program struct {
opts options
clientBuildFS fs.FS
opts options
}
// Start should quickly start the program
@@ -36,7 +37,8 @@ func (p *program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
args := p.opts
args.runningAsService = true
go run(args)
go run(args, p.clientBuildFS)
return nil
}
@@ -95,7 +97,7 @@ func sendSigReload() {
}
pidfile := fmt.Sprintf("/var/run/%s.pid", serviceName)
data, err := ioutil.ReadFile(pidfile)
data, err := os.ReadFile(pidfile)
if errors.Is(err, os.ErrNotExist) {
var code int
var psdata string
@@ -142,7 +144,7 @@ func sendSigReload() {
// run - this is a special command that is not supposed to be used directly
// it is specified when we register a service, and it indicates to the app
// that it is being run as a service/daemon.
func handleServiceControlAction(opts options) {
func handleServiceControlAction(opts options, clientBuildFS fs.FS) {
action := opts.serviceControlAction
log.Printf("Service control action: %s", action)
@@ -165,7 +167,10 @@ func handleServiceControlAction(opts options) {
Arguments: serialize(runOpts),
}
configureService(svcConfig)
prg := &program{runOpts}
prg := &program{
clientBuildFS: clientBuildFS,
opts: runOpts,
}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)

View File

@@ -12,7 +12,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -164,7 +163,7 @@ func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
status.WarningValidation = "certificate data and file can't be set together"
return false
}
tls.CertificateChainData, err = ioutil.ReadFile(tls.CertificatePath)
tls.CertificateChainData, err = os.ReadFile(tls.CertificatePath)
if err != nil {
status.WarningValidation = err.Error()
return false
@@ -177,7 +176,7 @@ func tlsLoadConfig(tls *tlsConfigSettings, status *tlsConfigStatus) bool {
status.WarningValidation = "private key data and file can't be set together"
return false
}
tls.PrivateKeyData, err = ioutil.ReadFile(tls.PrivateKeyPath)
tls.PrivateKeyData, err = os.ReadFile(tls.PrivateKeyPath)
if err != nil {
status.WarningValidation = err.Error()
return false
@@ -574,18 +573,17 @@ func LoadSystemRootCAs() (roots *x509.CertPool) {
}
roots = x509.NewCertPool()
for _, dir := range dirs {
fis, err := ioutil.ReadDir(dir)
dirEnts, err := os.ReadDir(dir)
if errors.Is(err, os.ErrNotExist) {
continue
}
if err != nil {
} else if err != nil {
log.Error("opening directory: %q: %s", dir, err)
}
var rootsAdded bool
for _, fi := range fis {
for _, de := range dirEnts {
var certData []byte
certData, err = ioutil.ReadFile(filepath.Join(dir, fi.Name()))
certData, err = os.ReadFile(filepath.Join(dir, de.Name()))
if err == nil && roots.AppendCertsFromPEM(certData) {
rootsAdded = true
}

View File

@@ -3,6 +3,7 @@ package home
import (
"context"
"crypto/tls"
"io/fs"
"net"
"net/http"
"strconv"
@@ -12,7 +13,6 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/golibs/log"
"github.com/NYTimes/gziphandler"
"github.com/gobuffalo/packr"
)
// HTTP scheme constants.
@@ -33,11 +33,14 @@ const (
)
type webConfig struct {
firstRun bool
BindHost net.IP
BindPort int
BetaBindPort int
PortHTTPS int
firstRun bool
clientFS fs.FS
clientBetaFS fs.FS
// ReadTimeout is an option to pass to http.Server for setting an
// appropriate field.
@@ -85,19 +88,18 @@ func CreateWeb(conf *webConfig) *Web {
w := Web{}
w.conf = conf
// Initialize and run the admin Web interface
box := packr.NewBox("../../build/static")
boxBeta := packr.NewBox("../../build2/static")
clientFS := http.FileServer(http.FS(conf.clientFS))
betaClientFS := http.FileServer(http.FS(conf.clientBetaFS))
// if not configured, redirect / to /install.html, otherwise redirect /install.html to /
Context.mux.Handle("/", withMiddlewares(http.FileServer(box), gziphandler.GzipHandler, optionalAuthHandler, postInstallHandler))
w.handlerBeta = withMiddlewares(http.FileServer(boxBeta), gziphandler.GzipHandler, optionalAuthHandler, postInstallHandler)
Context.mux.Handle("/", withMiddlewares(clientFS, gziphandler.GzipHandler, optionalAuthHandler, postInstallHandler))
w.handlerBeta = withMiddlewares(betaClientFS, gziphandler.GzipHandler, optionalAuthHandler, postInstallHandler)
// add handlers for /install paths, we only need them when we're not configured yet
if conf.firstRun {
log.Info("This is the first launch of AdGuard Home, redirecting everything to /install.html ")
Context.mux.Handle("/install.html", preInstallHandler(http.FileServer(box)))
w.installerBeta = preInstallHandler(http.FileServer(boxBeta))
Context.mux.Handle("/install.html", preInstallHandler(clientFS))
w.installerBeta = preInstallHandler(betaClientFS)
w.registerInstallHandlers()
// This must be removed in API v1.
w.registerBetaInstallHandlers()

View File

@@ -4,7 +4,7 @@ import (
"context"
"encoding/binary"
"fmt"
"io/ioutil"
"io"
"net"
"strings"
"time"
@@ -163,7 +163,7 @@ func (w *Whois) query(ctx context.Context, target, serverAddr string) (string, e
}
// This use of ReadAll is now safe, because we limited the conn Reader.
data, err := ioutil.ReadAll(connReadCloser)
data, err := io.ReadAll(connReadCloser)
if err != nil {
return "", err
}

View File

@@ -5,9 +5,9 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"net"
"os"
"strings"
"testing"
"time"
@@ -21,7 +21,7 @@ import (
func prepareTestFile(t *testing.T, dir string, linesNum int) (name string) {
t.Helper()
f, err := ioutil.TempFile(dir, "*.txt")
f, err := os.CreateTemp(dir, "*.txt")
require.NoError(t, err)
// Use defer and not t.Cleanup to make sure that the file is closed
// after this function is done.
@@ -285,7 +285,7 @@ func TestQLogFile(t *testing.T) {
}
func NewTestQLogFileData(t *testing.T, data string) (file *QLogFile) {
f, err := ioutil.TempFile(t.TempDir(), "*.txt")
f, err := os.CreateTemp(t.TempDir(), "*.txt")
require.Nil(t, err)
t.Cleanup(func() {
assert.Nil(t, f.Close())

View File

@@ -1,20 +1,21 @@
module github.com/AdguardTeam/AdGuardHome/internal/tools
go 1.15
go 1.16
require (
github.com/fzipp/gocyclo v0.3.1
github.com/golangci/misspell v0.3.5
github.com/google/go-cmp v0.5.5 // indirect
github.com/gookit/color v1.4.2 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254
github.com/kisielk/errcheck v1.6.0
github.com/kyoh86/looppointer v0.1.7
github.com/kyoh86/nolint v0.0.1 // indirect
github.com/securego/gosec/v2 v2.7.0
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
golang.org/x/tools v0.1.0
honnef.co/go/tools v0.1.3
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect
golang.org/x/tools v0.1.1
honnef.co/go/tools v0.1.4
mvdan.cc/gofumpt v0.1.1
mvdan.cc/unparam v0.0.0-20210104141923-aac4ce9116a7
)

View File

@@ -136,7 +136,6 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golangci/misspell v0.3.5 h1:pLzmVdl3VxTOncgzHcvLOKirdvcx/TydsClUQXTehjo=
github.com/golangci/misspell v0.3.5/go.mod h1:dEbvlSfYbMQDtrpRMQU675gSDLDNa8sCPPChZ7PhiVA=
@@ -169,8 +168,9 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gookit/color v1.3.8 h1:w2WcSwaCa1ojRWO60Mm4GJUJomBNKR9G+x9DwaaCL1c=
github.com/gookit/color v1.3.8/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU=
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 h1:Nb2aRlC404yz7gQIfRZxX9/MLvQiqXyiBTJtgAy6yrI=
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254/go.mod h1:M9mZEtGIsR1oDaZagNPNG9iq9n2HrhZ17dsXk73V3Lw=
@@ -345,6 +345,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
@@ -353,6 +355,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6yfWfDmlWd35khcWpUa4L0xI/k=
@@ -404,8 +407,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
@@ -415,8 +418,9 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -453,8 +457,9 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -470,6 +475,7 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -517,8 +523,10 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -585,8 +593,9 @@ golang.org/x/tools v0.0.0-20201007032633-0806396f153e/go.mod h1:z6u4i615ZeAfBE4X
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210104081019-d8d6ddbec6ee/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -669,7 +678,6 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -706,8 +714,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.1.3 h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
honnef.co/go/tools v0.1.4 h1:SadWOkti5uVN1FAMgxn165+Mw00fuQKyk4Gyn/inxNQ=
honnef.co/go/tools v0.1.4/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
mvdan.cc/gofumpt v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
mvdan.cc/unparam v0.0.0-20210104141923-aac4ce9116a7 h1:HT3e4Krq+IE44tiN36RvVEb6tvqeIdtsVSsxmNPqlFU=

View File

@@ -1,5 +1,7 @@
// +build tools
//go:build tools
package tools
import (

View File

@@ -3,7 +3,7 @@ package updater
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"strings"
"time"
@@ -52,7 +52,7 @@ func (u *Updater) VersionInfo(forceRecheck bool) (VersionInfo, error) {
// This use of ReadAll is safe, because we just limited the appropriate
// ReadCloser.
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return VersionInfo{}, fmt.Errorf("updater: HTTP GET %s: %w", vcu, err)
}

View File

@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@@ -299,17 +298,17 @@ func (u *Updater) downloadPackageFile(url, filename string) error {
log.Debug("updater: reading HTTP body")
// This use of ReadAll is now safe, because we limited body's Reader.
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("ioutil.ReadAll() failed: %w", err)
return fmt.Errorf("io.ReadAll() failed: %w", err)
}
_ = os.Mkdir(u.updateDir, 0o755)
log.Debug("updater: saving package to file")
err = ioutil.WriteFile(filename, body, 0o644)
err = os.WriteFile(filename, body, 0o644)
if err != nil {
return fmt.Errorf("ioutil.WriteFile() failed: %w", err)
return fmt.Errorf("os.WriteFile() failed: %w", err)
}
return nil
}
@@ -484,11 +483,11 @@ func zipFileUnpack(zipfile, outdir string) ([]string, error) {
// Copy file on disk
func copyFile(src, dst string) error {
d, e := ioutil.ReadFile(src)
d, e := os.ReadFile(src)
if e != nil {
return e
}
e = ioutil.WriteFile(dst, d, 0o644)
e = os.WriteFile(dst, d, 0o644)
if e != nil {
return e
}

View File

@@ -1,10 +1,10 @@
package updater
import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
@@ -102,13 +102,13 @@ func TestUpdateGetVersion(t *testing.T) {
func TestUpdate(t *testing.T) {
wd := t.TempDir()
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "AdGuardHome"), []byte("AdGuardHome"), 0o755))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "README.md"), []byte("README.md"), 0o644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "LICENSE.txt"), []byte("LICENSE.txt"), 0o644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "AdGuardHome.yaml"), []byte("AdGuardHome.yaml"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "AdGuardHome"), []byte("AdGuardHome"), 0o755))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "README.md"), []byte("README.md"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "LICENSE.txt"), []byte("LICENSE.txt"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "AdGuardHome.yaml"), []byte("AdGuardHome.yaml"), 0o644))
// start server for returning package file
pkgData, err := ioutil.ReadFile("testdata/AdGuardHome.tar.gz")
pkgData, err := os.ReadFile("testdata/AdGuardHome.tar.gz")
assert.Nil(t, err)
l, lport := startHTTPServer(string(pkgData))
t.Cleanup(func() { assert.Nil(t, l.Close()) })
@@ -139,28 +139,28 @@ func TestUpdate(t *testing.T) {
u.clean()
// check backup files
d, err := ioutil.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.yaml"))
d, err := os.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.yaml"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome.yaml", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome"))
d, err = os.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome", string(d))
// check updated files
d, err = ioutil.ReadFile(filepath.Join(wd, "AdGuardHome"))
d, err = os.ReadFile(filepath.Join(wd, "AdGuardHome"))
assert.Nil(t, err)
assert.Equal(t, "1", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "README.md"))
d, err = os.ReadFile(filepath.Join(wd, "README.md"))
assert.Nil(t, err)
assert.Equal(t, "2", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "LICENSE.txt"))
d, err = os.ReadFile(filepath.Join(wd, "LICENSE.txt"))
assert.Nil(t, err)
assert.Equal(t, "3", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "AdGuardHome.yaml"))
d, err = os.ReadFile(filepath.Join(wd, "AdGuardHome.yaml"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome.yaml", string(d))
}
@@ -168,13 +168,13 @@ func TestUpdate(t *testing.T) {
func TestUpdateWindows(t *testing.T) {
wd := t.TempDir()
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "AdGuardHome.exe"), []byte("AdGuardHome.exe"), 0o755))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "README.md"), []byte("README.md"), 0o644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "LICENSE.txt"), []byte("LICENSE.txt"), 0o644))
assert.Nil(t, ioutil.WriteFile(filepath.Join(wd, "AdGuardHome.yaml"), []byte("AdGuardHome.yaml"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "AdGuardHome.exe"), []byte("AdGuardHome.exe"), 0o755))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "README.md"), []byte("README.md"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "LICENSE.txt"), []byte("LICENSE.txt"), 0o644))
assert.Nil(t, os.WriteFile(filepath.Join(wd, "AdGuardHome.yaml"), []byte("AdGuardHome.yaml"), 0o644))
// start server for returning package file
pkgData, err := ioutil.ReadFile("testdata/AdGuardHome.zip")
pkgData, err := os.ReadFile("testdata/AdGuardHome.zip")
assert.Nil(t, err)
l, lport := startHTTPServer(string(pkgData))
@@ -207,28 +207,28 @@ func TestUpdateWindows(t *testing.T) {
u.clean()
// check backup files
d, err := ioutil.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.yaml"))
d, err := os.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.yaml"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome.yaml", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.exe"))
d, err = os.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.exe"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome.exe", string(d))
// check updated files
d, err = ioutil.ReadFile(filepath.Join(wd, "AdGuardHome.exe"))
d, err = os.ReadFile(filepath.Join(wd, "AdGuardHome.exe"))
assert.Nil(t, err)
assert.Equal(t, "1", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "README.md"))
d, err = os.ReadFile(filepath.Join(wd, "README.md"))
assert.Nil(t, err)
assert.Equal(t, "2", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "LICENSE.txt"))
d, err = os.ReadFile(filepath.Join(wd, "LICENSE.txt"))
assert.Nil(t, err)
assert.Equal(t, "3", string(d))
d, err = ioutil.ReadFile(filepath.Join(wd, "AdGuardHome.yaml"))
d, err = os.ReadFile(filepath.Join(wd, "AdGuardHome.yaml"))
assert.Nil(t, err)
assert.Equal(t, "AdGuardHome.yaml", string(d))
}

View File

@@ -1,5 +1,7 @@
// +build !race
//go:build !race
package version
const isRace = false

View File

@@ -1,5 +1,7 @@
// +build race
//go:build race
package version
const isRace = true