mirror of
https://github.com/ClaperCo/Claper.git
synced 2026-07-09 20:09:55 +02:00
* Add audit log * Update translation files * Improve Audit queries * Improve Audit.Log schema * Make user auth audit logs async * Relax Flop and Flop Phoenix dep specs * Make Flop.validate!/2 call more robust * Improve a11y and UI for audit log live view * Improve audit_logs indexes * Fix formatting * Fix async_log_action and tests * Add remote_ip * Update translation files
32 lines
838 B
Elixir
32 lines
838 B
Elixir
defmodule ClaperWeb.Helpers.ConnUtils do
|
|
@moduledoc """
|
|
Utility functions for extracting information from Plug.Conn.
|
|
"""
|
|
|
|
@doc """
|
|
Extracts the client IP address from the connection.
|
|
|
|
The `RemoteIp` plug (configured in the endpoint) resolves the real client IP
|
|
by inspecting the headers defined in `REMOTE_IP_HEADERS` and trusting only
|
|
the proxies listed in `REMOTE_IP_PROXIES`, then rewrites `conn.remote_ip`
|
|
before this is called.
|
|
"""
|
|
def get_client_ip(conn) do
|
|
conn.remote_ip |> :inet.ntoa() |> to_string()
|
|
end
|
|
|
|
@doc """
|
|
Extracts the user agent string from the connection.
|
|
|
|
Returns `nil` if no user agent header is present.
|
|
"""
|
|
def get_user_agent(conn) do
|
|
user_agent = Plug.Conn.get_req_header(conn, "user-agent")
|
|
|
|
case user_agent do
|
|
[ua | _] -> ua
|
|
[] -> nil
|
|
end
|
|
end
|
|
end
|