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 get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
279 get("/conversations/:id", PleromaAPIController, :conversation)
280 post("/conversations/read", PleromaAPIController, :read_conversations)
284 pipe_through(:authenticated_api)
286 patch("/conversations/:id", PleromaAPIController, :update_conversation)
287 put("/statuses/:id/reactions/:emoji", PleromaAPIController, :react_with_emoji)
288 delete("/statuses/:id/reactions/:emoji", PleromaAPIController, :unreact_with_emoji)
289 post("/notifications/read", PleromaAPIController, :read_notification)
291 patch("/accounts/update_avatar", AccountController, :update_avatar)
292 patch("/accounts/update_banner", AccountController, :update_banner)
293 patch("/accounts/update_background", AccountController, :update_background)
295 get("/mascot", MascotController, :show)
296 put("/mascot", MascotController, :update)
298 post("/scrobble", ScrobbleController, :new_scrobble)
303 get("/accounts/:id/favourites", AccountController, :favourites)
307 pipe_through(:authenticated_api)
309 post("/accounts/:id/subscribe", AccountController, :subscribe)
310 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
313 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
316 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
318 get("/accounts/:id/scrobbles", ScrobbleController, :user_scrobbles)
321 scope "/api/v1", Pleroma.Web.MastodonAPI do
322 pipe_through(:authenticated_api)
324 get("/accounts/verify_credentials", AccountController, :verify_credentials)
326 get("/accounts/relationships", AccountController, :relationships)
328 get("/accounts/:id/lists", AccountController, :lists)
329 get("/accounts/:id/identity_proofs", AccountController, :identity_proofs)
331 get("/follow_requests", FollowRequestController, :index)
332 get("/blocks", AccountController, :blocks)
333 get("/mutes", AccountController, :mutes)
335 get("/timelines/home", TimelineController, :home)
336 get("/timelines/direct", TimelineController, :direct)
338 get("/favourites", StatusController, :favourites)
339 get("/bookmarks", StatusController, :bookmarks)
341 get("/notifications", NotificationController, :index)
342 get("/notifications/:id", NotificationController, :show)
343 post("/notifications/:id/dismiss", NotificationController, :dismiss)
344 post("/notifications/clear", NotificationController, :clear)
345 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
346 # Deprecated: was removed in Mastodon v3, use `/notifications/:id/dismiss` instead
347 post("/notifications/dismiss", NotificationController, :dismiss)
349 get("/scheduled_statuses", ScheduledActivityController, :index)
350 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
352 get("/lists", ListController, :index)
353 get("/lists/:id", ListController, :show)
354 get("/lists/:id/accounts", ListController, :list_accounts)
356 get("/domain_blocks", DomainBlockController, :index)
358 get("/filters", FilterController, :index)
360 get("/suggestions", SuggestionController, :index)
362 get("/conversations", ConversationController, :index)
363 post("/conversations/:id/read", ConversationController, :read)
365 get("/endorsements", AccountController, :endorsements)
367 patch("/accounts/update_credentials", AccountController, :update_credentials)
369 post("/statuses", StatusController, :create)
370 delete("/statuses/:id", StatusController, :delete)
372 post("/statuses/:id/reblog", StatusController, :reblog)
373 post("/statuses/:id/unreblog", StatusController, :unreblog)
374 post("/statuses/:id/favourite", StatusController, :favourite)
375 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
376 post("/statuses/:id/pin", StatusController, :pin)
377 post("/statuses/:id/unpin", StatusController, :unpin)
378 post("/statuses/:id/bookmark", StatusController, :bookmark)
379 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
380 post("/statuses/:id/mute", StatusController, :mute_conversation)
381 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
383 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
384 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
386 post("/polls/:id/votes", PollController, :vote)
388 post("/media", MediaController, :create)
389 put("/media/:id", MediaController, :update)
391 delete("/lists/:id", ListController, :delete)
392 post("/lists", ListController, :create)
393 put("/lists/:id", ListController, :update)
395 post("/lists/:id/accounts", ListController, :add_to_list)
396 delete("/lists/:id/accounts", ListController, :remove_from_list)
398 post("/filters", FilterController, :create)
399 get("/filters/:id", FilterController, :show)
400 put("/filters/:id", FilterController, :update)
401 delete("/filters/:id", FilterController, :delete)
403 post("/reports", ReportController, :create)
405 post("/follows", AccountController, :follows)
406 post("/accounts/:id/follow", AccountController, :follow)
407 post("/accounts/:id/unfollow", AccountController, :unfollow)
408 post("/accounts/:id/block", AccountController, :block)
409 post("/accounts/:id/unblock", AccountController, :unblock)
410 post("/accounts/:id/mute", AccountController, :mute)
411 post("/accounts/:id/unmute", AccountController, :unmute)
413 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
414 post("/follow_requests/:id/reject", FollowRequestController, :reject)
416 post("/domain_blocks", DomainBlockController, :create)
417 delete("/domain_blocks", DomainBlockController, :delete)
419 post("/push/subscription", SubscriptionController, :create)
420 get("/push/subscription", SubscriptionController, :get)
421 put("/push/subscription", SubscriptionController, :update)
422 delete("/push/subscription", SubscriptionController, :delete)
424 get("/markers", MarkerController, :index)
425 post("/markers", MarkerController, :upsert)
428 scope "/api/web", Pleroma.Web do
429 pipe_through(:authenticated_api)
431 put("/settings", MastoFEController, :put_settings)
434 scope "/api/v1", Pleroma.Web.MastodonAPI do
437 post("/accounts", AccountController, :create)
438 get("/accounts/search", SearchController, :account_search)
440 get("/instance", InstanceController, :show)
441 get("/instance/peers", InstanceController, :peers)
443 post("/apps", AppController, :create)
444 get("/apps/verify_credentials", AppController, :verify_credentials)
446 get("/statuses/:id/card", StatusController, :card)
447 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
448 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
450 get("/custom_emojis", CustomEmojiController, :index)
452 get("/trends", MastodonAPIController, :empty_array)
454 get("/timelines/public", TimelineController, :public)
455 get("/timelines/tag/:tag", TimelineController, :hashtag)
456 get("/timelines/list/:list_id", TimelineController, :list)
458 get("/statuses", StatusController, :index)
459 get("/statuses/:id", StatusController, :show)
460 get("/statuses/:id/context", StatusController, :context)
462 get("/polls/:id", PollController, :show)
464 get("/accounts/:id/statuses", AccountController, :statuses)
465 get("/accounts/:id/followers", AccountController, :followers)
466 get("/accounts/:id/following", AccountController, :following)
467 get("/accounts/:id", AccountController, :show)
469 get("/search", SearchController, :search)
472 scope "/api/v2", Pleroma.Web.MastodonAPI do
474 get("/search", SearchController, :search2)
477 scope "/api", Pleroma.Web do
478 pipe_through(:config)
480 get("/help/test", TwitterAPI.UtilController, :help_test)
481 post("/help/test", TwitterAPI.UtilController, :help_test)
482 get("/statusnet/config", TwitterAPI.UtilController, :config)
483 get("/statusnet/version", TwitterAPI.UtilController, :version)
484 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
487 scope "/api", Pleroma.Web do
491 "/account/confirm_email/:user_id/:token",
492 TwitterAPI.Controller,
499 pipe_through(:base_api)
501 get("/openapi", OpenApiSpex.Plug.RenderSpec, [])
504 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
505 pipe_through(:authenticated_api)
507 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
508 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
510 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
514 plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
515 plug(Pleroma.Plugs.StaticFEPlug)
519 plug(:accepts, ["json", "xml"])
522 scope "/", Pleroma.Web do
523 pipe_through([:ostatus, :http_signature])
525 get("/objects/:uuid", OStatus.OStatusController, :object)
526 get("/activities/:uuid", OStatus.OStatusController, :activity)
527 get("/notice/:id", OStatus.OStatusController, :notice)
528 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
530 get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
531 get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
533 get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
536 scope "/", Pleroma.Web do
537 pipe_through(:browser)
538 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
541 scope "/", Pleroma.Web.ActivityPub do
542 # XXX: not really ostatus
543 pipe_through(:ostatus)
545 get("/users/:nickname/outbox", ActivityPubController, :outbox)
548 pipeline :ap_service_actor do
549 plug(:accepts, ["activity+json", "json"])
552 # Server to Server (S2S) AP interactions
553 pipeline :activitypub do
554 plug(:ap_service_actor)
555 plug(:http_signature)
558 # Client to Server (C2S) AP interactions
559 pipeline :activitypub_client do
560 plug(:ap_service_actor)
566 scope "/", Pleroma.Web.ActivityPub do
567 pipe_through([:activitypub_client])
569 get("/api/ap/whoami", ActivityPubController, :whoami)
570 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
572 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
573 post("/api/ap/upload_media", ActivityPubController, :upload_media)
575 get("/users/:nickname/followers", ActivityPubController, :followers)
576 get("/users/:nickname/following", ActivityPubController, :following)
579 scope "/", Pleroma.Web.ActivityPub do
580 pipe_through(:activitypub)
581 post("/inbox", ActivityPubController, :inbox)
582 post("/users/:nickname/inbox", ActivityPubController, :inbox)
585 scope "/relay", Pleroma.Web.ActivityPub do
586 pipe_through(:ap_service_actor)
588 get("/", ActivityPubController, :relay)
591 pipe_through(:http_signature)
592 post("/inbox", ActivityPubController, :inbox)
595 get("/following", ActivityPubController, :relay_following)
596 get("/followers", ActivityPubController, :relay_followers)
599 scope "/internal/fetch", Pleroma.Web.ActivityPub do
600 pipe_through(:ap_service_actor)
602 get("/", ActivityPubController, :internal_fetch)
603 post("/inbox", ActivityPubController, :inbox)
606 scope "/.well-known", Pleroma.Web do
607 pipe_through(:well_known)
609 get("/host-meta", WebFinger.WebFingerController, :host_meta)
610 get("/webfinger", WebFinger.WebFingerController, :webfinger)
611 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
614 scope "/nodeinfo", Pleroma.Web do
615 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
618 scope "/", Pleroma.Web do
621 get("/web/manifest.json", MastoFEController, :manifest)
624 scope "/", Pleroma.Web do
625 pipe_through(:mastodon_html)
627 get("/web/login", MastodonAPI.AuthController, :login)
628 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
630 post("/auth/password", MastodonAPI.AuthController, :password_reset)
632 get("/web/*path", MastoFEController, :index)
635 scope "/proxy/", Pleroma.Web.MediaProxy do
636 get("/:sig/:url", MediaProxyController, :remote)
637 get("/:sig/:url/:filename", MediaProxyController, :remote)
640 if Pleroma.Config.get(:env) == :dev do
642 pipe_through([:mailbox_preview])
644 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
648 # Test-only routes needed to test action dispatching and plug chain execution
649 if Pleroma.Config.get(:env) == :test do
650 scope "/test/authenticated_api", Pleroma.Tests do
651 pipe_through(:authenticated_api)
653 for action <- [:skipped_oauth, :performed_oauth, :missed_oauth] do
654 get("/#{action}", OAuthTestController, action)
659 scope "/", Pleroma.Web.MongooseIM do
660 get("/user_exists", MongooseIMController, :user_exists)
661 get("/check_password", MongooseIMController, :check_password)
664 scope "/", Fallback do
665 get("/registration/:token", RedirectController, :registration_page)
666 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
667 get("/api*path", RedirectController, :api_not_implemented)
668 get("/*path", RedirectController, :redirector)
670 options("/*path", RedirectController, :empty)