Skip to content

Instantly share code, notes, and snippets.

@presswizards
Created July 11, 2024 08:05
Show Gist options
  • Save presswizards/67978a143936503f0589d00229cc2fac to your computer and use it in GitHub Desktop.
Save presswizards/67978a143936503f0589d00229cc2fac to your computer and use it in GitHub Desktop.
Plesk Add Trusted IPs to fail2ban to prevent badbot blocks
#!/bin/bash
# add to crontab to run once per day or week like so via "crontab -e":
# 0 0 */1 * * ~/add_trusted_ips.sh > /dev/null
# URL containing the list of trusted IPs
URL1="https://optimize.exactlywww.com/exactdn/servers.php"
URL2="https://www.cloudflare.com/ips-v4/"
URL3="https://www.cloudflare.com/ips-v6/"
URL4="https://api.bunny.net/system/edgeserverlist/plain"
# Fetch the list of IPs from the URLs
ips1=$(curl -s $URL1)
ips2=$(curl -s $URL2)
ips3=$(curl -s $URL3)
ips4=$(curl -s $URL4)
# Convert the list of IPs from newline-delimited to semicolon-delimited
trusted_ips1=$(echo "$ips1" | tr '\n' ';')
trusted_ips2=$(echo "$ips2" | tr '\n' ';')
trusted_ips3=$(echo "$ips3" | tr '\n' ';')
trusted_ips4=$(echo "$ips4" | tr -d '\r' | tr '\n' ';')
# Remove the old IPs from the Plesk trusted list to prevent duplicates
sudo plesk bin ip_ban --remove-trusted "$trusted_ips1"
sudo plesk bin ip_ban --remove-trusted "$trusted_ips2"
sudo plesk bin ip_ban --remove-trusted "$trusted_ips3"
sudo plesk bin ip_ban --remove-trusted "$trusted_ips4"
# Add the fresh IPs to the Plesk trusted list with descriptions
sudo plesk bin ip_ban --add-trusted "$trusted_ips1" -description "ExactDN"
sudo plesk bin ip_ban --add-trusted "$trusted_ips2" -description "CloudflareIPv4"
sudo plesk bin ip_ban --add-trusted "$trusted_ips3" -description "CloudflareIPv6"
sudo plesk bin ip_ban --add-trusted "$trusted_ips4" -description "BunnyCDN"
@presswizards
Copy link
Author

@presswizards
Copy link
Author

Add support for other server and home/office IPs, if exists in a local file, or just hardcoded...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment