-
-
Save AllanTaylor314/d35b573fa1c8b99fc528df728a662cf8 to your computer and use it in GitHub Desktop.
Cloudflare Auth Hook for Certbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo $CERTBOT_DOMAIN | |
echo $CERTBOT_VALIDATION | |
if [ -z "$CERTBOT_TOKEN" ] | |
then | |
echo 'DNS' | |
API_TOKEN="YOUR_TOKEN_HERE" | |
DOMAIN=$CERTBOT_DOMAIN | |
ZONE_ID="zone_id_here" | |
echo $ZONE_ID | |
CREATE_DOMAIN="_acme-challenge.$CERTBOT_DOMAIN" | |
RECORD_ID_PRE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \ | |
-H "Authorization: Bearer $API_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
--data '{"type":"TXT","name":"'"$CREATE_DOMAIN"'","content":"'"$CERTBOT_VALIDATION"'","ttl":120}') | |
echo "RecordID=$RECORD_ID_PRE" | |
RECORD_ID=$(echo $RECORD_ID_PRE | python -c "import sys,json;print(json.load(sys.stdin)['result']['id'])") | |
if [ ! -d /tmp/CERTBOT_$CERTBOT_DOMAIN ];then | |
mkdir -m 0700 /tmp/CERTBOT_$CERTBOT_DOMAIN | |
fi | |
echo $ZONE_ID > /tmp/CERTBOT_$CERTBOT_DOMAIN/ZONE_ID | |
echo $RECORD_ID > /tmp/CERTBOT_$CERTBOT_DOMAIN/RECORD_ID | |
sleep 25 | |
else | |
echo 'HTTP' | |
echo $CERTBOT_VALIDATION > /var/www/html/.well-known/acme-challenge/$CERTBOT_TOKEN | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$CERTBOT_TOKEN" ] | |
then | |
echo 'DNS' | |
API_TOKEN="YOUR_TOKEN_HERE" | |
if [ -f /tmp/CERTBOT_$CERTBOT_DOMAIN/ZONE_ID ]; then | |
ZONE_ID=$(cat /tmp/CERTBOT_$CERTBOT_DOMAIN/ZONE_ID) | |
rm -f /tmp/CERTBOT_$CERTBOT_DOMAIN/ZONE_ID | |
fi | |
if [ -f /tmp/CERTBOT_$CERTBOT_DOMAIN/RECORD_ID ]; then | |
RECORD_ID=$(cat /tmp/CERTBOT_$CERTBOT_DOMAIN/RECORD_ID) | |
rm -f /tmp/CERTBOT_$CERTBOT_DOMAIN/RECORD_ID | |
fi | |
if [ -n "${ZONE_ID}" ]; then | |
if [ -n "${RECORD_ID}" ]; then | |
curl -s -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \ | |
-H "Authorization: Bearer $API_TOKEN" \ | |
-H "Content-Type: application/json" | |
fi | |
fi | |
else | |
echo 'HTTP' | |
rm -f /var/www/html/.well-known/acme-challenge/$CERTBOT_TOKEN | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
systemctl restart apache2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment