Add LegacyAuthenticationPlug to router.
[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 end
107
108 scope "/api/v1", Pleroma.Web.MastodonAPI do
109 pipe_through(:authenticated_api)
110
111 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
112 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
113 get("/accounts/relationships", MastodonAPIController, :relationships)
114 get("/accounts/search", MastodonAPIController, :account_search)
115 post("/accounts/:id/follow", MastodonAPIController, :follow)
116 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
117 post("/accounts/:id/block", MastodonAPIController, :block)
118 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
119 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
120 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
121
122 get("/follow_requests", MastodonAPIController, :follow_requests)
123 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
124 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
125
126 post("/follows", MastodonAPIController, :follow)
127
128 get("/blocks", MastodonAPIController, :blocks)
129
130 get("/mutes", MastodonAPIController, :empty_array)
131
132 get("/timelines/home", MastodonAPIController, :home_timeline)
133
134 get("/timelines/direct", MastodonAPIController, :dm_timeline)
135
136 get("/favourites", MastodonAPIController, :favourites)
137
138 post("/statuses", MastodonAPIController, :post_status)
139 delete("/statuses/:id", MastodonAPIController, :delete_status)
140
141 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
142 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
143 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
144 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
145
146 post("/notifications/clear", MastodonAPIController, :clear_notifications)
147 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
148 get("/notifications", MastodonAPIController, :notifications)
149 get("/notifications/:id", MastodonAPIController, :get_notification)
150
151 post("/media", MastodonAPIController, :upload)
152 put("/media/:id", MastodonAPIController, :update_media)
153
154 get("/lists", MastodonAPIController, :get_lists)
155 get("/lists/:id", MastodonAPIController, :get_list)
156 delete("/lists/:id", MastodonAPIController, :delete_list)
157 post("/lists", MastodonAPIController, :create_list)
158 put("/lists/:id", MastodonAPIController, :rename_list)
159 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
160 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
161 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
162
163 get("/domain_blocks", MastodonAPIController, :domain_blocks)
164 post("/domain_blocks", MastodonAPIController, :block_domain)
165 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
166
167 get("/filters", MastodonAPIController, :get_filters)
168 post("/filters", MastodonAPIController, :create_filter)
169 get("/filters/:id", MastodonAPIController, :get_filter)
170 put("/filters/:id", MastodonAPIController, :update_filter)
171 delete("/filters/:id", MastodonAPIController, :delete_filter)
172
173 get("/suggestions", MastodonAPIController, :suggestions)
174 end
175
176 scope "/api/web", Pleroma.Web.MastodonAPI do
177 pipe_through(:authenticated_api)
178
179 put("/settings", MastodonAPIController, :put_settings)
180 end
181
182 scope "/api/v1", Pleroma.Web.MastodonAPI do
183 pipe_through(:api)
184 get("/instance", MastodonAPIController, :masto_instance)
185 get("/instance/peers", MastodonAPIController, :peers)
186 post("/apps", MastodonAPIController, :create_app)
187 get("/custom_emojis", MastodonAPIController, :custom_emojis)
188
189 get("/timelines/public", MastodonAPIController, :public_timeline)
190 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
191 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
192
193 get("/statuses/:id", MastodonAPIController, :get_status)
194 get("/statuses/:id/context", MastodonAPIController, :get_context)
195 get("/statuses/:id/card", MastodonAPIController, :empty_object)
196 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
197 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
198
199 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
200 get("/accounts/:id/followers", MastodonAPIController, :followers)
201 get("/accounts/:id/following", MastodonAPIController, :following)
202 get("/accounts/:id", MastodonAPIController, :user)
203
204 get("/trends", MastodonAPIController, :empty_array)
205
206 get("/search", MastodonAPIController, :search)
207 end
208
209 scope "/api/v2", Pleroma.Web.MastodonAPI do
210 pipe_through(:api)
211 get("/search", MastodonAPIController, :search2)
212 end
213
214 scope "/api", Pleroma.Web do
215 pipe_through(:config)
216
217 get("/help/test", TwitterAPI.UtilController, :help_test)
218 post("/help/test", TwitterAPI.UtilController, :help_test)
219 get("/statusnet/config", TwitterAPI.UtilController, :config)
220 get("/statusnet/version", TwitterAPI.UtilController, :version)
221 end
222
223 scope "/api", Pleroma.Web do
224 pipe_through(:api)
225
226 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
227 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
228 get("/users/show", TwitterAPI.Controller, :show_user)
229
230 get("/statuses/followers", TwitterAPI.Controller, :followers)
231 get("/statuses/friends", TwitterAPI.Controller, :friends)
232 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
233 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
234
235 post("/account/register", TwitterAPI.Controller, :register)
236
237 get("/search", TwitterAPI.Controller, :search)
238 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
239 end
240
241 scope "/api", Pleroma.Web do
242 if @public do
243 pipe_through(:api)
244 else
245 pipe_through(:authenticated_api)
246 end
247
248 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
249
250 get(
251 "/statuses/public_and_external_timeline",
252 TwitterAPI.Controller,
253 :public_and_external_timeline
254 )
255
256 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
257 end
258
259 scope "/api", Pleroma.Web do
260 pipe_through(:authenticated_api)
261
262 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
263 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
264
265 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
266 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
267 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
268
269 post(
270 "/account/most_recent_notification",
271 TwitterAPI.Controller,
272 :update_most_recent_notification
273 )
274
275 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
276 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
277 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
278 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
279 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
280
281 post("/statuses/update", TwitterAPI.Controller, :status_update)
282 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
283 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
284 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
285
286 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
287 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
288 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
289
290 post("/friendships/create", TwitterAPI.Controller, :follow)
291 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
292 post("/blocks/create", TwitterAPI.Controller, :block)
293 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
294
295 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
296 post("/media/upload", TwitterAPI.Controller, :upload_json)
297
298 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
299 post("/favorites/create", TwitterAPI.Controller, :favorite)
300 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
301
302 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
303
304 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
305 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
306
307 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
308 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
309
310 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
311 end
312
313 pipeline :ap_relay do
314 plug(:accepts, ["activity+json"])
315 end
316
317 pipeline :ostatus do
318 plug(:accepts, ["xml", "atom", "html", "activity+json"])
319 end
320
321 scope "/", Pleroma.Web do
322 pipe_through(:ostatus)
323
324 get("/objects/:uuid", OStatus.OStatusController, :object)
325 get("/activities/:uuid", OStatus.OStatusController, :activity)
326 get("/notice/:id", OStatus.OStatusController, :notice)
327 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
328 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
329
330 if @federating do
331 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
332 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
333 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
334 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
335 end
336 end
337
338 pipeline :activitypub do
339 plug(:accepts, ["activity+json"])
340 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
341 end
342
343 scope "/", Pleroma.Web.ActivityPub do
344 # XXX: not really ostatus
345 pipe_through(:ostatus)
346
347 get("/users/:nickname/followers", ActivityPubController, :followers)
348 get("/users/:nickname/following", ActivityPubController, :following)
349 get("/users/:nickname/outbox", ActivityPubController, :outbox)
350 end
351
352 if @federating do
353 if @allow_relay do
354 scope "/relay", Pleroma.Web.ActivityPub do
355 pipe_through(:ap_relay)
356 get("/", ActivityPubController, :relay)
357 end
358 end
359
360 scope "/", Pleroma.Web.ActivityPub do
361 pipe_through(:activitypub)
362 post("/users/:nickname/inbox", ActivityPubController, :inbox)
363 post("/inbox", ActivityPubController, :inbox)
364 end
365
366 scope "/.well-known", Pleroma.Web do
367 pipe_through(:well_known)
368
369 get("/host-meta", WebFinger.WebFingerController, :host_meta)
370 get("/webfinger", WebFinger.WebFingerController, :webfinger)
371 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
372 end
373
374 scope "/nodeinfo", Pleroma.Web do
375 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
376 end
377 end
378
379 scope "/", Pleroma.Web.MastodonAPI do
380 pipe_through(:mastodon_html)
381
382 get("/web/login", MastodonAPIController, :login)
383 post("/web/login", MastodonAPIController, :login_post)
384 get("/web/*path", MastodonAPIController, :index)
385 delete("/auth/sign_out", MastodonAPIController, :logout)
386 end
387
388 pipeline :remote_media do
389 plug(:accepts, ["html"])
390 end
391
392 scope "/proxy/", Pleroma.Web.MediaProxy do
393 pipe_through(:remote_media)
394 get("/:sig/:url", MediaProxyController, :remote)
395 end
396
397 scope "/", Fallback do
398 get("/registration/:token", RedirectController, :registration_page)
399 get("/*path", RedirectController, :redirector)
400 end
401 end
402
403 defmodule Fallback.RedirectController do
404 use Pleroma.Web, :controller
405
406 def redirector(conn, _params) do
407 if Mix.env() != :test do
408 conn
409 |> put_resp_content_type("text/html")
410 |> send_file(200, "priv/static/index.html")
411 end
412 end
413
414 def registration_page(conn, params) do
415 redirector(conn, params)
416 end
417 end