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)
164 patch("/users/:nickname/force_password_reset", AdminAPIController, :force_password_reset)
166 get("/users", AdminAPIController, :list_users)
167 get("/users/:nickname", AdminAPIController, :user_show)
168 get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
170 get("/reports", AdminAPIController, :list_reports)
171 get("/reports/:id", AdminAPIController, :report_show)
172 put("/reports/:id", AdminAPIController, :report_update_state)
173 post("/reports/:id/respond", AdminAPIController, :report_respond)
175 put("/statuses/:id", AdminAPIController, :status_update)
176 delete("/statuses/:id", AdminAPIController, :status_delete)
178 get("/config", AdminAPIController, :config_show)
179 post("/config", AdminAPIController, :config_update)
180 get("/config/migrate_to_db", AdminAPIController, :migrate_to_db)
181 get("/config/migrate_from_db", AdminAPIController, :migrate_from_db)
183 get("/moderation_log", AdminAPIController, :list_log)
185 post("/reload_emoji", AdminAPIController, :reload_emoji)
188 scope "/api/pleroma/emoji", Pleroma.Web.PleromaAPI do
191 pipe_through(:admin_api)
193 post("/import_from_fs", EmojiAPIController, :import_from_fs)
195 post("/:pack_name/update_file", EmojiAPIController, :update_file)
196 post("/:pack_name/update_metadata", EmojiAPIController, :update_metadata)
197 put("/:name", EmojiAPIController, :create)
198 delete("/:name", EmojiAPIController, :delete)
199 post("/download_from", EmojiAPIController, :download_from)
200 post("/list_from", EmojiAPIController, :list_from)
204 # Pack info / downloading
205 get("/", EmojiAPIController, :list_packs)
206 get("/:name/download_shared/", EmojiAPIController, :download_shared)
210 scope "/", Pleroma.Web.TwitterAPI do
211 pipe_through(:pleroma_html)
213 post("/main/ostatus", UtilController, :remote_subscribe)
214 get("/ostatus_subscribe", UtilController, :remote_follow)
216 post("/ostatus_subscribe", UtilController, :do_remote_follow)
219 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
220 pipe_through(:authenticated_api)
222 post("/change_email", UtilController, :change_email)
223 post("/change_password", UtilController, :change_password)
224 post("/delete_account", UtilController, :delete_account)
225 put("/notification_settings", UtilController, :update_notificaton_settings)
226 post("/disable_account", UtilController, :disable_account)
228 post("/blocks_import", UtilController, :blocks_import)
229 post("/follow_import", UtilController, :follow_import)
232 scope "/oauth", Pleroma.Web.OAuth do
235 get("/authorize", OAuthController, :authorize)
238 post("/authorize", OAuthController, :create_authorization)
239 post("/token", OAuthController, :token_exchange)
240 post("/revoke", OAuthController, :token_revoke)
241 get("/registration_details", OAuthController, :registration_details)
244 pipe_through(:browser)
246 get("/prepare_request", OAuthController, :prepare_request)
247 get("/:provider", OAuthController, :request)
248 get("/:provider/callback", OAuthController, :callback)
249 post("/register", OAuthController, :register)
253 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
255 pipe_through(:authenticated_api)
257 get("/conversations/:id/statuses", PleromaAPIController, :conversation_statuses)
258 get("/conversations/:id", PleromaAPIController, :conversation)
262 pipe_through(:authenticated_api)
264 patch("/conversations/:id", PleromaAPIController, :update_conversation)
265 post("/notifications/read", PleromaAPIController, :read_notification)
267 patch("/accounts/update_avatar", AccountController, :update_avatar)
268 patch("/accounts/update_banner", AccountController, :update_banner)
269 patch("/accounts/update_background", AccountController, :update_background)
271 get("/mascot", MascotController, :show)
272 put("/mascot", MascotController, :update)
274 post("/scrobble", ScrobbleController, :new_scrobble)
279 get("/accounts/:id/favourites", AccountController, :favourites)
283 pipe_through(:authenticated_api)
285 post("/accounts/:id/subscribe", AccountController, :subscribe)
286 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
289 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
292 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
294 get("/accounts/:id/scrobbles", ScrobbleController, :user_scrobbles)
297 scope "/api/v1", Pleroma.Web.MastodonAPI do
298 pipe_through(:authenticated_api)
300 get("/accounts/verify_credentials", AccountController, :verify_credentials)
302 get("/accounts/relationships", AccountController, :relationships)
304 get("/accounts/:id/lists", AccountController, :lists)
305 get("/accounts/:id/identity_proofs", MastodonAPIController, :empty_array)
307 get("/follow_requests", FollowRequestController, :index)
308 get("/blocks", AccountController, :blocks)
309 get("/mutes", AccountController, :mutes)
311 get("/timelines/home", TimelineController, :home)
312 get("/timelines/direct", TimelineController, :direct)
314 get("/favourites", StatusController, :favourites)
315 get("/bookmarks", StatusController, :bookmarks)
317 get("/notifications", NotificationController, :index)
318 get("/notifications/:id", NotificationController, :show)
319 post("/notifications/clear", NotificationController, :clear)
320 post("/notifications/dismiss", NotificationController, :dismiss)
321 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
323 get("/scheduled_statuses", ScheduledActivityController, :index)
324 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
326 get("/lists", ListController, :index)
327 get("/lists/:id", ListController, :show)
328 get("/lists/:id/accounts", ListController, :list_accounts)
330 get("/domain_blocks", DomainBlockController, :index)
332 get("/filters", FilterController, :index)
334 get("/suggestions", SuggestionController, :index)
336 get("/conversations", ConversationController, :index)
337 post("/conversations/:id/read", ConversationController, :read)
339 get("/endorsements", AccountController, :endorsements)
341 patch("/accounts/update_credentials", AccountController, :update_credentials)
343 post("/statuses", StatusController, :create)
344 delete("/statuses/:id", StatusController, :delete)
346 post("/statuses/:id/reblog", StatusController, :reblog)
347 post("/statuses/:id/unreblog", StatusController, :unreblog)
348 post("/statuses/:id/favourite", StatusController, :favourite)
349 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
350 post("/statuses/:id/pin", StatusController, :pin)
351 post("/statuses/:id/unpin", StatusController, :unpin)
352 post("/statuses/:id/bookmark", StatusController, :bookmark)
353 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
354 post("/statuses/:id/mute", StatusController, :mute_conversation)
355 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
357 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
358 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
360 post("/polls/:id/votes", PollController, :vote)
362 post("/media", MediaController, :create)
363 put("/media/:id", MediaController, :update)
365 delete("/lists/:id", ListController, :delete)
366 post("/lists", ListController, :create)
367 put("/lists/:id", ListController, :update)
369 post("/lists/:id/accounts", ListController, :add_to_list)
370 delete("/lists/:id/accounts", ListController, :remove_from_list)
372 post("/filters", FilterController, :create)
373 get("/filters/:id", FilterController, :show)
374 put("/filters/:id", FilterController, :update)
375 delete("/filters/:id", FilterController, :delete)
377 post("/reports", ReportController, :create)
379 post("/follows", AccountController, :follows)
380 post("/accounts/:id/follow", AccountController, :follow)
381 post("/accounts/:id/unfollow", AccountController, :unfollow)
382 post("/accounts/:id/block", AccountController, :block)
383 post("/accounts/:id/unblock", AccountController, :unblock)
384 post("/accounts/:id/mute", AccountController, :mute)
385 post("/accounts/:id/unmute", AccountController, :unmute)
387 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
388 post("/follow_requests/:id/reject", FollowRequestController, :reject)
390 post("/domain_blocks", DomainBlockController, :create)
391 delete("/domain_blocks", DomainBlockController, :delete)
393 post("/push/subscription", SubscriptionController, :create)
394 get("/push/subscription", SubscriptionController, :get)
395 put("/push/subscription", SubscriptionController, :update)
396 delete("/push/subscription", SubscriptionController, :delete)
399 scope "/api/web", Pleroma.Web do
400 pipe_through(:authenticated_api)
402 put("/settings", MastoFEController, :put_settings)
405 scope "/api/v1", Pleroma.Web.MastodonAPI do
408 post("/accounts", AccountController, :create)
409 get("/accounts/search", SearchController, :account_search)
411 get("/instance", InstanceController, :show)
412 get("/instance/peers", InstanceController, :peers)
414 post("/apps", AppController, :create)
415 get("/apps/verify_credentials", AppController, :verify_credentials)
417 get("/statuses/:id/card", StatusController, :card)
418 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
419 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
421 get("/custom_emojis", CustomEmojiController, :index)
423 get("/trends", MastodonAPIController, :empty_array)
425 get("/timelines/public", TimelineController, :public)
426 get("/timelines/tag/:tag", TimelineController, :hashtag)
427 get("/timelines/list/:list_id", TimelineController, :list)
429 get("/statuses", StatusController, :index)
430 get("/statuses/:id", StatusController, :show)
431 get("/statuses/:id/context", StatusController, :context)
433 get("/polls/:id", PollController, :show)
435 get("/accounts/:id/statuses", AccountController, :statuses)
436 get("/accounts/:id/followers", AccountController, :followers)
437 get("/accounts/:id/following", AccountController, :following)
438 get("/accounts/:id", AccountController, :show)
440 get("/search", SearchController, :search)
443 scope "/api/v2", Pleroma.Web.MastodonAPI do
445 get("/search", SearchController, :search2)
448 scope "/api", Pleroma.Web do
449 pipe_through(:config)
451 get("/help/test", TwitterAPI.UtilController, :help_test)
452 post("/help/test", TwitterAPI.UtilController, :help_test)
453 get("/statusnet/config", TwitterAPI.UtilController, :config)
454 get("/statusnet/version", TwitterAPI.UtilController, :version)
455 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
458 scope "/api", Pleroma.Web do
462 "/account/confirm_email/:user_id/:token",
463 TwitterAPI.Controller,
469 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
470 pipe_through(:authenticated_api)
472 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
473 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
475 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
478 pipeline :ap_service_actor do
479 plug(:accepts, ["activity+json", "json"])
483 plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
487 plug(:accepts, ["json", "xml"])
490 scope "/", Pleroma.Web do
491 pipe_through(:ostatus)
492 pipe_through(:http_signature)
494 get("/objects/:uuid", OStatus.OStatusController, :object)
495 get("/activities/:uuid", OStatus.OStatusController, :activity)
496 get("/notice/:id", OStatus.OStatusController, :notice)
497 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
499 get("/users/:nickname/feed", Feed.FeedController, :feed)
500 get("/users/:nickname", Feed.FeedController, :feed_redirect)
502 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
503 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
504 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
505 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
507 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
510 pipeline :activitypub do
511 plug(:accepts, ["activity+json", "json"])
512 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
513 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
516 scope "/", Pleroma.Web.ActivityPub do
517 # XXX: not really ostatus
518 pipe_through(:ostatus)
520 get("/users/:nickname/outbox", ActivityPubController, :outbox)
523 pipeline :activitypub_client do
524 plug(:accepts, ["activity+json", "json"])
526 plug(Pleroma.Plugs.OAuthPlug)
527 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
528 plug(Pleroma.Plugs.UserFetcherPlug)
529 plug(Pleroma.Plugs.SessionAuthenticationPlug)
530 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
531 plug(Pleroma.Plugs.AuthenticationPlug)
532 plug(Pleroma.Plugs.UserEnabledPlug)
533 plug(Pleroma.Plugs.SetUserSessionIdPlug)
534 plug(Pleroma.Plugs.EnsureUserKeyPlug)
537 scope "/", Pleroma.Web.ActivityPub do
538 pipe_through([:activitypub_client])
540 get("/api/ap/whoami", ActivityPubController, :whoami)
541 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
543 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
544 post("/api/ap/upload_media", ActivityPubController, :upload_media)
546 get("/users/:nickname/followers", ActivityPubController, :followers)
547 get("/users/:nickname/following", ActivityPubController, :following)
550 scope "/", Pleroma.Web.ActivityPub do
551 pipe_through(:activitypub)
552 post("/inbox", ActivityPubController, :inbox)
553 post("/users/:nickname/inbox", ActivityPubController, :inbox)
556 scope "/relay", Pleroma.Web.ActivityPub do
557 pipe_through(:ap_service_actor)
559 get("/", ActivityPubController, :relay)
562 pipe_through(:http_signature)
563 post("/inbox", ActivityPubController, :inbox)
566 get("/following", ActivityPubController, :following, assigns: %{relay: true})
567 get("/followers", ActivityPubController, :followers, assigns: %{relay: true})
570 scope "/internal/fetch", Pleroma.Web.ActivityPub do
571 pipe_through(:ap_service_actor)
573 get("/", ActivityPubController, :internal_fetch)
574 post("/inbox", ActivityPubController, :inbox)
577 scope "/.well-known", Pleroma.Web do
578 pipe_through(:well_known)
580 get("/host-meta", WebFinger.WebFingerController, :host_meta)
581 get("/webfinger", WebFinger.WebFingerController, :webfinger)
582 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
585 scope "/nodeinfo", Pleroma.Web do
586 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
589 scope "/", Pleroma.Web do
590 pipe_through(:mastodon_html)
592 get("/web/login", MastodonAPI.AuthController, :login)
593 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
595 post("/auth/password", MastodonAPI.AuthController, :password_reset)
597 get("/web/*path", MastoFEController, :index)
600 pipeline :remote_media do
603 scope "/proxy/", Pleroma.Web.MediaProxy do
604 pipe_through(:remote_media)
606 get("/:sig/:url", MediaProxyController, :remote)
607 get("/:sig/:url/:filename", MediaProxyController, :remote)
610 if Pleroma.Config.get(:env) == :dev do
612 pipe_through([:mailbox_preview])
614 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
618 scope "/", Pleroma.Web.MongooseIM do
619 get("/user_exists", MongooseIMController, :user_exists)
620 get("/check_password", MongooseIMController, :check_password)
623 scope "/", Fallback do
624 get("/registration/:token", RedirectController, :registration_page)
625 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
626 get("/api*path", RedirectController, :api_not_implemented)
627 get("/*path", RedirectController, :redirector)
629 options("/*path", RedirectController, :empty)