Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
6fe23c54
Verified
Commit
6fe23c54
authored
Nov 05, 2018
by
href
Browse files
Runtime configured router
parent
bd97b361
Changes
8
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/plugs/federating_plug.ex
0 → 100644
View file @
6fe23c54
defmodule
Pleroma
.
Web
.
FederatingPlug
do
import
Plug
.
Conn
def
init
(
options
)
do
options
end
def
call
(
conn
,
opts
)
do
if
Keyword
.
get
(
Application
.
get_env
(
:pleroma
,
:instance
),
:federating
)
do
conn
else
conn
|>
put_status
(
404
)
|>
Phoenix
.
Controller
.
render
(
Pleroma
.
Web
.
ErrorView
,
"404.json"
)
|>
halt
()
end
end
end
lib/pleroma/web/activity_pub/activity_pub_controller.ex
View file @
6fe23c54
...
...
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
action_fallback
(
:errors
)
plug
(
Pleroma
.
Web
.
FederatingPlug
when
action
in
[
:inbox
,
:relay
])
plug
(
:relay_active?
when
action
in
[
:relay
])
def
relay_active?
(
conn
,
_
)
do
...
...
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
View file @
6fe23c54
...
...
@@ -6,6 +6,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
alias
Pleroma
.
{
User
,
Repo
}
alias
Pleroma
.
Web
.
ActivityPub
.
MRF
plug
(
Pleroma
.
Web
.
FederatingPlug
)
def
schemas
(
conn
,
_params
)
do
response
=
%{
links:
[
...
...
lib/pleroma/web/ostatus/ostatus_controller.ex
View file @
6fe23c54
...
...
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPubController
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
plug
(
Pleroma
.
Web
.
FederatingPlug
when
action
in
[
:salmon_incoming
])
action_fallback
(
:errors
)
def
feed_redirect
(
conn
,
%{
"nickname"
=>
nickname
})
do
...
...
lib/pleroma/web/router.ex
View file @
6fe23c54
...
...
@@ -3,11 +3,6 @@ defmodule Pleroma.Web.Router do
alias
Pleroma
.
{
Repo
,
User
,
Web
.
Router
}
@instance
Application
.
get_env
(
:pleroma
,
:instance
)
@federating
Keyword
.
get
(
@instance
,
:federating
)
@public
Keyword
.
get
(
@instance
,
:public
)
@registrations_open
Keyword
.
get
(
@instance
,
:registrations_open
)
pipeline
:api
do
plug
(
:accepts
,
[
"json"
])
plug
(
:fetch_session
)
...
...
@@ -242,11 +237,7 @@ defmodule Pleroma.Web.Router do
end
scope
"/api"
,
Pleroma
.
Web
do
if
@public
do
pipe_through
(
:api
)
else
pipe_through
(
:authenticated_api
)
end
pipe_through
(
:api
)
get
(
"/statuses/public_timeline"
,
TwitterAPI
.
Controller
,
:public_timeline
)
...
...
@@ -330,12 +321,10 @@ defmodule Pleroma.Web.Router do
get
(
"/users/:nickname/feed"
,
OStatus
.
OStatusController
,
:feed
)
get
(
"/users/:nickname"
,
OStatus
.
OStatusController
,
:feed_redirect
)
if
@federating
do
post
(
"/users/:nickname/salmon"
,
OStatus
.
OStatusController
,
:salmon_incoming
)
post
(
"/push/hub/:nickname"
,
Websub
.
WebsubController
,
:websub_subscription_request
)
get
(
"/push/subscriptions/:id"
,
Websub
.
WebsubController
,
:websub_subscription_confirmation
)
post
(
"/push/subscriptions/:id"
,
Websub
.
WebsubController
,
:websub_incoming
)
end
post
(
"/users/:nickname/salmon"
,
OStatus
.
OStatusController
,
:salmon_incoming
)
post
(
"/push/hub/:nickname"
,
Websub
.
WebsubController
,
:websub_subscription_request
)
get
(
"/push/subscriptions/:id"
,
Websub
.
WebsubController
,
:websub_subscription_confirmation
)
post
(
"/push/subscriptions/:id"
,
Websub
.
WebsubController
,
:websub_incoming
)
end
pipeline
:activitypub
do
...
...
@@ -352,29 +341,27 @@ defmodule Pleroma.Web.Router do
get
(
"/users/:nickname/outbox"
,
ActivityPubController
,
:outbox
)
end
if
@federating
do
scope
"/relay"
,
Pleroma
.
Web
.
ActivityPub
do
pipe_through
(
:ap_relay
)
get
(
"/"
,
ActivityPubController
,
:relay
)
end
scope
"/relay"
,
Pleroma
.
Web
.
ActivityPub
do
pipe_through
(
:ap_relay
)
get
(
"/"
,
ActivityPubController
,
:relay
)
end
scope
"/"
,
Pleroma
.
Web
.
ActivityPub
do
pipe_through
(
:activitypub
)
post
(
"/users/:nickname/inbox"
,
ActivityPubController
,
:inbox
)
post
(
"/inbox"
,
ActivityPubController
,
:inbox
)
end
scope
"/"
,
Pleroma
.
Web
.
ActivityPub
do
pipe_through
(
:activitypub
)
post
(
"/users/:nickname/inbox"
,
ActivityPubController
,
:inbox
)
post
(
"/inbox"
,
ActivityPubController
,
:inbox
)
end
scope
"/.well-known"
,
Pleroma
.
Web
do
pipe_through
(
:well_known
)
scope
"/.well-known"
,
Pleroma
.
Web
do
pipe_through
(
:well_known
)
get
(
"/host-meta"
,
WebFinger
.
WebFingerController
,
:host_meta
)
get
(
"/webfinger"
,
WebFinger
.
WebFingerController
,
:webfinger
)
get
(
"/nodeinfo"
,
Nodeinfo
.
NodeinfoController
,
:schemas
)
end
get
(
"/host-meta"
,
WebFinger
.
WebFingerController
,
:host_meta
)
get
(
"/webfinger"
,
WebFinger
.
WebFingerController
,
:webfinger
)
get
(
"/nodeinfo"
,
Nodeinfo
.
NodeinfoController
,
:schemas
)
end
scope
"/nodeinfo"
,
Pleroma
.
Web
do
get
(
"/:version"
,
Nodeinfo
.
NodeinfoController
,
:nodeinfo
)
end
scope
"/nodeinfo"
,
Pleroma
.
Web
do
get
(
"/:version"
,
Nodeinfo
.
NodeinfoController
,
:nodeinfo
)
end
scope
"/"
,
Pleroma
.
Web
.
MastodonAPI
do
...
...
lib/pleroma/web/twitter_api/twitter_api_controller.ex
View file @
6fe23c54
...
...
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
require
Logger
plug
(
:only_if_public_instance
when
action
in
[
:public_timeline
,
:public_and_external_timeline
])
action_fallback
(
:errors
)
def
verify_credentials
(%{
assigns:
%{
user:
user
}}
=
conn
,
_params
)
do
...
...
@@ -518,6 +519,17 @@ defp forbidden_json_reply(conn, error_message) do
json_reply
(
conn
,
403
,
json
)
end
def
only_if_public_instance
(
conn
=
%{
conn:
%{
assigns:
%{
user:
_user
}}},
_
),
do
:
conn
def
only_if_public_instance
(
conn
,
_
)
do
if
Keyword
.
get
(
Application
.
get_env
(
:pleroma
,
:instance
),
:public
)
do
conn
else
conn
|>
forbidden_json_reply
(
"Invalid credentials."
)
end
end
defp
error_json
(
conn
,
error_message
)
do
%{
"error"
=>
error_message
,
"request"
=>
conn
.
request_path
}
|>
Jason
.
encode!
()
end
...
...
lib/pleroma/web/web_finger/web_finger_controller.ex
View file @
6fe23c54
...
...
@@ -3,6 +3,8 @@ defmodule Pleroma.Web.WebFinger.WebFingerController do
alias
Pleroma
.
Web
.
WebFinger
plug
(
Pleroma
.
Web
.
FederatingPlug
)
def
host_meta
(
conn
,
_params
)
do
xml
=
WebFinger
.
host_meta
()
...
...
lib/pleroma/web/websub/websub_controller.ex
View file @
6fe23c54
...
...
@@ -5,6 +5,15 @@ defmodule Pleroma.Web.Websub.WebsubController do
alias
Pleroma
.
Web
.
Websub
.
WebsubClientSubscription
require
Logger
plug
(
Pleroma
.
Web
.
FederatingPlug
when
action
in
[
:websub_subscription_request
,
:websub_subscription_confirmation
,
:websub_incoming
]
)
def
websub_subscription_request
(
conn
,
%{
"nickname"
=>
nickname
}
=
params
)
do
user
=
User
.
get_cached_by_nickname
(
nickname
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment