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