]>
git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_artfiles.sh
3 ################################################################################
4 # ACME.sh 3rd party DNS API plugin for ArtFiles.de
5 ################################################################################
6 # Author: Martin Arndt, https://troublezone.net/
8 # Issues: https://github.com/Eagle3386/acme.sh/issues
9 ################################################################################
11 # 1. export AF_API_USERNAME="api12345678"
12 # 2. export AF_API_PASSWORD="apiPassword"
13 # 3. acme.sh --issue -d example.com --dns dns_artfiles
14 ################################################################################
16 ########## API configuration ###################################################
17 AF_API_SUCCESS
='status":"OK'
18 AF_URL_DCP
='https://dcp.c.artfiles.de/api/'
19 AF_URL_DNS
=${AF_URL_DCP}'dns/{*}_dns.html?domain='
20 AF_URL_DOMAINS
=${AF_URL_BASE}'domain/get_domains.html'
22 ########## Public functions ####################################################
24 # Adds a new TXT record for given ACME challenge value & domain.
25 # Usage: dns_artfiles_add _acme-challenge.www.example.com "ACME challenge value"
29 _info
'Using ArtFiles.de DNS addition API'
30 _debug
'Domain' "$domain"
31 _debug
'txtValue' "$txtValue"
33 AF_API_USERNAME
="${AF_API_USERNAME:-$(_readaccountconf_mutable AF_API_USERNAME)}"
34 AF_API_PASSWORD
="${AF_API_PASSWORD:-$(_readaccountconf_mutable AF_API_PASSWORD)}"
35 if [ -z "$AF_API_USERNAME" ] ||
[ -z "$AF_API_PASSWORD" ]; then
36 _err
'Missing ArtFiles.de username and/or password.'
37 _err
'Please ensure both are set via export command & try again.'
42 _saveaccountconf_mutable
'AF_API_USERNAME' "$AF_API_USERNAME"
43 _saveaccountconf_mutable
'AF_API_PASSWORD' "$AF_API_PASSWORD"
48 if ! _contains
"$response" 'TXT'; then
49 _err
'Retrieving TXT records failed.'
55 _dns
'SET' "$(printf -- '%s\n_acme-challenge "%s
"' "$response" "$txtValue")"
56 if ! _contains
"$response" "$AF_API_SUCCESS"; then
57 _err
'Adding ACME challenge value failed.'
63 # Removes the existing TXT record for given ACME challenge value & domain.
64 # Usage: dns_artfiles_rm _acme-challenge.www.example.com "ACME challenge value"
68 _info
'Using ArtFiles.de DNS removal API'
69 _debug
'Domain' "$domain"
70 _debug
'txtValue' "$txtValue"
78 if ! _contains
"$response" "$txtValue"; then
79 _err
'Retrieved TXT records are missing given ACME challenge value.'
85 response
="$(printf -- '%s' "$response" | sed '$d')"
86 _dns
'SET' "$response"
87 if ! _contains
"$response" "$AF_API_SUCCESS"; then
88 _err
'Removing ACME challenge value failed.'
94 ########## Private functions ###################################################
96 # Cleans awful TXT records response of ArtFiles's API & pretty prints it.
97 # Usage: _clean_records
99 # Extract TXT part, strip trailing quote sign (ACME.sh API guidelines forbid
100 # usage of SED's GNU extensions, hence couldn't omit it via regex), strip '\'
101 # from '\"' & turn '\n' into real LF characters.
102 # Yup, awful API to use - but that's all we got to get this working, so... ;)
103 _debug2
'Raw ' "$response"
105 printf -- '%s' "$response"
106 \ | sed 's/^\(.*TXT":"\)\([^,}]*\)\(.*\)$/\2/;s/.$//;s/\\"/"/g;s/\\n/\n/g'
108 _debug2
'Clean' "$response"
111 # Executes an HTTP GET or POST request for getting or setting DNS records,
112 # containing given payload upon POST.
113 # Usage: _dns [GET | SET] [payload]
116 payload
="$(printf -- '%s' "$2" | _url_encode)"
118 printf -- '%s%s' "$AF_URL_DNS" "$domain"
119 \ | sed 's/{\*}/'"$
(printf -- '%s' "$action" | _lower_case
)"'/'
122 if [ "$action" = 'SET' ]; then
123 _debug2
'Payload' "$payload"
124 response
="$(_post '' "$url&TXT
=$payload" '' 'POST' 'application/x-www-form-urlencoded')"
126 response
="$(_get "$url" '' 10)"
129 if ! _contains
"$response" "$AF_API_SUCCESS"; then
130 _err
"DNS API error: $response"
135 _debug
'Response' "$response"
140 # Gets the root domain zone for given domain.
141 # Usage: _get_zone _acme-challenge.www.example.com
144 domains
="$(_get "$AF_URL_DOMAINS" "" 10)"
145 _info
'Getting domain zone...'
146 _debug2
'FQDN' "$fqdn"
147 _debug2
'Domains' "$domains"
149 while _contains
"$fqdn" "."; do
150 if _contains
"$domains" "$fqdn"; then
152 _info
"Found root domain zone: $domain"
156 _debug2
'FQDN' "$fqdn"
160 if [ "$domain" = "$fqdn" ]; then
164 _err
'Couldn\'t find root domain zone.'
169 # Adds the HTTP Authorization & Content-Type headers to a follow-up request.
170 # Usage: _set_headers
172 encoded
="$(printf -- '%s:%s' "$AF_API_USERNAME" "$AF_API_PASSWORD" | _base64)"
173 export _H1
="Authorization: Basic $encoded"
174 export _H2
='Content-Type: application/json'