diff --git a/dns_scripts/dns_add_cloudflare b/dns_scripts/dns_add_cloudflare index 7bc3ea9..ef3d6fc 100755 --- a/dns_scripts/dns_add_cloudflare +++ b/dns_scripts/dns_add_cloudflare @@ -10,17 +10,15 @@ PARAMS=( -H "X-Auth-Email: $email" -H "X-Auth-Key: $key" -H 'Content-Type: appli # get a list of all domain names from cloudflare # If you have a lot, you may need add "&page=1&per_page=1000" and/or "&status=active" -resp=$(curl --silent "${PARAMS[@]}" -X GET "$API?match=all") - -re='"result":\[(([^][]*\[[^][]*])+[^][]*)]' # find result section +resp=$(curl --silent "${PARAMS[@]}" -X GET "$API") +re='"result":\[(([^][]*\[[^][]*])*[^][]*)]' # find result section [[ "${resp// }" =~ $re ]] && resp="${BASH_REMATCH[1]}" while [[ "$resp" ]]; do # iterate through domains returned - re='[^}{]*\{(([^}{]*\{[^}{]*})+[^}{]*)}(.*)' + re='[^}{]*\{(([^}{]*\{[^}{]*})*[^}{]*)}(.*)' [[ "$resp" =~ $re ]]; first="${BASH_REMATCH[1]}"; resp="${BASH_REMATCH[3]}" # remove subsections - leave only domain level while [[ "$first" =~ (.*)[\[\{][^]\{\}[]*[\]\}](.*) ]]; do first="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"; done - re='"name":"([^"]*)"'; [[ "$first" =~ $re ]] && domains=( "${domains[@]}" "${BASH_REMATCH[1]}" ) re='"id":"([^"]*)"'; [[ "$first" =~ $re ]] && ids=( "${ids[@]}" "${BASH_REMATCH[1]}" ) done diff --git a/dns_scripts/dns_del_cloudflare b/dns_scripts/dns_del_cloudflare index 9c0716f..aaa53fb 100755 --- a/dns_scripts/dns_del_cloudflare +++ b/dns_scripts/dns_del_cloudflare @@ -1,53 +1,50 @@ #!/usr/bin/env bash - -# need to add your email address and key to cloudflare below -email="" -key="" - -fulldomain="$1" - -# get a list of all domain names from cloudflare. If you have a lot, you may need -# "status=active&page=1&per_page=1000&match=all" instead of just "match=all" -all_domains=$(curl --silent -X GET "https://api.cloudflare.com/client/v4/zones?match=all" \ - -H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json" \ - | grep -o "\"name\":\"[^\"]*\"" | awk -F'"' '{print $4}') - -NumParts=$(echo "$fulldomain" | awk -F"." '{print NF}') - -i=1 -while [ $i -lt "$NumParts" ]; do - let parts=NumParts-i - testpart=$(echo "$fulldomain" |awk -v n=$parts -F\. '{for (i=n; i