Pull request 2474: AGDNS-3196-web-port-env

Squashed commit of the following:

commit 0e1ba286f7
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Sep 9 17:01:50 2025 +0300

    all: imp docs

commit aef2460bdc
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Sep 9 11:01:13 2025 +0300

    all: web port env
This commit is contained in:
Stanislav Chzhen 2025-09-15 15:36:42 +03:00
parent e5c4e24e16
commit 83d484031f
5 changed files with 45 additions and 2 deletions

View File

@ -18,6 +18,10 @@ See also the [v0.107.66 GitHub milestone][ms-v0.107.66].
NOTE: Add new changes BELOW THIS COMMENT.
-->
### Added
- Support for configuring the suggested default HTTP port for the installation wizard via the `ADGUARD_HOME_DEFAULT_WEB_PORT` environment variable (useful for vendors).
### Security
- Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.25.1][go-1.25.1].

View File

@ -375,7 +375,7 @@ export const Settings = ({ handleSubmit, handleFix, validateForm, config, interf
type="number"
data-testid="install_dns_port"
error={fieldState.error?.message}
placeholder={STANDARD_WEB_PORT.toString()}
placeholder={STANDARD_DNS_PORT.toString()}
onChange={(e) => {
const { value } = e.target;
field.onChange(toNumber(value));

View File

@ -46,7 +46,7 @@ func (web *webAPI) handleInstallGetAddresses(w http.ResponseWriter, r *http.Requ
data := getAddrsResponse{
Version: version.Version(),
WebPort: int(defaultPortHTTP),
WebPort: int(web.conf.defaultWebPort),
DNSPort: int(defaultPortDNS),
}

View File

@ -14,6 +14,7 @@ import (
"path/filepath"
"runtime"
"slices"
"strconv"
"sync"
"syscall"
"time"
@ -575,6 +576,8 @@ func initWeb(
) (web *webAPI, err error) {
logger := baseLogger.With(slogutil.KeyPrefix, "webapi")
webPort := suggestedWebPort(ctx, logger)
var clientFS fs.FS
if opts.localFrontend {
logger.WarnContext(ctx, "using local frontend files")
@ -606,6 +609,8 @@ func initWeb(
ReadHeaderTimeout: readHdrTimeout,
WriteTimeout: writeTimeout,
defaultWebPort: webPort,
firstRun: globalContext.firstRun,
disableUpdate: disableUpdate,
runningAsService: opts.runningAsService,
@ -620,6 +625,37 @@ func initWeb(
return web, nil
}
// suggestedWebPort returns the suggested default HTTP port for the installation
// wizard, using the port provided via an environment variable. It falls back
// to [defaultPortHTTP] on error.
func suggestedWebPort(ctx context.Context, l *slog.Logger) (p uint16) {
const webPortEnv = "ADGUARD_HOME_DEFAULT_WEB_PORT"
s := os.Getenv(webPortEnv)
if s == "" {
return defaultPortHTTP
}
v, err := strconv.ParseUint(s, 10, 16)
if err == nil && v == 0 {
err = errors.ErrOutOfRange
}
if err != nil {
l.WarnContext(
ctx,
"invalid web port; using default",
"env", webPortEnv,
"val", s,
slogutil.KeyError, err,
)
return defaultPortHTTP
}
return uint16(v)
}
func fatalOnError(err error) {
if err != nil {
log.Fatal(err)

View File

@ -80,6 +80,9 @@ type webConfig struct {
// appropriate field.
WriteTimeout time.Duration
// defaultWebPort is the suggested default HTTP port for the install wizard.
defaultWebPort uint16
firstRun bool
// disableUpdate, if true, tells AdGuard Home to not check for updates.