<% content_for :title, "Edit WAF Policy" %>

Edit WAF Policy

Modify the firewall policy settings

<%= link_to "← Back to Policy", waf_policy_path(@waf_policy), 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_with(model: @waf_policy, local: true, class: "space-y-6") do |form| %>

📋 Basic Information

<%= form.label :name, class: "block text-sm font-medium text-gray-700" %> <%= form.text_field :name, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "e.g., Block Brazil" %>
<%= form.label :description, "Description", class: "block text-sm font-medium text-gray-700" %> <%= form.text_area :description, rows: 3, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "Explain why this policy is needed..." %>
<%= 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] }, @waf_policy.action), { prompt: "Select action" }, { class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", id: "action-select" } %>
<%= form.check_box :enabled, class: "h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" %> <%= form.label :enabled, "Enable this policy", class: "ml-2 text-sm text-gray-700" %>
<%= form.label :expires_at, "Expires At (optional)", class: "block text-sm font-medium text-gray-700" %> <%= form.datetime_local_field :expires_at, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm" %>

Leave blank for permanent policy

🎯 Targets Configuration

Policy Type: <%= @waf_policy.policy_type.humanize %> <% unless @waf_policy.new_record? %> (Cannot change policy type after creation) <% end %>

<% if @waf_policy.new_record? %>
<%= form.label :policy_type, "Policy Type", class: "block text-sm font-medium text-gray-700" %> <%= form.select :policy_type, options_for_select(@policy_types.map { |type| [type.humanize, type] }, @waf_policy.policy_type), { prompt: "Select policy type" }, { class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", id: "policy-type-select", disabled: !@waf_policy.new_record? } %>
<% else %>
<%= form.label :policy_type, "Policy Type", class: "block text-sm font-medium text-gray-700" %>
<%= @waf_policy.policy_type.humanize %>
<%= form.hidden_field :policy_type %>
<% end %> <% if @waf_policy.country_policy? %>
<%= form.label :targets, "Countries", class: "block text-sm font-medium text-gray-700 mb-2" %>
<%= select_tag "waf_policy[targets][]", options_for_select(@waf_policy.targets.map { |code| [CountryHelper.display_with_flag(code), code] }, @waf_policy.targets), { multiple: true, class: "hidden", data: { "country-selector-target": "select" } } %>
<% end %> <% if @waf_policy.asn_policy? %>
<%= form.label :targets, "ASN Numbers", class: "block text-sm font-medium text-gray-700" %> <%= text_field_tag "waf_policy[targets][]", @waf_policy.targets.join(', '), class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "e.g., 12345, 67890" %>

Enter ASNs separated by commas

<% end %> <% if @waf_policy.company_policy? %>
<%= form.label :targets, "Companies", class: "block text-sm font-medium text-gray-700" %> <%= text_field_tag "waf_policy[targets][]", @waf_policy.targets.join(', '), class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "e.g., AWS, Digital Ocean, Google Cloud" %>

Enter company names separated by commas

<% end %> <% if @waf_policy.network_type_policy? %>
<%= form.label :targets, "Network Types", class: "block text-sm font-medium text-gray-700" %>
<% end %>

⚙️ Additional Configuration

<%= label_tag "additional_data[redirect_url]", "Redirect URL", class: "block text-sm font-medium text-gray-700" %> <%= text_field_tag "additional_data[redirect_url]", @waf_policy.additional_data&.dig('redirect_url'), class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "https://example.com/compliance" %>
<%= label_tag "additional_data[redirect_status]", "HTTP Status", class: "block text-sm font-medium text-gray-700" %> <%= select_tag "additional_data[redirect_status]", options_for_select([["301 Moved Permanently", 301], ["302 Found", 302], ["307 Temporary Redirect", 307]], @waf_policy.additional_data&.dig('redirect_status')), { include_blank: true, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm" } %>
<%= label_tag "additional_data[challenge_type]", "Challenge Type", class: "block text-sm font-medium text-gray-700" %> <%= select_tag "additional_data[challenge_type]", options_for_select([["CAPTCHA", "captcha"], ["JavaScript", "javascript"], ["Proof of Work", "proof_of_work"]], @waf_policy.additional_data&.dig('challenge_type')), { include_blank: true, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm" } %>
<%= label_tag "additional_data[challenge_message]", "Challenge Message", class: "block text-sm font-medium text-gray-700" %> <%= text_area_tag "additional_data[challenge_message]", @waf_policy.additional_data&.dig('challenge_message'), rows: 2, class: "block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm", placeholder: "Please verify you are human to continue..." %>
<%= link_to "Cancel", waf_policy_path(@waf_policy), 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 "Update Policy", 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 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" %>
<% end %>