Forked from mkg20001/generate-nginx-cloudflare-allow.sh
Last active
October 8, 2024 10:13
-
-
Save aquarion/bfe7e61042c9e8786c9a678fe4f14e1e to your computer and use it in GitHub Desktop.
A script to generate a config to allow or additionally allow cloudflare addresses for a specific domain
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 | |
#PASSWORD=$1 # Now using .my.cnf for password | |
LOC=/var/backups/mysql/$1 | |
# Exit immediately if a pipeline returns non-zero. | |
# Short form: set -e | |
set -o errexit | |
# Print a helpful message if a pipeline with non-zero exit code causes the | |
# script to exit as described above. | |
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR | |
# Allow the above trap be inherited by all functions in the script. | |
# Short form: set -E | |
set -o errtrace | |
# Return value of a pipeline is the value of the last (rightmost) command to | |
# exit with a non-zero status, or zero if all commands in the pipeline exit | |
# successfully. | |
set -o pipefail | |
set -e | |
cf_ips() { | |
echo "# https://www.cloudflare.com/ips" | |
for type in v4 v6; do | |
echo "# IP$type" | |
curl -sL "https://www.cloudflare.com/ips-$type/" | sed "s|^|allow |g" | sed "s|\$|;|g" | |
echo | |
done | |
echo "# Generated at $(LC_ALL=C date)" | |
} | |
cf_ips > allow-cloudflare.conf | |
(cf_ips && echo "deny all; # deny all remaining ips") > allow-cloudflare-only.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment