You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
725 B
33 lines
725 B
6 years ago
|
# Pleroma: A lightweight social networking server
|
||
5 years ago
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||
6 years ago
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||
|
|
||
6 years ago
|
defmodule Pleroma.Web.FederatingPlug do
|
||
|
import Plug.Conn
|
||
|
|
||
|
def init(options) do
|
||
|
options
|
||
|
end
|
||
|
|
||
6 years ago
|
def call(conn, _opts) do
|
||
5 years ago
|
if federating?() do
|
||
6 years ago
|
conn
|
||
|
else
|
||
5 years ago
|
fail(conn)
|
||
6 years ago
|
end
|
||
|
end
|
||
5 years ago
|
|
||
|
def federating?, do: Pleroma.Config.get([:instance, :federating])
|
||
5 years ago
|
|
||
4 years ago
|
# Definition for the use in :if_func / :unless_func plug options
|
||
|
def federating?(_conn), do: federating?()
|
||
|
|
||
5 years ago
|
defp fail(conn) do
|
||
5 years ago
|
conn
|
||
|
|> put_status(404)
|
||
|
|> Phoenix.Controller.put_view(Pleroma.Web.ErrorView)
|
||
|
|> Phoenix.Controller.render("404.json")
|
||
|
|> halt()
|
||
|
end
|
||
6 years ago
|
end
|