Update dns_hover.sh

Fixing format
This commit is contained in:
ddarek2000 2020-08-31 14:15:23 -04:00 committed by GitHub
parent f28540731e
commit 3f95564c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,19 +18,19 @@ HOVER_Api="https://www.hover.com/api"
#Usage: dns_hover_add _acme-challenge.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" #Usage: dns_hover_add _acme-challenge.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_hover_add() { dns_hover_add() {
fulldomain=$1 fulldomain="$1"
txtvalue=$2 txtvalue="$2"
_info "Using HOVER" _info "Using HOVER"
_debug fulldomain "$fulldomain" _debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue" _debug txtvalue "$txtvalue"
########### Login first ########### ########### Login first ###########
if ! _HOVER_login; then if ! _HOVER_login; then
_err "Cannot Login" _err "Cannot Login"
return 1 return 1
fi fi
########### Now detect current config ########### ########### Now detect current config ###########
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root "$fulldomain"; then if ! _get_root "$fulldomain"; then
@ -41,7 +41,7 @@ dns_hover_add() {
_debug _domain_id "$_domain_id" _debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain" _debug _sub_domain "$_sub_domain"
_debug _domain "$_domain" _debug _domain "$_domain"
_debug "Getting txt records" _debug "Getting txt records"
_cf_rest GET "domains/$_domain_id/dns" _cf_rest GET "domains/$_domain_id/dns"
@ -49,9 +49,9 @@ dns_hover_add() {
_err "Error" _err "Error"
return 1 return 1
fi fi
########### ADD or UPDATE ########### ########### ADD or UPDATE ###########
count=$(printf "%s\n" "$response" | _egrep_o ",\"name\":\"$_sub_domain\",\"type\":\"TXT\"[^,]*" | cut -d : -f 2| wc -l ) count=$(printf "%s\n" "$response" | _egrep_o ",\"name\":\"$_sub_domain\",\"type\":\"TXT\"[^,]*" | cut -d : -f 2 | wc -l)
_debug count "$count" _debug count "$count"
if [ "$count" -eq "0" ]; then if [ "$count" -eq "0" ]; then
_info "Adding record" _info "Adding record"
@ -69,19 +69,6 @@ dns_hover_add() {
_err "Add txt record error." _err "Add txt record error."
fi fi
# else
# _info "Updating record"
# record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\",\"name\":\"$_sub_domain\",\"type\":\"TXT\"" | tr -d \" | tr "," ":" | cut -d : -f 2 | head -n 1)
# _debug "record_id" "$record_id"
#
# _cf_rest PUT "domains/$_domain_id/dns/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
# if [ "$?" = "0" ]; then
# _info "Updated, OK"
# return 0
# fi
# _err "Update error"
# return 1
# verify response # verify response
if ! _contains "$response" "\"succeeded\":true"; then if ! _contains "$response" "\"succeeded\":true"; then
_err "Error" _err "Error"
@ -94,19 +81,19 @@ dns_hover_add() {
#Usage: fulldomain txtvalue #Usage: fulldomain txtvalue
#Remove the txt record after validation. #Remove the txt record after validation.
dns_hover_rm() { dns_hover_rm() {
fulldomain=$1 fulldomain="$1"
txtvalue=$2 txtvalue="$2"
_info "Using hover" _info "Using hover"
_debug fulldomain "$fulldomain" _debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue" _debug txtvalue "$txtvalue"
########### Login first ########### ########### Login first ###########
if ! _HOVER_login; then if ! _HOVER_login; then
_err "Cannot Login" _err "Cannot Login"
return 1 return 1
fi fi
########### Now detect current config ########### ########### Now detect current config ###########
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root "$fulldomain"; then if ! _get_root "$fulldomain"; then
@ -116,7 +103,7 @@ dns_hover_rm() {
_debug _domain_id "$_domain_id" _debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain" _debug _sub_domain "$_sub_domain"
_debug _domain "$_domain" _debug _domain "$_domain"
_debug "Getting txt records" _debug "Getting txt records"
_cf_rest GET "domains/$_domain_id/dns" _cf_rest GET "domains/$_domain_id/dns"
@ -126,10 +113,10 @@ dns_hover_rm() {
return 1 return 1
fi fi
########### DELETE ########### ########### DELETE ###########
count=$(printf "%s\n" "$response" | _egrep_o ",\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\"" | cut -d : -f 2| wc -l ) count=$(printf "%s\n" "$response" | _egrep_o ",\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\"" | cut -d : -f 2| wc -l )
_debug count "$count" _debug count "$count"
if [ "$count" -eq "0" ]; then if [ "$count" -eq "0" ]; then
_info "Don't need to remove." _info "Don't need to remove."
else else
@ -159,7 +146,7 @@ dns_hover_rm() {
#################### Private functions below ################################## #################### Private functions below ##################################
################################################################################ ################################################################################
# usage: _HOVER_login # usage: _HOVER_login
# returns 0 success # returns 0 success
_HOVER_login() { _HOVER_login() {
@ -168,7 +155,7 @@ _HOVER_login() {
# _saveaccountconf_mutable HOVER_Password "$HOVER_Password" # _saveaccountconf_mutable HOVER_Password "$HOVER_Password"
if [ -z "$HOVER_COOKIE" ]; then if [ -z "$HOVER_COOKIE" ]; then
HOVER_Username="${HOVER_Username:-$(_readaccountconf_mutable HOVER_Username)}" HOVER_Username="${HOVER_Username:-$(_readaccountconf_mutable HOVER_Username)}"
HOVER_Password="${HOVER_Password:-$(_readaccountconf_mutable HOVER_Password)}" HOVER_Password="${HOVER_Password:-$(_readaccountconf_mutable HOVER_Password)}"
@ -258,7 +245,7 @@ _cf_rest() {
if [ "$ep" != "login" ]; then if [ "$ep" != "login" ]; then
export _H1="Cookie:$HOVER_COOKIE" export _H1="Cookie:$HOVER_COOKIE"
export _H3="Content-Type: application/json" export _H3="Content-Type: application/json"
fi fi
export _H2="Accept-Language:en-US" export _H2="Accept-Language:en-US"