Skip to content

Commit

Permalink
home: imp cyclo
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed May 31, 2021
1 parent c304a0b commit f6abe0b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
99 changes: 48 additions & 51 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,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{}
Expand All @@ -642,59 +663,35 @@ func printHTTPAddresses(proto string) {
port = tlsConf.PortHTTPS
}

var hostStr string
const (
hostMsg = "Go to %s://%s"
hostBetaMsg = hostMsg + " (BETA)"
)
// TODO(e.burkov): Inspect and perhaps merge with the previous
// condition.
if proto == schemeHTTPS && tlsConf.ServerName != "" {
if tlsConf.PortHTTPS == 443 {
log.Printf(hostMsg, proto, tlsConf.ServerName)
} else {
log.Printf(hostMsg, proto, aghnet.JoinHostPort(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.
//
// TODO(e.burkov): Find out when it happens.
hostStr = config.BindHost.String()
log.Printf(hostMsg, proto, aghnet.JoinHostPort(hostStr, port))
if config.BetaBindPort != 0 {
log.Printf(hostBetaMsg, proto, aghnet.JoinHostPort(
hostStr,
config.BetaBindPort,
))
}
printWebAddrs(proto, tlsConf.ServerName, tlsConf.PortHTTPS, 0)

return
}
return
}

for _, iface := range ifaces {
for _, addr := range iface.Addresses {
hostStr = addr.String()
log.Printf(hostMsg, proto, aghnet.JoinHostPort(
hostStr,
config.BindPort,
))
if config.BetaBindPort != 0 {
log.Printf(hostBetaMsg, proto, aghnet.JoinHostPort(
hostStr,
config.BetaBindPort,
))
}
}
}
} else {
hostStr = config.BindHost.String()
log.Printf(hostMsg, proto, aghnet.JoinHostPort(hostStr, port))
if config.BetaBindPort != 0 {
log.Printf(hostBetaMsg, proto, aghnet.JoinHostPort(
hostStr,
config.BetaBindPort,
))
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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/home/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/home/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,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()

Expand Down

0 comments on commit f6abe0b

Please sign in to comment.