2018-12-23 20:04:54 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:04:54 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-24 07:41:09 +00:00
|
|
|
defmodule Pleroma.Web.Plugs.FederatingPlug do
|
2018-11-05 14:19:03 +00:00
|
|
|
import Plug.Conn
|
|
|
|
|
|
|
|
def init(options) do
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2018-12-09 09:12:48 +00:00
|
|
|
def call(conn, _opts) do
|
2020-03-03 19:22:02 +00:00
|
|
|
if federating?() do
|
2018-11-05 14:19:03 +00:00
|
|
|
conn
|
|
|
|
else
|
2020-03-05 18:19:21 +00:00
|
|
|
fail(conn)
|
2018-11-05 14:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
2020-03-03 19:22:02 +00:00
|
|
|
|
|
|
|
def federating?, do: Pleroma.Config.get([:instance, :federating])
|
2020-03-05 18:19:21 +00:00
|
|
|
|
2020-04-30 15:19:51 +00:00
|
|
|
# Definition for the use in :if_func / :unless_func plug options
|
|
|
|
def federating?(_conn), do: federating?()
|
|
|
|
|
2020-03-09 17:51:44 +00:00
|
|
|
defp fail(conn) do
|
2020-03-05 18:19:21 +00:00
|
|
|
conn
|
|
|
|
|> put_status(404)
|
|
|
|
|> Phoenix.Controller.put_view(Pleroma.Web.ErrorView)
|
|
|
|
|> Phoenix.Controller.render("404.json")
|
|
|
|
|> halt()
|
|
|
|
end
|
2018-11-05 14:19:03 +00:00
|
|
|
end
|