2018-12-23 13:04:54 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 15:44:49 -07:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:04:54 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-11-05 07:19:03 -07:00
|
|
|
defmodule Pleroma.Web.FederatingPlug do
|
|
|
|
import Plug.Conn
|
|
|
|
|
|
|
|
def init(options) do
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2018-12-09 02:12:48 -07:00
|
|
|
def call(conn, _opts) do
|
2020-03-03 12:22:02 -07:00
|
|
|
if federating?() do
|
2018-11-05 07:19:03 -07:00
|
|
|
conn
|
|
|
|
else
|
2020-03-05 11:19:21 -07:00
|
|
|
fail(conn)
|
2018-11-05 07:19:03 -07:00
|
|
|
end
|
|
|
|
end
|
2020-03-03 12:22:02 -07:00
|
|
|
|
|
|
|
def federating?, do: Pleroma.Config.get([:instance, :federating])
|
2020-03-05 11:19:21 -07:00
|
|
|
|
2020-03-09 11:51:44 -06:00
|
|
|
defp fail(conn) do
|
2020-03-05 11:19:21 -07:00
|
|
|
conn
|
|
|
|
|> put_status(404)
|
|
|
|
|> Phoenix.Controller.put_view(Pleroma.Web.ErrorView)
|
|
|
|
|> Phoenix.Controller.render("404.json")
|
|
|
|
|> halt()
|
|
|
|
end
|
2018-11-05 07:19:03 -07:00
|
|
|
end
|