From a8ffb6949c76ea16e96ec4d45e6524cd8cc42c2d Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 3 Jan 2020 16:31:28 +1100 Subject: [PATCH] FEATURE: support MaxMind DB downloads using a license key MaxMind now requires an account with a license key to download files. Discourse admins can register for such an account at: https://www.maxmind.com/en/geolite2/signup License key generation is available in the profile section. Once registered you can set the license key using `DISCOURSE_MAXMIND_LICENSE_KEY` This amends it so we unconditionally skip MaxMind DB downloads if no license key exists. --- config/discourse_defaults.conf | 6 +++++- lib/discourse_ip_info.rb | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf index ff58c372332..aee0f88ab29 100644 --- a/config/discourse_defaults.conf +++ b/config/discourse_defaults.conf @@ -236,11 +236,15 @@ max_logster_logs = 1000 # during precompile update maxmind database if older than N days # set to 0 to disable -refresh_maxmind_db_during_precompile_days = 30 +refresh_maxmind_db_during_precompile_days = 2 # backup path containing maxmind db files maxmind_backup_path = +# register an account at: https://www.maxmind.com/en/geolite2/signup +# then head to profile and get your license key +maxmind_license_key= + # when enabled the following headers will be added to every response: # (note, if measurements do not exist for the header they will be omitted) # diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 75853c10f20..50c5d3854f2 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -25,10 +25,19 @@ class DiscourseIpInfo end def self.mmdb_download(name) + + if GlobalSetting.maxmind_license_key.blank? + STDERR.puts "MaxMind IP database updates require a license" + STDERR.puts "Please set DISCOURSE_MAXMIND_LICENSE_KEY to one you generated at https://www.maxmind.com" + return + end + FileUtils.mkdir_p(path) + url = "https://download.maxmind.com/app/geoip_download?license_key=#{GlobalSetting.maxmind_license_key}&edition_id=#{name}&suffix=tar.gz" + gz_file = FileHelper.download( - "https://geolite.maxmind.com/geoip/databases/#{name}/update", + url, max_file_size: 100.megabytes, tmp_file_name: "#{name}.gz", validate_uri: false,