diff --git a/HOSTING.md b/HOSTING.md index f5106c1c9..2efcf9b87 100644 --- a/HOSTING.md +++ b/HOSTING.md @@ -27,21 +27,37 @@ Total cost: $105/mo Besides the DockerHub registry, one can build docker image from [Dockerfile](./Dockerfile). #### Up and Running -The repo supplies with a [Docker Compose](./docker-compose.yml) file, this serves as a sample for running Plausible with Docker. -In this sample, the db migration is done by default on startup, so you need to clean the data up every time you run: - -First run -```bash -$ docker-compose up -``` - -subsequent runs-- -```bash -$ docker-compose down -$ docker volume rm plausible_db-data -f -$ docker-compose up -``` - +The repo supplies with a [Docker Compose](./docker-compose.yml) file and the sample [environment variables](./plausible-variables.sample.env) , this serves as a sample for running Plausible with Docker. + +- Running the setup takes care of the initial migration steps, this needs to be executed only once, on the first run. + ```bash + docker-compose run --rm setup + docker-compose down + ``` + +- After the setup, you can start plausible as -- + ```bash + docker-compose up -d plausible + ``` + after a successful startup (can take upto 5 mins), `plausible` is available at port `80`, navigate to [`http://localhost`](http://localhost). + +- stopping plausible -- + ```bash + docker-compose down + ``` +- purging and removing everything -- + ```bash + docker-compose down + docker volume rm plausible_event-data -f + docker volume rm plausible_db-data -f + ``` +Note: +- #1 you need to stop plausible and restart plausible if you change the environment variables. +- #2 With docker-compose, you need to remove the existing container and rebuild if you want your changes need to be reflected: + ```bash + docker rmi -f plausible_plausible:latest + docker-compose up -d plausible + ``` ### Non-docker building It is possible to create a release artifact by running a release. @@ -95,6 +111,11 @@ Following are the variables that can be used to configure the availability of th - The current running environment. _defaults to **prod**_ - APP_VERSION (*String*) - The version of the app running. _defaults to current docker tag_ +- DISABLE_AUTH (*Boolean String*) + - Disables authentication completely, no registration, login will be shown. _defaults to `false`_ + - Note: This option is **not recommended** for production deployments. +- DISABLE_REGISTRATION + - Disables registration of new users, keep your admin credentials handy ;) _defaults to `false`_ ### Default User Generation For self-hosting, a default user is generated during the [Database Migration](#Database Migration) to access Plausible. To be noted that, a default user is a user whose trial period expires in 100 Years ;). diff --git a/config/config.exs b/config/config.exs index 6b399ddae..7aab559e8 100644 --- a/config/config.exs +++ b/config/config.exs @@ -8,6 +8,15 @@ config :plausible, ecto_repos: [Plausible.Repo], environment: System.get_env("ENVIRONMENT", "dev") +disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false")) + +config :plausible, :selfhost, + disable_authentication: disable_auth, + disable_registration: + if(disable_auth, + do: true, + else: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false")) + ) config :plausible, :clickhouse, hostname: System.get_env("CLICKHOUSE_DATABASE_HOST", "localhost"), @@ -74,7 +83,7 @@ config :plausible, :paddle, config :plausible, Plausible.Repo, - pool_size: String.to_integer(System.get_env("DATABASE_POOL_SIZE", "10")), + pool_size: String.to_integer(System.get_env("DATABASE_POOLSIZE", "10")), timeout: 300_000, connect_timeout: 300_000, handshake_timeout: 300_000, @@ -144,7 +153,7 @@ case mailer_adapter do ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || true, retries: System.get_env("SMTP_RETRIES") || 2, no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true, - auth: :always + auth: :if_available "Bamboo.LocalAdapter" -> config :plausible, Plausible.Mailer, adapter: :"Elixir.#{mailer_adapter}" diff --git a/config/dev.exs b/config/dev.exs index 5da1a0995..20e866057 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -21,7 +21,9 @@ config :plausible, PlausibleWeb.Endpoint, ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, ~r{priv/gettext/.*(po)$}, ~r{lib/plausible_web/views/.*(ex)$}, - ~r{lib/plausible_web/templates/.*(eex)$} + ~r{lib/plausible_web/templates/.*(eex)$}, + ~r{lib/plausible_web/controllers/.*(ex)$}, + ~r{lib/plausible_web/plugs/.*(ex)$} ] ] diff --git a/config/releases.exs b/config/releases.exs index af4362885..2c571428f 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -14,7 +14,7 @@ secret_key_base = "/NJrhNtbyCVAsTyvtk1ZYCwfm981Vpo/0XrVwjJvemDaKC/vsvBRevLwsc6u8RCg" ) -db_pool_size = String.to_integer(System.get_env("DATABASE_POOL_SIZE", "10")) +db_pool_size = String.to_integer(System.get_env("DATABASE_POOLSIZE", "10")) db_url = System.get_env( @@ -34,7 +34,7 @@ ck_host = System.get_env("CLICKHOUSE_DATABASE_HOST", "localhost") ck_db = System.get_env("CLICKHOUSE_DATABASE_NAME", "plausible_dev") ck_db_user = System.get_env("CLICKHOUSE_DATABASE_USER") ck_db_pwd = System.get_env("CLICKHOUSE_DATABASE_PASSWORD") -ck_db_pool = System.get_env("CLICKHOUSE_DATABASE_POOLSIZE") || 10 +ck_db_pool = String.to_integer(System.get_env("CLICKHOUSE_DATABASE_POOLSIZE", "10")) ### Mandatory params End sentry_dsn = System.get_env("SENTRY_DSN") @@ -52,6 +52,7 @@ 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") +disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false")) config :plausible, admin_user: admin_user, @@ -60,6 +61,14 @@ config :plausible, environment: env, mailer_email: mailer_email +config :plausible, :selfhost, + disable_authentication: disable_auth, + disable_registration: + if(!disable_auth, + do: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false")), + else: false + ) + config :plausible, PlausibleWeb.Endpoint, url: [host: host, scheme: scheme], http: [ diff --git a/docker-compose.yml b/docker-compose.yml index d3e6275cf..4c7c5ef73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,7 @@ services: # As it says, this service is a fake smtp server which accepts SMTP connections # the inbox is available at localhost:8025, in actuality, you need to use a proper smtp server - fakesmtp_server: - container_name: fakesmtp_server + fake_smtp: image: mailhog/mailhog:v1.0.0 ports: - 1025:1025 @@ -17,7 +16,6 @@ services: plausible_db: - container_name: plausible_db image: postgres:12 command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"] volumes: @@ -30,50 +28,44 @@ services: - 5432:5432 plausible_events_db: - container_name: plausible_events_db - image: yandex/clickhouse-server + image: yandex/clickhouse-server:latest volumes: - event-data:/var/lib/clickhouse ports: - 8123:8123 plausible: - container_name: plausible build: context: . dockerfile: ./Dockerfile - command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate &&/entrypoint.sh run" - environment: - - ENVIRONMENT=production - - PORT=8080 - - SECRET_KEY_BASE=iYb1mP5cnmY+gUxo7C/h6XMigossPhzwd8/ic6LFnQ9Y58Fl1xduSWaPq0fHDdbn - - SIGNING_SALT=PL/THF0VMOzuv1bOcldjDzYFBLryvXNs - - HOST=localhost - - DATABASE_URL=postgres://postgres:postgres@plausible_db:5432/plausible - - DATABASE_TLS_ENABLED=false - - ADMIN_USER_NAME=admin - - ADMIN_USER_EMAIL=admin@plausible.local - - ADMIN_USER_PWD=admin@1234! - - APP_VERSION=test - - MAILER_ADAPTER=Bamboo.SMTPAdapter - - SMTP_HOST_ADDR=fakesmtp_server - - SMTP_HOST_PORT=1025 - - SMTP_USER_NAME=fakeuser@plausible.local - - SMTP_USER_PWD=password - - SMTP_HOST_SSL_ENABLED=false - - SMTP_MX_LOOKUPS_ENABLED=false - - CLICKHOUSE_DATABASE_HOST=plausible_events_db - - CLICKHOUSE_DATABASE_NAME=plausible_events_db + command: sh -c "sleep 10 && /entrypoint.sh run" depends_on: - - plausible_events_db - plausible_db - - fakesmtp_server + - plausible_events_db + - fake_smtp ports: - 80:8080 links: - plausible_db - plausible_events_db - - fakesmtp_server + - fake_smtp + env_file: + - plausible-variables.sample.env + + + setup: + build: + context: . + dockerfile: ./Dockerfile + command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate" + depends_on: + - plausible_db + - plausible_events_db + links: + - plausible_db + - plausible_events_db + env_file: + - plausible-variables.sample.env volumes: diff --git a/lib/plausible/application.ex b/lib/plausible/application.ex index 0535fe513..bae4a9751 100644 --- a/lib/plausible/application.ex +++ b/lib/plausible/application.ex @@ -5,6 +5,7 @@ defmodule Plausible.Application do def start(_type, _args) do clickhouse_config = Application.get_env(:plausible, :clickhouse) + children = [ Plausible.Repo, PlausibleWeb.Endpoint, diff --git a/lib/plausible_release.ex b/lib/plausible_release.ex index 3b7964788..da2c9f70b 100644 --- a/lib/plausible_release.ex +++ b/lib/plausible_release.ex @@ -14,17 +14,23 @@ defmodule Plausible.Release do Application.get_env(:plausible, :admin_pwd)} ) - {: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() - - IO.puts("Admin user created successful!") + 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() + + IO.puts("Admin user created successful!") + + _ -> + IO.puts("Admin user already exists. I won't override, bailing") + end end def migrate do diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex index 31b914800..30b8ff5f5 100644 --- a/lib/plausible_web/controllers/api/external_controller.ex +++ b/lib/plausible_web/controllers/api/external_controller.ex @@ -78,16 +78,17 @@ defmodule PlausibleWeb.Api.ExternalController do if forwarded_for do String.split(forwarded_for, ",") |> Enum.map(&String.trim/1) - |> List.first + |> List.first() else to_string(:inet_parse.ntoa(conn.remote_ip)) end end defp visitor_country(conn) do - result = get_ip(conn) - |> Geolix.lookup() - |> Map.get(:country) + result = + get_ip(conn) + |> Geolix.lookup() + |> Map.get(:country) if result && result.country do result.country.iso_code diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 99bf4dda9..6ad16ca56 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -11,12 +11,17 @@ defmodule PlausibleWeb.AuthController do when action in [:user_settings, :save_settings, :delete_me, :password_form, :set_password] def register_form(conn, _params) do - changeset = Plausible.Auth.User.changeset(%Plausible.Auth.User{}) + if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) do + conn + |> redirect(to: "/login") + else + changeset = Plausible.Auth.User.changeset(%Plausible.Auth.User{}) - render(conn, "register_form.html", - changeset: changeset, - layout: {PlausibleWeb.LayoutView, "focus.html"} - ) + render(conn, "register_form.html", + changeset: changeset, + layout: {PlausibleWeb.LayoutView, "focus.html"} + ) + end end def register(conn, %{"user" => params}) do diff --git a/lib/plausible_web/controllers/page_controller.ex b/lib/plausible_web/controllers/page_controller.ex index 7f7167856..e41cb1511 100644 --- a/lib/plausible_web/controllers/page_controller.ex +++ b/lib/plausible_web/controllers/page_controller.ex @@ -1,96 +1,14 @@ defmodule PlausibleWeb.PageController do use PlausibleWeb, :controller use Plausible.Repo - - @demo_referrers [ - {"indiehackers.com", 56}, - {"Github", 23}, - {"Twitter", 17}, - {"Reddit", 8}, - {"Google", 6}, - {"DuckDuckGo", 4}, - {"Bing", 2} - ] - - @demo_pages [ - {"/", 140}, - {"/plausible.io", 63}, - {"/blog", 41}, - {"/register", 13}, - {"/login", 7}, - {"/blog/google-analytics-and-privacy", 4}, - {"/blog/launching-plausible", 2} - ] + plug PlausibleWeb.AutoAuthPlug def index(conn, _params) do if conn.assigns[:current_user] do user = conn.assigns[:current_user] |> Repo.preload(:sites) render(conn, "sites.html", sites: user.sites) else - render(conn, "index.html", - demo_referrers: @demo_referrers, - demo_pages: @demo_pages, - landing_nav: true - ) - end - end - - defmodule Token do - use Joken.Config - end - - defp sign_token!(user) do - claims = %{ - id: user.id, - email: user.email, - name: user.name - } - - signer = Joken.Signer.create("HS256", "4d1d2ae6-4595-4d0b-b98a-8ca5b1f2095a") - {:ok, token, _} = Token.generate_and_sign(claims, signer) - token - end - - def feedback(conn, _params) do - if conn.assigns[:current_user] do - token = sign_token!(conn.assigns[:current_user]) - redirect(conn, external: "https://plausible.nolt.io/sso/#{token}") - else - redirect(conn, external: "https://plausible.nolt.io") - end - end - - def roadmap(conn, _params) do - if conn.assigns[:current_user] do - token = sign_token!(conn.assigns[:current_user]) - - redirect(conn, - external: - "https://plausible.nolt.io/sso/#{token}?returnUrl=https://plausible.nolt.io/roadmap" - ) - else - redirect(conn, external: "https://plausible.nolt.io/roadmap") + render(conn, "index.html" ) end end - - def contact_form(conn, _params) do - render(conn, "contact_form.html") - end - - def submit_contact_form(conn, %{"text" => text, "email" => email}) do - PlausibleWeb.Email.feedback(email, text) |> Plausible.Mailer.send_email() - render(conn, "contact_thanks.html") - end - - def privacy(conn, _params) do - render(conn, "privacy.html") - end - - def data_policy(conn, _params) do - render(conn, "data_policy.html") - end - - def terms(conn, _params) do - render(conn, "terms.html") - end end diff --git a/lib/plausible_web/controllers/tracker_controller.ex b/lib/plausible_web/controllers/tracker_controller.ex index fec800500..50e3349c5 100644 --- a/lib/plausible_web/controllers/tracker_controller.ex +++ b/lib/plausible_web/controllers/tracker_controller.ex @@ -1,9 +1,23 @@ defmodule PlausibleWeb.TrackerController do use PlausibleWeb, :controller require EEx - EEx.function_from_file(:defp, :render_plausible, Application.app_dir(:plausible, "priv/tracker/js/plausible.js"), [:base_url]) - EEx.function_from_file(:defp, :render_p, Application.app_dir(:plausible, "priv/tracker/js/p.js"), [:base_url]) - @max_age 3600 # 1 hour + + EEx.function_from_file( + :defp, + :render_plausible, + Application.app_dir(:plausible, "priv/tracker/js/plausible.js"), + [:base_url] + ) + + EEx.function_from_file( + :defp, + :render_p, + Application.app_dir(:plausible, "priv/tracker/js/p.js"), + [:base_url] + ) + + #  1 hour + @max_age 3600 def plausible(conn, _params) do send_js(conn, render_plausible(base_url())) diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.ex index 657043ead..41b5fbfaf 100644 --- a/lib/plausible_web/email.ex +++ b/lib/plausible_web/email.ex @@ -100,18 +100,6 @@ defmodule PlausibleWeb.Email do |> render("trial_over_email.html", user: user) end - def feedback(from, text) do - from = if from == "", do: "anonymous@plausible.io", else: from - - base_email() - |> to("hello@plausible.io") - |> from("feedback@plausible.io") - |> put_param("ReplyTo", from) - |> tag("feedback") - |> subject("New feedback submission") - |> text_body(text) - end - def weekly_report(email, site, assigns) do base_email() |> to(email) diff --git a/lib/plausible_web/plugs/auto_auth_plug.ex b/lib/plausible_web/plugs/auto_auth_plug.ex new file mode 100644 index 000000000..5de238d5e --- /dev/null +++ b/lib/plausible_web/plugs/auto_auth_plug.ex @@ -0,0 +1,26 @@ +defmodule PlausibleWeb.AutoAuthPlug do + import Plug.Conn + alias PlausibleWeb.AuthController + + def init(options) do + options + end + + def call(conn, _opts) do + cond do + Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> + conn + |> AuthController.login(%{ + "email" => Application.fetch_env!(:plausible, :admin_email), + "password" => Application.fetch_env!(:plausible, :admin_pwd) + }) + |> halt + + true -> + Plug.Conn.put_session(conn, :login_dest, conn.request_path) + |> Phoenix.Controller.redirect(to: "/login") + |> halt + + end + end +end diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index b170f1b45..3080d13dd 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -92,13 +92,6 @@ defmodule PlausibleWeb.Router do get "/auth/google/callback", AuthController, :google_auth_callback get "/", PageController, :index - get "/privacy", PageController, :privacy - get "/terms", PageController, :terms - get "/data-policy", PageController, :data_policy - get "/feedback", PageController, :feedback - get "/roadmap", PageController, :roadmap - get "/contact", PageController, :contact_form - post "/contact", PageController, :submit_contact_form get "/billing/change-plan", BillingController, :change_plan_form get "/billing/change-plan/preview/:plan_id", BillingController, :change_plan_preview diff --git a/lib/plausible_web/templates/auth/login_form.html.eex b/lib/plausible_web/templates/auth/login_form.html.eex index 211fbfcc0..0214fb4fe 100644 --- a/lib/plausible_web/templates/auth/login_form.html.eex +++ b/lib/plausible_web/templates/auth/login_form.html.eex @@ -16,7 +16,9 @@

Forgot password? Click here to reset it.

<%= submit "Login →", class: "button mt-4 w-full" %> -

- Don't have an account? <%= link("Register", to: "/register") %> instead. -

+ <%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost),:disable_registration) do %> +

+ Don't have an account? <%= link("Register", to: "/register") %> instead. +

+ <% end %> <% end %> diff --git a/lib/plausible_web/templates/layout/_footer.html.eex b/lib/plausible_web/templates/layout/_footer.html.eex index 1c14f79ca..7e722e408 100644 --- a/lib/plausible_web/templates/layout/_footer.html.eex +++ b/lib/plausible_web/templates/layout/_footer.html.eex @@ -5,14 +5,13 @@

Made by @ukutaht in London, UK

diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex index 5641bf4c2..c92e392a1 100644 --- a/lib/plausible_web/templates/layout/app.html.eex +++ b/lib/plausible_web/templates/layout/app.html.eex @@ -50,15 +50,31 @@ - <% true -> %> + <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> %> + <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) -> %> + + <% true -> %> + <% end %> diff --git a/lib/plausible_web/templates/page/contact_form.html.eex b/lib/plausible_web/templates/page/contact_form.html.eex deleted file mode 100644 index 3b7d88dd6..000000000 --- a/lib/plausible_web/templates/page/contact_form.html.eex +++ /dev/null @@ -1,16 +0,0 @@ -
- <%= form_for @conn, "/contact", [class: "bg-white shadow-md rounded px-8 py-6 mb-4 mt-16"], fn f -> %> -

Contact us

-

Please get in touch with any questions and thoughts, we'll get back to you as soon as possible!

- <%= textarea f, :text, rows: 4, class: "transition bg-gray-100 appearance-none border border-transparent rounded w-full p-2 text-gray-700 leading-normal appearance-none focus:outline-none focus:bg-white focus:border-gray-300 text-xs mt-4" %> - <%= if @conn.assigns[:current_user] do %> - <%= hidden_input f, :email, value: @conn.assigns[:current_user].email %> - <% else %> -
- <%= label f, :email, "Your email (optional)", class: "block text-gray-700 text-sm font-bold mb-2" %> - <%= email_input f, :email, class: "transition bg-gray-100 appearance-none border border-transparent rounded w-full p-2 text-gray-700 leading-normal appearance-none focus:outline-none focus:bg-white focus:border-gray-300", placeholder: "example@email.com" %> -
- <% end %> - <%= submit "Send", class: "button mt-4 w-full" %> - <% end %> -
diff --git a/lib/plausible_web/templates/page/contact_thanks.html.eex b/lib/plausible_web/templates/page/contact_thanks.html.eex deleted file mode 100644 index 0aabd64d5..000000000 --- a/lib/plausible_web/templates/page/contact_thanks.html.eex +++ /dev/null @@ -1,4 +0,0 @@ -
-

Message submitted!

-
Thank you for getting in touch.
-
diff --git a/lib/plausible_web/templates/page/data_policy.html.eex b/lib/plausible_web/templates/page/data_policy.html.eex deleted file mode 100644 index 35ce52c39..000000000 --- a/lib/plausible_web/templates/page/data_policy.html.eex +++ /dev/null @@ -1,39 +0,0 @@ -
- -

Data policy

- -
-Plausible aims to track overall trends in your website traffic, not individual visitors. With privacy in mind, we don’t collect or store any data beyond what is absolutely necessary. Here is a list of what we collect and store about your website visitors. -
- -
-

User-Agent

- We use the User-Agent header to figure out what browsers and operating systems your visitors are using. -
- -
-

Referer

- Plausible uses the referrer string to show which other websites are driving traffic to the site you’re tracking. -
- -
-

Page URLs

- We track the pathname of each pageview to be able to show the Top Pages report. -
- -
-

Window inner width

- We use window.innerWidth to determine the actual size of the open browser window, rather than the full width of the device. This is more accurate and makes fingerprinting harder. -
- -
-

We don’t store IP addresses

- We never store IP addresses in our database or logs. The IP address is used to look up the visitor country, which we store to show the Top Countries report. The IP address is discarded. -
- -
-

Cookie policy

- Plausible installs a first-party cookie to be able to differentiate between a new visitor and a returning visitor. This cookie contains a random identifier that is sent along with each pageview request. On the backend, this allows us to aggregate and show unique visitors and total pageviews separately. -
- <%= link("Back to homepage", to: "/", class: "text-indigo-500") %> -
diff --git a/lib/plausible_web/templates/page/index.html.eex b/lib/plausible_web/templates/page/index.html.eex index 9aeddba81..82eab4336 100644 --- a/lib/plausible_web/templates/page/index.html.eex +++ b/lib/plausible_web/templates/page/index.html.eex @@ -1,695 +1,3 @@ -
- - -
-
-
-

- Simple and privacy-friendly -
- alternative to Google Analytics -

-

- Plausible is a lightweight and open-source website analytics tool. It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR. -

- -
-
-
-
- -
-
- <%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/screenshot.png")) %> -
-
- -
-
-
-
-

- Why use Plausible? -

-

- Plausible is built for privacy-conscious website owners. Here’s what makes it a great Google Analytics alternative -

-
- -
-
    -
  • -
    -
    -
    - - - -
    -
    -
    -

    Check website traffic and site analytics in 1 minute

    -

    - Plausible is simple and it cuts through the noise. No layers of menus, no need - for custom reports. Get all the important insights on one single page. No training necessary. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    Lightweight script which keeps your site speed fast

    -

    - Plausible script is 14 times smaller than Google Analytics script. You will reduce your page weight and your site will load faster. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - - -
    -
    -
    -

    Doesn’t track nor collect any personal data

    -

    - Plausible respects the privacy of your visitors. Your traffic data is not used for any other purposes. You fully own and control it. See our data policy for details. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    No cookie banners or GDPR/CCPA consent needed

    -

    - Plausible does not use cookies and is fully compliant with GDPR, CCPA, PECR and other privacy regulations out of the box. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    Define key goals and track conversions

    -

    - Set custom events or page URLs as your goals and see how they convert over time to understand and identify the trends that matter. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    Get weekly or monthly reports directly into your inbox

    -

    - Keep an eye on your traffic with automated email reports. Email reports can be scheduled to be sent to multiple recipients. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    Open your web analytics to everyone

    -

    - Your stats are private by default but you can choose to be transparent and make them public so anyone with your custom link can view them. -

    -
    -
    -
  • - -
  • -
    -
    -
    - - - -
    -
    -
    -

    Share the stats privately with your clients

    -

    - You can share your stats privately by generating a shared link. This link is impossible to guess but - you can add password protection for extra security. -

    -
    -
    -
  • - -
-
-
-
- -
-
- - -
-
-

- Simple analytics at a glance -

-

- Google Analytics is overkill for most site owners. Plausible is easy to use and understand with no training or prior experience. -

- -
    -
  • -
    -
    -
    - - - -
    -
    -
    -

    Unique visitors, total page views and the bounce rate

    -

    - Choose the time range that you want to analyze. The visitor numbers are automatically presented on an hourly, daily or monthly graph. -

    -
    -
    -
  • -
  • -
    -
    -
    - - - -
    -
    -
    -

    Top referral sources and most visited pages

    -

    - Answer the most important question about your website – where are your visitors coming from and what are they viewing? -

    -
    -
    -
  • -
  • -
    -
    -
    - - - - -
    -
    -
    -

    Visitor location and device stats

    -

    - See the list of countries your traffic is coming from. See the device, browser and operating system your visitors are using. All the basics in a completely anonymous way. -

    -
    -
    -
  • -
-
- -
- - - - - - - - - <%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/screenshot-countries.png"), class: "relative mx-auto shadow-xl", alt: "Screenshot of referrers") %> -
-
-
-
- -
-
-
-
-
- Wordpress -
-
- <%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/ghost.svg"), class: "max-h-12", alt: "Ghost") %> -
-
- Wix -
-
- Wix -
-
- Weebly -
-
- Google Search Console -
-
-
-

- Integrates seamlessly with your favourite tools -

-

- Plausible is simple to set up and integrate with popular tools such as WordPress, Ghost, Squarespace, Wix, Weebly and Google Search Console. -

-
-
-
-
- -
-
- - - - - - - - - -
-
-
-

- “Plausible is focused on exactly what I need: clear insights into my site visitors, without getting in my way. -

-
- -
-
-
-
- -
-
-
-
-

- Pricing -

-

- Simple, traffic-based pricing -

-

- Sign up for 30-day unlimited trial. No credit card required. -

-
-
-
-
-
-
-
-
-
-
-
- - Personal - -
-
- $6 - - /mo - -
-
-
-
    -
  • -
    - - - -
    -

    - Up to 10k pageviews per month -

    -
  • -
  • -
    - - - -
    -

    - Unlimited websites -

    -
  • -
  • -
    - - - -
    -

    - 100% Data ownership -

    -
  • -
  • -
    - - - -
    -

    - Email support -

    -
  • -
- -
-
-
-
-
- - Startup - -
-
- $12 - - /mo - -
-
-
-
    -
  • -
    - - - -
    -

    - Up to 100k pageviews per month -

    -
  • -
  • -
    - - - -
    -

    - Unlimited websites -

    -
  • -
  • -
    - - - -
    -

    - 100% data ownership -

    -
  • -
  • -
    - - - -
    -

    - Priority support -

    -
  • -
- -
-
-
-
-
- - Business - -
-
- $36 - - /mo - -
-
-
-
    -
  • -
    - - - -
    -

    - Up to 1m pageviews per month -

    -
  • -
  • -
    - - - -
    -

    - Unlimited websites -

    -
  • -
  • -
    - - - -
    -

    - 100% data ownership -

    -
  • -
  • -
    - - - -
    -

    - Priority support -

    -
  • -
- -
-
-
-
-
-
-
- -
-
-

- Frequently asked questions -

-
-
-
-
-

- 1. Can I use Plausible on more than one website? -

-
-

- Yes. You can add as many websites as you want under a single account. You will be charged for the total pageviews on all of your websites combined. For example, on the 10k plan you can either have 10 websites that each get 1000 pageviews per month, or one website that gets 10,000 pageviews per month. -

-
-
-
-

- 2. What happens if I go over my plan limit? -

-
-

- You don't have to pay for a one-time spike in traffic, but if you go over your plan limit for 2 months in a row, we will contact you to discuss upgrade options. -

-
-
-
-

- 3. Is Plausible open-source? -

-
-

- Plausible is fully open-source and available <%= link("on Github", to: "https://github.com/plausible-insights/plausible", class: "text-indigo-600") %> so you can check out the code. We welcome feedback, have a public roadmap and are available to you via email. -

-
-
-
-
-
-

- 4. Why is Plausible not free like Google Analytics? -

-
-

- Google Analytics is free because Google has built their company and their wealth by collecting and analyzing huge amounts of personal information from web users and using these personal and behavioral insights to sell advertisements.

- - With Plausible, you 100% own and control all of your website data. This data is not being shared with or sold to any third-parties. Since we don't make money from targeted advertisement, we must ask for a small fee to keep the servers running. -

-
-
-
-

- 5. How do you make sure my visitors' privacy is protected? -

-
-

- We take painstaking care to not collect or store any personal information that could be tied back to the visitor. You own your data and we will never sell it or use it in nefarious ways. <%= link("Read more about our data policy", to: "/data-policy", class: "text-indigo-600") %>. -

-
-
-
-
-
-
-
- -
-
-

- Ready to dive in? -
- Start your free trial today. -

- -
+
+ You will be redirected... If it doesn't work, please click login.
diff --git a/lib/plausible_web/templates/page/privacy.html.eex b/lib/plausible_web/templates/page/privacy.html.eex deleted file mode 100644 index 31db64ae2..000000000 --- a/lib/plausible_web/templates/page/privacy.html.eex +++ /dev/null @@ -1,11 +0,0 @@ -
-

Privacy Policy

-

Your privacy is important to us. It is Plausible Analytics' policy to respect your privacy regarding any information we may collect from you across our website, <%= link(plausible_url(), to: plausible_url()) %>, and other sites we own and operate.

-

We only ask for personal information when we truly need it to provide a service to you. We collect it by fair and lawful means, with your knowledge and consent. We also let you know why we’re collecting it and how it will be used.

-

We only retain collected information for as long as necessary to provide you with your requested service. What data we store, we’ll protect within commercially acceptable means to prevent loss and theft, as well as unauthorised access, disclosure, copying, use or modification.

-

We don’t share any personally identifying information publicly or with third-parties, except when required to by law.

-

Our website may link to external sites that are not operated by us. Please be aware that we have no control over the content and practices of these sites, and cannot accept responsibility or liability for their respective privacy policies.

-

You are free to refuse our request for your personal information, with the understanding that we may be unable to provide you with some of your desired services.

-

Your continued use of our website will be regarded as acceptance of our practices around privacy and personal information. If you have any questions about how we handle user data and personal information, feel free to contact us.

-

This policy is effective as of 25 January 2019.

-
diff --git a/lib/plausible_web/templates/page/sites.html.eex b/lib/plausible_web/templates/page/sites.html.eex deleted file mode 100644 index 786a1870b..000000000 --- a/lib/plausible_web/templates/page/sites.html.eex +++ /dev/null @@ -1,22 +0,0 @@ -
-
-

My websites

- + Add a website -
-
-
- <%= for site <- @sites do %> -
- -

<%= site.domain %>

-
- <%= link(to: "/#{URI.encode_www_form(site.domain)}/settings", class: "flex absolute hover:bg-gray-100 transition rounded py-2 px-5", style: "top: 12px; right: 6px;") do %> -
- -
-

Settings

- <% end %> -
- <% end %> -
-
diff --git a/lib/plausible_web/templates/page/terms.html.eex b/lib/plausible_web/templates/page/terms.html.eex deleted file mode 100644 index 448957e2a..000000000 --- a/lib/plausible_web/templates/page/terms.html.eex +++ /dev/null @@ -1,33 +0,0 @@ -
-

Terms of Service

-

1. Terms

-

By accessing the website at <%= link(plausible_url(), to: plausible_url()) %>, you are agreeing to be bound by these terms of service, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this website are protected by applicable copyright and trademark law.

-

2. Use License

-
    -
  1. Permission is granted to temporarily download one copy of the materials (information or software) on Plausible Insights' website for personal, non-commercial transitory viewing only. This is the grant of a license, not a transfer of title, and under this license you may not: -
      -
    1. modify or copy the materials;
    2. -
    3. use the materials for any commercial purpose, or for any public display (commercial or non-commercial);
    4. -
    5. attempt to decompile or reverse engineer any software contained on Plausible Insights' website;
    6. -
    7. remove any copyright or other proprietary notations from the materials; or
    8. -
    9. transfer the materials to another person or "mirror" the materials on any other server.
    10. -
    -
  2. -
  3. This license shall automatically terminate if you violate any of these restrictions and may be terminated by Plausible Insights at any time. Upon terminating your viewing of these materials or upon the termination of this license, you must destroy any downloaded materials in your possession whether in electronic or printed format.
  4. -
-

3. Disclaimer

-
    -
  1. The materials on Plausible Insights' website are provided on an 'as is' basis. Plausible Insights makes no warranties, expressed or implied, and hereby disclaims and negates all other warranties including, without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights.
  2. -
  3. Further, Plausible Insights does not warrant or make any representations concerning the accuracy, likely results, or reliability of the use of the materials on its website or otherwise relating to such materials or on any sites linked to this site.
  4. -
-

4. Limitations

-

In no event shall Plausible Insights or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption) arising out of the use or inability to use the materials on Plausible Insights' website, even if Plausible Insights or a Plausible Insights authorized representative has been notified orally or in writing of the possibility of such damage. Because some jurisdictions do not allow limitations on implied warranties, or limitations of liability for consequential or incidental damages, these limitations may not apply to you.

-

5. Accuracy of materials

-

The materials appearing on Plausible Insights' website could include technical, typographical, or photographic errors. Plausible Insights does not warrant that any of the materials on its website are accurate, complete or current. Plausible Insights may make changes to the materials contained on its website at any time without notice. However Plausible Insights does not make any commitment to update the materials.

-

6. Links

-

Plausible Insights has not reviewed all of the sites linked to its website and is not responsible for the contents of any such linked site. The inclusion of any link does not imply endorsement by Plausible Insights of the site. Use of any such linked website is at the user's own risk.

-

7. Modifications

-

Plausible Insights may revise these terms of service for its website at any time without notice. By using this website you are agreeing to be bound by the then current version of these terms of service.

-

8. Governing Law

-

These terms and conditions are governed by and construed in accordance with the laws of Estonia and you irrevocably submit to the exclusive jurisdiction of the courts in that State or location.

-
diff --git a/mix.exs b/mix.exs index 8e7c03aa9..69f19f77b 100644 --- a/mix.exs +++ b/mix.exs @@ -81,7 +81,6 @@ defmodule Plausible.MixProject do {:excoveralls, "~> 0.10", only: :test}, {:double, "~> 0.7.0", only: :test}, {:junit_formatter, "~> 3.1", only: [:test]}, - {:joken, "~> 2.0"}, {:php_serializer, "~> 0.9.0"}, {:csv, "~> 2.3"}, {:oauther, "~> 1.1"}, diff --git a/plausible-variables.sample.env b/plausible-variables.sample.env new file mode 100644 index 000000000..eb06acb9c --- /dev/null +++ b/plausible-variables.sample.env @@ -0,0 +1,22 @@ +ENVIRONMENT=production +PORT=8080 +SECRET_KEY_BASE=iYb1mP5cnmY+gUxo7C/h6XMigossPhzwd8/ic6LFnQ9Y58Fl1xduSWaPq0fHDdbn +SIGNING_SALT=PL/THF0VMOzuv1bOcldjDzYFBLryvXNs +HOST=localhost +DATABASE_URL=postgres://postgres:postgres@plausible_db:5432/plausible +DATABASE_TLS_ENABLED=false +ADMIN_USER_NAME=admin +ADMIN_USER_EMAIL=admin@plausible.local +ADMIN_USER_PWD=admin@1234! +APP_VERSION=test +MAILER_ADAPTER=Bamboo.SMTPAdapter +SMTP_HOST_ADDR=fakesmtp_server +SMTP_HOST_PORT=1025 +SMTP_USER_NAME=fakeuser@plausible.local +SMTP_USER_PWD=password +SMTP_HOST_SSL_ENABLED=false +SMTP_MX_LOOKUPS_ENABLED=false +CLICKHOUSE_DATABASE_HOST=plausible_events_db +CLICKHOUSE_DATABASE_NAME=plausible_events_db +DISABLE_AUTH=false +DISABLE_REGISTRATION=false \ No newline at end of file diff --git a/test/plausible_web/controllers/admin_auth_controller_test.exs b/test/plausible_web/controllers/admin_auth_controller_test.exs new file mode 100644 index 000000000..328991604 --- /dev/null +++ b/test/plausible_web/controllers/admin_auth_controller_test.exs @@ -0,0 +1,49 @@ +defmodule PlausibleWeb.AdminAuthControllerTest do + use PlausibleWeb.ConnCase + + describe "GET /" do + test "no landing page", %{conn: conn} do + set_config(disable_authentication: false) + conn = get(conn, "/") + assert redirected_to(conn) == "/login" + end + + test "disable authentication", %{conn: conn} do + set_config(disable_authentication: true) + + admin_user = + Plausible.Auth.find_user_by(email: Application.get_env(:plausible, :admin_email)) + + # goto landing page + conn = get(conn, "/") + assert get_session(conn, :current_user_id) == admin_user.id + assert redirected_to(conn) == "/sites" + + # trying logging out + conn = post(conn, "/logout") + assert redirected_to(conn) == "/" + conn = get(conn, "/") + assert redirected_to(conn) == "/sites" + end + + test "disable registration", %{conn: conn} do + set_config(disable_registration: true) + conn = get(conn, "/register") + assert redirected_to(conn) == "/login" + end + end + + def set_config(config) do + updated_config = + Keyword.merge( + [disable_authentication: false, disable_registration: false], + config + ) + + Application.put_env( + :plausible, + :selfhost, + updated_config + ) + end +end diff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exs index 8d3e25c85..8f7a705ed 100644 --- a/test/plausible_web/controllers/api/external_controller_test.exs +++ b/test/plausible_web/controllers/api/external_controller_test.exs @@ -399,7 +399,6 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do assert pageview["country_code"] == "US" end - test "responds 400 when required fields are missing", %{conn: conn} do params = %{} diff --git a/test/plausible_web/controllers/page_controller_test.exs b/test/plausible_web/controllers/page_controller_test.exs deleted file mode 100644 index 9018d3003..000000000 --- a/test/plausible_web/controllers/page_controller_test.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule PlausibleWeb.PageControllerTest do - use PlausibleWeb.ConnCase - - describe "GET /" do - test "shows the landing page", %{conn: conn} do - conn = get(conn, "/") - assert html_response(conn, 200) =~ "Plausible" - end - end -end diff --git a/test/support/clickhouse_setup.ex b/test/support/clickhouse_setup.ex index d15dfd0a0..6a1658fa3 100644 --- a/test/support/clickhouse_setup.ex +++ b/test/support/clickhouse_setup.ex @@ -237,7 +237,7 @@ defmodule Plausible.Test.ClickhouseSetup do referrer: "", is_bounce: false, start: ~N[2019-01-01 03:00:00] - }, + } ]) end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 3b76c7e3e..ed3e31974 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,6 +1,7 @@ {:ok, _} = Application.ensure_all_started(:ex_machina) ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter]) Plausible.Test.ClickhouseSetup.run() +Plausible.Release.init_admin() ExUnit.start() Application.ensure_all_started(:double) Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, :manual)