analytics/lib/plausible_web/plugs/firewall.ex
2020-11-03 11:20:11 +02:00

18 lines
348 B
Elixir

defmodule PlausibleWeb.Firewall do
import Plug.Conn
def init(opts) do
opts
end
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
end
end
end