logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

deprecation_warnings.ex (13151B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 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_exiftool_filter do
  19. filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, [])
  20. if Pleroma.Upload.Filter.Exiftool in filters do
  21. Logger.warning("""
  22. !!!DEPRECATION WARNING!!!
  23. Your config is using Exiftool as a filter instead of Exiftool.StripLocation. This should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  24. ```
  25. config :pleroma, Pleroma.Upload,
  26. filters: [Pleroma.Upload.Filter.Exiftool]
  27. ```
  28. Is now
  29. ```
  30. config :pleroma, Pleroma.Upload,
  31. filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
  32. ```
  33. """)
  34. new_config =
  35. filters
  36. |> Enum.map(fn
  37. Pleroma.Upload.Filter.Exiftool -> Pleroma.Upload.Filter.Exiftool.StripLocation
  38. filter -> filter
  39. end)
  40. Config.put([Pleroma.Upload, :filters], new_config)
  41. :error
  42. else
  43. :ok
  44. end
  45. end
  46. def check_simple_policy_tuples do
  47. has_strings =
  48. Config.get([:mrf_simple])
  49. |> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
  50. if has_strings do
  51. Logger.warning("""
  52. !!!DEPRECATION WARNING!!!
  53. Your config is using strings in the SimplePolicy configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  54. ```
  55. config :pleroma, :mrf_simple,
  56. media_removal: ["instance.tld"],
  57. media_nsfw: ["instance.tld"],
  58. federated_timeline_removal: ["instance.tld"],
  59. report_removal: ["instance.tld"],
  60. reject: ["instance.tld"],
  61. followers_only: ["instance.tld"],
  62. accept: ["instance.tld"],
  63. avatar_removal: ["instance.tld"],
  64. banner_removal: ["instance.tld"],
  65. reject_deletes: ["instance.tld"]
  66. ```
  67. Is now
  68. ```
  69. config :pleroma, :mrf_simple,
  70. media_removal: [{"instance.tld", "Reason for media removal"}],
  71. media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
  72. federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
  73. report_removal: [{"instance.tld", "Reason for report removal"}],
  74. reject: [{"instance.tld", "Reason for reject"}],
  75. followers_only: [{"instance.tld", "Reason for followers only"}],
  76. accept: [{"instance.tld", "Reason for accept"}],
  77. avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
  78. banner_removal: [{"instance.tld", "Reason for banner removal"}],
  79. reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
  80. ```
  81. """)
  82. new_config =
  83. Config.get([:mrf_simple])
  84. |> Enum.map(fn {k, v} ->
  85. {k,
  86. Enum.map(v, fn
  87. {instance, reason} -> {instance, reason}
  88. instance -> {instance, ""}
  89. end)}
  90. end)
  91. Config.put([:mrf_simple], new_config)
  92. :error
  93. else
  94. :ok
  95. end
  96. end
  97. def check_quarantined_instances_tuples do
  98. has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
  99. if has_strings do
  100. Logger.warning("""
  101. !!!DEPRECATION WARNING!!!
  102. Your config is using strings in the quarantined_instances configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  103. ```
  104. config :pleroma, :instance,
  105. quarantined_instances: ["instance.tld"]
  106. ```
  107. Is now
  108. ```
  109. config :pleroma, :instance,
  110. quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
  111. ```
  112. """)
  113. new_config =
  114. Config.get([:instance, :quarantined_instances])
  115. |> Enum.map(fn
  116. {instance, reason} -> {instance, reason}
  117. instance -> {instance, ""}
  118. end)
  119. Config.put([:instance, :quarantined_instances], new_config)
  120. :error
  121. else
  122. :ok
  123. end
  124. end
  125. def check_transparency_exclusions_tuples do
  126. has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
  127. if has_strings do
  128. Logger.warning("""
  129. !!!DEPRECATION WARNING!!!
  130. Your config is using strings in the transparency_exclusions configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  131. ```
  132. config :pleroma, :mrf,
  133. transparency_exclusions: ["instance.tld"]
  134. ```
  135. Is now
  136. ```
  137. config :pleroma, :mrf,
  138. transparency_exclusions: [{"instance.tld", "Reason to exclude transparency"}]
  139. ```
  140. """)
  141. new_config =
  142. Config.get([:mrf, :transparency_exclusions])
  143. |> Enum.map(fn
  144. {instance, reason} -> {instance, reason}
  145. instance -> {instance, ""}
  146. end)
  147. Config.put([:mrf, :transparency_exclusions], new_config)
  148. :error
  149. else
  150. :ok
  151. end
  152. end
  153. def check_hellthread_threshold do
  154. if Config.get([:mrf_hellthread, :threshold]) do
  155. Logger.warning("""
  156. !!!DEPRECATION WARNING!!!
  157. You are using the old configuration mechanism for the hellthread filter. Please check config.md.
  158. """)
  159. :error
  160. else
  161. :ok
  162. end
  163. end
  164. def warn do
  165. [
  166. check_hellthread_threshold(),
  167. check_old_mrf_config(),
  168. check_media_proxy_whitelist_config(),
  169. check_welcome_message_config(),
  170. check_gun_pool_options(),
  171. check_activity_expiration_config(),
  172. check_remote_ip_plug_name(),
  173. check_uploaders_s3_public_endpoint(),
  174. check_old_chat_shoutbox(),
  175. check_quarantined_instances_tuples(),
  176. check_transparency_exclusions_tuples(),
  177. check_simple_policy_tuples(),
  178. check_exiftool_filter()
  179. ]
  180. |> Enum.reduce(:ok, fn
  181. :ok, :ok -> :ok
  182. _, _ -> :error
  183. end)
  184. end
  185. def check_welcome_message_config do
  186. instance_config = Pleroma.Config.get([:instance])
  187. use_old_config =
  188. Keyword.has_key?(instance_config, :welcome_user_nickname) or
  189. Keyword.has_key?(instance_config, :welcome_message)
  190. if use_old_config do
  191. Logger.error("""
  192. !!!DEPRECATION WARNING!!!
  193. Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
  194. \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
  195. \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
  196. """)
  197. :error
  198. else
  199. :ok
  200. end
  201. end
  202. def check_old_mrf_config do
  203. warning_preface = """
  204. !!!DEPRECATION WARNING!!!
  205. 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:
  206. """
  207. move_namespace_and_warn(@mrf_config_map, warning_preface)
  208. end
  209. @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | :error
  210. def move_namespace_and_warn(config_map, warning_preface) do
  211. warning =
  212. Enum.reduce(config_map, "", fn
  213. {old, new, err_msg}, acc ->
  214. old_config = Config.get(old)
  215. if old_config do
  216. Config.put(new, old_config)
  217. acc <> err_msg
  218. else
  219. acc
  220. end
  221. end)
  222. if warning == "" do
  223. :ok
  224. else
  225. Logger.warning(warning_preface <> warning)
  226. :error
  227. end
  228. end
  229. @spec check_media_proxy_whitelist_config() :: :ok | :error
  230. def check_media_proxy_whitelist_config do
  231. whitelist = Config.get([:media_proxy, :whitelist])
  232. if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
  233. Logger.warning("""
  234. !!!DEPRECATION WARNING!!!
  235. 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.
  236. """)
  237. :error
  238. else
  239. :ok
  240. end
  241. end
  242. def check_gun_pool_options do
  243. pool_config = Config.get(:connections_pool)
  244. if timeout = pool_config[:await_up_timeout] do
  245. Logger.warning("""
  246. !!!DEPRECATION WARNING!!!
  247. 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.
  248. """)
  249. Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
  250. end
  251. pools_configs = Config.get(:pools)
  252. warning_preface = """
  253. !!!DEPRECATION WARNING!!!
  254. Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings. The setting will not take effect until updated.
  255. """
  256. updated_config =
  257. Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
  258. if timeout = config[:timeout] do
  259. Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
  260. else
  261. acc
  262. end
  263. end)
  264. if updated_config != [] do
  265. pool_warnings =
  266. updated_config
  267. |> Keyword.keys()
  268. |> Enum.map(fn pool_name ->
  269. "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
  270. end)
  271. Logger.warning(Enum.join([warning_preface | pool_warnings]))
  272. Config.put(:pools, updated_config)
  273. :error
  274. else
  275. :ok
  276. end
  277. end
  278. @spec check_activity_expiration_config() :: :ok | :error
  279. def check_activity_expiration_config do
  280. warning_preface = """
  281. !!!DEPRECATION WARNING!!!
  282. 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:
  283. """
  284. move_namespace_and_warn(
  285. [
  286. {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
  287. "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
  288. ],
  289. warning_preface
  290. )
  291. end
  292. @spec check_remote_ip_plug_name() :: :ok | :error
  293. def check_remote_ip_plug_name do
  294. warning_preface = """
  295. !!!DEPRECATION WARNING!!!
  296. 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:
  297. """
  298. move_namespace_and_warn(
  299. [
  300. {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
  301. "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
  302. ],
  303. warning_preface
  304. )
  305. end
  306. @spec check_uploaders_s3_public_endpoint() :: :ok | :error
  307. def check_uploaders_s3_public_endpoint do
  308. s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
  309. use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
  310. if use_old_config do
  311. Logger.error("""
  312. !!!DEPRECATION WARNING!!!
  313. Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
  314. Please make the following change at your earliest convenience.\n
  315. \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
  316. \n* `config :pleroma, Pleroma.Upload, base_url`
  317. """)
  318. :error
  319. else
  320. :ok
  321. end
  322. end
  323. @spec check_old_chat_shoutbox() :: :ok | :error
  324. def check_old_chat_shoutbox do
  325. instance_config = Pleroma.Config.get([:instance])
  326. chat_config = Pleroma.Config.get([:chat]) || []
  327. use_old_config =
  328. Keyword.has_key?(instance_config, :chat_limit) or
  329. Keyword.has_key?(chat_config, :enabled)
  330. if use_old_config do
  331. Logger.error("""
  332. !!!DEPRECATION WARNING!!!
  333. Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
  334. \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
  335. \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
  336. """)
  337. :error
  338. else
  339. :ok
  340. end
  341. end
  342. end