Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -402,40 +402,55 @@ curl "https://api.metadefender.com/v4/hash/$hash" -H "apikey: $apikey"

# Used in geoblock.sh
download_geoip_mmdb() {
# Rate limit to 1 hour, we have 24 requests per day
if [ -f "$GEOBLOCK_DIR/IPInfo-Country.mmdb" ]
then
if [ "$(( $(date +"%s") - $(stat -c "%Y" "$GEOBLOCK_DIR/IPInfo-Country.mmdb") ))" -lt "3600" ]
then
print_text_in_color "$IGreen" "No need to update $GEOBLOCK_DIR/IPInfo-Country.mmdb since it's newer than 1 hour."
return 1
fi
elif [ -f "$GEOBLOCK_DIR/GeoLite2-Country.mmdb" ]
then
print_text_in_color "$ICyan" "Replacing Maxmind with IPInfo GeoIP database..."
fi

# Download or update current GeoIP DB
maxmind_geoip
export MwKfcYATm43NMT
export i9HL69SLnp4ymy
export x8v8GyVQg2UejdPh
{
echo "GEOIPUPDATE_ACCOUNT_ID=$MwKfcYATm43NMT"
echo "GEOIPUPDATE_LICENSE_KEY=$i9HL69SLnp4ymy"
echo "GEOIPUPDATE_EDITION_IDS=GeoLite2-Country"
echo "GEOIPUPDATE_FREQUENCY=0"
echo "GEOIPUPDATE_PRESERVE_FILE_TIMES=1"
echo "GEOIPUPDATE_VERBOSE=1"
} > /tmp/dockerenv
unset MwKfcYATm43NMT
unset i9HL69SLnp4ymy
install_docker
if docker run --name maxmind --env-file /tmp/dockerenv -v "$GEOBLOCK_DIR":"$GEOBLOCK_DIR" ghcr.io/maxmind/geoipupdate
print_text_in_color "$ICyan" "Downloading latest GeoIP database from https://ipinfo.io..."
if ! curl -sfL https://ipinfo.io/data/free/country.mmdb?token="$x8v8GyVQg2UejdPh" -o "$GEOBLOCK_DIR"/IPInfo-Country.mmdb
then
docker rm -f maxmind
rm -f /tmp/dockerenv
# Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove IPInfos config
rm -f "$GEOBLOCK_DIR"/IPInfo-Country.mmdb
else
docker rm -f maxmind
rm -f /tmp/dockerenv
print_text_in_color "$ICyan" "Rate limit for Maxmind GeoDatabase reached! We're now trying to get the Country Database from https://ipinfo.io instead."
if ! curl -sfL https://ipinfo.io/data/free/country.mmdb?token="$x8v8GyVQg2UejdPh" -o "$GEOBLOCK_DIR"/IPInfo-Country.mmdb
print_text_in_color "$IRed" "Failed downloading GeoIP database from IPInfo, trying plan B..."
export MwKfcYATm43NMT
export i9HL69SLnp4ymy
{
echo "GEOIPUPDATE_ACCOUNT_ID=$MwKfcYATm43NMT"
echo "GEOIPUPDATE_LICENSE_KEY=$i9HL69SLnp4ymy"
echo "GEOIPUPDATE_EDITION_IDS=GeoLite2-Country"
echo "GEOIPUPDATE_FREQUENCY=0"
echo "GEOIPUPDATE_PRESERVE_FILE_TIMES=1"
echo "GEOIPUPDATE_VERBOSE=1"
} > /tmp/dockerenv
unset MwKfcYATm43NMT
unset i9HL69SLnp4ymy
install_docker
if docker run --name maxmind --env-file /tmp/dockerenv -v "$GEOBLOCK_DIR":"$GEOBLOCK_DIR" ghcr.io/maxmind/geoipupdate
then
msg_box "Sorry, we couldn't get the needed IP geolocation database from any source, please try again in 24 hours."
return 1
docker rm -f maxmind
rm -f /tmp/dockerenv
# Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove IPInfos config
rm -f "$GEOBLOCK_DIR"/IPInfo-Country.mmdb
print_text_in_color "$IGreen" "Maxmind GeoIP database downloaded!"
else
# Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove MaxMinds config
rm -f "$GEOBLOCK_DIR"/GeoLite2-Country.mmdb
return 0
docker rm -f maxmind
rm -f /tmp/dockerenv
print_text_in_color "$IRed" "Rate limit for Maxmind GeoIP database reached! Can't continue from here, please report this to $ISSUES"
fi
else
# Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove MaxMinds config
rm -f "$GEOBLOCK_DIR"/GeoLite2-Country.mmdb
return 0
fi
unset x8v8GyVQg2UejdPh
}
Expand Down