Skip to content

Instantly share code, notes, and snippets.

@ckdake
Created July 25, 2016 13:37
Show Gist options
  • Save ckdake/6b199473065d48190e45ea216b566952 to your computer and use it in GitHub Desktop.
Save ckdake/6b199473065d48190e45ea216b566952 to your computer and use it in GitHub Desktop.
helping cloudflare and certbot get along.
CLOUDFLARE_USER=example@example.com
CLOUDFLARE_KEY=probablyshoulduseyourapikeyhereinstead
#Monday at 2:30am
30 2 * * 1 /opt/letsencrypt/certbot-auto --pre-hook "/root/cloudflare_tools/pause_all_domains.sh" --post-hook "/root/cloudflare_tools/unpause_all_domains.sh" --apache renew
#!/bin/bash
for f in /etc/letsencrypt/renewal/*; do
domain=${f#/etc/letsencrypt/renewal/}
domain=${domain#www.}
domain=${domain%.conf}
domain=`echo ${domain} | rev | cut -d. -f 1,2 | rev`
echo $domain
done
#!/bin/bash
cd /root/cloudflare_tools/
for d in `./domains_to_renew.sh | sort | uniq`; do
./pause_domain.sh $d;
done;
#!/bin/bash
# apt-get install jq
source ~/.cloudflare
CLOUDFLARE_ZONE_ID=`curl -X GET "https://api.cloudflare.com/client/v4/zones?name=${1}&status=active&page=1&per_page=20&order=status&direction=desc&match=all" \
-H "X-Auth-Email: ${CLOUDFLARE_USER}" \
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
-H "Content-Type: application/json" 2> /dev/null | jq -r ".result[0].id"`
RESULT=`curl -X PATCH "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}" \
-H "X-Auth-Email: ${CLOUDFLARE_USER}" \
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
-H "Content-Type: application/json" \
--data '{"paused":true}' 2> /dev/null | jq -r ".success, .errors, .messages"`
echo $RESULT
#!/bin/bash
cd /root/cloudflare_tools/
for d in `./domains_to_renew.sh | sort | uniq`; do
./unpause_domain.sh $d;
done;
#!/bin/bash
# apt-get install jq
source ~/.cloudflare
CLOUDFLARE_ZONE_ID=`curl -X GET "https://api.cloudflare.com/client/v4/zones?name=${1}&status=active&page=1&per_page=20&order=status&direction=desc&match=all" \
-H "X-Auth-Email: ${CLOUDFLARE_USER}" \
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
-H "Content-Type: application/json" 2> /dev/null | jq -r ".result[0].id"`
RESULT=`curl -X PATCH "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}" \
-H "X-Auth-Email: ${CLOUDFLARE_USER}" \
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
-H "Content-Type: application/json" \
--data '{"paused":false}' 2> /dev/null | jq -r ".success, .errors, .messages"`
echo $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment