1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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.
18 # https://en.wikipedia.org/wiki/Localhost
19 # https://en.wikipedia.org/wiki/Private_network
31 def call(%{remote_ip: original_remote_ip} = conn, _) do
32 config = Pleroma.Config.get(__MODULE__, [])
34 if Keyword.get(config, :enabled, false) do
35 %{remote_ip: new_remote_ip} = conn = RemoteIp.call(conn, remote_ip_opts(config))
36 assign(conn, :remote_ip_found, original_remote_ip != new_remote_ip)
42 defp remote_ip_opts(config) do
43 headers = config |> Keyword.get(:headers, @headers) |> MapSet.new()
44 reserved = Keyword.get(config, :reserved, @reserved)
48 |> Keyword.get(:proxies, [])
49 |> Enum.concat(reserved)
50 |> Enum.map(&InetCidr.parse/1)