Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ config :plausible, PlausibleWeb.Endpoint,
view: PlausibleWeb.ErrorView,
accepts: ~w(html json)
],
pubsub: [name: Plausible.PubSub, adapter: Phoenix.PubSub.PG2],
session_extra: System.get_env("SESSION_EXTRA", "SameSite=Lax")
pubsub: [name: Plausible.PubSub, adapter: Phoenix.PubSub.PG2]

config :sentry,
dsn: System.get_env("SENTRY_DSN"),
Expand Down
9 changes: 0 additions & 9 deletions lib/plausible/site/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Plausible.Site do
field :domain, :string
field :timezone, :string
field :public, :boolean
field :embeddable, :boolean

many_to_many :members, User, join_through: Plausible.Site.Membership
has_one :google_auth, GoogleAuth
Expand Down Expand Up @@ -36,14 +35,6 @@ defmodule Plausible.Site do
change(site, public: false)
end

def make_embeddable(site) do
change(site, embeddable: true)
end

def make_not_embeddable(site) do
change(site, embeddable: false)
end

defp clean_domain(changeset) do
clean_domain =
(get_field(changeset, :domain) || "")
Expand Down
22 changes: 0 additions & 22 deletions lib/plausible_web/controllers/site_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,6 @@ defmodule PlausibleWeb.SiteController do
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
end

def make_embeddable(conn, %{"website" => website}) do
site =
Sites.get_for_user!(conn.assigns[:current_user].id, website)
|> Plausible.Site.make_embeddable()
|> Repo.update!()

conn
|> put_flash(:success, "Stats for #{site.domain} are now embeddable.")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
end

def make_not_embeddable(conn, %{"website" => website}) do
site =
Sites.get_for_user!(conn.assigns[:current_user].id, website)
|> Plausible.Site.make_not_embeddable()
|> Repo.update!()

conn
|> put_flash(:success, "Stats for #{site.domain} are now not embeddable.")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
end

def enable_weekly_report(conn, %{"website" => website}) do
site = Sites.get_for_user!(conn.assigns[:current_user].id, website)

Expand Down
25 changes: 12 additions & 13 deletions lib/plausible_web/controllers/stats_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule PlausibleWeb.StatsController do

plug PlausibleWeb.AuthorizeStatsPlug when action in [:stats, :csv_export]
plug PlausibleWeb.UpgradeBillingPlug when action in [:stats]
plug PlausibleWeb.EmbeddableStatsPlug when action in [:stats]
plug PlausibleWeb.EmbeddableAuthSharedLinkPlug when action in [:shared_link, :authenticate_shared_link]

def base_domain() do
PlausibleWeb.Endpoint.host()
Expand All @@ -24,7 +22,6 @@ defmodule PlausibleWeb.StatsController do
|> put_resp_header("x-robots-tag", "noindex")
|> render("stats.html",
site: site,
embed_mode: get_session(conn, "embed_mode"),
has_goals: Plausible.Sites.has_goals?(site),
title: "Plausible · " <> site.domain,
offer_email_report: offer_email_report,
Expand All @@ -33,10 +30,7 @@ defmodule PlausibleWeb.StatsController do
else
conn
|> assign(:skip_plausible_tracking, true)
|> render("waiting_first_pageview.html",
site: site,
embed_mode: get_session(conn, "embed_mode")
)
|> render("waiting_first_pageview.html", site: site)
end
end

Expand Down Expand Up @@ -65,27 +59,32 @@ defmodule PlausibleWeb.StatsController do
|> send_resp(200, csv_content)
end

def shared_link(%{assigns: %{shared_link: shared_link}} = conn, %{"slug" => slug}) do
def shared_link(conn, %{"slug" => slug}) do
shared_link =
Repo.get_by(Plausible.Site.SharedLink, slug: slug)
|> Repo.preload(:site)

if shared_link do
if shared_link.password_hash do
conn
|> put_session("embed_mode", Enum.at(conn.path_info, 1) == "embed")
|> assign(:skip_plausible_tracking, true)
|> render("shared_link_password.html",
link: shared_link,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
else
conn
|> put_session("embed_mode", Enum.at(conn.path_info, 1) == "embed")
|> shared_link_auth_success(shared_link)
shared_link_auth_success(conn, shared_link)
end
else
render_error(conn, 404)
end
end

def authenticate_shared_link(%{assigns: %{shared_link: shared_link}} = conn, %{"slug" => slug, "password" => password}) do
def authenticate_shared_link(conn, %{"slug" => slug, "password" => password}) do
shared_link =
Repo.get_by(Plausible.Site.SharedLink, slug: slug)
|> Repo.preload(:site)

if shared_link do
if Plausible.Auth.Password.match?(password, shared_link.password_hash) do
shared_link_auth_success(conn, shared_link)
Expand Down
2 changes: 1 addition & 1 deletion lib/plausible_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule PlausibleWeb.Endpoint do
signing_salt: "3IL0ob4k",
# 5 years, this is super long but the SlidingSessionTimeout will log people out if they don't return for 2 weeks
max_age: 60 * 60 * 24 * 365 * 5,
extra: config[:session_extra]
extra: "SameSite=Lax"

plug CORSPlug
plug PlausibleWeb.Tracker
Expand Down
27 changes: 0 additions & 27 deletions lib/plausible_web/plugs/embeddable_auth_shared_link_plug.ex

This file was deleted.

23 changes: 0 additions & 23 deletions lib/plausible_web/plugs/embeddable_stats_plug.ex

This file was deleted.

3 changes: 0 additions & 3 deletions lib/plausible_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ defmodule PlausibleWeb.Router do
post "/sites", SiteController, :create_site
post "/sites/:website/make-public", SiteController, :make_public
post "/sites/:website/make-private", SiteController, :make_private
post "/sites/:website/make-embeddable", SiteController, :make_embeddable
post "/sites/:website/make-not-embeddable", SiteController, :make_not_embeddable
post "/sites/:website/weekly-report/enable", SiteController, :enable_weekly_report
post "/sites/:website/weekly-report/disable", SiteController, :disable_weekly_report
post "/sites/:website/weekly-report/recipients", SiteController, :add_weekly_report_recipient
Expand Down Expand Up @@ -163,7 +161,6 @@ defmodule PlausibleWeb.Router do
delete "/:website", SiteController, :delete_site
delete "/:website/stats", SiteController, :reset_stats

get "/share/embed/:slug", StatsController, :shared_link
get "/share/:slug", StatsController, :shared_link
post "/share/:slug/authenticate", StatsController, :authenticate_shared_link
get "/:domain/visitors.csv", StatsController, :csv_export
Expand Down
128 changes: 62 additions & 66 deletions lib/plausible_web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,73 @@
<%= render("_tracking.html", assigns) %>
</head>
<body class="flex flex-col h-full bg-gray-50">
<%= if !(@conn.assigns[:embed_mode] && @conn.assigns.site.embeddable) do %>
<nav class="relative py-8 z-10">
<div class="container">
<nav class="relative flex items-center justify-between sm:h-10 md:justify-center">
<div class="flex items-center flex-1 md:absolute md:inset-y-0 md:left-0">
<div class="flex items-center justify-between">
<a href="<%= home_dest(@conn) %>"><%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo.png"), class: "h-8 w-auto sm:h-10 -mt-2", alt: "Plausible logo") %></a>
</div>
<nav class="relative py-8 z-10">
<div class="container">
<nav class="relative flex items-center justify-between sm:h-10 md:justify-center">
<div class="flex items-center flex-1 md:absolute md:inset-y-0 md:left-0">
<div class="flex items-center justify-between">
<a href="<%= home_dest(@conn) %>"><%= img_tag(PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_logo.png"), class: "h-8 w-auto sm:h-10 -mt-2", alt: "Plausible logo") %></a>
</div>
<div class="absolute flex items-center justify-end inset-y-0 right-0">
<%= cond do %>
<% @conn.assigns[:current_user] -> %>
<ul class="flex">
<%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_subscription) && @conn.assigns[:current_user].subscription == nil do %>
<li class="mr-6 hidden sm:block">
<%= link(trial_notificaton(@conn.assigns[:current_user]), to: "/settings", class: "font-bold text-orange-900 rounded p-2 bg-orange-200", style: "line-height: 40px;") %>
</li>
<% else %>
<li class="mr-6 hidden sm:block">
<%= link("Docs", to: "https://docs.plausible.io", class: "font-bold rounded p-2 hover:bg-gray-200", style: "line-height: 40px;", target: "_blank") %>
</li>
<% end %>
</div>
<div class="absolute flex items-center justify-end inset-y-0 right-0">
<%= cond do %>
<% @conn.assigns[:current_user] -> %>
<ul class="flex">
<%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_subscription) && @conn.assigns[:current_user].subscription == nil do %>
<li class="mr-6 hidden sm:block">
<%= link(trial_notificaton(@conn.assigns[:current_user]), to: "/settings", class: "font-bold text-orange-900 rounded p-2 bg-orange-200", style: "line-height: 40px;") %>
</li>
<% else %>
<li class="mr-6 hidden sm:block">
<%= link("Docs", to: "https://docs.plausible.io", class: "font-bold rounded p-2 hover:bg-gray-200", style: "line-height: 40px;", target: "_blank") %>
</li>
<% end %>
<li>
<div class="relative font-bold rounded">
<div data-dropdown-trigger class="flex items-center hover:bg-gray-200 rounded p-2 cursor-pointer">
<span class="mr-2"><%= @conn.assigns[:current_user].name || @conn.assigns[:current_user].email %></span>
<svg style="height: 18px; transform: translateY(2px); fill: #606f7b;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 512 640" enable-background="new 0 0 512 512" xml:space="preserve"><g><circle cx="256" cy="52.8" r="50.8"/><circle cx="256" cy="256" r="50.8"/><circle cx="256" cy="459.2" r="50.8"/></g></svg>
</div>

<div data-dropdown style="top: 42px; right: 0px; width: 185px;" class="dropdown-content hidden absolute right-0 bg-white border border-gray-300 rounded shadow-md z-10">
<%= link("Settings", to: "/settings", class: "block py-2 px-2 border-b border-gray-300 hover:bg-gray-100") %>
<%= link("Log out", to: "/logout", method: :post, class: "block py-2 px-2 hover:bg-gray-100") %>
</div>
</div>
</li>
</ul>
<% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="relative font-bold rounded">
<div data-dropdown-trigger class="flex items-center hover:bg-gray-200 rounded p-2 cursor-pointer">
<span class="mr-2"><%= @conn.assigns[:current_user].name || @conn.assigns[:current_user].email %></span>
<svg style="height: 18px; transform: translateY(2px); fill: #606f7b;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 512 640" enable-background="new 0 0 512 512" xml:space="preserve"><g><circle cx="256" cy="52.8" r="50.8"/><circle cx="256" cy="256" r="50.8"/><circle cx="256" cy="459.2" r="50.8"/></g></svg>
<div class="inline-flex rounded shadow ml-6">
<a href="/" class="inline-flex items-center justify-center px-5 py-2 border border-transparent text-base leading-6 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:ring transition duration-150 ease-in-out">My Sites</a>
</div>

<div data-dropdown style="top: 42px; right: 0px; width: 185px;" class="dropdown-content hidden absolute right-0 bg-white border border-gray-300 rounded shadow-md z-10">
<%= link("Settings", to: "/settings", class: "block py-2 px-2 border-b border-gray-300 hover:bg-gray-100") %>
<%= link("Log out", to: "/logout", method: :post, class: "block py-2 px-2 hover:bg-gray-100") %>
</li>
</ul>
<% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex">
<a href="/login" class="font-medium text-gray-500 hover:text-gray-900 focus:outline-none focus:text-gray-900 transition duration-150 ease-in-out">Login</a>
</div>
</div>
</li>
</ul>
<% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_authentication) -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex rounded shadow ml-6">
<a href="/" class="inline-flex items-center justify-center px-5 py-2 border border-transparent text-base leading-6 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:ring transition duration-150 ease-in-out">My Sites</a>
</div>
</li>
</ul>
<% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex">
<a href="/login" class="font-medium text-gray-500 hover:text-gray-900 focus:outline-none focus:text-gray-900 transition duration-150 ease-in-out">Login</a>
</div>
</li>
</ul>
<% true -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex">
<a href="/login" class="font-medium text-gray-500 hover:text-gray-900 focus:outline-none focus:text-gray-900 transition duration-150 ease-in-out">Login</a>
</div>
<div class="inline-flex rounded shadow ml-6">
<a href="/register" class="inline-flex items-center justify-center px-5 py-2 border border-transparent text-base leading-6 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:ring transition duration-150 ease-in-out">Sign up</a>
</div>
</li>
</ul>
<% end %>
</div>
</nav>
</div>
</nav>
<% end %>
<% true -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex">
<a href="/login" class="font-medium text-gray-500 hover:text-gray-900 focus:outline-none focus:text-gray-900 transition duration-150 ease-in-out">Login</a>
</div>
<div class="inline-flex rounded shadow ml-6">
<a href="/register" class="inline-flex items-center justify-center px-5 py-2 border border-transparent text-base leading-6 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:ring transition duration-150 ease-in-out">Sign up</a>
</div>
</li>
</ul>
<% end %>
</div>
</nav>
</div>
</nav>

<%= render("_flash.html", assigns) %>

Expand Down Expand Up @@ -137,9 +135,7 @@
<main class="flex-1">
<%= Map.get(assigns, :inner_layout) || render @view_module, @view_template, assigns %>
</main>
<%= if !(@conn.assigns[:embed_mode] && @conn.assigns.site.embeddable) do %>
<%= render("_footer.html", assigns) %>
<% end %>
<%= render("_footer.html", assigns) %>
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
</body>
</html>
Loading