1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Router do
6 use Pleroma.Web, :router
9 plug(:accepts, ["html"])
15 plug(Pleroma.Plugs.OAuthPlug)
16 plug(Pleroma.Plugs.UserEnabledPlug)
19 pipeline :authenticate do
20 plug(Pleroma.Plugs.OAuthPlug)
21 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
22 plug(Pleroma.Plugs.UserFetcherPlug)
23 plug(Pleroma.Plugs.SessionAuthenticationPlug)
24 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
25 plug(Pleroma.Plugs.AuthenticationPlug)
28 pipeline :after_auth do
29 plug(Pleroma.Plugs.UserEnabledPlug)
30 plug(Pleroma.Plugs.SetUserSessionIdPlug)
31 plug(Pleroma.Plugs.EnsureUserKeyPlug)
35 plug(:accepts, ["json"])
38 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
44 plug(Pleroma.Plugs.IdempotencyPlug)
47 pipeline :authenticated_api do
49 plug(Pleroma.Plugs.AuthExpectedPlug)
51 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
52 plug(Pleroma.Plugs.IdempotencyPlug)
55 pipeline :admin_api do
57 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
59 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
60 plug(Pleroma.Plugs.UserIsAdminPlug)
61 plug(Pleroma.Plugs.IdempotencyPlug)
64 pipeline :mastodon_html do
70 pipeline :pleroma_html do
73 plug(Pleroma.Plugs.EnsureUserKeyPlug)
76 pipeline :well_known do
77 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
81 plug(:accepts, ["json", "xml"])
82 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
85 pipeline :pleroma_api do
86 plug(:accepts, ["html", "json"])
87 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
90 pipeline :mailbox_preview do
91 plug(:accepts, ["html"])
93 plug(:put_secure_browser_headers, %{
94 "content-security-policy" =>
95 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
99 pipeline :http_signature do
100 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
101 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
104 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
105 pipe_through(:pleroma_api)
107 get("/password_reset/:token", PasswordController, :reset, as: :reset_password)
108 post("/password_reset", PasswordController, :do_reset, as: :reset_password)
109 get("/emoji", UtilController, :emoji)
110 get("/captcha", UtilController, :captcha)
111 get("/healthcheck", UtilController, :healthcheck)
114 scope "/api/pleroma", Pleroma.Web do
115 pipe_through(:pleroma_api)
116 post("/uploader_callback/:upload_path", UploaderController, :callback)
119 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
120 pipe_through(:admin_api)
122 post("/users/follow", AdminAPIController, :user_follow)
123 post("/users/unfollow", AdminAPIController, :user_unfollow)
125 delete("/users", AdminAPIController, :user_delete)
126 post("/users", AdminAPIController, :users_create)
127 patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
128 patch("/users/activate", AdminAPIController, :user_activate)
129 patch("/users/deactivate", AdminAPIController, :user_deactivate)
130 put("/users/tag", AdminAPIController, :tag_users)
131 delete("/users/tag", AdminAPIController, :untag_users)
133 get("/users/:nickname/permission_group", AdminAPIController, :right_get)
134 get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
136 post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
139 "/users/:nickname/permission_group/:permission_group",
144 post("/users/permission_group/:permission_group", AdminAPIController, :right_add_multiple)
147 "/users/permission_group/:permission_group",
149 :right_delete_multiple
152 get("/relay", AdminAPIController, :relay_list)
153 post("/relay", AdminAPIController, :relay_follow)
154 delete("/relay", AdminAPIController, :relay_unfollow)
156 post("/users/invite_token", AdminAPIController, :create_invite_token)
157 get("/users/invites", AdminAPIController, :invites)
158 post("/users/revoke_invite", AdminAPIController, :revoke_invite)
159 post("/users/email_invite", AdminAPIController, :email_invite)
161 get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
162 patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
163 get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
164 patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
166 get("/users", AdminAPIController, :list_users)
167 get("/users/:nickname", AdminAPIController, :user_show)
168 get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
170 get("/instances/:instance/statuses", AdminAPIController, :list_instance_statuses)
172 patch("/users/confirm_email", AdminAPIController, :confirm_email)
173 patch("/users/resend_confirmation_email", AdminAPIController, :resend_confirmation_email)
175 get("/reports", AdminAPIController, :list_reports)
176 get("/reports/:id", AdminAPIController, :report_show)
177 patch("/reports", AdminAPIController, :reports_update)
178 post("/reports/:id/notes", AdminAPIController, :report_notes_create)
179 delete("/reports/:report_id/notes/:id", AdminAPIController, :report_notes_delete)
181 put("/statuses/:id", AdminAPIController, :status_update)
182 delete("/statuses/:id", AdminAPIController, :status_delete)
183 get("/statuses", AdminAPIController, :list_statuses)
185 get("/config", AdminAPIController, :config_show)
186 post("/config", AdminAPIController, :config_update)
187 get("/config/descriptions", AdminAPIController, :config_descriptions)
188 get("/need_reboot", AdminAPIController, :need_reboot)
189 get("/restart", AdminAPIController, :restart)
191 get("/moderation_log", AdminAPIController, :list_log)
193 post("/reload_emoji", AdminAPIController, :reload_emoji)
194 get("/stats", AdminAPIController, :stats)
196 get("/oauth_app", AdminAPIController, :oauth_app_list)
197 post("/oauth_app", AdminAPIController, :oauth_app_create)
198 patch("/oauth_app/:id", AdminAPIController, :oauth_app_update)
199 delete("/oauth_app/:id", AdminAPIController, :oauth_app_delete)
202 scope "/api/pleroma/emoji", Pleroma.Web.PleromaAPI do
205 pipe_through(:admin_api)
207 post("/import_from_fs", EmojiAPIController, :import_from_fs)
209 post("/:pack_name/update_file", EmojiAPIController, :update_file)
210 post("/:pack_name/update_metadata", EmojiAPIController, :update_metadata)
211 put("/:name", EmojiAPIController, :create)
212 delete("/:name", EmojiAPIController, :delete)
213 post("/download_from", EmojiAPIController, :download_from)
214 post("/list_from", EmojiAPIController, :list_from)
218 # Pack info / downloading
219 get("/", EmojiAPIController, :list_packs)
220 get("/:name/download_shared/", EmojiAPIController, :download_shared)
224 scope "/", Pleroma.Web.TwitterAPI do
225 pipe_through(:pleroma_html)
227 post("/main/ostatus", UtilController, :remote_subscribe)
228 get("/ostatus_subscribe", RemoteFollowController, :follow)
230 post("/ostatus_subscribe", RemoteFollowController, :do_follow)
233 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
234 pipe_through(:authenticated_api)
236 post("/change_email", UtilController, :change_email)
237 post("/change_password", UtilController, :change_password)
238 post("/delete_account", UtilController, :delete_account)
239 put("/notification_settings", UtilController, :update_notificaton_settings)
240 post("/disable_account", UtilController, :disable_account)
242 post("/blocks_import", UtilController, :blocks_import)
243 post("/follow_import", UtilController, :follow_import)
246 scope "/oauth", Pleroma.Web.OAuth do
249 get("/authorize", OAuthController, :authorize)
252 post("/authorize", OAuthController, :create_authorization)
253 post("/token", OAuthController, :token_exchange)
254 post("/revoke", OAuthController, :token_revoke)
255 get("/registration_details", OAuthController, :registration_details)
258 pipe_through(:browser)
260 get("/prepare_request", OAuthController, :prepare_request)
261 get("/:provider", OAuthController, :request)
262 get("/:provider/callback", OAuthController, :callback)
263 post("/register", OAuthController, :register)
267 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
270 get("/statuses/:id/reactions/:emoji", PleromaAPIController, :emoji_reactions_by)
271 get("/statuses/:id/reactions", PleromaAPIController, :emoji_reactions_by)
274 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
276 pipe_through(:authenticated_api)
278 post("/chats/by-ap-id/:ap_id", ChatController, :create)
279 get("/chats", ChatController, :index)
280 get("/chats/:id/messages", ChatController, :messages)
281 post("/chats/:id/messages", ChatController, :post_chat_message)
285 pipe_through(:authenticated_api)
287 get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
288 get("/conversations/:id", PleromaAPIController, :conversation)
289 post("/conversations/read", PleromaAPIController, :read_conversations)
293 pipe_through(:authenticated_api)
295 patch("/conversations/:id", PleromaAPIController, :update_conversation)
296 put("/statuses/:id/reactions/:emoji", PleromaAPIController, :react_with_emoji)
297 delete("/statuses/:id/reactions/:emoji", PleromaAPIController, :unreact_with_emoji)
298 post("/notifications/read", PleromaAPIController, :read_notification)
300 patch("/accounts/update_avatar", AccountController, :update_avatar)
301 patch("/accounts/update_banner", AccountController, :update_banner)
302 patch("/accounts/update_background", AccountController, :update_background)
304 get("/mascot", MascotController, :show)
305 put("/mascot", MascotController, :update)
307 post("/scrobble", ScrobbleController, :new_scrobble)
312 get("/accounts/:id/favourites", AccountController, :favourites)
316 pipe_through(:authenticated_api)
318 post("/accounts/:id/subscribe", AccountController, :subscribe)
319 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
322 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
325 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
327 get("/accounts/:id/scrobbles", ScrobbleController, :user_scrobbles)
330 scope "/api/v1", Pleroma.Web.MastodonAPI do
331 pipe_through(:authenticated_api)
333 get("/accounts/verify_credentials", AccountController, :verify_credentials)
335 get("/accounts/relationships", AccountController, :relationships)
337 get("/accounts/:id/lists", AccountController, :lists)
338 get("/accounts/:id/identity_proofs", AccountController, :identity_proofs)
340 get("/follow_requests", FollowRequestController, :index)
341 get("/blocks", AccountController, :blocks)
342 get("/mutes", AccountController, :mutes)
344 get("/timelines/home", TimelineController, :home)
345 get("/timelines/direct", TimelineController, :direct)
347 get("/favourites", StatusController, :favourites)
348 get("/bookmarks", StatusController, :bookmarks)
350 get("/notifications", NotificationController, :index)
351 get("/notifications/:id", NotificationController, :show)
352 post("/notifications/:id/dismiss", NotificationController, :dismiss)
353 post("/notifications/clear", NotificationController, :clear)
354 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
355 # Deprecated: was removed in Mastodon v3, use `/notifications/:id/dismiss` instead
356 post("/notifications/dismiss", NotificationController, :dismiss)
358 get("/scheduled_statuses", ScheduledActivityController, :index)
359 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
361 get("/lists", ListController, :index)
362 get("/lists/:id", ListController, :show)
363 get("/lists/:id/accounts", ListController, :list_accounts)
365 get("/domain_blocks", DomainBlockController, :index)
367 get("/filters", FilterController, :index)
369 get("/suggestions", SuggestionController, :index)
371 get("/conversations", ConversationController, :index)
372 post("/conversations/:id/read", ConversationController, :read)
374 get("/endorsements", AccountController, :endorsements)
376 patch("/accounts/update_credentials", AccountController, :update_credentials)
378 post("/statuses", StatusController, :create)
379 delete("/statuses/:id", StatusController, :delete)
381 post("/statuses/:id/reblog", StatusController, :reblog)
382 post("/statuses/:id/unreblog", StatusController, :unreblog)
383 post("/statuses/:id/favourite", StatusController, :favourite)
384 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
385 post("/statuses/:id/pin", StatusController, :pin)
386 post("/statuses/:id/unpin", StatusController, :unpin)
387 post("/statuses/:id/bookmark", StatusController, :bookmark)
388 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
389 post("/statuses/:id/mute", StatusController, :mute_conversation)
390 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
392 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
393 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
395 post("/polls/:id/votes", PollController, :vote)
397 post("/media", MediaController, :create)
398 put("/media/:id", MediaController, :update)
400 delete("/lists/:id", ListController, :delete)
401 post("/lists", ListController, :create)
402 put("/lists/:id", ListController, :update)
404 post("/lists/:id/accounts", ListController, :add_to_list)
405 delete("/lists/:id/accounts", ListController, :remove_from_list)
407 post("/filters", FilterController, :create)
408 get("/filters/:id", FilterController, :show)
409 put("/filters/:id", FilterController, :update)
410 delete("/filters/:id", FilterController, :delete)
412 post("/reports", ReportController, :create)
414 post("/follows", AccountController, :follows)
415 post("/accounts/:id/follow", AccountController, :follow)
416 post("/accounts/:id/unfollow", AccountController, :unfollow)
417 post("/accounts/:id/block", AccountController, :block)
418 post("/accounts/:id/unblock", AccountController, :unblock)
419 post("/accounts/:id/mute", AccountController, :mute)
420 post("/accounts/:id/unmute", AccountController, :unmute)
422 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
423 post("/follow_requests/:id/reject", FollowRequestController, :reject)
425 post("/domain_blocks", DomainBlockController, :create)
426 delete("/domain_blocks", DomainBlockController, :delete)
428 post("/push/subscription", SubscriptionController, :create)
429 get("/push/subscription", SubscriptionController, :get)
430 put("/push/subscription", SubscriptionController, :update)
431 delete("/push/subscription", SubscriptionController, :delete)
433 get("/markers", MarkerController, :index)
434 post("/markers", MarkerController, :upsert)
437 scope "/api/web", Pleroma.Web do
438 pipe_through(:authenticated_api)
440 put("/settings", MastoFEController, :put_settings)
443 scope "/api/v1", Pleroma.Web.MastodonAPI do
446 post("/accounts", AccountController, :create)
447 get("/accounts/search", SearchController, :account_search)
449 get("/instance", InstanceController, :show)
450 get("/instance/peers", InstanceController, :peers)
452 post("/apps", AppController, :create)
453 get("/apps/verify_credentials", AppController, :verify_credentials)
455 get("/statuses/:id/card", StatusController, :card)
456 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
457 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
459 get("/custom_emojis", CustomEmojiController, :index)
461 get("/trends", MastodonAPIController, :empty_array)
463 get("/timelines/public", TimelineController, :public)
464 get("/timelines/tag/:tag", TimelineController, :hashtag)
465 get("/timelines/list/:list_id", TimelineController, :list)
467 get("/statuses", StatusController, :index)
468 get("/statuses/:id", StatusController, :show)
469 get("/statuses/:id/context", StatusController, :context)
471 get("/polls/:id", PollController, :show)
473 get("/accounts/:id/statuses", AccountController, :statuses)
474 get("/accounts/:id/followers", AccountController, :followers)
475 get("/accounts/:id/following", AccountController, :following)
476 get("/accounts/:id", AccountController, :show)
478 get("/search", SearchController, :search)
481 scope "/api/v2", Pleroma.Web.MastodonAPI do
483 get("/search", SearchController, :search2)
486 scope "/api", Pleroma.Web do
487 pipe_through(:config)
489 get("/help/test", TwitterAPI.UtilController, :help_test)
490 post("/help/test", TwitterAPI.UtilController, :help_test)
491 get("/statusnet/config", TwitterAPI.UtilController, :config)
492 get("/statusnet/version", TwitterAPI.UtilController, :version)
493 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
496 scope "/api", Pleroma.Web do
500 "/account/confirm_email/:user_id/:token",
501 TwitterAPI.Controller,
508 pipe_through(:base_api)
510 get("/openapi", OpenApiSpex.Plug.RenderSpec, [])
513 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
514 pipe_through(:authenticated_api)
516 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
517 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
519 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
523 plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
524 plug(Pleroma.Plugs.StaticFEPlug)
528 plug(:accepts, ["json", "xml"])
531 scope "/", Pleroma.Web do
532 pipe_through([:ostatus, :http_signature])
534 get("/objects/:uuid", OStatus.OStatusController, :object)
535 get("/activities/:uuid", OStatus.OStatusController, :activity)
536 get("/notice/:id", OStatus.OStatusController, :notice)
537 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
539 get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
540 get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
542 get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
545 scope "/", Pleroma.Web do
546 pipe_through(:browser)
547 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
550 scope "/", Pleroma.Web.ActivityPub do
551 # XXX: not really ostatus
552 pipe_through(:ostatus)
554 get("/users/:nickname/outbox", ActivityPubController, :outbox)
557 pipeline :ap_service_actor do
558 plug(:accepts, ["activity+json", "json"])
561 # Server to Server (S2S) AP interactions
562 pipeline :activitypub do
563 plug(:ap_service_actor)
564 plug(:http_signature)
567 # Client to Server (C2S) AP interactions
568 pipeline :activitypub_client do
569 plug(:ap_service_actor)
575 scope "/", Pleroma.Web.ActivityPub do
576 pipe_through([:activitypub_client])
578 get("/api/ap/whoami", ActivityPubController, :whoami)
579 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
581 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
582 post("/api/ap/upload_media", ActivityPubController, :upload_media)
584 get("/users/:nickname/followers", ActivityPubController, :followers)
585 get("/users/:nickname/following", ActivityPubController, :following)
588 scope "/", Pleroma.Web.ActivityPub do
589 pipe_through(:activitypub)
590 post("/inbox", ActivityPubController, :inbox)
591 post("/users/:nickname/inbox", ActivityPubController, :inbox)
594 scope "/relay", Pleroma.Web.ActivityPub do
595 pipe_through(:ap_service_actor)
597 get("/", ActivityPubController, :relay)
600 pipe_through(:http_signature)
601 post("/inbox", ActivityPubController, :inbox)
604 get("/following", ActivityPubController, :relay_following)
605 get("/followers", ActivityPubController, :relay_followers)
608 scope "/internal/fetch", Pleroma.Web.ActivityPub do
609 pipe_through(:ap_service_actor)
611 get("/", ActivityPubController, :internal_fetch)
612 post("/inbox", ActivityPubController, :inbox)
615 scope "/.well-known", Pleroma.Web do
616 pipe_through(:well_known)
618 get("/host-meta", WebFinger.WebFingerController, :host_meta)
619 get("/webfinger", WebFinger.WebFingerController, :webfinger)
620 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
623 scope "/nodeinfo", Pleroma.Web do
624 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
627 scope "/", Pleroma.Web do
630 get("/web/manifest.json", MastoFEController, :manifest)
633 scope "/", Pleroma.Web do
634 pipe_through(:mastodon_html)
636 get("/web/login", MastodonAPI.AuthController, :login)
637 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
639 post("/auth/password", MastodonAPI.AuthController, :password_reset)
641 get("/web/*path", MastoFEController, :index)
644 scope "/proxy/", Pleroma.Web.MediaProxy do
645 get("/:sig/:url", MediaProxyController, :remote)
646 get("/:sig/:url/:filename", MediaProxyController, :remote)
649 if Pleroma.Config.get(:env) == :dev do
651 pipe_through([:mailbox_preview])
653 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
657 # Test-only routes needed to test action dispatching and plug chain execution
658 if Pleroma.Config.get(:env) == :test do
659 scope "/test/authenticated_api", Pleroma.Tests do
660 pipe_through(:authenticated_api)
662 for action <- [:skipped_oauth, :performed_oauth, :missed_oauth] do
663 get("/#{action}", OAuthTestController, action)
668 scope "/", Pleroma.Web.MongooseIM do
669 get("/user_exists", MongooseIMController, :user_exists)
670 get("/check_password", MongooseIMController, :check_password)
673 scope "/", Fallback do
674 get("/registration/:token", RedirectController, :registration_page)
675 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
676 get("/api*path", RedirectController, :api_not_implemented)
677 get("/*path", RedirectController, :redirector)
679 options("/*path", RedirectController, :empty)