From 34e14930deec600a24db4fb8ceaa1daa63776c1c Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 31 Jan 2019 14:56:34 +0300 Subject: [PATCH] /install/get_default_addresses -- now it gives out list of interfaces --- control.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/control.go b/control.go index 51b0d77c..7acc58ae 100644 --- a/control.go +++ b/control.go @@ -700,10 +700,11 @@ type ipport struct { } type firstRunData struct { - Web ipport `json:"web"` - DNS ipport `json:"dns"` - Username string `json:"username,omitempty"` - Password string `json:"password,omitempty"` + Web ipport `json:"web"` + DNS ipport `json:"dns"` + Username string `json:"username,omitempty"` + Password string `json:"password,omitempty"` + Interfaces map[string]interface{} `json:"interfaces"` } func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) { @@ -718,16 +719,13 @@ func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) { return } - // find an interface with an ipv4 address - addr := findIPv4IfaceAddr(ifaces) - if len(addr) == 0 { - httpError(w, http.StatusServiceUnavailable, "Couldn't find any interface with IPv4, plase try again later") - return - } - data.Web.IP = addr - data.DNS.IP = addr + // 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 + data.Interfaces = make(map[string]interface{}) + for _, iface := range ifaces { + data.Interfaces[iface.Name] = iface + } w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) @@ -746,6 +744,7 @@ func handleSetAllSettings(w http.ResponseWriter, r *http.Request) { } spew.Dump(newSettings) + // TODO: validate that hosts and ports are bindable config.firstRun = false config.BindHost = newSettings.Web.IP config.BindPort = newSettings.Web.Port