-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.go
104 lines (94 loc) · 2.18 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package dns
import (
"time"
"github.com/jeessy2/ddns-go/v6/config"
"github.com/jeessy2/ddns-go/v6/dns/internet"
"github.com/jeessy2/ddns-go/v6/util"
)
// DNS interface
type DNS interface {
Init(dnsConf *config.DnsConfig, ipv4cache *util.IpCache, ipv6cache *util.IpCache)
// 添加或更新IPv4/IPv6记录
AddUpdateDomainRecords() (domains config.Domains)
}
var (
addresses = []string{
alidnsEndpoint,
baiduEndpoint,
zonesAPI,
recordListAPI,
googleDomainEndpoint,
huaweicloudEndpoint,
nameCheapEndpoint,
nameSiloListRecordEndpoint,
porkbunEndpoint,
tencentCloudEndPoint,
}
Ipcache = [][2]util.IpCache{}
)
// RunTimer 定时运行
func RunTimer(delay time.Duration) {
internet.Wait(addresses)
for {
RunOnce()
time.Sleep(delay)
}
}
// RunOnce RunOnce
func RunOnce() {
conf, err := config.GetConfigCached()
if err != nil {
return
}
if util.ForceCompareGlobal || len(Ipcache) != len(conf.DnsConf) {
Ipcache = [][2]util.IpCache{}
for range conf.DnsConf {
Ipcache = append(Ipcache, [2]util.IpCache{{}, {}})
}
}
for i, dc := range conf.DnsConf {
var dnsSelected DNS
switch dc.DNS.Name {
case "alidns":
dnsSelected = &Alidns{}
case "tencentcloud":
dnsSelected = &TencentCloud{}
case "dnspod":
dnsSelected = &Dnspod{}
case "cloudflare":
dnsSelected = &Cloudflare{}
case "huaweicloud":
dnsSelected = &Huaweicloud{}
case "callback":
dnsSelected = &Callback{}
case "baiducloud":
dnsSelected = &BaiduCloud{}
case "porkbun":
dnsSelected = &Porkbun{}
case "godaddy":
dnsSelected = &GoDaddyDNS{}
case "googledomain":
dnsSelected = &GoogleDomain{}
case "namecheap":
dnsSelected = &NameCheap{}
case "namesilo":
dnsSelected = &NameSilo{}
case "vercel":
dnsSelected = &Vercel{}
default:
dnsSelected = &Alidns{}
}
dnsSelected.Init(&dc, &Ipcache[i][0], &Ipcache[i][1])
domains := dnsSelected.AddUpdateDomainRecords()
// webhook
v4Status, v6Status := config.ExecWebhook(&domains, &conf)
// 重置单个cache
if v4Status == config.UpdatedFailed {
Ipcache[i][0] = util.IpCache{}
}
if v6Status == config.UpdatedFailed {
Ipcache[i][1] = util.IpCache{}
}
}
util.ForceCompareGlobal = false
}