MRF Transparency
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_controller.ex
1 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
2 use Pleroma.Web, :controller
3
4 alias Pleroma.Stats
5 alias Pleroma.Web
6 alias Pleroma.{User, Repo}
7
8 def schemas(conn, _params) do
9 response = %{
10 links: [
11 %{
12 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
13 href: Web.base_url() <> "/nodeinfo/2.0.json"
14 }
15 ]
16 }
17
18 json(conn, response)
19 end
20
21 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
22 def nodeinfo(conn, %{"version" => "2.0"}) do
23 instance = Application.get_env(:pleroma, :instance)
24 media_proxy = Application.get_env(:pleroma, :media_proxy)
25 suggestions = Application.get_env(:pleroma, :suggestions)
26 chat = Application.get_env(:pleroma, :chat)
27 gopher = Application.get_env(:pleroma, :gopher)
28 stats = Stats.get_stats()
29 mrf_simple = Application.get_env(:pleroma, :mrf_simple)
30
31 mrf_policies = Keyword.get(instance, :rewrite_policy)
32
33 mrf_policies =
34 if(is_list(mrf_policies)) do
35 mrf_policies
36 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
37 else
38 [to_string(mrf_policies) |> String.split(".") |> List.last()]
39 end
40
41 quarantined = Keyword.get(instance, :quarantined_instances)
42
43 quarantined =
44 if is_list(quarantined) do
45 quarantined
46 else
47 []
48 end
49
50 staff_accounts =
51 User.moderator_user_query()
52 |> Repo.all()
53 |> Enum.map(fn u -> u.ap_id end)
54
55 response = %{
56 version: "2.0",
57 software: %{
58 name: "pleroma",
59 version: Keyword.get(instance, :version)
60 },
61 protocols: ["ostatus", "activitypub"],
62 services: %{
63 inbound: [],
64 outbound: []
65 },
66 openRegistrations: Keyword.get(instance, :registrations_open),
67 usage: %{
68 users: %{
69 total: stats.user_count || 0
70 },
71 localPosts: stats.status_count || 0
72 },
73 metadata: %{
74 nodeName: Keyword.get(instance, :name),
75 nodeDescription: Keyword.get(instance, :description),
76 mediaProxy: Keyword.get(media_proxy, :enabled),
77 private: !Keyword.get(instance, :public, true),
78 suggestions: %{
79 enabled: Keyword.get(suggestions, :enabled, false),
80 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
81 timeout: Keyword.get(suggestions, :timeout, 5000),
82 limit: Keyword.get(suggestions, :limit, 23),
83 web: Keyword.get(suggestions, :web, "")
84 },
85 staffAccounts: staff_accounts,
86 chat: Keyword.get(chat, :enabled),
87 gopher: Keyword.get(gopher, :enabled),
88 federation: %{
89 mrf_policies: mrf_policies,
90 mrf_simple: mrf_simple,
91 quarantined_instances: quarantined
92 }
93 }
94 }
95
96 conn
97 |> put_resp_header(
98 "content-type",
99 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
100 )
101 |> json(response)
102 end
103
104 def nodeinfo(conn, _) do
105 conn
106 |> put_status(404)
107 |> json(%{error: "Nodeinfo schema version not handled"})
108 end
109 end