Merge branch 'fix_486' into 'develop'
[akkoma] / lib / pleroma / web / router.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Router do
6 use Pleroma.Web, :router
7
8 pipeline :api do
9 plug(:accepts, ["json"])
10 plug(:fetch_session)
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)
20 end
21
22 pipeline :authenticated_api do
23 plug(:accepts, ["json"])
24 plug(:fetch_session)
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)
34 end
35
36 pipeline :admin_api do
37 plug(:accepts, ["json"])
38 plug(:fetch_session)
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)
50 end
51
52 pipeline :mastodon_html do
53 plug(:accepts, ["html"])
54 plug(:fetch_session)
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)
64 end
65
66 pipeline :pleroma_html do
67 plug(:accepts, ["html"])
68 plug(:fetch_session)
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)
75 end
76
77 pipeline :well_known do
78 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
79 end
80
81 pipeline :config do
82 plug(:accepts, ["json", "xml"])
83 end
84
85 pipeline :oauth do
86 plug(:accepts, ["html", "json"])
87 end
88
89 pipeline :pleroma_api do
90 plug(:accepts, ["html", "json"])
91 end
92
93 pipeline :mailbox_preview do
94 plug(:accepts, ["html"])
95
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'"
99 })
100 end
101
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)
108 end
109
110 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
111 pipe_through(:admin_api)
112 delete("/user", AdminAPIController, :user_delete)
113 post("/user", AdminAPIController, :user_create)
114 put("/users/tag", AdminAPIController, :tag_users)
115 delete("/users/tag", AdminAPIController, :untag_users)
116
117 get("/permission_group/:nickname", AdminAPIController, :right_get)
118 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
119 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
120 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
121
122 post("/relay", AdminAPIController, :relay_follow)
123 delete("/relay", AdminAPIController, :relay_unfollow)
124
125 get("/invite_token", AdminAPIController, :get_invite_token)
126 post("/email_invite", AdminAPIController, :email_invite)
127
128 get("/password_reset", AdminAPIController, :get_password_reset)
129 end
130
131 scope "/", Pleroma.Web.TwitterAPI do
132 pipe_through(:pleroma_html)
133 get("/ostatus_subscribe", UtilController, :remote_follow)
134 post("/ostatus_subscribe", UtilController, :do_remote_follow)
135 post("/main/ostatus", UtilController, :remote_subscribe)
136 end
137
138 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
139 pipe_through(:authenticated_api)
140 post("/blocks_import", UtilController, :blocks_import)
141 post("/follow_import", UtilController, :follow_import)
142 post("/change_password", UtilController, :change_password)
143 post("/delete_account", UtilController, :delete_account)
144 end
145
146 scope "/oauth", Pleroma.Web.OAuth do
147 get("/authorize", OAuthController, :authorize)
148 post("/authorize", OAuthController, :create_authorization)
149 post("/token", OAuthController, :token_exchange)
150 post("/revoke", OAuthController, :token_revoke)
151 end
152
153 scope "/api/v1", Pleroma.Web.MastodonAPI do
154 pipe_through(:authenticated_api)
155
156 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
157 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
158 get("/accounts/relationships", MastodonAPIController, :relationships)
159 get("/accounts/search", MastodonAPIController, :account_search)
160 post("/accounts/:id/follow", MastodonAPIController, :follow)
161 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
162 post("/accounts/:id/block", MastodonAPIController, :block)
163 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
164 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
165 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
166 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
167
168 get("/follow_requests", MastodonAPIController, :follow_requests)
169 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
170 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
171
172 post("/follows", MastodonAPIController, :follow)
173
174 get("/blocks", MastodonAPIController, :blocks)
175
176 get("/mutes", MastodonAPIController, :empty_array)
177
178 get("/timelines/home", MastodonAPIController, :home_timeline)
179
180 get("/timelines/direct", MastodonAPIController, :dm_timeline)
181
182 get("/favourites", MastodonAPIController, :favourites)
183
184 post("/statuses", MastodonAPIController, :post_status)
185 delete("/statuses/:id", MastodonAPIController, :delete_status)
186
187 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
188 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
189 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
190 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
191
192 post("/notifications/clear", MastodonAPIController, :clear_notifications)
193 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
194 get("/notifications", MastodonAPIController, :notifications)
195 get("/notifications/:id", MastodonAPIController, :get_notification)
196
197 post("/media", MastodonAPIController, :upload)
198 put("/media/:id", MastodonAPIController, :update_media)
199
200 get("/lists", MastodonAPIController, :get_lists)
201 get("/lists/:id", MastodonAPIController, :get_list)
202 delete("/lists/:id", MastodonAPIController, :delete_list)
203 post("/lists", MastodonAPIController, :create_list)
204 put("/lists/:id", MastodonAPIController, :rename_list)
205 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
206 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
207 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
208
209 get("/domain_blocks", MastodonAPIController, :domain_blocks)
210 post("/domain_blocks", MastodonAPIController, :block_domain)
211 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
212
213 get("/filters", MastodonAPIController, :get_filters)
214 post("/filters", MastodonAPIController, :create_filter)
215 get("/filters/:id", MastodonAPIController, :get_filter)
216 put("/filters/:id", MastodonAPIController, :update_filter)
217 delete("/filters/:id", MastodonAPIController, :delete_filter)
218
219 post("/push/subscription", MastodonAPIController, :create_push_subscription)
220 get("/push/subscription", MastodonAPIController, :get_push_subscription)
221 put("/push/subscription", MastodonAPIController, :update_push_subscription)
222 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
223
224 get("/suggestions", MastodonAPIController, :suggestions)
225
226 get("/endorsements", MastodonAPIController, :empty_array)
227 end
228
229 scope "/api/web", Pleroma.Web.MastodonAPI do
230 pipe_through(:authenticated_api)
231
232 put("/settings", MastodonAPIController, :put_settings)
233 end
234
235 scope "/api", Pleroma.Web.RichMedia do
236 pipe_through(:authenticated_api)
237
238 get("/rich_media/parse", RichMediaController, :parse)
239 end
240
241 scope "/api/v1", Pleroma.Web.MastodonAPI do
242 pipe_through(:api)
243 get("/instance", MastodonAPIController, :masto_instance)
244 get("/instance/peers", MastodonAPIController, :peers)
245 post("/apps", MastodonAPIController, :create_app)
246 get("/custom_emojis", MastodonAPIController, :custom_emojis)
247
248 get("/timelines/public", MastodonAPIController, :public_timeline)
249 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
250 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
251
252 get("/statuses/:id", MastodonAPIController, :get_status)
253 get("/statuses/:id/context", MastodonAPIController, :get_context)
254 get("/statuses/:id/card", MastodonAPIController, :empty_object)
255 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
256 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
257
258 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
259 get("/accounts/:id/followers", MastodonAPIController, :followers)
260 get("/accounts/:id/following", MastodonAPIController, :following)
261 get("/accounts/:id", MastodonAPIController, :user)
262
263 get("/trends", MastodonAPIController, :empty_array)
264
265 get("/search", MastodonAPIController, :search)
266 end
267
268 scope "/api/v2", Pleroma.Web.MastodonAPI do
269 pipe_through(:api)
270 get("/search", MastodonAPIController, :search2)
271 end
272
273 scope "/api", Pleroma.Web do
274 pipe_through(:config)
275
276 get("/help/test", TwitterAPI.UtilController, :help_test)
277 post("/help/test", TwitterAPI.UtilController, :help_test)
278 get("/statusnet/config", TwitterAPI.UtilController, :config)
279 get("/statusnet/version", TwitterAPI.UtilController, :version)
280 end
281
282 scope "/api", Pleroma.Web do
283 pipe_through(:api)
284
285 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
286 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
287 get("/users/show", TwitterAPI.Controller, :show_user)
288
289 get("/statuses/followers", TwitterAPI.Controller, :followers)
290 get("/statuses/friends", TwitterAPI.Controller, :friends)
291 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
292 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
293 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
294
295 post("/account/register", TwitterAPI.Controller, :register)
296 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
297
298 get(
299 "/account/confirm_email/:user_id/:token",
300 TwitterAPI.Controller,
301 :confirm_email,
302 as: :confirm_email
303 )
304
305 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
306
307 get("/search", TwitterAPI.Controller, :search)
308 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
309 end
310
311 scope "/api", Pleroma.Web do
312 pipe_through(:api)
313
314 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
315
316 get(
317 "/statuses/public_and_external_timeline",
318 TwitterAPI.Controller,
319 :public_and_external_timeline
320 )
321
322 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
323 end
324
325 scope "/api", Pleroma.Web, as: :twitter_api_search do
326 pipe_through(:api)
327 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
328 end
329
330 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
331 pipe_through(:authenticated_api)
332
333 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
334 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
335
336 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
337 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
338 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
339
340 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
341 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
342 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
343 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
344 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
345 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
346
347 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
348 # for now.
349 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
350
351 post("/statuses/update", TwitterAPI.Controller, :status_update)
352 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
353 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
354 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
355
356 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
357 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
358 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
359
360 post("/friendships/create", TwitterAPI.Controller, :follow)
361 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
362 post("/blocks/create", TwitterAPI.Controller, :block)
363 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
364
365 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
366 post("/media/upload", TwitterAPI.Controller, :upload_json)
367 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
368
369 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
370 post("/favorites/create", TwitterAPI.Controller, :favorite)
371 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
372
373 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
374
375 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
376 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
377
378 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
379 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
380
381 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
382 end
383
384 pipeline :ap_relay do
385 plug(:accepts, ["activity+json"])
386 end
387
388 pipeline :ostatus do
389 plug(:accepts, ["xml", "atom", "html", "activity+json"])
390 end
391
392 scope "/", Pleroma.Web do
393 pipe_through(:ostatus)
394
395 get("/objects/:uuid", OStatus.OStatusController, :object)
396 get("/activities/:uuid", OStatus.OStatusController, :activity)
397 get("/notice/:id", OStatus.OStatusController, :notice)
398 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
399 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
400
401 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
402 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
403 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
404 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
405 end
406
407 pipeline :activitypub do
408 plug(:accepts, ["activity+json"])
409 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
410 end
411
412 scope "/", Pleroma.Web.ActivityPub do
413 # XXX: not really ostatus
414 pipe_through(:ostatus)
415
416 get("/users/:nickname/followers", ActivityPubController, :followers)
417 get("/users/:nickname/following", ActivityPubController, :following)
418 get("/users/:nickname/outbox", ActivityPubController, :outbox)
419 end
420
421 pipeline :activitypub_client do
422 plug(:accepts, ["activity+json"])
423 plug(:fetch_session)
424 plug(Pleroma.Plugs.OAuthPlug)
425 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
426 plug(Pleroma.Plugs.UserFetcherPlug)
427 plug(Pleroma.Plugs.SessionAuthenticationPlug)
428 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
429 plug(Pleroma.Plugs.AuthenticationPlug)
430 plug(Pleroma.Plugs.UserEnabledPlug)
431 plug(Pleroma.Plugs.SetUserSessionIdPlug)
432 plug(Pleroma.Plugs.EnsureUserKeyPlug)
433 end
434
435 scope "/", Pleroma.Web.ActivityPub do
436 pipe_through([:activitypub_client])
437
438 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
439 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
440 end
441
442 scope "/relay", Pleroma.Web.ActivityPub do
443 pipe_through(:ap_relay)
444 get("/", ActivityPubController, :relay)
445 end
446
447 scope "/", Pleroma.Web.ActivityPub do
448 pipe_through(:activitypub)
449 post("/users/:nickname/inbox", ActivityPubController, :inbox)
450 post("/inbox", ActivityPubController, :inbox)
451 end
452
453 scope "/.well-known", Pleroma.Web do
454 pipe_through(:well_known)
455
456 get("/host-meta", WebFinger.WebFingerController, :host_meta)
457 get("/webfinger", WebFinger.WebFingerController, :webfinger)
458 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
459 end
460
461 scope "/nodeinfo", Pleroma.Web do
462 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
463 end
464
465 scope "/", Pleroma.Web.MastodonAPI do
466 pipe_through(:mastodon_html)
467
468 get("/web/login", MastodonAPIController, :login)
469 post("/web/login", MastodonAPIController, :login_post)
470 get("/web/*path", MastodonAPIController, :index)
471 delete("/auth/sign_out", MastodonAPIController, :logout)
472 end
473
474 pipeline :remote_media do
475 end
476
477 scope "/proxy/", Pleroma.Web.MediaProxy do
478 pipe_through(:remote_media)
479 get("/:sig/:url", MediaProxyController, :remote)
480 get("/:sig/:url/:filename", MediaProxyController, :remote)
481 end
482
483 if Mix.env() == :dev do
484 scope "/dev" do
485 pipe_through([:mailbox_preview])
486
487 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
488 end
489 end
490
491 scope "/", Fallback do
492 get("/registration/:token", RedirectController, :registration_page)
493 get("/*path", RedirectController, :redirector)
494
495 options("/*path", RedirectController, :empty)
496 end
497 end
498
499 defmodule Fallback.RedirectController do
500 use Pleroma.Web, :controller
501
502 def redirector(conn, _params) do
503 conn
504 |> put_resp_content_type("text/html")
505 |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html"))
506 end
507
508 def registration_page(conn, params) do
509 redirector(conn, params)
510 end
511
512 def empty(conn, _params) do
513 conn
514 |> put_status(204)
515 |> text("")
516 end
517 end