Minor cleanup, added strings, added more information to response when error occurs

This commit is contained in:
Andrey Meshkov 2019-02-07 14:22:08 +03:00
parent f2d7f8161b
commit bb8d7c37bb
5 changed files with 21 additions and 37 deletions

1
app.go
View File

@ -149,6 +149,7 @@ func run(args options) {
// add handlers for /install paths, we only need them when we're not configured yet
if config.firstRun {
log.Printf("This is the first launch of AdGuard Home, redirecting everything to /install.html ")
http.Handle("/install.html", preInstallHandler(http.FileServer(box)))
registerInstallHandlers()
}

3
client/package-lock.json generated vendored
View File

@ -9122,7 +9122,8 @@
"merge": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/merge/-/merge-1.2.1.tgz",
"integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ=="
"integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==",
"dev": true
},
"merge-descriptors": {
"version": "1.0.1",

View File

@ -160,7 +160,7 @@
"filter_label": "Filter",
"unknown_filter": "Unknown filter {{filterId}}",
"install_welcome_title": "Welcome to AdGuard Home!",
"install_welcome_desc": "Lorem ipsum dolor sit amet consectetur adipisicing elit.",
"install_welcome_desc": "AdGuard Home is a network-wide ad-and-tracker blocking DNS server. Its purpose is to let you control your entire network and all your devices, and it does not require using a client-side program.",
"install_settings_title": "Admin Web Interface",
"install_settings_listen": "Listen interface",
"install_settings_port": "Port",

View File

@ -723,7 +723,7 @@ func handleInstallGetAddresses(w http.ResponseWriter, r *http.Request) {
// fill out the fields
// find out if port 80 is available -- if not, fall back to 3000
if checkPortAvailable("", 80) {
if checkPortAvailable("", 80) == nil {
data.Web.Port = 80
} else {
data.Web.Port = 3000
@ -731,15 +731,15 @@ func handleInstallGetAddresses(w http.ResponseWriter, r *http.Request) {
// find out if port 53 is available -- if not, show a big warning
data.DNS.Port = 53
if !checkPacketPortAvailable("", 53) {
if checkPacketPortAvailable("", 53) != nil {
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 {
for i := range iface.Addresses {
ip, _, err := net.ParseCIDR(iface.Addresses[i])
if err != nil {
ip, _, e := net.ParseCIDR(iface.Addresses[i])
if e != nil {
continue
}
iface.Addresses[i] = ip.String()
@ -764,13 +764,15 @@ func handleInstallConfigure(w http.ResponseWriter, r *http.Request) {
}
// validate that hosts and ports are bindable
if !checkPortAvailable(newSettings.Web.IP, newSettings.Web.Port) {
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s", net.JoinHostPort(newSettings.Web.IP, strconv.Itoa(newSettings.Web.Port)))
err = checkPortAvailable(newSettings.Web.IP, newSettings.Web.Port)
if err != nil {
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s due to %s", net.JoinHostPort(newSettings.Web.IP, strconv.Itoa(newSettings.Web.Port)), err)
return
}
if !checkPacketPortAvailable(newSettings.DNS.IP, newSettings.DNS.Port) {
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s", net.JoinHostPort(newSettings.DNS.IP, strconv.Itoa(newSettings.DNS.Port)))
err = checkPacketPortAvailable(newSettings.DNS.IP, newSettings.DNS.Port)
if err != nil {
httpError(w, http.StatusBadRequest, "Impossible to listen on IP:port %s due to %s", net.JoinHostPort(newSettings.DNS.IP, strconv.Itoa(newSettings.DNS.Port)), err)
return
}

View File

@ -14,8 +14,6 @@ import (
"runtime"
"strconv"
"strings"
"github.com/hmage/golibs/log"
)
// ----------------------------------
@ -124,7 +122,7 @@ func preInstall(handler func(http.ResponseWriter, *http.Request)) func(http.Resp
}
}
// preInstallStruct wraps preInstall into a struct that can be returned as an interface where neccessary
// preInstallStruct wraps preInstall into a struct that can be returned as an interface where necessary
type preInstallHandlerStruct struct {
handler http.Handler
}
@ -241,41 +239,23 @@ func getValidNetInterfaces() ([]netInterface, error) {
return netIfaces, nil
}
func findIPv4IfaceAddr(ifaces []netInterface) string {
for _, iface := range ifaces {
for _, addr := range iface.Addresses {
ip, _, err := net.ParseCIDR(addr)
if err != nil {
log.Printf("SHOULD NOT HAPPEN: got iface.Addresses element that's not a parseable CIDR: %s", addr)
continue
}
if ip.To4() == nil {
log.Tracef("Ignoring IP that isn't IPv4: %s", ip)
continue
}
return ip.To4().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(host string, port int) bool {
func checkPortAvailable(host string, port int) error {
ln, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil {
return false
return err
}
ln.Close()
return true
return nil
}
func checkPacketPortAvailable(host string, port int) bool {
func checkPacketPortAvailable(host string, port int) error {
ln, err := net.ListenPacket("udp", net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil {
return false
return err
}
ln.Close()
return true
return err
}
// ---------------------