analytics/lib/plausible_web/plugs/firewall.ex

18 lines
348 B
Elixir
Raw Normal View History

defmodule PlausibleWeb.Firewall do
import Plug.Conn
2020-08-11 13:52:03 +03:00
def init(opts) do
opts
end
2020-08-11 13:52:03 +03:00
def call(conn, _opts) do
blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist)
2020-11-03 12:20:11 +03:00
2020-08-11 13:52:03 +03:00
if PlausibleWeb.RemoteIp.get(conn) in blocklist do
send_resp(conn, 404, "Not found") |> halt
else
conn
end
end
end