Skip to content

Commit 730af10

Browse files
authored
Add DNS provider for Active24 (#2478)
1 parent 2bc147f commit 730af10

File tree

16 files changed

+1055
-39
lines changed

16 files changed

+1055
-39
lines changed

README.md

Lines changed: 38 additions & 38 deletions
Large diffs are not rendered by default.

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/dns/zz_gen_active24.md

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data/zz_cli_help.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ To display the documentation for a specific DNS provider, run:
149149
$ lego dnshelp -c code
150150
151151
Supported DNS providers:
152-
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi
152+
acme-dns, active24, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi
153153
154154
More information: https://go-acme.github.io/lego/dns
155155
"""

providers/dns/active24/active24.go

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Package active24 implements a DNS provider for solving the DNS-01 challenge using Active24.
2+
package active24
3+
4+
import (
5+
"context"
6+
"errors"
7+
"fmt"
8+
"net/http"
9+
"strconv"
10+
"time"
11+
12+
"github.com/go-acme/lego/v4/challenge/dns01"
13+
"github.com/go-acme/lego/v4/platform/config/env"
14+
"github.com/go-acme/lego/v4/providers/dns/active24/internal"
15+
)
16+
17+
// Environment variables names.
18+
const (
19+
envNamespace = "ACTIVE24_"
20+
21+
EnvAPIKey = envNamespace + "API_KEY"
22+
EnvSecret = envNamespace + "SECRET"
23+
24+
EnvTTL = envNamespace + "TTL"
25+
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
26+
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
27+
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
28+
)
29+
30+
// Config is used to configure the creation of the DNSProvider.
31+
type Config struct {
32+
APIKey string
33+
Secret string
34+
35+
PropagationTimeout time.Duration
36+
PollingInterval time.Duration
37+
TTL int
38+
HTTPClient *http.Client
39+
}
40+
41+
// NewDefaultConfig returns a default configuration for the DNSProvider.
42+
func NewDefaultConfig() *Config {
43+
return &Config{
44+
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
45+
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
46+
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
47+
HTTPClient: &http.Client{
48+
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
49+
},
50+
}
51+
}
52+
53+
// DNSProvider implements the challenge.Provider interface.
54+
type DNSProvider struct {
55+
config *Config
56+
client *internal.Client
57+
}
58+
59+
// NewDNSProvider returns a DNSProvider instance configured for Active24.
60+
func NewDNSProvider() (*DNSProvider, error) {
61+
values, err := env.Get(EnvAPIKey, EnvSecret)
62+
if err != nil {
63+
return nil, fmt.Errorf("active24: %w", err)
64+
}
65+
66+
config := NewDefaultConfig()
67+
config.APIKey = values[EnvAPIKey]
68+
config.Secret = values[EnvSecret]
69+
70+
return NewDNSProviderConfig(config)
71+
}
72+
73+
// NewDNSProviderConfig return a DNSProvider instance configured for Active24.
74+
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
75+
if config == nil {
76+
return nil, errors.New("active24: the configuration of the DNS provider is nil")
77+
}
78+
79+
client, err := internal.NewClient(config.APIKey, config.Secret)
80+
if err != nil {
81+
return nil, fmt.Errorf("active24: %w", err)
82+
}
83+
84+
if config.HTTPClient != nil {
85+
client.HTTPClient = config.HTTPClient
86+
}
87+
88+
return &DNSProvider{
89+
config: config,
90+
client: client,
91+
}, nil
92+
}
93+
94+
// Present creates a TXT record using the specified parameters.
95+
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
96+
ctx := context.Background()
97+
98+
info := dns01.GetChallengeInfo(domain, keyAuth)
99+
100+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
101+
if err != nil {
102+
return fmt.Errorf("active24: could not find zone for domain %q: %w", domain, err)
103+
}
104+
105+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
106+
if err != nil {
107+
return fmt.Errorf("active24: %w", err)
108+
}
109+
110+
serviceID, err := d.findServiceID(ctx, dns01.UnFqdn(authZone))
111+
if err != nil {
112+
return fmt.Errorf("active24: find service ID: %w", err)
113+
}
114+
115+
record := internal.Record{
116+
Type: "TXT",
117+
Name: subDomain,
118+
Content: info.Value,
119+
TTL: d.config.TTL,
120+
}
121+
122+
err = d.client.CreateRecord(ctx, strconv.Itoa(serviceID), record)
123+
if err != nil {
124+
return fmt.Errorf("active24: create record: %w", err)
125+
}
126+
127+
return nil
128+
}
129+
130+
// CleanUp removes the TXT record matching the specified parameters.
131+
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
132+
ctx := context.Background()
133+
134+
info := dns01.GetChallengeInfo(domain, keyAuth)
135+
136+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
137+
if err != nil {
138+
return fmt.Errorf("active24: could not find zone for domain %q: %w", domain, err)
139+
}
140+
141+
serviceID, err := d.findServiceID(ctx, dns01.UnFqdn(authZone))
142+
if err != nil {
143+
return fmt.Errorf("active24: find service ID: %w", err)
144+
}
145+
146+
recordID, err := d.findRecordID(ctx, strconv.Itoa(serviceID), info)
147+
if err != nil {
148+
return fmt.Errorf("active24: find record ID: %w", err)
149+
}
150+
151+
err = d.client.DeleteRecord(ctx, strconv.Itoa(serviceID), strconv.Itoa(recordID))
152+
if err != nil {
153+
return fmt.Errorf("active24: delete record %w", err)
154+
}
155+
156+
return nil
157+
}
158+
159+
// Timeout returns the timeout and interval to use when checking for DNS propagation.
160+
// Adjusting here to cope with spikes in propagation times.
161+
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
162+
return d.config.PropagationTimeout, d.config.PollingInterval
163+
}
164+
165+
func (d *DNSProvider) findServiceID(ctx context.Context, domain string) (int, error) {
166+
services, err := d.client.GetServices(ctx)
167+
if err != nil {
168+
return 0, fmt.Errorf("get services: %w", err)
169+
}
170+
171+
for _, service := range services {
172+
if service.ServiceName != "domain" {
173+
continue
174+
}
175+
176+
if service.Name != domain {
177+
continue
178+
}
179+
180+
return service.ID, nil
181+
}
182+
183+
return 0, fmt.Errorf("service not found for domain: %s", domain)
184+
}
185+
186+
func (d *DNSProvider) findRecordID(ctx context.Context, serviceID string, info dns01.ChallengeInfo) (int, error) {
187+
// NOTE(ldez): Despite the API documentation, the filter doesn't seem to work.
188+
filter := internal.RecordFilter{
189+
Name: dns01.UnFqdn(info.EffectiveFQDN),
190+
Type: []string{"TXT"},
191+
Content: info.Value,
192+
}
193+
194+
records, err := d.client.GetRecords(ctx, serviceID, filter)
195+
if err != nil {
196+
return 0, fmt.Errorf("get records: %w", err)
197+
}
198+
199+
for _, record := range records {
200+
if record.Type != "TXT" {
201+
continue
202+
}
203+
204+
if record.Name != dns01.UnFqdn(info.EffectiveFQDN) {
205+
continue
206+
}
207+
208+
if record.Content != info.Value {
209+
continue
210+
}
211+
212+
return record.ID, nil
213+
}
214+
215+
return 0, errors.New("no record found")
216+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Name = "Active24"
2+
Description = ''''''
3+
URL = "https://www.active24.cz"
4+
Code = "active24"
5+
Since = "v4.23.0"
6+
7+
Example = '''
8+
ACTIVE24_API_KEY="xxx" \
9+
ACTIVE24_SECRET="yyy" \
10+
lego --email [email protected] --dns active24 -d '*.example.com' -d example.com run
11+
'''
12+
13+
[Configuration]
14+
[Configuration.Credentials]
15+
ACTIVE24_API_KEY = "API key"
16+
ACTIVE24_SECRET = "Secret"
17+
[Configuration.Additional]
18+
ACTIVE24_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
19+
ACTIVE24_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
20+
ACTIVE24_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
21+
ACTIVE24_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
22+
23+
[Links]
24+
API = "https://rest.active24.cz/v2/docs"

0 commit comments

Comments
 (0)