1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
6 use Pleroma.Web, :controller
13 alias Pleroma.Web.ActivityPub.MRF
15 plug(Pleroma.Web.FederatingPlug)
17 def schemas(conn, _params) do
21 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
22 href: Web.base_url() <> "/nodeinfo/2.0.json"
25 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
26 href: Web.base_url() <> "/nodeinfo/2.1.json"
34 # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
37 instance = Application.get_env(:pleroma, :instance)
38 media_proxy = Application.get_env(:pleroma, :media_proxy)
39 suggestions = Application.get_env(:pleroma, :suggestions)
40 chat = Application.get_env(:pleroma, :chat)
41 gopher = Application.get_env(:pleroma, :gopher)
42 stats = Stats.get_stats()
45 Application.get_env(:pleroma, :mrf_simple)
48 # This horror is needed to convert regex sigils to strings
50 Application.get_env(:pleroma, :mrf_keyword, [])
51 |> Enum.map(fn {key, value} ->
54 {pattern, replacement} ->
57 if not is_binary(pattern) do
62 "replacement" => replacement
66 if not is_binary(pattern) do
77 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
79 quarantined = Keyword.get(instance, :quarantined_instances)
82 if is_list(quarantined) do
89 User.moderator_user_query()
91 |> Enum.map(fn u -> u.ap_id end)
94 Config.get([:mrf_user_allowlist], [])
95 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
98 if Keyword.get(instance, :mrf_transparency) do
100 mrf_policies: mrf_policies,
101 mrf_simple: mrf_simple,
102 mrf_keyword: mrf_keyword,
103 mrf_user_allowlist: mrf_user_allowlist,
104 quarantined_instances: quarantined
114 "mastodon_api_streaming",
115 if Keyword.get(media_proxy, :enabled) do
118 if Keyword.get(gopher, :enabled) do
121 if Keyword.get(chat, :enabled) do
124 if Keyword.get(suggestions, :enabled) do
127 if Keyword.get(instance, :allow_relay) do
136 name: Pleroma.Application.name() |> String.downcase(),
137 version: Pleroma.Application.version()
139 protocols: ["ostatus", "activitypub"],
144 openRegistrations: Keyword.get(instance, :registrations_open),
147 total: stats.user_count || 0
149 localPosts: stats.status_count || 0
152 nodeName: Keyword.get(instance, :name),
153 nodeDescription: Keyword.get(instance, :description),
154 private: !Keyword.get(instance, :public, true),
156 enabled: Keyword.get(suggestions, :enabled, false),
157 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
158 timeout: Keyword.get(suggestions, :timeout, 5000),
159 limit: Keyword.get(suggestions, :limit, 23),
160 web: Keyword.get(suggestions, :web, "")
162 staffAccounts: staff_accounts,
163 federation: federation_response,
164 postFormats: Keyword.get(instance, :allowed_post_formats),
166 general: Keyword.get(instance, :upload_limit),
167 avatar: Keyword.get(instance, :avatar_upload_limit),
168 banner: Keyword.get(instance, :banner_upload_limit),
169 background: Keyword.get(instance, :background_upload_limit)
171 accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
172 invitesEnabled: Keyword.get(instance, :invites_enabled, false),
174 restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
179 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
180 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
181 def nodeinfo(conn, %{"version" => "2.0"}) do
185 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
187 |> json(raw_nodeinfo())
190 def nodeinfo(conn, %{"version" => "2.1"}) do
191 raw_response = raw_nodeinfo()
195 |> Map.get(:software)
196 |> Map.put(:repository, Pleroma.Application.repository())
200 |> Map.put(:software, updated_software)
201 |> Map.put(:version, "2.1")
206 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
211 def nodeinfo(conn, _) do
214 |> json(%{error: "Nodeinfo schema version not handled"})