From a258c8a946e1bd7d976b37d9460001e01016cbf9 Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:16:23 -0300 Subject: [PATCH 1/6] Create dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 dnsapi/dns_googledomains.sh diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh new file mode 100644 index 00000000..9437673c --- /dev/null +++ b/dnsapi/dns_googledomains.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env sh +GOOGLEDOMAINS_API="https://acmedns.googleapis.com/v1/acmeChallengeSets" +dns_googledomains_add() { + fulldomain=$1 + txtvalue=$2 + _info "Using Google Domains api" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + + GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" + + if [ -z "$GOOGLEDOMAINS_TOKEN" ]; then + GOOGLEDOMAINS_TOKEN="" + _err "You did not specify GOOGLEDOMAINS_TOKEN yet." + _err "Please create your key and try again." + _err "e.g." + _err "export GOOGLEDOMAINS_TOKEN=d41d8cd98f00b204e9800998ecf8427e" + return 1 + fi + #save the api token to the account conf file. + _saveaccountconf_mutable GOOGLEDOMAINS_TOKEN "$GOOGLEDOMAINS_TOKEN" + + _debug "First detect the root zone" + i=0 + while [ $i -le $(echo "$fulldomain" | grep -o '\.' | wc -l) ]; do + # join the domain parts from the current index to the end + current_domain=$(echo "$fulldomain" | cut -d "." -f $(($i+1))-) + + # make a curl request to the URL and break the loop if the HTTP response code is 200 + response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" + + if _contains "$response" "INVALID_ARGUMENT"; then + _info "Invalid domain: $current_domain" + else + _info "Found valid domain: $current_domain" + break + fi + i=$((i+1)) + done + export _H1="Content-Type: application/json" + _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToAdd\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" +} + +#fulldomain txtvalue +dns_googledomains_rm() { + fulldomain=$1 + txtvalue=$2 + + GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" + _info "Using Google Domains api" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + i=0 + while [ $i -le $(echo "$fulldomain" | grep -o '\.' | wc -l) ]; do + # join the domain parts from the current index to the end + current_domain=$(echo "$fulldomain" | cut -d "." -f $(($i+1))-) + echo $current_domain + + # make a curl request to the URL and break the loop if the HTTP response code is 200 + response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" + echo $response + if _contains "$response" "INVALID_ARGUMENT"; then + echo "Invalid domain: $current_domain" + else + echo "Found valid domain: $current_domain" + break + fi + i=$((i+1)) + done + export _H1="Content-Type: application/json" + _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToRemove\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" +} \ No newline at end of file From cbf5a84acabc6d54fb00bc5ce9e12d7feb38d271 Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:20:03 -0300 Subject: [PATCH 2/6] Update dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh index 9437673c..56727484 100644 --- a/dnsapi/dns_googledomains.sh +++ b/dnsapi/dns_googledomains.sh @@ -22,9 +22,9 @@ dns_googledomains_add() { _debug "First detect the root zone" i=0 - while [ $i -le $(echo "$fulldomain" | grep -o '\.' | wc -l) ]; do + while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $(($i+1))-) + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i+1))-) # make a curl request to the URL and break the loop if the HTTP response code is 200 response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" @@ -40,8 +40,6 @@ dns_googledomains_add() { export _H1="Content-Type: application/json" _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToAdd\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" } - -#fulldomain txtvalue dns_googledomains_rm() { fulldomain=$1 txtvalue=$2 @@ -51,14 +49,12 @@ dns_googledomains_rm() { _debug fulldomain "$fulldomain" _debug txtvalue "$txtvalue" i=0 - while [ $i -le $(echo "$fulldomain" | grep -o '\.' | wc -l) ]; do + while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $(($i+1))-) - echo $current_domain + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i+1))-) # make a curl request to the URL and break the loop if the HTTP response code is 200 response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" - echo $response if _contains "$response" "INVALID_ARGUMENT"; then echo "Invalid domain: $current_domain" else @@ -67,6 +63,4 @@ dns_googledomains_rm() { fi i=$((i+1)) done - export _H1="Content-Type: application/json" - _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToRemove\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" } \ No newline at end of file From 64b6f3df7ae7e2503ea5f7df0420ca501c94615b Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:24:23 -0300 Subject: [PATCH 3/6] Update dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh index 56727484..e3d01ce9 100644 --- a/dnsapi/dns_googledomains.sh +++ b/dnsapi/dns_googledomains.sh @@ -63,4 +63,4 @@ dns_googledomains_rm() { fi i=$((i+1)) done -} \ No newline at end of file +} From b30227d54429a9b62286c86bac882aa5d2ba4f47 Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:29:10 -0300 Subject: [PATCH 4/6] Update dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh index e3d01ce9..8329e84b 100644 --- a/dnsapi/dns_googledomains.sh +++ b/dnsapi/dns_googledomains.sh @@ -24,18 +24,18 @@ dns_googledomains_add() { i=0 while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $((i+1))-) - + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) + # make a curl request to the URL and break the loop if the HTTP response code is 200 response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" - + if _contains "$response" "INVALID_ARGUMENT"; then _info "Invalid domain: $current_domain" else _info "Found valid domain: $current_domain" break fi - i=$((i+1)) + i=$((i + 1)) done export _H1="Content-Type: application/json" _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToAdd\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" @@ -51,8 +51,8 @@ dns_googledomains_rm() { i=0 while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $((i+1))-) - + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) + # make a curl request to the URL and break the loop if the HTTP response code is 200 response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" if _contains "$response" "INVALID_ARGUMENT"; then @@ -61,6 +61,6 @@ dns_googledomains_rm() { echo "Found valid domain: $current_domain" break fi - i=$((i+1)) + i=$((i + 1)) done } From 6e5374e8f914e3fefb87a5b405959ac95f982000 Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:30:46 -0300 Subject: [PATCH 5/6] Update dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 106 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh index 8329e84b..5ab76102 100644 --- a/dnsapi/dns_googledomains.sh +++ b/dnsapi/dns_googledomains.sh @@ -1,66 +1,66 @@ #!/usr/bin/env sh GOOGLEDOMAINS_API="https://acmedns.googleapis.com/v1/acmeChallengeSets" dns_googledomains_add() { - fulldomain=$1 - txtvalue=$2 - _info "Using Google Domains api" - _debug fulldomain "$fulldomain" - _debug txtvalue "$txtvalue" + fulldomain=$1 + txtvalue=$2 + _info "Using Google Domains api" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" - GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" + GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" - if [ -z "$GOOGLEDOMAINS_TOKEN" ]; then - GOOGLEDOMAINS_TOKEN="" - _err "You did not specify GOOGLEDOMAINS_TOKEN yet." - _err "Please create your key and try again." - _err "e.g." - _err "export GOOGLEDOMAINS_TOKEN=d41d8cd98f00b204e9800998ecf8427e" - return 1 - fi - #save the api token to the account conf file. - _saveaccountconf_mutable GOOGLEDOMAINS_TOKEN "$GOOGLEDOMAINS_TOKEN" + if [ -z "$GOOGLEDOMAINS_TOKEN" ]; then + GOOGLEDOMAINS_TOKEN="" + _err "You did not specify GOOGLEDOMAINS_TOKEN yet." + _err "Please create your key and try again." + _err "e.g." + _err "export GOOGLEDOMAINS_TOKEN=d41d8cd98f00b204e9800998ecf8427e" + return 1 + fi + #save the api token to the account conf file. + _saveaccountconf_mutable GOOGLEDOMAINS_TOKEN "$GOOGLEDOMAINS_TOKEN" - _debug "First detect the root zone" - i=0 - while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do - # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) + _debug "First detect the root zone" + i=0 + while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do + # join the domain parts from the current index to the end + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) - # make a curl request to the URL and break the loop if the HTTP response code is 200 - response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" + # make a curl request to the URL and break the loop if the HTTP response code is 200 + response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" - if _contains "$response" "INVALID_ARGUMENT"; then - _info "Invalid domain: $current_domain" - else - _info "Found valid domain: $current_domain" - break - fi - i=$((i + 1)) - done - export _H1="Content-Type: application/json" - _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToAdd\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" + if _contains "$response" "INVALID_ARGUMENT"; then + _info "Invalid domain: $current_domain" + else + _info "Found valid domain: $current_domain" + break + fi + i=$((i + 1)) + done + export _H1="Content-Type: application/json" + _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToAdd\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" } dns_googledomains_rm() { - fulldomain=$1 - txtvalue=$2 + fulldomain=$1 + txtvalue=$2 - GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" - _info "Using Google Domains api" - _debug fulldomain "$fulldomain" - _debug txtvalue "$txtvalue" - i=0 - while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do - # join the domain parts from the current index to the end - current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) + GOOGLEDOMAINS_TOKEN="${GOOGLEDOMAINS_TOKEN:-$(_readaccountconf_mutable GOOGLEDOMAINS_TOKEN)}" + _info "Using Google Domains api" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + i=0 + while [ $i -le "$(echo "$fulldomain" | grep -o '\.' | wc -l)" ]; do + # join the domain parts from the current index to the end + current_domain=$(echo "$fulldomain" | cut -d "." -f $((i + 1))-) - # make a curl request to the URL and break the loop if the HTTP response code is 200 - response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" - if _contains "$response" "INVALID_ARGUMENT"; then - echo "Invalid domain: $current_domain" - else - echo "Found valid domain: $current_domain" - break - fi - i=$((i + 1)) - done + # make a curl request to the URL and break the loop if the HTTP response code is 200 + response="$(_get "$GOOGLEDOMAINS_API/$current_domain")" + if _contains "$response" "INVALID_ARGUMENT"; then + echo "Invalid domain: $current_domain" + else + echo "Found valid domain: $current_domain" + break + fi + i=$((i + 1)) + done } From 334500ce7ed63ff7392cfeb5c59da89cff2dc0d6 Mon Sep 17 00:00:00 2001 From: Marcio Cruz <40072316+CruzMarcio@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:44:55 -0300 Subject: [PATCH 6/6] Update dns_googledomains.sh --- dnsapi/dns_googledomains.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dnsapi/dns_googledomains.sh b/dnsapi/dns_googledomains.sh index 5ab76102..538f022a 100644 --- a/dnsapi/dns_googledomains.sh +++ b/dnsapi/dns_googledomains.sh @@ -63,4 +63,6 @@ dns_googledomains_rm() { fi i=$((i + 1)) done + export _H1="Content-Type: application/json" + _post "{\"accessToken\":\"$GOOGLEDOMAINS_TOKEN\",\"keepExpiredRecords\":true,\"recordsToRemove\":[{\"digest\":\"$txtvalue\",\"fqdn\":\"$fulldomain\"}]}" "$GOOGLEDOMAINS_API/$current_domain:rotateChallenges" "" "" }