Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for TXT & CNAME #61

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rest-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ 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))
log.Println(fmt.Sprintf("Serving dyndns REST services on :8080..."))
go log.Fatal(http.ListenAndServe(":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 == "" {
Expand Down Expand Up @@ -76,6 +78,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") },
}
Expand Down
13 changes: 12 additions & 1 deletion rest-api/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down