allow users with admin:metrics to read app metrics
[akkoma] / lib / pleroma / web / router.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Router do
6 use Pleroma.Web, :router
7 import Phoenix.LiveDashboard.Router
8
9 pipeline :accepts_html do
10 plug(:accepts, ["html"])
11 end
12
13 pipeline :accepts_html_xml do
14 plug(:accepts, ["html", "xml", "rss", "atom"])
15 end
16
17 pipeline :accepts_html_json do
18 plug(:accepts, ["html", "activity+json", "json"])
19 end
20
21 pipeline :accepts_html_xml_json do
22 plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
23 end
24
25 pipeline :accepts_xml_rss_atom do
26 plug(:accepts, ["xml", "rss", "atom"])
27 end
28
29 pipeline :browser do
30 plug(:accepts, ["html"])
31 plug(:fetch_session)
32 end
33
34 pipeline :oauth do
35 plug(:fetch_session)
36 plug(Pleroma.Web.Plugs.OAuthPlug)
37 plug(Pleroma.Web.Plugs.UserEnabledPlug)
38 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
39 end
40
41 # Note: expects _user_ authentication (user-unbound app-bound tokens don't qualify)
42 pipeline :expect_user_authentication do
43 plug(Pleroma.Web.Plugs.ExpectAuthenticatedCheckPlug)
44 end
45
46 # Note: expects public instance or _user_ authentication (user-unbound tokens don't qualify)
47 pipeline :expect_public_instance_or_user_authentication do
48 plug(Pleroma.Web.Plugs.ExpectPublicOrAuthenticatedCheckPlug)
49 end
50
51 pipeline :authenticate do
52 plug(Pleroma.Web.Plugs.OAuthPlug)
53 plug(Pleroma.Web.Plugs.BasicAuthDecoderPlug)
54 plug(Pleroma.Web.Plugs.UserFetcherPlug)
55 plug(Pleroma.Web.Plugs.AuthenticationPlug)
56 end
57
58 pipeline :after_auth do
59 plug(Pleroma.Web.Plugs.UserEnabledPlug)
60 plug(Pleroma.Web.Plugs.SetUserSessionIdPlug)
61 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
62 plug(Pleroma.Web.Plugs.UserTrackingPlug)
63 end
64
65 pipeline :base_api do
66 plug(:accepts, ["json"])
67 plug(:fetch_session)
68 plug(:authenticate)
69 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
70 end
71
72 pipeline :no_auth_or_privacy_expectations_api do
73 plug(:base_api)
74 plug(:after_auth)
75 plug(Pleroma.Web.Plugs.IdempotencyPlug)
76 end
77
78 # Pipeline for app-related endpoints (no user auth checks — app-bound tokens must be supported)
79 pipeline :app_api do
80 plug(:no_auth_or_privacy_expectations_api)
81 end
82
83 pipeline :api do
84 plug(:expect_public_instance_or_user_authentication)
85 plug(:no_auth_or_privacy_expectations_api)
86 end
87
88 pipeline :authenticated_api do
89 plug(:expect_user_authentication)
90 plug(:no_auth_or_privacy_expectations_api)
91 plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
92 end
93
94 pipeline :admin_api do
95 plug(:expect_user_authentication)
96 plug(:base_api)
97 plug(Pleroma.Web.Plugs.AdminSecretAuthenticationPlug)
98 plug(:after_auth)
99 plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
100 plug(Pleroma.Web.Plugs.UserIsStaffPlug)
101 plug(Pleroma.Web.Plugs.IdempotencyPlug)
102 end
103
104 pipeline :require_privileged_staff do
105 plug(Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug)
106 end
107
108 pipeline :require_admin do
109 plug(Pleroma.Web.Plugs.UserIsAdminPlug)
110 end
111
112 pipeline :mastodon_html do
113 plug(:browser)
114 plug(:authenticate)
115 plug(:after_auth)
116 end
117
118 pipeline :pleroma_html do
119 plug(:browser)
120 plug(:authenticate)
121 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
122 end
123
124 pipeline :well_known do
125 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
126 end
127
128 pipeline :config do
129 plug(:accepts, ["json", "xml"])
130 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
131 end
132
133 pipeline :pleroma_api do
134 plug(:accepts, ["html", "json"])
135 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
136 end
137
138 pipeline :mailbox_preview do
139 plug(:accepts, ["html"])
140
141 plug(:put_secure_browser_headers, %{
142 "content-security-policy" =>
143 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
144 })
145 end
146
147 pipeline :http_signature do
148 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
149 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
150 end
151
152 pipeline :static_fe do
153 plug(:fetch_session)
154 plug(:authenticate)
155 plug(Pleroma.Web.Plugs.StaticFEPlug)
156 end
157
158 scope "/api/v1/pleroma", Pleroma.Web.TwitterAPI do
159 pipe_through(:pleroma_api)
160
161 get("/password_reset/:token", PasswordController, :reset, as: :reset_password)
162 post("/password_reset", PasswordController, :do_reset, as: :reset_password)
163 get("/emoji", UtilController, :emoji)
164 get("/captcha", UtilController, :captcha)
165 get("/healthcheck", UtilController, :healthcheck)
166 post("/remote_interaction", UtilController, :remote_interaction)
167 end
168
169 scope "/api/v1/pleroma", Pleroma.Web do
170 pipe_through(:pleroma_api)
171 post("/uploader_callback/:upload_path", UploaderController, :callback)
172 end
173
174 # AdminAPI: only admins can perform these actions
175 scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
176 pipe_through([:admin_api, :require_admin])
177
178 put("/users/disable_mfa", AdminAPIController, :disable_mfa)
179
180 get("/users/:nickname/permission_group", AdminAPIController, :right_get)
181 get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
182
183 post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
184
185 delete(
186 "/users/:nickname/permission_group/:permission_group",
187 AdminAPIController,
188 :right_delete
189 )
190
191 post("/users/permission_group/:permission_group", AdminAPIController, :right_add_multiple)
192
193 delete(
194 "/users/permission_group/:permission_group",
195 AdminAPIController,
196 :right_delete_multiple
197 )
198
199 post("/users/follow", UserController, :follow)
200 post("/users/unfollow", UserController, :unfollow)
201 post("/users", UserController, :create)
202
203 patch("/users/suggest", UserController, :suggest)
204 patch("/users/unsuggest", UserController, :unsuggest)
205
206 get("/relay", RelayController, :index)
207 post("/relay", RelayController, :follow)
208 delete("/relay", RelayController, :unfollow)
209
210 patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
211 get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
212 patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
213
214 get("/instance_document/:name", InstanceDocumentController, :show)
215 patch("/instance_document/:name", InstanceDocumentController, :update)
216 delete("/instance_document/:name", InstanceDocumentController, :delete)
217
218 patch("/users/confirm_email", AdminAPIController, :confirm_email)
219 patch("/users/resend_confirmation_email", AdminAPIController, :resend_confirmation_email)
220
221 get("/config", ConfigController, :show)
222 post("/config", ConfigController, :update)
223 get("/config/descriptions", ConfigController, :descriptions)
224 get("/need_reboot", AdminAPIController, :need_reboot)
225 get("/restart", AdminAPIController, :restart)
226
227 get("/oauth_app", OAuthAppController, :index)
228 post("/oauth_app", OAuthAppController, :create)
229 patch("/oauth_app/:id", OAuthAppController, :update)
230 delete("/oauth_app/:id", OAuthAppController, :delete)
231
232 get("/media_proxy_caches", MediaProxyCacheController, :index)
233 post("/media_proxy_caches/delete", MediaProxyCacheController, :delete)
234 post("/media_proxy_caches/purge", MediaProxyCacheController, :purge)
235
236 get("/frontends", FrontendController, :index)
237 post("/frontends/install", FrontendController, :install)
238
239 post("/backups", AdminAPIController, :create_backup)
240
241 get("/announcements", AnnouncementController, :index)
242 post("/announcements", AnnouncementController, :create)
243 get("/announcements/:id", AnnouncementController, :show)
244 patch("/announcements/:id", AnnouncementController, :change)
245 delete("/announcements/:id", AnnouncementController, :delete)
246 end
247
248 # AdminAPI: admins and mods (staff) can perform these actions (if enabled by config)
249 scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
250 pipe_through([:admin_api, :require_privileged_staff])
251
252 delete("/users", UserController, :delete)
253
254 get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
255 patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
256
257 get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
258
259 get("/statuses", StatusController, :index)
260 end
261
262 # AdminAPI: admins and mods (staff) can perform these actions
263 scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
264 pipe_through(:admin_api)
265
266 put("/users/tag", AdminAPIController, :tag_users)
267 delete("/users/tag", AdminAPIController, :untag_users)
268
269 patch("/users/:nickname/toggle_activation", UserController, :toggle_activation)
270 patch("/users/activate", UserController, :activate)
271 patch("/users/deactivate", UserController, :deactivate)
272 patch("/users/approve", UserController, :approve)
273
274 post("/users/invite_token", InviteController, :create)
275 get("/users/invites", InviteController, :index)
276 post("/users/revoke_invite", InviteController, :revoke)
277 post("/users/email_invite", InviteController, :email)
278
279 get("/users", UserController, :index)
280 get("/users/:nickname", UserController, :show)
281
282 get("/instances/:instance/statuses", InstanceController, :list_statuses)
283 delete("/instances/:instance", InstanceController, :delete)
284
285 get("/reports", ReportController, :index)
286 get("/reports/:id", ReportController, :show)
287 patch("/reports", ReportController, :update)
288 post("/reports/:id/notes", ReportController, :notes_create)
289 delete("/reports/:report_id/notes/:id", ReportController, :notes_delete)
290
291 get("/statuses/:id", StatusController, :show)
292 put("/statuses/:id", StatusController, :update)
293 delete("/statuses/:id", StatusController, :delete)
294
295 get("/moderation_log", AdminAPIController, :list_log)
296
297 post("/reload_emoji", AdminAPIController, :reload_emoji)
298 get("/stats", AdminAPIController, :stats)
299 end
300
301 scope "/api/v1/pleroma/emoji", Pleroma.Web.PleromaAPI do
302 scope "/pack" do
303 pipe_through(:admin_api)
304
305 post("/", EmojiPackController, :create)
306 patch("/", EmojiPackController, :update)
307 delete("/", EmojiPackController, :delete)
308 end
309
310 scope "/pack" do
311 pipe_through(:api)
312
313 get("/", EmojiPackController, :show)
314 end
315
316 # Modifying packs
317 scope "/packs" do
318 pipe_through(:admin_api)
319
320 get("/import", EmojiPackController, :import_from_filesystem)
321 get("/remote", EmojiPackController, :remote)
322 post("/download", EmojiPackController, :download)
323
324 post("/files", EmojiFileController, :create)
325 patch("/files", EmojiFileController, :update)
326 delete("/files", EmojiFileController, :delete)
327 end
328
329 # Pack info / downloading
330 scope "/packs" do
331 pipe_through(:api)
332
333 get("/", EmojiPackController, :index)
334 get("/archive", EmojiPackController, :archive)
335 end
336 end
337
338 scope "/", Pleroma.Web.TwitterAPI do
339 pipe_through(:pleroma_html)
340
341 post("/main/ostatus", UtilController, :remote_subscribe)
342 get("/main/ostatus", UtilController, :show_subscribe_form)
343 get("/ostatus_subscribe", RemoteFollowController, :follow)
344 post("/ostatus_subscribe", RemoteFollowController, :do_follow)
345 end
346
347 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
348 pipe_through(:authenticated_api)
349
350 post("/change_email", UtilController, :change_email)
351 post("/change_password", UtilController, :change_password)
352 post("/delete_account", UtilController, :delete_account)
353 put("/notification_settings", UtilController, :update_notificaton_settings)
354 post("/disable_account", UtilController, :disable_account)
355 post("/move_account", UtilController, :move_account)
356
357 put("/aliases", UtilController, :add_alias)
358 get("/aliases", UtilController, :list_aliases)
359 delete("/aliases", UtilController, :delete_alias)
360 end
361
362 scope "/api/pleroma", Pleroma.Web.PleromaAPI do
363 pipe_through(:authenticated_api)
364
365 post("/mutes_import", UserImportController, :mutes)
366 post("/blocks_import", UserImportController, :blocks)
367 post("/follow_import", UserImportController, :follow)
368
369 get("/accounts/mfa", TwoFactorAuthenticationController, :settings)
370 get("/accounts/mfa/backup_codes", TwoFactorAuthenticationController, :backup_codes)
371 get("/accounts/mfa/setup/:method", TwoFactorAuthenticationController, :setup)
372 post("/accounts/mfa/confirm/:method", TwoFactorAuthenticationController, :confirm)
373 delete("/accounts/mfa/:method", TwoFactorAuthenticationController, :disable)
374 end
375
376 scope "/oauth", Pleroma.Web.OAuth do
377 # Note: use /api/v1/accounts/verify_credentials for userinfo of signed-in user
378
379 get("/registration_details", OAuthController, :registration_details)
380
381 post("/mfa/verify", MFAController, :verify, as: :mfa_verify)
382 get("/mfa", MFAController, :show)
383
384 scope [] do
385 pipe_through(:oauth)
386
387 get("/authorize", OAuthController, :authorize)
388 post("/authorize", OAuthController, :create_authorization)
389 end
390
391 scope [] do
392 pipe_through(:fetch_session)
393
394 post("/token", OAuthController, :token_exchange)
395 post("/revoke", OAuthController, :token_revoke)
396 post("/mfa/challenge", MFAController, :challenge)
397 end
398
399 scope [] do
400 pipe_through(:browser)
401
402 get("/prepare_request", OAuthController, :prepare_request)
403 get("/:provider", OAuthController, :request)
404 get("/:provider/callback", OAuthController, :callback)
405 post("/register", OAuthController, :register)
406 end
407 end
408
409 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
410 pipe_through(:api)
411
412 get("/apps", AppController, :index)
413 get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
414 get("/statuses/:id/reactions", EmojiReactionController, :index)
415 end
416
417 scope "/api/v0/pleroma", Pleroma.Web.PleromaAPI do
418 pipe_through(:authenticated_api)
419 get("/reports", ReportController, :index)
420 get("/reports/:id", ReportController, :show)
421 end
422
423 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
424 scope [] do
425 pipe_through(:authenticated_api)
426
427 get("/conversations/:id/statuses", ConversationController, :statuses)
428 get("/conversations/:id", ConversationController, :show)
429 post("/conversations/read", ConversationController, :mark_as_read)
430 patch("/conversations/:id", ConversationController, :update)
431
432 put("/statuses/:id/reactions/:emoji", EmojiReactionController, :create)
433 delete("/statuses/:id/reactions/:emoji", EmojiReactionController, :delete)
434 post("/notifications/read", NotificationController, :mark_as_read)
435
436 get("/mascot", MascotController, :show)
437 put("/mascot", MascotController, :update)
438
439 get("/backups", BackupController, :index)
440 post("/backups", BackupController, :create)
441 end
442
443 scope [] do
444 pipe_through(:api)
445 get("/accounts/:id/favourites", AccountController, :favourites)
446 end
447
448 scope [] do
449 pipe_through(:authenticated_api)
450
451 post("/accounts/:id/subscribe", AccountController, :subscribe)
452 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
453 end
454
455 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
456 end
457
458 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
459 pipe_through(:api)
460 get("/federation_status", InstancesController, :show)
461 end
462
463 scope "/api/v1", Pleroma.Web.PleromaAPI do
464 pipe_through(:authenticated_api)
465 put("/statuses/:id/emoji_reactions/:emoji", EmojiReactionController, :create)
466 end
467
468 scope "/api/v1/akkoma", Pleroma.Web.AkkomaAPI do
469 pipe_through(:authenticated_api)
470 get("/metrics", MetricsController, :show)
471 get("/translation/languages", TranslationController, :languages)
472
473 get("/frontend_settings/:frontend_name", FrontendSettingsController, :list_profiles)
474
475 get(
476 "/frontend_settings/:frontend_name/:profile_name",
477 FrontendSettingsController,
478 :get_profile
479 )
480
481 put(
482 "/frontend_settings/:frontend_name/:profile_name",
483 FrontendSettingsController,
484 :update_profile
485 )
486
487 delete(
488 "/frontend_settings/:frontend_name/:profile_name",
489 FrontendSettingsController,
490 :delete_profile
491 )
492 end
493
494 scope "/api/v1", Pleroma.Web.MastodonAPI do
495 pipe_through(:authenticated_api)
496
497 get("/accounts/verify_credentials", AccountController, :verify_credentials)
498 patch("/accounts/update_credentials", AccountController, :update_credentials)
499
500 get("/accounts/relationships", AccountController, :relationships)
501 get("/accounts/:id/lists", AccountController, :lists)
502 get("/accounts/:id/identity_proofs", AccountController, :identity_proofs)
503 get("/endorsements", AccountController, :endorsements)
504 get("/blocks", AccountController, :blocks)
505 get("/mutes", AccountController, :mutes)
506
507 post("/follows", AccountController, :follow_by_uri)
508 post("/accounts/:id/follow", AccountController, :follow)
509 post("/accounts/:id/unfollow", AccountController, :unfollow)
510 post("/accounts/:id/block", AccountController, :block)
511 post("/accounts/:id/unblock", AccountController, :unblock)
512 post("/accounts/:id/mute", AccountController, :mute)
513 post("/accounts/:id/unmute", AccountController, :unmute)
514 post("/accounts/:id/note", AccountController, :note)
515 post("/accounts/:id/remove_from_followers", AccountController, :remove_from_followers)
516
517 get("/conversations", ConversationController, :index)
518 post("/conversations/:id/read", ConversationController, :mark_as_read)
519 delete("/conversations/:id", ConversationController, :delete)
520
521 get("/domain_blocks", DomainBlockController, :index)
522 post("/domain_blocks", DomainBlockController, :create)
523 delete("/domain_blocks", DomainBlockController, :delete)
524
525 get("/filters", FilterController, :index)
526
527 post("/filters", FilterController, :create)
528 get("/filters/:id", FilterController, :show)
529 put("/filters/:id", FilterController, :update)
530 delete("/filters/:id", FilterController, :delete)
531
532 get("/follow_requests", FollowRequestController, :index)
533 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
534 post("/follow_requests/:id/reject", FollowRequestController, :reject)
535
536 get("/lists", ListController, :index)
537 get("/lists/:id", ListController, :show)
538 get("/lists/:id/accounts", ListController, :list_accounts)
539
540 delete("/lists/:id", ListController, :delete)
541 post("/lists", ListController, :create)
542 put("/lists/:id", ListController, :update)
543 post("/lists/:id/accounts", ListController, :add_to_list)
544 delete("/lists/:id/accounts", ListController, :remove_from_list)
545
546 get("/markers", MarkerController, :index)
547 post("/markers", MarkerController, :upsert)
548
549 post("/media", MediaController, :create)
550 get("/media/:id", MediaController, :show)
551 put("/media/:id", MediaController, :update)
552
553 get("/notifications", NotificationController, :index)
554 get("/notifications/:id", NotificationController, :show)
555
556 post("/notifications/:id/dismiss", NotificationController, :dismiss)
557 post("/notifications/clear", NotificationController, :clear)
558 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
559
560 post("/polls/:id/votes", PollController, :vote)
561
562 post("/reports", ReportController, :create)
563
564 get("/scheduled_statuses", ScheduledActivityController, :index)
565 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
566
567 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
568 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
569
570 # Unlike `GET /api/v1/accounts/:id/favourites`, demands authentication
571 get("/favourites", StatusController, :favourites)
572 get("/bookmarks", StatusController, :bookmarks)
573
574 post("/statuses", StatusController, :create)
575 put("/statuses/:id", StatusController, :update)
576 delete("/statuses/:id", StatusController, :delete)
577 post("/statuses/:id/reblog", StatusController, :reblog)
578 post("/statuses/:id/unreblog", StatusController, :unreblog)
579 post("/statuses/:id/favourite", StatusController, :favourite)
580 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
581 post("/statuses/:id/pin", StatusController, :pin)
582 post("/statuses/:id/unpin", StatusController, :unpin)
583 post("/statuses/:id/bookmark", StatusController, :bookmark)
584 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
585 post("/statuses/:id/mute", StatusController, :mute_conversation)
586 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
587 get("/statuses/:id/translations/:language", StatusController, :translate)
588
589 post("/push/subscription", SubscriptionController, :create)
590 get("/push/subscription", SubscriptionController, :show)
591 put("/push/subscription", SubscriptionController, :update)
592 delete("/push/subscription", SubscriptionController, :delete)
593
594 get("/suggestions", SuggestionController, :index)
595 delete("/suggestions/:account_id", SuggestionController, :dismiss)
596
597 get("/timelines/home", TimelineController, :home)
598 get("/timelines/direct", TimelineController, :direct)
599 get("/timelines/list/:list_id", TimelineController, :list)
600 get("/timelines/bubble", TimelineController, :bubble)
601
602 get("/announcements", AnnouncementController, :index)
603 post("/announcements/:id/dismiss", AnnouncementController, :mark_read)
604
605 get("/tags/:id", TagController, :show)
606 post("/tags/:id/follow", TagController, :follow)
607 post("/tags/:id/unfollow", TagController, :unfollow)
608 end
609
610 scope "/api/web", Pleroma.Web do
611 pipe_through(:authenticated_api)
612
613 # Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
614 put("/settings", MastoFEController, :put_settings)
615 end
616
617 scope "/api/v1", Pleroma.Web.MastodonAPI do
618 pipe_through(:app_api)
619
620 post("/apps", AppController, :create)
621 get("/apps/verify_credentials", AppController, :verify_credentials)
622 end
623
624 scope "/api/v1", Pleroma.Web.MastodonAPI do
625 pipe_through(:api)
626
627 get("/accounts/search", SearchController, :account_search)
628 get("/accounts/lookup", AccountController, :lookup)
629
630 get("/accounts/:id/statuses", AccountController, :statuses)
631 get("/accounts/:id/followers", AccountController, :followers)
632 get("/accounts/:id/following", AccountController, :following)
633 get("/accounts/:id", AccountController, :show)
634
635 post("/accounts", AccountController, :create)
636
637 get("/instance", InstanceController, :show)
638 get("/instance/peers", InstanceController, :peers)
639
640 get("/statuses", StatusController, :index)
641 get("/statuses/:id", StatusController, :show)
642 get("/statuses/:id/context", StatusController, :context)
643 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
644 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
645 get("/statuses/:id/history", StatusController, :show_history)
646 get("/statuses/:id/source", StatusController, :show_source)
647
648 get("/custom_emojis", CustomEmojiController, :index)
649
650 get("/trends", MastodonAPIController, :empty_array)
651
652 get("/timelines/public", TimelineController, :public)
653 get("/timelines/tag/:tag", TimelineController, :hashtag)
654
655 get("/polls/:id", PollController, :show)
656
657 get("/directory", DirectoryController, :index)
658 end
659
660 scope "/api/v2", Pleroma.Web.MastodonAPI do
661 pipe_through(:api)
662 get("/search", SearchController, :search2)
663
664 post("/media", MediaController, :create2)
665
666 get("/suggestions", SuggestionController, :index2)
667 end
668
669 scope "/api", Pleroma.Web do
670 pipe_through(:config)
671
672 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
673 end
674
675 scope "/api", Pleroma.Web do
676 pipe_through(:api)
677
678 get(
679 "/account/confirm_email/:user_id/:token",
680 TwitterAPI.Controller,
681 :confirm_email,
682 as: :confirm_email
683 )
684 end
685
686 scope "/api" do
687 pipe_through(:base_api)
688
689 get("/openapi", OpenApiSpex.Plug.RenderSpec, [])
690 end
691
692 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
693 pipe_through(:authenticated_api)
694
695 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
696 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
697 end
698
699 scope "/", Pleroma.Web do
700 # Note: html format is supported only if static FE is enabled
701 # Note: http signature is only considered for json requests (no auth for non-json requests)
702 pipe_through([:accepts_html_json, :http_signature, :static_fe])
703
704 get("/objects/:uuid", OStatus.OStatusController, :object)
705 get("/activities/:uuid", OStatus.OStatusController, :activity)
706 get("/notice/:id", OStatus.OStatusController, :notice)
707
708 # Notice compatibility routes for other frontends
709 get("/@:nickname/:id", OStatus.OStatusController, :notice)
710 get("/@:nickname/posts/:id", OStatus.OStatusController, :notice)
711 get("/:nickname/status/:id", OStatus.OStatusController, :notice)
712
713 # Mastodon compatibility routes
714 get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
715 get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
716 end
717
718 scope "/", Pleroma.Web do
719 # Note: html format is supported only if static FE is enabled
720 # Note: http signature is only considered for json requests (no auth for non-json requests)
721 pipe_through([:accepts_html_xml_json, :http_signature, :static_fe])
722
723 # Note: returns user _profile_ for json requests, redirects to user _feed_ for non-json ones
724 get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
725 end
726
727 scope "/", Pleroma.Web do
728 # Note: html format is supported only if static FE is enabled
729 pipe_through([:accepts_html_xml, :static_fe])
730
731 get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
732 end
733
734 scope "/", Pleroma.Web.StaticFE do
735 # Profile pages for static-fe
736 get("/users/:nickname/with_replies", StaticFEController, :show)
737 get("/users/:nickname/media", StaticFEController, :show)
738 end
739
740 scope "/", Pleroma.Web do
741 pipe_through(:accepts_html)
742 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
743 end
744
745 scope "/", Pleroma.Web do
746 pipe_through(:accepts_xml_rss_atom)
747 get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
748 end
749
750 scope "/", Pleroma.Web do
751 pipe_through(:browser)
752 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
753 end
754
755 pipeline :ap_service_actor do
756 plug(:accepts, ["activity+json", "json"])
757 end
758
759 # Server to Server (S2S) AP interactions
760 pipeline :activitypub do
761 plug(:ap_service_actor)
762 plug(:http_signature)
763 end
764
765 # Client to Server (C2S) AP interactions
766 pipeline :activitypub_client do
767 plug(:ap_service_actor)
768 plug(:fetch_session)
769 plug(:authenticate)
770 plug(:after_auth)
771 end
772
773 scope "/", Pleroma.Web.ActivityPub do
774 pipe_through([:activitypub_client])
775
776 get("/api/ap/whoami", ActivityPubController, :whoami)
777 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
778
779 get("/users/:nickname/outbox", ActivityPubController, :outbox)
780 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
781 post("/api/ap/upload_media", ActivityPubController, :upload_media)
782
783 get("/users/:nickname/collections/featured", ActivityPubController, :pinned)
784 end
785
786 scope "/", Pleroma.Web.ActivityPub do
787 # Note: html format is supported only if static FE is enabled
788 pipe_through([:accepts_html_json, :static_fe, :activitypub_client])
789
790 # The following two are S2S as well, see `ActivityPub.fetch_follow_information_for_user/1`:
791 get("/users/:nickname/followers", ActivityPubController, :followers)
792 get("/users/:nickname/following", ActivityPubController, :following)
793 end
794
795 scope "/", Pleroma.Web.ActivityPub do
796 pipe_through(:activitypub)
797 post("/inbox", ActivityPubController, :inbox)
798 post("/users/:nickname/inbox", ActivityPubController, :inbox)
799 end
800
801 scope "/relay", Pleroma.Web.ActivityPub do
802 pipe_through(:ap_service_actor)
803
804 get("/", ActivityPubController, :relay)
805
806 scope [] do
807 pipe_through(:http_signature)
808 post("/inbox", ActivityPubController, :inbox)
809 end
810
811 get("/following", ActivityPubController, :relay_following)
812 get("/followers", ActivityPubController, :relay_followers)
813 end
814
815 scope "/internal/fetch", Pleroma.Web.ActivityPub do
816 pipe_through(:ap_service_actor)
817
818 get("/", ActivityPubController, :internal_fetch)
819 post("/inbox", ActivityPubController, :inbox)
820 end
821
822 scope "/.well-known", Pleroma.Web do
823 pipe_through(:well_known)
824
825 get("/host-meta", WebFinger.WebFingerController, :host_meta)
826 get("/webfinger", WebFinger.WebFingerController, :webfinger)
827 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
828 end
829
830 scope "/nodeinfo", Pleroma.Web do
831 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
832 end
833
834 scope "/", Pleroma.Web do
835 pipe_through(:api)
836
837 get("/manifest.json", ManifestController, :show)
838 get("/web/manifest.json", MastoFEController, :manifest)
839 end
840
841 scope "/", Pleroma.Web do
842 pipe_through(:mastodon_html)
843
844 get("/web/login", MastodonAPI.AuthController, :login)
845 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
846
847 post("/auth/password", MastodonAPI.AuthController, :password_reset)
848
849 get("/web/*path", MastoFEController, :index)
850
851 get("/embed/:id", EmbedController, :show)
852 end
853
854 scope "/proxy/", Pleroma.Web do
855 get("/preview/:sig/:url", MediaProxy.MediaProxyController, :preview)
856 get("/preview/:sig/:url/:filename", MediaProxy.MediaProxyController, :preview)
857 get("/:sig/:url", MediaProxy.MediaProxyController, :remote)
858 get("/:sig/:url/:filename", MediaProxy.MediaProxyController, :remote)
859 end
860
861 if Pleroma.Config.get(:env) == :dev do
862 scope "/dev" do
863 pipe_through([:mailbox_preview])
864
865 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
866 end
867 end
868
869 scope "/" do
870 pipe_through([:pleroma_html, :authenticate, :require_admin])
871
872 live_dashboard("/phoenix/live_dashboard",
873 metrics: {Pleroma.Web.Telemetry, :live_dashboard_metrics},
874 csp_nonce_assign_key: :csp_nonce
875 )
876 end
877
878 # Test-only routes needed to test action dispatching and plug chain execution
879 if Pleroma.Config.get(:env) == :test do
880 @test_actions [
881 :do_oauth_check,
882 :fallback_oauth_check,
883 :skip_oauth_check,
884 :fallback_oauth_skip_publicity_check,
885 :skip_oauth_skip_publicity_check,
886 :missing_oauth_check_definition
887 ]
888
889 scope "/test/api", Pleroma.Tests do
890 pipe_through(:api)
891
892 for action <- @test_actions do
893 get("/#{action}", AuthTestController, action)
894 end
895 end
896
897 scope "/test/authenticated_api", Pleroma.Tests do
898 pipe_through(:authenticated_api)
899
900 for action <- @test_actions do
901 get("/#{action}", AuthTestController, action)
902 end
903 end
904 end
905
906 scope "/", Pleroma.Web.MongooseIM do
907 get("/user_exists", MongooseIMController, :user_exists)
908 get("/check_password", MongooseIMController, :check_password)
909 end
910
911 scope "/", Pleroma.Web.Fallback do
912 get("/registration/:token", RedirectController, :registration_page)
913 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
914 get("/api/*path", RedirectController, :api_not_implemented)
915 get("/*path", RedirectController, :redirector_with_preload)
916
917 options("/*path", RedirectController, :empty)
918 end
919
920 # TODO: Change to Phoenix.Router.routes/1 for Phoenix 1.6.0+
921 def get_api_routes do
922 __MODULE__.__routes__()
923 |> Enum.reject(fn r -> r.plug == Pleroma.Web.Fallback.RedirectController end)
924 |> Enum.map(fn r ->
925 r.path
926 |> String.split("/", trim: true)
927 |> List.first()
928 end)
929 |> Enum.uniq()
930 end
931 end