mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
feat: 优化dns处理
This commit is contained in:
2
go.mod
2
go.mod
@@ -99,6 +99,6 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/libdns/alidns => github.com/devhaozi/alidns v0.0.0-20250329210040-6497b3450b2e
|
||||
github.com/libdns/alidns => github.com/devhaozi/alidns v0.0.0-20250330070326-05637d1994b2
|
||||
github.com/mholt/acmez/v3 => github.com/tnb-labs/acmez/v3 v3.0.0-20250329064837-dd8e7d30835a
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -10,8 +10,8 @@ github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/devhaozi/alidns v0.0.0-20250329210040-6497b3450b2e h1:BXNrrReE2H1/T26hxFXKX58/mmD+mE/tAVHlvChQaqM=
|
||||
github.com/devhaozi/alidns v0.0.0-20250329210040-6497b3450b2e/go.mod h1:e18uAG6GanfRhcJj6/tps2rCMzQJaYVcGKT+ELjdjGE=
|
||||
github.com/devhaozi/alidns v0.0.0-20250330070326-05637d1994b2 h1:X+QklrHA7FubkxJKTQoM5oLSD53e5JULlXRb/QNUm3g=
|
||||
github.com/devhaozi/alidns v0.0.0-20250330070326-05637d1994b2/go.mod h1:e18uAG6GanfRhcJj6/tps2rCMzQJaYVcGKT+ELjdjGE=
|
||||
github.com/devhaozi/westcn v0.0.0-20250329192208-199d82100bff h1:SLHnJyRcp6OxbMjHr7FvPvT84IoXuofu+1EeMU+Tr1M=
|
||||
github.com/devhaozi/westcn v0.0.0-20250329192208-199d82100bff/go.mod h1:dUJZQSurBuEWKixGyCYCyiVIkSFxrgqN3B036tHMPtU=
|
||||
github.com/expr-lang/expr v1.17.2 h1:o0A99O/Px+/DTjEnQiodAgOIK9PPxL8DtXhBRKC+Iso=
|
||||
|
||||
@@ -26,10 +26,10 @@ type Client struct {
|
||||
// UseDns 使用 DNS 接口验证
|
||||
func (c *Client) UseDns(dnsType DnsType, param DNSParam) {
|
||||
c.zClient.ChallengeSolvers = map[string]acmez.Solver{
|
||||
acme.ChallengeTypeDNS01: dnsSolver{
|
||||
acme.ChallengeTypeDNS01: &dnsSolver{
|
||||
dns: dnsType,
|
||||
param: param,
|
||||
records: &[]libdns.Record{},
|
||||
records: []libdns.Record{},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -39,11 +39,11 @@ func (c *Client) UseManualDns(total int, check ...bool) {
|
||||
c.controlChan = make(chan struct{})
|
||||
c.dataChan = make(chan any)
|
||||
c.zClient.ChallengeSolvers = map[string]acmez.Solver{
|
||||
acme.ChallengeTypeDNS01: manualDNSSolver{
|
||||
acme.ChallengeTypeDNS01: &manualDNSSolver{
|
||||
check: len(check) > 0 && check[0],
|
||||
controlChan: c.controlChan,
|
||||
dataChan: c.dataChan,
|
||||
records: &[]DNSRecord{},
|
||||
records: []DNSRecord{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package acme
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/devhaozi/westcn"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/devhaozi/westcn"
|
||||
"github.com/libdns/alidns"
|
||||
"github.com/libdns/cloudflare"
|
||||
"github.com/libdns/cloudns"
|
||||
@@ -62,10 +62,10 @@ func (s httpSolver) CleanUp(_ context.Context, challenge acme.Challenge) error {
|
||||
type dnsSolver struct {
|
||||
dns DnsType
|
||||
param DNSParam
|
||||
records *[]libdns.Record
|
||||
records []libdns.Record
|
||||
}
|
||||
|
||||
func (s dnsSolver) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||
func (s *dnsSolver) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||
dnsName := challenge.DNS01TXTRecordName()
|
||||
keyAuth := challenge.DNS01KeyAuthorization()
|
||||
provider, err := s.getDNSProvider()
|
||||
@@ -92,11 +92,11 @@ func (s dnsSolver) Present(ctx context.Context, challenge acme.Challenge) error
|
||||
return fmt.Errorf("expected to add 1 record, but actually added %d records", len(results))
|
||||
}
|
||||
|
||||
s.records = &results
|
||||
s.records = results
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s dnsSolver) CleanUp(ctx context.Context, challenge acme.Challenge) error {
|
||||
func (s *dnsSolver) CleanUp(ctx context.Context, challenge acme.Challenge) error {
|
||||
dnsName := challenge.DNS01TXTRecordName()
|
||||
provider, err := s.getDNSProvider()
|
||||
if err != nil {
|
||||
@@ -111,11 +111,11 @@ func (s dnsSolver) CleanUp(ctx context.Context, challenge acme.Challenge) error
|
||||
return fmt.Errorf("failed to get the effective TLD+1 for %q: %w", dnsName, err)
|
||||
}
|
||||
|
||||
_, _ = provider.DeleteRecords(ctx, zone+".", *s.records)
|
||||
_, _ = provider.DeleteRecords(ctx, zone+".", s.records)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s dnsSolver) getDNSProvider() (DNSProvider, error) {
|
||||
func (s *dnsSolver) getDNSProvider() (DNSProvider, error) {
|
||||
var dns DNSProvider
|
||||
|
||||
switch s.dns {
|
||||
@@ -241,10 +241,10 @@ type manualDNSSolver struct {
|
||||
check bool
|
||||
controlChan chan struct{}
|
||||
dataChan chan any
|
||||
records *[]DNSRecord
|
||||
records []DNSRecord
|
||||
}
|
||||
|
||||
func (s manualDNSSolver) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||
func (s *manualDNSSolver) Present(ctx context.Context, challenge acme.Challenge) error {
|
||||
full := challenge.DNS01TXTRecordName()
|
||||
keyAuth := challenge.DNS01KeyAuthorization()
|
||||
domain, err := publicsuffix.EffectiveTLDPlusOne(full)
|
||||
@@ -252,18 +252,27 @@ func (s manualDNSSolver) Present(ctx context.Context, challenge acme.Challenge)
|
||||
return fmt.Errorf("failed to get the effective TLD+1 for %q: %w", full, err)
|
||||
}
|
||||
|
||||
*s.records = append(*s.records, DNSRecord{
|
||||
s.records = append(s.records, DNSRecord{
|
||||
Name: strings.TrimSuffix(full, "."+domain),
|
||||
Domain: domain,
|
||||
Value: keyAuth,
|
||||
})
|
||||
s.dataChan <- *s.records
|
||||
s.dataChan <- s.records
|
||||
|
||||
<-s.controlChan
|
||||
return nil
|
||||
select {
|
||||
case <-s.controlChan:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func (s manualDNSSolver) CleanUp(_ context.Context, _ acme.Challenge) error {
|
||||
func (s *manualDNSSolver) CleanUp(_ context.Context, _ acme.Challenge) error {
|
||||
defer func() {
|
||||
_ = recover()
|
||||
}()
|
||||
close(s.controlChan)
|
||||
close(s.dataChan)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user