projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'develop' into dtluna/pleroma-refactor/1
[akkoma]
/
lib
/
pleroma
/
web
/
websub
/
websub.ex
diff --git
a/lib/pleroma/web/websub/websub.ex
b/lib/pleroma/web/websub/websub.ex
index c1532b6ce4393123e4765a747ec1e23219d0e41a..afbe944c57996e0b08670c7598c7161b338fa1f3 100644
(file)
--- a/
lib/pleroma/web/websub/websub.ex
+++ b/
lib/pleroma/web/websub/websub.ex
@@
-1,4
+1,5
@@
defmodule Pleroma.Web.Websub do
defmodule Pleroma.Web.Websub do
+ alias Ecto.Changeset
alias Pleroma.Repo
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
alias Pleroma.Web.OStatus.FeedRepresenter
alias Pleroma.Repo
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
alias Pleroma.Web.OStatus.FeedRepresenter
@@
-8,9
+9,12
@@
defmodule Pleroma.Web.Websub do
import Ecto.Query
import Ecto.Query
- def verify(subscription, getter \\ &HTTPoison.get/3 ) do
+ @websub_verifier Application.get_env(:pleroma, :websub_verifier)
+
+ def verify(subscription, getter \\ &HTTPoison.get/3) do
challenge = Base.encode16(:crypto.strong_rand_bytes(8))
challenge = Base.encode16(:crypto.strong_rand_bytes(8))
- lease_seconds = NaiveDateTime.diff(subscription.valid_until, subscription.updated_at) |> to_string
+ lease_seconds = NaiveDateTime.diff(subscription.valid_until, subscription.updated_at)
+ lease_seconds = lease_seconds |> to_string
params = %{
"hub.challenge": challenge,
params = %{
"hub.challenge": challenge,
@@
-25,11
+29,11
@@
defmodule Pleroma.Web.Websub do
with {:ok, response} <- getter.(url, [], [params: params]),
^challenge <- response.body
do
with {:ok, response} <- getter.(url, [], [params: params]),
^challenge <- response.body
do
- changeset =
Ecto.
Changeset.change(subscription, %{state: "active"})
+ changeset = Changeset.change(subscription, %{state: "active"})
Repo.update(changeset)
else _e ->
Repo.update(changeset)
else _e ->
- changeset =
Ecto.
Changeset.change(subscription, %{state: "rejected"})
- {:ok, subscription
} = Repo.update(changeset)
+ changeset = Changeset.change(subscription, %{state: "rejected"})
+ {:ok, subscription} = Repo.update(changeset)
{:error, subscription}
end
end
{:error, subscription}
end
end
@@
-39,12
+43,14
@@
defmodule Pleroma.Web.Websub do
where: sub.topic == ^topic and sub.state == "active"
subscriptions = Repo.all(query)
Enum.each(subscriptions, fn(sub) ->
where: sub.topic == ^topic and sub.state == "active"
subscriptions = Repo.all(query)
Enum.each(subscriptions, fn(sub) ->
- response = FeedRepresenter.to_simple_form(user, [activity], [user])
+ response = user
+ |> FeedRepresenter.to_simple_form([activity], [user])
|> :xmerl.export_simple(:xmerl_xml)
|> to_string
|> :xmerl.export_simple(:xmerl_xml)
|> to_string
- signature = sign(sub.secret, response)
+ signature = sign(sub.secret
|| ""
, response)
Logger.debug("Pushing to #{sub.callback}")
Logger.debug("Pushing to #{sub.callback}")
+
HTTPoison.post(sub.callback, response, [
{"Content-Type", "application/atom+xml"},
{"X-Hub-Signature", "sha1=#{signature}"}
HTTPoison.post(sub.callback, response, [
{"Content-Type", "application/atom+xml"},
{"X-Hub-Signature", "sha1=#{signature}"}
@@
-70,10
+76,11
@@
defmodule Pleroma.Web.Websub do
callback: callback
}
callback: callback
}
- change =
Ecto.
Changeset.change(subscription, data)
+ change = Changeset.change(subscription, data)
websub = Repo.insert_or_update!(change)
websub = Repo.insert_or_update!(change)
- change = Ecto.Changeset.change(websub, %{valid_until: NaiveDateTime.add(websub.updated_at, lease_time)})
+ change = Changeset.change(websub, %{valid_until:
+ NaiveDateTime.add(websub.updated_at, lease_time)})
websub = Repo.update!(change)
Pleroma.Web.Federator.enqueue(:verify_websub, websub)
websub = Repo.update!(change)
Pleroma.Web.Federator.enqueue(:verify_websub, websub)
@@
-88,7
+95,8
@@
defmodule Pleroma.Web.Websub do
end
defp get_subscription(topic, callback) do
end
defp get_subscription(topic, callback) do
- Repo.get_by(WebsubServerSubscription, topic: topic, callback: callback) || %WebsubServerSubscription{}
+ Repo.get_by(WebsubServerSubscription, topic: topic, callback: callback) ||
+ %WebsubServerSubscription{}
end
# Temp hack for mastodon.
end
# Temp hack for mastodon.