AdGuardHome/internal/home/options.go

493 lines
14 KiB
Go
Raw Normal View History

package home
import (
"fmt"
"net/netip"
"os"
"strconv"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/stringutil"
)
// TODO(a.garipov): Replace with package flag.
// options represents the command-line options.
type options struct {
// confFilename is the path to the configuration file.
confFilename string
// workDir is the path to the working directory where AdGuard Home stores
// filter data, the query log, and other data.
workDir string
// logFile is the path to the log file. If empty, AdGuard Home writes to
// stdout; if "syslog", to syslog.
logFile string
// pidFile is the file name for the file to which the PID is saved.
pidFile string
// serviceControlAction is the service action to perform. See
// [service.ControlAction] and [handleServiceControlAction].
serviceControlAction string
// bindHost is the address on which to serve the HTTP UI.
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
//
// Deprecated: Use bindAddr.
bindHost netip.Addr
// bindPort is the port on which to serve the HTTP UI.
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
//
// Deprecated: Use bindAddr.
bindPort uint16
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
// bindAddr is the address to serve the web UI on.
bindAddr netip.AddrPort
// checkConfig is true if the current invocation is only required to check
// the configuration file and exit.
checkConfig bool
// disableUpdate, if set, makes AdGuard Home not check for updates.
disableUpdate bool
// performUpdate, if set, updates AdGuard Home without GUI and exits.
performUpdate bool
// verbose shows if verbose logging is enabled.
verbose bool
// runningAsService flag is set to true when options are passed from the
// service runner
//
// TODO(a.garipov): Perhaps this could be determined by a non-empty
// serviceControlAction?
runningAsService bool
Pull request: 2508 ip conversion vol.2 Merge in DNS/adguard-home from 2508-ip-conversion-vol2 to master Closes #2508. Squashed commit of the following: commit 5b9d33f9cd352756831f63e34c4aea48674628c1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:15:17 2021 +0300 util: replace net.IPNet with pointer commit 680126de7d59464077f9edf1bbaa925dd3fcee19 Merge: d3ba6a6c 5a50efad Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:02:41 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit d3ba6a6cdd01c0aa736418fdb86ed40120169fe9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 18:29:54 2021 +0300 all: remove last conversion commit 88b63f11a6c3f8705d7fa0c448c50dd646cc9214 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 14:12:45 2021 +0300 all: improve code quality commit 71af60c70a0dbaf55e2221023d6d2e4993c9e9a7 Merge: 98af3784 9f75725d Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 17:13:27 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit 98af3784ce44d0993d171653c13d6e83bb8d1e6a Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:32:53 2021 +0300 all: log changes commit e99595a172bae1e844019d344544be84ddd65e4e Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:06:49 2021 +0300 all: fix or remove remaining net.IP <-> string conversions commit 7fd0634ce945f7e4c9b856684c5199f8a84a543e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jan 15 15:36:17 2021 +0300 all: remove redundant net.IP <-> string converions commit 5df8af030421237d41b67ed659f83526cc258199 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:35:25 2021 +0300 stats: remove redundant net.IP <-> string conversion commit fbe4e3fc015e6898063543a90c04401d76dbb18f Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:20:35 2021 +0300 querylog: remove redundant net.IP <-> string conversion
2021-01-20 17:27:53 +03:00
// glinetMode shows if the GL-Inet compatibility mode is enabled.
glinetMode bool
Pull request: 2508 ip conversion vol.2 Merge in DNS/adguard-home from 2508-ip-conversion-vol2 to master Closes #2508. Squashed commit of the following: commit 5b9d33f9cd352756831f63e34c4aea48674628c1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:15:17 2021 +0300 util: replace net.IPNet with pointer commit 680126de7d59464077f9edf1bbaa925dd3fcee19 Merge: d3ba6a6c 5a50efad Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:02:41 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit d3ba6a6cdd01c0aa736418fdb86ed40120169fe9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 18:29:54 2021 +0300 all: remove last conversion commit 88b63f11a6c3f8705d7fa0c448c50dd646cc9214 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 14:12:45 2021 +0300 all: improve code quality commit 71af60c70a0dbaf55e2221023d6d2e4993c9e9a7 Merge: 98af3784 9f75725d Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 17:13:27 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit 98af3784ce44d0993d171653c13d6e83bb8d1e6a Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:32:53 2021 +0300 all: log changes commit e99595a172bae1e844019d344544be84ddd65e4e Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:06:49 2021 +0300 all: fix or remove remaining net.IP <-> string conversions commit 7fd0634ce945f7e4c9b856684c5199f8a84a543e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jan 15 15:36:17 2021 +0300 all: remove redundant net.IP <-> string converions commit 5df8af030421237d41b67ed659f83526cc258199 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:35:25 2021 +0300 stats: remove redundant net.IP <-> string conversion commit fbe4e3fc015e6898063543a90c04401d76dbb18f Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:20:35 2021 +0300 querylog: remove redundant net.IP <-> string conversion
2021-01-20 17:27:53 +03:00
// noEtcHosts flag should be provided when /etc/hosts file shouldn't be
// used.
noEtcHosts bool
Pull request: 2508 ip conversion vol.2 Merge in DNS/adguard-home from 2508-ip-conversion-vol2 to master Closes #2508. Squashed commit of the following: commit 5b9d33f9cd352756831f63e34c4aea48674628c1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:15:17 2021 +0300 util: replace net.IPNet with pointer commit 680126de7d59464077f9edf1bbaa925dd3fcee19 Merge: d3ba6a6c 5a50efad Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Jan 20 17:02:41 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit d3ba6a6cdd01c0aa736418fdb86ed40120169fe9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 18:29:54 2021 +0300 all: remove last conversion commit 88b63f11a6c3f8705d7fa0c448c50dd646cc9214 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Jan 19 14:12:45 2021 +0300 all: improve code quality commit 71af60c70a0dbaf55e2221023d6d2e4993c9e9a7 Merge: 98af3784 9f75725d Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 17:13:27 2021 +0300 Merge branch 'master' into 2508-ip-conversion-vol2 commit 98af3784ce44d0993d171653c13d6e83bb8d1e6a Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:32:53 2021 +0300 all: log changes commit e99595a172bae1e844019d344544be84ddd65e4e Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Jan 18 16:06:49 2021 +0300 all: fix or remove remaining net.IP <-> string conversions commit 7fd0634ce945f7e4c9b856684c5199f8a84a543e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Jan 15 15:36:17 2021 +0300 all: remove redundant net.IP <-> string converions commit 5df8af030421237d41b67ed659f83526cc258199 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:35:25 2021 +0300 stats: remove redundant net.IP <-> string conversion commit fbe4e3fc015e6898063543a90c04401d76dbb18f Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Jan 14 16:20:35 2021 +0300 querylog: remove redundant net.IP <-> string conversion
2021-01-20 17:27:53 +03:00
// localFrontend forces AdGuard Home to use the frontend files from disk
// rather than the ones that have been compiled into the binary.
localFrontend bool
}
// initCmdLineOpts completes initialization of the global command-line option
// slice. It must only be called once.
func initCmdLineOpts() {
// The --help option cannot be put directly into cmdLineOpts, because that
// causes initialization cycle due to printHelp referencing cmdLineOpts.
cmdLineOpts = append(cmdLineOpts, cmdLineOpt{
updateWithValue: nil,
updateNoValue: nil,
effect: func(o options, exec string) (effect, error) {
return func() error { printHelp(exec); exitWithError(); return nil }, nil
},
serialize: func(o options) (val string, ok bool) { return "", false },
description: "Print this help.",
longName: "help",
shortName: "",
})
}
// effect is the type for functions used for their side-effects.
type effect func() (err error)
// cmdLineOpt contains the data for a single command-line option. Only one of
// updateWithValue, updateNoValue, and effect must be present.
type cmdLineOpt struct {
updateWithValue func(o options, v string) (updated options, err error)
updateNoValue func(o options) (updated options, err error)
effect func(o options, exec string) (eff effect, err error)
// serialize is a function that encodes the option into a slice of
// command-line arguments, if necessary. If ok is false, this option should
// be skipped.
serialize func(o options) (val string, ok bool)
description string
longName string
shortName string
}
// cmdLineOpts are all command-line options of AdGuard Home.
var cmdLineOpts = []cmdLineOpt{{
updateWithValue: func(o options, v string) (options, error) {
o.confFilename = v
return o, nil
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) {
return o.confFilename, o.confFilename != ""
},
description: "Path to the config file.",
longName: "config",
shortName: "c",
}, {
updateWithValue: func(o options, v string) (options, error) { o.workDir = v; return o, nil },
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) { return o.workDir, o.workDir != "" },
description: "Path to the working directory.",
longName: "work-dir",
shortName: "w",
}, {
updateWithValue: func(o options, v string) (oo options, err error) {
o.bindHost, err = netip.ParseAddr(v)
return o, err
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) {
if !o.bindHost.IsValid() {
return "", false
}
return o.bindHost.String(), true
},
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
description: "Deprecated. Host address to bind HTTP server on. Use --web-addr. " +
"The short -h will work as --help in the future.",
longName: "host",
shortName: "h",
}, {
updateWithValue: func(o options, v string) (options, error) {
p, err := strconv.ParseUint(v, 10, 16)
if err != nil {
err = fmt.Errorf("parsing port: %w", err)
} else {
o.bindPort = uint16(p)
}
return o, err
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) {
if o.bindPort == 0 {
return "", false
}
return strconv.Itoa(int(o.bindPort)), true
},
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
description: "Deprecated. Port to serve HTTP pages on. Use --web-addr.",
longName: "port",
shortName: "p",
Pull request: web-addr-cmdline Merge in DNS/adguard-home from web-addr-cmdline to master Squashed commit of the following: commit 27652dbfae227f9a9f4d921f14af1e5897d7830d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:51:43 2023 +0400 home: web-addr opt commit b234d108e70fed3ff11eeb4986946f8a50dda515 Merge: eef1b5cbb 66345e855 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:10:57 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline # Conflicts: # CHANGELOG.md commit eef1b5cbb9f7dd9819c8038800a4bbcf3ff575aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 17:04:12 2023 +0400 all: docs Updates #4231. commit b4adb0bae82e44101f7b6685a29926c3d02e95af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 16:58:12 2023 +0400 all: docker Updates #4231. commit a4012fddc50a3f5143136df8f3b865d7e1b9087c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:24:02 2023 +0400 all: docker commit bd5cc3308298b1022dea501c2fe79d96df24ce2a Merge: 36841dd85 123ca8738 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 22 11:22:51 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 36841dd85fe1d006e6ec518329cb8ceea0915599 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:53:40 2023 +0400 all: docker commit 5c4756a56d251f1486b92f333f11485b5f4807f4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:50:41 2023 +0400 all: imp docs commit 7b6fba81f2d5a354bdf259d812d04f3bd64de0c6 Merge: 54c119024 ca313521d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 21 11:47:36 2023 +0400 Merge remote-tracking branch 'origin/master' into web-addr-cmdline commit 54c119024f3999d5c4dec06b21e3bb78803bf388 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:57:54 2023 +0400 home: imp code commit c87e0a690376aa6a28a018c3cbbb5de0ad16333d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:56:45 2023 +0400 all: imp docs commit de240d00e334f7fd3dbf39ac08472183deeb32db Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 15:54:27 2023 +0400 all: docker commit 568d5371e73fb6c5ba19a036e7a5135764f6538b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:38:53 2023 +0400 all: docs commit 407e230c8e3bc293e8d533ca5db1f28fec4b3c54 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:24:23 2023 +0400 home: deprecate opts commit 6e628fad6f4ee9f23213eeb55bec500db4435175 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 20 13:18:10 2023 +0400 home: web-addr opt
2023-06-23 10:03:01 +03:00
}, {
updateWithValue: func(o options, v string) (oo options, err error) {
o.bindAddr, err = netip.ParseAddrPort(v)
return o, err
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) {
return o.bindAddr.String(), o.bindAddr.IsValid()
},
description: "Address to serve the web UI on, in the host:port format.",
longName: "web-addr",
shortName: "",
}, {
updateWithValue: func(o options, v string) (options, error) {
o.serviceControlAction = v
return o, nil
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) {
return o.serviceControlAction, o.serviceControlAction != ""
},
description: `Service control action: status, install (as a service), ` +
`uninstall (as a service), start, stop, restart, reload (configuration).`,
longName: "service",
shortName: "s",
}, {
updateWithValue: func(o options, v string) (options, error) { o.logFile = v; return o, nil },
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) { return o.logFile, o.logFile != "" },
description: `Path to log file. If empty, write to stdout; ` +
`if "syslog", write to system log.`,
longName: "logfile",
shortName: "l",
}, {
updateWithValue: func(o options, v string) (options, error) { o.pidFile = v; return o, nil },
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) { return o.pidFile, o.pidFile != "" },
description: "Path to a file where PID is stored.",
longName: "pidfile",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.checkConfig = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.checkConfig },
description: "Check configuration and exit.",
longName: "check-config",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.disableUpdate = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.disableUpdate },
description: "Don't check for updates.",
longName: "no-check-update",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.performUpdate = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.performUpdate },
Pull request: 5191-update-flag Merge in DNS/adguard-home from 5191-update-flag to master Updates #5191. Updates #4223. Squashed commit of the following: commit fbace4942844dc67f2467479385e06843c3abb6a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Jan 9 12:05:16 2023 +0400 all: imp code, docs commit 8237dceb771ba95f545f79565d76cbb4ebd0d805 Merge: ca9518f2 bbdcc673 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Dec 30 14:45:55 2022 +0400 Merge branch 'master' into 5191-update-flag commit ca9518f20e5643572adf9734b93a5436ba30c865 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 20:36:33 2022 +0400 home: imp code commit 1dc6c7c3480df3df4a5f3f923f1feab7761a7945 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 18:26:08 2022 +0400 all: imp code, docs commit 7bbe893e98063b956482fd6f1c6be95a4f1956cf Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 03:44:48 2022 +0400 home: restart service on update commit e0d3c287a7e1c05b1e397f4727c447a1fcd9f7f6 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 03:22:49 2022 +0400 all: update on first run commit 0aa4e78f03bf3819425accb468ce59e747506ef3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 02:47:30 2022 +0400 all: move some code to init less commit 68aebfa050b9965afef26653e9b699ff4aaf5b8b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 29 00:36:00 2022 +0400 WIP commit 2c7fb97d701ac158613c5a3a4d4d35c5b79b3d59 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 28 14:15:59 2022 +0400 home: imp logs commit 4b06d089da835d6d187803bbb5ca1caf9973e2d3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Dec 27 19:21:17 2022 +0400 all: fix update flag
2023-01-09 13:38:31 +03:00
description: "Update the current binary and restart the service in case it's installed.",
longName: "update",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: nil,
effect: func(_ options, _ string) (f effect, err error) {
log.Info("warning: using --no-mem-optimization flag has no effect and is deprecated")
return nil, nil
},
serialize: func(o options) (val string, ok bool) { return "", false },
description: "Deprecated. Disable memory optimization.",
longName: "no-mem-optimization",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.noEtcHosts = true; return o, nil },
effect: func(_ options, _ string) (f effect, err error) {
log.Info(
"warning: --no-etc-hosts flag is deprecated " +
"and will be removed in the future versions; " +
"set clients.runtime_sources.hosts and dns.hostsfile_enabled " +
"in the configuration file to false instead",
)
return nil, nil
},
serialize: func(o options) (val string, ok bool) { return "", o.noEtcHosts },
description: "Deprecated: use clients.runtime_sources.hosts and dns.hostsfile_enabled " +
"instead. Do not use the OS-provided hosts.",
longName: "no-etc-hosts",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.localFrontend = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.localFrontend },
description: "Use local frontend directories.",
longName: "local-frontend",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.verbose = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.verbose },
description: "Enable verbose output.",
longName: "verbose",
shortName: "v",
}, {
updateWithValue: nil,
updateNoValue: func(o options) (options, error) { o.glinetMode = true; return o, nil },
effect: nil,
serialize: func(o options) (val string, ok bool) { return "", o.glinetMode },
description: "Run in GL-Inet compatibility mode.",
longName: "glinet",
shortName: "",
}, {
updateWithValue: nil,
updateNoValue: nil,
effect: func(o options, exec string) (effect, error) {
return func() error {
if o.verbose {
fmt.Print(version.Verbose(configmigrate.LastSchemaVersion))
} else {
fmt.Println(version.Full())
}
os.Exit(0)
return nil
}, nil
},
serialize: func(o options) (val string, ok bool) { return "", false },
description: "Show the version and exit. Show more detailed version description with -v.",
longName: "version",
shortName: "",
}}
// printHelp prints the entire help message. It exits with an error code if
// there are any I/O errors.
func printHelp(exec string) {
b := &strings.Builder{}
stringutil.WriteToBuilder(
b,
"Usage:\n\n",
fmt.Sprintf("%s [options]\n\n", exec),
"Options:\n",
)
var err error
for _, opt := range cmdLineOpts {
val := ""
if opt.updateWithValue != nil {
val = " VALUE"
}
longDesc := opt.longName + val
if opt.shortName != "" {
_, err = fmt.Fprintf(b, " -%s, --%-28s %s\n", opt.shortName, longDesc, opt.description)
} else {
_, err = fmt.Fprintf(b, " --%-32s %s\n", longDesc, opt.description)
}
if err != nil {
// The only error here can be from incorrect Fprintf usage, which is
// a programmer error.
panic(err)
}
}
_, err = fmt.Print(b)
if err != nil {
// Exit immediately, since not being able to print out a help message
// essentially means that the I/O is very broken at the moment.
exitWithError()
}
}
// parseCmdOpts parses the command-line arguments into options and effects.
func parseCmdOpts(cmdName string, args []string) (o options, eff effect, err error) {
// Don't use range since the loop changes the loop variable.
argsLen := len(args)
for i := 0; i < len(args); i++ {
arg := args[i]
isKnown := false
for _, opt := range cmdLineOpts {
isKnown = argMatches(opt, arg)
if !isKnown {
continue
}
if opt.updateWithValue != nil {
i++
if i >= argsLen {
return o, eff, fmt.Errorf("got %s without argument", arg)
}
o, err = opt.updateWithValue(o, args[i])
} else {
o, eff, err = updateOptsNoValue(o, eff, opt, cmdName)
}
if err != nil {
return o, eff, fmt.Errorf("applying option %s: %w", arg, err)
}
break
}
if !isKnown {
return o, eff, fmt.Errorf("unknown option %s", arg)
}
}
return o, eff, err
}
// argMatches returns true if arg matches command-line option opt.
func argMatches(opt cmdLineOpt, arg string) (ok bool) {
if arg == "" || arg[0] != '-' {
return false
}
arg = arg[1:]
if arg == "" {
return false
}
return (opt.shortName != "" && arg == opt.shortName) ||
(arg[0] == '-' && arg[1:] == opt.longName)
}
// updateOptsNoValue sets values or effects from opt into o or prev.
func updateOptsNoValue(
o options,
prev effect,
opt cmdLineOpt,
cmdName string,
) (updated options, chained effect, err error) {
if opt.updateNoValue != nil {
o, err = opt.updateNoValue(o)
if err != nil {
return o, prev, err
}
return o, prev, nil
}
next, err := opt.effect(o, cmdName)
if err != nil {
return o, prev, err
}
chained = chainEffect(prev, next)
return o, chained, nil
}
// chainEffect chans the next effect after the prev one. If prev is nil, eff
// only calls next. If next is nil, eff is prev; if prev is nil, eff is next.
func chainEffect(prev, next effect) (eff effect) {
if prev == nil {
return next
} else if next == nil {
return prev
}
eff = func() (err error) {
err = prev()
if err != nil {
return err
}
return next()
}
return eff
}
// optsToArgs converts command line options into a list of arguments.
func optsToArgs(o options) (args []string) {
for _, opt := range cmdLineOpts {
val, ok := opt.serialize(o)
if !ok {
continue
}
if opt.shortName != "" {
args = append(args, "-"+opt.shortName)
} else {
args = append(args, "--"+opt.longName)
}
if val != "" {
args = append(args, val)
}
}
return args
}