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
12 alias Pleroma.Web.ActivityPub.MRF
14 plug(Pleroma.Web.FederatingPlug)
16 def schemas(conn, _params) do
20 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
21 href: Web.base_url() <> "/nodeinfo/2.0.json"
24 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
25 href: Web.base_url() <> "/nodeinfo/2.1.json"
33 # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
36 instance = Application.get_env(:pleroma, :instance)
37 media_proxy = Application.get_env(:pleroma, :media_proxy)
38 suggestions = Application.get_env(:pleroma, :suggestions)
39 chat = Application.get_env(:pleroma, :chat)
40 gopher = Application.get_env(:pleroma, :gopher)
41 stats = Stats.get_stats()
44 Application.get_env(:pleroma, :mrf_simple)
47 # This horror is needed to convert regex sigils to strings
49 Application.get_env(:pleroma, :mrf_keyword, [])
50 |> Enum.map(fn {key, value} ->
53 {pattern, replacement} ->
56 if not is_binary(pattern) do
61 "replacement" => replacement
65 if not is_binary(pattern) do
76 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
78 quarantined = Keyword.get(instance, :quarantined_instances)
81 if is_list(quarantined) do
89 |> Enum.map(fn u -> u.ap_id end)
92 Config.get([:mrf_user_allowlist], [])
93 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
96 if Keyword.get(instance, :mrf_transparency) do
98 mrf_policies: mrf_policies,
99 mrf_simple: mrf_simple,
100 mrf_keyword: mrf_keyword,
101 mrf_user_allowlist: mrf_user_allowlist,
102 quarantined_instances: quarantined
112 "mastodon_api_streaming",
113 if Keyword.get(media_proxy, :enabled) do
116 if Keyword.get(gopher, :enabled) do
119 if Keyword.get(chat, :enabled) do
122 if Keyword.get(suggestions, :enabled) do
125 if Keyword.get(instance, :allow_relay) do
128 if Keyword.get(instance, :safe_dm_mentions) do
137 name: Pleroma.Application.name() |> String.downcase(),
138 version: Pleroma.Application.version()
140 protocols: ["ostatus", "activitypub"],
145 openRegistrations: Keyword.get(instance, :registrations_open),
148 total: stats.user_count || 0
150 localPosts: stats.status_count || 0
153 nodeName: Keyword.get(instance, :name),
154 nodeDescription: Keyword.get(instance, :description),
155 private: !Keyword.get(instance, :public, true),
157 enabled: Keyword.get(suggestions, :enabled, false),
158 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
159 timeout: Keyword.get(suggestions, :timeout, 5000),
160 limit: Keyword.get(suggestions, :limit, 23),
161 web: Keyword.get(suggestions, :web, "")
163 staffAccounts: staff_accounts,
164 federation: federation_response,
165 postFormats: Keyword.get(instance, :allowed_post_formats),
167 general: Keyword.get(instance, :upload_limit),
168 avatar: Keyword.get(instance, :avatar_upload_limit),
169 banner: Keyword.get(instance, :banner_upload_limit),
170 background: Keyword.get(instance, :background_upload_limit)
172 accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
173 invitesEnabled: Keyword.get(instance, :invites_enabled, false),
175 restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
180 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
181 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
182 def nodeinfo(conn, %{"version" => "2.0"}) do
186 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
188 |> json(raw_nodeinfo())
191 def nodeinfo(conn, %{"version" => "2.1"}) do
192 raw_response = raw_nodeinfo()
196 |> Map.get(:software)
197 |> Map.put(:repository, Pleroma.Application.repository())
201 |> Map.put(:software, updated_software)
202 |> Map.put(:version, "2.1")
207 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
212 def nodeinfo(conn, _) do
215 |> json(%{error: "Nodeinfo schema version not handled"})