diff --git a/config/config.exs b/config/config.exs index 9293656..a225d0f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -45,7 +45,7 @@ config :tailwind, # Configures Elixir's Logger config :logger, :console, format: "$time $metadata[$level] $message\n", - metadata: [:request_id] + metadata: [:remote_ip, :request_id] # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason diff --git a/lib/heimdall_web/controllers/secret_html.ex b/lib/heimdall_web/controllers/secret_html.ex index 77a679f..54b4881 100644 --- a/lib/heimdall_web/controllers/secret_html.ex +++ b/lib/heimdall_web/controllers/secret_html.ex @@ -32,7 +32,7 @@ defmodule HeimdallWeb.SecretHTML do "RSA (public key to encrypt & private key to decrypt)" end - defp remote_ip_to_string({num1, num2, num3, num4}) do - "#{num1}.#{num2}.#{num3}.#{num4}" + defp remote_ip_to_string(remote_ip_tuple) do + remote_ip_tuple |> Tuple.to_list() |> Enum.join(".") end end diff --git a/lib/heimdall_web/router.ex b/lib/heimdall_web/router.ex index 690b2b4..a551fbe 100644 --- a/lib/heimdall_web/router.ex +++ b/lib/heimdall_web/router.ex @@ -8,6 +8,7 @@ defmodule HeimdallWeb.Router do plug :put_root_layout, {HeimdallWeb.Layouts, :root} plug :protect_from_forgery plug :put_secure_browser_headers + plug RemoteIp end pipeline :api do diff --git a/mix.exs b/mix.exs index 407f283..9f019ef 100644 --- a/mix.exs +++ b/mix.exs @@ -49,6 +49,7 @@ defmodule Heimdall.MixProject do {:phoenix_live_view, "~> 0.18.16"}, {:plug_cowboy, "~> 2.5"}, {:postgrex, ">= 0.0.0"}, + {:remote_ip, ">= 0.0.0"}, {:swoosh, "~> 1.3"}, {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev}, {:telemetry_metrics, "~> 0.6"}, diff --git a/mix.lock b/mix.lock index 49aa54c..fd4203a 100644 --- a/mix.lock +++ b/mix.lock @@ -44,6 +44,7 @@ "plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"}, "postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "remote_ip": {:hex, :remote_ip, "1.1.0", "cb308841595d15df3f9073b7c39243a1dd6ca56e5020295cb012c76fbec50f2d", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "616ffdf66aaad6a72fc546dabf42eed87e2a99e97b09cbd92b10cc180d02ed74"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, "swoosh": {:hex, :swoosh, "1.14.0", "710e363e114dedb4080b737e0307f5410887ffc9a239f818231e5618b6b84e1b", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dccfc986ac99c18345ab3e1a8b934b2d817fd6d59a2494f0af78502184c71025"}, "tailwind": {:hex, :tailwind, "0.2.1", "83d8eadbe71a8e8f67861fe7f8d51658ecfb258387123afe4d9dc194eddc36b0", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "e8a13f6107c95f73e58ed1b4221744e1eb5a093cd1da244432067e19c8c9a277"},