Removed requirement for domain split location by getting available domains automatically. Removed uppercase domain removal bug.
This commit is contained in:
parent
a493033f7d
commit
2a21be7919
@ -349,6 +349,19 @@ Ok, let's issue a cert now:
|
|||||||
acme.sh --issue --dns dns_gandi_livedns -d example.com -d www.example.com
|
acme.sh --issue --dns dns_gandi_livedns -d example.com -d www.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 19. Use DigitalOcean API (native)
|
||||||
|
|
||||||
|
You need to obtain a read and write capable API key from your DigitalOcean account. See: https://www.digitalocean.com/help/api/
|
||||||
|
|
||||||
|
```
|
||||||
|
export DO_API_KEY="75310dc4ca779ac39a19f6355db573b49ce92ae126553ebd61ac3a3ae34834cc"
|
||||||
|
```
|
||||||
|
|
||||||
|
Ok, let's issue a cert now:
|
||||||
|
```
|
||||||
|
acme.sh --issue --dns dns_dgon -d example.com -d www.example.com
|
||||||
|
```
|
||||||
|
|
||||||
# Use custom API
|
# Use custom API
|
||||||
|
|
||||||
If your API is not supported yet, you can write your own DNS API.
|
If your API is not supported yet, you can write your own DNS API.
|
||||||
|
|||||||
@ -11,10 +11,6 @@
|
|||||||
##
|
##
|
||||||
## DO_API_KEY="75310dc4ca779ac39a19f6355db573b49ce92ae126553ebd61ac3a3ae34834cc"
|
## DO_API_KEY="75310dc4ca779ac39a19f6355db573b49ce92ae126553ebd61ac3a3ae34834cc"
|
||||||
##
|
##
|
||||||
## DO_DOMAIN_START="3"
|
|
||||||
## start of the digital ocean dns base domain from the LEFT
|
|
||||||
## (EG: one.two.three.four.five.com -> one.two & three.four.five.com)
|
|
||||||
##
|
|
||||||
|
|
||||||
##################### Public functions #####################
|
##################### Public functions #####################
|
||||||
|
|
||||||
@ -22,20 +18,18 @@
|
|||||||
## Usage: fulldomain txtvalue
|
## Usage: fulldomain txtvalue
|
||||||
## EG: "_acme-challenge.www.other.domain.com" "XKrxpRBosdq0HG9i01zxXp5CPBs"
|
## EG: "_acme-challenge.www.other.domain.com" "XKrxpRBosdq0HG9i01zxXp5CPBs"
|
||||||
dns_dgon_add() {
|
dns_dgon_add() {
|
||||||
fulldomain=$1
|
fulldomain="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
_info "Using digitalocean dns validation - add record"
|
_info "Using digitalocean dns validation - add record"
|
||||||
_debug fulldomain "$fulldomain"
|
_debug fulldomain "$fulldomain"
|
||||||
_debug txtvalue "$txtvalue"
|
_debug txtvalue "$txtvalue"
|
||||||
_debug DO_DOMAIN_START "$DO_DOMAIN_START"
|
|
||||||
|
|
||||||
## save the env vars (key and domain split location) for later automated use
|
## save the env vars (key and domain split location) for later automated use
|
||||||
_saveaccountconf DO_API_KEY "$DO_API_KEY"
|
_saveaccountconf DO_API_KEY "$DO_API_KEY"
|
||||||
_saveaccountconf DO_DOMAIN_START "$DO_DOMAIN_START"
|
|
||||||
|
|
||||||
## split the domain for DO API
|
## split the domain for DO API
|
||||||
if ! _get_base_domain "$fulldomain" "$DO_DOMAIN_START"; then
|
if ! _get_base_domain "$fulldomain"; then
|
||||||
_err "invalid domain or split"
|
_err "domain not found in your account for addition"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
@ -54,7 +48,7 @@ dns_dgon_add() {
|
|||||||
## args: BODY, URL, [need64, httpmethod]
|
## args: BODY, URL, [need64, httpmethod]
|
||||||
response="$(_post "$PBODY" "$PURL")"
|
response="$(_post "$PBODY" "$PURL")"
|
||||||
|
|
||||||
## check response (sort of)
|
## check response
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error in response: $response"
|
_err "error in response: $response"
|
||||||
return 1
|
return 1
|
||||||
@ -69,16 +63,15 @@ dns_dgon_add() {
|
|||||||
## Usage: fulldomain txtvalue
|
## Usage: fulldomain txtvalue
|
||||||
## EG: "_acme-challenge.www.other.domain.com" "XKrxpRBosdq0HG9i01zxXp5CPBs"
|
## EG: "_acme-challenge.www.other.domain.com" "XKrxpRBosdq0HG9i01zxXp5CPBs"
|
||||||
dns_dgon_rm() {
|
dns_dgon_rm() {
|
||||||
fulldomain=$1
|
fulldomain="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
_info "Using digitalocean dns validation - remove record"
|
_info "Using digitalocean dns validation - remove record"
|
||||||
_debug fulldomain "$fulldomain"
|
_debug fulldomain "$fulldomain"
|
||||||
_debug txtvalue "$txtvalue"
|
_debug txtvalue "$txtvalue"
|
||||||
_debug DO_DOMAIN_START "$DO_DOMAIN_START"
|
|
||||||
|
|
||||||
## split the domain for DO API
|
## split the domain for DO API
|
||||||
if ! _get_base_domain "$fulldomain" "$DO_DOMAIN_START"; then
|
if ! _get_base_domain "$fulldomain"; then
|
||||||
_err "invalid domain or split in remove"
|
_err "domain not found in your account for removal"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
@ -139,41 +132,74 @@ dns_dgon_rm() {
|
|||||||
|
|
||||||
##################### Private functions below #####################
|
##################### Private functions below #####################
|
||||||
|
|
||||||
## Split the domain provided at "base_domain_start_position" from the FRONT
|
## Split the domain provided into the "bade domain" and the "start prefix".
|
||||||
## USAGE: fulldomain base_domain_start_position
|
## This function searches for the longest subdomain in your account
|
||||||
## EG: "_acme-challenge.two.three.four.domain.com" "3"
|
## for the full domain given and splits it into the base domain (zone)
|
||||||
|
## and the prefix/record to be added/removed
|
||||||
|
## USAGE: fulldomain
|
||||||
|
## EG: "_acme-challenge.two.three.four.domain.com"
|
||||||
## returns
|
## returns
|
||||||
## _sub_domain="_acme-challenge.two"
|
## _sub_domain="_acme-challenge.two"
|
||||||
## _domain="three.four.domain.com"
|
## _domain="three.four.domain.com" *IF* zone "three.four.domain.com" exists
|
||||||
|
## if only "domain.com" exists it will return
|
||||||
|
## _sub_domain="_acme-challenge.two.three.four"
|
||||||
|
## _domain="domain.com"
|
||||||
_get_base_domain() {
|
_get_base_domain() {
|
||||||
# args
|
# args
|
||||||
domain=$1
|
fulldomain="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
|
||||||
dom_point=$2
|
_debug fulldomain "$fulldomain"
|
||||||
sub_point=$(_math "$dom_point" - 1)
|
|
||||||
_debug "split domain" "$domain"
|
|
||||||
_debug "split dom_point" "$dom_point"
|
|
||||||
_debug "split sub_point" "$sub_point"
|
|
||||||
|
|
||||||
# domain max length - 253
|
# domain max legal length = 253
|
||||||
MAX_DOM=255
|
MAX_DOM=255
|
||||||
|
|
||||||
## cut in half and check
|
## get a list of domains for the account to check thru
|
||||||
_domain=$(printf "%s" "$domain" | cut -d . -f "$dom_point"-"$MAX_DOM")
|
## Set the headers
|
||||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$sub_point")
|
export _H1="Content-Type: application/json"
|
||||||
if [ -z "$_domain" ]; then
|
export _H2="Authorization: Bearer $DO_API_KEY"
|
||||||
## not valid
|
_debug DO_API_KEY "$DO_API_KEY"
|
||||||
_err "invalid split location"
|
## get URL for the list of domains
|
||||||
return 1
|
## havent seen this request paginated, tested with 18 domains (more requres manual requests with DO)
|
||||||
fi
|
DOMURL="https://api.digitalocean.com/v2/domains"
|
||||||
if [ -z "$_sub_domain" ]; then
|
|
||||||
## not valid
|
## get the domain list (DO gives basically a full XFER!)
|
||||||
_err "invalid split location"
|
domain_list="$(_get "$DOMURL")"
|
||||||
|
|
||||||
|
## check response
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
_err "error in domain_list response: $domain_list"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
_debug2 domain_list "$domain_list"
|
||||||
|
|
||||||
_debug "split _domain" "$_domain"
|
## for each shortening of our $fulldomain, check if it exists in the $domain_list
|
||||||
_debug "split _sub_domain" "$_sub_domain"
|
## can never start on 1 (aka whole $fulldomain) as $fulldomain starts with "_acme-challenge"
|
||||||
|
i=2
|
||||||
|
while [ $i -gt 0 ]; do
|
||||||
|
## get next longest domain
|
||||||
|
_domain=$(printf "%s" "$fulldomain" | cut -d . -f "$i"-"$MAX_DOM")
|
||||||
|
## check we got something back from our cut (or are we at the end)
|
||||||
|
if [ -z "$_domain" ]; then
|
||||||
|
## we got to the end of the domain - invalid domain
|
||||||
|
_err "domain not found in DigitalOcean account"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
## we got part of a domain back - grep it out
|
||||||
|
found="$(echo "$domain_list" | _egrep_o "\"name\"\s*\:\s*\"$_domain\"")"
|
||||||
|
## check if it exists
|
||||||
|
if [ ! -z "$found" ]; then
|
||||||
|
## exists - exit loop returning the parts
|
||||||
|
sub_point=$(_math $i - 1)
|
||||||
|
_sub_domain=$(printf "%s" "$fulldomain" | cut -d . -f 1-"$sub_point")
|
||||||
|
_debug _domain "$_domain"
|
||||||
|
_debug _sub_domain "$_sub_domain"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
## increment cut point $i
|
||||||
|
i=$(_math $i + 1)
|
||||||
|
done
|
||||||
|
|
||||||
## all ok
|
## we went through the entire domain zone list and dint find one that matched
|
||||||
return 0
|
## doesnt look like we can add in the record
|
||||||
|
_err "domain not found in DigitalOcean account, but we should never get here"
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user