Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

197 řádky
6.4KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Config.DeprecationWarnings do
  5. alias Pleroma.Config
  6. require Logger
  7. alias Pleroma.Config
  8. @type config_namespace() :: atom() | [atom()]
  9. @type config_map() :: {config_namespace(), config_namespace(), String.t()}
  10. @mrf_config_map [
  11. {[:instance, :rewrite_policy], [:mrf, :policies],
  12. "\n* `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`"},
  13. {[:instance, :mrf_transparency], [:mrf, :transparency],
  14. "\n* `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`"},
  15. {[:instance, :mrf_transparency_exclusions], [:mrf, :transparency_exclusions],
  16. "\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"}
  17. ]
  18. def check_hellthread_threshold do
  19. if Config.get([:mrf_hellthread, :threshold]) do
  20. Logger.warn("""
  21. !!!DEPRECATION WARNING!!!
  22. You are using the old configuration mechanism for the hellthread filter. Please check config.md.
  23. """)
  24. :error
  25. else
  26. :ok
  27. end
  28. end
  29. def warn do
  30. with :ok <- check_hellthread_threshold(),
  31. :ok <- check_old_mrf_config(),
  32. :ok <- check_media_proxy_whitelist_config(),
  33. :ok <- check_welcome_message_config(),
  34. :ok <- check_gun_pool_options(),
  35. :ok <- check_activity_expiration_config(),
  36. :ok <- check_remote_ip_plug_name() do
  37. :ok
  38. else
  39. _ ->
  40. :error
  41. end
  42. end
  43. def check_welcome_message_config do
  44. instance_config = Pleroma.Config.get([:instance])
  45. use_old_config =
  46. Keyword.has_key?(instance_config, :welcome_user_nickname) or
  47. Keyword.has_key?(instance_config, :welcome_message)
  48. if use_old_config do
  49. Logger.error("""
  50. !!!DEPRECATION WARNING!!!
  51. Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
  52. \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
  53. \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
  54. """)
  55. :error
  56. else
  57. :ok
  58. end
  59. end
  60. def check_old_mrf_config do
  61. warning_preface = """
  62. !!!DEPRECATION WARNING!!!
  63. Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
  64. """
  65. move_namespace_and_warn(@mrf_config_map, warning_preface)
  66. end
  67. @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
  68. def move_namespace_and_warn(config_map, warning_preface) do
  69. warning =
  70. Enum.reduce(config_map, "", fn
  71. {old, new, err_msg}, acc ->
  72. old_config = Config.get(old)
  73. if old_config do
  74. Config.put(new, old_config)
  75. acc <> err_msg
  76. else
  77. acc
  78. end
  79. end)
  80. if warning == "" do
  81. :ok
  82. else
  83. Logger.warn(warning_preface <> warning)
  84. :error
  85. end
  86. end
  87. @spec check_media_proxy_whitelist_config() :: :ok | nil
  88. def check_media_proxy_whitelist_config do
  89. whitelist = Config.get([:media_proxy, :whitelist])
  90. if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
  91. Logger.warn("""
  92. !!!DEPRECATION WARNING!!!
  93. Your config is using old format (only domain) for MediaProxy whitelist option. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
  94. """)
  95. :error
  96. else
  97. :ok
  98. end
  99. end
  100. def check_gun_pool_options do
  101. pool_config = Config.get(:connections_pool)
  102. if timeout = pool_config[:await_up_timeout] do
  103. Logger.warn("""
  104. !!!DEPRECATION WARNING!!!
  105. Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`. Please change to `config :pleroma, :connections_pool, connect_timeout` to ensure compatibility with future releases.
  106. """)
  107. Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
  108. end
  109. pools_configs = Config.get(:pools)
  110. warning_preface = """
  111. !!!DEPRECATION WARNING!!!
  112. Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
  113. """
  114. updated_config =
  115. Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
  116. if timeout = config[:timeout] do
  117. Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
  118. else
  119. acc
  120. end
  121. end)
  122. if updated_config != [] do
  123. pool_warnings =
  124. updated_config
  125. |> Keyword.keys()
  126. |> Enum.map(fn pool_name ->
  127. "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
  128. end)
  129. Logger.warn(Enum.join([warning_preface | pool_warnings]))
  130. Config.put(:pools, updated_config)
  131. :error
  132. else
  133. :ok
  134. end
  135. end
  136. @spec check_activity_expiration_config() :: :ok | nil
  137. def check_activity_expiration_config do
  138. warning_preface = """
  139. !!!DEPRECATION WARNING!!!
  140. Your config is using old namespace for activity expiration configuration. Setting should work for now, but you are advised to change to new namespace to prevent possible issues later:
  141. """
  142. move_namespace_and_warn(
  143. [
  144. {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
  145. "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
  146. ],
  147. warning_preface
  148. )
  149. end
  150. @spec check_remote_ip_plug_name() :: :ok | nil
  151. def check_remote_ip_plug_name do
  152. warning_preface = """
  153. !!!DEPRECATION WARNING!!!
  154. Your config is using old namespace for RemoteIp Plug. Setting should work for now, but you are advised to change to new namespace to prevent possible issues later:
  155. """
  156. move_namespace_and_warn(
  157. [
  158. {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
  159. "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
  160. ],
  161. warning_preface
  162. )
  163. end
  164. end