<% content_for :title, "Create New Rule" %>

Create New Rule

Create a WAF rule to allow, block, or rate limit traffic

<%= 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 :rule_type, "Rule Type", class: "block text-sm font-medium text-gray-700" %> <%= form.select :rule_type, options_for_select(@rule_types.map { |type| [type.humanize, type] }, @rule.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" } %>

Choose the type of rule you want to create

<%= form.label :action, "Action", class: "block text-sm font-medium text-gray-700" %> <%= form.select :action, options_for_select(@actions.map { |action| [action.humanize, action] }, @rule.action), { prompt: "Select 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

<%= 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 :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 || "manual"), { }, { 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.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.check_box :enabled, class: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500" %> <%= form.label :enabled, "Enable immediately", class: "ml-2 block text-sm text-gray-900" %>
<%= link_to "Cancel", rules_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" %> <%= form.submit "Create 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 %>