forked from Github/acme.sh
neil
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 797 additions and 45 deletions
-
3Dockerfile
-
11README.md
-
46acme.sh
-
93dnsapi/README.md
-
50dnsapi/dns_hostingde.sh
-
4dnsapi/dns_nsone.sh
-
211dnsapi/dns_nw.sh
-
217dnsapi/dns_online.sh
-
207dnsapi/dns_rackspace.sh
@ -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