diff --git a/.env.dev b/.env.dev index 48ab1190f..f5aca325e 100644 --- a/.env.dev +++ b/.env.dev @@ -6,3 +6,4 @@ DISABLE_SUBSCRIPTION=false ENVIRONMENT=dev MAILER_ADAPTER=Bamboo.LocalAdapter LOG_LEVEL=debug +SELFHOST=false diff --git a/.env.test b/.env.test index 34ac1fd95..a82cb188d 100644 --- a/.env.test +++ b/.env.test @@ -1,10 +1,11 @@ DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_test CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_test SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg +BASE_URL=http://localhost:8000 CRON_ENABLED=false LOG_LEVEL=warn ENVIRONMENT=test MAILER_ADAPTER=Bamboo.TestAdapter -DISABLE_SUBSCRIPTION=false ADMIN_USER_EMAIL=admin@email.com ADMIN_USER_PWD=fakepassword +SELFHOST=false diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cfd87fa1..c51434624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. -## [1.1.2] - Unreleased +## [1.2] - Unreleased ### Added - Ability to add event metadata plausible/analytics#381 @@ -25,6 +25,8 @@ All notable changes to this project will be documented in this file. - Improve onboarding UX and design plausible/analytics#441 - Allows outbound link tracking script to use new tab redirection plausible/analytics#494 - "This Month" view is now Month-to-date for the current month plausible/analytics#491 +- Background jobs are enabled by default for self-hosted installations plausible/analytics#603 +- All new users on self-hosted installations have a never-ending trial plausible/analytics#603 ### Fixed - Do not error when activating an already activated account plausible/analytics#370 diff --git a/assets/css/app.css b/assets/css/app.css index 7d0dc308d..1dbb7101e 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -283,3 +283,7 @@ blockquote { .dark .fullwidth-shadow::before { box-shadow: 0 4px 2px -2px rgba(200, 200, 200, 0.1); } + +iframe[hidden] { + display: none; +} diff --git a/config/runtime.exs b/config/runtime.exs index 927c9ddfa..c4f3243f9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -6,11 +6,21 @@ end port = System.get_env("PORT") || 8000 -base_url = - System.get_env("BASE_URL", "http://localhost:8000") - |> URI.parse() +base_url = System.get_env("BASE_URL") -secret_key_base = System.get_env("SECRET_KEY_BASE") +if !base_url do + raise "BASE_URL configuration option is required. See https://plausible.io/docs/self-hosting-configuration#server" +end + +base_url = URI.parse(base_url) + +if base_url.scheme not in ["http", "https"] do + raise "BASE_URL must start with `http` or `https`. Currently configured as `#{ + System.get_env("BASE_URL") + }`" +end + +secret_key_base = System.fetch_env!("SECRET_KEY_BASE") db_url = System.get_env( @@ -48,10 +58,12 @@ 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") 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") hcaptcha_secret = System.get_env("HCAPTCHA_SECRET") log_level = String.to_existing_atom(System.get_env("LOG_LEVEL", "warn")) appsignal_api_key = System.get_env("APPSIGNAL_API_KEY") +is_selfhost = String.to_existing_atom(System.get_env("SELFHOST", "true")) {user_agent_cache_limit, ""} = Integer.parse(System.get_env("USER_AGENT_CACHE_LIMIT", "1000")) @@ -64,16 +76,12 @@ config :plausible, admin_pwd: admin_pwd, environment: env, mailer_email: mailer_email, - admin_emails: admin_emails + admin_emails: admin_emails, + is_selfhost: is_selfhost config :plausible, :selfhost, disable_authentication: disable_auth, - disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "true")), - disable_registration: - if(!disable_auth, - do: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false")), - else: false - ) + disable_registration: if(!disable_auth, do: disable_registration, else: false) config :plausible, PlausibleWeb.Endpoint, url: [host: base_url.host, scheme: base_url.scheme, port: base_url.port], @@ -146,49 +154,56 @@ config :plausible, :custom_domain_server, config :plausible, PlausibleWeb.Firewall, blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1) -if config_env() !== :test do +if config_env() == :prod do base_cron = [ # Daily at midnight - {"0 0 * * *", Plausible.Workers.RotateSalts} - ] - - extra_cron = [ - # hourly - {"0 * * * *", Plausible.Workers.SendSiteSetupEmails}, + {"0 0 * * *", Plausible.Workers.RotateSalts}, # hourly {"0 * * * *", Plausible.Workers.ScheduleEmailReports}, + # hourly + {"0 * * * *", Plausible.Workers.SendSiteSetupEmails}, # Daily at midnight {"0 0 * * *", Plausible.Workers.FetchTweets}, # Daily at midday - {"0 12 * * *", Plausible.Workers.SendTrialNotifications}, - # Daily at midday {"0 12 * * *", Plausible.Workers.SendCheckStatsEmails}, - # Every 10 minutes - {"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates}, # Every 15 minutes {"*/15 * * * *", Plausible.Workers.SpikeNotifier}, # Every day at midnight {"0 0 * * *", Plausible.Workers.CleanEmailVerificationCodes} ] - base_queues = [rotate_salts: 1] + extra_cron = [ + # Daily at midday + {"0 12 * * *", Plausible.Workers.SendTrialNotifications}, + # Every 10 minutes + {"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates} + ] - extra_queues = [ - provision_ssl_certificates: 1, - fetch_tweets: 1, - check_stats_emails: 1, - site_setup_emails: 1, - trial_notification_emails: 1, + base_queues = [ + rotate_salts: 1, schedule_email_reports: 1, send_email_reports: 1, spike_notifications: 1, - clean_email_verification_codes: 1 + fetch_tweets: 1, + clean_email_verification_codes: 1, + check_stats_emails: 1, + site_setup_emails: 1 + ] + + extra_queues = [ + provision_ssl_certificates: 1, + trial_notification_emails: 1 ] config :plausible, Oban, repo: Plausible.Repo, - queues: if(cron_enabled, do: base_queues ++ extra_queues, else: base_queues), - crontab: if(cron_enabled, do: base_cron ++ extra_cron, else: base_cron) + queues: if(is_selfhost, do: base_queues, else: base_queues ++ extra_queues), + crontab: if(is_selfhost, do: base_cron, else: base_cron ++ extra_cron) +else + config :plausible, Oban, + repo: Plausible.Repo, + queues: false, + crontab: false end config :plausible, :hcaptcha, diff --git a/config/test.exs b/config/test.exs index 2c493ead9..3d3b6d9a7 100644 --- a/config/test.exs +++ b/config/test.exs @@ -29,8 +29,3 @@ config :geolix, config :plausible, session_timeout: 0 - -config :plausible, Oban, - repo: Plausible.Repo, - queues: false, - crontab: false diff --git a/lib/plausible/auth/auth.ex b/lib/plausible/auth/auth.ex index 6475cbda4..ecd4f5357 100644 --- a/lib/plausible/auth/auth.ex +++ b/lib/plausible/auth/auth.ex @@ -58,9 +58,9 @@ defmodule Plausible.Auth do end end - def create_user(name, email) do + def create_user(name, email, pwd) do %Auth.User{} - |> Auth.User.new(%{name: name, email: email}) + |> Auth.User.new(%{name: name, email: email, password: pwd, password_confirmation: pwd}) |> Repo.insert() end diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.ex index 6460395e3..12740b15c 100644 --- a/lib/plausible/auth/user.ex +++ b/lib/plausible/auth/user.ex @@ -35,7 +35,7 @@ defmodule Plausible.Auth.User do |> validate_length(:password, min: 6, message: "has to be at least 6 characters") |> validate_confirmation(:password) |> hash_password() - |> change(trial_expiry_date: Timex.today() |> Timex.shift(days: 30)) + |> change(trial_expiry_date: trial_expiry()) |> unique_constraint(:email) end @@ -62,4 +62,12 @@ defmodule Plausible.Auth.User do end def hash_password(changeset), do: changeset + + defp trial_expiry() do + if Application.get_env(:plausible, :is_selfhost) do + Timex.today() |> Timex.shift(years: 100) + else + Timex.today() |> Timex.shift(days: 30) + end + end end diff --git a/lib/plausible_release.ex b/lib/plausible_release.ex index 6d1a66690..69fde22d4 100644 --- a/lib/plausible_release.ex +++ b/lib/plausible_release.ex @@ -19,16 +19,7 @@ defmodule Plausible.Release do case Plausible.Auth.find_user_by(email: admin_email) do nil -> - {:ok, admin} = Plausible.Auth.create_user(admin_user, admin_email) - # set the password - {:ok, admin} = Plausible.Auth.User.set_password(admin, admin_pwd) |> Repo.update() - # bump-up the trail period - admin - |> Ecto.Changeset.cast(%{trial_expiry_date: Timex.today() |> Timex.shift(years: 100)}, [ - :trial_expiry_date - ]) - |> Repo.update() - + {:ok, _} = Plausible.Auth.create_user(admin_user, admin_email, admin_pwd) IO.puts("Admin user created successful!") _ -> diff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eex index 08ae26a08..5d04a2fdf 100644 --- a/lib/plausible_web/templates/auth/user_settings.html.eex +++ b/lib/plausible_web/templates/auth/user_settings.html.eex @@ -1,4 +1,4 @@ -<%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_subscription) do %> +<%= if !Application.get_env(:plausible, :is_selfhost) do %>
- Made and hosted in the EU 🇪🇺
+ <%= if !Application.get_env(:plausible, :is_selfhost) do %>
+ Made and hosted in the EU 🇪🇺
+ <% end %>
100% self-funded and independent
- Built by @ukutaht and @markosaric
+ Built by @ukutaht and @markosaric
- NB: Your Google account does not have access to your currently configured property, <%= @site.google_auth.property %>. Please select a verified property from the list below. -
- <% else %> -- Select the Google Search Console property you would like to pull keyword data from. If you don't see your domain, <%= link("set it up and verify", to: "https://docs.plausible.io/google-search-console-integration", class: "text-indigo-500") %> on Search Console first. -
- <% end %> + <%= case @search_console_domains do %> + <% {:ok, domains} -> %> + <%= if @site.google_auth.property && !(@site.google_auth.property in domains) do %> ++ NB: Your Google account does not have access to your currently configured property, <%= @site.google_auth.property %>. Please select a verified property from the list below. +
+ <% else %> ++ Select the Google Search Console property you would like to pull keyword data from. If you don't see your domain, <%= link("set it up and verify", to: "https://docs.plausible.io/google-search-console-integration", class: "text-indigo-500") %> on Search Console first. +
+ <% end %> - <%= form_for Plausible.Site.GoogleAuth.changeset(@site.google_auth), "/#{URI.encode_www_form(@site.domain)}/settings/google", [class: "max-w-xs"], fn f -> %> -The following error happened when fetching your Google Search Console domains.
<%= error %>
- <% end %> - <% else %> - <%= button("Continue with Google", to: Plausible.Google.Api.authorize_url(@site.id), class: "button mt-8") %> - -