Skip to content

Instantly share code, notes, and snippets.

@HackingGate
Last active July 2, 2019 15:08
Show Gist options
  • Save HackingGate/68ce248c8928a9305ea3ea20bd439053 to your computer and use it in GitHub Desktop.
Save HackingGate/68ce248c8928a9305ea3ea20bd439053 to your computer and use it in GitHub Desktop.
Quickly turn on CloudFlare development mode when incident happens
# You need jq and curl installed:
# sudo apt install jq curl -y
#!/bin/bash
# CHANGE THESE
auth_email="[email protected]"
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # find in cloudflare account settings
zone_identifier="023e105f4ecef8ad9ca31a8372d0c353" # get zone ID via API
# Get zone ID
#domain_name=example.com
#zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=${domain_name}&status=active&page=1&per_page=20&order=status&direction=desc&match=all" \
# -H "X-Auth-Email: ${auth_email}" \
# -H "X-Auth-Key: ${auth_key}" \
# -H "Content-Type: application/json" \
# | jq -r '.result[] | "\(.id)"')
# Purge everything
curl -s -X DELETE "https://api.cloudflare.com/client/v4/zones/${zone_identifier}/purge_cache" \
-H "X-Auth-Email: ${auth_email}" \
-H "X-Auth-Key: ${auth_key}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}' \
| jq
# Turn on development mode
curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/development_mode" \
-H "X-Auth-Email: ${auth_email}" \
-H "X-Auth-Key: ${auth_key}" \
-H "Content-Type: application/json" \
--data '{"value":"on"}' \
| jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment