From 99be3d3dccbbd7877192c6291bbaae92f66e06bf Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 6 Aug 2018 07:14:16 +0000 Subject: relay: add relay follow/unfollow tasks --- lib/mix/tasks/relay_follow.ex | 12 ++++++++++++ lib/mix/tasks/relay_unfollow.ex | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/mix/tasks/relay_follow.ex create mode 100644 lib/mix/tasks/relay_unfollow.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex new file mode 100644 index 000000000..a8152d96f --- /dev/null +++ b/lib/mix/tasks/relay_follow.ex @@ -0,0 +1,12 @@ +defmodule Mix.Tasks.RelayFollow do + use Mix.Task + require Logger + alias Pleroma.Web.ActivityPub.Relay + + @shortdoc "Follows a remote relay" + def run([target]) do + Mix.Task.run("app.start") + + :ok = Relay.follow(target) + end +end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex new file mode 100644 index 000000000..81b7197b2 --- /dev/null +++ b/lib/mix/tasks/relay_unfollow.ex @@ -0,0 +1,12 @@ +defmodule Mix.Tasks.RelayUnfollow do + use Mix.Task + require Logger + alias Pleroma.Web.ActivityPub.Relay + + @shortdoc "Follows a remote relay" + def run([target]) do + Mix.Task.run("app.start") + + :ok = Relay.unfollow(target) + end +end -- cgit v1.2.3 From 266b3140519eacc6c0adaccd959e2f3167e1fc13 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 6 Aug 2018 07:27:11 +0000 Subject: relay: fix invoking federator, use a timer to sleep the mix task to force a context switch --- lib/mix/tasks/relay_follow.ex | 3 +++ lib/mix/tasks/relay_unfollow.ex | 3 +++ 2 files changed, 6 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index a8152d96f..ac6f20924 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -8,5 +8,8 @@ defmodule Mix.Tasks.RelayFollow do Mix.Task.run("app.start") :ok = Relay.follow(target) + + # put this task to sleep to allow the genserver to push out the messages + :timer.sleep(500) end end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index 81b7197b2..4621ace83 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -8,5 +8,8 @@ defmodule Mix.Tasks.RelayUnfollow do Mix.Task.run("app.start") :ok = Relay.unfollow(target) + + # put this task to sleep to allow the genserver to push out the messages + :timer.sleep(500) end end -- cgit v1.2.3 From e95d958b525cd0a448d38753099bbf7a4f30ba90 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 27 Aug 2018 23:30:53 +0000 Subject: sample config: show how amazon s3 support is activated, including third-party clones like wasabi --- lib/mix/tasks/sample_config.eex | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 6db36fa09..cfb5ef4c0 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -24,3 +24,20 @@ config :pleroma, Pleroma.Repo, database: "pleroma_dev", hostname: "localhost", pool_size: 10 + +# Configure S3 support if desired: +# +# config :pleroma, Pleroma.Upload, +# use_s3: true, +# bucket: "some-bucket" +# +# Configure S3 credentials: +# config :ex_aws, :s3, +# access_key_id: "xxxxxxxxxxxxx", +# secret_access_key: "yyyyyyyyyyyy", +# region: "us-east-1", +# scheme: "https://", +# +# For using third-party S3 clones like wasabi, also do: +# config :ex_aws, :s3, +# host: "s3.wasabisys.com" -- cgit v1.2.3 From 03c35e579ba4804e176b9095186c2cdc0c244331 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 28 Aug 2018 00:18:24 +0000 Subject: sample config: add S3 public endpoint option --- lib/mix/tasks/sample_config.eex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index cfb5ef4c0..2acf35ed9 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -25,18 +25,21 @@ config :pleroma, Pleroma.Repo, hostname: "localhost", pool_size: 10 -# Configure S3 support if desired: +# Configure S3 support if desired. +# The public S3 endpoint is different depending on region and provider, +# consult your S3 provider's documentation for details on what to use. # # config :pleroma, Pleroma.Upload, # use_s3: true, -# bucket: "some-bucket" +# bucket: "some-bucket", +# public_endpoint: "https://s3.amazonaws.com" # # Configure S3 credentials: # config :ex_aws, :s3, # access_key_id: "xxxxxxxxxxxxx", # secret_access_key: "yyyyyyyyyyyy", # region: "us-east-1", -# scheme: "https://", +# scheme: "https://" # # For using third-party S3 clones like wasabi, also do: # config :ex_aws, :s3, -- cgit v1.2.3 From ab9e5d64d6dc6911dadac7219d38f3749971f53c Mon Sep 17 00:00:00 2001 From: Thurloat Date: Tue, 28 Aug 2018 22:39:33 -0300 Subject: add a sample swift config --- lib/mix/tasks/sample_config.eex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 2acf35ed9..3b4953cda 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -44,3 +44,21 @@ config :pleroma, Pleroma.Repo, # For using third-party S3 clones like wasabi, also do: # config :ex_aws, :s3, # host: "s3.wasabisys.com" + + +# Configure Openstack Swift support if desired. +# +# Many openstack deployments are different, so config is left very open with +# no assumptions made on which provider you're using. This should allow very +# wide support without needing separate handlers for OVH, Rackspace, etc. +# +# config :pleroma, Pleroma.Uploaders.Swift, +# container: "some-container", +# username: "api-username-yyyy", +# password: "api-key-xxxx", +# tenant_id: "", +# auth_url: "https://keystone-endpoint.provider.com", +# storage_url: "https://swift-endpoint.prodider.com/v1/AUTH_/", +# object_url: "https://cdn-endpoint.provider.com/" +# + -- cgit v1.2.3 From d424e9fa5f3d0d1ff9e416f6bf548e0e8bb02361 Mon Sep 17 00:00:00 2001 From: Thurloat Date: Tue, 28 Aug 2018 23:49:23 -0300 Subject: fix S3 ref in sample config to generate proper path. --- lib/mix/tasks/sample_config.eex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 3b4953cda..3881ead26 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -29,8 +29,7 @@ config :pleroma, Pleroma.Repo, # The public S3 endpoint is different depending on region and provider, # consult your S3 provider's documentation for details on what to use. # -# config :pleroma, Pleroma.Upload, -# use_s3: true, +# config :pleroma, Pleroma.Uploaders.S3, # bucket: "some-bucket", # public_endpoint: "https://s3.amazonaws.com" # -- cgit v1.2.3 From 8e28e8a18f330696d48070a138a6fa83ef7edfb2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 20 Sep 2018 23:51:06 +0000 Subject: mix: remove fix_ap_users task, now obsolete --- lib/mix/tasks/fix_ap_users.ex | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 lib/mix/tasks/fix_ap_users.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/fix_ap_users.ex b/lib/mix/tasks/fix_ap_users.ex deleted file mode 100644 index 7e970850e..000000000 --- a/lib/mix/tasks/fix_ap_users.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Mix.Tasks.FixApUsers do - use Mix.Task - import Ecto.Query - alias Pleroma.{Repo, User} - - @shortdoc "Grab all ap users again" - def run([]) do - Mix.Task.run("app.start") - - q = - from( - u in User, - where: fragment("? @> ?", u.info, ^%{"ap_enabled" => true}), - where: u.local == false - ) - - users = Repo.all(q) - - Enum.each(users, fn user -> - try do - IO.puts("Fetching #{user.nickname}") - Pleroma.Web.ActivityPub.Transmogrifier.upgrade_user_from_ap_id(user.ap_id, false) - rescue - e -> IO.inspect(e) - end - end) - end -end -- cgit v1.2.3 From a494508320d2e2650a2c09ae53b212b8c1ab7bd3 Mon Sep 17 00:00:00 2001 From: Greizgh Date: Sat, 27 Oct 2018 14:31:51 +0200 Subject: Cleanup postgresql setup script Drop unused CREATEDB privilege. Do not try to handle multiple run. --- lib/mix/tasks/sample_psql.eex | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_psql.eex b/lib/mix/tasks/sample_psql.eex index bc22f166c..b6f57948b 100644 --- a/lib/mix/tasks/sample_psql.eex +++ b/lib/mix/tasks/sample_psql.eex @@ -1,8 +1,5 @@ -CREATE USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; --- in case someone runs this second time accidentally -ALTER USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; -CREATE DATABASE pleroma_dev; -ALTER DATABASE pleroma_dev OWNER TO pleroma; +CREATE USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>'; +CREATE DATABASE pleroma_dev OWNER pleroma; \c pleroma_dev; --Extensions made by ecto.migrate that need superuser access CREATE EXTENSION IF NOT EXISTS citext; -- cgit v1.2.3 From 69192f36ff617d237481c401850171bf79a2f547 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 28 Oct 2018 19:47:56 +0000 Subject: mix tasks: add new task to unsubscribe all users from, and then ban a remote user (e.g. followbots) --- lib/mix/tasks/unsubscribe_user.ex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/mix/tasks/unsubscribe_user.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex new file mode 100644 index 000000000..bb72634b6 --- /dev/null +++ b/lib/mix/tasks/unsubscribe_user.ex @@ -0,0 +1,32 @@ +defmodule Mix.Tasks.UnsubscribeUser do + use Mix.Task + alias Pleroma.{User, Repo} + require Logger + + @shortdoc "Unsubscribe all users from a target and then deactivate them" + def run([nickname]) do + Mix.Task.run("app.start") + + with %User{} = user <- User.get_by_nickname(nickname) do + Logger.info("Deactivating #{user.nickname}") + User.deactivate(user) + + {:ok, friends} = User.get_friends(user) + + Enum.each(friends, fn friend -> + user = Repo.get(User, user.id) + + Logger.info("Unsubscribing #{friend.nickname} from #{user.nickname}") + User.unfollow(user, friend) + end) + + :timer.sleep(500) + + user = Repo.get(User, user.id) + + if length(user.following) == 0 do + Logger.info("Successfully unsubscribed all followers from #{user.nickname}") + end + end + end +end -- cgit v1.2.3 From b92e38d2d4c05da19b00162d7ca35f1905b44a80 Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 29 Oct 2018 23:08:56 +0000 Subject: Add user reactivation task. --- lib/mix/tasks/deactivate_user.ex | 2 +- lib/mix/tasks/reactivate_user.ex | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/mix/tasks/reactivate_user.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/deactivate_user.ex b/lib/mix/tasks/deactivate_user.ex index 96b3db6e4..f18541787 100644 --- a/lib/mix/tasks/deactivate_user.ex +++ b/lib/mix/tasks/deactivate_user.ex @@ -2,7 +2,7 @@ defmodule Mix.Tasks.DeactivateUser do use Mix.Task alias Pleroma.User - @shortdoc "Toggle deactivation status for a user" + @shortdoc "Deactivate a user" def run([nickname]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/reactivate_user.ex b/lib/mix/tasks/reactivate_user.ex new file mode 100644 index 000000000..40bd068ea --- /dev/null +++ b/lib/mix/tasks/reactivate_user.ex @@ -0,0 +1,13 @@ +defmodule Mix.Tasks.ReactivateUser do + use Mix.Task + alias Pleroma.User + + @shortdoc "Reactivate a user" + def run([nickname]) do + Mix.Task.run("app.start") + + with user <- User.get_by_nickname(nickname) do + User.deactivate(user, false) + end + end +end -- cgit v1.2.3 From f584a603f95f95c7c8d2c1897b24b5c7399f4f74 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 07:56:21 +0000 Subject: user: make User.delete() return data consistent with Object.delete() --- lib/mix/tasks/rm_user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/rm_user.ex b/lib/mix/tasks/rm_user.ex index 27521b745..b7c922d6c 100644 --- a/lib/mix/tasks/rm_user.ex +++ b/lib/mix/tasks/rm_user.ex @@ -7,7 +7,7 @@ defmodule Mix.Tasks.RmUser do Mix.Task.run("app.start") with %User{local: true} = user <- User.get_by_nickname(nickname) do - User.delete(user) + {:ok, _} = User.delete(user) end end end -- cgit v1.2.3 From e1814bb322dda732143fdb0cb60dbce82fe433da Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 13 Jul 2018 01:02:18 +0200 Subject: Document mix tasks --- lib/mix/tasks/make_moderator.ex | 9 ++++++++- lib/mix/tasks/register_user.ex | 8 ++++++++ lib/mix/tasks/set_locked.ex | 11 ++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index a454a958e..000671c44 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -1,9 +1,16 @@ defmodule Mix.Tasks.SetModerator do + @moduledoc """ + Set moderator to a local user + + Usage: ``mix set_moderator `` + + Example: ``mix set_moderator lain`` + """ + use Mix.Task import Mix.Ecto alias Pleroma.{Repo, User} - @shortdoc "Set moderator status" def run([nickname | rest]) do Application.ensure_all_started(:pleroma) diff --git a/lib/mix/tasks/register_user.ex b/lib/mix/tasks/register_user.ex index e74721c49..1f5321093 100644 --- a/lib/mix/tasks/register_user.ex +++ b/lib/mix/tasks/register_user.ex @@ -1,4 +1,12 @@ defmodule Mix.Tasks.RegisterUser do + @moduledoc """ + Manually register a local user + + Usage: ``mix register_user `` + + Example: ``mix register_user 仮面の告白 lain lain@example.org "blushy-crushy fediverse idol + pleroma dev" pleaseDontHeckLain`` + """ + use Mix.Task alias Pleroma.{Repo, User} diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex index 2b3b18b09..a154595ca 100644 --- a/lib/mix/tasks/set_locked.ex +++ b/lib/mix/tasks/set_locked.ex @@ -1,9 +1,18 @@ defmodule Mix.Tasks.SetLocked do + @moduledoc """ + Lock a local user + + The local user will then have to manually accept/reject followers. This can also be done by the user into their settings. + + Usage: ``mix set_locked `` + + Example: ``mix set_locked lain`` + """ + use Mix.Task import Mix.Ecto alias Pleroma.{Repo, User} - @shortdoc "Set locked status" def run([nickname | rest]) do ensure_started(Repo, []) -- cgit v1.2.3 From 8b2541e4e7fb37f38422bf6c02cc10863a927e61 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 2 Nov 2018 09:32:48 +0100 Subject: Document the mix tasks in ex_doc instead --- lib/mix/tasks/deactivate_user.ex | 8 +++++++- lib/mix/tasks/generate_config.ex | 10 +++++++++- lib/mix/tasks/generate_invite_token.ex | 9 ++++++++- lib/mix/tasks/make_moderator.ex | 2 +- lib/mix/tasks/rm_user.ex | 8 +++++++- 5 files changed, 32 insertions(+), 5 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/deactivate_user.ex b/lib/mix/tasks/deactivate_user.ex index f18541787..e71ed1ec0 100644 --- a/lib/mix/tasks/deactivate_user.ex +++ b/lib/mix/tasks/deactivate_user.ex @@ -2,7 +2,13 @@ defmodule Mix.Tasks.DeactivateUser do use Mix.Task alias Pleroma.User - @shortdoc "Deactivate a user" + @moduledoc """ + Deactivates a user (local or remote) + + Usage: ``mix deactivate_user `` + + Example: ``mix deactivate_user lain`` + """ def run([nickname]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/generate_config.ex b/lib/mix/tasks/generate_config.ex index 70a110561..e3cbbf131 100644 --- a/lib/mix/tasks/generate_config.ex +++ b/lib/mix/tasks/generate_config.ex @@ -1,7 +1,15 @@ defmodule Mix.Tasks.GenerateConfig do use Mix.Task - @shortdoc "Generates a new config" + @moduledoc """ + Generate a new config + + ## Usage + ``mix generate_config`` + + This mix task is interactive, and will overwrite the config present at ``config/generated_config.exs``. + """ + def run(_) do IO.puts("Answer a few questions to generate a new config\n") IO.puts("--- THIS WILL OVERWRITE YOUR config/generated_config.exs! ---\n") diff --git a/lib/mix/tasks/generate_invite_token.ex b/lib/mix/tasks/generate_invite_token.ex index c4daa9a6c..418ef3790 100644 --- a/lib/mix/tasks/generate_invite_token.ex +++ b/lib/mix/tasks/generate_invite_token.ex @@ -1,7 +1,14 @@ defmodule Mix.Tasks.GenerateInviteToken do use Mix.Task - @shortdoc "Generate invite token for user" + @moduledoc """ + Generates invite token + + This is in the form of a URL to be used by the Invited user to register themselves. + + ## Usage + ``mix generate_invite_token`` + """ def run([]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index 000671c44..15586dc30 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -2,7 +2,7 @@ defmodule Mix.Tasks.SetModerator do @moduledoc """ Set moderator to a local user - Usage: ``mix set_moderator `` + Usage: ``mix set_moderator `` Example: ``mix set_moderator lain`` """ diff --git a/lib/mix/tasks/rm_user.ex b/lib/mix/tasks/rm_user.ex index b7c922d6c..50463046c 100644 --- a/lib/mix/tasks/rm_user.ex +++ b/lib/mix/tasks/rm_user.ex @@ -2,7 +2,13 @@ defmodule Mix.Tasks.RmUser do use Mix.Task alias Pleroma.User - @shortdoc "Permanently delete a user" + @moduledoc """ + Permanently deletes a user + + Usage: ``mix rm_user [nickname]`` + + Example: ``mix rm_user lain`` + """ def run([nickname]) do Mix.Task.run("app.start") -- cgit v1.2.3 From 64c0289893e870cf3f5525fdffb6b25ab3cc2f25 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 8 Nov 2018 15:21:09 +0100 Subject: lib/mix/tasks: Add remaining documentation for mix tasks --- lib/mix/tasks/generate_password_reset.ex | 8 +++++++- lib/mix/tasks/reactivate_user.ex | 8 +++++++- lib/mix/tasks/relay_follow.ex | 7 +++++++ lib/mix/tasks/relay_unfollow.ex | 8 +++++++- lib/mix/tasks/unsubscribe_user.ex | 9 ++++++++- 5 files changed, 36 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex index 6bf640150..e581e2e11 100644 --- a/lib/mix/tasks/generate_password_reset.ex +++ b/lib/mix/tasks/generate_password_reset.ex @@ -2,7 +2,13 @@ defmodule Mix.Tasks.GeneratePasswordReset do use Mix.Task alias Pleroma.User - @shortdoc "Generate password reset link for user" + @doc """ + Generate password reset link for user + + Usage: ``mix generate_password_reset `` + + Example: ``mix generate_password_reset lain`` + """ def run([nickname]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/reactivate_user.ex b/lib/mix/tasks/reactivate_user.ex index 40bd068ea..41e4cbbec 100644 --- a/lib/mix/tasks/reactivate_user.ex +++ b/lib/mix/tasks/reactivate_user.ex @@ -2,7 +2,13 @@ defmodule Mix.Tasks.ReactivateUser do use Mix.Task alias Pleroma.User - @shortdoc "Reactivate a user" + @doc """ + Reactivate a user + + Usage: ``mix reactivate_user `` + + Example: ``mix reactivate_user lain`` + """ def run([nickname]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index ac6f20924..7428ec6ef 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -4,6 +4,13 @@ defmodule Mix.Tasks.RelayFollow do alias Pleroma.Web.ActivityPub.Relay @shortdoc "Follows a remote relay" + @doc """ + Follows a remote relay + + Usage: ``mix relay_follow `` + + Example: ``mix relay_follow https://example.org/relay`` + """ def run([target]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index 4621ace83..cb13a0729 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -3,7 +3,13 @@ defmodule Mix.Tasks.RelayUnfollow do require Logger alias Pleroma.Web.ActivityPub.Relay - @shortdoc "Follows a remote relay" + @doc """ + Unfollows a remote relay + + Usage: ``mix relay_follow `` + + Example: ``mix relay_follow https://example.org/relay`` + """ def run([target]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex index bb72634b6..75811374b 100644 --- a/lib/mix/tasks/unsubscribe_user.ex +++ b/lib/mix/tasks/unsubscribe_user.ex @@ -3,7 +3,14 @@ defmodule Mix.Tasks.UnsubscribeUser do alias Pleroma.{User, Repo} require Logger - @shortdoc "Unsubscribe all users from a target and then deactivate them" + @doc """ + Deactivate and Unsubscribe local users from a user + + Usage: ``mix unsubscribe_user `` + + Example: ``mix unsubscribe_user lain`` + """ + def run([nickname]) do def run([nickname]) do Mix.Task.run("app.start") -- cgit v1.2.3 From 5e3207045e5c58c4c0ebb5d37d0cbfbd5a7db4db Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 8 Nov 2018 15:26:11 +0100 Subject: lib/mix/tasks/unsubscribe_user.ex: Fix syntax from bad line copy --- lib/mix/tasks/unsubscribe_user.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex index 75811374b..fe4f7d479 100644 --- a/lib/mix/tasks/unsubscribe_user.ex +++ b/lib/mix/tasks/unsubscribe_user.ex @@ -10,7 +10,6 @@ defmodule Mix.Tasks.UnsubscribeUser do Example: ``mix unsubscribe_user lain`` """ - def run([nickname]) do def run([nickname]) do Mix.Task.run("app.start") -- cgit v1.2.3 From 5ecb5629f6714cf20df3ac28eef585822fb2ea45 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 8 Nov 2018 15:28:50 +0100 Subject: lib/mix/tasks: s/@doc/@moduledoc/ --- lib/mix/tasks/generate_password_reset.ex | 2 +- lib/mix/tasks/reactivate_user.ex | 2 +- lib/mix/tasks/relay_follow.ex | 2 +- lib/mix/tasks/relay_unfollow.ex | 2 +- lib/mix/tasks/unsubscribe_user.ex | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex index e581e2e11..f7f4c4f59 100644 --- a/lib/mix/tasks/generate_password_reset.ex +++ b/lib/mix/tasks/generate_password_reset.ex @@ -2,7 +2,7 @@ defmodule Mix.Tasks.GeneratePasswordReset do use Mix.Task alias Pleroma.User - @doc """ + @moduledoc """ Generate password reset link for user Usage: ``mix generate_password_reset `` diff --git a/lib/mix/tasks/reactivate_user.ex b/lib/mix/tasks/reactivate_user.ex index 41e4cbbec..a30d3ac8b 100644 --- a/lib/mix/tasks/reactivate_user.ex +++ b/lib/mix/tasks/reactivate_user.ex @@ -2,7 +2,7 @@ defmodule Mix.Tasks.ReactivateUser do use Mix.Task alias Pleroma.User - @doc """ + @moduledoc """ Reactivate a user Usage: ``mix reactivate_user `` diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index 7428ec6ef..4d57c6bca 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -4,7 +4,7 @@ defmodule Mix.Tasks.RelayFollow do alias Pleroma.Web.ActivityPub.Relay @shortdoc "Follows a remote relay" - @doc """ + @moduledoc """ Follows a remote relay Usage: ``mix relay_follow `` diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index cb13a0729..bd69fd8a0 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -3,7 +3,7 @@ defmodule Mix.Tasks.RelayUnfollow do require Logger alias Pleroma.Web.ActivityPub.Relay - @doc """ + @moduledoc """ Unfollows a remote relay Usage: ``mix relay_follow `` diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex index fe4f7d479..62ea61a5c 100644 --- a/lib/mix/tasks/unsubscribe_user.ex +++ b/lib/mix/tasks/unsubscribe_user.ex @@ -3,7 +3,7 @@ defmodule Mix.Tasks.UnsubscribeUser do alias Pleroma.{User, Repo} require Logger - @doc """ + @moduledoc """ Deactivate and Unsubscribe local users from a user Usage: ``mix unsubscribe_user `` -- cgit v1.2.3 From a2bf5426cb84940dbd58aec10a7b1b0a90f26a60 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 11 Nov 2018 06:42:14 +0000 Subject: sample config: document how to make CSPPlug send STS headers (off by default to allow for SSL debugging) --- lib/mix/tasks/sample_config.eex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 3881ead26..824bc97a1 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -25,6 +25,10 @@ config :pleroma, Pleroma.Repo, hostname: "localhost", pool_size: 10 +# Enable Strict-Transport-Security once SSL is working: +# config :pleroma, :csp, +# sts: true + # Configure S3 support if desired. # The public S3 endpoint is different depending on region and provider, # consult your S3 provider's documentation for details on what to use. -- cgit v1.2.3 From 2829fa41830ad8565fc186c3dc110f4d275f8827 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 12 Nov 2018 15:17:04 +0000 Subject: sample config: chase http_security change --- lib/mix/tasks/sample_config.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 824bc97a1..462c34636 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -26,7 +26,7 @@ config :pleroma, Pleroma.Repo, pool_size: 10 # Enable Strict-Transport-Security once SSL is working: -# config :pleroma, :csp, +# config :pleroma, :http_security, # sts: true # Configure S3 support if desired. -- cgit v1.2.3 From 011a2e36b1bec75afab96b7ed529dd5c4f18af7a Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 12 Oct 2018 05:12:09 +0200 Subject: lib/mix/tasks/make_admin.ex: New task --- lib/mix/tasks/set_admin.ex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/mix/tasks/set_admin.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex new file mode 100644 index 000000000..d5ccf261b --- /dev/null +++ b/lib/mix/tasks/set_admin.ex @@ -0,0 +1,32 @@ +defmodule Mix.Tasks.SetAdmin do + use Mix.Task + alias Pleroma.User + + @doc """ + Sets admin status + Usage: set_admin nickname [true|false] + """ + def run([nickname | rest]) do + Application.ensure_all_started(:pleroma) + + status = + case rest do + [status] -> status == "true" + _ -> true + end + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + info = + user.info + |> Map.put("is_admin", !!status) + + cng = User.info_changeset(user, %{info: info}) + {:ok, user} = User.update_and_set_cache(cng) + + IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}") + else + _ -> + IO.puts("No local user #{nickname}") + end + end +end -- cgit v1.2.3 From 7fbfd2db964ba9d6eac0d6ccd9b5fd94ee38df6f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 10 Nov 2018 14:55:32 +0100 Subject: lib/mix/tasks/relay_{un,}follow.ex: Support status reply of Relay.{un,}follow --- lib/mix/tasks/relay_follow.ex | 2 +- lib/mix/tasks/relay_unfollow.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index 4d57c6bca..61280d084 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -14,7 +14,7 @@ defmodule Mix.Tasks.RelayFollow do def run([target]) do Mix.Task.run("app.start") - :ok = Relay.follow(target) + _status = Relay.follow(target) # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index bd69fd8a0..6aa67590b 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -13,7 +13,7 @@ defmodule Mix.Tasks.RelayUnfollow do def run([target]) do Mix.Task.run("app.start") - :ok = Relay.unfollow(target) + _status = Relay.unfollow(target) # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) -- cgit v1.2.3 From 1a31d7118793644050f3c045ff3e58db1543bdd4 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 10 Nov 2018 15:08:03 +0100 Subject: lib/mix/tasks/relay_{un,}follow.ex: Use a with block --- lib/mix/tasks/relay_follow.ex | 10 ++++++---- lib/mix/tasks/relay_unfollow.ex | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index 61280d084..39cecb71b 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -14,9 +14,11 @@ defmodule Mix.Tasks.RelayFollow do def run([target]) do Mix.Task.run("app.start") - _status = Relay.follow(target) - - # put this task to sleep to allow the genserver to push out the messages - :timer.sleep(500) + with :ok <- Relay.follow(target) do + # put this task to sleep to allow the genserver to push out the messages + :timer.sleep(500) + else + e -> Mix.puts("Error: #{inspect(e)}") + end end end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index 6aa67590b..5f12bd9ea 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -13,9 +13,11 @@ defmodule Mix.Tasks.RelayUnfollow do def run([target]) do Mix.Task.run("app.start") - _status = Relay.unfollow(target) - - # put this task to sleep to allow the genserver to push out the messages - :timer.sleep(500) + with :ok <- Relay.unfollow(target) do + # put this task to sleep to allow the genserver to push out the messages + :timer.sleep(500) + else + e -> Mix.puts("Error: #{inspect(e)}") + end end end -- cgit v1.2.3 From 12ccf0c4f835cee1e942e13482322b0d9a5e7c2d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 10 Nov 2018 15:31:37 +0100 Subject: Change Relay from `status` to `{status, message}` --- lib/mix/tasks/relay_follow.ex | 6 ++++-- lib/mix/tasks/relay_unfollow.ex | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index 39cecb71b..bec63af7c 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -14,11 +14,13 @@ defmodule Mix.Tasks.RelayFollow do def run([target]) do Mix.Task.run("app.start") - with :ok <- Relay.follow(target) do + {status, message} = Relay.follow(target) + + if :ok == status do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) else - e -> Mix.puts("Error: #{inspect(e)}") + Mix.puts("Error: #{inspect(message)}") end end end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index 5f12bd9ea..df719af2b 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -13,11 +13,13 @@ defmodule Mix.Tasks.RelayUnfollow do def run([target]) do Mix.Task.run("app.start") - with :ok <- Relay.unfollow(target) do + {status, message} = Relay.unfollow(target) + + if :ok == status do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) else - e -> Mix.puts("Error: #{inspect(e)}") + Mix.puts("Error: #{inspect(message)}") end end end -- cgit v1.2.3 From 44b6200103d52ab86b46f8b4b9e0768036184d05 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 10 Nov 2018 15:53:37 +0100 Subject: lib/mix/tasks/relay*: Use a with block --- lib/mix/tasks/relay_follow.ex | 6 ++---- lib/mix/tasks/relay_unfollow.ex | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex index bec63af7c..85b1c024d 100644 --- a/lib/mix/tasks/relay_follow.ex +++ b/lib/mix/tasks/relay_follow.ex @@ -14,13 +14,11 @@ defmodule Mix.Tasks.RelayFollow do def run([target]) do Mix.Task.run("app.start") - {status, message} = Relay.follow(target) - - if :ok == status do + with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) else - Mix.puts("Error: #{inspect(message)}") + {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") end end end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex index df719af2b..237fb771c 100644 --- a/lib/mix/tasks/relay_unfollow.ex +++ b/lib/mix/tasks/relay_unfollow.ex @@ -13,13 +13,11 @@ defmodule Mix.Tasks.RelayUnfollow do def run([target]) do Mix.Task.run("app.start") - {status, message} = Relay.unfollow(target) - - if :ok == status do + with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) else - Mix.puts("Error: #{inspect(message)}") + {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") end end end -- cgit v1.2.3 From b19597f602e70121a1762476873377c782549817 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 23 Nov 2018 17:40:45 +0100 Subject: reverse proxy / uploads --- lib/mix/tasks/migrate_local_uploads.ex | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/mix/tasks/migrate_local_uploads.ex (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/migrate_local_uploads.ex b/lib/mix/tasks/migrate_local_uploads.ex new file mode 100644 index 000000000..40117350c --- /dev/null +++ b/lib/mix/tasks/migrate_local_uploads.ex @@ -0,0 +1,80 @@ +defmodule Mix.Tasks.MigrateLocalUploads do + use Mix.Task + import Mix.Ecto + alias Pleroma.{Upload, Uploaders.Local, Uploaders.S3} + require Logger + + @log_every 50 + @shortdoc "Migrate uploads from local to remote storage" + + def run([target_uploader | args]) do + delete? = Enum.member?(args, "--delete") + Application.ensure_all_started(:pleroma) + + local_path = Pleroma.Config.get!([Local, :uploads]) + uploader = Module.concat(Pleroma.Uploaders, target_uploader) + + unless Code.ensure_loaded?(uploader) do + raise("The uploader #{inspect(uploader)} is not an existing/loaded module.") + end + + target_enabled? = Pleroma.Config.get([Upload, :uploader]) == uploader + + unless target_enabled? do + Pleroma.Config.put([Upload, :uploader], uploader) + end + + Logger.info("Migrating files from local #{local_path} to #{to_string(uploader)}") + + if delete? do + Logger.warn( + "Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)" + ) + + :timer.sleep(:timer.seconds(5)) + end + + uploads = File.ls!(local_path) + total_count = length(uploads) + + uploads + |> Task.async_stream( + fn uuid -> + u_path = Path.join(local_path, uuid) + + {name, path} = + cond do + File.dir?(u_path) -> + files = for file <- File.ls!(u_path), do: {{file, uuid}, Path.join([u_path, file])} + List.first(files) + + File.exists?(u_path) -> + # {uuid, u_path} + raise "should_dedupe local storage not supported yet sorry" + end + + {:ok, _} = + Upload.store({:from_local, name, path}, should_dedupe: false, uploader: uploader) + + if delete? do + File.rm_rf!(u_path) + end + + Logger.debug("uploaded: #{inspect(name)}") + end, + timeout: 150_000 + ) + |> Stream.chunk_every(@log_every) + |> Enum.reduce(0, fn done, count -> + count = count + length(done) + Logger.info("Uploaded #{count}/#{total_count} files") + count + end) + + Logger.info("Done!") + end + + def run(_) do + Logger.error("Usage: migrate_local_uploads UploaderName [--delete]") + end +end -- cgit v1.2.3 From 02d3dc6869f388388ea744ea4ee3b54279d55e86 Mon Sep 17 00:00:00 2001 From: href Date: Thu, 29 Nov 2018 21:11:45 +0100 Subject: Uploads fun, part. 2 --- lib/mix/tasks/migrate_local_uploads.ex | 63 +++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 23 deletions(-) (limited to 'lib/mix/tasks') diff --git a/lib/mix/tasks/migrate_local_uploads.ex b/lib/mix/tasks/migrate_local_uploads.ex index 40117350c..8f9e210c0 100644 --- a/lib/mix/tasks/migrate_local_uploads.ex +++ b/lib/mix/tasks/migrate_local_uploads.ex @@ -34,33 +34,50 @@ defmodule Mix.Tasks.MigrateLocalUploads do :timer.sleep(:timer.seconds(5)) end - uploads = File.ls!(local_path) + uploads = + File.ls!(local_path) + |> Enum.map(fn id -> + root_path = Path.join(local_path, id) + + cond do + File.dir?(root_path) -> + files = for file <- File.ls!(root_path), do: {id, file, Path.join([root_path, file])} + + case List.first(files) do + {id, file, path} -> + {%Pleroma.Upload{id: id, name: file, path: id <> "/" <> file, tempfile: path}, + root_path} + + _ -> + nil + end + + File.exists?(root_path) -> + file = Path.basename(id) + [hash, ext] = String.split(id, ".") + {%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path} + + true -> + nil + end + end) + |> Enum.filter(& &1) + total_count = length(uploads) + Logger.info("Found #{total_count} uploads") uploads |> Task.async_stream( - fn uuid -> - u_path = Path.join(local_path, uuid) - - {name, path} = - cond do - File.dir?(u_path) -> - files = for file <- File.ls!(u_path), do: {{file, uuid}, Path.join([u_path, file])} - List.first(files) - - File.exists?(u_path) -> - # {uuid, u_path} - raise "should_dedupe local storage not supported yet sorry" - end - - {:ok, _} = - Upload.store({:from_local, name, path}, should_dedupe: false, uploader: uploader) - - if delete? do - File.rm_rf!(u_path) + fn {upload, root_path} -> + case Upload.store(upload, uploader: uploader, filters: [], size_limit: nil) do + {:ok, _} -> + if delete?, do: File.rm_rf!(root_path) + Logger.debug("uploaded: #{inspect(upload.path)} #{inspect(upload)}") + :ok + + error -> + Logger.error("failed to upload #{inspect(upload.path)}: #{inspect(error)}") end - - Logger.debug("uploaded: #{inspect(name)}") end, timeout: 150_000 ) @@ -75,6 +92,6 @@ defmodule Mix.Tasks.MigrateLocalUploads do end def run(_) do - Logger.error("Usage: migrate_local_uploads UploaderName [--delete]") + Logger.error("Usage: migrate_local_uploads S3|Swift [--delete]") end end -- cgit v1.2.3