From 68b729e635b6cb05bbe01aca53fcf5d164973247 Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Sun, 19 Apr 2020 15:20:22 -0400 Subject: [PATCH 1/4] AliDNS Handler - Use Resolver --- handler/alidns/alidns_handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/handler/alidns/alidns_handler.go b/handler/alidns/alidns_handler.go index a5f92c5..5376d51 100644 --- a/handler/alidns/alidns_handler.go +++ b/handler/alidns/alidns_handler.go @@ -28,7 +28,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } }() - var lastIP string aliDNS := NewAliDNS(handler.Configuration.Email, handler.Configuration.Password) for { @@ -39,14 +38,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. continue } log.Println("currentIP is:", currentIP) + for _, subDomain := range domain.SubDomains { + hostname := subDomain + "." + domain.DomainName + lastIP := godns.ResolveDNS(hostname, handler.Configuration.Resolver) + //check against currently known IP, if no change, skip update + if currentIP == lastIP { + log.Printf("IP is the same as cached one. Skip update.\n") + } else { + lastIP = currentIP - //check against locally cached IP, if no change, skip update - if currentIP == lastIP { - log.Printf("IP is the same as cached one. Skip update.\n") - } else { - lastIP = currentIP - - for _, subDomain := range domain.SubDomains { log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName) records := aliDNS.GetDomainRecords(domain.DomainName, subDomain) if records == nil || len(records) == 0 { From 9397f6b27203df9ad89a246c95d61b5b1ba26c11 Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Sun, 19 Apr 2020 15:26:10 -0400 Subject: [PATCH 2/4] DNSPod Handler - Use Resolver --- handler/dnspod/dnspod_handler.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/handler/dnspod/dnspod_handler.go b/handler/dnspod/dnspod_handler.go index 1df4d74..901f573 100644 --- a/handler/dnspod/dnspod_handler.go +++ b/handler/dnspod/dnspod_handler.go @@ -36,7 +36,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } }() - var lastIP string for { log.Printf("Checking IP for domain %s \r\n", domain.DomainName) domainID := handler.GetDomain(domain.DomainName) @@ -53,13 +52,14 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } log.Println("currentIP is:", currentIP) - //check against locally cached IP, if no change, skip update - if currentIP == lastIP { - log.Printf("IP is the same as cached one. Skip update.\n") - } else { - lastIP = currentIP - - for _, subDomain := range domain.SubDomains { + for _, subDomain := range domain.SubDomains { + hostname := subDomain + "." + domain.DomainName + lastIP := godns.ResolveDNS(hostname, handler.Configuration.Resolver) + //check against currently known IP, if no change, skip update + if currentIP == lastIP { + log.Printf("IP is the same as cached one. Skip update.\n") + } else { + lastIP = currentIP subDomainID, ip := handler.GetSubDomain(domainID, subDomain) @@ -213,7 +213,7 @@ func (handler *Handler) UpdateIP(domainID int64, subDomainID string, subDomainNa } else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 { value.Add("record_type", "AAAA") } else { - log.Println("Error: must specify \"ip_type\" in config for DNSPod."); + log.Println("Error: must specify \"ip_type\" in config for DNSPod.") return } From 57ecf1f7bb4f2fdbea6a119ea8cf710ac80b38a6 Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Sun, 19 Apr 2020 15:31:49 -0400 Subject: [PATCH 3/4] Duck Handler - Use Resolver --- handler/duck/duck_handler.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/handler/duck/duck_handler.go b/handler/duck/duck_handler.go index 6be7bc8..16a1daf 100644 --- a/handler/duck/duck_handler.go +++ b/handler/duck/duck_handler.go @@ -35,8 +35,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } }() - var lastIP string - for { currentIP, err := godns.GetCurrentIP(handler.Configuration) @@ -47,20 +45,23 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. log.Println("currentIP is:", currentIP) //check against locally cached IP, if no change, skip update - if currentIP == lastIP { - log.Printf("IP is the same as cached one. Skip update.\n") - } else { - lastIP = currentIP - client := godns.GetHttpClient(handler.Configuration) - var ip string - if strings.ToUpper(handler.Configuration.IPType) == godns.IPV4 { - ip = fmt.Sprintf("ip=%s", currentIP) - } else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 { - ip = fmt.Sprintf("ipv6=%s", currentIP) - } + client := godns.GetHttpClient(handler.Configuration) + var ip string - for _, subDomain := range domain.SubDomains { + if strings.ToUpper(handler.Configuration.IPType) == godns.IPV4 { + ip = fmt.Sprintf("ip=%s", currentIP) + } else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 { + ip = fmt.Sprintf("ipv6=%s", currentIP) + } + + for _, subDomain := range domain.SubDomains { + hostname := subDomain + "." + domain.DomainName + lastIP := godns.ResolveDNS(hostname, handler.Configuration.Resolver) + //check against currently known IP, if no change, skip update + if currentIP == lastIP { + log.Printf("IP is the same as cached one. Skip update.\n") + } else { // update IP with HTTP GET request resp, err := client.Get(fmt.Sprintf(DuckUrl, subDomain, handler.Configuration.LoginToken, ip)) if err != nil { From 1c1aa6c4209e9a99d95b9a85172b833f302ccfda Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Sun, 19 Apr 2020 15:34:25 -0400 Subject: [PATCH 4/4] HE Handler - Use Resolver --- handler/he/he_handler.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/handler/he/he_handler.go b/handler/he/he_handler.go index 7c05f66..63d3fad 100644 --- a/handler/he/he_handler.go +++ b/handler/he/he_handler.go @@ -37,7 +37,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } }() - var lastIP string for { currentIP, err := godns.GetCurrentIP(handler.Configuration) @@ -48,12 +47,14 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. log.Println("currentIP is:", currentIP) //check against locally cached IP, if no change, skip update - if currentIP == lastIP { - log.Printf("IP is the same as cached one. Skip update.\n") - } else { - lastIP = currentIP - for _, subDomain := range domain.SubDomains { + for _, subDomain := range domain.SubDomains { + hostname := subDomain + "." + domain.DomainName + lastIP := godns.ResolveDNS(hostname, handler.Configuration.Resolver) + //check against currently known IP, if no change, skip update + if currentIP == lastIP { + log.Printf("IP is the same as cached one. Skip update.\n") + } else { log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName) handler.UpdateIP(domain.DomainName, subDomain, currentIP) @@ -63,6 +64,7 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns. } } } + // Sleep with interval log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.Interval) time.Sleep(time.Second * time.Duration(handler.Configuration.Interval))