forked from TrueCloudLab/lego
42941ccea6
- Packages - Isolate code used by the CLI into the package `cmd` - (experimental) Add e2e tests for HTTP01, TLS-ALPN-01 and DNS-01, use [Pebble](https://github.com/letsencrypt/pebble) and [challtestsrv](https://github.com/letsencrypt/boulder/tree/master/test/challtestsrv) - Support non-ascii domain name (punnycode) - Check all challenges in a predictable order - No more global exported variables - Archive revoked certificates - Fixes revocation for subdomains and non-ascii domains - Disable pending authorizations - use pointer for RemoteError/ProblemDetails - Poll authz URL instead of challenge URL - The ability for a DNS provider to solve the challenge sequentially - Check all nameservers in a predictable order - Option to disable the complete propagation Requirement - CLI, support for renew with CSR - CLI, add SAN on renew - Add command to list certificates. - Logs every iteration of waiting for the propagation - update DNSimple client - update github.com/miekg/dns
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package duckdns
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/miekg/dns"
|
|
"github.com/xenolf/lego/challenge/dns01"
|
|
)
|
|
|
|
// updateTxtRecord Update the domains TXT record
|
|
// To update the TXT record we just need to make one simple get request.
|
|
// In DuckDNS you only have one TXT record shared with the domain and all sub domains.
|
|
func (d *DNSProvider) updateTxtRecord(domain, token, txt string, clear bool) error {
|
|
u, _ := url.Parse("https://www.duckdns.org/update")
|
|
|
|
mainDomain := getMainDomain(domain)
|
|
if len(mainDomain) == 0 {
|
|
return fmt.Errorf("unable to find the main domain for: %s", domain)
|
|
}
|
|
|
|
query := u.Query()
|
|
query.Set("domains", mainDomain)
|
|
query.Set("token", token)
|
|
query.Set("clear", strconv.FormatBool(clear))
|
|
query.Set("txt", txt)
|
|
u.RawQuery = query.Encode()
|
|
|
|
response, err := d.config.HTTPClient.Get(u.String())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
bodyBytes, err := ioutil.ReadAll(response.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
body := string(bodyBytes)
|
|
if body != "OK" {
|
|
return fmt.Errorf("request to change TXT record for DuckDNS returned the following result (%s) this does not match expectation (OK) used url [%s]", body, u)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DuckDNS only lets you write to your subdomain
|
|
// so it must be in format subdomain.duckdns.org
|
|
// not in format subsubdomain.subdomain.duckdns.org
|
|
// so strip off everything that is not top 3 levels
|
|
func getMainDomain(domain string) string {
|
|
domain = dns01.UnFqdn(domain)
|
|
|
|
split := dns.Split(domain)
|
|
if strings.HasSuffix(strings.ToLower(domain), "duckdns.org") {
|
|
if len(split) < 3 {
|
|
return ""
|
|
}
|
|
|
|
firstSubDomainIndex := split[len(split)-3]
|
|
return domain[firstSubDomainIndex:]
|
|
}
|
|
|
|
return domain[split[len(split)-1]:]
|
|
}
|