index.twig 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {% extends 'layout.twig' %}
  2. {% block title %}Audit — IRDB{% endblock %}
  3. {% macro action_pill(action) %}
  4. {%- set bucket = action|split('.')[0]|default('') -%}
  5. {%- set classes = {
  6. 'reporter': 'bg-blue-100 text-blue-900 dark:bg-blue-900 dark:text-blue-100',
  7. 'consumer': 'bg-cyan-100 text-cyan-900 dark:bg-cyan-900 dark:text-cyan-100',
  8. 'token': 'bg-purple-100 text-purple-900 dark:bg-purple-900 dark:text-purple-100',
  9. 'policy': 'bg-indigo-100 text-indigo-900 dark:bg-indigo-900 dark:text-indigo-100',
  10. 'category': 'bg-violet-100 text-violet-900 dark:bg-violet-900 dark:text-violet-100',
  11. 'manual_block': 'bg-amber-100 text-amber-900 dark:bg-amber-900 dark:text-amber-100',
  12. 'allowlist': 'bg-emerald-100 text-emerald-900 dark:bg-emerald-900 dark:text-emerald-100',
  13. 'job': 'bg-slate-200 text-slate-800 dark:bg-slate-700 dark:text-slate-100',
  14. } -%}
  15. <span class="inline-block rounded px-2 py-0.5 font-mono text-[0.7rem] uppercase tracking-tight {{ classes[bucket]|default('bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300') }}">{{ action }}</span>
  16. {% endmacro %}
  17. {% block content %}
  18. {% import _self as h %}
  19. <div class="mx-auto max-w-6xl">
  20. <div class="flex items-center justify-between">
  21. <h1 class="text-2xl font-semibold tracking-tight">Audit log</h1>
  22. {% if list %}
  23. <span class="text-sm text-slate-500 dark:text-slate-400">{{ list.total }} total</span>
  24. {% endif %}
  25. </div>
  26. {% if error %}
  27. <div class="mt-4 rounded-md border border-red-300 bg-red-50 px-4 py-2 text-sm text-red-800 dark:border-red-800 dark:bg-red-950 dark:text-red-300">{{ error }}</div>
  28. {% endif %}
  29. <form method="get" action="/app/audit" class="mt-4 grid grid-cols-2 gap-3 rounded-2xl border border-slate-200 bg-white p-4 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900 md:grid-cols-7">
  30. <div>
  31. <label for="f-actor-kind" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Actor kind</label>
  32. <select id="f-actor-kind" name="actor_kind" class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-sm dark:border-slate-700 dark:bg-slate-950">
  33. <option value="">— any —</option>
  34. {% for k in allowed_kinds %}
  35. <option value="{{ k }}" {% if filters.actor_kind == k %}selected{% endif %}>{{ k }}</option>
  36. {% endfor %}
  37. </select>
  38. </div>
  39. <div>
  40. <label for="f-actor-id" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Actor id</label>
  41. <input type="number" id="f-actor-id" name="actor_id" min="1" value="{{ filters.actor_id|default('') }}"
  42. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-sm dark:border-slate-700 dark:bg-slate-950">
  43. </div>
  44. <div class="col-span-2">
  45. <label for="f-action" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Action</label>
  46. <select id="f-action" name="action" class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-sm dark:border-slate-700 dark:bg-slate-950">
  47. <option value="">— any —</option>
  48. {% for a in allowed_actions %}
  49. <option value="{{ a }}" {% if filters.action == a %}selected{% endif %}>{{ a }}</option>
  50. {% endfor %}
  51. </select>
  52. </div>
  53. <div>
  54. <label for="f-entity-type" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Entity type</label>
  55. <input type="text" id="f-entity-type" name="entity_type" value="{{ filters.entity_type|default('') }}"
  56. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-sm dark:border-slate-700 dark:bg-slate-950">
  57. </div>
  58. <div>
  59. <label for="f-entity-id" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Entity id</label>
  60. <input type="text" id="f-entity-id" name="entity_id" value="{{ filters.entity_id|default('') }}"
  61. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 text-sm dark:border-slate-700 dark:bg-slate-950">
  62. </div>
  63. <div class="col-span-2 md:col-span-7 grid grid-cols-1 gap-3 md:grid-cols-3 md:items-end">
  64. <div>
  65. <label for="f-from" class="block text-xs font-medium text-slate-600 dark:text-slate-400">From (ISO)</label>
  66. <input type="text" id="f-from" name="from" placeholder="2026-04-01T00:00:00Z" value="{{ filters.from|default('') }}"
  67. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono text-sm dark:border-slate-700 dark:bg-slate-950">
  68. </div>
  69. <div>
  70. <label for="f-to" class="block text-xs font-medium text-slate-600 dark:text-slate-400">To (ISO)</label>
  71. <input type="text" id="f-to" name="to" placeholder="2026-04-30T23:59:59Z" value="{{ filters.to|default('') }}"
  72. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono text-sm dark:border-slate-700 dark:bg-slate-950">
  73. </div>
  74. <div class="flex justify-end gap-2">
  75. <a href="/app/audit" class="rounded-md border border-slate-300 px-3 py-1.5 text-sm hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">Reset</a>
  76. <button type="submit" class="rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-500">Filter</button>
  77. </div>
  78. </div>
  79. </form>
  80. {% if list %}
  81. <div class="mt-6 overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900" x-data="{ open: null }">
  82. <table class="w-full text-sm">
  83. <thead class="border-b border-slate-200 bg-slate-50 text-left text-xs uppercase tracking-wider text-slate-500 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-400">
  84. <tr>
  85. <th class="px-4 py-2 font-medium">When</th>
  86. <th class="px-4 py-2 font-medium">Actor</th>
  87. <th class="px-4 py-2 font-medium">Action</th>
  88. <th class="px-4 py-2 font-medium">Entity</th>
  89. <th class="px-4 py-2 font-medium">Source IP</th>
  90. <th class="px-4 py-2 font-medium text-right">Payload</th>
  91. </tr>
  92. </thead>
  93. <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
  94. {% for ev in list.items %}
  95. <tr>
  96. <td class="px-4 py-2 align-top"><time class="irdb-dt font-mono text-xs text-slate-600 dark:text-slate-300" datetime="{{ ev.occurred_at }}" title="{{ ev.occurred_at }}">{{ ev.occurred_at }}</time></td>
  97. <td class="px-4 py-2 align-top text-xs">
  98. <span class="rounded bg-slate-100 px-1.5 py-0.5 font-mono uppercase tracking-tight text-slate-700 dark:bg-slate-800 dark:text-slate-300">{{ ev.actor_kind }}</span>
  99. {% if ev.actor_id %}<span class="ml-1 font-mono text-slate-500">#{{ ev.actor_id }}</span>{% endif %}
  100. </td>
  101. <td class="px-4 py-2 align-top">{{ h.action_pill(ev.action) }}</td>
  102. <td class="px-4 py-2 align-top text-xs">
  103. <span class="font-mono text-slate-600 dark:text-slate-300">{{ ev.entity_type|default('—') }}</span>
  104. {% if ev.entity_id %}<span class="ml-1 font-mono text-slate-500">#{{ ev.entity_id }}</span>{% endif %}
  105. </td>
  106. <td class="px-4 py-2 align-top font-mono text-xs text-slate-500">{{ ev.source_ip|default('—') }}</td>
  107. <td class="px-4 py-2 align-top text-right">
  108. {% if ev.details %}
  109. <button type="button" x-on:click="open = (open === {{ ev.id }} ? null : {{ ev.id }})" class="rounded border border-slate-300 px-2 py-0.5 text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">View</button>
  110. {% else %}
  111. <span class="text-xs text-slate-400">—</span>
  112. {% endif %}
  113. </td>
  114. </tr>
  115. {% if ev.details %}
  116. <tr x-show="open === {{ ev.id }}" x-cloak>
  117. <td colspan="6" class="bg-slate-50 px-4 py-3 dark:bg-slate-950">
  118. <pre class="overflow-x-auto rounded bg-white p-3 text-xs dark:bg-slate-900">{{ ev.details|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  119. </td>
  120. </tr>
  121. {% endif %}
  122. {% else %}
  123. <tr><td colspan="6" class="px-4 py-6 text-center text-slate-400">No events match these filters.</td></tr>
  124. {% endfor %}
  125. </tbody>
  126. </table>
  127. </div>
  128. {% if list.total > list.page_size %}
  129. {% set total_pages = (list.total // list.page_size) + (list.total % list.page_size > 0 ? 1 : 0) %}
  130. <nav class="mt-4 flex items-center justify-between text-sm">
  131. <span class="text-slate-500 dark:text-slate-400">Page {{ page }} of {{ total_pages }}</span>
  132. <div class="flex gap-2">
  133. {% set prev_qs = filters|merge({'page': page - 1}) %}
  134. {% set next_qs = filters|merge({'page': page + 1}) %}
  135. {% if page > 1 %}
  136. <a href="/app/audit?{{ prev_qs|url_encode }}" class="rounded-md border border-slate-300 px-3 py-1.5 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">‹ Prev</a>
  137. {% endif %}
  138. {% if page < total_pages %}
  139. <a href="/app/audit?{{ next_qs|url_encode }}" class="rounded-md border border-slate-300 px-3 py-1.5 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">Next ›</a>
  140. {% endif %}
  141. </div>
  142. </nav>
  143. {% endif %}
  144. {% endif %}
  145. </div>
  146. {% endblock %}