Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
7.9KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 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(),
  37. :ok <- check_uploders_s3_public_endpoint(),
  38. :ok <- check_old_chat_shoutbox() do
  39. :ok
  40. else
  41. _ ->
  42. :error
  43. end
  44. end
  45. def check_welcome_message_config do
  46. instance_config = Pleroma.Config.get([:instance])
  47. use_old_config =
  48. Keyword.has_key?(instance_config, :welcome_user_nickname) or
  49. Keyword.has_key?(instance_config, :welcome_message)
  50. if use_old_config do
  51. Logger.error("""
  52. !!!DEPRECATION WARNING!!!
  53. Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
  54. \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
  55. \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
  56. """)
  57. :error
  58. else
  59. :ok
  60. end
  61. end
  62. def check_old_mrf_config do
  63. warning_preface = """
  64. !!!DEPRECATION WARNING!!!
  65. 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:
  66. """
  67. move_namespace_and_warn(@mrf_config_map, warning_preface)
  68. end
  69. @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
  70. def move_namespace_and_warn(config_map, warning_preface) do
  71. warning =
  72. Enum.reduce(config_map, "", fn
  73. {old, new, err_msg}, acc ->
  74. old_config = Config.get(old)
  75. if old_config do
  76. Config.put(new, old_config)
  77. acc <> err_msg
  78. else
  79. acc
  80. end
  81. end)
  82. if warning == "" do
  83. :ok
  84. else
  85. Logger.warn(warning_preface <> warning)
  86. :error
  87. end
  88. end
  89. @spec check_media_proxy_whitelist_config() :: :ok | nil
  90. def check_media_proxy_whitelist_config do
  91. whitelist = Config.get([:media_proxy, :whitelist])
  92. if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
  93. Logger.warn("""
  94. !!!DEPRECATION WARNING!!!
  95. 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.
  96. """)
  97. :error
  98. else
  99. :ok
  100. end
  101. end
  102. def check_gun_pool_options do
  103. pool_config = Config.get(:connections_pool)
  104. if timeout = pool_config[:await_up_timeout] do
  105. Logger.warn("""
  106. !!!DEPRECATION WARNING!!!
  107. 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.
  108. """)
  109. Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
  110. end
  111. pools_configs = Config.get(:pools)
  112. warning_preface = """
  113. !!!DEPRECATION WARNING!!!
  114. 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.
  115. """
  116. updated_config =
  117. Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
  118. if timeout = config[:timeout] do
  119. Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
  120. else
  121. acc
  122. end
  123. end)
  124. if updated_config != [] do
  125. pool_warnings =
  126. updated_config
  127. |> Keyword.keys()
  128. |> Enum.map(fn pool_name ->
  129. "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
  130. end)
  131. Logger.warn(Enum.join([warning_preface | pool_warnings]))
  132. Config.put(:pools, updated_config)
  133. :error
  134. else
  135. :ok
  136. end
  137. end
  138. @spec check_activity_expiration_config() :: :ok | nil
  139. def check_activity_expiration_config do
  140. warning_preface = """
  141. !!!DEPRECATION WARNING!!!
  142. 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:
  143. """
  144. move_namespace_and_warn(
  145. [
  146. {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
  147. "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
  148. ],
  149. warning_preface
  150. )
  151. end
  152. @spec check_remote_ip_plug_name() :: :ok | nil
  153. def check_remote_ip_plug_name do
  154. warning_preface = """
  155. !!!DEPRECATION WARNING!!!
  156. 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:
  157. """
  158. move_namespace_and_warn(
  159. [
  160. {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
  161. "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
  162. ],
  163. warning_preface
  164. )
  165. end
  166. @spec check_uploders_s3_public_endpoint() :: :ok | nil
  167. def check_uploders_s3_public_endpoint do
  168. s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
  169. use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
  170. if use_old_config do
  171. Logger.error("""
  172. !!!DEPRECATION WARNING!!!
  173. Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
  174. Please make the following change at your earliest convenience.\n
  175. \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
  176. \n* `config :pleroma, Pleroma.Upload, base_url`
  177. """)
  178. :error
  179. else
  180. :ok
  181. end
  182. end
  183. @spec check_old_chat_shoutbox() :: :ok | nil
  184. def check_old_chat_shoutbox do
  185. instance_config = Pleroma.Config.get([:instance])
  186. chat_config = Pleroma.Config.get([:chat]) || []
  187. use_old_config =
  188. Keyword.has_key?(instance_config, :chat_limit) or
  189. Keyword.has_key?(chat_config, :enabled)
  190. if use_old_config do
  191. Logger.error("""
  192. !!!DEPRECATION WARNING!!!
  193. Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
  194. \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
  195. \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
  196. """)
  197. :error
  198. else
  199. :ok
  200. end
  201. end
  202. end