-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Microsoft Public IP Space & streamline scripts
- Loading branch information
1 parent
8aa3f72
commit a30f822
Showing
7 changed files
with
137 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
10 changes: 10 additions & 0 deletions
10
images/v2-alpine_cloudflare_rate-limit/bin/abuseipdb_cron.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Execute this script with a cron job on the host system to keep the AbuseIPDB list up to date without pulling the latest image | ||
# | ||
|
||
# Update the AbuseIPDB blocklist | ||
/usr/local/bin/abuseipdb_update.sh | ||
# Reload caddy to apply the new updated AbuseIPDB list | ||
caddy reload --config /etc/caddy/Caddyfile |
39 changes: 39 additions & 0 deletions
39
images/v2-alpine_cloudflare_rate-limit/bin/abuseipdb_update.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# This script expects the following environment variables to exist: | ||
# ABUSE_IP_DB_LOCAL_BASE_DIRECTORY | ||
# ABUSE_IP_DB_LOCAL_FILENAME | ||
# ABUSE_IP_DB_REMOTE_FILENAME | ||
# ABUSE_IP_DB_MINIMUM_ENTRY_COUNT | ||
# | ||
# Check the Dockerfile for a detailed explanation of these environment variables | ||
# | ||
|
||
DOWNLOAD_URL="https://raw.githubusercontent.com/borestad/blocklist-abuseipdb/refs/heads/main/${ABUSE_IP_DB_REMOTE_FILENAME}" | ||
OUTPUT_FILE="${ABUSE_IP_DB_LOCAL_BASE_DIRECTORY}/${ABUSE_IP_DB_LOCAL_FILENAME}" | ||
|
||
# Download the AbuseIPDB blocklist | ||
TEMP_DOWNLOAD_FILE=$(mktemp) | ||
if ! wget "${DOWNLOAD_URL}" -O "${TEMP_DOWNLOAD_FILE}" | ||
then | ||
echo "Failed to download the AbuseIPDB blocklist" | ||
exit 1 | ||
fi | ||
|
||
LINE_COUNT=$(wc -l < "${TEMP_DOWNLOAD_FILE}") | ||
if [ "${LINE_COUNT}" -lt "${ABUSE_IP_DB_MINIMUM_ENTRY_COUNT}" ] | ||
then | ||
echo "Too few IPs in the list (${TEMP_DOWNLOAD_FILE}). Expected: ${ABUSE_IP_DB_MINIMUM_ENTRY_COUNT} Actual: ${LINE_COUNT}" | ||
exit 1 | ||
fi | ||
|
||
echo "Successfully downloaded the AbuseIPDB blocklist to ${TEMP_DOWNLOAD_FILE}" | ||
|
||
# Truncate the output file, otherwise running this script multiple times would append the result every time | ||
true > "${OUTPUT_FILE}" | ||
|
||
# Loop through each IP in the AbuseIPDB file, excluding comments, and add remote_ip before each IP so it can be imported in a Caddyfile | ||
for IP in $(grep -hv '^#' "${TEMP_DOWNLOAD_FILE}"); do | ||
echo "remote_ip $IP" >> "${OUTPUT_FILE}" | ||
done |
32 changes: 0 additions & 32 deletions
32
images/v2-alpine_cloudflare_rate-limit/bin/download_abuseipdb.sh
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
images/v2-alpine_cloudflare_rate-limit/bin/microsoft-public-ip-space_cron.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Execute this script with a cron job on the host system to keep the Microsoft Public IP Space up to date without pulling the latest image | ||
# | ||
|
||
# Update the AbuseIPDB blocklist | ||
/usr/local/bin/microsoft-public-ip-space_update.sh | ||
# Reload caddy to apply the new updated AbuseIPDB list | ||
caddy reload --config /etc/caddy/Caddyfile |
44 changes: 44 additions & 0 deletions
44
images/v2-alpine_cloudflare_rate-limit/bin/microsoft-public-ip-space_update.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
# Microsoft landing page which contains the URL to the current public IP CSV | ||
PAGE_URL="https://www.microsoft.com/en-us/download/details.aspx?id=53602" | ||
|
||
# Microsoft blocks requests from wget without a valid user agent, so we fake one | ||
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36" | ||
|
||
# Output file name | ||
OUTPUT_FILE="${MICROSOFT_PUBLIC_IP_SPACE_LOCAL_BASE_DIRECTORY}/${MICROSOFT_PUBLIC_IP_SPACE_LOCAL_FILENAME}" | ||
|
||
# Determine the current CSV URL | ||
LATEST_CSV_URL=$(wget --user-agent="$USER_AGENT" -q -O - "${PAGE_URL}" | grep -oE 'https://download\.microsoft\.com/download/[^\"]+\.csv' | head -n 1) | ||
|
||
if [ -z "${LATEST_CSV_URL}" ]; then | ||
echo "Failed to determine the latest CSV URL" | ||
exit 1 | ||
fi | ||
|
||
LATEST_CSV_DATA=$(wget --user-agent="$USER_AGENT" -q -O - "${LATEST_CSV_URL}") | ||
|
||
LINE_COUNT=$(echo "${LATEST_CSV_DATA}" | wc -l) | ||
if [ "${LINE_COUNT}" -lt 100 ] | ||
then | ||
echo "Too few IPs in the list. Expected: 100 Actual: ${LINE_COUNT}" | ||
exit 1 | ||
fi | ||
|
||
# Truncate the output file, otherwise running this script multiple times would append the result every time | ||
true > "${OUTPUT_FILE}" | ||
|
||
# Remove header row from the CSV | ||
LATEST_CSV_DATA=$(echo "${LATEST_CSV_DATA}" | tail -n +2) | ||
|
||
# Get first column (IP range) | ||
LATEST_CSV_DATA=$(echo "${LATEST_CSV_DATA}" | cut -d',' -f1) | ||
|
||
# Filter IPv6 addresses | ||
LATEST_CSV_DATA=$(echo "${LATEST_CSV_DATA}" | grep -v ':') | ||
|
||
echo "${LATEST_CSV_DATA}" | while read -r IP_RANGE | ||
do | ||
echo "remote_ip ${IP_RANGE}" >> "${OUTPUT_FILE}" | ||
done |