Updates
This commit is contained in:
@@ -133,7 +133,7 @@
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-900">
|
||||
<% network_range = @network_ranges_by_ip[event.ip_address.to_s] %>
|
||||
<% network_range = event.network_range %>
|
||||
<% if network_range %>
|
||||
<%= link_to event.ip_address, network_range_path(event.ip_address),
|
||||
class: "text-blue-600 hover:text-blue-800 hover:underline font-mono" %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% content_for :title, "Event #{@event.event_id} - Baffle Hub" %>
|
||||
<% content_for :title, "Event #{@event.request_id} - Baffle Hub" %>
|
||||
|
||||
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8" data-controller="timeline" data-timeline-mode-value="events">
|
||||
<!-- Header -->
|
||||
@@ -15,7 +15,7 @@
|
||||
<svg class="flex-shrink-0 h-5 w-5 text-gray-400" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
<span class="ml-4 text-gray-700 font-medium"><%= @event.event_id %></span>
|
||||
<span class="ml-4 text-gray-700 font-medium"><%= @event.request_id %></span>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -48,8 +48,8 @@
|
||||
<div class="px-6 py-4">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-gray-500">Event ID</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900 font-mono break-all"><%= @event.event_id %></dd>
|
||||
<dt class="text-sm font-medium text-gray-500">Request ID</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900 font-mono break-all"><%= @event.request_id %></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-gray-500">Timestamp</dt>
|
||||
@@ -77,10 +77,17 @@
|
||||
</span>
|
||||
</dd>
|
||||
</div>
|
||||
<% if @event.rule_matched.present? %>
|
||||
<% if @event.rule.present? %>
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-gray-500">Rule Matched</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900"><%= @event.rule_matched %></dd>
|
||||
<dd class="mt-1 text-sm text-gray-900">
|
||||
<%= link_to "Rule ##{@event.rule.id}", @event.rule, class: "text-blue-600 hover:text-blue-800" %>
|
||||
<span class="text-gray-500">(<%= @event.rule.waf_rule_type %>)</span>
|
||||
<% if @event.waf_policy.present? %>
|
||||
<br>
|
||||
<span class="text-xs text-gray-500">Policy: <%= link_to @event.waf_policy.name, @event.waf_policy, class: "text-blue-600 hover:text-blue-800" %></span>
|
||||
<% end %>
|
||||
</dd>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @event.blocked_reason.present? %>
|
||||
|
||||
@@ -251,6 +251,39 @@
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @network_range.persisted? && @network_range.agent_tally.any? %>
|
||||
<div class="border-t border-gray-200 pt-4">
|
||||
<h4 class="text-sm font-medium text-gray-900 mb-2">Top User Agents</h4>
|
||||
<div class="space-y-1">
|
||||
<% @network_range.agent_tally.sort_by { |ua, count| -count }.first(5).each do |user_agent, count| %>
|
||||
<div class="flex justify-between text-sm">
|
||||
<span class="text-gray-600 truncate" title="<%= user_agent %>">
|
||||
<% if user_agent.present? %>
|
||||
<% ua = parse_user_agent(user_agent) %>
|
||||
<% if ua[:name].present? %>
|
||||
<%= ua[:name] %>
|
||||
<% if ua[:version].present? %>
|
||||
<span class="text-gray-400">(<%= ua[:version] %>)</span>
|
||||
<% end %>
|
||||
<% if ua[:bot] %>
|
||||
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs bg-orange-100 text-orange-800 ml-1">
|
||||
🤖 <%= ua[:bot_name] || 'Bot' %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= truncate(user_agent, length: 50) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<em class="text-gray-400">Unknown</em>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="font-medium"><%= count %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -312,15 +345,12 @@
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<!-- Rule Type -->
|
||||
<div>
|
||||
<%= form.label :rule_type, "Rule Type", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.select :rule_type,
|
||||
<%= form.label :waf_rule_type, "Rule Type", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.select :waf_rule_type,
|
||||
options_for_select([
|
||||
['Network - IP/CIDR based blocking', 'network'],
|
||||
['Rate Limit - Request rate limiting', 'rate_limit'],
|
||||
['Path Pattern - URL path filtering', 'path_pattern'],
|
||||
['Header Pattern - HTTP header filtering', 'header_pattern'],
|
||||
['Query Pattern - Query parameter filtering', 'query_pattern'],
|
||||
['Body Signature - Request body filtering', 'body_signature']
|
||||
['Path Pattern - URL path filtering', 'path_pattern']
|
||||
], 'network'),
|
||||
{ },
|
||||
{
|
||||
@@ -333,15 +363,15 @@
|
||||
|
||||
<!-- Action -->
|
||||
<div>
|
||||
<%= form.label :action, "Action", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.select :action,
|
||||
<%= form.label :waf_action, "Action", class: "block text-sm font-medium text-gray-700" %>
|
||||
<%= form.select :waf_action,
|
||||
options_for_select([
|
||||
['Deny - Block requests', 'deny'],
|
||||
['Allow - Whitelist requests', 'allow'],
|
||||
['Rate Limit - Throttle requests', 'rate_limit'],
|
||||
['Redirect - Redirect to URL', 'redirect'],
|
||||
['Challenge - Present CAPTCHA', 'challenge'],
|
||||
['Monitor - Log but allow', 'monitor']
|
||||
['Log - Log but allow', 'log']
|
||||
], 'deny'),
|
||||
{ },
|
||||
{
|
||||
@@ -468,13 +498,13 @@
|
||||
<div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="text-sm font-medium text-gray-900">
|
||||
<%= rule.action.upcase %> <%= rule.cidr %>
|
||||
<%= rule.waf_action.upcase %> <%= rule.cidr %>
|
||||
</span>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
||||
Priority: <%= rule.priority %>
|
||||
</span>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
|
||||
<%= rule.rule_type.humanize %>
|
||||
<%= rule.waf_rule_type.humanize %>
|
||||
</span>
|
||||
<% if rule.source.include?('surgical') %>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800">
|
||||
@@ -523,51 +553,109 @@
|
||||
<!-- Network Relationships -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
|
||||
<!-- Parent Ranges -->
|
||||
<% if @parent_ranges.any? %>
|
||||
<% if @parent_ranges.any? || @supernet_rules.any? %>
|
||||
<div class="bg-white shadow rounded-lg">
|
||||
<div class="px-6 py-4 border-b border-gray-200">
|
||||
<h3 class="text-lg font-medium text-gray-900">Parent Network Ranges</h3>
|
||||
<h3 class="text-lg font-medium text-gray-900">
|
||||
Supernet Ranges
|
||||
<% if @supernet_rules.any? %>
|
||||
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
||||
<%= @supernet_rules.count %> <%= 'rule'.pluralize(@supernet_rules.count) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">Broader networks that contain this range</p>
|
||||
</div>
|
||||
<div class="divide-y divide-gray-200">
|
||||
<% @parent_ranges.each do |parent| %>
|
||||
<div class="px-6 py-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<%= link_to parent.cidr, network_range_path(parent), class: "text-sm font-medium text-gray-900 hover:text-blue-600" %>
|
||||
<div class="text-sm text-gray-500">
|
||||
Prefix: /<%= parent.prefix_length %> |
|
||||
<% if parent.company.present? %><%= parent.company %> | <% end %>
|
||||
<%= parent.source %>
|
||||
</div>
|
||||
<%# Show rules for this parent %>
|
||||
<% parent_rules = @supernet_rules.select { |r| r.network_range_id == parent.id } %>
|
||||
<% if parent_rules.any? %>
|
||||
<div class="mt-2 pl-3 border-l-2 border-blue-200 space-y-1">
|
||||
<% parent_rules.each do |rule| %>
|
||||
<%= render 'rules/compact_rule', rule: rule %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%# Show supernet rules that don't have a parent range loaded %>
|
||||
<% orphan_supernet_rules = @supernet_rules.reject { |r| @parent_ranges.map(&:id).include?(r.network_range_id) } %>
|
||||
<% if orphan_supernet_rules.any? %>
|
||||
<div class="px-6 py-3 bg-gray-50">
|
||||
<div class="text-sm font-medium text-gray-700 mb-2">Additional Supernet Rules</div>
|
||||
<div class="space-y-1">
|
||||
<% orphan_supernet_rules.each do |rule| %>
|
||||
<%= render 'rules/compact_rule', rule: rule %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- Child Ranges -->
|
||||
<% if @child_ranges.any? %>
|
||||
<% if @child_ranges.any? || @subnet_rules.any? %>
|
||||
<div class="bg-white shadow rounded-lg">
|
||||
<div class="px-6 py-4 border-b border-gray-200">
|
||||
<h3 class="text-lg font-medium text-gray-900">Child Network Ranges</h3>
|
||||
<h3 class="text-lg font-medium text-gray-900">
|
||||
Subnet Ranges
|
||||
<% if @subnet_rules.any? %>
|
||||
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
||||
<%= @subnet_rules.count %> <%= 'rule'.pluralize(@subnet_rules.count) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">More specific networks within this range</p>
|
||||
</div>
|
||||
<div class="divide-y divide-gray-200">
|
||||
<% @child_ranges.each do |child| %>
|
||||
<div class="px-6 py-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<%= link_to child.cidr, network_range_path(child), class: "text-sm font-medium text-gray-900 hover:text-blue-600" %>
|
||||
<div class="text-sm text-gray-500">
|
||||
Prefix: /<%= child.prefix_length %> |
|
||||
<% if child.company.present? %><%= child.company %> | <% end %>
|
||||
<%= child.source %>
|
||||
</div>
|
||||
<%# Show rules for this child %>
|
||||
<% child_rules = @subnet_rules.select { |r| r.network_range_id == child.id } %>
|
||||
<% if child_rules.any? %>
|
||||
<div class="mt-2 pl-3 border-l-2 border-green-200 space-y-1">
|
||||
<% child_rules.each do |rule| %>
|
||||
<%= render 'rules/compact_rule', rule: rule %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%# Show subnet rules that don't have a child range loaded %>
|
||||
<% orphan_subnet_rules = @subnet_rules.reject { |r| @child_ranges.map(&:id).include?(r.network_range_id) } %>
|
||||
<% if orphan_subnet_rules.any? %>
|
||||
<div class="px-6 py-3 bg-gray-50">
|
||||
<div class="text-sm font-medium text-gray-700 mb-2">Additional Subnet Rules</div>
|
||||
<div class="space-y-1">
|
||||
<% orphan_subnet_rules.each do |rule| %>
|
||||
<%= render 'rules/compact_rule', rule: rule %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -577,7 +665,20 @@
|
||||
<% if @related_events.any? %>
|
||||
<div class="bg-white shadow rounded-lg" data-controller="timeline" data-timeline-mode-value="events">
|
||||
<div class="px-6 py-4 border-b border-gray-200">
|
||||
<h3 class="text-lg font-medium text-gray-900">Recent Events (<%= @related_events.count %>)</h3>
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-lg font-medium text-gray-900">Recent Events (<%= number_with_delimiter(@events_pagy.count) %>)</h3>
|
||||
<% if @events_pagy.pages > 1 %>
|
||||
<span class="text-sm text-gray-500">
|
||||
Page <%= @events_pagy.page %> of <%= @events_pagy.pages %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<!-- Top Pagination -->
|
||||
<% if @events_pagy.pages > 1 %>
|
||||
<div class="mt-4">
|
||||
<%= pagy_nav_tailwind(@events_pagy, pagy_id: 'network_events_top') %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
@@ -591,7 +692,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
<% @related_events.first(20).each do |event| %>
|
||||
<% @related_events.each do |event| %>
|
||||
<tr class="hover:bg-gray-50 cursor-pointer" onclick="window.location='<%= event_path(event) %>'">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
<div class="text-gray-900" data-timeline-target="timestamp" data-iso="<%= event.timestamp.iso8601 %>">
|
||||
@@ -649,6 +750,11 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Bottom Pagination -->
|
||||
<% if @events_pagy.pages > 1 %>
|
||||
<%= pagy_nav_tailwind(@events_pagy, pagy_id: 'network_events_bottom') %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -44,9 +44,9 @@
|
||||
<div class="px-6 py-4 space-y-6">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<%= 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),
|
||||
<%= 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",
|
||||
@@ -55,9 +55,9 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= 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),
|
||||
<%= 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" } %>
|
||||
<p class="mt-2 text-sm text-gray-500">What action to take when this rule matches</p>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<div class="ml-5 w-0 flex-1">
|
||||
<dl>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Total Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(@rules.count) %></dd>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(Rule.count) %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -42,26 +42,8 @@
|
||||
</div>
|
||||
<div class="ml-5 w-0 flex-1">
|
||||
<dl>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Active Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(@rules.active.count) %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white overflow-hidden shadow rounded-lg">
|
||||
<div class="p-5">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-6 w-6 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-5 w-0 flex-1">
|
||||
<dl>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Block Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(@rules.where(action: 'deny').count) %></dd>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Active Block Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(Rule.deny.active.count) %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,13 +55,31 @@
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-6 w-6 text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636m12.728 12.728L18.364 5.636M5.636 18.364l12.728-12.728" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-5 w-0 flex-1">
|
||||
<dl>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Disabled Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(Rule.where(enabled: false).count) %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white overflow-hidden shadow rounded-lg">
|
||||
<div class="p-5">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-6 w-6 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-5 w-0 flex-1">
|
||||
<dl>
|
||||
<dt class="text-sm font-medium text-gray-500 truncate">Expired Rules</dt>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(@rules.expired.count) %></dd>
|
||||
<dd class="text-lg font-medium text-gray-900"><%= number_with_delimiter(Rule.expired.count) %></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -114,7 +114,7 @@
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Rule</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Type</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Action</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Target</th>
|
||||
<th class="px-6 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Events</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Created</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||
@@ -123,54 +123,77 @@
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
<% @rules.each do |rule| %>
|
||||
<tr class="hover:bg-gray-50">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
<td class="px-6 py-4">
|
||||
<div class="space-y-1">
|
||||
<!-- Rule name -->
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-900">
|
||||
<%= link_to "Rule ##{rule.id}", rule_path(rule), class: "text-blue-600 hover:text-blue-900" %>
|
||||
</div>
|
||||
<div class="text-sm text-gray-500">
|
||||
<%= rule.source.humanize %>
|
||||
<% if rule.network_range? && rule.network_range %>
|
||||
• <%= link_to rule.network_range.cidr, network_range_path(rule.network_range), class: "text-blue-600 hover:text-blue-900" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Policy (if created by a policy) -->
|
||||
<% if rule.waf_policy.present? %>
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">Policy</div>
|
||||
<div class="text-sm">
|
||||
<%= link_to rule.waf_policy.name, waf_policy_path(rule.waf_policy), class: "text-blue-600 hover:text-blue-900" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- IP network -->
|
||||
<% if rule.network_range? && rule.network_range %>
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">IP network</div>
|
||||
<div class="text-sm text-gray-900">
|
||||
<%= link_to rule.network_range.cidr, network_range_path(rule.network_range), class: "text-blue-600 hover:text-blue-900" %>
|
||||
<% if rule.network_range.company.present? %>
|
||||
<div class="text-xs text-gray-500"><%= rule.network_range.company %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif rule.conditions.present? && rule.conditions&.dig('cidr').present? %>
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">IP network</div>
|
||||
<div class="text-sm text-gray-900">
|
||||
<%= rule.conditions['cidr'] %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium <%=
|
||||
case rule.rule_type
|
||||
case rule.waf_rule_type
|
||||
when 'network' then 'bg-blue-100 text-blue-800'
|
||||
when 'rate_limit' then 'bg-yellow-100 text-yellow-800'
|
||||
when 'path_pattern' then 'bg-purple-100 text-purple-800'
|
||||
else 'bg-gray-100 text-gray-800'
|
||||
end %>">
|
||||
<%= rule.rule_type.humanize %>
|
||||
<%= rule.waf_rule_type.humanize %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium <%=
|
||||
case rule.action
|
||||
case rule.waf_action
|
||||
when 'allow' then 'bg-green-100 text-green-800'
|
||||
when 'deny' then 'bg-red-100 text-red-800'
|
||||
when 'rate_limit' then 'bg-yellow-100 text-yellow-800'
|
||||
when 'redirect' then 'bg-indigo-100 text-indigo-800'
|
||||
when 'log' then 'bg-gray-100 text-gray-800'
|
||||
when 'challenge' then 'bg-orange-100 text-orange-800'
|
||||
else 'bg-gray-100 text-gray-800'
|
||||
end %>">
|
||||
<%= rule.action.upcase %>
|
||||
<%= rule.waf_action.upcase %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
<% if rule.network_range? && rule.network_range %>
|
||||
<%= rule.network_range.cidr %>
|
||||
<% if rule.network_range.company.present? %>
|
||||
<div class="text-xs text-gray-500"><%= rule.network_range.company %></div>
|
||||
<% end %>
|
||||
<% elsif rule.conditions.present? %>
|
||||
<div class="max-w-xs truncate">
|
||||
<%= JSON.parse(rule.conditions || "{}").map { |k, v| "#{k}: #{v}" }.join(", ") rescue "Invalid JSON" %>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center">
|
||||
<% event_count = rule.events.count %>
|
||||
<% if event_count > 0 %>
|
||||
<%= link_to number_with_delimiter(event_count), events_path(rule_id: rule.id), class: "text-blue-600 hover:text-blue-900 font-medium" %>
|
||||
<div class="text-xs text-gray-500">
|
||||
<span class="text-red-600"><%= rule.events.where(waf_action: :deny).count %> blocked</span>
|
||||
</div>
|
||||
<% else %>
|
||||
<span class="text-gray-400">-</span>
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
<div class="px-6 py-4 space-y-6">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<%= 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),
|
||||
<%= 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" } %>
|
||||
@@ -50,9 +50,9 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= 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),
|
||||
<%= 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),
|
||||
{ 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" } %>
|
||||
<p class="mt-2 text-sm text-gray-500">What action to take when this rule matches</p>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% content_for :title, "Rule ##{@rule.id} - #{@rule.action.upcase}" %>
|
||||
<% content_for :title, "Rule ##{@rule.id} - #{@rule.waf_action.upcase}" %>
|
||||
|
||||
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
|
||||
<!-- Header -->
|
||||
@@ -23,15 +23,16 @@
|
||||
<div class="mt-2 flex items-center space-x-3">
|
||||
<h1 class="text-3xl font-bold text-gray-900">Rule #<%= @rule.id %></h1>
|
||||
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium <%=
|
||||
case @rule.action
|
||||
case @rule.waf_action
|
||||
when 'allow' then 'bg-green-100 text-green-800'
|
||||
when 'deny' then 'bg-red-100 text-red-800'
|
||||
when 'rate_limit' then 'bg-yellow-100 text-yellow-800'
|
||||
when 'redirect' then 'bg-indigo-100 text-indigo-800'
|
||||
when 'log' then 'bg-gray-100 text-gray-800'
|
||||
when 'challenge' then 'bg-orange-100 text-orange-800'
|
||||
else 'bg-gray-100 text-gray-800'
|
||||
end %>">
|
||||
<%= @rule.action.upcase %>
|
||||
<%= @rule.waf_action.upcase %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,12 +61,12 @@
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-gray-500">Rule Type</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900"><%= @rule.rule_type.humanize %></dd>
|
||||
<dd class="mt-1 text-sm text-gray-900"><%= @rule.waf_rule_type.humanize %></dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-gray-500">Action</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900"><%= @rule.action.upcase %></dd>
|
||||
<dd class="mt-1 text-sm text-gray-900"><%= @rule.waf_action.upcase %></dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -118,6 +119,38 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Event Statistics -->
|
||||
<div class="bg-white shadow rounded-lg mb-6">
|
||||
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
|
||||
<h3 class="text-lg font-medium text-gray-900">Event Statistics</h3>
|
||||
<%= link_to "View Events", events_path(rule_id: @rule.id), class: "text-sm text-blue-600 hover:text-blue-800" %>
|
||||
</div>
|
||||
<div class="px-6 py-4">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div class="bg-blue-50 rounded-lg p-4">
|
||||
<div class="text-sm font-medium text-gray-500">Total Events</div>
|
||||
<div class="mt-2 text-3xl font-bold text-gray-900"><%= @rule.events.count %></div>
|
||||
</div>
|
||||
|
||||
<div class="bg-red-50 rounded-lg p-4">
|
||||
<div class="text-sm font-medium text-gray-500">Blocked Events</div>
|
||||
<div class="mt-2 text-3xl font-bold text-red-900"><%= @rule.events.where(waf_action: :deny).count %></div>
|
||||
</div>
|
||||
|
||||
<div class="bg-green-50 rounded-lg p-4">
|
||||
<div class="text-sm font-medium text-gray-500">Allowed Events</div>
|
||||
<div class="mt-2 text-3xl font-bold text-green-900"><%= @rule.events.where(waf_action: :allow).count %></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @rule.events.any? %>
|
||||
<div class="mt-4 text-sm text-gray-500">
|
||||
Last event: <%= time_ago_in_words(@rule.events.maximum(:timestamp)) %> ago
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Target Information -->
|
||||
<% if @rule.network_rule? && @rule.network_range.present? %>
|
||||
<div class="bg-white shadow rounded-lg mb-6">
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
Rule #<%= rule.id %> - <%= rule.network_range&.cidr || "Unknown" %>
|
||||
</div>
|
||||
<div class="text-sm text-gray-500">
|
||||
<%= rule.action.upcase %> • Created <%= time_ago_in_words(rule.created_at) %> ago
|
||||
<%= rule.waf_action.upcase %> • Created <%= time_ago_in_words(rule.created_at) %> ago
|
||||
<% if rule.redirect_action? %>
|
||||
• Redirect to <%= rule.redirect_url %>
|
||||
<% elsif rule.challenge_action? %>
|
||||
|
||||
Reference in New Issue
Block a user