File: //bigscoots/wpo/nginx/abuserbl_ip_blocklist.sh
#!/bin/bash
source /bigscoots/includes/common.sh
# Define the URL of the server file
abuserbl_file_url="http://67.202.70.147/abuserbl_block.list"
# Define the path to the local file
local_abuserbl_path="/root/.bigscoots/nginx/includes/abuserbl_block.list"
# Define a flag to track whether ngxreload_t has been called
ngx_reloaded=false
# Fetch the MD5 checksum of the server file
abuserbl_checksum=$(curl -s "$abuserbl_file_url" | md5sum | awk '{print $1}')
# Check if the server checksum is not empty
if [[ -n "$abuserbl_checksum" ]]
then
# Check if the local file exists
if [[ -f "$local_abuserbl_path" ]]
then
# Calculate the MD5 checksum of the local file
local_checksum=$(md5sum "$local_abuserbl_path" | awk '{print $1}')
# Check if the checksums are different
if [[ "$abuserbl_checksum" != "$local_checksum" ]]
then
# Checksums are different. Updating local file...
# Download the server file and replace the local file
curl -s -o "$local_abuserbl_path" "$abuserbl_file_url"
# Set the flag to indicate that ngxreload_t has been called
ngx_reloaded=true
fi
else
# Local file does not exist. Downloading the server file...
# Download the server file to the local path
curl -s -o "$local_abuserbl_path" "$abuserbl_file_url"
# Set the flag to indicate that ngxreload_t has been called
ngx_reloaded=true
fi
else
send_slack_alert "#wpo-alerts" ":warning:" "AbuseRBL" "NA" "Server checksum not found. Unable to compare."
fi
add_after_line="include /usr/local/nginx/conf/cloudflare.conf;"
nginx_conf="/usr/local/nginx/conf/nginx.conf"
new_line="include /root/.bigscoots/nginx/includes/abuserbl_block.list;"
# Check if the include file already exists in nginx.conf
if ! grep -q "$new_line" "$nginx_conf"
then
# Add the new_line after add_after_line using sed
sed -i "\|$add_after_line|a $new_line" "$nginx_conf"
fi
mkdir -p /root/.bigscoots/nginx/includes
touch /root/.bigscoots/nginx/includes/abuserbl_block_whitelist.list
# Check if ngxreload_t has not been called earlier in the script
if [ "$ngx_reloaded" = true ]
then
ngxreload_t
fi