diff --git a/CHANGELOG.md b/CHANGELOG.md index ee8ea6e90..a85f9ce2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## untagged +- QoL: Add a script for creating DNS records in Cloudflare + ([#692](https://github.com/chatmail/relay/pull/692)) + - Require TLS 1.2 for outgoing SMTP connections ([#685](https://github.com/chatmail/relay/pull/685)) diff --git a/README.md b/README.md index 9f60d1138..ad5d49e31 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,20 @@ Please substitute it with your own domain. mta-sts.chat.example.com. 3600 IN CNAME chat.example.com. ``` +> [!note] +> If you use Cloudflare as your DNS server, you can use a script that will automatically create all the necessary DNS records! +> To do this, you need to [create an API token](https://dash.cloudflare.com/profile/api-tokens) +> and execute the following commands in the console after you clone the repository (step 2): +> ```bash +> CLOUDFLARE_API_KEY="dsfkljhfkjldwsnfkjldsnf" # REPLACE TO YOURS +> ZONE_ID="sdkjbfbnjkdsbfjkdsbkjfbds" # REPLACE TO YOURS +> CHATMAIL_FULL_DNS_NAME="chat.example.com" # REPLACE TO YOURS +> CHATMAIL_PUBLIC_IP="198.51.100.5" # REPLACE TO YOURS +> # IPV6_ENABLED="true" # (optional) by default 'false' +> # CHATMAIL_PUBLIC_IPv6="2001:db8::5" # (optional) REPLACE TO YOURS +> ./scripts/create_cloudflare_records.sh +> ``` + 2. On your local PC, clone the repository and bootstrap the Python virtualenv. ``` diff --git a/scripts/create_cloudflare_records.sh b/scripts/create_cloudflare_records.sh new file mode 100755 index 000000000..5b2b5c60f --- /dev/null +++ b/scripts/create_cloudflare_records.sh @@ -0,0 +1,173 @@ +#!/bin/bash +# go to https://dash.cloudflare.com/profile/api-tokens +# "create token" -> "Edit zone DNS" +## optionaly: rename token +## set your zone +# "continue to summary" -> "create token" +# copy your created token + +CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} +ZONE_ID=${ZONE_ID} + +CHATMAIL_FULL_DNS_NAME=${CHATMAIL_FULL_DNS_NAME} +CHATMAIL_PUBLIC_IP=${CHATMAIL_PUBLIC_IP} + +IPV6_ENABLED=${IPV6_ENABLED:-false} +CHATMAIL_PUBLIC_IPv6=${CHATMAIL_PUBLIC_IPv6} + +##################### +# why 'proxied' is 'false'? +# I suppose that if Cloudflare is blocked in a country, clients cannot use Deltachat without a VPN. +##################### +PROXIED=${PROXIED:-"false"} + +check_variables() { + required_vars=( + CLOUDFLARE_API_KEY + ZONE_ID + CHATMAIL_FULL_DNS_NAME + CHATMAIL_PUBLIC_IP + ) + + missing_vars=() + + for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then + missing_vars+=("$var") + fi + done + + if [ ${#missing_vars[@]} -ne 0 ]; then + echo "❌ Error: this variables not set or empty:" + for var in "${missing_vars[@]}"; do + echo " - $var" + done + echo "Please execute command 'export var_name=\"var_value\"' and restart script." + exit 1 + fi +} + + +create_record() { + local data=$1 + curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records \ + -H 'Content-Type: application/json' \ + -H "Authorization: Bearer ${CLOUDFLARE_API_KEY}" \ + -d "$1" +} + +generate_post_data_a_aaaa_record() +{ + local name=$1 + local type=${2:-"A"} + cat <