Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions README.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions cmd/zz_gen_cmd_dnshelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions docs/content/dns/zz_gen_active24.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/data/zz_cli_help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ To display the documentation for a specific DNS provider, run:
$ lego dnshelp -c code

Supported DNS providers:
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
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

More information: https://go-acme.github.io/lego/dns
"""
216 changes: 216 additions & 0 deletions providers/dns/active24/active24.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Package active24 implements a DNS provider for solving the DNS-01 challenge using Active24.
package active24

import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
"time"

"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/platform/config/env"
"github.com/go-acme/lego/v4/providers/dns/active24/internal"
)

// Environment variables names.
const (
envNamespace = "ACTIVE24_"

EnvAPIKey = envNamespace + "API_KEY"
EnvSecret = envNamespace + "SECRET"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
)

// Config is used to configure the creation of the DNSProvider.
type Config struct {
APIKey string
Secret string

PropagationTimeout time.Duration
PollingInterval time.Duration
TTL int
HTTPClient *http.Client
}

// NewDefaultConfig returns a default configuration for the DNSProvider.
func NewDefaultConfig() *Config {
return &Config{
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
},
}
}

// DNSProvider implements the challenge.Provider interface.
type DNSProvider struct {
config *Config
client *internal.Client
}

// NewDNSProvider returns a DNSProvider instance configured for Active24.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIKey, EnvSecret)
if err != nil {
return nil, fmt.Errorf("active24: %w", err)
}

config := NewDefaultConfig()
config.APIKey = values[EnvAPIKey]
config.Secret = values[EnvSecret]

return NewDNSProviderConfig(config)
}

// NewDNSProviderConfig return a DNSProvider instance configured for Active24.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("active24: the configuration of the DNS provider is nil")
}

client, err := internal.NewClient(config.APIKey, config.Secret)
if err != nil {
return nil, fmt.Errorf("active24: %w", err)
}

if config.HTTPClient != nil {
client.HTTPClient = config.HTTPClient
}

return &DNSProvider{
config: config,
client: client,
}, nil
}

// Present creates a TXT record using the specified parameters.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
ctx := context.Background()

info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("active24: could not find zone for domain %q: %w", domain, err)
}

subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
if err != nil {
return fmt.Errorf("active24: %w", err)
}

serviceID, err := d.findServiceID(ctx, dns01.UnFqdn(authZone))
if err != nil {
return fmt.Errorf("active24: find service ID: %w", err)
}

record := internal.Record{
Type: "TXT",
Name: subDomain,
Content: info.Value,
TTL: d.config.TTL,
}

err = d.client.CreateRecord(ctx, strconv.Itoa(serviceID), record)
if err != nil {
return fmt.Errorf("active24: create record: %w", err)
}

return nil
}

// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()

info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("active24: could not find zone for domain %q: %w", domain, err)
}

serviceID, err := d.findServiceID(ctx, dns01.UnFqdn(authZone))
if err != nil {
return fmt.Errorf("active24: find service ID: %w", err)
}

recordID, err := d.findRecordID(ctx, strconv.Itoa(serviceID), info)
if err != nil {
return fmt.Errorf("active24: find record ID: %w", err)
}

err = d.client.DeleteRecord(ctx, strconv.Itoa(serviceID), strconv.Itoa(recordID))
if err != nil {
return fmt.Errorf("active24: delete record %w", err)
}

return nil
}

// Timeout returns the timeout and interval to use when checking for DNS propagation.
// Adjusting here to cope with spikes in propagation times.
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}

func (d *DNSProvider) findServiceID(ctx context.Context, domain string) (int, error) {
services, err := d.client.GetServices(ctx)
if err != nil {
return 0, fmt.Errorf("get services: %w", err)
}

for _, service := range services {
if service.ServiceName != "domain" {
continue
}

if service.Name != domain {
continue
}

return service.ID, nil
}

return 0, fmt.Errorf("service not found for domain: %s", domain)
}

func (d *DNSProvider) findRecordID(ctx context.Context, serviceID string, info dns01.ChallengeInfo) (int, error) {
// NOTE(ldez): Despite the API documentation, the filter doesn't seem to work.
filter := internal.RecordFilter{
Name: dns01.UnFqdn(info.EffectiveFQDN),
Type: []string{"TXT"},
Content: info.Value,
}

records, err := d.client.GetRecords(ctx, serviceID, filter)
if err != nil {
return 0, fmt.Errorf("get records: %w", err)
}

for _, record := range records {
if record.Type != "TXT" {
continue
}

if record.Name != dns01.UnFqdn(info.EffectiveFQDN) {
continue
}

if record.Content != info.Value {
continue
}

return record.ID, nil
}

return 0, errors.New("no record found")
}
24 changes: 24 additions & 0 deletions providers/dns/active24/active24.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Name = "Active24"
Description = ''''''
URL = "https://www.active24.cz"
Code = "active24"
Since = "v4.23.0"

Example = '''
ACTIVE24_API_KEY="xxx" \
ACTIVE24_SECRET="yyy" \
lego --email [email protected] --dns active24 -d '*.example.com' -d example.com run
'''

[Configuration]
[Configuration.Credentials]
ACTIVE24_API_KEY = "API key"
ACTIVE24_SECRET = "Secret"
[Configuration.Additional]
ACTIVE24_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
ACTIVE24_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
ACTIVE24_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
ACTIVE24_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"

[Links]
API = "https://rest.active24.cz/v2/docs"
Loading