|
|
@ -1,4 +1,4 @@ |
|
|
|
#!/usr/bin/env #!/bin/sh |
|
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
# Author: Mohammad Ali Sarbanha <sarbanha at yahoo dot com> |
|
|
|
# Repository: https://github.com/sarbanha/acme.sh-dnsapi-dns_arvancdn |
|
|
@ -16,30 +16,30 @@ dns_arvancdn_add() { |
|
|
|
_debug "dns_arvan_add(): Started" |
|
|
|
|
|
|
|
ARVAN_API_KEY="${ARVAN_API_KEY:-$(_readaccountconf_mutable ARVAN_API_KEY)}" |
|
|
|
if [ -z $ARVAN_API_KEY ]; then |
|
|
|
if [ -z "${ARVAN_API_KEY}" ]; then |
|
|
|
ARVAN_API_KEY="" |
|
|
|
_err "dns_arvan_add(): ARVAN_API_KEY has not been defined yet." |
|
|
|
_err "dns_arvan_add(): export ARVAN_API_KEY=\"---YOUR-API-KEY---\"" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
_saveaccountconf_mutable ARVAN_API_KEY "$ARVAN_API_KEY" |
|
|
|
_saveaccountconf_mutable ARVAN_API_KEY "${ARVAN_API_KEY}" |
|
|
|
|
|
|
|
_debug "dns_arvan_add(): Check domain root zone availability for $_fulldomain" |
|
|
|
_zone=$(_get_root $_fulldomain) |
|
|
|
_debug "dns_arvan_add(): Check domain root zone availability for ${_fulldomain}" |
|
|
|
_zone=$(_get_root "${_fulldomain}") |
|
|
|
if [ $? -ne 0 ]; then |
|
|
|
_err "dns_arvan_add(): Root zone for $_fulldomain not found!" |
|
|
|
_err "dns_arvan_add(): Root zone for ${_fulldomain} not found!" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
_record_name=$(echo $_zone | sed "s/\.\..*//") |
|
|
|
_zone=$(echo $_zone | sed "s/.*\.\.//") |
|
|
|
_record_name=$(echo "${_zone}" | sed "s/\.\..*//") |
|
|
|
_zone=$(echo "${_zone}" | sed "s/.*\.\.//") |
|
|
|
|
|
|
|
_debug "dns_arvan_add(): fulldomain $_fulldomain" |
|
|
|
_debug "dns_arvan_add(): textvalue $_challenge" |
|
|
|
_debug "dns_arvan_add(): domain $_record_name" |
|
|
|
_debug "dns_arvan_add(): domain $_zone" |
|
|
|
_debug "dns_arvan_add(): fulldomain ${_fulldomain}" |
|
|
|
_debug "dns_arvan_add(): textvalue ${_challenge}" |
|
|
|
_debug "dns_arvan_add(): domain ${_record_name}" |
|
|
|
_debug "dns_arvan_add(): domain ${_zone}" |
|
|
|
|
|
|
|
_record_add $_record_name $_zone $_challenge |
|
|
|
_record_add "${_record_name}" "${_zone}" "${_challenge}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -50,26 +50,26 @@ dns_arvancdn_rm(){ |
|
|
|
_challenge=$2 |
|
|
|
|
|
|
|
ARVAN_API_KEY="${ARVAN_API_KEY:-$(_readaccountconf_mutable ARVAN_API_KEY)}" |
|
|
|
if [ -z $ARVAN_API_KEY ]; then |
|
|
|
if [ -z "${ARVAN_API_KEY}" ]; then |
|
|
|
ARVAN_API_KEY="" |
|
|
|
_err "dns_arvan_rm(): ARVAN_API_KEY has not been defined yet." |
|
|
|
_err "dns_arvan_rm(): export ARVAN_API_KEY=\"---YOUR-API-KEY---\"" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
_zone=$(_get_root $_fulldomain) |
|
|
|
_zone=$(_get_root "${_fulldomain}") |
|
|
|
if [ $? -ne 0 ]; then |
|
|
|
_err "dns_arvan_rm(): Root zone for $_fulldomain not found!" |
|
|
|
_err "dns_arvan_rm(): Root zone for ${_fulldomain} not found!" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
_record_name=$(echo $_zone | sed "s/\.\..*//") |
|
|
|
_zone=$(echo $_zone | sed "s/.*\.\.//") |
|
|
|
_record_name=$(echo "${_zone}" | sed "s/\.\..*//") |
|
|
|
_zone=$(echo "${_zone}" | sed "s/.*\.\.//") |
|
|
|
|
|
|
|
|
|
|
|
_record_id=$(_record_get_id $_zone $_challenge) |
|
|
|
_record_id=$(_record_get_id "${_zone}" "${_challenge}") |
|
|
|
|
|
|
|
_record_remove $_zone $_record_id |
|
|
|
_record_remove "${_zone}" "${_record_id}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -83,30 +83,30 @@ _get_root(){ |
|
|
|
_zone=$_fulldomain |
|
|
|
|
|
|
|
export _H1="Content-Type: application-json" |
|
|
|
export _H2="Authorization: apikey $ARVAN_API_KEY" |
|
|
|
export _H2="Authorization: apikey ${ARVAN_API_KEY}" |
|
|
|
|
|
|
|
_response=$(_get $ARVAN_CDN_API/domains) |
|
|
|
_domains_list=( $( echo $_response | grep -Poe '"domain":"[^"]*"' | sed 's/"domain":"//' | sed 's/"//') ) |
|
|
|
_response=$(_get "${ARVAN_CDN_API}/domains") |
|
|
|
_domains_list=( $( echo "${_response}" | grep -Poe '"domain":"[^"]*"' | sed 's/"domain":"//' | sed 's/"//') ) |
|
|
|
|
|
|
|
_debug2 "_get_root(): $_response" |
|
|
|
_debug2 "_get_root(): $_domains_list" |
|
|
|
_debug2 "_get_root(): reponse ${_response}" |
|
|
|
_debug2 "_get_root(): domains list ${_domains_list}" |
|
|
|
|
|
|
|
#Fibding a matching Zone |
|
|
|
while [[ ! -z $_zone ]]; do |
|
|
|
for tmp in ${_domains_list[@]}; do |
|
|
|
if [ $tmp = $_zone ]; then |
|
|
|
while [[ ! -z "${_zone}" ]]; do |
|
|
|
for tmp in "${_domains_list[@]}"; do |
|
|
|
if [ "${tmp}" = "${_zone}" ]; then |
|
|
|
break 2 |
|
|
|
fi |
|
|
|
done |
|
|
|
_zone=$(echo $_zone | sed 's/^[^.]*\.\?//') |
|
|
|
_zone=$(echo "${_zone}" | sed 's/^[^.]*\.\?//') |
|
|
|
done |
|
|
|
if [ -z $_zone ]; then |
|
|
|
if [ -z "${_zone}" ]; then |
|
|
|
_debug2 "_get_root(): Zone not found on provider" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
_marked_zone=$(echo $_fulldomain | sed "s/^\(.*\)\.\(${_zone}\)$/\1..\2/") |
|
|
|
echo $_marked_zone |
|
|
|
_marked_zone=$(echo "${_fulldomain}" | sed "s/^\(.*\)\.\(${_zone}\)$/\1..\2/") |
|
|
|
echo "${_marked_zone}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -118,13 +118,13 @@ _record_add(){ |
|
|
|
_challenge=$3 |
|
|
|
|
|
|
|
export _H1="Content-Type: application-json" |
|
|
|
export _H2="Authorization: apikey $ARVAN_API_KEY" |
|
|
|
export _H2="Authorization: apikey ${ARVAN_API_KEY}" |
|
|
|
|
|
|
|
_payload="{\"type\":\"txt\",\"name\":\"$_record_name\",\"cloud\":false,\"value\":{\"text\":\"$_challenge\"},\"ttl\":120}" |
|
|
|
_response=$(_post "$_payload" "$ARVAN_CDN_API/domains/$_zone/dns-records" "" "POST" "application/json" | _base64) |
|
|
|
_payload="{\"type\":\"txt\",\"name\":\"${_record_name}\",\"cloud\":false,\"value\":{\"text\":\"${_challenge}\"},\"ttl\":120}" |
|
|
|
_response=$(_post "${_payload}" "${ARVAN_CDN_API}/domains/${_zone}/dns-records" "" "POST" "application/json" | _base64) |
|
|
|
|
|
|
|
_debug2 "_record_add(): " $_response |
|
|
|
_debug2 " Payload: " $_payload |
|
|
|
_debug2 "_record_add(): ${_response}" |
|
|
|
_debug2 " Payload: ${_payload}" |
|
|
|
} |
|
|
|
|
|
|
|
#Usage: _record_get_id zone challenge |
|
|
@ -134,13 +134,13 @@ _record_get_id(){ |
|
|
|
_challenge=$2 |
|
|
|
|
|
|
|
export _H1="Content-Type: application-json" |
|
|
|
export _H2="Authorization: apikey $ARVAN_API_KEY" |
|
|
|
export _H2="Authorization: apikey ${ARVAN_API_KEY}" |
|
|
|
|
|
|
|
_response=$(_get $ARVAN_CDN_API/domains/$_zone/dns-records/?type=txt\&search=$_challenge | _json_decode | _normalizeJson | grep -Eo '"id":.*?,"value":\{"text":".*?"\}' | sed 's/"id":"\([^"]*\)".*/\1/') |
|
|
|
_debug2 "_record_get_id(): " $_response |
|
|
|
_response=$(_get "${ARVAN_CDN_API}/domains/${_zone}/dns-records/?type=txt\&search=${_challenge}" | _json_decode | _normalizeJson | grep -Eo '"id":.*?,"value":\{"text":".*?"\}' | sed 's/"id":"\([^"]*\)".*/\1/') |
|
|
|
_debug2 "_record_get_id(): ${_response}" |
|
|
|
|
|
|
|
|
|
|
|
echo "$_response" |
|
|
|
echo "${_response}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -153,9 +153,9 @@ _record_remove(){ |
|
|
|
export _H1="Content-Type: application-json" |
|
|
|
export _H2="Authorization: apikey $ARVAN_API_KEY" |
|
|
|
|
|
|
|
_response=$(_post "" $ARVAN_CDN_API/domains/$_zone/dns-records/$_record_id "" "DELETE" "application/json") |
|
|
|
_response=$(_post "" "$ARVAN_CDN_API/domains/$_zone/dns-records/$_record_id" "" "DELETE" "application/json") |
|
|
|
|
|
|
|
_debug "_record_remove(): ACME Challenge Removed" |
|
|
|
_debug2 " Response: " $_response |
|
|
|
_debug2 " Response: $_response" |
|
|
|
|
|
|
|
} |