diff --git a/lib.sh b/lib.sh index d76a2066cc..27905d4c51 100644 --- a/lib.sh +++ b/lib.sh @@ -156,6 +156,7 @@ HTTP2_CONF="/etc/apache2/mods-available/http2.conf" # GeoBlock GEOBLOCK_MOD_CONF="/etc/apache2/conf-available/geoblock.conf" GEOBLOCK_MOD="/etc/apache2/mods-available/maxminddb.load" +GEOBLOCK_DIR="/usr/share/GeoIP" # PHP-FPM PHPVER=8.3 PHP_FPM_DIR=/etc/php/$PHPVER/fpm @@ -404,7 +405,8 @@ curl "https://api.metadefender.com/v4/hash/$hash" -H "apikey: $apikey" download_geoip_mmdb() { maxmind_geoip export MwKfcYATm43NMT - export i9HL69SLnp4ymy + export i9HL69SLnp4ymy + export x8v8GyVQg2UejdPh { echo "GEOIPUPDATE_ACCOUNT_ID=$MwKfcYATm43NMT" echo "GEOIPUPDATE_LICENSE_KEY=$i9HL69SLnp4ymy" @@ -414,18 +416,29 @@ download_geoip_mmdb() { echo "GEOIPUPDATE_VERBOSE=1" } > /tmp/dockerenv unset MwKfcYATm43NMT - unset i9HL69SLnp4ymy + unset i9HL69SLnp4ymy install_docker - if docker run --name maxmind --env-file /tmp/dockerenv -v /usr/share/GeoIP:/usr/share/GeoIP ghcr.io/maxmind/geoipupdate + if docker run --name maxmind --env-file /tmp/dockerenv -v "$GEOBLOCK_DIR":"$GEOBLOCK_DIR" ghcr.io/maxmind/geoipupdate 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 - msg_box "Update limit for Maxmind GeoDatabase reached! Please try again tomorrow." - return 1 + 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 + then + msg_box "Sorry, we couldn't get the needed IP geolocation database from any source, please try again in 24 hours." + return 1 + 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 fi + unset x8v8GyVQg2UejdPh } # Check if process is runnnig: is_process_running dpkg diff --git a/network/geoblock.sh b/network/geoblock.sh index d942c42855..06dab4409a 100644 --- a/network/geoblock.sh +++ b/network/geoblock.sh @@ -35,8 +35,9 @@ else # Remove old database files find /var/scripts -type f -regex \ "$SCRIPTS/202[0-9]-[01][0-9]-Maxmind-Country-IPv[46]\.dat" -delete -find /usr/share/GeoIP -type f -regex \ + find "$GEOBLOCK_DIR" -type f -regex \ "*.dat" -delete + rm -f "$GEOBLOCK_DIR"/IPInfo-Country.mmdb # Remove Apache2 mod if [ -f "$GEOBLOCK_MOD" ] then @@ -69,8 +70,8 @@ find /usr/share/GeoIP -type f -regex \ # Show successful uninstall if applicable removal_popup "$SCRIPT_NAME" # Make sure it's clean from unused packages and files - apt purge libmaxminddb0* libmaxminddb-dev* mmdb-bin* apache2-dev* -y - apt autoremove -y + apt-get purge libmaxminddb0* libmaxminddb-dev* mmdb-bin* apache2-dev* -y + apt-get autoremove -y check_command systemctl restart apache2 fi @@ -221,10 +222,19 @@ fi cat << GEOBLOCKCONF_CREATE > "$GEOBLOCK_MOD_CONF" MaxMindDBEnable On - MaxMindDBFile DB /usr/share/GeoIP/GeoLite2-Country.mmdb - MaxMindDBEnv MM_CONTINENT_CODE DB/continent/code - MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code + # Check for IPinfo mmdb + + MaxMindDBFile DB $GEOBLOCK_DIR/IPInfo-Country.mmdb + MaxMindDBEnv MM_CONTINENT_CODE DB/continent + MaxMindDBEnv MM_COUNTRY_CODE DB/country + + # Check for Maxmind mmdb + + MaxMindDBFile DB $GEOBLOCK_DIR/GeoLite2-Country.mmdb + MaxMindDBEnv MM_CONTINENT_CODE DB/continent/code + MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code + # Geoblock rules diff --git a/nextcloud_update.sh b/nextcloud_update.sh index 9854c638e0..bb1701f0e6 100644 --- a/nextcloud_update.sh +++ b/nextcloud_update.sh @@ -596,7 +596,7 @@ elif [ -f "$GEOBLOCK_MOD" ] then if download_geoip_mmdb then - print_text_in_color "$IGreen" "MaxMind database updated!" + print_text_in_color "$IGreen" "GeoBlock database updated!" fi fi