GameServerWeb.Plugs.IpBan (game_server_web v1.0.938)

Copy Markdown

Plug that blocks requests from banned IP addresses.

Ban entries are stored in a dedicated ETS table (:ip_bans). When a ban exists for the client IP, the request is rejected with 403 Forbidden.

Banning / unbanning an IP

GameServerWeb.Plugs.IpBan.ban("1.2.3.4")                    # permanent
GameServerWeb.Plugs.IpBan.ban("1.2.3.4", :timer.hours(24))  # 24h ban
GameServerWeb.Plugs.IpBan.unban("1.2.3.4")
GameServerWeb.Plugs.IpBan.banned?("1.2.3.4")
GameServerWeb.Plugs.IpBan.list_bans()

This plug runs early in the endpoint pipeline, after RealIp extracts the true client address.

Summary

Functions

Ban an IP address. Pass ttl_ms for a temporary ban (milliseconds) or :infinity (default) for a permanent ban.

Check if an IP is currently banned.

Ensure the ETS tables exist (called once at app startup).

List all currently active bans as [{ip, expires_at}].

Return recent ban/unban log entries as a list of maps, newest first.

Remove a ban for the given IP.

Functions

ban(ip, ttl_ms \\ :infinity)

Ban an IP address. Pass ttl_ms for a temporary ban (milliseconds) or :infinity (default) for a permanent ban.

banned?(ip)

Check if an IP is currently banned.

init_table()

Ensure the ETS tables exist (called once at app startup).

list_bans()

List all currently active bans as [{ip, expires_at}].

list_log()

Return recent ban/unban log entries as a list of maps, newest first.

Each entry: %{action: :ban | :unban, ip: String.t(), ttl: term(), at: DateTime.t()}

unban(ip)

Remove a ban for the given IP.