Skip to content

Commit

Permalink
Use DBIP database for countries
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht committed Apr 2, 2021
1 parent 86f0983 commit 60c688f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion assets/js/dashboard/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ if (container) {
hasGoals: container.dataset.hasGoals === 'true',
insertedAt: container.dataset.insertedAt,
embedded: container.dataset.embedded,
background: container.dataset.background
background: container.dataset.background,
selfhosted: container.dataset.selfhosted === 'true'
}

const loggedIn = container.dataset.loggedIn === 'true'
Expand Down
11 changes: 10 additions & 1 deletion assets/js/dashboard/stats/countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,22 @@ class Countries extends React.Component {
});
}

geolocationDbNotice() {
if (this.props.site.selfhosted) {
return (
<span className="text-xs text-gray-500 absolute bottom-4 right-3">IP Geolocation by <a target="_blank" href="https://db-ip.com" className="text-indigo-600">DB-IP</a></span>
)
}
}

renderBody() {
if (this.state.countries) {
return (
<React.Fragment>
<h3 className="font-bold dark:text-gray-100">Countries</h3>
<div className="mx-auto mt-6" style={{width: '100%', maxWidth: '475px', height: '320px'}} id="map-container"></div>
<div className="mx-auto mt-6" style={{width: '100%', maxWidth: '475px', height: '335px'}} id="map-container"></div>
<MoreLink site={this.props.site} list={this.state.countries} endpoint="countries" />
{ this.geolocationDbNotice() }
</React.Fragment>
)
}
Expand Down
2 changes: 1 addition & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false"))
custom_domain_server_ip = System.get_env("CUSTOM_DOMAIN_SERVER_IP")
custom_domain_server_user = System.get_env("CUSTOM_DOMAIN_SERVER_USER")
custom_domain_server_password = System.get_env("CUSTOM_DOMAIN_SERVER_PASSWORD")
geolite2_country_db = System.get_env("GEOLITE2_COUNTRY_DB")
geolite2_country_db = System.get_env("GEOLITE2_COUNTRY_DB", "priv/dbip-country-lite-2021-04.mmdb")
disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false"))
disable_registration = String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false"))
hcaptcha_sitekey = System.get_env("HCAPTCHA_SITEKEY")
Expand Down
9 changes: 0 additions & 9 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,5 @@ config :plausible,
paddle_api: Plausible.PaddleApi.Mock,
google_api: Plausible.Google.Api.Mock

config :geolix,
databases: [
%{
id: :country,
adapter: Geolix.Adapter.Fake,
data: %{{1, 1, 1, 1} => %{country: %{iso_code: "US"}}}
}
]

config :plausible,
session_timeout: 0
2 changes: 1 addition & 1 deletion lib/plausible_web/templates/stats/stats.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<% end %>
<div class="pt-6"></div>
<div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>"></div>
<div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>" data-selfhosted="<%= Application.get_env(:plausible, :is_selfhost) %>"></div>
<div id="modal_root"></div>
<%= if !@conn.assigns[:current_user] && @conn.assigns[:demo] do %>
<div class="bg-gray-50 dark:bg-gray-850">
Expand Down
Binary file added priv/dbip-country-lite-2021-04.mmdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
assert event.referrer == ""
end

# Fake data is set up in config/test.exs
test "looks up the country from the ip address", %{conn: conn} do
params = %{
name: "pageview",
Expand All @@ -464,12 +463,12 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do

conn
|> put_req_header("content-type", "text/plain")
|> put_req_header("x-forwarded-for", "1.1.1.1")
|> put_req_header("x-forwarded-for", "78.76.58.149")
|> post("/api/event", Jason.encode!(params))

pageview = get_event("external-controller-test-20.com")

assert pageview.country_code == "US"
assert pageview.country_code == "SE"
end

test "URL is decoded", %{conn: conn} do
Expand Down

0 comments on commit 60c688f

Please sign in to comment.