Skip to content

Commit

Permalink
Pull request: web-addr-cmdline
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from web-addr-cmdline to master

Squashed commit of the following:

commit 27652db
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 17:51:43 2023 +0400

    home: web-addr opt

commit b234d10
Merge: eef1b5c 66345e8
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 17:10:57 2023 +0400

    Merge remote-tracking branch 'origin/master' into web-addr-cmdline

    # Conflicts:
    #	CHANGELOG.md

commit eef1b5c
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 17:04:12 2023 +0400

    all: docs

    Updates #4231.

commit b4adb0b
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 16:58:12 2023 +0400

    all: docker

    Updates #4231.

commit a4012fd
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 11:24:02 2023 +0400

    all: docker

commit bd5cc33
Merge: 36841dd 123ca87
Author: Dimitry Kolyshev <[email protected]>
Date:   Thu Jun 22 11:22:51 2023 +0400

    Merge remote-tracking branch 'origin/master' into web-addr-cmdline

commit 36841dd
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jun 21 11:53:40 2023 +0400

    all: docker

commit 5c4756a
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jun 21 11:50:41 2023 +0400

    all: imp docs

commit 7b6fba8
Merge: 54c1190 ca31352
Author: Dimitry Kolyshev <[email protected]>
Date:   Wed Jun 21 11:47:36 2023 +0400

    Merge remote-tracking branch 'origin/master' into web-addr-cmdline

commit 54c1190
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 15:57:54 2023 +0400

    home: imp code

commit c87e0a6
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 15:56:45 2023 +0400

    all: imp docs

commit de240d0
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 15:54:27 2023 +0400

    all: docker

commit 568d537
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 13:38:53 2023 +0400

    all: docs

commit 407e230
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 13:24:23 2023 +0400

    home: deprecate opts

commit 6e628fa
Author: Dimitry Kolyshev <[email protected]>
Date:   Tue Jun 20 13:18:10 2023 +0400

    home: web-addr opt
  • Loading branch information
Mizzick committed Jun 23, 2023
1 parent 66345e8 commit e54fc9b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ NOTE: Add new changes BELOW THIS COMMENT.

### Added

- The new command-line flag `--web-addr` is the address to serve the web UI on,
in the host:port format.
- The ability to set inactivity periods for filtering blocked services in the
configuration file ([#951]). The UI changes are coming in the upcoming
releases.
Expand Down Expand Up @@ -80,8 +82,15 @@ In this release, the schema version has changed from 20 to 21.
To rollback this change, replace `dns.blocked_services` object with the list
of ids of blocked services and change the `schema_version` back to `20`.

### Deprecated

- Flags `-h`, `--host`, `-p`, `--port` have been deprecated. The `-h` flag
will work as an alias for `--help`, instead of the deprecated `--host` in the
future releases.

### Fixed

- Cannot set `bind_host` in AdGuardHome.yaml (docker version) ([#4231]).
- The blocklists can now be deleted properly ([#5700]).
- Queries with the question-section target `.`, for example `NS .`, are now
counted in the statistics and correctly shown in the query log ([#5910]).
Expand All @@ -90,6 +99,7 @@ In this release, the schema version has changed from 20 to 21.

[#951]: https://github.com/AdguardTeam/AdGuardHome/issues/951
[#1577]: https://github.com/AdguardTeam/AdGuardHome/issues/1577
[#4231]: https://github.com/AdguardTeam/AdGuardHome/issues/4231
[#5700]: https://github.com/AdguardTeam/AdGuardHome/issues/5700
[#5910]: https://github.com/AdguardTeam/AdGuardHome/issues/5910
[#5913]: https://github.com/AdguardTeam/AdGuardHome/issues/5913
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ CMD [ \
"/opt/adguardhome/AdGuardHome", \
"--no-check-update", \
"-c", "/opt/adguardhome/conf/AdGuardHome.yaml", \
"-h", "0.0.0.0", \
"-w", "/opt/adguardhome/work" \
]
13 changes: 13 additions & 0 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ func setupBindOpts(opts options) (err error) {
config.BindHost = opts.bindHost
}

// Rewrite deprecated options.
bindAddr := opts.bindAddr
if bindAddr.IsValid() {
config.BindHost = bindAddr.Addr()
config.BindPort = int(bindAddr.Port())

err = checkPorts()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
}
}

return nil
}

Expand Down
30 changes: 26 additions & 4 deletions internal/home/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ type options struct {
serviceControlAction string

// bindHost is the address on which to serve the HTTP UI.
//
// Deprecated: Use bindAddr.
bindHost netip.Addr

// bindPort is the port on which to serve the HTTP UI.
//
// Deprecated: Use bindAddr.
bindPort int

// 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
Expand Down Expand Up @@ -147,9 +154,10 @@ var cmdLineOpts = []cmdLineOpt{{

return o.bindHost.String(), true
},
description: "Host address to bind HTTP server on.",
longName: "host",
shortName: "h",
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) {
var err error
Expand All @@ -174,9 +182,23 @@ var cmdLineOpts = []cmdLineOpt{{

return strconv.Itoa(o.bindPort), true
},
description: "Port to serve HTTP pages on.",
description: "Deprecated. Port to serve HTTP pages on. Use --web-addr.",
longName: "port",
shortName: "p",
}, {
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
Expand Down
21 changes: 21 additions & 0 deletions internal/home/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ func TestParseBindPort(t *testing.T) {
testParseErr(t, "port too high", "-p", "18446744073709551617") // 2^64 + 1
}

func TestParseBindAddr(t *testing.T) {
wantAddrPort := netip.MustParseAddrPort("1.2.3.4:8089")

assert.Zero(t, testParseOK(t).bindAddr, "empty is not web-addr")

assert.Equal(t, wantAddrPort, testParseOK(t, "--web-addr", "1.2.3.4:8089").bindAddr)
assert.Equal(t, netip.MustParseAddrPort("1.2.3.4:0"), testParseOK(t, "--web-addr", "1.2.3.4:0").bindAddr)
testParseParamMissing(t, "-web-addr")

testParseErr(t, "not an int", "--web-addr", "1.2.3.4:x")
testParseErr(t, "hex not supported", "--web-addr", "1.2.3.4:0x100")
testParseErr(t, "port negative", "--web-addr", "1.2.3.4:-1")
testParseErr(t, "port too high", "--web-addr", "1.2.3.4:65536")
testParseErr(t, "port too high", "--web-addr", "1.2.3.4:4294967297") // 2^32 + 1
testParseErr(t, "port too high", "--web-addr", "1.2.3.4:18446744073709551617") // 2^64 + 1
}

func TestParseLogfile(t *testing.T) {
assert.Equal(t, "", testParseOK(t).logFile, "empty is no log file")
assert.Equal(t, "path", testParseOK(t, "-l", "path").logFile, "-l is log file")
Expand Down Expand Up @@ -162,6 +179,10 @@ func TestOptsToArgs(t *testing.T) {
name: "bind_port",
args: []string{"-p", "666"},
opts: options{bindPort: 666},
}, {
name: "web-addr",
args: []string{"--web-addr", "1.2.3.4:8080"},
opts: options{bindAddr: netip.MustParseAddrPort("1.2.3.4:8080")},
}, {
name: "log_file",
args: []string{"-l", "path"},
Expand Down

0 comments on commit e54fc9b

Please sign in to comment.