完善邮件服务IPv6解析记录
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-08-30 21:56:32 +08:00
1 parent 482c6b0f80
commit d70ab71af0
2 files changed
+28 -12

No files matched your search

+19 -8
View File
@@ -61,7 +61,7 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
address = "[\u672a\u68c0\u6d4b\u5230\u516c\u7f51 IPv4]" address = "[\u672a\u68c0\u6d4b\u5230\u516c\u7f51 IPv4]"
} }
items := make([]*DNSItem, 0, 10) items := make([]*DNSItem, 0, 13)
appendARecord := func(host string) { appendARecord := func(host string) {
for _, item := range items { for _, item := range items {
if item.Type == "A" && item.Host == host { if item.Type == "A" && item.Host == host {
@@ -76,6 +76,20 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
Tips: ipTips, Tips: ipTips,
}) })
} }
appendAAAARecord := func(host, address string) {
for _, item := range items {
if item.Type == "AAAA" && item.Host == host {
return
}
}
items = append(items, &DNSItem{
Type: "AAAA",
Host: host,
Value: address,
TTL: dnsRecordTTL,
Tips: ipTips,
})
}
webHost := dnsHostForDomain(configData.WebDomain, domain) webHost := dnsHostForDomain(configData.WebDomain, domain)
if webHost == "@" { if webHost == "@" {
@@ -105,13 +119,10 @@ func buildDNSItemsWithWebIPv4(configData *config.Config, domain, dkimPublicKey,
appendARecord("@") appendARecord("@")
if ipv6Address := buildSPFAddressMechanism(ipv6); strings.HasPrefix(ipv6Address, "ip6:") { if ipv6Address := buildSPFAddressMechanism(ipv6); strings.HasPrefix(ipv6Address, "ip6:") {
items = append(items, &DNSItem{ address := strings.TrimPrefix(ipv6Address, "ip6:")
Type: "AAAA", for _, host := range []string{"@", "smtp", "imap", "pop"} {
Host: "@", appendAAAARecord(host, address)
Value: strings.TrimPrefix(ipv6Address, "ip6:"), }
TTL: dnsRecordTTL,
Tips: ipTips,
})
} }
items = append(items, items = append(items,
+9 -4
View File
@@ -69,8 +69,8 @@ func TestBuildDNSItemsCreatesExpectedRecordShape(t *testing.T) {
} }
items := buildDNSItemsWithWebIPv4(cfg, "example.com", "v=DKIM1; k=rsa; p=test", "198.51.100.20", "2001:db8::20", "", []string{"203.0.113.20"}) items := buildDNSItemsWithWebIPv4(cfg, "example.com", "v=DKIM1; k=rsa; p=test", "198.51.100.20", "2001:db8::20", "", []string{"203.0.113.20"})
if len(items) != 10 { if len(items) != 13 {
t.Fatalf("DNS item count = %d, want 10", len(items)) t.Fatalf("DNS item count = %d, want 13", len(items))
} }
if items[0].Host != "panel" || items[0].Type != "A" || items[0].Value != "203.0.113.20" { if items[0].Host != "panel" || items[0].Type != "A" || items[0].Value != "203.0.113.20" {
t.Fatalf("web A record = %#v", items[0]) t.Fatalf("web A record = %#v", items[0])
@@ -81,8 +81,13 @@ func TestBuildDNSItemsCreatesExpectedRecordShape(t *testing.T) {
if items[5].Type != "AAAA" || items[5].Host != "@" || items[5].Value != "2001:db8::20" { if items[5].Type != "AAAA" || items[5].Host != "@" || items[5].Value != "2001:db8::20" {
t.Fatalf("root AAAA record = %#v", items[5]) t.Fatalf("root AAAA record = %#v", items[5])
} }
if items[6].Value != "smtp.example.com | 1" || items[6].TTL != dnsRecordTTL { for index, host := range map[int]string{6: "smtp", 7: "imap", 8: "pop"} {
t.Fatalf("MX record = %#v", items[6]) if items[index].Type != "AAAA" || items[index].Host != host || items[index].Value != "2001:db8::20" {
t.Fatalf("mail service AAAA record = %#v", items[index])
}
}
if items[9].Value != "smtp.example.com | 1" || items[9].TTL != dnsRecordTTL {
t.Fatalf("MX record = %#v", items[9])
} }
} }