@@ -402,40 +402,55 @@ curl "https://api.metadefender.com/v4/hash/$hash" -H "apikey: $apikey"
402
402
403
403
# Used in geoblock.sh
404
404
download_geoip_mmdb () {
405
+ # Rate limit to 1 hour, we have 24 requests per day
406
+ if [ -f " $GEOBLOCK_DIR /IPInfo-Country.mmdb" ]
407
+ then
408
+ if [ " $(( $(date + "% s") - $(stat - c "% Y" "$GEOBLOCK_DIR / IPInfo- Country.mmdb") )) " -lt " 3600" ]
409
+ then
410
+ print_text_in_color " $IGreen " " No need to update $GEOBLOCK_DIR /IPInfo-Country.mmdb since it's newer than 1 hour."
411
+ return 1
412
+ fi
413
+ elif [ -f " $GEOBLOCK_DIR /GeoLite2-Country.mmdb" ]
414
+ then
415
+ print_text_in_color " $ICyan " " Replacing Maxmind with IPInfo GeoIP database..."
416
+ fi
417
+
418
+ # Download or update current GeoIP DB
405
419
maxmind_geoip
406
- export MwKfcYATm43NMT
407
- export i9HL69SLnp4ymy
408
420
export x8v8GyVQg2UejdPh
409
- {
410
- echo " GEOIPUPDATE_ACCOUNT_ID=$MwKfcYATm43NMT "
411
- echo " GEOIPUPDATE_LICENSE_KEY=$i9HL69SLnp4ymy "
412
- echo " GEOIPUPDATE_EDITION_IDS=GeoLite2-Country"
413
- echo " GEOIPUPDATE_FREQUENCY=0"
414
- echo " GEOIPUPDATE_PRESERVE_FILE_TIMES=1"
415
- echo " GEOIPUPDATE_VERBOSE=1"
416
- } > /tmp/dockerenv
417
- unset MwKfcYATm43NMT
418
- unset i9HL69SLnp4ymy
419
- install_docker
420
- if docker run --name maxmind --env-file /tmp/dockerenv -v " $GEOBLOCK_DIR " :" $GEOBLOCK_DIR " ghcr.io/maxmind/geoipupdate
421
+ print_text_in_color " $ICyan " " Downloading latest GeoIP database from https://ipinfo.io..."
422
+ if ! curl -sfL https://ipinfo.io/data/free/country.mmdb? token=" $x8v8GyVQg2UejdPh " -o " $GEOBLOCK_DIR " /IPInfo-Country.mmdb
421
423
then
422
- docker rm -f maxmind
423
- rm -f /tmp/dockerenv
424
- # Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove IPInfos config
425
- rm -f " $GEOBLOCK_DIR " /IPInfo-Country.mmdb
426
- else
427
- docker rm -f maxmind
428
- rm -f /tmp/dockerenv
429
- 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."
430
- if ! curl -sfL https://ipinfo.io/data/free/country.mmdb? token=" $x8v8GyVQg2UejdPh " -o " $GEOBLOCK_DIR " /IPInfo-Country.mmdb
424
+ print_text_in_color " $IRed " " Failed downloading GeoIP database from IPInfo, trying plan B..."
425
+ export MwKfcYATm43NMT
426
+ export i9HL69SLnp4ymy
427
+ {
428
+ echo " GEOIPUPDATE_ACCOUNT_ID=$MwKfcYATm43NMT "
429
+ echo " GEOIPUPDATE_LICENSE_KEY=$i9HL69SLnp4ymy "
430
+ echo " GEOIPUPDATE_EDITION_IDS=GeoLite2-Country"
431
+ echo " GEOIPUPDATE_FREQUENCY=0"
432
+ echo " GEOIPUPDATE_PRESERVE_FILE_TIMES=1"
433
+ echo " GEOIPUPDATE_VERBOSE=1"
434
+ } > /tmp/dockerenv
435
+ unset MwKfcYATm43NMT
436
+ unset i9HL69SLnp4ymy
437
+ install_docker
438
+ if docker run --name maxmind --env-file /tmp/dockerenv -v " $GEOBLOCK_DIR " :" $GEOBLOCK_DIR " ghcr.io/maxmind/geoipupdate
431
439
then
432
- msg_box " Sorry, we couldn't get the needed IP geolocation database from any source, please try again in 24 hours."
433
- return 1
440
+ docker rm -f maxmind
441
+ rm -f /tmp/dockerenv
442
+ # Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove IPInfos config
443
+ rm -f " $GEOBLOCK_DIR " /IPInfo-Country.mmdb
444
+ print_text_in_color " $IGreen " " Maxmind GeoIP database downloaded!"
434
445
else
435
- # Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove MaxMinds config
436
- rm -f " $GEOBLOCK_DIR " /GeoLite2-Country.mmdb
437
- return 0
446
+ docker rm -f maxmind
447
+ rm -f /tmp/dockerenv
448
+ print_text_in_color " $IRed " " Rate limit for Maxmind GeoIP database reached! Can't continue from here, please report this to $ISSUES "
438
449
fi
450
+ else
451
+ # Since only one mmdb file can exist at the same time due to Apache "if" confitions, remove MaxMinds config
452
+ rm -f " $GEOBLOCK_DIR " /GeoLite2-Country.mmdb
453
+ return 0
439
454
fi
440
455
unset x8v8GyVQg2UejdPh
441
456
}
0 commit comments