Download IP ban list and format for NGINX
#!/bin/bash | |
# | |
# -------------------------------------------------------------------------------------------- | |
# Nginx IP Address Deny List download and format | |
# -------------------------------------------------------------------------------------------- | |
# This file pulls from http://www.stopforumspam.com/downloads/bannedips.zip to | |
# retrieve a list of IPs known to be associated with spam. The program | |
# downloads, unzips, and formats the IP addresses into an NGINX config using | |
# 'deny' | |
# | |
# -------------------------------------------------------------------------------------------- | |
# Author Info | |
# -------------------------------------------------------------------------------------------- | |
# Name :: Tim Kennell Jr. ~ tikenn | |
# Licence :: MIT (http://opensource.org/licenses/MIT) | |
# Version :: 0.1 | |
# | |
# -------------------------------------------------------------------------------------------- | |
# Config | |
# -------------------------------------------------------------------------------------------- | |
# DOWNLOAD :: directory to download the file to | |
# | |
# STORE :: this is where the place we store and delete the old file. | |
# - If you change the location make sure you delete the files | |
# - associated and rerun this script. | |
# | |
# -------------------------------------------------------------------------------------------- | |
# Setting up crontab | |
# -------------------------------------------------------------------------------------------- | |
# - Create a file in /etc/cron.d/ | |
# - Run the file at least once a day to retrieve the most recent version | |
# - Example line (runs at midnight): "0 0 * * * /path/to/hulk.sh" | |
# | |
# ~ tikenn | |
DOWNLOAD=/opt/hulk | |
STORE=/etc/nginx/conf.d/ | |
# -------------------------------------------------------------------------------------------- | |
# Core App | |
# -------------------------------------------------------------------------------------------- | |
[[ -f "$DOWNLOAD/bannedips.zip" ]] && rm "$DOWNLOAD/bannedips.zip" | |
wget -O "$DOWNLOAD/bannedips.zip" http://www.stopforumspam.com/downloads/bannedips.zip | |
unzip -o "$DOWNLOAD/bannedips.zip" -d "$DOWNLOAD" | |
[[ -f "$STORE/bannedips.conf" ]] && rm "$STORE/bannedips.conf" | |
while read -r -d , ip ; do | |
echo "deny $ip;" >> "$STORE/bannedips.conf" | |
done < "$DOWNLOAD/bannedips.csv" | |
service nginx reload | |
# --------------------------------------------------------------------------------------------- | |
# End of Core App | |
# -------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment