Fix configuration for firewall

This commit is contained in:
Uku Taht 2020-08-11 13:52:03 +03:00
parent 2e1904e5f0
commit 74b74a271e
3 changed files with 7 additions and 10 deletions

View File

@ -182,7 +182,7 @@ config :plausible, :custom_domain_server,
ip: System.get_env("CUSTOM_DOMAIN_SERVER_IP")
config :plausible, PlausibleWeb.Firewall,
blocklist: System.get_env("IP_BLOCKLIST", "")
blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1)
config :geolix,
databases: [

View File

@ -148,7 +148,7 @@ config :plausible, :custom_domain_server,
ip: custom_domain_server_ip
config :plausible, PlausibleWeb.Firewall,
blocklist: System.get_env("IP_BLOCKLIST", "")
blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1)
base_cron = [
# Daily at midnight

View File

@ -1,16 +1,13 @@
defmodule PlausibleWeb.Firewall do
import Plug.Conn
def init(options) do
blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist)
|> String.split(",")
|> Enum.map(&String.trim/1)
Keyword.merge(options, blocklist: blocklist)
def init(opts) do
opts
end
def call(conn, opts) do
if PlausibleWeb.RemoteIp.get(conn) in opts[:blocklist] do
def call(conn, _opts) do
blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist)
if PlausibleWeb.RemoteIp.get(conn) in blocklist do
send_resp(conn, 404, "Not found") |> halt
else
conn