1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.RemoteIp do
7 This is a shim to call [`RemoteIp`](https://git.pleroma.social/pleroma/remote_ip) but with runtime configuration.
16 # https://en.wikipedia.org/wiki/Localhost
17 # https://en.wikipedia.org/wiki/Private_network
30 config = Pleroma.Config.get(__MODULE__, [])
32 if Keyword.get(config, :enabled, false) do
33 RemoteIp.call(conn, remote_ip_opts(config))
39 defp remote_ip_opts(config) do
40 headers = config |> Keyword.get(:headers, @headers) |> MapSet.new()
41 reserved = Keyword.get(config, :reserved, @reserved)
45 |> Keyword.get(:proxies, [])
46 |> Enum.concat(reserved)
47 |> Enum.map(&InetCidr.parse/1)