Add a way to use the admin api without a user.
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 pipeline :api do
5 plug(:accepts, ["json"])
6 plug(:fetch_session)
7 plug(Pleroma.Plugs.OAuthPlug)
8 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
9 plug(Pleroma.Plugs.UserFetcherPlug)
10 plug(Pleroma.Plugs.SessionAuthenticationPlug)
11 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
12 plug(Pleroma.Plugs.AuthenticationPlug)
13 plug(Pleroma.Plugs.UserEnabledPlug)
14 plug(Pleroma.Plugs.SetUserSessionIdPlug)
15 plug(Pleroma.Plugs.EnsureUserKeyPlug)
16 end
17
18 pipeline :authenticated_api do
19 plug(:accepts, ["json"])
20 plug(:fetch_session)
21 plug(Pleroma.Plugs.OAuthPlug)
22 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
23 plug(Pleroma.Plugs.UserFetcherPlug)
24 plug(Pleroma.Plugs.SessionAuthenticationPlug)
25 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
26 plug(Pleroma.Plugs.AuthenticationPlug)
27 plug(Pleroma.Plugs.UserEnabledPlug)
28 plug(Pleroma.Plugs.SetUserSessionIdPlug)
29 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
30 end
31
32 pipeline :admin_api do
33 plug(:accepts, ["json"])
34 plug(:fetch_session)
35 plug(Pleroma.Plugs.OAuthPlug)
36 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
37 plug(Pleroma.Plugs.UserFetcherPlug)
38 plug(Pleroma.Plugs.SessionAuthenticationPlug)
39 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
40 plug(Pleroma.Plugs.AuthenticationPlug)
41 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
42 plug(Pleroma.Plugs.UserEnabledPlug)
43 plug(Pleroma.Plugs.SetUserSessionIdPlug)
44 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
45 plug(Pleroma.Plugs.UserIsAdminPlug)
46 end
47
48 pipeline :mastodon_html do
49 plug(:accepts, ["html"])
50 plug(:fetch_session)
51 plug(Pleroma.Plugs.OAuthPlug)
52 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
53 plug(Pleroma.Plugs.UserFetcherPlug)
54 plug(Pleroma.Plugs.SessionAuthenticationPlug)
55 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
56 plug(Pleroma.Plugs.AuthenticationPlug)
57 plug(Pleroma.Plugs.UserEnabledPlug)
58 plug(Pleroma.Plugs.SetUserSessionIdPlug)
59 plug(Pleroma.Plugs.EnsureUserKeyPlug)
60 end
61
62 pipeline :pleroma_html do
63 plug(:accepts, ["html"])
64 plug(:fetch_session)
65 plug(Pleroma.Plugs.OAuthPlug)
66 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
67 plug(Pleroma.Plugs.UserFetcherPlug)
68 plug(Pleroma.Plugs.SessionAuthenticationPlug)
69 plug(Pleroma.Plugs.AuthenticationPlug)
70 plug(Pleroma.Plugs.EnsureUserKeyPlug)
71 end
72
73 pipeline :well_known do
74 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
75 end
76
77 pipeline :config do
78 plug(:accepts, ["json", "xml"])
79 end
80
81 pipeline :oauth do
82 plug(:accepts, ["html", "json"])
83 end
84
85 pipeline :pleroma_api do
86 plug(:accepts, ["html", "json"])
87 end
88
89 pipeline :mailbox_preview do
90 plug(:accepts, ["html"])
91
92 plug(:put_secure_browser_headers, %{
93 "content-security-policy" =>
94 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
95 })
96 end
97
98 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
99 pipe_through(:pleroma_api)
100 get("/password_reset/:token", UtilController, :show_password_reset)
101 post("/password_reset", UtilController, :password_reset)
102 get("/emoji", UtilController, :emoji)
103 get("/captcha", UtilController, :captcha)
104 end
105
106 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
107 pipe_through(:admin_api)
108 delete("/user", AdminAPIController, :user_delete)
109 post("/user", AdminAPIController, :user_create)
110 put("/users/tag", AdminAPIController, :tag_users)
111 delete("/users/tag", AdminAPIController, :untag_users)
112
113 get("/permission_group/:nickname", AdminAPIController, :right_get)
114 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
115 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
116 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
117
118 post("/relay", AdminAPIController, :relay_follow)
119 delete("/relay", AdminAPIController, :relay_unfollow)
120
121 get("/invite_token", AdminAPIController, :get_invite_token)
122 post("/email_invite", AdminAPIController, :email_invite)
123
124 get("/password_reset", AdminAPIController, :get_password_reset)
125 end
126
127 scope "/", Pleroma.Web.TwitterAPI do
128 pipe_through(:pleroma_html)
129 get("/ostatus_subscribe", UtilController, :remote_follow)
130 post("/ostatus_subscribe", UtilController, :do_remote_follow)
131 post("/main/ostatus", UtilController, :remote_subscribe)
132 end
133
134 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
135 pipe_through(:authenticated_api)
136 post("/follow_import", UtilController, :follow_import)
137 post("/change_password", UtilController, :change_password)
138 post("/delete_account", UtilController, :delete_account)
139 end
140
141 scope "/oauth", Pleroma.Web.OAuth do
142 get("/authorize", OAuthController, :authorize)
143 post("/authorize", OAuthController, :create_authorization)
144 post("/token", OAuthController, :token_exchange)
145 post("/revoke", OAuthController, :token_revoke)
146 end
147
148 scope "/api/v1", Pleroma.Web.MastodonAPI do
149 pipe_through(:authenticated_api)
150
151 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
152 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
153 get("/accounts/relationships", MastodonAPIController, :relationships)
154 get("/accounts/search", MastodonAPIController, :account_search)
155 post("/accounts/:id/follow", MastodonAPIController, :follow)
156 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
157 post("/accounts/:id/block", MastodonAPIController, :block)
158 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
159 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
160 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
161 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
162
163 get("/follow_requests", MastodonAPIController, :follow_requests)
164 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
165 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
166
167 post("/follows", MastodonAPIController, :follow)
168
169 get("/blocks", MastodonAPIController, :blocks)
170
171 get("/mutes", MastodonAPIController, :empty_array)
172
173 get("/timelines/home", MastodonAPIController, :home_timeline)
174
175 get("/timelines/direct", MastodonAPIController, :dm_timeline)
176
177 get("/favourites", MastodonAPIController, :favourites)
178
179 post("/statuses", MastodonAPIController, :post_status)
180 delete("/statuses/:id", MastodonAPIController, :delete_status)
181
182 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
183 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
184 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
185 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
186
187 post("/notifications/clear", MastodonAPIController, :clear_notifications)
188 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
189 get("/notifications", MastodonAPIController, :notifications)
190 get("/notifications/:id", MastodonAPIController, :get_notification)
191
192 post("/media", MastodonAPIController, :upload)
193 put("/media/:id", MastodonAPIController, :update_media)
194
195 get("/lists", MastodonAPIController, :get_lists)
196 get("/lists/:id", MastodonAPIController, :get_list)
197 delete("/lists/:id", MastodonAPIController, :delete_list)
198 post("/lists", MastodonAPIController, :create_list)
199 put("/lists/:id", MastodonAPIController, :rename_list)
200 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
201 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
202 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
203
204 get("/domain_blocks", MastodonAPIController, :domain_blocks)
205 post("/domain_blocks", MastodonAPIController, :block_domain)
206 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
207
208 get("/filters", MastodonAPIController, :get_filters)
209 post("/filters", MastodonAPIController, :create_filter)
210 get("/filters/:id", MastodonAPIController, :get_filter)
211 put("/filters/:id", MastodonAPIController, :update_filter)
212 delete("/filters/:id", MastodonAPIController, :delete_filter)
213
214 post("/push/subscription", MastodonAPIController, :create_push_subscription)
215 get("/push/subscription", MastodonAPIController, :get_push_subscription)
216 put("/push/subscription", MastodonAPIController, :update_push_subscription)
217 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
218
219 get("/suggestions", MastodonAPIController, :suggestions)
220
221 get("/endorsements", MastodonAPIController, :empty_array)
222 end
223
224 scope "/api/web", Pleroma.Web.MastodonAPI do
225 pipe_through(:authenticated_api)
226
227 put("/settings", MastodonAPIController, :put_settings)
228 end
229
230 scope "/api/v1", Pleroma.Web.MastodonAPI do
231 pipe_through(:api)
232 get("/instance", MastodonAPIController, :masto_instance)
233 get("/instance/peers", MastodonAPIController, :peers)
234 post("/apps", MastodonAPIController, :create_app)
235 get("/custom_emojis", MastodonAPIController, :custom_emojis)
236
237 get("/timelines/public", MastodonAPIController, :public_timeline)
238 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
239 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
240
241 get("/statuses/:id", MastodonAPIController, :get_status)
242 get("/statuses/:id/context", MastodonAPIController, :get_context)
243 get("/statuses/:id/card", MastodonAPIController, :empty_object)
244 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
245 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
246
247 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
248 get("/accounts/:id/followers", MastodonAPIController, :followers)
249 get("/accounts/:id/following", MastodonAPIController, :following)
250 get("/accounts/:id", MastodonAPIController, :user)
251
252 get("/trends", MastodonAPIController, :empty_array)
253
254 get("/search", MastodonAPIController, :search)
255 end
256
257 scope "/api/v2", Pleroma.Web.MastodonAPI do
258 pipe_through(:api)
259 get("/search", MastodonAPIController, :search2)
260 end
261
262 scope "/api", Pleroma.Web do
263 pipe_through(:config)
264
265 get("/help/test", TwitterAPI.UtilController, :help_test)
266 post("/help/test", TwitterAPI.UtilController, :help_test)
267 get("/statusnet/config", TwitterAPI.UtilController, :config)
268 get("/statusnet/version", TwitterAPI.UtilController, :version)
269 end
270
271 scope "/api", Pleroma.Web do
272 pipe_through(:api)
273
274 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
275 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
276 get("/users/show", TwitterAPI.Controller, :show_user)
277
278 get("/statuses/followers", TwitterAPI.Controller, :followers)
279 get("/statuses/friends", TwitterAPI.Controller, :friends)
280 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
281 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
282
283 post("/account/register", TwitterAPI.Controller, :register)
284 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
285
286 get("/search", TwitterAPI.Controller, :search)
287 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
288 end
289
290 scope "/api", Pleroma.Web do
291 pipe_through(:api)
292
293 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
294
295 get(
296 "/statuses/public_and_external_timeline",
297 TwitterAPI.Controller,
298 :public_and_external_timeline
299 )
300
301 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
302 end
303
304 scope "/api", Pleroma.Web, as: :twitter_api_search do
305 pipe_through(:api)
306 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
307 end
308
309 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
310 pipe_through(:authenticated_api)
311
312 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
313 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
314
315 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
316 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
317 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
318
319 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
320 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
321 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
322 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
323 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
324 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
325
326 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
327 # for now.
328 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
329
330 post("/statuses/update", TwitterAPI.Controller, :status_update)
331 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
332 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
333 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
334
335 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
336 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
337 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
338
339 post("/friendships/create", TwitterAPI.Controller, :follow)
340 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
341 post("/blocks/create", TwitterAPI.Controller, :block)
342 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
343
344 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
345 post("/media/upload", TwitterAPI.Controller, :upload_json)
346 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
347
348 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
349 post("/favorites/create", TwitterAPI.Controller, :favorite)
350 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
351
352 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
353
354 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
355 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
356
357 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
358 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
359
360 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
361 end
362
363 pipeline :ap_relay do
364 plug(:accepts, ["activity+json"])
365 end
366
367 pipeline :ostatus do
368 plug(:accepts, ["xml", "atom", "html", "activity+json"])
369 end
370
371 scope "/", Pleroma.Web do
372 pipe_through(:ostatus)
373
374 get("/objects/:uuid", OStatus.OStatusController, :object)
375 get("/activities/:uuid", OStatus.OStatusController, :activity)
376 get("/notice/:id", OStatus.OStatusController, :notice)
377 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
378 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
379
380 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
381 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
382 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
383 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
384 end
385
386 pipeline :activitypub do
387 plug(:accepts, ["activity+json"])
388 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
389 end
390
391 scope "/", Pleroma.Web.ActivityPub do
392 # XXX: not really ostatus
393 pipe_through(:ostatus)
394
395 get("/users/:nickname/followers", ActivityPubController, :followers)
396 get("/users/:nickname/following", ActivityPubController, :following)
397 get("/users/:nickname/outbox", ActivityPubController, :outbox)
398 end
399
400 scope "/relay", Pleroma.Web.ActivityPub do
401 pipe_through(:ap_relay)
402 get("/", ActivityPubController, :relay)
403 end
404
405 scope "/", Pleroma.Web.ActivityPub do
406 pipe_through(:activitypub)
407 post("/users/:nickname/inbox", ActivityPubController, :inbox)
408 post("/inbox", ActivityPubController, :inbox)
409 end
410
411 scope "/.well-known", Pleroma.Web do
412 pipe_through(:well_known)
413
414 get("/host-meta", WebFinger.WebFingerController, :host_meta)
415 get("/webfinger", WebFinger.WebFingerController, :webfinger)
416 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
417 end
418
419 scope "/nodeinfo", Pleroma.Web do
420 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
421 end
422
423 scope "/", Pleroma.Web.MastodonAPI do
424 pipe_through(:mastodon_html)
425
426 get("/web/login", MastodonAPIController, :login)
427 post("/web/login", MastodonAPIController, :login_post)
428 get("/web/*path", MastodonAPIController, :index)
429 delete("/auth/sign_out", MastodonAPIController, :logout)
430 end
431
432 pipeline :remote_media do
433 end
434
435 scope "/proxy/", Pleroma.Web.MediaProxy do
436 pipe_through(:remote_media)
437 get("/:sig/:url", MediaProxyController, :remote)
438 get("/:sig/:url/:filename", MediaProxyController, :remote)
439 end
440
441 if Mix.env() == :dev do
442 scope "/dev" do
443 pipe_through([:mailbox_preview])
444
445 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
446 end
447 end
448
449 scope "/", Fallback do
450 get("/registration/:token", RedirectController, :registration_page)
451 get("/*path", RedirectController, :redirector)
452
453 options("/*path", RedirectController, :empty)
454 end
455 end
456
457 defmodule Fallback.RedirectController do
458 use Pleroma.Web, :controller
459
460 def redirector(conn, _params) do
461 conn
462 |> put_resp_content_type("text/html")
463 |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html"))
464 end
465
466 def registration_page(conn, params) do
467 redirector(conn, params)
468 end
469
470 def empty(conn, _params) do
471 conn
472 |> put_status(204)
473 |> text("")
474 end
475 end