2018-12-23 20:05:55 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:05:55 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-06-29 00:24:51 +00:00
|
|
|
defmodule Mix.Tasks.Pleroma.User do
|
|
|
|
use Mix.Task
|
2019-06-19 23:05:19 +00:00
|
|
|
import Mix.Pleroma
|
2019-10-20 10:42:42 +00:00
|
|
|
alias Ecto.Changeset
|
2019-02-09 15:16:26 +00:00
|
|
|
alias Pleroma.User
|
2021-12-05 21:56:11 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2019-04-06 09:58:22 +00:00
|
|
|
alias Pleroma.UserInviteToken
|
2020-05-01 12:05:25 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.Builder
|
|
|
|
alias Pleroma.Web.ActivityPub.Pipeline
|
2018-06-29 00:24:51 +00:00
|
|
|
|
|
|
|
@shortdoc "Manages Pleroma users"
|
2022-07-15 12:27:16 +00:00
|
|
|
@moduledoc File.read!("docs/docs/administration/CLI_tasks/user.md")
|
2018-06-29 00:24:51 +00:00
|
|
|
|
|
|
|
def run(["new", nickname, email | rest]) do
|
|
|
|
{options, [], []} =
|
|
|
|
OptionParser.parse(
|
|
|
|
rest,
|
|
|
|
strict: [
|
|
|
|
name: :string,
|
|
|
|
bio: :string,
|
|
|
|
password: :string,
|
2018-12-02 08:36:31 +00:00
|
|
|
moderator: :boolean,
|
2019-01-04 21:11:46 +00:00
|
|
|
admin: :boolean,
|
|
|
|
assume_yes: :boolean
|
|
|
|
],
|
|
|
|
aliases: [
|
|
|
|
y: :assume_yes
|
2018-06-29 00:24:51 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
name = Keyword.get(options, :name, nickname)
|
|
|
|
bio = Keyword.get(options, :bio, "")
|
|
|
|
|
|
|
|
{password, generated_password?} =
|
|
|
|
case Keyword.get(options, :password) do
|
|
|
|
nil ->
|
|
|
|
{:crypto.strong_rand_bytes(16) |> Base.encode64(), true}
|
|
|
|
|
|
|
|
password ->
|
|
|
|
{password, false}
|
|
|
|
end
|
|
|
|
|
|
|
|
moderator? = Keyword.get(options, :moderator, false)
|
2018-12-02 08:36:31 +00:00
|
|
|
admin? = Keyword.get(options, :admin, false)
|
2019-01-04 21:11:46 +00:00
|
|
|
assume_yes? = Keyword.get(options, :assume_yes, false)
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("""
|
2018-06-29 00:24:51 +00:00
|
|
|
A user will be created with the following information:
|
|
|
|
- nickname: #{nickname}
|
|
|
|
- email: #{email}
|
2021-10-06 06:08:21 +00:00
|
|
|
- password: #{if(generated_password?, do: "[generated; a reset link will be created]", else: password)}
|
2018-06-29 00:24:51 +00:00
|
|
|
- name: #{name}
|
|
|
|
- bio: #{bio}
|
|
|
|
- moderator: #{if(moderator?, do: "true", else: "false")}
|
2018-12-02 08:36:31 +00:00
|
|
|
- admin: #{if(admin?, do: "true", else: "false")}
|
2018-06-29 00:24:51 +00:00
|
|
|
""")
|
|
|
|
|
2020-11-27 19:42:28 +00:00
|
|
|
proceed? = assume_yes? or shell_prompt("Continue?", "n") in ~w(Yn Y y)
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2019-05-01 09:09:53 +00:00
|
|
|
if proceed? do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2018-12-16 16:25:31 +00:00
|
|
|
params = %{
|
|
|
|
nickname: nickname,
|
|
|
|
email: email,
|
|
|
|
password: password,
|
|
|
|
password_confirmation: password,
|
|
|
|
name: name,
|
|
|
|
bio: bio
|
|
|
|
}
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2020-10-13 19:29:34 +00:00
|
|
|
changeset = User.register_changeset(%User{}, params, is_confirmed: true)
|
2018-12-18 14:13:52 +00:00
|
|
|
{:ok, _user} = User.register(changeset)
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("User #{nickname} created")
|
2018-06-29 00:24:51 +00:00
|
|
|
|
|
|
|
if moderator? do
|
|
|
|
run(["set", nickname, "--moderator"])
|
|
|
|
end
|
|
|
|
|
2018-12-02 08:36:31 +00:00
|
|
|
if admin? do
|
|
|
|
run(["set", nickname, "--admin"])
|
|
|
|
end
|
|
|
|
|
2018-06-29 00:24:51 +00:00
|
|
|
if generated_password? do
|
|
|
|
run(["reset_password", nickname])
|
|
|
|
end
|
|
|
|
else
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("User will not be created.")
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["rm", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2020-05-01 12:05:25 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
|
|
|
|
{:ok, delete_data, _} <- Builder.delete(user, user.ap_id),
|
|
|
|
{:ok, _delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("User #{nickname} deleted.")
|
2018-12-02 08:36:31 +00:00
|
|
|
else
|
2020-02-25 14:34:56 +00:00
|
|
|
_ -> shell_error("No local user #{nickname}")
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["reset_password", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
|
2018-06-29 00:24:51 +00:00
|
|
|
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("Generated password reset token for #{user.nickname}")
|
2018-06-29 00:24:51 +00:00
|
|
|
|
2022-11-26 20:45:47 +00:00
|
|
|
IO.puts(
|
|
|
|
"URL: #{Pleroma.Web.Router.Helpers.reset_password_url(Pleroma.Web.Endpoint,
|
|
|
|
:reset,
|
|
|
|
token.token)}"
|
|
|
|
)
|
2018-06-29 00:24:51 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No local user #{nickname}")
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|
2018-12-02 17:05:59 +00:00
|
|
|
end
|
|
|
|
|
2020-06-11 20:54:39 +00:00
|
|
|
def run(["reset_mfa", nickname]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
|
|
|
|
{:ok, _token} <- Pleroma.MFA.disable(user) do
|
|
|
|
shell_info("Multi-Factor Authentication disabled for #{user.nickname}")
|
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
shell_error("No local user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-25 16:36:51 +00:00
|
|
|
def run(["activate", nickname]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
|
|
|
false <- user.is_active do
|
|
|
|
User.set_activation(user, true)
|
|
|
|
:timer.sleep(500)
|
|
|
|
|
|
|
|
shell_info("Successfully activated #{nickname}")
|
|
|
|
else
|
|
|
|
true ->
|
|
|
|
shell_info("User #{nickname} already activated")
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
shell_error("No user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-21 05:06:57 +00:00
|
|
|
def run(["deactivate", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-12-02 17:05:59 +00:00
|
|
|
|
2021-01-25 16:48:28 +00:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
|
|
|
true <- user.is_active do
|
2020-10-13 22:16:03 +00:00
|
|
|
User.set_activation(user, false)
|
2018-12-02 17:05:59 +00:00
|
|
|
:timer.sleep(500)
|
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
user = User.get_cached_by_id(user.id)
|
2018-12-02 17:05:59 +00:00
|
|
|
|
2020-05-12 03:44:33 +00:00
|
|
|
if Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) do
|
2021-01-25 16:48:28 +00:00
|
|
|
shell_info("Successfully deactivated #{nickname} and unsubscribed all local followers")
|
2018-12-02 17:05:59 +00:00
|
|
|
end
|
|
|
|
else
|
2021-01-25 16:48:28 +00:00
|
|
|
false ->
|
|
|
|
shell_info("User #{nickname} already deactivated")
|
|
|
|
|
2018-12-02 17:05:59 +00:00
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No user #{nickname}")
|
2018-12-02 17:05:59 +00:00
|
|
|
end
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|
|
|
|
|
2020-05-21 05:06:57 +00:00
|
|
|
def run(["deactivate_all_from_instance", instance]) do
|
2019-07-19 19:11:04 +00:00
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{nickname: "@#{instance}"})
|
2020-09-16 06:47:18 +00:00
|
|
|
|> Pleroma.Repo.chunk_stream(500, :batches)
|
2019-07-19 19:11:04 +00:00
|
|
|
|> Stream.each(fn users ->
|
|
|
|
users
|
|
|
|
|> Enum.each(fn user ->
|
2020-05-21 05:06:57 +00:00
|
|
|
run(["deactivate", user.nickname])
|
2019-07-19 19:11:04 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
2018-06-29 00:24:51 +00:00
|
|
|
def run(["set", nickname | rest]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-12-04 18:00:45 +00:00
|
|
|
|
2018-06-29 00:24:51 +00:00
|
|
|
{options, [], []} =
|
|
|
|
OptionParser.parse(
|
|
|
|
rest,
|
|
|
|
strict: [
|
2018-12-01 15:55:52 +00:00
|
|
|
admin: :boolean,
|
2020-09-08 21:39:41 +00:00
|
|
|
confirmed: :boolean,
|
|
|
|
locked: :boolean,
|
|
|
|
moderator: :boolean
|
2018-06-29 00:24:51 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
2018-12-12 20:32:32 +00:00
|
|
|
user =
|
2020-09-08 21:39:41 +00:00
|
|
|
case Keyword.get(options, :admin) do
|
2018-12-12 20:32:32 +00:00
|
|
|
nil -> user
|
2020-09-08 21:39:41 +00:00
|
|
|
value -> set_admin(user, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
user =
|
|
|
|
case Keyword.get(options, :confirmed) do
|
|
|
|
nil -> user
|
2020-10-13 21:07:36 +00:00
|
|
|
value -> set_confirmation(user, value)
|
2018-12-12 20:32:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
user =
|
|
|
|
case Keyword.get(options, :locked) do
|
|
|
|
nil -> user
|
|
|
|
value -> set_locked(user, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
_user =
|
2020-09-08 21:39:41 +00:00
|
|
|
case Keyword.get(options, :moderator) do
|
2018-12-12 20:32:32 +00:00
|
|
|
nil -> user
|
2020-09-08 21:39:41 +00:00
|
|
|
value -> set_moderator(user, value)
|
2018-12-12 20:32:32 +00:00
|
|
|
end
|
2018-06-29 00:24:51 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No local user #{nickname}")
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-04 02:33:11 +00:00
|
|
|
def run(["tag", nickname | tags]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-02-04 02:33:11 +00:00
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
2019-02-04 02:33:11 +00:00
|
|
|
user = user |> User.tag(tags)
|
|
|
|
|
2020-07-09 15:59:48 +00:00
|
|
|
shell_info("Tags of #{user.nickname}: #{inspect(user.tags)}")
|
2019-02-04 02:33:11 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("Could not change user tags for #{nickname}")
|
2019-02-04 02:33:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["untag", nickname | tags]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-02-04 02:33:11 +00:00
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
2019-02-04 02:33:11 +00:00
|
|
|
user = user |> User.untag(tags)
|
|
|
|
|
2020-07-09 15:59:48 +00:00
|
|
|
shell_info("Tags of #{user.nickname}: #{inspect(user.tags)}")
|
2019-02-04 02:33:11 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("Could not change user tags for #{nickname}")
|
2019-02-04 02:33:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-24 14:36:33 +00:00
|
|
|
def run(["refetch_public_keys"]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{
|
|
|
|
external: true,
|
|
|
|
is_active: true
|
|
|
|
})
|
|
|
|
|> refetch_public_keys()
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["refetch_public_keys" | rest]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{
|
|
|
|
ap_id: rest
|
|
|
|
})
|
|
|
|
|> refetch_public_keys()
|
|
|
|
end
|
|
|
|
|
2019-04-06 09:58:22 +00:00
|
|
|
def run(["invite" | rest]) do
|
|
|
|
{options, [], []} =
|
|
|
|
OptionParser.parse(rest,
|
|
|
|
strict: [
|
2019-04-08 09:01:28 +00:00
|
|
|
expires_at: :string,
|
2019-04-06 09:58:22 +00:00
|
|
|
max_use: :integer
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2019-04-06 15:38:35 +00:00
|
|
|
options =
|
|
|
|
options
|
2019-04-08 09:01:28 +00:00
|
|
|
|> Keyword.update(:expires_at, {:ok, nil}, fn
|
2019-04-06 15:38:35 +00:00
|
|
|
nil -> {:ok, nil}
|
|
|
|
val -> Date.from_iso8601(val)
|
|
|
|
end)
|
|
|
|
|> Enum.into(%{})
|
2019-04-06 09:58:22 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2018-12-09 09:12:48 +00:00
|
|
|
|
2019-04-08 09:01:28 +00:00
|
|
|
with {:ok, val} <- options[:expires_at],
|
|
|
|
options = Map.put(options, :expires_at, val),
|
2019-04-06 15:38:35 +00:00
|
|
|
{:ok, invite} <- UserInviteToken.create_invite(options) do
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("Generated user invite token " <> String.replace(invite.invite_type, "_", " "))
|
2018-12-09 09:12:48 +00:00
|
|
|
|
|
|
|
url =
|
|
|
|
Pleroma.Web.Router.Helpers.redirect_url(
|
|
|
|
Pleroma.Web.Endpoint,
|
|
|
|
:registration_page,
|
2019-04-06 13:24:22 +00:00
|
|
|
invite.token
|
2018-12-09 09:12:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
IO.puts(url)
|
|
|
|
else
|
2019-04-06 15:38:35 +00:00
|
|
|
error ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("Could not create invite token: #{inspect(error)}")
|
2018-12-09 09:12:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-06 15:38:35 +00:00
|
|
|
def run(["invites"]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-04-06 09:58:22 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("Invites list:")
|
2019-04-06 09:58:22 +00:00
|
|
|
|
|
|
|
UserInviteToken.list_invites()
|
|
|
|
|> Enum.each(fn invite ->
|
2019-04-06 15:38:35 +00:00
|
|
|
expire_info =
|
2019-04-08 09:01:28 +00:00
|
|
|
with expires_at when not is_nil(expires_at) <- invite.expires_at do
|
|
|
|
" | Expires at: #{Date.to_string(expires_at)}"
|
2019-04-06 09:58:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
using_info =
|
2019-04-06 15:38:35 +00:00
|
|
|
with max_use when not is_nil(max_use) <- invite.max_use do
|
|
|
|
" | Max use: #{max_use} Left use: #{max_use - invite.uses}"
|
2019-04-06 09:58:22 +00:00
|
|
|
end
|
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info(
|
2021-10-06 06:08:21 +00:00
|
|
|
"ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{invite.used}#{expire_info}#{using_info}"
|
2019-04-06 09:58:22 +00:00
|
|
|
)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-04-06 15:38:35 +00:00
|
|
|
def run(["revoke_invite", token]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-04-06 09:58:22 +00:00
|
|
|
|
2019-04-06 15:38:35 +00:00
|
|
|
with {:ok, invite} <- UserInviteToken.find_by_token(token),
|
|
|
|
{:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("Invite for token #{token} was revoked.")
|
2019-04-06 09:58:22 +00:00
|
|
|
else
|
2019-06-19 23:05:19 +00:00
|
|
|
_ -> shell_error("No invite found with token #{token}")
|
2019-04-06 09:58:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-12 15:04:08 +00:00
|
|
|
def run(["delete_activities", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-03-12 15:04:08 +00:00
|
|
|
|
2019-04-22 07:20:43 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
2019-09-24 07:16:52 +00:00
|
|
|
User.delete_user_activities(user)
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("User #{nickname} statuses deleted.")
|
2019-03-12 15:04:08 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No local user #{nickname}")
|
2019-03-12 15:04:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 13:28:25 +00:00
|
|
|
def run(["change_email", nickname, email]) do
|
|
|
|
start_pleroma()
|
2020-05-08 13:12:33 +00:00
|
|
|
|
2019-07-20 13:28:25 +00:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
2020-05-08 13:12:33 +00:00
|
|
|
user
|
|
|
|
|> User.update_changeset(%{"email" => email})
|
|
|
|
|> User.update_and_set_cache()
|
|
|
|
|
|
|
|
shell_info("#{nickname}'s email updated")
|
2019-07-20 13:28:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-22 00:17:59 +00:00
|
|
|
def run(["show", nickname]) do
|
|
|
|
start_pleroma()
|
2020-05-08 13:12:33 +00:00
|
|
|
|
2019-07-22 00:17:59 +00:00
|
|
|
nickname
|
|
|
|
|> User.get_cached_by_nickname()
|
2020-05-08 13:12:33 +00:00
|
|
|
|> IO.inspect()
|
2019-07-22 00:17:59 +00:00
|
|
|
end
|
|
|
|
|
2019-07-20 13:28:25 +00:00
|
|
|
def run(["send_confirmation", nickname]) do
|
|
|
|
start_pleroma()
|
2020-05-08 13:12:33 +00:00
|
|
|
|
2019-07-20 13:28:25 +00:00
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
2020-05-08 13:12:33 +00:00
|
|
|
user
|
|
|
|
|> Pleroma.Emails.UserEmail.account_confirmation_email()
|
|
|
|
|> IO.inspect()
|
|
|
|
|> Pleroma.Emails.Mailer.deliver!()
|
|
|
|
|
|
|
|
shell_info("#{nickname}'s email sent")
|
2019-07-20 13:28:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-14 02:52:06 +00:00
|
|
|
def run(["confirm", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-05-16 13:23:41 +00:00
|
|
|
|
|
|
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
2020-10-14 02:52:06 +00:00
|
|
|
{:ok, user} = User.confirm(user)
|
2019-05-16 13:23:41 +00:00
|
|
|
|
2020-10-13 19:29:34 +00:00
|
|
|
message = if !user.is_confirmed, do: "needs", else: "doesn't need"
|
2019-05-16 13:23:41 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("#{nickname} #{message} confirmation.")
|
2019-05-16 13:23:41 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No local user #{nickname}")
|
2019-05-16 13:23:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-08 21:39:41 +00:00
|
|
|
def run(["confirm_all"]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{
|
|
|
|
local: true,
|
2020-10-12 22:42:27 +00:00
|
|
|
is_active: true,
|
2020-09-08 21:39:41 +00:00
|
|
|
is_moderator: false,
|
|
|
|
is_admin: false,
|
|
|
|
invisible: false
|
|
|
|
})
|
2020-09-23 17:32:47 +00:00
|
|
|
|> Pleroma.Repo.chunk_stream(500, :batches)
|
2020-09-08 21:39:41 +00:00
|
|
|
|> Stream.each(fn users ->
|
|
|
|
users
|
2020-10-13 21:07:36 +00:00
|
|
|
|> Enum.each(fn user -> User.set_confirmation(user, true) end)
|
2020-09-08 21:39:41 +00:00
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["unconfirm_all"]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{
|
|
|
|
local: true,
|
2020-10-12 22:42:27 +00:00
|
|
|
is_active: true,
|
2020-09-08 21:39:41 +00:00
|
|
|
is_moderator: false,
|
|
|
|
is_admin: false,
|
|
|
|
invisible: false
|
|
|
|
})
|
2020-09-23 17:32:47 +00:00
|
|
|
|> Pleroma.Repo.chunk_stream(500, :batches)
|
2020-09-08 21:39:41 +00:00
|
|
|
|> Stream.each(fn users ->
|
|
|
|
users
|
2020-10-13 21:07:36 +00:00
|
|
|
|> Enum.each(fn user -> User.set_confirmation(user, false) end)
|
2020-09-08 21:39:41 +00:00
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
2019-06-19 19:29:36 +00:00
|
|
|
def run(["sign_out", nickname]) do
|
2019-06-19 23:05:19 +00:00
|
|
|
start_pleroma()
|
2019-06-19 19:29:36 +00:00
|
|
|
|
2019-06-19 19:39:53 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
2019-12-05 21:25:44 +00:00
|
|
|
User.global_sign_out(user)
|
2019-06-19 19:29:36 +00:00
|
|
|
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_info("#{nickname} signed out from all apps.")
|
2019-06-19 19:29:36 +00:00
|
|
|
else
|
|
|
|
_ ->
|
2019-06-19 23:05:19 +00:00
|
|
|
shell_error("No local user #{nickname}")
|
2019-06-19 19:29:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-05 21:56:11 +00:00
|
|
|
def run(["blocking", nickname]) do
|
|
|
|
start_pleroma()
|
2021-12-14 13:58:16 +00:00
|
|
|
|
2021-12-05 21:56:11 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
|
|
|
blocks = User.following_ap_ids(user)
|
|
|
|
IO.inspect(blocks, limit: :infinity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["timeline_query", nickname]) do
|
|
|
|
start_pleroma()
|
2022-12-05 12:58:48 +00:00
|
|
|
|
2021-12-14 13:58:16 +00:00
|
|
|
params = %{local: true}
|
|
|
|
|
2021-12-05 21:56:11 +00:00
|
|
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
2022-12-05 12:58:48 +00:00
|
|
|
followed_hashtags =
|
|
|
|
user
|
|
|
|
|> User.followed_hashtags()
|
|
|
|
|> Enum.map(& &1.id)
|
|
|
|
|
2021-12-05 21:56:11 +00:00
|
|
|
params =
|
|
|
|
params
|
|
|
|
|> Map.put(:type, ["Create", "Announce"])
|
2021-12-14 13:58:16 +00:00
|
|
|
|> Map.put(:limit, 20)
|
2021-12-05 21:56:11 +00:00
|
|
|
|> Map.put(:blocking_user, user)
|
|
|
|
|> Map.put(:muting_user, user)
|
|
|
|
|> Map.put(:reply_filtering_user, user)
|
|
|
|
|> Map.put(:announce_filtering_user, user)
|
|
|
|
|> Map.put(:user, user)
|
|
|
|
|> Map.put(:local_only, params[:local])
|
2022-12-05 12:58:48 +00:00
|
|
|
|> Map.put(:hashtags, followed_hashtags)
|
2021-12-05 21:56:11 +00:00
|
|
|
|> Map.delete(:local)
|
2021-12-14 13:58:16 +00:00
|
|
|
|
2021-12-06 12:03:16 +00:00
|
|
|
_activities =
|
2021-12-14 13:58:16 +00:00
|
|
|
[user.ap_id | User.following(user)]
|
|
|
|
|> ActivityPub.fetch_activities(params)
|
2021-12-05 21:56:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-17 20:58:30 +00:00
|
|
|
def run(["list"]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
Pleroma.User.Query.build(%{local: true})
|
2020-09-16 06:47:18 +00:00
|
|
|
|> Pleroma.Repo.chunk_stream(500, :batches)
|
2019-11-17 20:58:30 +00:00
|
|
|
|> Stream.each(fn users ->
|
|
|
|
users
|
|
|
|
|> Enum.each(fn user ->
|
|
|
|
shell_info(
|
2021-10-06 06:08:21 +00:00
|
|
|
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{user.is_locked}, is_active: #{user.is_active}"
|
2019-11-17 20:58:30 +00:00
|
|
|
)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
2022-07-23 18:58:45 +00:00
|
|
|
def run(["fix_follow_state", local_user, remote_user]) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
with {:local, %User{} = local} <- {:local, User.get_by_nickname(local_user)},
|
|
|
|
{:remote, %User{} = remote} <- {:remote, User.get_by_nickname(remote_user)},
|
|
|
|
{:follow_data, %{data: %{"state" => request_state}}} <-
|
|
|
|
{:follow_data, Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(local, remote)} do
|
|
|
|
calculated_state = User.following?(local, remote)
|
|
|
|
|
2022-07-29 18:50:26 +00:00
|
|
|
IO.puts(
|
2022-07-23 18:58:45 +00:00
|
|
|
"Request state is #{request_state}, vs calculated state of following=#{calculated_state}"
|
|
|
|
)
|
|
|
|
|
|
|
|
if calculated_state == false && request_state == "accept" do
|
2022-07-29 18:50:26 +00:00
|
|
|
IO.puts("Discrepancy found, fixing")
|
2022-07-23 18:58:45 +00:00
|
|
|
Pleroma.Web.CommonAPI.reject_follow_request(local, remote)
|
|
|
|
shell_info("Relationship fixed")
|
|
|
|
else
|
|
|
|
shell_info("No discrepancy found")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
{:local, _} ->
|
|
|
|
shell_error("No local user #{local_user}")
|
|
|
|
|
|
|
|
{:remote, _} ->
|
|
|
|
shell_error("No remote user #{remote_user}")
|
|
|
|
|
|
|
|
{:follow_data, _} ->
|
|
|
|
shell_error("No follow data for #{local_user} and #{remote_user}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 13:30:08 +00:00
|
|
|
def run(["convert_id", id]) do
|
|
|
|
{:ok, uuid} = FlakeId.Ecto.Type.dump(id)
|
|
|
|
{:ok, raw_id} = Ecto.UUID.load(uuid)
|
|
|
|
shell_info(raw_id)
|
|
|
|
end
|
|
|
|
|
2022-08-24 14:36:33 +00:00
|
|
|
defp refetch_public_keys(query) do
|
|
|
|
query
|
|
|
|
|> Pleroma.Repo.chunk_stream(50, :batches)
|
|
|
|
|> Stream.each(fn users ->
|
|
|
|
users
|
|
|
|
|> Enum.each(fn user ->
|
|
|
|
IO.puts("Re-Resolving: #{user.ap_id}")
|
|
|
|
|
|
|
|
with {:ok, user} <- Pleroma.User.fetch_by_ap_id(user.ap_id),
|
|
|
|
changeset <- Pleroma.User.update_changeset(user),
|
|
|
|
{:ok, _user} <- Pleroma.User.update_and_set_cache(changeset) do
|
|
|
|
:ok
|
|
|
|
else
|
|
|
|
error -> IO.puts("Could not resolve: #{user.ap_id}, #{inspect(error)}")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
2018-12-04 18:00:45 +00:00
|
|
|
defp set_moderator(user, value) do
|
2019-10-20 10:42:42 +00:00
|
|
|
{:ok, user} =
|
|
|
|
user
|
|
|
|
|> Changeset.change(%{is_moderator: value})
|
|
|
|
|> User.update_and_set_cache()
|
2018-12-05 16:58:26 +00:00
|
|
|
|
2019-10-16 18:59:21 +00:00
|
|
|
shell_info("Moderator status of #{user.nickname}: #{user.is_moderator}")
|
2018-12-12 20:32:32 +00:00
|
|
|
user
|
2018-12-04 18:00:45 +00:00
|
|
|
end
|
2018-12-01 15:55:52 +00:00
|
|
|
|
2018-12-04 18:00:45 +00:00
|
|
|
defp set_admin(user, value) do
|
2019-12-05 21:25:44 +00:00
|
|
|
{:ok, user} = User.admin_api_update(user, %{is_admin: value})
|
2018-12-04 18:00:45 +00:00
|
|
|
|
2019-10-16 18:59:21 +00:00
|
|
|
shell_info("Admin status of #{user.nickname}: #{user.is_admin}")
|
2018-12-12 20:32:32 +00:00
|
|
|
user
|
2018-12-04 18:00:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp set_locked(user, value) do
|
2019-10-20 10:42:42 +00:00
|
|
|
{:ok, user} =
|
|
|
|
user
|
2020-10-13 14:31:13 +00:00
|
|
|
|> Changeset.change(%{is_locked: value})
|
2019-10-20 10:42:42 +00:00
|
|
|
|> User.update_and_set_cache()
|
2018-12-04 18:00:45 +00:00
|
|
|
|
2020-10-13 14:31:13 +00:00
|
|
|
shell_info("Locked status of #{user.nickname}: #{user.is_locked}")
|
2018-12-12 20:32:32 +00:00
|
|
|
user
|
2018-12-01 15:55:52 +00:00
|
|
|
end
|
2020-09-08 21:39:41 +00:00
|
|
|
|
2020-10-13 21:07:36 +00:00
|
|
|
defp set_confirmation(user, value) do
|
|
|
|
{:ok, user} = User.set_confirmation(user, value)
|
2020-09-08 21:39:41 +00:00
|
|
|
|
2020-10-13 19:29:34 +00:00
|
|
|
shell_info("Confirmation status of #{user.nickname}: #{user.is_confirmed}")
|
2020-09-08 21:39:41 +00:00
|
|
|
user
|
|
|
|
end
|
2018-06-29 00:24:51 +00:00
|
|
|
end
|