mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
UX: Show on IP lookup if MaxMind key is missing (#18993)
as discussed in https://meta.discourse.org/t/maxminddb-not-found-error/148512/7. shows a warning to the admin if no license for maxmind is found
This commit is contained in:
parent
c0216f85a8
commit
c58a41cb3e
|
@ -31,7 +31,15 @@
|
||||||
|
|
||||||
<dt>{{i18n "ip_lookup.location"}}</dt>
|
<dt>{{i18n "ip_lookup.location"}}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{#if this.location.location}}
|
{{#if this.location.no_license}}
|
||||||
|
<a
|
||||||
|
href="https://meta.discourse.org/t/configure-maxmind-for-reverse-ip-lookups/173941"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
{{i18n "ip_lookup.no_license"}}
|
||||||
|
</a>
|
||||||
|
{{else if this.location.location}}
|
||||||
<a
|
<a
|
||||||
href="https://maps.google.com/maps?q={{this.location.latitude}},{{this.location.longitude}}"
|
href="https://maps.google.com/maps?q={{this.location.latitude}},{{this.location.longitude}}"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
|
|
|
@ -1078,6 +1078,7 @@ en:
|
||||||
confirm_delete_other_accounts: "Are you sure you want to delete these accounts?"
|
confirm_delete_other_accounts: "Are you sure you want to delete these accounts?"
|
||||||
powered_by: "using <a href='https://maxmind.com'>MaxMindDB</a>"
|
powered_by: "using <a href='https://maxmind.com'>MaxMindDB</a>"
|
||||||
copied: "copied"
|
copied: "copied"
|
||||||
|
no_license: "Configure MaxMind to enable GeoIP information"
|
||||||
|
|
||||||
user_fields:
|
user_fields:
|
||||||
none: "(select an option)"
|
none: "(select an option)"
|
||||||
|
|
|
@ -11,8 +11,10 @@ class DiscourseIpInfo
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_db(path)
|
def open_db(path)
|
||||||
|
unless GlobalSetting.maxmind_license_key.blank?
|
||||||
@loc_mmdb = mmdb_load(File.join(path, "GeoLite2-City.mmdb"))
|
@loc_mmdb = mmdb_load(File.join(path, "GeoLite2-City.mmdb"))
|
||||||
@asn_mmdb = mmdb_load(File.join(path, "GeoLite2-ASN.mmdb"))
|
@asn_mmdb = mmdb_load(File.join(path, "GeoLite2-ASN.mmdb"))
|
||||||
|
end
|
||||||
@cache = LruRedux::ThreadSafeCache.new(2000)
|
@cache = LruRedux::ThreadSafeCache.new(2000)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ class DiscourseIpInfo
|
||||||
message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.",
|
message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
ret[:no_license] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if @asn_mmdb
|
if @asn_mmdb
|
||||||
|
|
|
@ -1153,6 +1153,8 @@ RSpec.describe Report do
|
||||||
freeze_time DateTime.parse("2017-03-01 12:00")
|
freeze_time DateTime.parse("2017-03-01 12:00")
|
||||||
|
|
||||||
ip = [81, 2, 69, 142]
|
ip = [81, 2, 69, 142]
|
||||||
|
# Assign a dummy MaxMind license key, which is now checked in open_db
|
||||||
|
global_setting "maxmind_license_key", "dummy"
|
||||||
|
|
||||||
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
||||||
Resolv::DNS
|
Resolv::DNS
|
||||||
|
|
|
@ -1680,6 +1680,8 @@ RSpec.describe Admin::UsersController do
|
||||||
shared_examples "IP info retrieval possible" do
|
shared_examples "IP info retrieval possible" do
|
||||||
it "retrieves IP info" do
|
it "retrieves IP info" do
|
||||||
ip = "81.2.69.142"
|
ip = "81.2.69.142"
|
||||||
|
# Assign a dummy MaxMind license key, which is now checked in open_db
|
||||||
|
global_setting "maxmind_license_key", "dummy"
|
||||||
|
|
||||||
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
||||||
Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com")
|
Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com")
|
||||||
|
@ -1717,6 +1719,8 @@ RSpec.describe Admin::UsersController do
|
||||||
|
|
||||||
it "prevents retrieval of IP info with a 404 response" do
|
it "prevents retrieval of IP info with a 404 response" do
|
||||||
ip = "81.2.69.142"
|
ip = "81.2.69.142"
|
||||||
|
# Assign a dummy MaxMind license key, which is now checked in open_db
|
||||||
|
global_setting "maxmind_license_key", "dummy"
|
||||||
|
|
||||||
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
|
||||||
Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com")
|
Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com")
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
RSpec.describe UserAuthTokenSerializer do
|
RSpec.describe UserAuthTokenSerializer do
|
||||||
fab!(:user) { Fabricate(:moderator) }
|
fab!(:user) { Fabricate(:moderator) }
|
||||||
let(:token) { UserAuthToken.generate!(user_id: user.id, client_ip: "2a02:ea00::", staff: true) }
|
let(:token) { UserAuthToken.generate!(user_id: user.id, client_ip: "2a02:ea00::", staff: true) }
|
||||||
|
# Assign a dummy MaxMind license key, which is now checked in open_db
|
||||||
|
global_setting "maxmind_license_key", "dummy"
|
||||||
|
|
||||||
before(:each) { DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) }
|
before(:each) { DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user