2019-05-06 17:12:50 +02:00
#!/usr/bin/env sh
2019-05-06 17:14:31 +02:00
## Acmeproxy DNS provider to be used with acmeproxy (http://github.com/mdbraber/acmeproxy)
## API integration by Maarten den Braber
2019-05-06 17:12:50 +02:00
##
2019-05-06 17:14:31 +02:00
## Report any bugs via https://github.com/mdbraber/acme.sh
2019-05-06 17:12:50 +02:00
dns_acmeproxy_add( ) {
fulldomain = " ${ 1 } "
txtvalue = " ${ 2 } "
action = "present"
_debug " Calling: _acmeproxy_request() ' ${ fulldomain } ' ' ${ txtvalue } ' ' ${ action } ' "
2019-05-07 16:47:23 +02:00
_acmeproxy_request " $fulldomain " " $txtvalue " " $action "
2019-05-06 17:12:50 +02:00
}
dns_acmeproxy_rm( ) {
fulldomain = " ${ 1 } "
txtvalue = " ${ 2 } "
action = "cleanup"
_debug " Calling: _acmeproxy_request() ' ${ fulldomain } ' ' ${ txtvalue } ' ' ${ action } ' "
2019-05-07 16:47:23 +02:00
_acmeproxy_request " $fulldomain " " $txtvalue " " $action "
2019-05-06 17:12:50 +02:00
}
_acmeproxy_request( ) {
## Nothing to see here, just some housekeeping
fulldomain = $1
txtvalue = $2
action = $3
_info "Using acmeproxy"
_debug fulldomain " $fulldomain "
_debug txtvalue " $txtvalue "
ACMEPROXY_ENDPOINT = " ${ ACMEPROXY_ENDPOINT :- $( _readaccountconf_mutable ACMEPROXY_ENDPOINT) } "
ACMEPROXY_USERNAME = " ${ ACMEPROXY_USERNAME :- $( _readaccountconf_mutable ACMEPROXY_USERNAME) } "
ACMEPROXY_PASSWORD = " ${ ACMEPROXY_PASSWORD :- $( _readaccountconf_mutable ACMEPROXY_PASSWORD) } "
## Check for the endpoint
2019-05-07 16:47:23 +02:00
if [ -z " $ACMEPROXY_ENDPOINT " ] ; then
2019-05-06 17:12:50 +02:00
ACMEPROXY_ENDPOINT = ""
_err "You didn't specify the endpoint"
_err "Please set them via 'export ACMEPROXY_ENDPOINT=https://ip:port' and try again."
return 1
fi
## Save the credentials to the account file
_saveaccountconf_mutable ACMEPROXY_ENDPOINT " $ACMEPROXY_ENDPOINT "
_saveaccountconf_mutable ACMEPROXY_USERNAME " $ACMEPROXY_USERNAME "
_saveaccountconf_mutable ACMEPROXY_PASSWORD " $ACMEPROXY_PASSWORD "
2019-05-13 08:45:57 +02:00
if [ -z " $ACMEPROXY_USERNAME " ] || [ -z " $ACMEPROXY_PASSWORD " ] ; then
_info "ACMEPROXY_USERNAME and/or ACMEPROXY_PASSWORD not set - using without client authentication! Make sure you're using server authentication (e.g. IP-based)"
export _H1 = "Accept: application/json"
export _H2 = "Content-Type: application/json"
else
## Base64 encode the credentials
credentials = $( printf "%b" " $ACMEPROXY_USERNAME : $ACMEPROXY_PASSWORD " | _base64)
2019-05-06 17:12:50 +02:00
2019-05-13 08:45:57 +02:00
## Construct the HTTP Authorization header
export _H1 = " Authorization: Basic $credentials "
export _H2 = "Accept: application/json"
export _H3 = "Content-Type: application/json"
fi
2019-05-06 17:12:50 +02:00
## Add the challenge record to the acmeproxy grid member
response = " $( _post " {\"fqdn\": \" $fulldomain .\", \"value\": \" $txtvalue \"} " " $ACMEPROXY_ENDPOINT / $action " "" "POST" ) "
## Let's see if we get something intelligible back from the unit
2019-05-07 16:47:23 +02:00
if echo " $response " | grep " \" $txtvalue \" " >/dev/null; then
2019-05-06 18:31:58 +02:00
_info "Successfully updated the txt record"
2019-05-06 17:12:50 +02:00
return 0
else
_err "Error encountered during record addition"
_err " $response "
return 1
fi
}
#################### Private functions below ##################################