From c36a7895ada28cd20a3f19cb1e58d9b9c05383a6 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 17 Jan 2019 17:16:49 +0300 Subject: [PATCH] Add install page API stubs --- control.go | 42 ++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + 2 files changed, 43 insertions(+) diff --git a/control.go b/control.go index 4600c184..533e535f 100644 --- a/control.go +++ b/control.go @@ -13,6 +13,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/dnsforward" "github.com/AdguardTeam/dnsproxy/upstream" + "github.com/davecgh/go-spew/spew" "github.com/hmage/golibs/log" "github.com/miekg/dns" govalidator "gopkg.in/asaskevich/govalidator.v4" @@ -693,6 +694,43 @@ func handleSafeSearchStatus(w http.ResponseWriter, r *http.Request) { } } +func handleGetDefaultAddresses(w http.ResponseWriter, r *http.Request) { + data := struct { + Web struct { + IP string + Port int + } + DNS struct { + IP string + Port int + } + }{} + + // TODO: replace mockup with actual data + data.Web.IP = "192.168.104.104" + data.Web.Port = 3000 + data.DNS.IP = "192.168.104.104" + data.DNS.Port = 53 + + w.Header().Set("Content-Type", "application/json") + err := json.NewEncoder(w).Encode(data) + if err != nil { + httpError(w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err) + return + } +} + +func handleSetAllSettings(w http.ResponseWriter, r *http.Request) { + newSettings := map[string]interface{}{} + err := json.NewDecoder(r.Body).Decode(&newSettings) + if err != nil { + httpError(w, http.StatusBadRequest, "Failed to parse new DHCP config json: %s", err) + return + } + + spew.Dump(newSettings) +} + func registerControlHandlers() { http.HandleFunc("/control/status", optionalAuth(ensureGET(handleStatus))) http.HandleFunc("/control/enable_protection", optionalAuth(ensurePOST(handleProtectionEnable))) @@ -731,4 +769,8 @@ func registerControlHandlers() { http.HandleFunc("/control/dhcp/interfaces", optionalAuth(ensureGET(handleDHCPInterfaces))) http.HandleFunc("/control/dhcp/set_config", optionalAuth(ensurePOST(handleDHCPSetConfig))) http.HandleFunc("/control/dhcp/find_active_dhcp", optionalAuth(ensurePOST(handleDHCPFindActiveServer))) + + // TODO: move to registerInstallHandlers() + http.HandleFunc("/control/install/get_default_addresses", ensureGET(handleGetDefaultAddresses)) + http.HandleFunc("/control/install/set_all_settings", ensurePOST(handleSetAllSettings)) } diff --git a/go.mod b/go.mod index cc8f3327..6e9e5c4f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ require ( github.com/AdguardTeam/dnsproxy v0.9.10 github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7 + github.com/davecgh/go-spew v1.1.1 github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-test/deep v1.0.1 github.com/gobuffalo/packr v1.19.0