Skip to content

Commit 0c531a9

Browse files
committed
Add support for external email domain blocklist
1 parent 08210f5 commit 0c531a9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

lib/teiserver/moderation/tasks/load_banned_domains_task.ex

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ defmodule Teiserver.Moderation.LoadBannedDomainsTask do
22
@moduledoc """
33
Loads the list of banned domains from the database into the cache.
44
"""
5+
alias Req.Response
56
alias Teiserver.Helpers.CacheHelper
67
alias Teiserver.Moderation
78
alias Teiserver.Moderation.BannedDomain
89

910
def perform do
10-
banned_domains =
11+
url = Config.get_site_config_cache("teiserver.Email domain blocklist URL")
12+
13+
external_banned_domains =
14+
with true <- url != nil and url != "",
15+
{:ok, %Response{status: 200, body: body}} <- Req.get(url) do
16+
String.split(body, "\n")
17+
else
18+
{:error, error} ->
19+
Logger.error("Error loading VPN list - #{inspect(error)}")
20+
[]
21+
22+
_any ->
23+
[]
24+
end
25+
26+
internal_banned_domains =
1127
Moderation.list_banned_domains()
1228
|> Enum.map(fn %BannedDomain{domain: domain} -> domain end)
1329

1430
CacheHelper.store_put(
1531
:application_metadata_cache,
1632
"banned_domains",
17-
banned_domains
33+
external_banned_domains ++ internal_banned_domains
1834
)
1935
end
2036

0 commit comments

Comments
 (0)