Skip to content

Instantly share code, notes, and snippets.

@magicdude4eva
Created July 5, 2017 15:55
Show Gist options
  • Save magicdude4eva/d3af60bae0707612923b1e4ab83e10c4 to your computer and use it in GitHub Desktop.
Save magicdude4eva/d3af60bae0707612923b1e4ab83e10c4 to your computer and use it in GitHub Desktop.
dyn_dns_acme.sh
#!/usr/bin/bash
#DynDNS.com Domain API
CUSTOMERNAME='PLEASE-SET'
USERNAME='PLEASE-SET'
PASSWORD='PLEASE-SET'
DYNAPIURL="https://api.dynect.net/"
ZONE="PLEASE-SET"
fulldomain=""
sessionstatus=""
authtoken=""
record_id=""
#REST_API
######## Public functions #####################
#Usage: dns_myapi_add _acme-challenge.www.domain.com "Challenge-code"
dns_dynect_add() {
fulldomain=$1
txtvalue=$2
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"
_info "Using dynect"
if ! get_token; then
return 1
fi
if [ ! -z "$authtoken" ]; then
if ! add_record "$fulldomain" "$textvalue"; then
return 1
fi
if ! publish_zone; then
return 1
fi
else
return 1
fi
return 0
}
#Usage: fulldomain txtvalue
#Remove the txt record after validation.
dns_dynect_rm() {
authtoken=""
sessionstatus=""
record_id=""
fulldomain=$1
_debug fulldomain "$fulldomain"
_info "Using dynect"
if ! get_token; then
return 1
fi
if [ ! -z "$authtoken" ]; then
if ! get_record_id; then
return 1
fi
if ! rm_record "$fulldomain"; then
return 1
fi
if ! publish_zone; then
return 1
fi
else
return 1
fi
return 0
}
#################### Private functions below ##################################
#get Auth-Token
get_token() {
_info "Getting token"
data="{\"customer_name\":\"$CUSTOMERNAME\", \"user_name\":\"$USERNAME\", \"password\":\"$PASSWORD\"}"
url="$DYNAPIURL""REST/Session/"
method="POST"
_debug data "$data"
_debug url "$url"
export _H1="Content-Type: application/json"
response="$(_post "$data" "$url" "" "$method")"
#response=$(curl --ipv4 -X POST -H "Content-Type: application/json" $url -d $data)
_debug response "$response"
sessionstatus=$(echo $response | grep -Po "(?<=\"status\": \")[^\"]*")
_debug sessionstatus "$sessionstatus"
if [ "$sessionstatus" = "success" ]; then
authtoken=$(echo $response | grep -Po "(?<=\"token\": \")[^\"]*")
_info "Token received"
_debug authtoken "$authtoken"
return 0
fi
_err "get token failed"
return 1
}
#add TXT record
add_record() {
_info "Adding TXT record"
data="{\"rdata\":{\"txtdata\":\"$txtvalue\"},\"ttl\":\"300\"}"
url="$DYNAPIURL""REST/TXTRecord/""$ZONE/""$fulldomain"
method="POST"
export _H1="Content-Type: application/json"
export _H2="Auth-Token: "$authtoken
response="$(_post "$data" "$url" "" "$method")"
sessionstatus=$(echo $response | grep -Po "(?<=\"status\": \")[^\"]*")
_debug response $response
_debug response $sessionstatus
if [ "$sessionstatus" = "success" ]; then
_info "TXT Record successfully added"
return 0
fi
_err "add TXT record failed"
return 1
}
#publish the zone
publish_zone() {
_info "Publishing zone"
data="{\"publish\":\"true\"}"
url="$DYNAPIURL""REST/Zone/""$ZONE/"
method="PUT"
export _H1="Content-Type: application/json"
export _H2="Auth-Token: "$authtoken
response="$(_post "$data" "$url" "" "$method")"
sessionstatus=$(echo $response | grep -Po "(?<=\"status\": \")[^\"]*")
if [ "$sessionstatus" = "success" ]; then
_info "Zone published"
return 0
fi
_err "publish zone failed"
return 1
}
#get record_id of TXT record so we can delete the record
get_record_id() {
_info "Getting record_id of TXT record"
url="$DYNAPIURL""REST/TXTRecord/""$ZONE/""$fulldomain"
export _H1="Content-Type: application/json"
export _H2="Auth-Token: $authtoken"
response="$(_get "$url" "" "")"
_debug response "$response"
sessionstatus=$(echo $response | grep -Po "(?<=\"status\": \")[^\"]*")
_debug sessionstatus "$sessionstatus"
if [ "$sessionstatus" = "success" ]; then
record_id=$(echo $response | grep -Po "(?<=\"data\": \[\"/REST/TXTRecord/$ZONE/$fulldomain/)[^\"]*")
_debug record_id "$record_id"
return 0
fi
_err "getting record_id failed"
return 1
}
#delete TXT record
rm_record() {
_info "Deleting TXT record"
url="$DYNAPIURL""REST/TXTRecord/""$ZONE/""$fulldomain/""$record_id/"
method="DELETE"
_debug url "$url"
export _H1="Content-Type: application/json"
export _H2="Auth-Token: $authtoken"
response="$(_post "" "$url" "" "$method")"
_debug response "$response"
sessionstatus=$(echo $response | grep -Po "(?<=\"status\": \")[^\"]*")
_debug sessionstatus "$sessionstatus"
if [ "$sessionstatus" = "success" ]; then
_info "TXT record successfully deleted"
return 0
fi
_err "delete TXT record failed"
return 1
}
@magicdude4eva
Copy link
Author

magicdude4eva commented Jan 1, 2018

Donations are always welcome

🍺 Please support me: If the above helped you in any way, then follow me on Twitter or send me some coins:

(CRO)    cro1w2kvwrzp23aq54n3amwav4yy4a9ahq2kz2wtmj (Memo: 644996249) or 0xb83c3Fe378F5224fAdD7a0f8a7dD33a6C96C422C (Cronos)
(USDC)   0xb83c3Fe378F5224fAdD7a0f8a7dD33a6C96C422C
(BTC)    3628nqihXvw2RXsKtTR36dN6WvYzaHyr52
(ETH)    0xb83c3Fe378F5224fAdD7a0f8a7dD33a6C96C422C
(BAT)    0xb83c3Fe378F5224fAdD7a0f8a7dD33a6C96C422C
(LTC)    MQxRAfhVU84KDVUqnZ5eV9MGyyaBEcQeDf
(Ripple) rKV8HEL3vLc6q9waTiJcewdRdSFyx67QFb (Tag: 1172047832)
(XLM)    GB67TJFJO3GUA432EJ4JTODHFYSBTM44P4XQCDOFTXJNNPV2UKUJYVBF (Memo ID: 1406379394)

Go to Curve.com to add your Crypto.com card to ApplePay and signup to Crypto.com for a staking and free Crypto debit card.

Use Binance Exchange to trade #altcoins. Sign up with Coinbase and instantly get $10 in BTC. I also accept old-school PayPal.

If you have no crypto, follow me at least on Twitter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment