forked from Github/acme.sh
Sebastiaan Hoogeveen
6 years ago
15 changed files with 1460 additions and 130 deletions
-
3Dockerfile
-
14README.md
-
372acme.sh
-
18deploy/README.md
-
59deploy/mydevil.sh
-
2deploy/qiniu.sh
-
134dnsapi/README.md
-
157dnsapi/dns_cn.sh
-
50dnsapi/dns_hostingde.sh
-
97dnsapi/dns_mydevil.sh
-
45dnsapi/dns_namecheap.sh
-
4dnsapi/dns_nsone.sh
-
211dnsapi/dns_nw.sh
-
217dnsapi/dns_online.sh
-
207dnsapi/dns_rackspace.sh
@ -0,0 +1,59 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: mydevil_deploy domain keyfile certfile cafile fullchain |
||||
|
mydevil_deploy() { |
||||
|
_cdomain="$1" |
||||
|
_ckey="$2" |
||||
|
_ccert="$3" |
||||
|
_cca="$4" |
||||
|
_cfullchain="$5" |
||||
|
ip="" |
||||
|
|
||||
|
_debug _cdomain "$_cdomain" |
||||
|
_debug _ckey "$_ckey" |
||||
|
_debug _ccert "$_ccert" |
||||
|
_debug _cca "$_cca" |
||||
|
_debug _cfullchain "$_cfullchain" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
ip=$(mydevil_get_ip "$_cdomain") |
||||
|
if [ -z "$ip" ]; then |
||||
|
_err "Could not find IP for domain $_cdomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Delete old certificate first |
||||
|
_info "Removing old certificate for $_cdomain at $ip" |
||||
|
devil ssl www del "$ip" "$_cdomain" |
||||
|
|
||||
|
# Add new certificate |
||||
|
_info "Adding new certificate for $_cdomain at $ip" |
||||
|
devil ssl www add "$ip" "$_cfullchain" "$_ckey" "$_cdomain" || return 1 |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: ip=$(mydevil_get_ip domain.com) |
||||
|
# echo $ip |
||||
|
mydevil_get_ip() { |
||||
|
devil dns list "$1" | cut -w -s -f 3,7 | grep "^A$(printf '\t')" | cut -w -s -f 2 || return 1 |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,157 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# DNS API for acme.sh for Core-Networks (https://beta.api.core-networks.de/doc/). |
||||
|
# created by 5ll and francis |
||||
|
|
||||
|
CN_API="https://beta.api.core-networks.de" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_cn_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _cn_login; then |
||||
|
_err "login failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _cn_get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "_sub_domain $_sub_domain" |
||||
|
_debug "_domain $_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
curData="{\"name\":\"$_sub_domain\",\"ttl\":120,\"type\":\"TXT\",\"data\":\"$txtvalue\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records/")" |
||||
|
|
||||
|
_debug "curData $curData" |
||||
|
_debug "curResult $curResult" |
||||
|
|
||||
|
if _contains "$curResult" ""; then |
||||
|
_info "Added, OK" |
||||
|
|
||||
|
if ! _cn_commit; then |
||||
|
_err "commiting changes failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
|
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
_debug "curData is $curData" |
||||
|
_debug "curResult is $curResult" |
||||
|
_err "error adding text record, response was $curResult" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
dns_cn_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _cn_login; then |
||||
|
_err "login failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _cn_get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Deleting record" |
||||
|
curData="{\"name\":\"$_sub_domain\",\"data\":\"$txtvalue\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records/delete")" |
||||
|
_debug curData is "$curData" |
||||
|
|
||||
|
_info "commiting changes" |
||||
|
if ! _cn_commit; then |
||||
|
_err "commiting changes failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Deletet txt record" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
################### Private functions below ################################## |
||||
|
_cn_login() { |
||||
|
CN_User="${CN_User:-$(_readaccountconf_mutable CN_User)}" |
||||
|
CN_Password="${CN_Password:-$(_readaccountconf_mutable CN_Password)}" |
||||
|
if [ -z "$CN_User" ] || [ -z "$CN_Password" ]; then |
||||
|
CN_User="" |
||||
|
CN_Password="" |
||||
|
_err "You must export variables: CN_User and CN_Password" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the config variables to the account conf file. |
||||
|
_saveaccountconf_mutable CN_User "$CN_User" |
||||
|
_saveaccountconf_mutable CN_Password "$CN_Password" |
||||
|
|
||||
|
_info "Getting an AUTH-Token" |
||||
|
curData="{\"login\":\"${CN_User}\",\"password\":\"${CN_Password}\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/auth/token")" |
||||
|
_debug "Calling _CN_login: '${curData}' '${CN_API}/auth/token'" |
||||
|
|
||||
|
if _contains "${curResult}" '"token":"'; then |
||||
|
authToken=$(echo "${curResult}" | cut -d ":" -f2 | cut -d "," -f1 | sed 's/^.\(.*\).$/\1/') |
||||
|
export _H1="Authorization: Bearer $authToken" |
||||
|
_info "Successfully acquired AUTH-Token" |
||||
|
_debug "AUTH-Token: '${authToken}'" |
||||
|
_debug "_H1 '${_H1}'" |
||||
|
else |
||||
|
_err "Couldn't acquire an AUTH-Token" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Commit changes |
||||
|
_cn_commit() { |
||||
|
_info "Commiting changes" |
||||
|
_post "" "${CN_API}/dnszones/$h/records/commit" |
||||
|
} |
||||
|
|
||||
|
_cn_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
|
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
_debug _H1 "${_H1}" |
||||
|
|
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_cn_zonelist="$(_get ${CN_API}/dnszones/)" |
||||
|
_debug _cn_zonelist "${_cn_zonelist}" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "something went wrong while getting the zone list" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$_cn_zonelist" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "Zonelist does not contain domain - iterating " |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
|
||||
|
done |
||||
|
_err "Zonelist does not contain domain - exiting" |
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,97 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_mydevil_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_mydevil_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# No need to check if record name exists, `devil` always adds new record. |
||||
|
# In worst case scenario, we end up with multiple identical records. |
||||
|
|
||||
|
_info "Adding $fulldomain record for domain $domain" |
||||
|
if devil dns add "$domain" "$fulldomain" TXT "$txtvalue"; then |
||||
|
_info "Successfully added TXT record, ready for validation." |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Unable to add DNS record." |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_mydevil_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# catch one or more numbers |
||||
|
num='[0-9][0-9]*' |
||||
|
# catch one or more whitespace |
||||
|
w=$(printf '[\t ][\t ]*') |
||||
|
# catch anything, except newline |
||||
|
any='.*' |
||||
|
# filter to make sure we do not delete other records |
||||
|
validRecords="^${num}${w}${fulldomain}${w}TXT${w}${any}${txtvalue}$" |
||||
|
for id in $(devil dns list "$domain" | tail -n+2 | grep "${validRecords}" | cut -w -s -f 1); do |
||||
|
_info "Removing record $id from domain $domain" |
||||
|
devil dns del "$domain" "$id" || _err "Could not remove DNS record." |
||||
|
done |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: domain=$(mydevil_get_domain "_acme-challenge.www.domain.com" || _err "Invalid domain name") |
||||
|
# echo $domain |
||||
|
mydevil_get_domain() { |
||||
|
fulldomain=$1 |
||||
|
domain="" |
||||
|
|
||||
|
for domain in $(devil dns list | cut -w -s -f 1 | tail -n+2); do |
||||
|
if _endswith "$fulldomain" "$domain"; then |
||||
|
printf -- "%s" "$domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,211 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
######################################################################## |
||||
|
# NocWorx script for acme.sh |
||||
|
# |
||||
|
# Handles DNS Updates for the Following vendors: |
||||
|
# - Nexcess.net |
||||
|
# - Thermo.io |
||||
|
# - Futurehosting.com |
||||
|
# |
||||
|
# Environment variables: |
||||
|
# |
||||
|
# - NW_API_TOKEN (Your API Token) |
||||
|
# - NW_API_ENDPOINT (One of the following listed below) |
||||
|
# |
||||
|
# Endpoints: |
||||
|
# - https://portal.nexcess.net (default) |
||||
|
# - https://core.thermo.io |
||||
|
# - https://my.futurehosting.com |
||||
|
# |
||||
|
# Note: If you do not have an API token, one can be generated at one |
||||
|
# of the following URLs: |
||||
|
# - https://portal.nexcess.net/api-token |
||||
|
# - https://core.thermo.io/api-token |
||||
|
# - https://my.futurehosting.com/api-token |
||||
|
# |
||||
|
# Author: Frank Laszlo <flaszlo@nexcess.net> |
||||
|
|
||||
|
NW_API_VERSION="0" |
||||
|
|
||||
|
# dns_nw_add() - Add TXT record |
||||
|
# Usage: dns_nw_add _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_add() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_add() '${host}' '${txtvalue}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_post_data="{\"zone_id\": \"${_zone_id}\", \"type\": \"TXT\", \"host\": \"${host}\", \"target\": \"${txtvalue}\", \"ttl\": \"300\"}" |
||||
|
|
||||
|
if _rest POST "dns-record" "${_post_data}" && [ -n "${response}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${response}" | _egrep_o "\"record_id\": *[0-9]+" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Error adding the TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "TXT record successfully added." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# dns_nw_rm() - Remove TXT record |
||||
|
# Usage: dns_nw_rm _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_rm() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_rm() '${host}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_parameters="?zone_id=${_zone_id}" |
||||
|
|
||||
|
if _rest GET "dns-record" "${_parameters}" && [ -n "${response}" ]; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"record_id":/|"record_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
_debug response "${response}" |
||||
|
|
||||
|
record="$(echo "${response}" | _egrep_o "{.*\"host\": *\"${_sub_domain}\", *\"target\": *\"${txtvalue}\".*}")" |
||||
|
_debug record "${record}" |
||||
|
|
||||
|
if [ "${record}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${record}" | _egrep_o "\"record_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_record_id}" ]; then |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
_rest DELETE "dns-record/${_record_id}" |
||||
|
|
||||
|
_info "TXT record successfully deleted." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_check_nw_api_creds() { |
||||
|
NW_API_TOKEN="${NW_API_TOKEN:-$(_readaccountconf_mutable NW_API_TOKEN)}" |
||||
|
NW_API_ENDPOINT="${NW_API_ENDPOINT:-$(_readaccountconf_mutable NW_API_ENDPOINT)}" |
||||
|
|
||||
|
if [ -z "${NW_API_ENDPOINT}" ]; then |
||||
|
NW_API_ENDPOINT="https://portal.nexcess.net" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "${NW_API_TOKEN}" ]; then |
||||
|
_err "You have not defined your NW_API_TOKEN." |
||||
|
_err "Please create your token and try again." |
||||
|
_err "If you need to generate a new token, please visit one of the following URLs:" |
||||
|
_err " - https://portal.nexcess.net/api-token" |
||||
|
_err " - https://core.thermo.io/api-token" |
||||
|
_err " - https://my.futurehosting.com/api-token" |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable NW_API_TOKEN "${NW_API_TOKEN}" |
||||
|
_saveaccountconf_mutable NW_API_ENDPOINT "${NW_API_ENDPOINT}" |
||||
|
} |
||||
|
|
||||
|
_get_root() { |
||||
|
domain="${1}" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if _rest GET "dns-zone"; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"zone_id":/|"zone_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
|
||||
|
_debug response "${response}" |
||||
|
while true; do |
||||
|
h=$(printf "%s" "${domain}" | cut -d . -f $i-100) |
||||
|
_debug h "${h}" |
||||
|
if [ -z "${h}" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hostedzone="$(echo "${response}" | _egrep_o "{.*\"domain\": *\"${h}\".*}")" |
||||
|
if [ "${hostedzone}" ]; then |
||||
|
_zone_id=$(printf "%s\n" "${hostedzone}" | _egrep_o "\"zone_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_zone_id}" ]; then |
||||
|
_sub_domain=$(printf "%s" "${domain}" | cut -d . -f 1-${p}) |
||||
|
_domain="${h}" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "${i}" + 1) |
||||
|
done |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_rest() { |
||||
|
method="${1}" |
||||
|
ep="/${2}" |
||||
|
data="${3}" |
||||
|
|
||||
|
_debug method "${method}" |
||||
|
_debug ep "${ep}" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Api-Version: ${NW_API_VERSION}" |
||||
|
export _H4="User-Agent: NW-ACME-CLIENT" |
||||
|
export _H5="Authorization: Bearer ${NW_API_TOKEN}" |
||||
|
|
||||
|
if [ "${method}" != "GET" ]; then |
||||
|
_debug data "${data}" |
||||
|
response="$(_post "${data}" "${NW_API_ENDPOINT}${ep}" "" "${method}")" |
||||
|
else |
||||
|
response="$(_get "${NW_API_ENDPOINT}${ep}${data}")" |
||||
|
fi |
||||
|
|
||||
|
if [ "${?}" != "0" ]; then |
||||
|
_err "error ${ep}" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "${response}" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,217 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Online API |
||||
|
# https://console.online.net/en/api/ |
||||
|
# |
||||
|
# Requires Online API key set in ONLINE_API_KEY |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
ONLINE_API="https://api.online.net/api/v1" |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_online_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
_debug _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
_online_create_TXT_record "$_real_dns_version" "$_sub_domain" "$txtvalue" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Record added." |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain |
||||
|
dns_online_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
_debug _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
if ! _online_rest GET "domain/$_domain/version/active"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
rid=$(echo "$response" | _egrep_o "\"id\":[0-9]+,\"name\":\"$_sub_domain\",\"data\":\"\\\u0022$txtvalue\\\u0022\"" | cut -d ':' -f 2 | cut -d ',' -f 1) |
||||
|
_debug rid "$rid" |
||||
|
if [ -z "$rid" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Removing DNS record" |
||||
|
_online_rest DELETE "domain/$_domain/version/$_real_dns_version/zone/$rid" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_online_check_config() { |
||||
|
ONLINE_API_KEY="${ONLINE_API_KEY:-$(_readaccountconf_mutable ONLINE_API_KEY)}" |
||||
|
if [ -z "$ONLINE_API_KEY" ]; then |
||||
|
_err "No API key specified for Online API." |
||||
|
_err "Create your key and export it as ONLINE_API_KEY" |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _online_rest GET "domain/"; then |
||||
|
_err "Invalid API key specified for Online API." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ONLINE_API_KEY "$ONLINE_API_KEY" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_online_rest GET "domain/$h/version/active" |
||||
|
|
||||
|
if ! _contains "$response" "Domain not found" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
_real_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
_err "Unable to retrive DNS zone matching this domain" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# this function create a temporary zone version |
||||
|
# as online.net does not allow updating an active version |
||||
|
_online_create_temporary_zone_version() { |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version" "name=acme.sh" |
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_temporary_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
|
||||
|
# Creating a dummy record in this temporary version, because online.net doesn't accept enabling an empty version |
||||
|
_online_create_TXT_record "$_temporary_dns_version" "dummy.acme.sh" "dummy" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_destroy_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest DELETE "domain/$_domain/version/$version_id" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_enable_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest PATCH "domain/$_domain/version/$version_id/enable" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_create_TXT_record() { |
||||
|
version=$1 |
||||
|
txt_name=$2 |
||||
|
txt_value=$3 |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version/$version/zone" "type=TXT&name=$txt_name&data=%22$txt_value%22&ttl=60&priority=0" |
||||
|
|
||||
|
# Note : the normal, expected response SHOULD be "Unknown method". |
||||
|
# this happens because the API HTTP response contains a Location: header, that redirect |
||||
|
# to an unknown online.net endpoint. |
||||
|
if [ "$?" != "0" ] || _contains "$response" "Unknown method" || _contains "$response" "\$ref"; then |
||||
|
return 0 |
||||
|
else |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_online_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
_online_url="$ONLINE_API/$ep" |
||||
|
_debug2 _online_url "$_online_url" |
||||
|
export _H1="Authorization: Bearer $ONLINE_API_KEY" |
||||
|
export _H2="X-Pretty-JSON: 1" |
||||
|
if [ "$data" ] || [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$_online_url" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$_online_url")" |
||||
|
fi |
||||
|
if [ "$?" != "0" ] || _contains "$response" "invalid_grant" || _contains "$response" "Method not allowed"; then |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,207 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# |
||||
|
#RACKSPACE_Username="" |
||||
|
# |
||||
|
#RACKSPACE_Apikey="" |
||||
|
|
||||
|
RACKSPACE_Endpoint="https://dns.api.rackspacecloud.com/v1.0" |
||||
|
|
||||
|
# 20190213 - The name & id fields swapped in the API response; fix sed |
||||
|
# 20190101 - Duplicating file for new pull request to dev branch |
||||
|
# Original - tcocca:rackspace_dnsapi https://github.com/Neilpang/acme.sh/pull/1297 |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_rackspace_add() { |
||||
|
fulldomain="$1" |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue="$2" |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Creating TXT record." |
||||
|
if ! _rackspace_rest POST "$RACKSPACE_Tenant/domains/$_domain_id/records" "{\"records\":[{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":300}]}"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if ! _contains "$response" "$txtvalue" >/dev/null; then |
||||
|
_err "Could not add TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_rackspace_rm() { |
||||
|
fulldomain=$1 |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue=$2 |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Checking for TXT record." |
||||
|
if ! _get_recordid "$_domain_id" "$fulldomain" "$txtvalue"; then |
||||
|
_err "Could not get TXT record id." |
||||
|
return 1 |
||||
|
fi |
||||
|
if [ "$_dns_record_id" = "" ]; then |
||||
|
_err "TXT record not found." |
||||
|
return 1 |
||||
|
fi |
||||
|
_info "Removing TXT record." |
||||
|
if ! _delete_txt_record "$_domain_id" "$_dns_record_id"; then |
||||
|
_err "Could not remove TXT record $_dns_record_id." |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root_zone() { |
||||
|
domain="$1" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
# Response looks like: |
||||
|
# {"ttl":300,"accountId":12345,"id":1111111,"name":"example.com","emailAddress": ...<and so on> |
||||
|
_domain_id=$(echo "$response" | sed -n "s/^.*\"id\":\([^,]*\),\"name\":\"$h\",.*/\1/p") |
||||
|
_debug2 domain_id "$_domain_id" |
||||
|
if [ -n "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_get_recordid() { |
||||
|
domainid="$1" |
||||
|
fulldomain="$2" |
||||
|
txtvalue="$3" |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains/$domainid/records?name=$fulldomain&type=TXT"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "$txtvalue"; then |
||||
|
_dns_record_id=0 |
||||
|
return 0 |
||||
|
fi |
||||
|
_dns_record_id=$(echo "$response" | tr '{' "\n" | grep "\"data\":\"$txtvalue\"" | sed -n 's/^.*"id":"\([^"]*\)".*/\1/p') |
||||
|
_debug _dns_record_id "$_dns_record_id" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_delete_txt_record() { |
||||
|
domainid="$1" |
||||
|
_dns_record_id="$2" |
||||
|
if ! _rackspace_rest DELETE "$RACKSPACE_Tenant/domains/$domainid/records?id=$_dns_record_id"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "RUNNING"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug ep "$ep" |
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="X-Auth-Token: $RACKSPACE_Token" |
||||
|
export _H3="X-Project-Id: $RACKSPACE_Tenant" |
||||
|
export _H4="Content-Type: application/json" |
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$RACKSPACE_Endpoint/$ep" "" "$m")" |
||||
|
retcode=$? |
||||
|
else |
||||
|
_info "Getting $RACKSPACE_Endpoint/$ep" |
||||
|
response="$(_get "$RACKSPACE_Endpoint/$ep")" |
||||
|
retcode=$? |
||||
|
fi |
||||
|
|
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_authorization() { |
||||
|
export _H1="Content-Type: application/json" |
||||
|
data="{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username\":\"$RACKSPACE_Username\",\"apiKey\":\"$RACKSPACE_Apikey\"}}}" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "https://identity.api.rackspacecloud.com/v2.0/tokens" "" "POST")" |
||||
|
retcode=$? |
||||
|
_debug2 response "$response" |
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "Authentication failed." |
||||
|
return 1 |
||||
|
fi |
||||
|
if _contains "$response" "token"; then |
||||
|
RACKSPACE_Token="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)",".*/\1/p')" |
||||
|
RACKSPACE_Tenant="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)"}.*/\1/p')" |
||||
|
_debug RACKSPACE_Token "$RACKSPACE_Token" |
||||
|
_debug RACKSPACE_Tenant "$RACKSPACE_Tenant" |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_auth() { |
||||
|
# retrieve the rackspace creds |
||||
|
RACKSPACE_Username="${RACKSPACE_Username:-$(_readaccountconf_mutable RACKSPACE_Username)}" |
||||
|
RACKSPACE_Apikey="${RACKSPACE_Apikey:-$(_readaccountconf_mutable RACKSPACE_Apikey)}" |
||||
|
# check their vals for null |
||||
|
if [ -z "$RACKSPACE_Username" ] || [ -z "$RACKSPACE_Apikey" ]; then |
||||
|
RACKSPACE_Username="" |
||||
|
RACKSPACE_Apikey="" |
||||
|
_err "You didn't specify a Rackspace username and api key." |
||||
|
_err "Please set those values and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
# save the username and api key to the account conf file. |
||||
|
_saveaccountconf_mutable RACKSPACE_Username "$RACKSPACE_Username" |
||||
|
_saveaccountconf_mutable RACKSPACE_Apikey "$RACKSPACE_Apikey" |
||||
|
if [ -z "$RACKSPACE_Token" ]; then |
||||
|
_info "Getting authorization token." |
||||
|
if ! _rackspace_authorization; then |
||||
|
_err "Can not get token." |
||||
|
fi |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_rootzone() { |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root_zone "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue