diff --git a/README.md b/README.md new file mode 100644 index 0000000..11cf554 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +This repository conatins everything needed to create and renew LetsEncrypt certificates (incl. wildcard certificates) on Dynu (https://www.dynu.com/). +This should work on machine that can run docker (I'm using it on a QNAP NAS). +If you already have certbot installed you can also just use the scripts in the scripts folder, without docker. + +h1. Usage with docker-compose: +You will need Docker and Docker-Compose: +https://docs.docker.com/install/ +https://docs.docker.com/compose/install/ + +docker-compose -f /certbot/docker-compose.yml up + +Cronjob to run it twice daily (like recomended by Certbot, certificates are only renewed when needed): +0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && docker-compose -f /certbot/docker-compose.yml up + +h1. Usage with locally installed certbot: +Required packages: certbot, jq, curl +certbot certonly --manual-public-ip-logging-ok --non-interactive --agree-tos --email --manual --preferred-challenges=dns --manual-auth-hook /script-pre.sh --manual-cleanup-hook /script-post.sh -d YOURDOMAIN.TLD -d *.YOURDOMAIN.TLD diff --git a/certbot/Dockerfile b/certbot/Dockerfile new file mode 100644 index 0000000..9079004 --- /dev/null +++ b/certbot/Dockerfile @@ -0,0 +1,5 @@ +FROM certbot/certbot:latest + +RUN apk update \ + && apk add jq curl\ + && rm -rf /var/cache/apk/* diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5b2efb5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + certbot: + build: certbot + volumes: + - /etc/letsencrypt/:/etc/letsencrypt/ + - ./scripts:/scripts/ + logging: + driver: json-file + options: + max-size: "10m" + max-file: "1" + command: certonly --manual-public-ip-logging-ok --non-interactive --agree-tos --email --manual --preferred-challenges=dns --manual-auth-hook /scripts/script-pre.sh --manual-cleanup-hook /scripts/script-post.sh -d YOURDOMAIN.TLD -d *.YOURDOMAIN.TLD diff --git a/scripts/script-post.sh b/scripts/script-post.sh new file mode 100644 index 0000000..2d7499f --- /dev/null +++ b/scripts/script-post.sh @@ -0,0 +1,16 @@ +#!/bin/sh +api_key='' +domainID='' + +while + records=$(curl -s -X GET "https://api.dynu.com/v2/dns/$domainID/record" -H "accept: application/json" -H "API-Key: $api_key") + identifier=$(echo $records | jq '.dnsRecords[] | select(.nodeName=="_acme-challenge")' | jq '.id' | head -n 1) + if [ ! -z "$identifier" ] + then + echo "Delete: $identifier" + curl -s -X DELETE "https://api.dynu.com/v2/dns/$domainID/record/$identifier" -H "accept: application/json" -H "API-Key: $api_key" + fi + [[ ! -z "$identifier" ]] +do + continue +done diff --git a/scripts/script-pre.sh b/scripts/script-pre.sh new file mode 100644 index 0000000..050f4d1 --- /dev/null +++ b/scripts/script-pre.sh @@ -0,0 +1,9 @@ +#!/bin/sh +api_key='' +domainID='' + + +#Create record +resultCreate=$(curl -s -X POST "https://api.dynu.com/v2/dns/$domainID/record" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"nodeName\":\"_acme-challenge\",\"recordType\":\"TXT\",\"ttl\":60,\"state\":true,\"group\":\"\",\"textData\":\"$CERTBOT_VALIDATION\"}" -H "API-Key: $api_key") +echo $resultCreate +sleep 30