mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 19:31:45 +03:00
Fill out port 80 if it's available, otherwise port 3000
This commit is contained in:
parent
34e14930de
commit
d97c426646
17
control.go
17
control.go
@ -697,6 +697,7 @@ func handleSafeSearchStatus(w http.ResponseWriter, r *http.Request) {
|
||||
type ipport struct {
|
||||
IP string `json:"ip"`
|
||||
Port int `json:"port"`
|
||||
Warning string `json:"warning"`
|
||||
}
|
||||
|
||||
type firstRunData struct {
|
||||
@ -720,8 +721,20 @@ func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// fill out the fields
|
||||
data.Web.Port = 3000 // TODO: find out if port 80 is available -- if not, fall back to 3000
|
||||
data.DNS.Port = 53 // TODO: find out if port 53 is available -- if not, show a big warning
|
||||
|
||||
// find out if port 80 is available -- if not, fall back to 3000
|
||||
if checkPortAvailable(80) {
|
||||
data.Web.Port = 80
|
||||
} else {
|
||||
data.Web.Port = 3000
|
||||
}
|
||||
|
||||
// find out if port 53 is available -- if not, show a big warning
|
||||
data.DNS.Port = 53
|
||||
if !checkPortAvailable(53) {
|
||||
data.DNS.Warning = "Port 53 is not available for binding -- this will make DNS clients unable to contact AdGuard Home."
|
||||
}
|
||||
|
||||
data.Interfaces = make(map[string]interface{})
|
||||
for _, iface := range ifaces {
|
||||
data.Interfaces[iface.Name] = iface
|
||||
|
10
helpers.go
10
helpers.go
@ -258,6 +258,16 @@ func findIPv4IfaceAddr(ifaces []netInterface) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// checkPortAvailable is not a cheap test to see if the port is bindable, because it's actually doing the bind momentarily
|
||||
func checkPortAvailable(port int) bool {
|
||||
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ln.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// debug logging helpers
|
||||
// ---------------------
|
||||
|
Loading…
Reference in New Issue
Block a user