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

Squashed commit of the following:

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

    all: imp docs

commit aef2460bdc70c438c1d5d09e1ee731a9770bdcb4
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 committed 2025-09-15 15:36:42 +03:00
1 parent e5c4e24e16
commit 83d484031f
5 files changed
+45 -2

No files matched your search

+4
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. 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 ### Security
- Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.25.1][go-1.25.1]. - Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.25.1][go-1.25.1].
+1 -1
View File
@@ -375,7 +375,7 @@ export const Settings = ({ handleSubmit, handleFix, validateForm, config, interf
type="number" type="number"
data-testid="install_dns_port" data-testid="install_dns_port"
error={fieldState.error?.message} error={fieldState.error?.message}
placeholder={STANDARD_WEB_PORT.toString()} placeholder={STANDARD_DNS_PORT.toString()}
onChange={(e) => { onChange={(e) => {
const { value } = e.target; const { value } = e.target;
field.onChange(toNumber(value)); field.onChange(toNumber(value));
+1 -1
View File
@@ -46,7 +46,7 @@ func (web *webAPI) handleInstallGetAddresses(w http.ResponseWriter, r *http.Requ
data := getAddrsResponse{ data := getAddrsResponse{
Version: version.Version(), Version: version.Version(),
WebPort: int(defaultPortHTTP), WebPort: int(web.conf.defaultWebPort),
DNSPort: int(defaultPortDNS), DNSPort: int(defaultPortDNS),
} }
+36
View File
@@ -14,6 +14,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"slices" "slices"
"strconv"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@@ -575,6 +576,8 @@ func initWeb(
) (web *webAPI, err error) { ) (web *webAPI, err error) {
logger := baseLogger.With(slogutil.KeyPrefix, "webapi") logger := baseLogger.With(slogutil.KeyPrefix, "webapi")
webPort := suggestedWebPort(ctx, logger)
var clientFS fs.FS var clientFS fs.FS
if opts.localFrontend { if opts.localFrontend {
logger.WarnContext(ctx, "using local frontend files") logger.WarnContext(ctx, "using local frontend files")
@@ -606,6 +609,8 @@ func initWeb(
ReadHeaderTimeout: readHdrTimeout, ReadHeaderTimeout: readHdrTimeout,
WriteTimeout: writeTimeout, WriteTimeout: writeTimeout,
defaultWebPort: webPort,
firstRun: globalContext.firstRun, firstRun: globalContext.firstRun,
disableUpdate: disableUpdate, disableUpdate: disableUpdate,
runningAsService: opts.runningAsService, runningAsService: opts.runningAsService,
@@ -620,6 +625,37 @@ func initWeb(
return web, nil 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) { func fatalOnError(err error) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
+3
View File
@@ -80,6 +80,9 @@ type webConfig struct {
// appropriate field. // appropriate field.
WriteTimeout time.Duration WriteTimeout time.Duration
// defaultWebPort is the suggested default HTTP port for the install wizard.
defaultWebPort uint16
firstRun bool firstRun bool
// disableUpdate, if true, tells AdGuard Home to not check for updates. // disableUpdate, if true, tells AdGuard Home to not check for updates.