defmodule PlausibleWeb.Live.Shields.IPRules do @moduledoc """ LiveView allowing IP Rules management """ use PlausibleWeb, :live_component alias PlausibleWeb.Live.Components.PrimaModal alias Plausible.Shields alias Plausible.Shield def update(assigns, socket) do socket = socket |> assign( ip_rules_count: assigns.ip_rules_count, remote_ip: assigns.remote_ip, site: assigns.site, current_user: assigns.current_user, form: new_form() ) |> assign_new(:ip_rules, fn %{site: site} -> Shields.list_ip_rules(site) end) {:ok, socket} end def render(assigns) do ~H"""
Reject incoming traffic from specific IP addresses. <.styled_link href="https://plausible.io/docs/excluding" target="_blank"> Learn more
<.button :if={@ip_rules_count < Shields.maximum_ip_rules()} id="add-ip-rule" phx-click={Prima.Modal.JS.open("ip-rule-form-modal")} > Add IP addressYou've reached the maximum number of IP addresses you can block ({Shields.maximum_ip_rules()}). Please remove one before adding another.
Your current IP address is: <%= @remote_ip %>. <.styled_link phx-target={@myself} phx-click="prefill-own-ip-rule"> Click here to block your own traffic, or enter a custom address below.
<.input data-autofocus field={f[:inet]} label="IP address" placeholder="e.g. 192.168.127.12" />Once added, we will start rejecting traffic from this IP within a few minutes.
<.button type="submit" class="w-full"> Add IP address