Pull request: 3172 fix mobileconfig
Merge in DNS/adguard-home from 3172-mobileconfig to master
Updates #3172.
Updates #2497.
Squashed commit of the following:
commit 30549ef4eda9d88f0738089e901492d7369caa25
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jun 1 21:00:17 2021 +0300
all: log changes
commit 9b9429447430a8e5656b992c04c4a74606dc5f9f
Author: Ildar Kamalov <ik@adguard.com>
Date: Tue Jun 1 17:56:59 2021 +0300
client: always show port input
commit 6d6a0bdfaa849220a5ddb4a17502ab05379d7a1c
Merge: 13a3bffd 77946a7f
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jun 1 17:50:41 2021 +0300
Merge branch 'master' into 3172-mobileconfig
commit 13a3bffd4dd6ccabf3d261f17b2c758a5c61eb9c
Author: Ildar Kamalov <ik@adguard.com>
Date: Tue Jun 1 17:20:17 2021 +0300
client: add port to mobile config form
commit f6abe0b6044572f3801c31b683e76f90c4a28487
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Mon May 31 19:43:37 2021 +0300
home: imp cyclo
commit c304a0bacdca6f8b5ffd21f3d00c8244ea9e4e36
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Mon May 31 18:19:46 2021 +0300
home: reduce allocs
commit 10a7678861079b710bb0ef14569c60a09612ec70
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Mon May 24 20:05:08 2021 +0300
all: make the host parameter required
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||
@@ -38,9 +37,11 @@ func httpError(w http.ResponseWriter, code int, format string, args ...interface
|
||||
// addresses to a slice of strings.
|
||||
func appendDNSAddrs(dst []string, addrs ...net.IP) (res []string) {
|
||||
for _, addr := range addrs {
|
||||
hostport := addr.String()
|
||||
var hostport string
|
||||
if config.DNS.Port != 53 {
|
||||
hostport = net.JoinHostPort(hostport, strconv.Itoa(config.DNS.Port))
|
||||
hostport = aghnet.JoinHostPort(addr.String(), config.DNS.Port)
|
||||
} else {
|
||||
hostport = addr.String()
|
||||
}
|
||||
|
||||
dst = append(dst, hostport)
|
||||
@@ -303,8 +304,7 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
|
||||
if r.TLS == nil && web.forceHTTPS {
|
||||
hostPort := host
|
||||
if port := web.conf.PortHTTPS; port != defaultHTTPSPort {
|
||||
portStr := strconv.Itoa(port)
|
||||
hostPort = net.JoinHostPort(host, portStr)
|
||||
hostPort = aghnet.JoinHostPort(host, port)
|
||||
}
|
||||
|
||||
httpsURL := &url.URL{
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -286,42 +285,48 @@ func shutdownSrv(ctx context.Context, cancel context.CancelFunc, srv *http.Serve
|
||||
|
||||
// Apply new configuration, start DNS server, restart Web server
|
||||
func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
newSettings := applyConfigReq{}
|
||||
err := json.NewDecoder(r.Body).Decode(&newSettings)
|
||||
req := applyConfigReq{}
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "Failed to parse 'configure' JSON: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if newSettings.Web.Port == 0 || newSettings.DNS.Port == 0 {
|
||||
if req.Web.Port == 0 || req.DNS.Port == 0 {
|
||||
httpError(w, http.StatusBadRequest, "port value can't be 0")
|
||||
return
|
||||
}
|
||||
|
||||
restartHTTP := true
|
||||
if config.BindHost.Equal(newSettings.Web.IP) && config.BindPort == newSettings.Web.Port {
|
||||
if config.BindHost.Equal(req.Web.IP) && config.BindPort == req.Web.Port {
|
||||
// no need to rebind
|
||||
restartHTTP = false
|
||||
}
|
||||
|
||||
// validate that hosts and ports are bindable
|
||||
if restartHTTP {
|
||||
err = aghnet.CheckPortAvailable(newSettings.Web.IP, newSettings.Web.Port)
|
||||
err = aghnet.CheckPortAvailable(req.Web.IP, req.Web.Port)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s due to %s",
|
||||
net.JoinHostPort(newSettings.Web.IP.String(), strconv.Itoa(newSettings.Web.Port)), err)
|
||||
httpError(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"can not listen on IP:port %s: %s",
|
||||
aghnet.JoinHostPort(req.Web.IP.String(), req.Web.Port),
|
||||
err,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = aghnet.CheckPacketPortAvailable(newSettings.DNS.IP, newSettings.DNS.Port)
|
||||
err = aghnet.CheckPacketPortAvailable(req.DNS.IP, req.DNS.Port)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = aghnet.CheckPortAvailable(newSettings.DNS.IP, newSettings.DNS.Port)
|
||||
err = aghnet.CheckPortAvailable(req.DNS.IP, req.DNS.Port)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusBadRequest, "%s", err)
|
||||
return
|
||||
@@ -331,10 +336,10 @@ func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
copyInstallSettings(&curConfig, &config)
|
||||
|
||||
Context.firstRun = false
|
||||
config.BindHost = newSettings.Web.IP
|
||||
config.BindPort = newSettings.Web.Port
|
||||
config.DNS.BindHosts = []net.IP{newSettings.DNS.IP}
|
||||
config.DNS.Port = newSettings.DNS.Port
|
||||
config.BindHost = req.Web.IP
|
||||
config.BindPort = req.Web.Port
|
||||
config.DNS.BindHosts = []net.IP{req.DNS.IP}
|
||||
config.DNS.Port = req.DNS.Port
|
||||
|
||||
// TODO(e.burkov): StartMods() should be put in a separate goroutine at
|
||||
// the moment we'll allow setting up TLS in the initial configuration or
|
||||
@@ -349,8 +354,8 @@ func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
u := User{}
|
||||
u.Name = newSettings.Username
|
||||
Context.auth.UserAdd(&u, newSettings.Password)
|
||||
u.Name = req.Username
|
||||
Context.auth.UserAdd(&u, req.Password)
|
||||
|
||||
err = config.write()
|
||||
if err != nil {
|
||||
@@ -361,8 +366,8 @@ func (web *Web) handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
web.conf.firstRun = false
|
||||
web.conf.BindHost = newSettings.Web.IP
|
||||
web.conf.BindPort = newSettings.Web.Port
|
||||
web.conf.BindHost = req.Web.IP
|
||||
web.conf.BindPort = req.Web.Port
|
||||
|
||||
registerControlHandlers()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||
@@ -254,7 +253,7 @@ func getDNSEncryption() (de dnsEncryption) {
|
||||
if tlsConf.PortHTTPS != 0 {
|
||||
addr := hostname
|
||||
if tlsConf.PortHTTPS != 443 {
|
||||
addr = net.JoinHostPort(addr, strconv.Itoa(tlsConf.PortHTTPS))
|
||||
addr = aghnet.JoinHostPort(addr, tlsConf.PortHTTPS)
|
||||
}
|
||||
|
||||
de.https = (&url.URL{
|
||||
@@ -267,14 +266,14 @@ func getDNSEncryption() (de dnsEncryption) {
|
||||
if tlsConf.PortDNSOverTLS != 0 {
|
||||
de.tls = (&url.URL{
|
||||
Scheme: "tls",
|
||||
Host: net.JoinHostPort(hostname, strconv.Itoa(tlsConf.PortDNSOverTLS)),
|
||||
Host: aghnet.JoinHostPort(hostname, tlsConf.PortDNSOverTLS),
|
||||
}).String()
|
||||
}
|
||||
|
||||
if tlsConf.PortDNSOverQUIC != 0 {
|
||||
de.quic = (&url.URL{
|
||||
Scheme: "quic",
|
||||
Host: net.JoinHostPort(hostname, strconv.Itoa(int(tlsConf.PortDNSOverQUIC))),
|
||||
Host: aghnet.JoinHostPort(hostname, tlsConf.PortDNSOverQUIC),
|
||||
}).String()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -630,7 +629,28 @@ func loadOptions() options {
|
||||
return o
|
||||
}
|
||||
|
||||
// printHTTPAddresses prints the IP addresses which user can use to open the
|
||||
// printWebAddrs prints addresses built from proto, addr, and an appropriate
|
||||
// port. At least one address is printed with the value of port. If the value
|
||||
// of betaPort is 0, the second address is not printed. The output example:
|
||||
//
|
||||
// Go to http://127.0.0.1:80
|
||||
// Go to http://127.0.0.1:3000 (BETA)
|
||||
//
|
||||
func printWebAddrs(proto, addr string, port, betaPort int) {
|
||||
const (
|
||||
hostMsg = "Go to %s://%s"
|
||||
hostBetaMsg = hostMsg + " (BETA)"
|
||||
)
|
||||
|
||||
log.Printf(hostMsg, proto, aghnet.JoinHostPort(addr, port))
|
||||
if betaPort == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf(hostBetaMsg, proto, aghnet.JoinHostPort(addr, config.BetaBindPort))
|
||||
}
|
||||
|
||||
// printHTTPAddresses prints the IP addresses which user can use to access the
|
||||
// admin interface. proto is either schemeHTTP or schemeHTTPS.
|
||||
func printHTTPAddresses(proto string) {
|
||||
tlsConf := tlsConfigSettings{}
|
||||
@@ -638,45 +658,40 @@ func printHTTPAddresses(proto string) {
|
||||
Context.tls.WriteDiskConfig(&tlsConf)
|
||||
}
|
||||
|
||||
port := strconv.Itoa(config.BindPort)
|
||||
port := config.BindPort
|
||||
if proto == schemeHTTPS {
|
||||
port = strconv.Itoa(tlsConf.PortHTTPS)
|
||||
port = tlsConf.PortHTTPS
|
||||
}
|
||||
|
||||
var hostStr string
|
||||
// TODO(e.burkov): Inspect and perhaps merge with the previous
|
||||
// condition.
|
||||
if proto == schemeHTTPS && tlsConf.ServerName != "" {
|
||||
if tlsConf.PortHTTPS == 443 {
|
||||
log.Printf("Go to https://%s", tlsConf.ServerName)
|
||||
} else {
|
||||
log.Printf("Go to https://%s:%s", tlsConf.ServerName, port)
|
||||
}
|
||||
} else if config.BindHost.IsUnspecified() {
|
||||
log.Println("AdGuard Home is available on the following addresses:")
|
||||
ifaces, err := aghnet.GetValidNetInterfacesForWeb()
|
||||
if err != nil {
|
||||
// That's weird, but we'll ignore it
|
||||
hostStr = config.BindHost.String()
|
||||
log.Printf("Go to %s://%s", proto, net.JoinHostPort(hostStr, port))
|
||||
if config.BetaBindPort != 0 {
|
||||
log.Printf("Go to %s://%s (BETA)", proto, net.JoinHostPort(hostStr, strconv.Itoa(config.BetaBindPort)))
|
||||
}
|
||||
return
|
||||
}
|
||||
printWebAddrs(proto, tlsConf.ServerName, tlsConf.PortHTTPS, 0)
|
||||
|
||||
for _, iface := range ifaces {
|
||||
for _, addr := range iface.Addresses {
|
||||
hostStr = addr.String()
|
||||
log.Printf("Go to %s://%s", proto, net.JoinHostPort(hostStr, strconv.Itoa(config.BindPort)))
|
||||
if config.BetaBindPort != 0 {
|
||||
log.Printf("Go to %s://%s (BETA)", proto, net.JoinHostPort(hostStr, strconv.Itoa(config.BetaBindPort)))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hostStr = config.BindHost.String()
|
||||
log.Printf("Go to %s://%s", proto, net.JoinHostPort(hostStr, port))
|
||||
if config.BetaBindPort != 0 {
|
||||
log.Printf("Go to %s://%s (BETA)", proto, net.JoinHostPort(hostStr, strconv.Itoa(config.BetaBindPort)))
|
||||
return
|
||||
}
|
||||
|
||||
bindhost := config.BindHost
|
||||
if !bindhost.IsUnspecified() {
|
||||
printWebAddrs(proto, bindhost.String(), port, config.BetaBindPort)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ifaces, err := aghnet.GetValidNetInterfacesForWeb()
|
||||
if err != nil {
|
||||
log.Error("web: getting iface ips: %s", err)
|
||||
// That's weird, but we'll ignore it.
|
||||
//
|
||||
// TODO(e.burkov): Find out when it happens.
|
||||
printWebAddrs(proto, bindhost.String(), port, config.BetaBindPort)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
for _, iface := range ifaces {
|
||||
for _, addr := range iface.Addresses {
|
||||
printWebAddrs(proto, addr.String(), config.BindPort, config.BetaBindPort)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"howett.net/plist"
|
||||
@@ -53,27 +54,27 @@ const (
|
||||
|
||||
func getMobileConfig(d dnsSettings) ([]byte, error) {
|
||||
var dspName string
|
||||
switch d.DNSProtocol {
|
||||
switch proto := d.DNSProtocol; proto {
|
||||
case dnsProtoHTTPS:
|
||||
dspName = fmt.Sprintf("%s DoH", d.ServerName)
|
||||
|
||||
u := &url.URL{
|
||||
Scheme: schemeHTTPS,
|
||||
Host: d.ServerName,
|
||||
Path: "/dns-query",
|
||||
Path: path.Join("/dns-query", d.clientID),
|
||||
}
|
||||
if d.clientID != "" {
|
||||
u.Path = path.Join(u.Path, d.clientID)
|
||||
}
|
||||
|
||||
d.ServerURL = u.String()
|
||||
// Empty the ServerName field since it is only must be presented
|
||||
// in DNS-over-TLS configuration.
|
||||
//
|
||||
// See https://developer.apple.com/documentation/devicemanagement/dnssettings/dnssettings.
|
||||
d.ServerName = ""
|
||||
case dnsProtoTLS:
|
||||
dspName = fmt.Sprintf("%s DoT", d.ServerName)
|
||||
if d.clientID != "" {
|
||||
d.ServerName = d.clientID + "." + d.ServerName
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("bad dns protocol %q", d.DNSProtocol)
|
||||
return nil, fmt.Errorf("bad dns protocol %q", proto)
|
||||
}
|
||||
|
||||
data := mobileConfig{
|
||||
@@ -99,25 +100,25 @@ func getMobileConfig(d dnsSettings) ([]byte, error) {
|
||||
return plist.MarshalIndent(data, plist.XMLFormat, "\t")
|
||||
}
|
||||
|
||||
func respondJSONError(w http.ResponseWriter, status int, msg string) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
err := json.NewEncoder(w).Encode(&jsonError{
|
||||
Message: msg,
|
||||
})
|
||||
if err != nil {
|
||||
log.Debug("writing %d json response: %s", status, err)
|
||||
}
|
||||
}
|
||||
|
||||
const errEmptyHost errors.Error = "no host in query parameters and no server_name"
|
||||
|
||||
func handleMobileConfig(w http.ResponseWriter, r *http.Request, dnsp string) {
|
||||
var err error
|
||||
|
||||
q := r.URL.Query()
|
||||
host := q.Get("host")
|
||||
if host == "" {
|
||||
host = Context.tls.conf.ServerName
|
||||
}
|
||||
|
||||
if host == "" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
const msg = "no host in query parameters and no server_name"
|
||||
err = json.NewEncoder(w).Encode(&jsonError{
|
||||
Message: msg,
|
||||
})
|
||||
if err != nil {
|
||||
log.Debug("writing 500 json response: %s", err)
|
||||
}
|
||||
respondJSONError(w, http.StatusInternalServerError, string(errEmptyHost))
|
||||
|
||||
return
|
||||
}
|
||||
@@ -126,14 +127,7 @@ func handleMobileConfig(w http.ResponseWriter, r *http.Request, dnsp string) {
|
||||
if clientID != "" {
|
||||
err = dnsforward.ValidateClientID(clientID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
err = json.NewEncoder(w).Encode(&jsonError{
|
||||
Message: err.Error(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Debug("writing 400 json response: %s", err)
|
||||
}
|
||||
respondJSONError(w, http.StatusBadRequest, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
@@ -147,7 +141,7 @@ func handleMobileConfig(w http.ResponseWriter, r *http.Request, dnsp string) {
|
||||
|
||||
mobileconfig, err := getMobileConfig(d)
|
||||
if err != nil {
|
||||
httpError(w, http.StatusInternalServerError, "plist.MarshalIndent: %s", err)
|
||||
respondJSONError(w, http.StatusInternalServerError, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -13,7 +15,7 @@ import (
|
||||
func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig?host=example.org", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -22,39 +24,11 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].Name)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].PayloadDisplayName)
|
||||
assert.Equal(t, "example.org", mc.PayloadContent[0].DNSSettings.ServerName)
|
||||
assert.Equal(t, "https://example.org/dns-query", mc.PayloadContent[0].DNSSettings.ServerURL)
|
||||
})
|
||||
|
||||
t.Run("success_no_host", func(t *testing.T) {
|
||||
oldTLSConf := Context.tls
|
||||
t.Cleanup(func() { Context.tls = oldTLSConf })
|
||||
|
||||
Context.tls = &TLSMod{
|
||||
conf: tlsConfigSettings{ServerName: "example.org"},
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig", nil)
|
||||
require.Nil(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOH(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].Name)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].PayloadDisplayName)
|
||||
assert.Equal(t, "example.org", mc.PayloadContent[0].DNSSettings.ServerName)
|
||||
assert.Equal(t, "https://example.org/dns-query", mc.PayloadContent[0].DNSSettings.ServerURL)
|
||||
})
|
||||
|
||||
@@ -65,17 +39,24 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
Context.tls = &TLSMod{conf: tlsConfigSettings{}}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
err = json.NewEncoder(b).Encode(&jsonError{
|
||||
Message: errEmptyHost.Error(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOH(w, r)
|
||||
assert.Equal(t, http.StatusInternalServerError, w.Code)
|
||||
assert.JSONEq(t, w.Body.String(), b.String())
|
||||
})
|
||||
|
||||
t.Run("client_id", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig?host=example.org&client_id=cli42", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -84,12 +65,11 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].Name)
|
||||
assert.Equal(t, "example.org DoH", mc.PayloadContent[0].PayloadDisplayName)
|
||||
assert.Equal(t, "example.org", mc.PayloadContent[0].DNSSettings.ServerName)
|
||||
assert.Equal(t, "https://example.org/dns-query/cli42", mc.PayloadContent[0].DNSSettings.ServerURL)
|
||||
})
|
||||
}
|
||||
@@ -97,7 +77,7 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig?host=example.org", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -106,33 +86,7 @@ func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoT", mc.PayloadContent[0].Name)
|
||||
assert.Equal(t, "example.org DoT", mc.PayloadContent[0].PayloadDisplayName)
|
||||
assert.Equal(t, "example.org", mc.PayloadContent[0].DNSSettings.ServerName)
|
||||
})
|
||||
|
||||
t.Run("success_no_host", func(t *testing.T) {
|
||||
oldTLSConf := Context.tls
|
||||
t.Cleanup(func() { Context.tls = oldTLSConf })
|
||||
|
||||
Context.tls = &TLSMod{
|
||||
conf: tlsConfigSettings{ServerName: "example.org"},
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig", nil)
|
||||
require.Nil(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOT(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoT", mc.PayloadContent[0].Name)
|
||||
@@ -147,17 +101,25 @@ func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
Context.tls = &TLSMod{conf: tlsConfigSettings{}}
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
err = json.NewEncoder(b).Encode(&jsonError{
|
||||
Message: errEmptyHost.Error(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOT(w, r)
|
||||
assert.Equal(t, http.StatusInternalServerError, w.Code)
|
||||
|
||||
assert.JSONEq(t, w.Body.String(), b.String())
|
||||
})
|
||||
|
||||
t.Run("client_id", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig?host=example.org&client_id=cli42", nil)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -166,7 +128,7 @@ func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
|
||||
var mc mobileConfig
|
||||
_, err = plist.Unmarshal(w.Body.Bytes(), &mc)
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, mc.PayloadContent, 1)
|
||||
assert.Equal(t, "example.org DoT", mc.PayloadContent[0].Name)
|
||||
|
||||
@@ -243,7 +243,8 @@ func handleServiceInstallCommand(s service.Service) {
|
||||
log.Printf(`Almost ready!
|
||||
AdGuard Home is successfully installed and will automatically start on boot.
|
||||
There are a few more things that must be configured before you can use it.
|
||||
Click on the link below and follow the Installation Wizard steps to finish setup.`)
|
||||
Click on the link below and follow the Installation Wizard steps to finish setup.
|
||||
AdGuard Home is now available at the following addresses:`)
|
||||
printHTTPAddresses(schemeHTTP)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -162,6 +161,8 @@ func (web *Web) TLSConfigChanged(ctx context.Context, tlsConf tlsConfigSettings)
|
||||
|
||||
// Start - start serving HTTP requests
|
||||
func (web *Web) Start() {
|
||||
log.Println("AdGuard Home is available at the following addresses:")
|
||||
|
||||
// for https, we have a separate goroutine loop
|
||||
go web.tlsServerLoop()
|
||||
|
||||
@@ -174,7 +175,7 @@ func (web *Web) Start() {
|
||||
// we need to have new instance, because after Shutdown() the Server is not usable
|
||||
web.httpServer = &http.Server{
|
||||
ErrorLog: log.StdLog("web: plain", log.DEBUG),
|
||||
Addr: net.JoinHostPort(hostStr, strconv.Itoa(web.conf.BindPort)),
|
||||
Addr: aghnet.JoinHostPort(hostStr, web.conf.BindPort),
|
||||
Handler: withMiddlewares(Context.mux, limitRequestBody),
|
||||
ReadTimeout: web.conf.ReadTimeout,
|
||||
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
|
||||
@@ -187,7 +188,7 @@ func (web *Web) Start() {
|
||||
if web.conf.BetaBindPort != 0 {
|
||||
web.httpServerBeta = &http.Server{
|
||||
ErrorLog: log.StdLog("web: plain", log.DEBUG),
|
||||
Addr: net.JoinHostPort(hostStr, strconv.Itoa(web.conf.BetaBindPort)),
|
||||
Addr: aghnet.JoinHostPort(hostStr, web.conf.BetaBindPort),
|
||||
Handler: withMiddlewares(Context.mux, limitRequestBody, web.wrapIndexBeta),
|
||||
ReadTimeout: web.conf.ReadTimeout,
|
||||
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
|
||||
@@ -248,7 +249,7 @@ func (web *Web) tlsServerLoop() {
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
|
||||
// prepare HTTPS server
|
||||
address := net.JoinHostPort(web.conf.BindHost.String(), strconv.Itoa(web.conf.PortHTTPS))
|
||||
address := aghnet.JoinHostPort(web.conf.BindHost.String(), web.conf.PortHTTPS)
|
||||
web.httpsServer.server = &http.Server{
|
||||
ErrorLog: log.StdLog("web: https", log.DEBUG),
|
||||
Addr: address,
|
||||
|
||||
Reference in New Issue
Block a user