|
@@ -0,0 +1,205 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+dns_dgon_add() {
|
|
|
+ fulldomain="$(echo "$1" | _lower_case)"
|
|
|
+ txtvalue=$2
|
|
|
+ _info "Using digitalocean dns validation - add record"
|
|
|
+ _debug fulldomain "$fulldomain"
|
|
|
+ _debug txtvalue "$txtvalue"
|
|
|
+
|
|
|
+
|
|
|
+ _saveaccountconf DO_API_KEY "$DO_API_KEY"
|
|
|
+
|
|
|
+
|
|
|
+ if ! _get_base_domain "$fulldomain"; then
|
|
|
+ _err "domain not found in your account for addition"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug _sub_domain "$_sub_domain"
|
|
|
+ _debug _domain "$_domain"
|
|
|
+
|
|
|
+
|
|
|
+ export _H1="Content-Type: application/json"
|
|
|
+ export _H2="Authorization: Bearer $DO_API_KEY"
|
|
|
+ PURL='https://api.digitalocean.com/v2/domains/'$_domain'/records'
|
|
|
+ PBODY='{"type":"TXT","name":"'$_sub_domain'","data":"'$txtvalue'"}'
|
|
|
+
|
|
|
+ _debug PURL "$PURL"
|
|
|
+ _debug PBODY "$PBODY"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ response="$(_post "$PBODY" "$PURL")"
|
|
|
+
|
|
|
+
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
+ _err "error in response: $response"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug2 response "$response"
|
|
|
+
|
|
|
+
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+dns_dgon_rm() {
|
|
|
+ fulldomain="$(echo "$1" | _lower_case)"
|
|
|
+ txtvalue=$2
|
|
|
+ _info "Using digitalocean dns validation - remove record"
|
|
|
+ _debug fulldomain "$fulldomain"
|
|
|
+ _debug txtvalue "$txtvalue"
|
|
|
+
|
|
|
+
|
|
|
+ if ! _get_base_domain "$fulldomain"; then
|
|
|
+ _err "domain not found in your account for removal"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug _sub_domain "$_sub_domain"
|
|
|
+ _debug _domain "$_domain"
|
|
|
+
|
|
|
+
|
|
|
+ export _H1="Content-Type: application/json"
|
|
|
+ export _H2="Authorization: Bearer $DO_API_KEY"
|
|
|
+
|
|
|
+
|
|
|
+ GURL="https://api.digitalocean.com/v2/domains/$_domain/records"
|
|
|
+
|
|
|
+
|
|
|
+ while [ -z "$record" ]; do
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ domain_list="$(_get "$GURL")"
|
|
|
+
|
|
|
+
|
|
|
+ record="$(echo "$domain_list" | _egrep_o "\"id\"\s*\:\s*\"*\d+\"*[^}]*\"name\"\s*\:\s*\"$_sub_domain\"[^}]*\"data\"\s*\:\s*\"$txtvalue\"")"
|
|
|
+
|
|
|
+ if [ -z "$record" ]; then
|
|
|
+
|
|
|
+ nextpage="$(echo "$domain_list" | _egrep_o "\"links\".*" | _egrep_o "\"next\".*" | _egrep_o "http.*page\=\d+")"
|
|
|
+ if [ -z "$nextpage" ]; then
|
|
|
+ _err "no record and no nextpage in digital ocean DNS removal"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug2 nextpage "$nextpage"
|
|
|
+ GURL="$nextpage"
|
|
|
+ fi
|
|
|
+
|
|
|
+ done
|
|
|
+
|
|
|
+
|
|
|
+ rec_id="$(echo "$record" | _egrep_o "id\"\s*\:\s*\"*\d+" | _egrep_o "\d+")"
|
|
|
+ _debug rec_id "$rec_id"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DURL="https://api.digitalocean.com/v2/domains/$_domain/records/$rec_id"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ response="$(_post "" "$DURL" "" "DELETE")"
|
|
|
+
|
|
|
+
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
+ _err "error in remove response: $response"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug2 response "$response"
|
|
|
+
|
|
|
+
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+_get_base_domain() {
|
|
|
+
|
|
|
+ fulldomain="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
|
|
|
+ _debug fulldomain "$fulldomain"
|
|
|
+
|
|
|
+
|
|
|
+ MAX_DOM=255
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ export _H1="Content-Type: application/json"
|
|
|
+ export _H2="Authorization: Bearer $DO_API_KEY"
|
|
|
+ _debug DO_API_KEY "$DO_API_KEY"
|
|
|
+
|
|
|
+
|
|
|
+ DOMURL="https://api.digitalocean.com/v2/domains"
|
|
|
+
|
|
|
+
|
|
|
+ domain_list="$(_get "$DOMURL")"
|
|
|
+
|
|
|
+
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
+ _err "error in domain_list response: $domain_list"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ _debug2 domain_list "$domain_list"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ i=2
|
|
|
+ while [ $i -gt 0 ]; do
|
|
|
+
|
|
|
+ _domain=$(printf "%s" "$fulldomain" | cut -d . -f "$i"-"$MAX_DOM")
|
|
|
+
|
|
|
+ if [ -z "$_domain" ]; then
|
|
|
+
|
|
|
+ _err "domain not found in DigitalOcean account"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ found="$(echo "$domain_list" | _egrep_o "\"name\"\s*\:\s*\"$_domain\"")"
|
|
|
+
|
|
|
+ if [ ! -z "$found" ]; then
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ i=$(_math $i + 1)
|
|
|
+ done
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ _err "domain not found in DigitalOcean account, but we should never get here"
|
|
|
+ return 1
|
|
|
+}
|