Assistance to create a script to turn on bot fight mode for all zones in account

Hi All,

Has anyone created a script at all that will achieve:

  1. Connecting to my CF account and listing all active zones.

  2. Turn on bot fight mode for all zones in account (or if not this something else that is turned on for all zones in account. As from there I can amend script to botfight mode params!

If we could please post the script that would be great.

Also I am aware there is an API documentation so please no need to post a link to the API documentation as I am struggling to learn here on this aspect and need some guidance from the community please if some one could assist would be appreciated greatly!

I can’t do all the work for you, this should be a start. Just replace the DNS lookup with the bot_management endpoint.

2 Likes

hi @sjr appreciate that mate! awesome help. However did not work.

Please see my bash script below and thanks for bash i prefer bash!

#!/bin/bash

CF_AUTH_EMAIL="[email protected]"
CF_AUTH_KEY="xxxxxxxx-globalapi-xxxxxxxxxxxx"

ZONE_IDS=`
curl -s --request GET \
  --url https://api.cloudflare.com/client/v4/zones \
  --header "Content-Type: application/json" \
  --header "X-Auth-Email: ${CF_AUTH_EMAIL}" \
  --header "X-Auth-Key: ${CF_AUTH_KEY}" \
 | jq -r '.result[] | "\(.id)"'
`

for zone_id in ${ZONE_IDS}; do 
	botf_on='
curl -X PUT "https://api.cloudflare.com/client/v4/zones/ZONEID/bot_management" \
     -H "X-Auth-Email: CF_AUTH_EMAIL" \
     -H "X-Auth-Key: CF_AUTH_KEY" \
     -H "Content-Type: application/json" \
     --data '{"fight_mode":true}'
| jq .
`
	echo -E "${botf_on}"
done

However below was the output from script:

./cfbotfighton.sh: line 14: jq: command not found
./cfbotfighton.sh: line 21: unexpected EOF while looking for matching `‘’
./cfbotfighton.sh: line 26: syntax error: unexpected end of file

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.