Merge branch 'security/ap-unsigned-create' into 'develop'
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 alias Pleroma.{Repo, User, Web.Router}
5
6 @instance Application.get_env(:pleroma, :instance)
7 @federating Keyword.get(@instance, :federating)
8 @allow_relay Keyword.get(@instance, :allow_relay)
9 @public Keyword.get(@instance, :public)
10 @registrations_open Keyword.get(@instance, :registrations_open)
11
12 pipeline :api do
13 plug(:accepts, ["json"])
14 plug(:fetch_session)
15 plug(Pleroma.Plugs.OAuthPlug)
16 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
17 plug(Pleroma.Plugs.UserFetcherPlug)
18 plug(Pleroma.Plugs.SessionAuthenticationPlug)
19 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
20 plug(Pleroma.Plugs.AuthenticationPlug)
21 plug(Pleroma.Plugs.UserEnabledPlug)
22 plug(Pleroma.Plugs.SetUserSessionIdPlug)
23 plug(Pleroma.Plugs.EnsureUserKeyPlug)
24 end
25
26 pipeline :authenticated_api do
27 plug(:accepts, ["json"])
28 plug(:fetch_session)
29 plug(Pleroma.Plugs.OAuthPlug)
30 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
31 plug(Pleroma.Plugs.UserFetcherPlug)
32 plug(Pleroma.Plugs.SessionAuthenticationPlug)
33 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
34 plug(Pleroma.Plugs.AuthenticationPlug)
35 plug(Pleroma.Plugs.UserEnabledPlug)
36 plug(Pleroma.Plugs.SetUserSessionIdPlug)
37 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
38 end
39
40 pipeline :mastodon_html do
41 plug(:accepts, ["html"])
42 plug(:fetch_session)
43 plug(Pleroma.Plugs.OAuthPlug)
44 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
45 plug(Pleroma.Plugs.UserFetcherPlug)
46 plug(Pleroma.Plugs.SessionAuthenticationPlug)
47 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
48 plug(Pleroma.Plugs.AuthenticationPlug)
49 plug(Pleroma.Plugs.UserEnabledPlug)
50 plug(Pleroma.Plugs.SetUserSessionIdPlug)
51 plug(Pleroma.Plugs.EnsureUserKeyPlug)
52 end
53
54 pipeline :pleroma_html do
55 plug(:accepts, ["html"])
56 plug(:fetch_session)
57 plug(Pleroma.Plugs.OAuthPlug)
58 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
59 plug(Pleroma.Plugs.UserFetcherPlug)
60 plug(Pleroma.Plugs.SessionAuthenticationPlug)
61 plug(Pleroma.Plugs.AuthenticationPlug)
62 plug(Pleroma.Plugs.EnsureUserKeyPlug)
63 end
64
65 pipeline :well_known do
66 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
67 end
68
69 pipeline :config do
70 plug(:accepts, ["json", "xml"])
71 end
72
73 pipeline :oauth do
74 plug(:accepts, ["html", "json"])
75 end
76
77 pipeline :pleroma_api do
78 plug(:accepts, ["html", "json"])
79 end
80
81 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
82 pipe_through(:pleroma_api)
83 get("/password_reset/:token", UtilController, :show_password_reset)
84 post("/password_reset", UtilController, :password_reset)
85 get("/emoji", UtilController, :emoji)
86 end
87
88 scope "/", Pleroma.Web.TwitterAPI do
89 pipe_through(:pleroma_html)
90 get("/ostatus_subscribe", UtilController, :remote_follow)
91 post("/ostatus_subscribe", UtilController, :do_remote_follow)
92 post("/main/ostatus", UtilController, :remote_subscribe)
93 end
94
95 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
96 pipe_through(:authenticated_api)
97 post("/follow_import", UtilController, :follow_import)
98 post("/change_password", UtilController, :change_password)
99 post("/delete_account", UtilController, :delete_account)
100 end
101
102 scope "/oauth", Pleroma.Web.OAuth do
103 get("/authorize", OAuthController, :authorize)
104 post("/authorize", OAuthController, :create_authorization)
105 post("/token", OAuthController, :token_exchange)
106 post("/revoke", OAuthController, :token_revoke)
107 end
108
109 scope "/api/v1", Pleroma.Web.MastodonAPI do
110 pipe_through(:authenticated_api)
111
112 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
113 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
114 get("/accounts/relationships", MastodonAPIController, :relationships)
115 get("/accounts/search", MastodonAPIController, :account_search)
116 post("/accounts/:id/follow", MastodonAPIController, :follow)
117 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
118 post("/accounts/:id/block", MastodonAPIController, :block)
119 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
120 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
121 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
122
123 get("/follow_requests", MastodonAPIController, :follow_requests)
124 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
125 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
126
127 post("/follows", MastodonAPIController, :follow)
128
129 get("/blocks", MastodonAPIController, :blocks)
130
131 get("/mutes", MastodonAPIController, :empty_array)
132
133 get("/timelines/home", MastodonAPIController, :home_timeline)
134
135 get("/timelines/direct", MastodonAPIController, :dm_timeline)
136
137 get("/favourites", MastodonAPIController, :favourites)
138
139 post("/statuses", MastodonAPIController, :post_status)
140 delete("/statuses/:id", MastodonAPIController, :delete_status)
141
142 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
143 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
144 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
145 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
146
147 post("/notifications/clear", MastodonAPIController, :clear_notifications)
148 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
149 get("/notifications", MastodonAPIController, :notifications)
150 get("/notifications/:id", MastodonAPIController, :get_notification)
151
152 post("/media", MastodonAPIController, :upload)
153 put("/media/:id", MastodonAPIController, :update_media)
154
155 get("/lists", MastodonAPIController, :get_lists)
156 get("/lists/:id", MastodonAPIController, :get_list)
157 delete("/lists/:id", MastodonAPIController, :delete_list)
158 post("/lists", MastodonAPIController, :create_list)
159 put("/lists/:id", MastodonAPIController, :rename_list)
160 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
161 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
162 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
163
164 get("/domain_blocks", MastodonAPIController, :domain_blocks)
165 post("/domain_blocks", MastodonAPIController, :block_domain)
166 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
167
168 get("/filters", MastodonAPIController, :get_filters)
169 post("/filters", MastodonAPIController, :create_filter)
170 get("/filters/:id", MastodonAPIController, :get_filter)
171 put("/filters/:id", MastodonAPIController, :update_filter)
172 delete("/filters/:id", MastodonAPIController, :delete_filter)
173
174 get("/suggestions", MastodonAPIController, :suggestions)
175
176 get("/endorsements", MastodonAPIController, :empty_array)
177 end
178
179 scope "/api/web", Pleroma.Web.MastodonAPI do
180 pipe_through(:authenticated_api)
181
182 put("/settings", MastodonAPIController, :put_settings)
183 end
184
185 scope "/api/v1", Pleroma.Web.MastodonAPI do
186 pipe_through(:api)
187 get("/instance", MastodonAPIController, :masto_instance)
188 get("/instance/peers", MastodonAPIController, :peers)
189 post("/apps", MastodonAPIController, :create_app)
190 get("/custom_emojis", MastodonAPIController, :custom_emojis)
191
192 get("/timelines/public", MastodonAPIController, :public_timeline)
193 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
194 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
195
196 get("/statuses/:id", MastodonAPIController, :get_status)
197 get("/statuses/:id/context", MastodonAPIController, :get_context)
198 get("/statuses/:id/card", MastodonAPIController, :empty_object)
199 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
200 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
201
202 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
203 get("/accounts/:id/followers", MastodonAPIController, :followers)
204 get("/accounts/:id/following", MastodonAPIController, :following)
205 get("/accounts/:id", MastodonAPIController, :user)
206
207 get("/trends", MastodonAPIController, :empty_array)
208
209 get("/search", MastodonAPIController, :search)
210 end
211
212 scope "/api/v2", Pleroma.Web.MastodonAPI do
213 pipe_through(:api)
214 get("/search", MastodonAPIController, :search2)
215 end
216
217 scope "/api", Pleroma.Web do
218 pipe_through(:config)
219
220 get("/help/test", TwitterAPI.UtilController, :help_test)
221 post("/help/test", TwitterAPI.UtilController, :help_test)
222 get("/statusnet/config", TwitterAPI.UtilController, :config)
223 get("/statusnet/version", TwitterAPI.UtilController, :version)
224 end
225
226 scope "/api", Pleroma.Web do
227 pipe_through(:api)
228
229 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
230 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
231 get("/users/show", TwitterAPI.Controller, :show_user)
232
233 get("/statuses/followers", TwitterAPI.Controller, :followers)
234 get("/statuses/friends", TwitterAPI.Controller, :friends)
235 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
236 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
237
238 post("/account/register", TwitterAPI.Controller, :register)
239
240 get("/search", TwitterAPI.Controller, :search)
241 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
242 end
243
244 scope "/api", Pleroma.Web do
245 if @public do
246 pipe_through(:api)
247 else
248 pipe_through(:authenticated_api)
249 end
250
251 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
252
253 get(
254 "/statuses/public_and_external_timeline",
255 TwitterAPI.Controller,
256 :public_and_external_timeline
257 )
258
259 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
260 end
261
262 scope "/api", Pleroma.Web do
263 pipe_through(:authenticated_api)
264
265 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
266 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
267
268 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
269 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
270 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
271
272 post(
273 "/account/most_recent_notification",
274 TwitterAPI.Controller,
275 :update_most_recent_notification
276 )
277
278 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
279 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
280 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
281 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
282 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
283
284 post("/statuses/update", TwitterAPI.Controller, :status_update)
285 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
286 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
287 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
288
289 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
290 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
291 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
292
293 post("/friendships/create", TwitterAPI.Controller, :follow)
294 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
295 post("/blocks/create", TwitterAPI.Controller, :block)
296 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
297
298 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
299 post("/media/upload", TwitterAPI.Controller, :upload_json)
300
301 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
302 post("/favorites/create", TwitterAPI.Controller, :favorite)
303 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
304
305 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
306
307 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
308 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
309
310 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
311 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
312
313 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
314 end
315
316 pipeline :ap_relay do
317 plug(:accepts, ["activity+json"])
318 end
319
320 pipeline :ostatus do
321 plug(:accepts, ["xml", "atom", "html", "activity+json"])
322 end
323
324 scope "/", Pleroma.Web do
325 pipe_through(:ostatus)
326
327 get("/objects/:uuid", OStatus.OStatusController, :object)
328 get("/activities/:uuid", OStatus.OStatusController, :activity)
329 get("/notice/:id", OStatus.OStatusController, :notice)
330 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
331 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
332
333 if @federating do
334 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
335 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
336 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
337 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
338 end
339 end
340
341 pipeline :activitypub do
342 plug(:accepts, ["activity+json"])
343 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
344 end
345
346 scope "/", Pleroma.Web.ActivityPub do
347 # XXX: not really ostatus
348 pipe_through(:ostatus)
349
350 get("/users/:nickname/followers", ActivityPubController, :followers)
351 get("/users/:nickname/following", ActivityPubController, :following)
352 get("/users/:nickname/outbox", ActivityPubController, :outbox)
353 end
354
355 if @federating do
356 if @allow_relay do
357 scope "/relay", Pleroma.Web.ActivityPub do
358 pipe_through(:ap_relay)
359 get("/", ActivityPubController, :relay)
360 end
361 end
362
363 scope "/", Pleroma.Web.ActivityPub do
364 pipe_through(:activitypub)
365 post("/users/:nickname/inbox", ActivityPubController, :inbox)
366 post("/inbox", ActivityPubController, :inbox)
367 end
368
369 scope "/.well-known", Pleroma.Web do
370 pipe_through(:well_known)
371
372 get("/host-meta", WebFinger.WebFingerController, :host_meta)
373 get("/webfinger", WebFinger.WebFingerController, :webfinger)
374 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
375 end
376
377 scope "/nodeinfo", Pleroma.Web do
378 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
379 end
380 end
381
382 scope "/", Pleroma.Web.MastodonAPI do
383 pipe_through(:mastodon_html)
384
385 get("/web/login", MastodonAPIController, :login)
386 post("/web/login", MastodonAPIController, :login_post)
387 get("/web/*path", MastodonAPIController, :index)
388 delete("/auth/sign_out", MastodonAPIController, :logout)
389 end
390
391 pipeline :remote_media do
392 plug(:accepts, ["html"])
393 end
394
395 scope "/proxy/", Pleroma.Web.MediaProxy do
396 pipe_through(:remote_media)
397 get("/:sig/:url", MediaProxyController, :remote)
398 end
399
400 scope "/", Fallback do
401 get("/registration/:token", RedirectController, :registration_page)
402 get("/*path", RedirectController, :redirector)
403
404 options("/*path", RedirectController, :empty)
405 end
406 end
407
408 defmodule Fallback.RedirectController do
409 use Pleroma.Web, :controller
410
411 def redirector(conn, _params) do
412 if Mix.env() != :test do
413 conn
414 |> put_resp_content_type("text/html")
415 |> send_file(200, "priv/static/index.html")
416 end
417 end
418
419 def registration_page(conn, params) do
420 redirector(conn, params)
421 end
422
423 def empty(conn, _params) do
424 conn
425 |> put_status(204)
426 |> text("")
427 end
428 end