-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudflare.go
55 lines (45 loc) · 1017 Bytes
/
cloudflare.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dyndns
import (
"strings"
cloudfl "github.com/cloudflare/cloudflare-go"
)
func cloudflareupd(configs Config) error {
api, err := cloudfl.New(configs.Auth.Apikey, configs.Auth.Email)
if err != nil {
return err
}
for _, domain := range configs.Domains {
zoneID := ""
zones, err := api.ListZones()
if err != nil {
return err
}
for _, zone := range zones {
if strings.HasSuffix(domain, zone.Name) {
zoneID = zone.ID
}
}
recordID := ""
records, err := api.DNSRecords(zoneID, cloudfl.DNSRecord{})
if err != nil {
return err
}
for _, r := range records {
if r.Type == "A" && r.Name == domain {
recordID = r.ID
}
}
record, err := api.DNSRecord(zoneID, recordID)
if err != nil {
return err
}
if configs.Ipupdate != record.Content {
record.Content = configs.Ipupdate
err = api.UpdateDNSRecord(zoneID, recordID, record)
if err != nil {
return err
}
}
}
return nil
}