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, ["json"])
11 plug(Pleroma.Plugs.OAuthPlug)
12 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
13 plug(Pleroma.Plugs.UserFetcherPlug)
14 plug(Pleroma.Plugs.SessionAuthenticationPlug)
15 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
16 plug(Pleroma.Plugs.AuthenticationPlug)
17 plug(Pleroma.Plugs.UserEnabledPlug)
18 plug(Pleroma.Plugs.SetUserSessionIdPlug)
19 plug(Pleroma.Plugs.EnsureUserKeyPlug)
22 pipeline :authenticated_api do
23 plug(:accepts, ["json"])
25 plug(Pleroma.Plugs.OAuthPlug)
26 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
27 plug(Pleroma.Plugs.UserFetcherPlug)
28 plug(Pleroma.Plugs.SessionAuthenticationPlug)
29 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
30 plug(Pleroma.Plugs.AuthenticationPlug)
31 plug(Pleroma.Plugs.UserEnabledPlug)
32 plug(Pleroma.Plugs.SetUserSessionIdPlug)
33 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
36 pipeline :admin_api do
37 plug(:accepts, ["json"])
39 plug(Pleroma.Plugs.OAuthPlug)
40 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
41 plug(Pleroma.Plugs.UserFetcherPlug)
42 plug(Pleroma.Plugs.SessionAuthenticationPlug)
43 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
44 plug(Pleroma.Plugs.AuthenticationPlug)
45 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
46 plug(Pleroma.Plugs.UserEnabledPlug)
47 plug(Pleroma.Plugs.SetUserSessionIdPlug)
48 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
49 plug(Pleroma.Plugs.UserIsAdminPlug)
52 pipeline :mastodon_html do
53 plug(:accepts, ["html"])
55 plug(Pleroma.Plugs.OAuthPlug)
56 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
57 plug(Pleroma.Plugs.UserFetcherPlug)
58 plug(Pleroma.Plugs.SessionAuthenticationPlug)
59 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
60 plug(Pleroma.Plugs.AuthenticationPlug)
61 plug(Pleroma.Plugs.UserEnabledPlug)
62 plug(Pleroma.Plugs.SetUserSessionIdPlug)
63 plug(Pleroma.Plugs.EnsureUserKeyPlug)
66 pipeline :pleroma_html do
67 plug(:accepts, ["html"])
69 plug(Pleroma.Plugs.OAuthPlug)
70 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
71 plug(Pleroma.Plugs.UserFetcherPlug)
72 plug(Pleroma.Plugs.SessionAuthenticationPlug)
73 plug(Pleroma.Plugs.AuthenticationPlug)
74 plug(Pleroma.Plugs.EnsureUserKeyPlug)
77 pipeline :well_known do
78 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
82 plug(:accepts, ["json", "xml"])
86 plug(:accepts, ["html", "json"])
89 pipeline :pleroma_api do
90 plug(:accepts, ["html", "json"])
93 pipeline :mailbox_preview do
94 plug(:accepts, ["html"])
96 plug(:put_secure_browser_headers, %{
97 "content-security-policy" =>
98 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
102 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
103 pipe_through(:pleroma_api)
104 get("/password_reset/:token", UtilController, :show_password_reset)
105 post("/password_reset", UtilController, :password_reset)
106 get("/emoji", UtilController, :emoji)
107 get("/captcha", UtilController, :captcha)
110 scope "/api/pleroma", Pleroma.Web do
111 pipe_through(:pleroma_api)
112 post("/uploader_callback/:upload_path", UploaderController, :callback)
115 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
116 pipe_through(:admin_api)
117 delete("/user", AdminAPIController, :user_delete)
118 post("/user", AdminAPIController, :user_create)
119 put("/users/tag", AdminAPIController, :tag_users)
120 delete("/users/tag", AdminAPIController, :untag_users)
122 get("/permission_group/:nickname", AdminAPIController, :right_get)
123 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
124 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
125 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
127 put("/activation_status/:nickname", AdminAPIController, :set_activation_status)
129 post("/relay", AdminAPIController, :relay_follow)
130 delete("/relay", AdminAPIController, :relay_unfollow)
132 get("/invite_token", AdminAPIController, :get_invite_token)
133 post("/email_invite", AdminAPIController, :email_invite)
135 get("/password_reset", AdminAPIController, :get_password_reset)
138 scope "/", Pleroma.Web.TwitterAPI do
139 pipe_through(:pleroma_html)
140 get("/ostatus_subscribe", UtilController, :remote_follow)
141 post("/ostatus_subscribe", UtilController, :do_remote_follow)
142 post("/main/ostatus", UtilController, :remote_subscribe)
145 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
146 pipe_through(:authenticated_api)
147 post("/blocks_import", UtilController, :blocks_import)
148 post("/follow_import", UtilController, :follow_import)
149 post("/change_password", UtilController, :change_password)
150 post("/delete_account", UtilController, :delete_account)
153 scope "/oauth", Pleroma.Web.OAuth do
154 get("/authorize", OAuthController, :authorize)
155 post("/authorize", OAuthController, :create_authorization)
156 post("/token", OAuthController, :token_exchange)
157 post("/revoke", OAuthController, :token_revoke)
160 scope "/api/v1", Pleroma.Web.MastodonAPI do
161 pipe_through(:authenticated_api)
163 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
164 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
165 get("/accounts/relationships", MastodonAPIController, :relationships)
166 get("/accounts/search", MastodonAPIController, :account_search)
167 post("/accounts/:id/follow", MastodonAPIController, :follow)
168 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
169 post("/accounts/:id/block", MastodonAPIController, :block)
170 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
171 post("/accounts/:id/mute", MastodonAPIController, :mute)
172 post("/accounts/:id/unmute", MastodonAPIController, :unmute)
173 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
175 get("/follow_requests", MastodonAPIController, :follow_requests)
176 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
177 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
179 post("/follows", MastodonAPIController, :follow)
181 get("/blocks", MastodonAPIController, :blocks)
183 get("/mutes", MastodonAPIController, :mutes)
185 get("/timelines/home", MastodonAPIController, :home_timeline)
187 get("/timelines/direct", MastodonAPIController, :dm_timeline)
189 get("/favourites", MastodonAPIController, :favourites)
190 get("/bookmarks", MastodonAPIController, :bookmarks)
192 post("/statuses", MastodonAPIController, :post_status)
193 delete("/statuses/:id", MastodonAPIController, :delete_status)
195 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
196 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
197 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
198 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
199 post("/statuses/:id/pin", MastodonAPIController, :pin_status)
200 post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
201 post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
202 post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
203 post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
204 post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
206 post("/notifications/clear", MastodonAPIController, :clear_notifications)
207 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
208 get("/notifications", MastodonAPIController, :notifications)
209 get("/notifications/:id", MastodonAPIController, :get_notification)
211 post("/media", MastodonAPIController, :upload)
212 put("/media/:id", MastodonAPIController, :update_media)
214 get("/lists", MastodonAPIController, :get_lists)
215 get("/lists/:id", MastodonAPIController, :get_list)
216 delete("/lists/:id", MastodonAPIController, :delete_list)
217 post("/lists", MastodonAPIController, :create_list)
218 put("/lists/:id", MastodonAPIController, :rename_list)
219 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
220 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
221 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
223 get("/domain_blocks", MastodonAPIController, :domain_blocks)
224 post("/domain_blocks", MastodonAPIController, :block_domain)
225 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
227 get("/filters", MastodonAPIController, :get_filters)
228 post("/filters", MastodonAPIController, :create_filter)
229 get("/filters/:id", MastodonAPIController, :get_filter)
230 put("/filters/:id", MastodonAPIController, :update_filter)
231 delete("/filters/:id", MastodonAPIController, :delete_filter)
233 post("/push/subscription", MastodonAPIController, :create_push_subscription)
234 get("/push/subscription", MastodonAPIController, :get_push_subscription)
235 put("/push/subscription", MastodonAPIController, :update_push_subscription)
236 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
238 get("/suggestions", MastodonAPIController, :suggestions)
240 get("/endorsements", MastodonAPIController, :empty_array)
242 post("/pleroma/flavour/:flavour", MastodonAPIController, :set_flavour)
243 get("/pleroma/flavour", MastodonAPIController, :get_flavour)
246 scope "/api/web", Pleroma.Web.MastodonAPI do
247 pipe_through(:authenticated_api)
249 put("/settings", MastodonAPIController, :put_settings)
252 scope "/api/v1", Pleroma.Web.MastodonAPI do
254 get("/instance", MastodonAPIController, :masto_instance)
255 get("/instance/peers", MastodonAPIController, :peers)
256 post("/apps", MastodonAPIController, :create_app)
257 get("/custom_emojis", MastodonAPIController, :custom_emojis)
259 get("/timelines/public", MastodonAPIController, :public_timeline)
260 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
261 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
263 get("/statuses/:id", MastodonAPIController, :get_status)
264 get("/statuses/:id/context", MastodonAPIController, :get_context)
265 get("/statuses/:id/card", MastodonAPIController, :status_card)
266 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
267 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
269 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
270 get("/accounts/:id/followers", MastodonAPIController, :followers)
271 get("/accounts/:id/following", MastodonAPIController, :following)
272 get("/accounts/:id", MastodonAPIController, :user)
274 get("/trends", MastodonAPIController, :empty_array)
276 get("/search", MastodonAPIController, :search)
279 scope "/api/v2", Pleroma.Web.MastodonAPI do
281 get("/search", MastodonAPIController, :search2)
284 scope "/api", Pleroma.Web do
285 pipe_through(:config)
287 get("/help/test", TwitterAPI.UtilController, :help_test)
288 post("/help/test", TwitterAPI.UtilController, :help_test)
289 get("/statusnet/config", TwitterAPI.UtilController, :config)
290 get("/statusnet/version", TwitterAPI.UtilController, :version)
291 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
294 scope "/api", Pleroma.Web do
297 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
298 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
299 get("/users/show", TwitterAPI.Controller, :show_user)
301 get("/statuses/followers", TwitterAPI.Controller, :followers)
302 get("/statuses/friends", TwitterAPI.Controller, :friends)
303 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
304 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
305 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
307 post("/account/register", TwitterAPI.Controller, :register)
308 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
311 "/account/confirm_email/:user_id/:token",
312 TwitterAPI.Controller,
317 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
319 get("/search", TwitterAPI.Controller, :search)
320 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
323 scope "/api", Pleroma.Web do
326 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
329 "/statuses/public_and_external_timeline",
330 TwitterAPI.Controller,
331 :public_and_external_timeline
334 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
337 scope "/api", Pleroma.Web, as: :twitter_api_search do
339 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
342 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
343 pipe_through(:authenticated_api)
345 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
346 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
348 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
349 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
350 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
352 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
353 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
354 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
355 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
356 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
357 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
359 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
361 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
363 post("/statuses/update", TwitterAPI.Controller, :status_update)
364 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
365 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
366 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
368 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
369 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
371 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
372 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
373 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
375 post("/friendships/create", TwitterAPI.Controller, :follow)
376 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
377 post("/blocks/create", TwitterAPI.Controller, :block)
378 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
380 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
381 post("/media/upload", TwitterAPI.Controller, :upload_json)
382 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
384 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
385 post("/favorites/create", TwitterAPI.Controller, :favorite)
386 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
388 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
390 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
391 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
393 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
394 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
396 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
398 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
399 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
402 pipeline :ap_relay do
403 plug(:accepts, ["activity+json"])
407 plug(:accepts, ["html", "xml", "atom", "activity+json"])
411 plug(:accepts, ["json", "xml"])
414 scope "/", Pleroma.Web do
415 pipe_through(:ostatus)
417 get("/objects/:uuid", OStatus.OStatusController, :object)
418 get("/activities/:uuid", OStatus.OStatusController, :activity)
419 get("/notice/:id", OStatus.OStatusController, :notice)
420 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
421 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
423 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
424 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
425 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
426 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
429 scope "/", Pleroma.Web do
430 pipe_through(:oembed)
432 get("/oembed", OEmbed.OEmbedController, :url)
435 pipeline :activitypub do
436 plug(:accepts, ["activity+json"])
437 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
440 scope "/", Pleroma.Web.ActivityPub do
441 # XXX: not really ostatus
442 pipe_through(:ostatus)
444 get("/users/:nickname/followers", ActivityPubController, :followers)
445 get("/users/:nickname/following", ActivityPubController, :following)
446 get("/users/:nickname/outbox", ActivityPubController, :outbox)
447 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
450 pipeline :activitypub_client do
451 plug(:accepts, ["activity+json"])
453 plug(Pleroma.Plugs.OAuthPlug)
454 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
455 plug(Pleroma.Plugs.UserFetcherPlug)
456 plug(Pleroma.Plugs.SessionAuthenticationPlug)
457 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
458 plug(Pleroma.Plugs.AuthenticationPlug)
459 plug(Pleroma.Plugs.UserEnabledPlug)
460 plug(Pleroma.Plugs.SetUserSessionIdPlug)
461 plug(Pleroma.Plugs.EnsureUserKeyPlug)
464 scope "/", Pleroma.Web.ActivityPub do
465 pipe_through([:activitypub_client])
467 get("/api/ap/whoami", ActivityPubController, :whoami)
468 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
469 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
472 scope "/relay", Pleroma.Web.ActivityPub do
473 pipe_through(:ap_relay)
474 get("/", ActivityPubController, :relay)
477 scope "/", Pleroma.Web.ActivityPub do
478 pipe_through(:activitypub)
479 post("/inbox", ActivityPubController, :inbox)
480 post("/users/:nickname/inbox", ActivityPubController, :inbox)
483 scope "/.well-known", Pleroma.Web do
484 pipe_through(:well_known)
486 get("/host-meta", WebFinger.WebFingerController, :host_meta)
487 get("/webfinger", WebFinger.WebFingerController, :webfinger)
488 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
491 scope "/nodeinfo", Pleroma.Web do
492 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
495 scope "/", Pleroma.Web.MastodonAPI do
496 pipe_through(:mastodon_html)
498 get("/web/login", MastodonAPIController, :login)
499 post("/web/login", MastodonAPIController, :login_post)
500 get("/web/*path", MastodonAPIController, :index)
501 delete("/auth/sign_out", MastodonAPIController, :logout)
504 pipeline :remote_media do
507 scope "/proxy/", Pleroma.Web.MediaProxy do
508 pipe_through(:remote_media)
509 get("/:sig/:url", MediaProxyController, :remote)
510 get("/:sig/:url/:filename", MediaProxyController, :remote)
513 if Mix.env() == :dev do
515 pipe_through([:mailbox_preview])
517 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
521 scope "/", Fallback do
522 get("/registration/:token", RedirectController, :registration_page)
523 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
524 get("/*path", RedirectController, :redirector)
526 options("/*path", RedirectController, :empty)
530 defmodule Fallback.RedirectController do
531 use Pleroma.Web, :controller
532 alias Pleroma.Web.Metadata
535 def redirector(conn, _params, code \\ 200) do
537 |> put_resp_content_type("text/html")
538 |> send_file(code, index_file_path())
541 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
542 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
543 redirector_with_meta(conn, %{user: user})
546 redirector(conn, params)
550 def redirector_with_meta(conn, params) do
551 {:ok, index_content} = File.read(index_file_path())
552 tags = Metadata.build_tags(params)
553 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
556 |> put_resp_content_type("text/html")
557 |> send_resp(200, response)
560 def index_file_path do
561 Pleroma.Plugs.InstanceStatic.file_path("index.html")
564 def registration_page(conn, params) do
565 redirector(conn, params)
568 def empty(conn, _params) do