<% content_for :title, "Edit Rule ##{@rule.id}" %>

Edit Rule #<%= @rule.id %>

Modify the WAF rule configuration

<%= form_with(model: @rule, local: true, class: "space-y-6") do |form| %> <% if @rule.errors.any? %>

There were <%= pluralize(@rule.errors.count, "error") %> with your submission:

    <% @rule.errors.full_messages.each do |message| %>
  • <%= message %>
  • <% end %>
<% end %>

Rule Configuration

<%= form.label :waf_rule_type, "Rule Type", class: "block text-sm font-medium text-gray-700" %> <%= form.select :waf_rule_type, options_for_select(@waf_rule_types.map { |type, _| [type.humanize, type] }, @rule.waf_rule_type), { prompt: "Select rule type" }, { class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", id: "rule_type_select", disabled: true } %>

Rule type cannot be changed after creation

<%= form.label :waf_action, "Action", class: "block text-sm font-medium text-gray-700" %> <%= form.select :waf_action, options_for_select(@waf_actions.map { |action, _| [action.humanize, action] }, @rule.waf_action), { }, { class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" } %>

What action to take when this rule matches

<% if @rule.network_rule? %>
<%= form.label :network_range_id, "Network Range", class: "block text-sm font-medium text-gray-700" %> <%= form.select :network_range_id, options_from_collection_for_select(NetworkRange.order(:network).limit(100), :id, :cidr, @rule.network_range_id), { prompt: "Select a network range" }, { class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" } %>

Select from recent network ranges or create new ones

<%= link_to "Create New Network Range", new_network_range_path, class: "inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50" %>
<% if @rule.network_range.present? %>

Currently targeting: <%= link_to @rule.network_range.cidr, network_range_path(@rule.network_range), class: "text-blue-600 hover:text-blue-900 underline" %> <% if @rule.network_range.company.present? %> - <%= @rule.network_range.company %> <% end %>

<% end %>
<% end %> <% unless @rule.network_rule? %>
<%= form.label :conditions, "Conditions", class: "block text-sm font-medium text-gray-700" %> <%= form.text_area :conditions, rows: 4, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: '{"path_pattern": "/admin/*", "user_agent": "bot*"}' %>

JSON format with matching conditions

<% end %>
<%= form.label :metadata, "Metadata", class: "block text-sm font-medium text-gray-700" %>
<%= form.text_area :metadata, rows: 3, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: '{"reason": "Suspicious activity detected", "source": "manual"}', data: { json_validator_target: "textarea", action: "input->json-validator#validate" } %>

JSON format with additional metadata

<%= form.label :expires_at, "Expires At", class: "block text-sm font-medium text-gray-700" %> <%= form.datetime_local_field :expires_at, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" %>

Leave blank for permanent rule

<%= form.label :source, "Source", class: "block text-sm font-medium text-gray-700" %> <%= form.select :source, options_for_select(Rule::SOURCES.map { |source| [source.humanize, source] }, @rule.source), { }, { class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" } %>

How this rule was created

<%= form.check_box :enabled, class: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500" %> <%= form.label :enabled, "Rule Enabled", class: "ml-2 block text-sm text-gray-900" %>
<%= link_to "Cancel", @rule, class: "inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50" %>
<%= link_to "Delete Rule", @rule, method: :delete, data: { confirm: "Are you sure you want to delete this rule? This action cannot be undone." }, class: "inline-flex items-center px-4 py-2 border border-red-300 rounded-md shadow-sm text-sm font-medium text-red-700 bg-red-50 hover:bg-red-100" %> <%= form.submit "Update Rule", class: "inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700" %>
<% end %>