# secrets files as long as you replace their contents by environment
# variables.
/config/*.secret.exs
+/config/generated_config.exs
# Database setup file, some may forget to delete it
/config/setup_db.psql
allow_followersonly: false,
allow_direct: false
-config :pleroma, :mrf_hellthread, threshold: 10
+config :pleroma, :mrf_hellthread,
+ delist_threshold: 5,
+ reject_threshold: 10
config :pleroma, :mrf_simple,
media_removal: [],
## Pleroma.Upload.Filter.Mogrify
-* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", {"impode", "1"}]`.
+* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", "auto-orient", {"impode", "1"}]`.
## Pleroma.Upload.Filter.Dedupe
* `allow_direct`: whether to allow direct messages
## :mrf_hellthread
-* `threshold`: Number of mentioned users after which the message gets discarded as spam
+* `delist_threshold`: Number of mentioned users after which the message gets delisted (the message can still be seen, but it will not show up in public timelines and mentioned users won't get notifications about it). Set to 0 to disable.
+* `reject_threshold`: Number of mentioned users after which the messaged gets rejected. Set to 0 to disable.
## :media_proxy
* `enabled`: Enables proxying of remote media to the instance’s proxy
- `--locked`/`--no-locked` - whether the user's account is locked
- `--moderator`/`--no-moderator` - whether the user is a moderator
- `--admin`/`--no-admin` - whether the user is an admin
+
+ ## Add tags to a user.
+
+ mix pleroma.user tag NICKNAME TAGS
+
+ ## Delete tags from a user.
+
+ mix pleroma.user untag NICKNAME TAGS
"""
def run(["new", nickname, email | rest]) do
{options, [], []} =
end
end
+ def run(["tag", nickname | tags]) do
+ Common.start_pleroma()
+
+ with %User{} = user <- User.get_by_nickname(nickname) do
+ user = user |> User.tag(tags)
+
+ Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
+ else
+ _ ->
+ Mix.shell().error("Could not change user tags for #{nickname}")
+ end
+ end
+
+ def run(["untag", nickname | tags]) do
+ Common.start_pleroma()
+
+ with %User{} = user <- User.get_by_nickname(nickname) do
+ user = user |> User.untag(tags)
+
+ Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
+ else
+ _ ->
+ Mix.shell().error("Could not change user tags for #{nickname}")
+ end
+ end
+
def run(["invite"]) do
Common.start_pleroma()
end
end
+ def check_hellthread_threshold do
+ if Pleroma.Config.get([:mrf_hellthread, :threshold]) do
+ Logger.warn("""
+ !!!DEPRECATION WARNING!!!
+ You are using the old configuration mechanism for the hellthread filter. Please check config.md.
+ """)
+ end
+ end
+
def warn do
check_frontend_config_mechanism()
+ check_hellthread_threshold()
end
end
end)
end
+ def extract_first_external_url(_, nil), do: {:error, "No content"}
+
def extract_first_external_url(object, content) do
key = "URL|#{object.id}"
"audio/ogg"
end
- defp check_mime_type(<<0x52, 0x49, 0x46, 0x46, _::binary>>) do
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do
"audio/wav"
end
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do
+ "image/webp"
+ end
+
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do
+ "video/avi"
+ end
+
defp check_mime_type(_) do
@default
end
:pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]]
- :pleroma, Pleroma.Upload.Filter.Mogrify, args: "strip"
+ :pleroma, Pleroma.Upload.Filter.Mogrify, args: ["strip", "auto-orient"]
""")
- Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: "strip")
+ Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: ["strip", "auto-orient"])
Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify])
else
opts
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
+ alias Pleroma.User
@behaviour Pleroma.Web.ActivityPub.MRF
+ defp delist_message(message) do
+ follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
+
+ message
+ |> Map.put("to", [follower_collection])
+ |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+ end
+
@impl true
- def filter(%{"type" => "Create"} = object) do
- threshold = Pleroma.Config.get([:mrf_hellthread, :threshold])
- recipients = (object["to"] || []) ++ (object["cc"] || [])
-
- if length(recipients) > threshold do
- {:reject, nil}
- else
- {:ok, object}
+ def filter(%{"type" => "Create"} = message) do
+ delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
+
+ reject_threshold =
+ Pleroma.Config.get(
+ [:mrf_hellthread, :reject_threshold],
+ Pleroma.Config.get([:mrf_hellthread, :threshold])
+ )
+
+ recipients = (message["to"] || []) ++ (message["cc"] || [])
+
+ cond do
+ length(recipients) > reject_threshold and reject_threshold > 0 ->
+ {:reject, nil}
+
+ length(recipients) > delist_threshold and delist_threshold > 0 ->
+ if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
+ Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
+ {:ok, delist_message(message)}
+ else
+ {:ok, message}
+ end
+
+ true ->
+ {:ok, message}
end
end
@impl true
- def filter(object), do: {:ok, object}
+ def filter(message), do: {:ok, message}
end
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
+ alias Pleroma.User
+ @behaviour Pleroma.Web.ActivityPub.MRF
+
+ defp get_tags(%User{tags: tags}) when is_list(tags), do: tags
+ defp get_tags(_), do: []
+
+ defp process_tag(
+ "mrf_tag:media-force-nsfw",
+ %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message
+ )
+ when length(child_attachment) > 0 do
+ tags = (object["tag"] || []) ++ ["nsfw"]
+
+ object =
+ object
+ |> Map.put("tags", tags)
+ |> Map.put("sensitive", true)
+
+ message = Map.put(message, "object", object)
+
+ {:ok, message}
+ end
+
+ defp process_tag(
+ "mrf_tag:media-strip",
+ %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message
+ )
+ when length(child_attachment) > 0 do
+ object = Map.delete(object, "attachment")
+ message = Map.put(message, "object", object)
+
+ {:ok, message}
+ end
+
+ defp process_tag(
+ "mrf_tag:force-unlisted",
+ %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
+ ) do
+ user = User.get_cached_by_ap_id(actor)
+
+ if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") do
+ to =
+ List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
+
+ cc =
+ List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"]
+
+ object =
+ message["object"]
+ |> Map.put("to", to)
+ |> Map.put("cc", cc)
+
+ message =
+ message
+ |> Map.put("to", to)
+ |> Map.put("cc", cc)
+ |> Map.put("object", object)
+
+ {:ok, message}
+ else
+ {:ok, message}
+ end
+ end
+
+ defp process_tag(
+ "mrf_tag:sandbox",
+ %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
+ ) do
+ user = User.get_cached_by_ap_id(actor)
+
+ if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") or
+ Enum.member?(cc, "https://www.w3.org/ns/activitystreams#Public") do
+ to =
+ List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
+
+ cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public")
+
+ object =
+ message["object"]
+ |> Map.put("to", to)
+ |> Map.put("cc", cc)
+
+ message =
+ message
+ |> Map.put("to", to)
+ |> Map.put("cc", cc)
+ |> Map.put("object", object)
+
+ {:ok, message}
+ else
+ {:ok, message}
+ end
+ end
+
+ defp process_tag(
+ "mrf_tag:disable-remote-subscription",
+ %{"type" => "Follow", "actor" => actor} = message
+ ) do
+ user = User.get_cached_by_ap_id(actor)
+
+ if user.local == true do
+ {:ok, message}
+ else
+ {:reject, nil}
+ end
+ end
+
+ defp process_tag("mrf_tag:disable-any-subscription", %{"type" => "Follow"}), do: {:reject, nil}
+
+ defp process_tag(_, message), do: {:ok, message}
+
+ def filter_message(actor, message) do
+ User.get_cached_by_ap_id(actor)
+ |> get_tags()
+ |> Enum.reduce({:ok, message}, fn
+ tag, {:ok, message} ->
+ process_tag(tag, message)
+
+ _, error ->
+ error
+ end)
+ end
+
+ @impl true
+ def filter(%{"object" => target_actor, "type" => "Follow"} = message),
+ do: filter_message(target_actor, message)
+
+ @impl true
+ def filter(%{"actor" => actor, "type" => "Create"} = message),
+ do: filter_message(actor, message)
+
+ @impl true
+ def filter(message), do: {:ok, message}
+end
|> Map.put("tag", combined)
end
+ def fix_tag(%{"tag" => %{} = tag} = object), do: Map.put(object, "tag", [tag])
+
def fix_tag(object), do: object
# content map usually only has one language so this will do for now.
end
def render("card.json", %{rich_media: rich_media, page_url: page_url}) do
- page_url = rich_media[:url] || page_url
- page_url_data = URI.parse(page_url)
+ page_url_data =
+ if rich_media[:url] != nil do
+ URI.merge(URI.parse(page_url), URI.parse(rich_media[:url]))
+ else
+ page_url
+ end
+
+ page_url = page_url_data |> to_string
+
+ image_url =
+ if rich_media[:image] != nil do
+ URI.merge(page_url_data, URI.parse(rich_media[:image]))
+ |> to_string
+ else
+ nil
+ end
+
site_name = rich_media[:site_name] || page_url_data.host
%{
provider_name: site_name,
provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
url: page_url,
- image: rich_media[:image] |> MediaProxy.url(),
+ image: image_url |> MediaProxy.url(),
title: rich_media[:title],
description: rich_media[:description],
pleroma: %{
describe "GET /api/statusnet/config.json" do
test "it returns the managed config", %{conn: conn} do
Pleroma.Config.put([:instance, :managed_config], false)
+ Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
response =
conn