1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00

enable socks for domain update and telegram notification seperately

- add configuration to enable socks for domain update
  and telegram notification seperately.
- sleep to reduce cpu usage while connection error occurred.
This commit is contained in:
Jemy Zhang
2020-05-05 15:11:41 +08:00
parent 09503d0c97
commit 9186772d50
11 changed files with 76 additions and 35 deletions

View File

@@ -28,9 +28,17 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
aliDNS := NewAliDNS(handler.Configuration.Email, handler.Configuration.Password)
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
@@ -68,9 +76,6 @@ 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))
}
}

View File

@@ -77,7 +77,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}()
var lastIP string
looping := false
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
log.Println("Error in GetCurrentIP:", err)
@@ -117,9 +125,6 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
log.Println("Failed to find zone for domain:", domain.DomainName)
}
}
// 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))
}
}
@@ -137,7 +142,7 @@ func recordTracked(domain *godns.Domain, record *DNSRecord) bool {
// Create a new request with auth in place and optional proxy
func (handler *Handler) newRequest(method, url string, body io.Reader) (*http.Request, *http.Client) {
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
if client == nil {
log.Println("cannot create HTTP client")
}

View File

@@ -36,7 +36,16 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
for {
if looping {
// 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))
}
looping = true
log.Printf("Checking IP for domain %s \r\n", domain.DomainName)
domainID := handler.GetDomain(domain.DomainName)
@@ -82,9 +91,6 @@ 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))
}
}
@@ -245,7 +251,7 @@ func (handler *Handler) UpdateIP(domainID int64, subDomainID string, subDomainNa
// PostData post data and invoke DNSPod API
func (handler *Handler) PostData(url string, content url.Values) (string, error) {
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
if client == nil {
return "", errors.New("failed to create HTTP client")

View File

@@ -38,7 +38,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
@@ -63,10 +71,6 @@ 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))
}
}
@@ -106,7 +110,7 @@ func (handler *Handler) updateDNS(dns, ip, hostname, action string) {
log.Fatalf("Unknown action %s\n", action)
}
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
req, _ := http.NewRequest("POST", DreamhostURL, strings.NewReader(values.Encode()))
req.SetBasicAuth(handler.Configuration.Email, handler.Configuration.Password)

View File

@@ -35,7 +35,16 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
@@ -46,7 +55,7 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
//check against locally cached IP, if no change, skip update
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
var ip string
if strings.ToUpper(handler.Configuration.IPType) == godns.IPV4 {
@@ -86,9 +95,5 @@ 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))
}
}

View File

@@ -36,7 +36,16 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
log.Println("get_currentIP:", err)
@@ -59,16 +68,13 @@ 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))
}
}
// UpdateIP update subdomain with current IP
func (handler *Handler) UpdateIP(domain, subDomain, currentIP string) {
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
resp, err := client.Get(fmt.Sprintf(GoogleURL,
handler.Configuration.Email,
handler.Configuration.Password,

View File

@@ -37,7 +37,15 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
}
}()
looping := false
for {
if looping {
// 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))
}
looping = true
currentIP, err := godns.GetCurrentIP(handler.Configuration)
if err != nil {
@@ -64,10 +72,6 @@ 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))
}
}
@@ -79,7 +83,7 @@ func (handler *Handler) UpdateIP(domain, subDomain, currentIP string) {
values.Add("password", handler.Configuration.Password)
values.Add("myip", currentIP)
client := godns.GetHttpClient(handler.Configuration)
client := godns.GetHttpClient(handler.Configuration, handler.Configuration.UseProxy)
req, _ := http.NewRequest("POST", HEUrl, strings.NewReader(values.Encode()))
resp, err := client.Do(req)