Skip to content

Instantly share code, notes, and snippets.

@DrJume
Last active June 21, 2021 14:51
Show Gist options
  • Save DrJume/5b7d081cfd5493b4bf6d2fa09ec7f241 to your computer and use it in GitHub Desktop.
Save DrJume/5b7d081cfd5493b4bf6d2fa09ec7f241 to your computer and use it in GitHub Desktop.
Cloudflare zone settings overview as table
#!/bin/bash
# parameters
CF_API_EMAIL=
CF_API_KEY=
# specify the id for a zone (domain)
# get it via the Cloudflare Dashboard
# of via flarectl: https://github.com/cloudflare/cloudflare-go/tree/master/cmd/flarectl
CF_ZONE=
# fetch data from Cloudflare API in JSON format
curl -X GET "https://api.cloudflare.com/client/v4/zones/$CF_ZONE/settings" \
-H "X-Auth-Email: $CF_API_EMAIL" -H "X-Auth-Key: $CF_API_KEY" -H "Content-Type: application/json" \
> "zone-settings-$CF_ZONE.json"
# filter & format JSON to CSV
# download jq from https://stedolan.github.io/jq/
cat "zone-settings-$CF_ZONE.json" | jq -r '[.result[] | {id, value} | to_entries | map(.value) | map(tostring)] | .[] | join(";")' \
> "zone-settings-$CF_ZONE.csv"
# visualize CSV as a table in the terminal
cat "zone-settings-$CF_ZONE.csv" | column -s';' -t -c 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment