1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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)
19 plug(:accepts, ["json"])
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.EnsureUserKeyPlug)
30 plug(Pleroma.Plugs.IdempotencyPlug)
33 pipeline :authenticated_api do
34 plug(:accepts, ["json"])
36 plug(Pleroma.Plugs.OAuthPlug)
37 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
38 plug(Pleroma.Plugs.UserFetcherPlug)
39 plug(Pleroma.Plugs.SessionAuthenticationPlug)
40 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
41 plug(Pleroma.Plugs.AuthenticationPlug)
42 plug(Pleroma.Plugs.UserEnabledPlug)
43 plug(Pleroma.Plugs.SetUserSessionIdPlug)
44 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
45 plug(Pleroma.Plugs.IdempotencyPlug)
48 pipeline :admin_api do
49 plug(:accepts, ["json"])
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.AdminSecretAuthenticationPlug)
58 plug(Pleroma.Plugs.UserEnabledPlug)
59 plug(Pleroma.Plugs.SetUserSessionIdPlug)
60 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
61 plug(Pleroma.Plugs.UserIsAdminPlug)
62 plug(Pleroma.Plugs.IdempotencyPlug)
65 pipeline :mastodon_html do
66 plug(:accepts, ["html"])
68 plug(Pleroma.Plugs.OAuthPlug)
69 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
70 plug(Pleroma.Plugs.UserFetcherPlug)
71 plug(Pleroma.Plugs.SessionAuthenticationPlug)
72 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
73 plug(Pleroma.Plugs.AuthenticationPlug)
74 plug(Pleroma.Plugs.UserEnabledPlug)
75 plug(Pleroma.Plugs.SetUserSessionIdPlug)
76 plug(Pleroma.Plugs.EnsureUserKeyPlug)
79 pipeline :pleroma_html do
80 plug(:accepts, ["html"])
82 plug(Pleroma.Plugs.OAuthPlug)
83 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
84 plug(Pleroma.Plugs.UserFetcherPlug)
85 plug(Pleroma.Plugs.SessionAuthenticationPlug)
86 plug(Pleroma.Plugs.AuthenticationPlug)
87 plug(Pleroma.Plugs.EnsureUserKeyPlug)
90 pipeline :well_known do
91 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
95 plug(:accepts, ["json", "xml"])
98 pipeline :pleroma_api do
99 plug(:accepts, ["html", "json"])
102 pipeline :mailbox_preview do
103 plug(:accepts, ["html"])
105 plug(:put_secure_browser_headers, %{
106 "content-security-policy" =>
107 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
111 pipeline :http_signature do
112 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
113 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
116 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
117 pipe_through(:pleroma_api)
119 get("/password_reset/:token", PasswordController, :reset, as: :reset_password)
120 post("/password_reset", PasswordController, :do_reset, as: :reset_password)
121 get("/emoji", UtilController, :emoji)
122 get("/captcha", UtilController, :captcha)
123 get("/healthcheck", UtilController, :healthcheck)
126 scope "/api/pleroma", Pleroma.Web do
127 pipe_through(:pleroma_api)
128 post("/uploader_callback/:upload_path", UploaderController, :callback)
131 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
132 pipe_through(:admin_api)
134 post("/users/follow", AdminAPIController, :user_follow)
135 post("/users/unfollow", AdminAPIController, :user_unfollow)
137 delete("/users", AdminAPIController, :user_delete)
138 post("/users", AdminAPIController, :users_create)
139 patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
140 put("/users/tag", AdminAPIController, :tag_users)
141 delete("/users/tag", AdminAPIController, :untag_users)
143 get("/users/:nickname/permission_group", AdminAPIController, :right_get)
144 get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
145 post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
148 "/users/:nickname/permission_group/:permission_group",
153 put("/users/:nickname/activation_status", AdminAPIController, :set_activation_status)
155 post("/relay", AdminAPIController, :relay_follow)
156 delete("/relay", AdminAPIController, :relay_unfollow)
158 post("/users/invite_token", AdminAPIController, :create_invite_token)
159 get("/users/invites", AdminAPIController, :invites)
160 post("/users/revoke_invite", AdminAPIController, :revoke_invite)
161 post("/users/email_invite", AdminAPIController, :email_invite)
163 get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
165 get("/users", AdminAPIController, :list_users)
166 get("/users/:nickname", AdminAPIController, :user_show)
167 get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
169 get("/reports", AdminAPIController, :list_reports)
170 get("/reports/:id", AdminAPIController, :report_show)
171 put("/reports/:id", AdminAPIController, :report_update_state)
172 post("/reports/:id/respond", AdminAPIController, :report_respond)
174 put("/statuses/:id", AdminAPIController, :status_update)
175 delete("/statuses/:id", AdminAPIController, :status_delete)
177 get("/config", AdminAPIController, :config_show)
178 post("/config", AdminAPIController, :config_update)
179 get("/config/migrate_to_db", AdminAPIController, :migrate_to_db)
180 get("/config/migrate_from_db", AdminAPIController, :migrate_from_db)
182 get("/moderation_log", AdminAPIController, :list_log)
185 scope "/", Pleroma.Web.TwitterAPI do
186 pipe_through(:pleroma_html)
188 post("/main/ostatus", UtilController, :remote_subscribe)
189 get("/ostatus_subscribe", UtilController, :remote_follow)
190 post("/ostatus_subscribe", UtilController, :do_remote_follow)
193 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
194 pipe_through(:authenticated_api)
196 post("/change_email", UtilController, :change_email)
197 post("/change_password", UtilController, :change_password)
198 post("/delete_account", UtilController, :delete_account)
199 put("/notification_settings", UtilController, :update_notificaton_settings)
200 post("/disable_account", UtilController, :disable_account)
202 post("/blocks_import", UtilController, :blocks_import)
203 post("/follow_import", UtilController, :follow_import)
206 scope "/oauth", Pleroma.Web.OAuth do
209 get("/authorize", OAuthController, :authorize)
212 post("/authorize", OAuthController, :create_authorization)
213 post("/token", OAuthController, :token_exchange)
214 post("/revoke", OAuthController, :token_revoke)
215 get("/registration_details", OAuthController, :registration_details)
218 pipe_through(:browser)
220 get("/prepare_request", OAuthController, :prepare_request)
221 get("/:provider", OAuthController, :request)
222 get("/:provider/callback", OAuthController, :callback)
223 post("/register", OAuthController, :register)
227 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
228 pipe_through(:authenticated_api)
230 get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
231 get("/conversations/:id", PleromaAPIController, :conversation)
233 patch("/conversations/:id", PleromaAPIController, :update_conversation)
234 post("/notifications/read", PleromaAPIController, :read_notification)
237 scope "/api/v1", Pleroma.Web.MastodonAPI do
238 pipe_through(:authenticated_api)
240 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
242 get("/accounts/relationships", MastodonAPIController, :relationships)
244 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
245 get("/accounts/:id/identity_proofs", MastodonAPIController, :empty_array)
247 get("/follow_requests", MastodonAPIController, :follow_requests)
248 get("/blocks", MastodonAPIController, :blocks)
249 get("/mutes", MastodonAPIController, :mutes)
251 get("/timelines/home", MastodonAPIController, :home_timeline)
252 get("/timelines/direct", MastodonAPIController, :dm_timeline)
254 get("/favourites", MastodonAPIController, :favourites)
255 # Note: not present in Mastodon: bookmarks
256 get("/bookmarks", MastodonAPIController, :bookmarks)
258 post("/notifications/clear", MastodonAPIController, :clear_notifications)
259 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
260 get("/notifications", MastodonAPIController, :notifications)
261 get("/notifications/:id", MastodonAPIController, :get_notification)
264 "/notifications/destroy_multiple",
265 MastodonAPIController,
266 :destroy_multiple_notifications
269 get("/scheduled_statuses", MastodonAPIController, :scheduled_statuses)
270 get("/scheduled_statuses/:id", MastodonAPIController, :show_scheduled_status)
272 get("/lists", ListController, :index)
273 get("/lists/:id", ListController, :show)
274 get("/lists/:id/accounts", ListController, :list_accounts)
276 get("/domain_blocks", MastodonAPIController, :domain_blocks)
278 get("/filters", MastodonAPIController, :get_filters)
280 get("/suggestions", MastodonAPIController, :suggestions)
282 get("/conversations", MastodonAPIController, :conversations)
283 post("/conversations/:id/read", MastodonAPIController, :conversation_read)
285 get("/endorsements", MastodonAPIController, :endorsements)
287 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
289 post("/statuses", MastodonAPIController, :post_status)
290 delete("/statuses/:id", MastodonAPIController, :delete_status)
292 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
293 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
294 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
295 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
296 post("/statuses/:id/pin", MastodonAPIController, :pin_status)
297 post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
298 # Note: not present in Mastodon: bookmark
299 post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
300 # Note: not present in Mastodon: unbookmark
301 post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
302 post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
303 post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
305 put("/scheduled_statuses/:id", MastodonAPIController, :update_scheduled_status)
306 delete("/scheduled_statuses/:id", MastodonAPIController, :delete_scheduled_status)
308 post("/polls/:id/votes", MastodonAPIController, :poll_vote)
310 post("/media", MastodonAPIController, :upload)
311 put("/media/:id", MastodonAPIController, :update_media)
313 delete("/lists/:id", ListController, :delete)
314 post("/lists", ListController, :create)
315 put("/lists/:id", ListController, :update)
317 post("/lists/:id/accounts", ListController, :add_to_list)
318 delete("/lists/:id/accounts", ListController, :remove_from_list)
320 post("/filters", MastodonAPIController, :create_filter)
321 get("/filters/:id", MastodonAPIController, :get_filter)
322 put("/filters/:id", MastodonAPIController, :update_filter)
323 delete("/filters/:id", MastodonAPIController, :delete_filter)
325 patch("/pleroma/accounts/update_avatar", MastodonAPIController, :update_avatar)
326 patch("/pleroma/accounts/update_banner", MastodonAPIController, :update_banner)
327 patch("/pleroma/accounts/update_background", MastodonAPIController, :update_background)
329 get("/pleroma/mascot", MastodonAPIController, :get_mascot)
330 put("/pleroma/mascot", MastodonAPIController, :set_mascot)
332 post("/reports", MastodonAPIController, :create_report)
334 post("/follows", MastodonAPIController, :follow)
335 post("/accounts/:id/follow", MastodonAPIController, :follow)
337 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
338 post("/accounts/:id/block", MastodonAPIController, :block)
339 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
340 post("/accounts/:id/mute", MastodonAPIController, :mute)
341 post("/accounts/:id/unmute", MastodonAPIController, :unmute)
343 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
344 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
346 post("/domain_blocks", MastodonAPIController, :block_domain)
347 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
349 post("/pleroma/accounts/:id/subscribe", MastodonAPIController, :subscribe)
350 post("/pleroma/accounts/:id/unsubscribe", MastodonAPIController, :unsubscribe)
352 post("/push/subscription", SubscriptionController, :create)
353 get("/push/subscription", SubscriptionController, :get)
354 put("/push/subscription", SubscriptionController, :update)
355 delete("/push/subscription", SubscriptionController, :delete)
358 scope "/api/web", Pleroma.Web.MastodonAPI do
359 pipe_through(:authenticated_api)
361 put("/settings", MastodonAPIController, :put_settings)
364 scope "/api/v1", Pleroma.Web.MastodonAPI do
367 post("/accounts", MastodonAPIController, :account_register)
369 get("/instance", MastodonAPIController, :masto_instance)
370 get("/instance/peers", MastodonAPIController, :peers)
371 post("/apps", MastodonAPIController, :create_app)
372 get("/apps/verify_credentials", MastodonAPIController, :verify_app_credentials)
373 get("/custom_emojis", MastodonAPIController, :custom_emojis)
375 get("/statuses/:id/card", MastodonAPIController, :status_card)
377 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
378 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
380 get("/trends", MastodonAPIController, :empty_array)
382 get("/accounts/search", SearchController, :account_search)
385 "/pleroma/accounts/confirmation_resend",
386 MastodonAPIController,
387 :account_confirmation_resend
390 get("/timelines/public", MastodonAPIController, :public_timeline)
391 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
392 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
394 get("/statuses", MastodonAPIController, :get_statuses)
395 get("/statuses/:id", MastodonAPIController, :get_status)
396 get("/statuses/:id/context", MastodonAPIController, :get_context)
398 get("/polls/:id", MastodonAPIController, :get_poll)
400 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
401 get("/accounts/:id/followers", MastodonAPIController, :followers)
402 get("/accounts/:id/following", MastodonAPIController, :following)
403 get("/accounts/:id", MastodonAPIController, :user)
405 get("/search", SearchController, :search)
407 get("/pleroma/accounts/:id/favourites", MastodonAPIController, :user_favourites)
410 scope "/api/v2", Pleroma.Web.MastodonAPI do
412 get("/search", SearchController, :search2)
415 scope "/api", Pleroma.Web do
416 pipe_through(:config)
418 get("/help/test", TwitterAPI.UtilController, :help_test)
419 post("/help/test", TwitterAPI.UtilController, :help_test)
420 get("/statusnet/config", TwitterAPI.UtilController, :config)
421 get("/statusnet/version", TwitterAPI.UtilController, :version)
422 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
425 scope "/api", Pleroma.Web do
429 "/account/confirm_email/:user_id/:token",
430 TwitterAPI.Controller,
436 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
437 pipe_through(:authenticated_api)
439 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
440 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
442 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
445 pipeline :ap_service_actor do
446 plug(:accepts, ["activity+json", "json"])
450 plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
454 plug(:accepts, ["json", "xml"])
457 scope "/", Pleroma.Web do
458 pipe_through(:ostatus)
459 pipe_through(:http_signature)
461 get("/objects/:uuid", OStatus.OStatusController, :object)
462 get("/activities/:uuid", OStatus.OStatusController, :activity)
463 get("/notice/:id", OStatus.OStatusController, :notice)
464 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
465 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
466 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
468 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
469 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
470 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
471 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
473 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
476 pipeline :activitypub do
477 plug(:accepts, ["activity+json", "json"])
478 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
479 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
482 scope "/", Pleroma.Web.ActivityPub do
483 # XXX: not really ostatus
484 pipe_through(:ostatus)
486 get("/users/:nickname/outbox", ActivityPubController, :outbox)
487 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
490 pipeline :activitypub_client do
491 plug(:accepts, ["activity+json", "json"])
493 plug(Pleroma.Plugs.OAuthPlug)
494 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
495 plug(Pleroma.Plugs.UserFetcherPlug)
496 plug(Pleroma.Plugs.SessionAuthenticationPlug)
497 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
498 plug(Pleroma.Plugs.AuthenticationPlug)
499 plug(Pleroma.Plugs.UserEnabledPlug)
500 plug(Pleroma.Plugs.SetUserSessionIdPlug)
501 plug(Pleroma.Plugs.EnsureUserKeyPlug)
504 scope "/", Pleroma.Web.ActivityPub do
505 pipe_through([:activitypub_client])
507 get("/api/ap/whoami", ActivityPubController, :whoami)
508 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
509 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
510 get("/users/:nickname/followers", ActivityPubController, :followers)
511 get("/users/:nickname/following", ActivityPubController, :following)
514 scope "/", Pleroma.Web.ActivityPub do
515 pipe_through(:activitypub)
517 post("/inbox", ActivityPubController, :inbox)
518 post("/users/:nickname/inbox", ActivityPubController, :inbox)
521 scope "/relay", Pleroma.Web.ActivityPub do
522 pipe_through(:ap_service_actor)
524 get("/", ActivityPubController, :relay)
527 pipe_through(:http_signature)
528 post("/inbox", ActivityPubController, :inbox)
531 get("/following", ActivityPubController, :following, assigns: %{relay: true})
532 get("/followers", ActivityPubController, :followers, assigns: %{relay: true})
535 scope "/internal/fetch", Pleroma.Web.ActivityPub do
536 pipe_through(:ap_service_actor)
538 get("/", ActivityPubController, :internal_fetch)
539 post("/inbox", ActivityPubController, :inbox)
542 scope "/.well-known", Pleroma.Web do
543 pipe_through(:well_known)
545 get("/host-meta", WebFinger.WebFingerController, :host_meta)
546 get("/webfinger", WebFinger.WebFingerController, :webfinger)
547 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
550 scope "/nodeinfo", Pleroma.Web do
551 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
554 scope "/", Pleroma.Web.MastodonAPI do
555 pipe_through(:mastodon_html)
557 get("/web/login", MastodonAPIController, :login)
558 delete("/auth/sign_out", MastodonAPIController, :logout)
560 post("/auth/password", MastodonAPIController, :password_reset)
562 get("/web/*path", MastodonAPIController, :index)
565 pipeline :remote_media do
568 scope "/proxy/", Pleroma.Web.MediaProxy do
569 pipe_through(:remote_media)
571 get("/:sig/:url", MediaProxyController, :remote)
572 get("/:sig/:url/:filename", MediaProxyController, :remote)
575 if Pleroma.Config.get(:env) == :dev do
577 pipe_through([:mailbox_preview])
579 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
583 scope "/", Pleroma.Web.MongooseIM do
584 get("/user_exists", MongooseIMController, :user_exists)
585 get("/check_password", MongooseIMController, :check_password)
588 scope "/", Fallback do
589 get("/registration/:token", RedirectController, :registration_page)
590 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
591 get("/api*path", RedirectController, :api_not_implemented)
592 get("/*path", RedirectController, :redirector)
594 options("/*path", RedirectController, :empty)