From 54dfea9fb2e0047bca0b7b3cd32cbfe3fabecb3b Mon Sep 17 00:00:00 2001 From: root Date: Mon, 12 Oct 2020 02:22:00 +0200 Subject: [PATCH 1/2] fixes for TXT & CNAME --- rest-api/main.go | 18 ++++++++++++++++-- rest-api/request_handler.go | 13 ++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rest-api/main.go b/rest-api/main.go index d556ad4..7fcc64e 100644 --- a/rest-api/main.go +++ b/rest-api/main.go @@ -27,13 +27,25 @@ func main() { router.HandleFunc("/v2/update", DynUpdate).Methods("GET") router.HandleFunc("/v3/update", DynUpdate).Methods("GET") - log.Println(fmt.Sprintf("Serving dyndns REST services on 0.0.0.0:8080...")) - log.Fatal(http.ListenAndServe(":8080", router)) +/* swearing monsters and other things + You want to know the truths? + No you don't + The problem here is that the "default" doesn't have a simple/easy method to listen on multiple + IPs and piorts for the same router ;( +*/ + log.Println(fmt.Sprintf("Serving dyndns REST services on :8080...")) + go log.Fatal(http.ListenAndServe(":8080", router)) + log.Println(fmt.Sprintf("Serving dyndns REST services on 127.0.0.1:8080...")) + go log.Fatal(http.ListenAndServe("127.0.0.1:8080", router)) + go log.Fatal(http.ListenAndServe("[fdee:cafe:feed:beef::f]:8080", router)) + log.Fatal(http.ListenAndServe("[fdee:cafe:feed:beef:1:1:1:1]:8080", router)) } func DynUpdate(w http.ResponseWriter, r *http.Request) { extractor := RequestDataExtractor{ Address: func(r *http.Request) string { return r.URL.Query().Get("myip") }, + Cname: func(r *http.Request) string { return r.URL.Query().Get("mycname") }, + Txt: func(r *http.Request) string { return r.URL.Query().Get("mytxt") }, Secret: func(r *http.Request) string { _, sharedSecret, ok := r.BasicAuth() if !ok || sharedSecret == "" { @@ -76,6 +88,8 @@ func DynUpdate(w http.ResponseWriter, r *http.Request) { func Update(w http.ResponseWriter, r *http.Request) { extractor := RequestDataExtractor{ Address: func(r *http.Request) string { return r.URL.Query().Get("addr") }, + Cname: func(r *http.Request) string { return r.URL.Query().Get("cname") }, + Txt: func(r *http.Request) string { return r.URL.Query().Get("txt") }, Secret: func(r *http.Request) string { return r.URL.Query().Get("secret") }, Domain: func(r *http.Request) string { return r.URL.Query().Get("domain") }, } diff --git a/rest-api/request_handler.go b/rest-api/request_handler.go index 2199454..c256e2a 100644 --- a/rest-api/request_handler.go +++ b/rest-api/request_handler.go @@ -16,6 +16,8 @@ type RequestDataExtractor struct { Address func(request *http.Request) string Secret func(request *http.Request) string Domain func(request *http.Request) string + Cname func(request *http.Request) string + Txt func(request *http.Request) string } type WebserviceResponse struct { @@ -25,6 +27,8 @@ type WebserviceResponse struct { Domains []string Address string AddrType string + Cname string + Txt string } func BuildWebserviceResponseFromRequest(r *http.Request, appConfig *Config, extractors RequestDataExtractor) WebserviceResponse { @@ -33,7 +37,8 @@ func BuildWebserviceResponseFromRequest(r *http.Request, appConfig *Config, extr sharedSecret := extractors.Secret(r) response.Domains = strings.Split(extractors.Domain(r), ",") response.Address = extractors.Address(r) - + response.Cname = extractors.Cname(r) + response.Txt = extractors.Txt(r) if sharedSecret != appConfig.SharedSecret { log.Println(fmt.Sprintf("Invalid shared secret: %s", sharedSecret)) response.Success = false @@ -57,6 +62,12 @@ func BuildWebserviceResponseFromRequest(r *http.Request, appConfig *Config, extr response.AddrType = "A" } else if ipparser.ValidIP6(response.Address) { response.AddrType = "AAAA" + } else if response.Cname != "" { + response.AddrType = "CNAME" + response.Address = response.Cname; + } else if response.Txt != "" { + response.AddrType="TXT" + response.Address=response.Txt; } else { var ip string var err error From 0a6e1a2ab553d9f7edb758b42f4c01b1e81ade23 Mon Sep 17 00:00:00 2001 From: hvisage Date: Sat, 24 Oct 2020 12:15:14 +0200 Subject: [PATCH 2/2] Update main.go cleaning up attempts --- rest-api/main.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/rest-api/main.go b/rest-api/main.go index 7fcc64e..255322f 100644 --- a/rest-api/main.go +++ b/rest-api/main.go @@ -27,18 +27,8 @@ func main() { router.HandleFunc("/v2/update", DynUpdate).Methods("GET") router.HandleFunc("/v3/update", DynUpdate).Methods("GET") -/* swearing monsters and other things - You want to know the truths? - No you don't - The problem here is that the "default" doesn't have a simple/easy method to listen on multiple - IPs and piorts for the same router ;( -*/ log.Println(fmt.Sprintf("Serving dyndns REST services on :8080...")) go log.Fatal(http.ListenAndServe(":8080", router)) - log.Println(fmt.Sprintf("Serving dyndns REST services on 127.0.0.1:8080...")) - go log.Fatal(http.ListenAndServe("127.0.0.1:8080", router)) - go log.Fatal(http.ListenAndServe("[fdee:cafe:feed:beef::f]:8080", router)) - log.Fatal(http.ListenAndServe("[fdee:cafe:feed:beef:1:1:1:1]:8080", router)) } func DynUpdate(w http.ResponseWriter, r *http.Request) {