end
defp assign_db_info(healthcheck) do
- database = Application.get_env(:pleroma, Repo)[:database]
+ database = Pleroma.Config.get([Repo, :database])
query =
"select state, count(pid) from pg_stat_activity where datname = '#{database}' group by state;"
result = Repo.query!(query)
- pool_size = Application.get_env(:pleroma, Repo)[:pool_size]
+ pool_size = Pleroma.Config.get([Repo, :pool_size])
db_info =
Enum.reduce(result.rows, %{active: 0, idle: 0}, fn [state, cnt], states ->
@ets __MODULE__.Ets
@ets_options [:ordered_set, :protected, :named_table, {:read_concurrency, true}]
- @groups Application.get_env(:pleroma, :emoji)[:groups]
+ @groups Pleroma.Config.get([:emoji, :groups])
@doc false
def start_link do
# Compat thing for old custom emoji handling & default emoji,
# it should run even if there are no emoji packs
- shortcode_globs = Application.get_env(:pleroma, :emoji)[:shortcode_globs] || []
+ shortcode_globs = Pleroma.Config.get([:emoji, :shortcode_globs], [])
emojis =
(load_from_file("config/emoji.txt") ++
paragraphs, breaks and links are allowed through the filter.
"""
- @markup Application.get_env(:pleroma, :markup)
@valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
require HtmlSanitizeEx.Scrubber.Meta
Meta.allow_tag_with_these_attributes("span", [])
# allow inline images for custom emoji
- @allow_inline_images Keyword.get(@markup, :allow_inline_images)
-
- if @allow_inline_images do
+ if Pleroma.Config.get([:markup, :allow_inline_images]) do
# restrict img tags to http/https only, because of MediaProxy.
Meta.allow_tag_with_uri_attributes("img", ["src"], ["http", "https"])
# credo:disable-for-previous-line
# No idea how to fix this oneā¦
- @markup Application.get_env(:pleroma, :markup)
@valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
Meta.remove_cdata_sections_before_scrub()
Meta.allow_tag_with_this_attribute_values("span", "class", ["h-card"])
Meta.allow_tag_with_these_attributes("span", [])
- @allow_inline_images Keyword.get(@markup, :allow_inline_images)
+ @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
if @allow_inline_images do
# restrict img tags to http/https only, because of MediaProxy.
])
end
- @allow_tables Keyword.get(@markup, :allow_tables)
-
- if @allow_tables do
+ if Pleroma.Config.get([:markup, :allow_tables]) do
Meta.allow_tag_with_these_attributes("table", [])
Meta.allow_tag_with_these_attributes("tbody", [])
Meta.allow_tag_with_these_attributes("td", [])
Meta.allow_tag_with_these_attributes("tr", [])
end
- @allow_headings Keyword.get(@markup, :allow_headings)
-
- if @allow_headings do
+ if Pleroma.Config.get([:markup, :allow_headings]) do
Meta.allow_tag_with_these_attributes("h1", [])
Meta.allow_tag_with_these_attributes("h2", [])
Meta.allow_tag_with_these_attributes("h3", [])
Meta.allow_tag_with_these_attributes("h5", [])
end
- @allow_fonts Keyword.get(@markup, :allow_fonts)
-
- if @allow_fonts do
+ if Pleroma.Config.get([:markup, :allow_fonts]) do
Meta.allow_tag_with_these_attributes("font", ["face"])
end
end
def process_request_options(options) do
- config = Application.get_env(:pleroma, :http, [])
- proxy = Keyword.get(config, :proxy_url, nil)
-
- case proxy do
+ case Pleroma.Config.get([:http, :proxy_url]) do
nil -> options
- _ -> options ++ [proxy: proxy]
+ proxy -> options ++ [proxy: proxy]
end
end
end
def call(conn, _opts) do
- if Keyword.get(Application.get_env(:pleroma, :instance), :federating) do
+ if Pleroma.Config.get([:instance, :federating]) do
conn
else
conn
* `http`: options for [hackney](https://github.com/benoitc/hackney).
"""
- @hackney Application.get_env(:pleroma, :hackney, :hackney)
+ @hackney Pleroma.Config.get(:hackney, :hackney)
@default_hackney_options []
end
def follow(%User{} = follower, %User{info: info} = followed) do
- user_config = Application.get_env(:pleroma, :user)
- deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
-
+ deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
ap_followers = followed.follower_address
cond do
end
def block(blocker, blocked, activity_id \\ nil, local \\ true) do
- ap_config = Application.get_env(:pleroma, :activitypub)
- unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked)
- outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks)
+ outgoing_blocks = Pleroma.Config.get([:activitypub, :outgoing_blocks])
+ unfollow_blocked = Pleroma.Config.get([:activitypub, :unfollow_blocked])
- with true <- unfollow_blocked do
+ if unfollow_blocked do
follow_activity = fetch_latest_follow(blocker, blocked)
-
- if follow_activity do
- unfollow(blocker, blocked, nil, local)
- end
+ if follow_activity, do: unfollow(blocker, blocked, nil, local)
end
with true <- outgoing_blocks,
plug(:relay_active? when action in [:relay])
def relay_active?(conn, _) do
- if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do
+ if Pleroma.Config.get([:instance, :allow_relay]) do
conn
else
conn
end
def get_policies do
- Application.get_env(:pleroma, :instance, [])
- |> Keyword.get(:rewrite_policy, [])
- |> get_policies()
+ Pleroma.Config.get([:instance, :rewrite_policy], []) |> get_policies()
end
defp get_policies(policy) when is_atom(policy), do: [policy]
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Jason,
- length: Application.get_env(:pleroma, :instance) |> Keyword.get(:upload_limit),
+ length: Pleroma.Config.get([:instance, :upload_limit]),
body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
)
def url("/" <> _ = url), do: url
def url(url) do
- config = Application.get_env(:pleroma, :media_proxy, [])
- domain = URI.parse(url).host
+ if !enabled?() or local?(url) or whitelisted?(url) do
+ url
+ else
+ encode_url(url)
+ end
+ end
- cond do
- !Keyword.get(config, :enabled, false) or String.starts_with?(url, Pleroma.Web.base_url()) ->
- url
+ defp enabled?, do: Pleroma.Config.get([:media_proxy, :enabled], false)
- Enum.any?(Pleroma.Config.get([:media_proxy, :whitelist]), fn pattern ->
- String.equivalent?(domain, pattern)
- end) ->
- url
+ defp local?(url), do: String.starts_with?(url, Pleroma.Web.base_url())
- true ->
- encode_url(url)
- end
+ defp whitelisted?(url) do
+ %{host: domain} = URI.parse(url)
+
+ Enum.any?(Pleroma.Config.get([:media_proxy, :whitelist]), fn pattern ->
+ String.equivalent?(domain, pattern)
+ end)
end
def encode_url(url) do
- secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
+ secret = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base])
# Must preserve `%2F` for compatibility with S3
# https://git.pleroma.social/pleroma/pleroma/issues/580
end
def decode_url(sig, url) do
- secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
+ secret = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base])
sig = Base.url_decode64!(sig, @base64_opts)
local_sig = :crypto.hmac(:sha, secret, url)
# returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
# under software.
def raw_nodeinfo do
- instance = Application.get_env(:pleroma, :instance)
- media_proxy = Application.get_env(:pleroma, :media_proxy)
- suggestions = Application.get_env(:pleroma, :suggestions)
- chat = Application.get_env(:pleroma, :chat)
- gopher = Application.get_env(:pleroma, :gopher)
stats = Stats.get_stats()
mrf_simple =
- Application.get_env(:pleroma, :mrf_simple)
+ Config.get(:mrf_simple)
|> Enum.into(%{})
# This horror is needed to convert regex sigils to strings
mrf_keyword =
- Application.get_env(:pleroma, :mrf_keyword, [])
+ Config.get(:mrf_keyword, [])
|> Enum.map(fn {key, value} ->
{key,
Enum.map(value, fn
MRF.get_policies()
|> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
- quarantined = Keyword.get(instance, :quarantined_instances)
-
- quarantined =
- if is_list(quarantined) do
- quarantined
- else
- []
- end
+ quarantined = Config.get([:instance, :quarantined_instances], [])
staff_accounts =
User.all_superusers()
|> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
federation_response =
- if Keyword.get(instance, :mrf_transparency) do
+ if Config.get([:instance, :mrf_transparency]) do
%{
mrf_policies: mrf_policies,
mrf_simple: mrf_simple,
"pleroma_api",
"mastodon_api",
"mastodon_api_streaming",
- if Keyword.get(media_proxy, :enabled) do
+ if Config.get([:media_proxy, :enabled]) do
"media_proxy"
end,
- if Keyword.get(gopher, :enabled) do
+ if Config.get([:gopher, :enabled]) do
"gopher"
end,
- if Keyword.get(chat, :enabled) do
+ if Config.get([:chat, :enabled]) do
"chat"
end,
- if Keyword.get(suggestions, :enabled) do
+ if Config.get([:suggestions, :enabled]) do
"suggestions"
end,
- if Keyword.get(instance, :allow_relay) do
+ if Config.get([:instance, :allow_relay]) do
"relay"
end,
- if Keyword.get(instance, :safe_dm_mentions) do
+ if Config.get([:instance, :safe_dm_mentions]) do
"safe_dm_mentions"
end
]
inbound: [],
outbound: []
},
- openRegistrations: Keyword.get(instance, :registrations_open),
+ openRegistrations: Config.get([:instance, :registrations_open]),
usage: %{
users: %{
total: stats.user_count || 0
localPosts: stats.status_count || 0
},
metadata: %{
- nodeName: Keyword.get(instance, :name),
- nodeDescription: Keyword.get(instance, :description),
- private: !Keyword.get(instance, :public, true),
+ nodeName: Config.get([:instance, :name]),
+ nodeDescription: Config.get([:instance, :description]),
+ private: !Config.get([:instance, :public], true),
suggestions: %{
- enabled: Keyword.get(suggestions, :enabled, false),
- thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
- timeout: Keyword.get(suggestions, :timeout, 5000),
- limit: Keyword.get(suggestions, :limit, 23),
- web: Keyword.get(suggestions, :web, "")
+ enabled: Config.get([:suggestions, :enabled], false),
+ thirdPartyEngine: Config.get([:suggestions, :third_party_engine], ""),
+ timeout: Config.get([:suggestions, :timeout], 5000),
+ limit: Config.get([:suggestions, :limit], 23),
+ web: Config.get([:suggestions, :web], "")
},
staffAccounts: staff_accounts,
federation: federation_response,
- postFormats: Keyword.get(instance, :allowed_post_formats),
+ postFormats: Config.get([:instance, :allowed_post_formats]),
uploadLimits: %{
- general: Keyword.get(instance, :upload_limit),
- avatar: Keyword.get(instance, :avatar_upload_limit),
- banner: Keyword.get(instance, :banner_upload_limit),
- background: Keyword.get(instance, :background_upload_limit)
+ general: Config.get([:instance, :upload_limit]),
+ avatar: Config.get([:instance, :avatar_upload_limit]),
+ banner: Config.get([:instance, :banner_upload_limit]),
+ background: Config.get([:instance, :background_upload_limit])
},
- accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
- invitesEnabled: Keyword.get(instance, :invites_enabled, false),
+ accountActivationRequired: Config.get([:instance, :account_activation_required], false),
+ invitesEnabled: Config.get([:instance, :invites_enabled], false),
features: features,
- restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
+ restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames])
}
}
end
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui" />
<title>
- <%= Application.get_env(:pleroma, :instance)[:name] %>
+ <%= Pleroma.Config.get([:instance, :name]) %>
</title>
<style>
body {
</head>
<body>
<div class="container">
- <h1><%= Application.get_env(:pleroma, :instance)[:name] %></h1>
+ <h1><%= Pleroma.Config.get([:instance, :name]) %></h1>
<%= render @view_module, @view_template, assigns %>
</div>
</body>
<meta charset='utf-8'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<title>
-<%= Application.get_env(:pleroma, :instance)[:name] %>
+<%= Pleroma.Config.get([:instance, :name]) %>
</title>
<link rel="icon" type="image/png" href="/favicon.png"/>
<script crossorigin='anonymous' src="/packs/locales.js"></script>
def only_if_public_instance(%{assigns: %{user: %User{}}} = conn, _), do: conn
def only_if_public_instance(conn, _) do
- if Keyword.get(Application.get_env(:pleroma, :instance), :public) do
+ if Pleroma.Config.get([:instance, :public]) do
conn
else
conn
use Pleroma.Web.ConnCase
test "returns and halt the conn when federating is disabled" do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:federating, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :federating], false)
conn =
build_conn()
assert conn.status == 404
assert conn.halted
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:federating, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :federating], true)
end
test "does nothing when federating is enabled" do
end
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(403)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
%{conn: conn, user: user} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
setup [:valid_user]
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(403)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
%{conn: conn, user: user} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do