diff --git a/dnsapi/dns_geos .sh b/dnsapi/dns_geos .sh index 3f35d8a7..432e69e0 100644 --- a/dnsapi/dns_geos .sh +++ b/dnsapi/dns_geos .sh @@ -19,98 +19,98 @@ export _ACME_CURL="curl -k -s -c $COOKIE_FILE -b $COOKIE_FILE --dump-header $HTT # Usage: dns_geos_add _acme-challenge.subdomain.domain.com "XyZ123..." dns_geos_add() { - _full_domain=$1 - _txt_value=$2 - _info "Using DNS-01 GeoScaling hook" + _full_domain=$1 + _txt_value=$2 + _info "Using DNS-01 GeoScaling hook" - _login || return 1 - _get_zone "$_full_domain" || return 1 - _debug "zone id \"$_zone_id\" will be used." + _login || return 1 + _get_zone "$_full_domain" || return 1 + _debug "zone id \"$_zone_id\" will be used." - body="id=${_zone_id}&name=${_sub_domain}&type=TXT&content=${_txt_value}&ttl=300&prio=0" - response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/add_record.php") - _debug "add:$response" - if _contains "$response" '"code":"OK"'; then - _info "TXT record added successfully." - else - _err "Couldn't add the TXT record." - return 1 - fi - _debug2 response "$response" - return 0 + body="id=${_zone_id}&name=${_sub_domain}&type=TXT&content=${_txt_value}&ttl=300&prio=0" + response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/add_record.php") + _debug "add:$response" + if _contains "$response" '"code":"OK"'; then + _info "TXT record added successfully." + else + _err "Couldn't add the TXT record." + return 1 + fi + _debug2 response "$response" + return 0 } #-- dns_geos_rm() - Remove TXT record ------------------------------------ # Usage: dns_geos_rm _acme-challenge.subdomain.domain.com "XyZ123..." dns_geos_rm() { - _full_domain=$1 - _txt_value=$2 - _info "Cleaning up after DNS-01 GeoScaling hook" - _login || return 1 - _get_zone "$_full_domain" || return 1 - _debug "zone id \"$_zone_id\" will be used." + _full_domain=$1 + _txt_value=$2 + _info "Cleaning up after DNS-01 GeoScaling hook" + _login || return 1 + _get_zone "$_full_domain" || return 1 + _debug "zone id \"$_zone_id\" will be used." - # Find the record id to clean - record_id=$(_get_record_id "$_zone_id" "$_full_domain") || return 1; - body="id=${_zone_id}&record_id=${record_id}" - response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php") - _debug "rm:$response" - if _contains "$response" '"code":"OK"'; then - _info "Record removed successfully." - else - _err "Could not clean (remove) up the record. Please go to GEOS administration interface and clean it by hand." - return 1 - fi - return 0 + # Find the record id to clean + record_id=$(_get_record_id "$_zone_id" "$_full_domain") || return 1; + body="id=${_zone_id}&record_id=${record_id}" + response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php") + _debug "rm:$response" + if _contains "$response" '"code":"OK"'; then + _info "Record removed successfully." + else + _err "Could not clean (remove) up the record. Please go to GEOS administration interface and clean it by hand." + return 1 + fi + return 0 } ########################## PRIVATE FUNCTIONS ########################### #$1:string,$2:char,$ret:count _count() { - echo "$1" | awk -F"$2" '{print NF-1}' + echo "$1" | awk -F"$2" '{print NF-1}' } #$1:fullname,eg:_acme-challenge.us.domain.com #ret:return root domain,us.domain.com domain.com _get_domain() { - i=2 - c=$(_count "$1" ".") - while [ $i -le "$c" ]; do - h=$(echo "$1" | cut -d . -f $i-) - if [ -z "$h" ]; then - return 1 - fi - echo "$h" - i=$(_math "$i" + 1) - done - return 0 + i=2 + c=$(_count "$1" ".") + while [ $i -le "$c" ]; do + h=$(echo "$1" | cut -d . -f $i-) + if [ -z "$h" ]; then + return 1 + fi + echo "$h" + i=$(_math "$i" + 1) + done + return 0 } _login() { - GEOS_Username="${GEOS_Username:-$(_readaccountconf_mutable GEOS_Username)}" - GEOS_Password="${GEOS_Password:-$(_readaccountconf_mutable GEOS_Password)}" - if [ -z "$GEOS_Username" ] || [ -z "$GEOS_Password" ]; then - GEOS_Username= - GEOS_Password= - _err "No auth details provided. Please set user credentials using the \$GEOS_Username and \$GEOS_Password environment variables." - return 1 - fi - _saveaccountconf_mutable GEOS_Username "$GEOS_Username" - _saveaccountconf_mutable GEOS_Password "$GEOS_Password" - username_encoded=$(echo -n "${GEOS_Username}" | _url_encode) - password_encoded=$(echo -n "${GEOS_Password}" | _url_encode) - body="username=${username_encoded}&password=${password_encoded}" - if ! _post "$body" "https://www.geoscaling.com/dns2/index.php?module=auth"; then - _err "geoscaling login failed for user $GEOS_Username bad RC from _post" - return 1 - fi - resp_header=$(grep 'HTTP/2 302' "$HTTP_HEADER") - if [ -z "$resp_header" ]; then - _err "geoscaling login failed for user $GEOS_Username. Check $HTTP_HEADER file" - return 1 - fi - return 0 + GEOS_Username="${GEOS_Username:-$(_readaccountconf_mutable GEOS_Username)}" + GEOS_Password="${GEOS_Password:-$(_readaccountconf_mutable GEOS_Password)}" + if [ -z "$GEOS_Username" ] || [ -z "$GEOS_Password" ]; then + GEOS_Username= + GEOS_Password= + _err "No auth details provided. Please set user credentials using the \$GEOS_Username and \$GEOS_Password environment variables." + return 1 + fi + _saveaccountconf_mutable GEOS_Username "$GEOS_Username" + _saveaccountconf_mutable GEOS_Password "$GEOS_Password" + username_encoded=$(echo -n "${GEOS_Username}" | _url_encode) + password_encoded=$(echo -n "${GEOS_Password}" | _url_encode) + body="username=${username_encoded}&password=${password_encoded}" + if ! _post "$body" "https://www.geoscaling.com/dns2/index.php?module=auth"; then + _err "geoscaling login failed for user $GEOS_Username bad RC from _post" + return 1 + fi + resp_header=$(grep 'HTTP/2 302' "$HTTP_HEADER") + if [ -z "$resp_header" ]; then + _err "geoscaling login failed for user $GEOS_Username. Check $HTTP_HEADER file" + return 1 + fi + return 0 } #$1:full domain name,_acme-challenge.www.domain.com @@ -118,30 +118,30 @@ _login() { # _sub_domain=_acme-challenge.www # _zone_id=xxxxxx _get_zone(){ - response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domains") - table=$(echo "$response" | tr -d "\n" | grep -oP "(?<=