Improved input service. New Manager web app. Directory and small readme for output service.
This commit is contained in:
42
manager/dyfi.go
Normal file
42
manager/dyfi.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func startDyfiUpdater(hostname, username, password string) {
|
||||
if hostname == "" || username == "" || password == "" {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info("Starting dy.fi updater for %s", hostname)
|
||||
|
||||
update := func() {
|
||||
url := fmt.Sprintf("https://www.dy.fi/nic/update?hostname=%s", hostname)
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
req.SetBasicAuth(username, password)
|
||||
req.Header.Set("User-Agent", "Go-TwoStepAuth-Client/1.0")
|
||||
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.Error("dy.fi update failed: %v", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
logger.Info("dy.fi update status: %s", resp.Status)
|
||||
}
|
||||
|
||||
// Update immediately on start
|
||||
update()
|
||||
|
||||
// Update every 7 days (dy.fi requires update at least every 30 days)
|
||||
go func() {
|
||||
ticker := time.NewTicker(7 * 24 * time.Hour)
|
||||
for range ticker.C {
|
||||
update()
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user