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)
50 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
52 quarantined = Keyword.get(instance, :quarantined_instances)
55 if is_list(quarantined) do
62 User.moderator_user_query()
64 |> Enum.map(fn u -> u.ap_id end)
67 Config.get([:mrf_user_allowlist], [])
68 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
71 if Keyword.get(instance, :mrf_transparency) do
73 mrf_policies: mrf_policies,
74 mrf_simple: mrf_simple,
75 mrf_user_allowlist: mrf_user_allowlist,
76 quarantined_instances: quarantined
86 "mastodon_api_streaming",
87 if Keyword.get(media_proxy, :enabled) do
90 if Keyword.get(gopher, :enabled) do
93 if Keyword.get(chat, :enabled) do
96 if Keyword.get(suggestions, :enabled) do
99 if Keyword.get(instance, :allow_relay) do
108 name: Pleroma.Application.name() |> String.downcase(),
109 version: Pleroma.Application.version()
111 protocols: ["ostatus", "activitypub"],
116 openRegistrations: Keyword.get(instance, :registrations_open),
119 total: stats.user_count || 0
121 localPosts: stats.status_count || 0
124 nodeName: Keyword.get(instance, :name),
125 nodeDescription: Keyword.get(instance, :description),
126 private: !Keyword.get(instance, :public, true),
128 enabled: Keyword.get(suggestions, :enabled, false),
129 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
130 timeout: Keyword.get(suggestions, :timeout, 5000),
131 limit: Keyword.get(suggestions, :limit, 23),
132 web: Keyword.get(suggestions, :web, "")
134 staffAccounts: staff_accounts,
135 federation: federation_response,
136 postFormats: Keyword.get(instance, :allowed_post_formats),
138 general: Keyword.get(instance, :upload_limit),
139 avatar: Keyword.get(instance, :avatar_upload_limit),
140 banner: Keyword.get(instance, :banner_upload_limit),
141 background: Keyword.get(instance, :background_upload_limit)
143 accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
144 invitesEnabled: Keyword.get(instance, :invites_enabled, false),
146 restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
151 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
152 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
153 def nodeinfo(conn, %{"version" => "2.0"}) do
157 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
159 |> json(raw_nodeinfo())
162 def nodeinfo(conn, %{"version" => "2.1"}) do
163 raw_response = raw_nodeinfo()
167 |> Map.get(:software)
168 |> Map.put(:repository, Pleroma.Application.repository())
172 |> Map.put(:software, updated_software)
173 |> Map.put(:version, "2.1")
178 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
183 def nodeinfo(conn, _) do
186 |> json(%{error: "Nodeinfo schema version not handled"})