mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
commit
10e125d06d
@ -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)
|
aliDNS := NewAliDNS(handler.Configuration.Email, handler.Configuration.Password)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -39,14 +38,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Println("currentIP is:", currentIP)
|
log.Println("currentIP is:", currentIP)
|
||||||
|
for _, subDomain := range domain.SubDomains {
|
||||||
//check against locally cached IP, if no change, skip update
|
hostname := subDomain + "." + domain.DomainName
|
||||||
|
lastIP := godns.ResolveDNS(hostname, handler.Configuration.Resolver)
|
||||||
|
//check against currently known IP, if no change, skip update
|
||||||
if currentIP == lastIP {
|
if currentIP == lastIP {
|
||||||
log.Printf("IP is the same as cached one. Skip update.\n")
|
log.Printf("IP is the same as cached one. Skip update.\n")
|
||||||
} else {
|
} else {
|
||||||
lastIP = currentIP
|
lastIP = currentIP
|
||||||
|
|
||||||
for _, subDomain := range domain.SubDomains {
|
|
||||||
log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName)
|
log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName)
|
||||||
records := aliDNS.GetDomainRecords(domain.DomainName, subDomain)
|
records := aliDNS.GetDomainRecords(domain.DomainName, subDomain)
|
||||||
if records == nil || len(records) == 0 {
|
if records == nil || len(records) == 0 {
|
||||||
|
@ -36,7 +36,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var lastIP string
|
|
||||||
for {
|
for {
|
||||||
log.Printf("Checking IP for domain %s \r\n", domain.DomainName)
|
log.Printf("Checking IP for domain %s \r\n", domain.DomainName)
|
||||||
domainID := handler.GetDomain(domain.DomainName)
|
domainID := handler.GetDomain(domain.DomainName)
|
||||||
@ -53,14 +52,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
log.Println("currentIP is:", currentIP)
|
log.Println("currentIP is:", currentIP)
|
||||||
|
|
||||||
//check against locally cached IP, if no change, skip update
|
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 {
|
if currentIP == lastIP {
|
||||||
log.Printf("IP is the same as cached one. Skip update.\n")
|
log.Printf("IP is the same as cached one. Skip update.\n")
|
||||||
} else {
|
} else {
|
||||||
lastIP = currentIP
|
lastIP = currentIP
|
||||||
|
|
||||||
for _, subDomain := range domain.SubDomains {
|
|
||||||
|
|
||||||
subDomainID, ip := handler.GetSubDomain(domainID, subDomain)
|
subDomainID, ip := handler.GetSubDomain(domainID, subDomain)
|
||||||
|
|
||||||
if subDomainID == "" || ip == "" {
|
if subDomainID == "" || ip == "" {
|
||||||
@ -213,7 +213,7 @@ func (handler *Handler) UpdateIP(domainID int64, subDomainID string, subDomainNa
|
|||||||
} else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 {
|
} else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 {
|
||||||
value.Add("record_type", "AAAA")
|
value.Add("record_type", "AAAA")
|
||||||
} else {
|
} else {
|
||||||
log.Println("Error: must specify \"ip_type\" in config for DNSPod.");
|
log.Println("Error: must specify \"ip_type\" in config for DNSPod.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var lastIP string
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
currentIP, err := godns.GetCurrentIP(handler.Configuration)
|
currentIP, err := godns.GetCurrentIP(handler.Configuration)
|
||||||
|
|
||||||
@ -47,10 +45,7 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
log.Println("currentIP is:", currentIP)
|
log.Println("currentIP is:", currentIP)
|
||||||
|
|
||||||
//check against locally cached IP, if no change, skip update
|
//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)
|
client := godns.GetHttpClient(handler.Configuration)
|
||||||
var ip string
|
var ip string
|
||||||
|
|
||||||
@ -61,6 +56,12 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
// update IP with HTTP GET request
|
// update IP with HTTP GET request
|
||||||
resp, err := client.Get(fmt.Sprintf(DuckUrl, subDomain, handler.Configuration.LoginToken, ip))
|
resp, err := client.Get(fmt.Sprintf(DuckUrl, subDomain, handler.Configuration.LoginToken, ip))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,7 +37,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var lastIP string
|
|
||||||
for {
|
for {
|
||||||
currentIP, err := godns.GetCurrentIP(handler.Configuration)
|
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)
|
log.Println("currentIP is:", currentIP)
|
||||||
|
|
||||||
//check against locally cached IP, if no change, skip update
|
//check against locally cached IP, if no change, skip update
|
||||||
|
|
||||||
|
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 {
|
if currentIP == lastIP {
|
||||||
log.Printf("IP is the same as cached one. Skip update.\n")
|
log.Printf("IP is the same as cached one. Skip update.\n")
|
||||||
} else {
|
} else {
|
||||||
lastIP = currentIP
|
|
||||||
|
|
||||||
for _, subDomain := range domain.SubDomains {
|
|
||||||
log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName)
|
log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName)
|
||||||
handler.UpdateIP(domain.DomainName, subDomain, currentIP)
|
handler.UpdateIP(domain.DomainName, subDomain, currentIP)
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep with interval
|
// Sleep with interval
|
||||||
log.Printf("Going to sleep, will start next checking in %d seconds...\r\n", handler.Configuration.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))
|
time.Sleep(time.Second * time.Duration(handler.Configuration.Interval))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user