|> unique_constraint(:host)
end
- def reachable?(url) do
+ def reachable?(url) when is_binary(url) do
!Repo.one(
from(i in Instance,
where:
)
end
- def set_reachable(url) do
+ def reachable?(_), do: true
+
+ def set_reachable(url) when is_binary(url) do
Repo.update_all(
from(i in Instance, where: i.host == ^host(url)),
set: [
)
end
- def set_unreachable(url, unreachable_since \\ nil) do
+ def set_reachable(_), do: {0, :noop}
+
+ def set_unreachable(url, unreachable_since \\ nil)
+
+ def set_unreachable(url, unreachable_since) when is_binary(url) do
unreachable_since = unreachable_since || DateTime.utc_now()
host = host(url)
existing_record = Repo.get_by(Instance, %{host: host})
end
end
+ def set_unreachable(_, _), do: {0, :noop}
+
defp host(url_or_host) do
if url_or_host =~ ~r/^http/i do
URI.parse(url_or_host).host
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxy do
- @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range)
+ @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since) ++
+ ~w(if-none-match if-range range referer)
@resp_cache_headers ~w(etag date last-modified cache-control)
@keep_resp_headers @resp_cache_headers ++
~w(content-type content-disposition content-encoding content-range accept-ranges vary)
[
{"Content-Type", "application/activity+json"},
{"signature", signature},
- {"digest", digest}
+ {"digest", digest},
+ {"referer", Pleroma.Web.Endpoint.url()}
]
) do
Instances.set_reachable(inbox)
defmodule Pleroma.Web.ActivityPub.ActivityPubController do
use Pleroma.Web, :controller
+
alias Pleroma.{Activity, User, Object}
alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
alias Pleroma.Web.ActivityPub.ActivityPub
plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay])
plug(:relay_active? when action in [:relay])
+ plug(:set_requester_reachable when action in [:inbox])
def relay_active?(conn, _) do
if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do
|> put_status(500)
|> json("error")
end
+
+ defp set_requester_reachable(conn, _) do
+ Pleroma.Web.ControllerHelper.set_requester_reachable(conn)
+ conn
+ end
end
|> put_status(status)
|> json(json)
end
+
+ def set_requester_reachable(conn) do
+ with [referer] <- get_req_header(conn, "referer"),
+ do: Pleroma.Instances.set_reachable(referer)
+ end
end
alias Pleroma.Web.ActivityPub.ActivityPub
plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming])
+ plug(:set_requester_reachable when action in [:salmon_incoming])
+
action_fallback(:errors)
def feed_redirect(conn, %{"nickname" => nickname}) do
|> put_status(500)
|> text("Something went wrong")
end
+
+ defp set_requester_reachable(conn, _) do
+ Pleroma.Web.ControllerHelper.set_requester_reachable(conn)
+ conn
+ end
end
poster.(
url,
feed,
- [{"Content-Type", "application/magic-envelope+xml"}]
+ [
+ {"Content-Type", "application/magic-envelope+xml"},
+ {"referer", Pleroma.Web.Endpoint.url()}
+ ]
) do
Instances.set_reachable(url)
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
xml,
[
{"Content-Type", "application/atom+xml"},
- {"X-Hub-Signature", "sha1=#{signature}"}
+ {"X-Hub-Signature", "sha1=#{signature}"},
+ {"referer", Pleroma.Web.Endpoint.url()}
]
) do
Instances.set_reachable(callback)
defmodule Pleroma.Web.Websub.WebsubController do
use Pleroma.Web, :controller
+
alias Pleroma.{Repo, User}
alias Pleroma.Web.{Websub, Federator}
alias Pleroma.Web.Websub.WebsubClientSubscription
+
require Logger
plug(
]
)
+ plug(:set_requester_reachable when action in [:websub_incoming])
+
def websub_subscription_request(conn, %{"nickname" => nickname} = params) do
user = User.get_cached_by_nickname(nickname)
|> send_resp(500, "Error")
end
end
+
+ defp set_requester_reachable(conn, _) do
+ Pleroma.Web.ControllerHelper.set_requester_reachable(conn)
+ conn
+ end
end