aboutsummaryrefslogtreecommitdiff
path: root/lib/mix
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2019-04-11 15:51:52 +0700
committerEgor Kislitsyn <egor@kislitsyn.com>2019-04-11 15:51:52 +0700
commit0f2f7d2cec8297b1b5645643d7584cde561ce628 (patch)
treeaa618de9dc399de2e3abf37ad9ecf66d8cb9761f /lib/mix
parent22ac2288be498bd6a5a6fefe2dc6d2e260a8dc39 (diff)
parente5d553aa45ffa218b0695d7976f012bfc1dcbafe (diff)
downloadpleroma-0f2f7d2cec8297b1b5645643d7584cde561ce628.tar.gz
Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
Diffstat (limited to 'lib/mix')
-rw-r--r--lib/mix/tasks/pleroma/instance.ex34
-rw-r--r--lib/mix/tasks/pleroma/relay.ex2
-rw-r--r--lib/mix/tasks/pleroma/robots_txt.eex2
-rw-r--r--lib/mix/tasks/pleroma/robotstxt.ex32
-rw-r--r--lib/mix/tasks/pleroma/uploads.ex3
-rw-r--r--lib/mix/tasks/pleroma/user.ex104
6 files changed, 164 insertions, 13 deletions
diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex
index 1ba452275..8f8d86a11 100644
--- a/lib/mix/tasks/pleroma/instance.ex
+++ b/lib/mix/tasks/pleroma/instance.ex
@@ -81,6 +81,14 @@ defmodule Mix.Tasks.Pleroma.Instance do
email = Common.get_option(options, :admin_email, "What is your admin email address?")
+ indexable =
+ Common.get_option(
+ options,
+ :indexable,
+ "Do you want search engines to index your site? (y/n)",
+ "y"
+ ) === "y"
+
dbhost =
Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
@@ -142,6 +150,8 @@ defmodule Mix.Tasks.Pleroma.Instance do
Mix.shell().info("Writing #{psql_path}.")
File.write(psql_path, result_psql)
+ write_robots_txt(indexable)
+
Mix.shell().info(
"\n" <>
"""
@@ -163,4 +173,28 @@ defmodule Mix.Tasks.Pleroma.Instance do
)
end
end
+
+ defp write_robots_txt(indexable) do
+ robots_txt =
+ EEx.eval_file(
+ Path.expand("robots_txt.eex", __DIR__),
+ indexable: indexable
+ )
+
+ static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
+
+ unless File.exists?(static_dir) do
+ File.mkdir_p!(static_dir)
+ end
+
+ robots_txt_path = Path.join(static_dir, "robots.txt")
+
+ if File.exists?(robots_txt_path) do
+ File.cp!(robots_txt_path, "#{robots_txt_path}.bak")
+ Mix.shell().info("Backing up existing robots.txt to #{robots_txt_path}.bak")
+ end
+
+ File.write(robots_txt_path, robots_txt)
+ Mix.shell().info("Writing #{robots_txt_path}.")
+ end
end
diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex
index cbe23f82e..fbec473c5 100644
--- a/lib/mix/tasks/pleroma/relay.ex
+++ b/lib/mix/tasks/pleroma/relay.ex
@@ -4,8 +4,8 @@
defmodule Mix.Tasks.Pleroma.Relay do
use Mix.Task
- alias Pleroma.Web.ActivityPub.Relay
alias Mix.Tasks.Pleroma.Common
+ alias Pleroma.Web.ActivityPub.Relay
@shortdoc "Manages remote relays"
@moduledoc """
diff --git a/lib/mix/tasks/pleroma/robots_txt.eex b/lib/mix/tasks/pleroma/robots_txt.eex
new file mode 100644
index 000000000..1af3c47ee
--- /dev/null
+++ b/lib/mix/tasks/pleroma/robots_txt.eex
@@ -0,0 +1,2 @@
+User-Agent: *
+Disallow: <%= if indexable, do: "", else: "/" %>
diff --git a/lib/mix/tasks/pleroma/robotstxt.ex b/lib/mix/tasks/pleroma/robotstxt.ex
new file mode 100644
index 000000000..2128e1cd6
--- /dev/null
+++ b/lib/mix/tasks/pleroma/robotstxt.ex
@@ -0,0 +1,32 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.RobotsTxt do
+ use Mix.Task
+
+ @shortdoc "Generate robots.txt"
+ @moduledoc """
+ Generates robots.txt
+
+ ## Overwrite robots.txt to disallow all
+
+ mix pleroma.robots_txt disallow_all
+
+ This will write a robots.txt that will hide all paths on your instance
+ from search engines and other robots that obey robots.txt
+
+ """
+ def run(["disallow_all"]) do
+ static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
+
+ if !File.exists?(static_dir) do
+ File.mkdir_p!(static_dir)
+ end
+
+ robots_txt_path = Path.join(static_dir, "robots.txt")
+ robots_txt_content = "User-Agent: *\nDisallow: /\n"
+
+ File.write!(robots_txt_path, robots_txt_content, [:write])
+ end
+end
diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex
index a01e61627..106fcf443 100644
--- a/lib/mix/tasks/pleroma/uploads.ex
+++ b/lib/mix/tasks/pleroma/uploads.ex
@@ -4,9 +4,9 @@
defmodule Mix.Tasks.Pleroma.Uploads do
use Mix.Task
+ alias Mix.Tasks.Pleroma.Common
alias Pleroma.Upload
alias Pleroma.Uploaders.Local
- alias Mix.Tasks.Pleroma.Common
require Logger
@log_every 50
@@ -20,7 +20,6 @@ defmodule Mix.Tasks.Pleroma.Uploads do
Options:
- `--delete` - delete local uploads after migrating them to the target uploader
-
A list of available uploaders can be seen in config.exs
"""
def run(["migrate_local", target_uploader | args]) do
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index 297332bc4..78493231c 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -5,9 +5,9 @@
defmodule Mix.Tasks.Pleroma.User do
use Mix.Task
import Ecto.Changeset
- alias Pleroma.Repo
- alias Pleroma.User
alias Mix.Tasks.Pleroma.Common
+ alias Pleroma.User
+ alias Pleroma.UserInviteToken
@shortdoc "Manages Pleroma users"
@moduledoc """
@@ -27,12 +27,28 @@ defmodule Mix.Tasks.Pleroma.User do
## Generate an invite link.
- mix pleroma.user invite
+ mix pleroma.user invite [OPTION...]
+
+ Options:
+ - `--expires_at DATE` - last day on which token is active (e.g. "2019-04-05")
+ - `--max_use NUMBER` - maximum numbers of token uses
+
+ ## List generated invites
+
+ mix pleroma.user invites
+
+ ## Revoke invite
+
+ mix pleroma.user revoke_invite TOKEN OR TOKEN_ID
## Delete the user's account.
mix pleroma.user rm NICKNAME
+ ## Delete the user's activities.
+
+ mix pleroma.user delete_activities NICKNAME
+
## Deactivate or activate the user's account.
mix pleroma.user toggle_activated NICKNAME
@@ -220,7 +236,7 @@ defmodule Mix.Tasks.Pleroma.User do
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
- user = Repo.get(User, user.id)
+ user = User.get_by_id(user.id)
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
@@ -228,7 +244,7 @@ defmodule Mix.Tasks.Pleroma.User do
:timer.sleep(500)
- user = Repo.get(User, user.id)
+ user = User.get_by_id(user.id)
if Enum.empty?(user.following) do
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
@@ -302,23 +318,91 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
- def run(["invite"]) do
+ def run(["invite" | rest]) do
+ {options, [], []} =
+ OptionParser.parse(rest,
+ strict: [
+ expires_at: :string,
+ max_use: :integer
+ ]
+ )
+
+ options =
+ options
+ |> Keyword.update(:expires_at, {:ok, nil}, fn
+ nil -> {:ok, nil}
+ val -> Date.from_iso8601(val)
+ end)
+ |> Enum.into(%{})
+
Common.start_pleroma()
- with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
- Mix.shell().info("Generated user invite token")
+ with {:ok, val} <- options[:expires_at],
+ options = Map.put(options, :expires_at, val),
+ {:ok, invite} <- UserInviteToken.create_invite(options) do
+ Mix.shell().info(
+ "Generated user invite token " <> String.replace(invite.invite_type, "_", " ")
+ )
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
- token.token
+ invite.token
)
IO.puts(url)
else
+ error ->
+ Mix.shell().error("Could not create invite token: #{inspect(error)}")
+ end
+ end
+
+ def run(["invites"]) do
+ Common.start_pleroma()
+
+ Mix.shell().info("Invites list:")
+
+ UserInviteToken.list_invites()
+ |> Enum.each(fn invite ->
+ expire_info =
+ with expires_at when not is_nil(expires_at) <- invite.expires_at do
+ " | Expires at: #{Date.to_string(expires_at)}"
+ end
+
+ using_info =
+ with max_use when not is_nil(max_use) <- invite.max_use do
+ " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
+ end
+
+ Mix.shell().info(
+ "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{
+ invite.used
+ }#{expire_info}#{using_info}"
+ )
+ end)
+ end
+
+ def run(["revoke_invite", token]) do
+ Common.start_pleroma()
+
+ with {:ok, invite} <- UserInviteToken.find_by_token(token),
+ {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
+ Mix.shell().info("Invite for token #{token} was revoked.")
+ else
+ _ -> Mix.shell().error("No invite found with token #{token}")
+ end
+ end
+
+ def run(["delete_activities", nickname]) do
+ Common.start_pleroma()
+
+ with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ User.delete_user_activities(user)
+ Mix.shell().info("User #{nickname} statuses deleted.")
+ else
_ ->
- Mix.shell().error("Could not create invite token.")
+ Mix.shell().error("No local user #{nickname}")
end
end