Last active
April 3, 2025 05:33
-
-
Save selivan/f053008964128fea0dc913c803062263 to your computer and use it in GitHub Desktop.
Script to update some settings for all zones on a Cloudflare account. Default: disable TLS ECH(Encrypted Client Hello).
This file contains hidden or 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 | |
ACCOUNT_EMAIL="$1" | |
GLOBAL_API_KEY="$2" | |
OPTION="${3:-ech}" | |
VALUE="${4:-off}" | |
if [ -z "${ACCOUNT_EMAIL}" ] || [ -z "${GLOBAL_API_KEY}" ]; then | |
echo "Usage: $0 CLOUDFLARE_ACCOUNT_EMAIL CLOUDFLARE_GLOBAL_API_KEY [OPTION] [VALUE]" | |
echo | |
echo "Set specified setting for all zones for given account" | |
echo "By default disable TLS ECH, that can not be done from web UI for free accounts" | |
echo "To disable TLS 1.3 use this option: tls_1_3 off" | |
echo | |
echo "Docs: https://developers.cloudflare.com/api/operations/zone-settings-get-all-zone-settings" | |
echo "Get all available zone settings: GET https://api.cloudflare.com/client/v4/zones/ID_ZONE/settings" | |
exit 1 | |
fi | |
type curl && type jq || exit 1 | |
# https://developers.cloudflare.com/api/operations/zones-get | |
zones=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?per_page=50" \ | |
-H "X-Auth-Email: ${ACCOUNT_EMAIL}" \ | |
-H "X-Auth-Key: ${GLOBAL_API_KEY}") | |
num_pages=$(echo "$zones" | jq --exit-status -r ".result_info.total_pages") || { echo "Something went wrong"; exit 1; } | |
for page in $(seq 1 $num_pages); do | |
curl -s -X GET "https://api.cloudflare.com/client/v4/zones?per_page=50&page=$page" \ | |
-H "X-Auth-Email: ${ACCOUNT_EMAIL}" \ | |
-H "X-Auth-Key: ${GLOBAL_API_KEY}" \ | |
| jq '.result' | jq '.[]' | jq -c '[.id,.name]' \ | |
| while read -r i; do | |
ID_ZONE=$(echo "$i" | jq -r '.[0]') | |
NAME_ZONE=$(echo "$i" | jq -r '.[1]') | |
echo "Zone id: ${ID_ZONE}" | |
echo "Name: ${NAME_ZONE}" | |
echo "Changing ${OPTION} to ${VALUE} ..." | |
curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/${ID_ZONE}/settings/${OPTION}" \ | |
-H "X-Auth-Email: ${ACCOUNT_EMAIL}" \ | |
-H "X-Auth-Key: ${GLOBAL_API_KEY}" \ | |
-H "Content-Type:application/json" --data "{\"id\":\"${OPTION}\",\"value\":\"${VALUE}\"}" | jq | |
done | |
done |
Notice: curl -s -X GET "https://api.cloudflare.com/client/v4/zones
gives first 40 zones by default and if you have more – then you need to use ?per_page=100
(or ?page=2
) in request
@igor-arkhipov Thanks for the catch! Updated script.
Much thanks!
simple for specify zoneid
Windows: https://gist.github.com/FazziCLAY/38f56ab423a0e0a2f864985cf3ce21be
Linux: https://gist.github.com/FazziCLAY/75f72acc8b728530a637121fdee4dfb5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! :)
P.S.: also requires
jq
to be installed –brew install jq