index.twig 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {% extends 'layout.twig' %}
  2. {% block title %}Allowlist — IRDB{% endblock %}
  3. {% block content %}
  4. {% import 'partials/sort.twig' as sort %}
  5. <div class="mx-auto max-w-5xl">
  6. <div class="flex items-center justify-between">
  7. <h1 class="text-2xl font-semibold tracking-tight">Allowlist</h1>
  8. <span class="text-sm text-slate-500 dark:text-slate-400">{{ list.total|default(0) }} total</span>
  9. </div>
  10. {% set kind_links = [
  11. { label: 'All', value: '' },
  12. { label: 'IPs', value: 'ip' },
  13. { label: 'Subnets', value: 'subnet' },
  14. ] %}
  15. <div class="mt-4 flex gap-2 text-sm">
  16. {% for k in kind_links %}
  17. {% set is_active = (kind|default('') == k.value) or (kind == null and k.value == '') %}
  18. <a href="/app/allowlist{% if k.value %}?kind={{ k.value }}{% endif %}"
  19. class="rounded-full px-3 py-1 {% if is_active %}bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-100{% else %}border border-slate-300 text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800{% endif %}">{{ k.label }}</a>
  20. {% endfor %}
  21. </div>
  22. {% if can_write %}
  23. <section class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900">
  24. <h2 class="text-sm font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">Add allowlist entry</h2>
  25. <form method="post" action="/app/allowlist" class="mt-3 grid grid-cols-1 gap-3 md:grid-cols-3 text-sm" x-data="{ kind: 'ip' }">
  26. <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
  27. <div>
  28. <label for="al-kind" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Kind</label>
  29. <select id="al-kind" name="kind" x-model="kind"
  30. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  31. <option value="ip">Single IP</option>
  32. <option value="subnet">Subnet (CIDR)</option>
  33. </select>
  34. </div>
  35. <div x-show="kind == 'ip'">
  36. <label for="al-ip" class="block text-xs font-medium text-slate-600 dark:text-slate-400">IP</label>
  37. <input type="text" id="al-ip" name="ip" placeholder="203.0.113.5"
  38. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono dark:border-slate-700 dark:bg-slate-950">
  39. </div>
  40. <div x-show="kind == 'subnet'">
  41. <label for="al-cidr" class="block text-xs font-medium text-slate-600 dark:text-slate-400">CIDR</label>
  42. <input type="text" id="al-cidr" name="cidr" placeholder="10.0.0.0/8"
  43. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono dark:border-slate-700 dark:bg-slate-950">
  44. </div>
  45. <div>
  46. <label for="al-reason" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Reason</label>
  47. <input type="text" id="al-reason" name="reason"
  48. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  49. </div>
  50. <div class="md:col-span-3 flex justify-end">
  51. <button type="submit" class="rounded-md bg-emerald-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-emerald-500">Add entry</button>
  52. </div>
  53. </form>
  54. </section>
  55. {% endif %}
  56. <section class="mt-6 overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
  57. <table class="w-full text-sm" data-sortable-table="allowlist-index">
  58. <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">
  59. <tr>
  60. {{ sort.th('Kind', 'kind') }}
  61. {{ sort.th('Target', 'target') }}
  62. {{ sort.th('Reason', 'reason') }}
  63. {{ sort.th('Created', 'created', 'date') }}
  64. {% if can_write %}<th class="px-4 py-2 text-right font-medium">Actions</th>{% endif %}
  65. </tr>
  66. </thead>
  67. <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
  68. {% for item in list.items|default([]) %}
  69. <tr>
  70. <td class="px-4 py-2 font-mono text-xs uppercase" data-sort-value="{{ item.kind }}">{{ item.kind }}</td>
  71. <td class="px-4 py-2 font-mono" data-sort-value="{{ item.kind == 'ip' ? item.ip : item.cidr }}">{{ item.kind == 'ip' ? item.ip : item.cidr }}</td>
  72. <td class="px-4 py-2 text-slate-600 dark:text-slate-300" data-sort-value="{{ item.reason|default('') }}">{{ item.reason|default('—') }}</td>
  73. <td class="px-4 py-2 text-slate-500 dark:text-slate-400" data-sort-value="{{ item.created_at|default('') }}">{% if item.created_at %}<time class="irdb-dt" datetime="{{ item.created_at }}">{{ item.created_at }}</time>{% endif %}</td>
  74. {% if can_write %}
  75. <td class="px-4 py-2 text-right">
  76. {% include 'partials/confirm_form.twig' with {
  77. action: '/app/allowlist/' ~ item.id ~ '/delete',
  78. label: 'Remove',
  79. description: 'This removes the allowlist entry immediately.',
  80. } only %}
  81. </td>
  82. {% endif %}
  83. </tr>
  84. {% else %}
  85. <tr><td colspan="5" class="px-4 py-6 text-center text-slate-400">No allowlist entries.</td></tr>
  86. {% endfor %}
  87. </tbody>
  88. </table>
  89. </section>
  90. </div>
  91. {% endblock %}