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
13 alias Pleroma.Web.Federator.Publisher
15 def schemas(conn, _params) do
19 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
20 href: Web.base_url() <> "/nodeinfo/2.0.json"
23 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
24 href: Web.base_url() <> "/nodeinfo/2.1.json"
32 # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
35 stats = Stats.get_stats()
38 Config.get(:mrf_simple)
41 # This horror is needed to convert regex sigils to strings
43 Config.get(:mrf_keyword, [])
44 |> Enum.map(fn {key, value} ->
47 {pattern, replacement} ->
50 if not is_binary(pattern) do
55 "replacement" => replacement
59 if not is_binary(pattern) do
70 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
72 quarantined = Config.get([:instance, :quarantined_instances], [])
76 |> Enum.map(fn u -> u.ap_id end)
79 Config.get([:mrf_user_allowlist], [])
80 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
83 if Config.get([:instance, :mrf_transparency]) do
85 mrf_policies: mrf_policies,
86 mrf_simple: mrf_simple,
87 mrf_keyword: mrf_keyword,
88 mrf_user_allowlist: mrf_user_allowlist,
89 quarantined_instances: quarantined
99 "mastodon_api_streaming",
101 "pleroma_explicit_addressing",
102 if Config.get([:media_proxy, :enabled]) do
105 if Config.get([:gopher, :enabled]) do
108 if Config.get([:chat, :enabled]) do
111 if Config.get([:suggestions, :enabled]) do
114 if Config.get([:instance, :allow_relay]) do
117 if Config.get([:instance, :safe_dm_mentions]) do
126 name: Pleroma.Application.name() |> String.downcase(),
127 version: Pleroma.Application.version()
129 protocols: Publisher.gather_nodeinfo_protocol_names(),
134 openRegistrations: Config.get([:instance, :registrations_open]),
137 total: stats.user_count || 0
139 localPosts: stats.status_count || 0
142 nodeName: Config.get([:instance, :name]),
143 nodeDescription: Config.get([:instance, :description]),
144 private: !Config.get([:instance, :public], true),
146 enabled: Config.get([:suggestions, :enabled], false),
147 thirdPartyEngine: Config.get([:suggestions, :third_party_engine], ""),
148 timeout: Config.get([:suggestions, :timeout], 5000),
149 limit: Config.get([:suggestions, :limit], 23),
150 web: Config.get([:suggestions, :web], "")
152 staffAccounts: staff_accounts,
153 federation: federation_response,
154 pollLimits: Config.get([:instance, :poll_limits]),
155 postFormats: Config.get([:instance, :allowed_post_formats]),
157 general: Config.get([:instance, :upload_limit]),
158 avatar: Config.get([:instance, :avatar_upload_limit]),
159 banner: Config.get([:instance, :banner_upload_limit]),
160 background: Config.get([:instance, :background_upload_limit])
162 accountActivationRequired: Config.get([:instance, :account_activation_required], false),
163 invitesEnabled: Config.get([:instance, :invites_enabled], false),
165 restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
166 skipThreadContainment: Config.get([:instance, :skip_thread_containment], false)
171 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
172 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
173 def nodeinfo(conn, %{"version" => "2.0"}) do
177 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
179 |> json(raw_nodeinfo())
182 def nodeinfo(conn, %{"version" => "2.1"}) do
183 raw_response = raw_nodeinfo()
187 |> Map.get(:software)
188 |> Map.put(:repository, Pleroma.Application.repository())
192 |> Map.put(:software, updated_software)
193 |> Map.put(:version, "2.1")
198 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
203 def nodeinfo(conn, _) do
204 render_error(conn, :not_found, "Nodeinfo schema version not handled")