1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00
This commit is contained in:
Timothy Ye 2018-06-15 22:16:21 +08:00
parent cc51388579
commit 91b55096b9
4 changed files with 26 additions and 62 deletions

View File

@ -52,8 +52,8 @@ func dnsLoop() {
log.Println("Creating DNS handler with provider:", configuration.Provider) log.Println("Creating DNS handler with provider:", configuration.Provider)
handler := handler.CreateHandler(configuration.Provider) handler := handler.CreateHandler(configuration.Provider)
handler.SetConfiguration(&configuration) handler.SetConfiguration(&configuration)
for _, domain := range configuration.Domains { for i, _ := range configuration.Domains {
go handler.DomainLoop(&domain, panicChan) go handler.DomainLoop(&configuration.Domains[i], panicChan)
} }
panicCount := 0 panicCount := 0

View File

@ -37,6 +37,7 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
}() }()
for { for {
log.Printf("Checking IP for domain %s \r\n", domain.DomainName)
domainID := handler.GetDomain(domain.DomainName) domainID := handler.GetDomain(domain.DomainName)
if domainID == -1 { if domainID == -1 {
@ -51,15 +52,6 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
} }
log.Println("currentIP is:", currentIP) log.Println("currentIP is:", currentIP)
// Compare currentIP with saved IP
savedIP := godns.LoadCurrentIP()
log.Println("savedIP is:", savedIP)
if savedIP != "" && strings.TrimRight(currentIP, "\n") == strings.TrimRight(savedIP, "\n") {
log.Printf("Current IP is not changed, no need to update...")
} else {
godns.SaveCurrentIP(currentIP)
for _, subDomain := range domain.SubDomains { for _, subDomain := range domain.SubDomains {
subDomainID, ip := handler.GetSubDomain(domainID, subDomain) subDomainID, ip := handler.GetSubDomain(domainID, subDomain)
@ -84,7 +76,6 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
log.Printf("%s.%s Current IP is same as domain IP, no need to update...\n", subDomain, domain.DomainName) log.Printf("%s.%s Current IP is same as domain IP, no need to update...\n", subDomain, domain.DomainName)
} }
} }
}
// Interval is 5 minutes // Interval is 5 minutes
log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL)

View File

@ -48,13 +48,6 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn
} }
log.Println("currentIP is:", currentIP) log.Println("currentIP is:", currentIP)
//Compare currentIP with saved IP
savedIP := godns.LoadCurrentIP()
if savedIP != "" && strings.TrimRight(currentIP, "\n") == strings.TrimRight(savedIP, "\n") {
log.Printf("Current IP is not changed, no need to update...")
} else {
godns.SaveCurrentIP(currentIP)
for _, subDomain := range domain.SubDomains { 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)
@ -65,7 +58,6 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn
godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP) godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP)
} }
} }
}
// Interval is 5 minutes // Interval is 5 minutes
log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL) log.Printf("Going to sleep, will start next checking in %d minutes...\r\n", godns.INTERVAL)

View File

@ -7,9 +7,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os"
"strings"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
"gopkg.in/gomail.v2" "gopkg.in/gomail.v2"
) )
@ -90,22 +87,6 @@ func CheckSettings(config *Settings) error {
return nil return nil
} }
// SaveCurrentIP saves current IP into a template file
func SaveCurrentIP(currentIP string) {
ioutil.WriteFile("./.current_ip", []byte(currentIP), os.FileMode(0644))
}
// LoadCurrentIP loads saved IP from template file
func LoadCurrentIP() string {
content, err := ioutil.ReadFile("./.current_ip")
if err != nil {
return ""
}
return strings.Replace(string(content), "\n", "", -1)
}
// SendNotify sends mail notify if IP is changed // SendNotify sends mail notify if IP is changed
func SendNotify(configuration *Settings, domain, currentIP string) error { func SendNotify(configuration *Settings, domain, currentIP string) error {
m := gomail.NewMessage() m := gomail.NewMessage()