fix 486: Add option --assume-yes to allow it to work non-interactive
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Stats
9 alias Pleroma.Web
10 alias Pleroma.{User, Repo}
11 alias Pleroma.Config
12 alias Pleroma.Web.ActivityPub.MRF
13
14 plug(Pleroma.Web.FederatingPlug)
15
16 def schemas(conn, _params) do
17 response = %{
18 links: [
19 %{
20 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
21 href: Web.base_url() <> "/nodeinfo/2.0.json"
22 }
23 ]
24 }
25
26 json(conn, response)
27 end
28
29 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
30 def nodeinfo(conn, %{"version" => "2.0"}) do
31 instance = Application.get_env(:pleroma, :instance)
32 media_proxy = Application.get_env(:pleroma, :media_proxy)
33 suggestions = Application.get_env(:pleroma, :suggestions)
34 chat = Application.get_env(:pleroma, :chat)
35 gopher = Application.get_env(:pleroma, :gopher)
36 stats = Stats.get_stats()
37
38 mrf_simple =
39 Application.get_env(:pleroma, :mrf_simple)
40 |> Enum.into(%{})
41
42 mrf_policies =
43 MRF.get_policies()
44 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
45
46 quarantined = Keyword.get(instance, :quarantined_instances)
47
48 quarantined =
49 if is_list(quarantined) do
50 quarantined
51 else
52 []
53 end
54
55 staff_accounts =
56 User.moderator_user_query()
57 |> Repo.all()
58 |> Enum.map(fn u -> u.ap_id end)
59
60 mrf_user_allowlist =
61 Config.get([:mrf_user_allowlist], [])
62 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
63
64 mrf_transparency = Keyword.get(instance, :mrf_transparency)
65
66 federation_response =
67 if mrf_transparency do
68 %{
69 mrf_policies: mrf_policies,
70 mrf_simple: mrf_simple,
71 mrf_user_allowlist: mrf_user_allowlist,
72 quarantined_instances: quarantined
73 }
74 else
75 %{}
76 end
77
78 features =
79 [
80 "pleroma_api",
81 "mastodon_api",
82 "mastodon_api_streaming",
83 if Keyword.get(media_proxy, :enabled) do
84 "media_proxy"
85 end,
86 if Keyword.get(gopher, :enabled) do
87 "gopher"
88 end,
89 if Keyword.get(chat, :enabled) do
90 "chat"
91 end,
92 if Keyword.get(suggestions, :enabled) do
93 "suggestions"
94 end,
95 if Keyword.get(instance, :allow_relay) do
96 "relay"
97 end
98 ]
99 |> Enum.filter(& &1)
100
101 response = %{
102 version: "2.0",
103 software: %{
104 name: Pleroma.Application.name(),
105 version: Pleroma.Application.version()
106 },
107 protocols: ["ostatus", "activitypub"],
108 services: %{
109 inbound: [],
110 outbound: []
111 },
112 openRegistrations: Keyword.get(instance, :registrations_open),
113 usage: %{
114 users: %{
115 total: stats.user_count || 0
116 },
117 localPosts: stats.status_count || 0
118 },
119 metadata: %{
120 nodeName: Keyword.get(instance, :name),
121 nodeDescription: Keyword.get(instance, :description),
122 private: !Keyword.get(instance, :public, true),
123 suggestions: %{
124 enabled: Keyword.get(suggestions, :enabled, false),
125 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
126 timeout: Keyword.get(suggestions, :timeout, 5000),
127 limit: Keyword.get(suggestions, :limit, 23),
128 web: Keyword.get(suggestions, :web, "")
129 },
130 staffAccounts: staff_accounts,
131 federation: federation_response,
132 postFormats: Keyword.get(instance, :allowed_post_formats),
133 uploadLimits: %{
134 general: Keyword.get(instance, :upload_limit),
135 avatar: Keyword.get(instance, :avatar_upload_limit),
136 banner: Keyword.get(instance, :banner_upload_limit),
137 background: Keyword.get(instance, :background_upload_limit)
138 },
139 accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
140 invitesEnabled: Keyword.get(instance, :invites_enabled, false),
141 features: features,
142 restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
143 }
144 }
145
146 conn
147 |> put_resp_header(
148 "content-type",
149 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
150 )
151 |> json(response)
152 end
153
154 def nodeinfo(conn, _) do
155 conn
156 |> put_status(404)
157 |> json(%{error: "Nodeinfo schema version not handled"})
158 end
159 end