Browse Source

adding example dns challenge scripts

pull/52/head
srvrco 10 years ago
parent
commit
50bb94f593
4 changed files with 92 additions and 0 deletions
  1. +26
    -0
      dns_scripts/dns_add_cloudflare
  2. +16
    -0
      dns_scripts/dns_add_nsupdate
  3. +35
    -0
      dns_scripts/dns_del_cloudflare
  4. +15
    -0
      dns_scripts/dns_del_nsupdate

+ 26
- 0
dns_scripts/dns_add_cloudflare View File

@ -0,0 +1,26 @@
#!/bin/bash
# need to add your email address and key to cloudflare below
email=""
key=""
fulldomain="$1"
token="$2"
NumParts=$(echo "$fulldomain" | awk -F"." '{print NF}')
if [[ $NumParts -gt 2 ]]; then
domain=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
txtname="_acme-challenge$(echo $fulldomain | awk -F\. '{for (i=1; i<NF-1; i++) printf "." $i}')"
else
domain=$fulldomain
txtname="_acme-challenge"
fi
response=$(curl --silent -X GET "https://api.cloudflare.com/client/v4/zones?name=${domain}&match=all" \
-H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json")
domain_id=$(echo "$response" | egrep -o "{[^{]*\"name\":\"${domain}\"[^}]*"|grep -oP '\"id\":"\K[^"]+')
response=$(curl --silent -X POST "https://api.cloudflare.com/client/v4/zones/${domain_id}/dns_records" \
-H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json" \
--data "{\"type\":\"TXT\",\"name\":\"${txtname}\",\"content\":\"$token\",\"ttl\":300}")

+ 16
- 0
dns_scripts/dns_add_nsupdate View File

@ -0,0 +1,16 @@
#!/bin/bash
# example of script to add token to local dns using nsupdate
dnskeyfile="path/to/bla.key"
fulldomain="$1"
token="$2"
updatefile=$(mktemp)
printf "update add _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${fulldomain}" "${token}" > "${updatefile}"
nsupdate -k "${dnskeyfile}" -v "${updatefile}"
rm -f ${updatefile}

+ 35
- 0
dns_scripts/dns_del_cloudflare View File

@ -0,0 +1,35 @@
#!/bin/bash
# need to add your email address and key to cloudflare below
email=""
key=""
fulldomain="$1"
NumParts=$(echo "$fulldomain" | awk -F"." '{print NF}')
if [[ $NumParts -gt 2 ]]; then
domain=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
txtname="_acme-challenge$(echo $fulldomain | awk -F\. '{for (i=1; i<NF-1; i++) printf "." $i}')"
else
domain=$fulldomain
txtname="_acme-challenge"
fi
response=$(curl --silent -X GET "https://api.cloudflare.com/client/v4/zones?name=${domain}&match=all" \
-H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json")
domain_id=$(echo "$response" | egrep -o "{[^{]*\"name\":\"${domain}\"[^}]*"|grep -oP '\"id\":"\K[^"]+')
response=$(curl --silent -X GET "https://api.cloudflare.com/client/v4/zones/${domain_id}/dns_records?type=TXT&name=${txtname}.${domain}" \
-H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json")
zone_ids=$(echo "$response" |grep -oP '\"id\":"\K[^"]+')
ids=( $zone_ids )
# loop though all IDs ( if more than one )
for id in "${ids[@]}"; do
response=$(curl --silent -X DELETE "https://api.cloudflare.com/client/v4/zones/${domain_id}/dns_records/${id}" \
-H "X-Auth-Email: ${email}" -H "X-Auth-Key: ${key}" -H "Content-Type: application/json")
done

+ 15
- 0
dns_scripts/dns_del_nsupdate View File

@ -0,0 +1,15 @@
#!/bin/bash
# example of script to add token to local dns using nsupdate
dnskeyfile="path/to/bla.key"
fulldomain="$1"
token="$2"
updatefile=$(mktemp)
printf "update delete _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${fulldomain}" "${token}" > "${updatefile}"
nsupdate -k "${dnskeyfile}" -v "${updatefile}"
rm -f ${updatefile}

Loading…
Cancel
Save