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/activate", AdminAPIController, :user_activate)
140 patch("/users/deactivate", AdminAPIController, :user_deactivate)
141 put("/users/tag", AdminAPIController, :tag_users)
142 delete("/users/tag", AdminAPIController, :untag_users)
144 get("/users/:nickname/permission_group", AdminAPIController, :right_get)
145 get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
146 post("/users/permission_group/:permission_group", AdminAPIController, :right_add)
147 delete("/users/permission_group/:permission_group", AdminAPIController, :right_delete)
149 post("/relay", AdminAPIController, :relay_follow)
150 delete("/relay", AdminAPIController, :relay_unfollow)
152 post("/users/invite_token", AdminAPIController, :create_invite_token)
153 get("/users/invites", AdminAPIController, :invites)
154 post("/users/revoke_invite", AdminAPIController, :revoke_invite)
155 post("/users/email_invite", AdminAPIController, :email_invite)
157 get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
158 patch("/users/:nickname/force_password_reset", AdminAPIController, :force_password_reset)
160 get("/users", AdminAPIController, :list_users)
161 get("/users/:nickname", AdminAPIController, :user_show)
162 get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
164 get("/reports", AdminAPIController, :list_reports)
165 get("/reports/:id", AdminAPIController, :report_show)
166 put("/reports/:id", AdminAPIController, :report_update_state)
167 post("/reports/:id/respond", AdminAPIController, :report_respond)
169 put("/statuses/:id", AdminAPIController, :status_update)
170 delete("/statuses/:id", AdminAPIController, :status_delete)
172 get("/config", AdminAPIController, :config_show)
173 post("/config", AdminAPIController, :config_update)
174 get("/config/migrate_to_db", AdminAPIController, :migrate_to_db)
175 get("/config/migrate_from_db", AdminAPIController, :migrate_from_db)
177 get("/moderation_log", AdminAPIController, :list_log)
179 post("/reload_emoji", AdminAPIController, :reload_emoji)
182 scope "/api/pleroma/emoji", Pleroma.Web.PleromaAPI do
185 pipe_through(:admin_api)
187 post("/import_from_fs", EmojiAPIController, :import_from_fs)
189 post("/:pack_name/update_file", EmojiAPIController, :update_file)
190 post("/:pack_name/update_metadata", EmojiAPIController, :update_metadata)
191 put("/:name", EmojiAPIController, :create)
192 delete("/:name", EmojiAPIController, :delete)
193 post("/download_from", EmojiAPIController, :download_from)
194 post("/list_from", EmojiAPIController, :list_from)
198 # Pack info / downloading
199 get("/", EmojiAPIController, :list_packs)
200 get("/:name/download_shared/", EmojiAPIController, :download_shared)
204 scope "/", Pleroma.Web.TwitterAPI do
205 pipe_through(:pleroma_html)
207 post("/main/ostatus", UtilController, :remote_subscribe)
208 get("/ostatus_subscribe", UtilController, :remote_follow)
210 post("/ostatus_subscribe", UtilController, :do_remote_follow)
213 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
214 pipe_through(:authenticated_api)
216 post("/change_email", UtilController, :change_email)
217 post("/change_password", UtilController, :change_password)
218 post("/delete_account", UtilController, :delete_account)
219 put("/notification_settings", UtilController, :update_notificaton_settings)
220 post("/disable_account", UtilController, :disable_account)
222 post("/blocks_import", UtilController, :blocks_import)
223 post("/follow_import", UtilController, :follow_import)
226 scope "/oauth", Pleroma.Web.OAuth do
229 get("/authorize", OAuthController, :authorize)
232 post("/authorize", OAuthController, :create_authorization)
233 post("/token", OAuthController, :token_exchange)
234 post("/revoke", OAuthController, :token_revoke)
235 get("/registration_details", OAuthController, :registration_details)
238 pipe_through(:browser)
240 get("/prepare_request", OAuthController, :prepare_request)
241 get("/:provider", OAuthController, :request)
242 get("/:provider/callback", OAuthController, :callback)
243 post("/register", OAuthController, :register)
247 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
249 pipe_through(:authenticated_api)
251 get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
252 get("/conversations/:id", PleromaAPIController, :conversation)
256 pipe_through(:authenticated_api)
258 patch("/conversations/:id", PleromaAPIController, :update_conversation)
259 post("/notifications/read", PleromaAPIController, :read_notification)
261 patch("/accounts/update_avatar", AccountController, :update_avatar)
262 patch("/accounts/update_banner", AccountController, :update_banner)
263 patch("/accounts/update_background", AccountController, :update_background)
265 get("/mascot", MascotController, :show)
266 put("/mascot", MascotController, :update)
268 post("/scrobble", ScrobbleController, :new_scrobble)
273 get("/accounts/:id/favourites", AccountController, :favourites)
277 pipe_through(:authenticated_api)
279 post("/accounts/:id/subscribe", AccountController, :subscribe)
280 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
283 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
286 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
288 get("/accounts/:id/scrobbles", ScrobbleController, :user_scrobbles)
291 scope "/api/v1", Pleroma.Web.MastodonAPI do
292 pipe_through(:authenticated_api)
294 get("/accounts/verify_credentials", AccountController, :verify_credentials)
296 get("/accounts/relationships", AccountController, :relationships)
298 get("/accounts/:id/lists", AccountController, :lists)
299 get("/accounts/:id/identity_proofs", MastodonAPIController, :empty_array)
301 get("/follow_requests", FollowRequestController, :index)
302 get("/blocks", AccountController, :blocks)
303 get("/mutes", AccountController, :mutes)
305 get("/timelines/home", TimelineController, :home)
306 get("/timelines/direct", TimelineController, :direct)
308 get("/favourites", StatusController, :favourites)
309 get("/bookmarks", StatusController, :bookmarks)
311 get("/notifications", NotificationController, :index)
312 get("/notifications/:id", NotificationController, :show)
313 post("/notifications/clear", NotificationController, :clear)
314 post("/notifications/dismiss", NotificationController, :dismiss)
315 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
317 get("/scheduled_statuses", ScheduledActivityController, :index)
318 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
320 get("/lists", ListController, :index)
321 get("/lists/:id", ListController, :show)
322 get("/lists/:id/accounts", ListController, :list_accounts)
324 get("/domain_blocks", DomainBlockController, :index)
326 get("/filters", FilterController, :index)
328 get("/suggestions", SuggestionController, :index)
330 get("/conversations", ConversationController, :index)
331 post("/conversations/:id/read", ConversationController, :read)
333 get("/endorsements", AccountController, :endorsements)
335 patch("/accounts/update_credentials", AccountController, :update_credentials)
337 post("/statuses", StatusController, :create)
338 delete("/statuses/:id", StatusController, :delete)
340 post("/statuses/:id/reblog", StatusController, :reblog)
341 post("/statuses/:id/unreblog", StatusController, :unreblog)
342 post("/statuses/:id/favourite", StatusController, :favourite)
343 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
344 post("/statuses/:id/pin", StatusController, :pin)
345 post("/statuses/:id/unpin", StatusController, :unpin)
346 post("/statuses/:id/bookmark", StatusController, :bookmark)
347 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
348 post("/statuses/:id/mute", StatusController, :mute_conversation)
349 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
351 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
352 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
354 post("/polls/:id/votes", PollController, :vote)
356 post("/media", MediaController, :create)
357 put("/media/:id", MediaController, :update)
359 delete("/lists/:id", ListController, :delete)
360 post("/lists", ListController, :create)
361 put("/lists/:id", ListController, :update)
363 post("/lists/:id/accounts", ListController, :add_to_list)
364 delete("/lists/:id/accounts", ListController, :remove_from_list)
366 post("/filters", FilterController, :create)
367 get("/filters/:id", FilterController, :show)
368 put("/filters/:id", FilterController, :update)
369 delete("/filters/:id", FilterController, :delete)
371 post("/reports", ReportController, :create)
373 post("/follows", AccountController, :follows)
374 post("/accounts/:id/follow", AccountController, :follow)
375 post("/accounts/:id/unfollow", AccountController, :unfollow)
376 post("/accounts/:id/block", AccountController, :block)
377 post("/accounts/:id/unblock", AccountController, :unblock)
378 post("/accounts/:id/mute", AccountController, :mute)
379 post("/accounts/:id/unmute", AccountController, :unmute)
381 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
382 post("/follow_requests/:id/reject", FollowRequestController, :reject)
384 post("/domain_blocks", DomainBlockController, :create)
385 delete("/domain_blocks", DomainBlockController, :delete)
387 post("/push/subscription", SubscriptionController, :create)
388 get("/push/subscription", SubscriptionController, :get)
389 put("/push/subscription", SubscriptionController, :update)
390 delete("/push/subscription", SubscriptionController, :delete)
393 scope "/api/web", Pleroma.Web do
394 pipe_through(:authenticated_api)
396 put("/settings", MastoFEController, :put_settings)
399 scope "/api/v1", Pleroma.Web.MastodonAPI do
402 post("/accounts", AccountController, :create)
403 get("/accounts/search", SearchController, :account_search)
405 get("/instance", InstanceController, :show)
406 get("/instance/peers", InstanceController, :peers)
408 post("/apps", AppController, :create)
409 get("/apps/verify_credentials", AppController, :verify_credentials)
411 get("/statuses/:id/card", StatusController, :card)
412 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
413 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
415 get("/custom_emojis", CustomEmojiController, :index)
417 get("/trends", MastodonAPIController, :empty_array)
419 get("/timelines/public", TimelineController, :public)
420 get("/timelines/tag/:tag", TimelineController, :hashtag)
421 get("/timelines/list/:list_id", TimelineController, :list)
423 get("/statuses", StatusController, :index)
424 get("/statuses/:id", StatusController, :show)
425 get("/statuses/:id/context", StatusController, :context)
427 get("/polls/:id", PollController, :show)
429 get("/accounts/:id/statuses", AccountController, :statuses)
430 get("/accounts/:id/followers", AccountController, :followers)
431 get("/accounts/:id/following", AccountController, :following)
432 get("/accounts/:id", AccountController, :show)
434 get("/search", SearchController, :search)
437 scope "/api/v2", Pleroma.Web.MastodonAPI do
439 get("/search", SearchController, :search2)
442 scope "/api", Pleroma.Web do
443 pipe_through(:config)
445 get("/help/test", TwitterAPI.UtilController, :help_test)
446 post("/help/test", TwitterAPI.UtilController, :help_test)
447 get("/statusnet/config", TwitterAPI.UtilController, :config)
448 get("/statusnet/version", TwitterAPI.UtilController, :version)
449 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
452 scope "/api", Pleroma.Web do
456 "/account/confirm_email/:user_id/:token",
457 TwitterAPI.Controller,
463 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
464 pipe_through(:authenticated_api)
466 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
467 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
469 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
472 pipeline :ap_service_actor do
473 plug(:accepts, ["activity+json", "json"])
477 plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
481 plug(:accepts, ["json", "xml"])
484 scope "/", Pleroma.Web do
485 pipe_through(:ostatus)
486 pipe_through(:http_signature)
488 get("/objects/:uuid", OStatus.OStatusController, :object)
489 get("/activities/:uuid", OStatus.OStatusController, :activity)
490 get("/notice/:id", OStatus.OStatusController, :notice)
491 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
493 get("/users/:nickname/feed", Feed.FeedController, :feed)
494 get("/users/:nickname", Feed.FeedController, :feed_redirect)
496 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
497 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
498 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
499 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
501 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
504 pipeline :activitypub do
505 plug(:accepts, ["activity+json", "json"])
506 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
507 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
510 scope "/", Pleroma.Web.ActivityPub do
511 # XXX: not really ostatus
512 pipe_through(:ostatus)
514 get("/users/:nickname/outbox", ActivityPubController, :outbox)
517 pipeline :activitypub_client do
518 plug(:accepts, ["activity+json", "json"])
520 plug(Pleroma.Plugs.OAuthPlug)
521 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
522 plug(Pleroma.Plugs.UserFetcherPlug)
523 plug(Pleroma.Plugs.SessionAuthenticationPlug)
524 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
525 plug(Pleroma.Plugs.AuthenticationPlug)
526 plug(Pleroma.Plugs.UserEnabledPlug)
527 plug(Pleroma.Plugs.SetUserSessionIdPlug)
528 plug(Pleroma.Plugs.EnsureUserKeyPlug)
531 scope "/", Pleroma.Web.ActivityPub do
532 pipe_through([:activitypub_client])
534 get("/api/ap/whoami", ActivityPubController, :whoami)
535 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
537 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
538 post("/api/ap/upload_media", ActivityPubController, :upload_media)
540 get("/users/:nickname/followers", ActivityPubController, :followers)
541 get("/users/:nickname/following", ActivityPubController, :following)
544 scope "/", Pleroma.Web.ActivityPub do
545 pipe_through(:activitypub)
546 post("/inbox", ActivityPubController, :inbox)
547 post("/users/:nickname/inbox", ActivityPubController, :inbox)
550 scope "/relay", Pleroma.Web.ActivityPub do
551 pipe_through(:ap_service_actor)
553 get("/", ActivityPubController, :relay)
556 pipe_through(:http_signature)
557 post("/inbox", ActivityPubController, :inbox)
560 get("/following", ActivityPubController, :following, assigns: %{relay: true})
561 get("/followers", ActivityPubController, :followers, assigns: %{relay: true})
564 scope "/internal/fetch", Pleroma.Web.ActivityPub do
565 pipe_through(:ap_service_actor)
567 get("/", ActivityPubController, :internal_fetch)
568 post("/inbox", ActivityPubController, :inbox)
571 scope "/.well-known", Pleroma.Web do
572 pipe_through(:well_known)
574 get("/host-meta", WebFinger.WebFingerController, :host_meta)
575 get("/webfinger", WebFinger.WebFingerController, :webfinger)
576 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
579 scope "/nodeinfo", Pleroma.Web do
580 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
583 scope "/", Pleroma.Web do
584 pipe_through(:mastodon_html)
586 get("/web/login", MastodonAPI.AuthController, :login)
587 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
589 post("/auth/password", MastodonAPI.AuthController, :password_reset)
591 get("/web/*path", MastoFEController, :index)
594 pipeline :remote_media do
597 scope "/proxy/", Pleroma.Web.MediaProxy do
598 pipe_through(:remote_media)
600 get("/:sig/:url", MediaProxyController, :remote)
601 get("/:sig/:url/:filename", MediaProxyController, :remote)
604 if Pleroma.Config.get(:env) == :dev do
606 pipe_through([:mailbox_preview])
608 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
612 scope "/", Pleroma.Web.MongooseIM do
613 get("/user_exists", MongooseIMController, :user_exists)
614 get("/check_password", MongooseIMController, :check_password)
617 scope "/", Fallback do
618 get("/registration/:token", RedirectController, :registration_page)
619 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
620 get("/api*path", RedirectController, :api_not_implemented)
621 get("/*path", RedirectController, :redirector)
623 options("/*path", RedirectController, :empty)