Enables a queue-all Waiting Room with Cloudflare based on CPU load percentage using the Cloudflare API.
This script will enable it under high CPU load which is indicative of a DDOS attack. Visitors will queue-up in the Waiting Room while enabled, and automatically be directed on-through to the site once disabled.
This is a beta script and I barely know what I'm doing so test this thoroughly before using.
It creates a service that runs on a timer, which executes our main shell script which gets the current Waiting Room status and checks the CPU usage. If CPU usage is above our defined limit, it uses the CloudFlare API to set enable the Waiting Room. If CPU usage normalizes and the time limit has passed, it will disable/suspend the Waiting Room.
A prerequisite to this script is that you've already created a Waiting Room at Cloudflare. It should be in a disabled/suspended state, allowing for this script to automate its usage.
Navigate to the parent path where you want to install. If you want to install to /home/cfautowr then navigate to /home
wget https://github.com/jwds1178/cfautowr/raw/master/cfautowr.sh;
Search-and-replace /home/cfautowr with the actual directory path where it's installed. Configure your Cloudflare API token, Waiting Room ID, Zone ID.
mkdir cfautowr;
cp cfautowr.sh cfautowr/cfautowr.sh
cd cfautowr;
chmod +x cfautowr.sh;
./cfautowr.sh -install;
It's now installed and running. Check the logs and confirm it's working.
-install : installs and enables service
-uninstall : uninstalls and then deletes the sub folder
-disable_script : temporarily disables the service from running
-enable_script : re-enables the service
-enable_wr : enables Waiting Room manually
-disable_wr : disables Waiting Room manually
This script was designed to run out of it's own separate folder, if you change that you may have problems.