mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-02 22:12:53 +03:00
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: 6536b32d9c60aef6
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: 9bb32bc46f7fd33a
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:
parent
9c60aef637
commit
c6888326b0
79 changed files with 382 additions and 703 deletions
internal/home
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue