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
10 alias Pleroma.{User, Repo}
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)
49 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
51 quarantined = Keyword.get(instance, :quarantined_instances)
54 if is_list(quarantined) do
61 User.moderator_user_query()
63 |> Enum.map(fn u -> u.ap_id end)
66 Config.get([:mrf_user_allowlist], [])
67 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
69 mrf_transparency = Keyword.get(instance, :mrf_transparency)
72 if mrf_transparency do
74 mrf_policies: mrf_policies,
75 mrf_simple: mrf_simple,
76 mrf_user_allowlist: mrf_user_allowlist,
77 quarantined_instances: quarantined
87 "mastodon_api_streaming",
88 if Keyword.get(media_proxy, :enabled) do
91 if Keyword.get(gopher, :enabled) do
94 if Keyword.get(chat, :enabled) do
97 if Keyword.get(suggestions, :enabled) do
100 if Keyword.get(instance, :allow_relay) do
109 name: Pleroma.Application.name() |> String.downcase(),
110 version: Pleroma.Application.version()
112 protocols: ["ostatus", "activitypub"],
117 openRegistrations: Keyword.get(instance, :registrations_open),
120 total: stats.user_count || 0
122 localPosts: stats.status_count || 0
125 nodeName: Keyword.get(instance, :name),
126 nodeDescription: Keyword.get(instance, :description),
127 private: !Keyword.get(instance, :public, true),
129 enabled: Keyword.get(suggestions, :enabled, false),
130 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
131 timeout: Keyword.get(suggestions, :timeout, 5000),
132 limit: Keyword.get(suggestions, :limit, 23),
133 web: Keyword.get(suggestions, :web, "")
135 staffAccounts: staff_accounts,
136 federation: federation_response,
137 postFormats: Keyword.get(instance, :allowed_post_formats),
139 general: Keyword.get(instance, :upload_limit),
140 avatar: Keyword.get(instance, :avatar_upload_limit),
141 banner: Keyword.get(instance, :banner_upload_limit),
142 background: Keyword.get(instance, :background_upload_limit)
144 accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
145 invitesEnabled: Keyword.get(instance, :invites_enabled, false),
147 restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
152 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
153 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
154 def nodeinfo(conn, %{"version" => "2.0"}) do
158 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
160 |> json(raw_nodeinfo())
163 def nodeinfo(conn, %{"version" => "2.1"}) do
164 raw_response = raw_nodeinfo()
168 |> Map.get(:software)
169 |> Map.put(:repository, Pleroma.Application.repository())
173 |> Map.put(:software, updated_software)
174 |> Map.put(:version, "2.1")
179 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
184 def nodeinfo(conn, _) do
187 |> json(%{error: "Nodeinfo schema version not handled"})