acls.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. {% extends "admin/base.html" %}
  2. {% block content %}
  3. <div class="space-y-4 sm:space-y-6">
  4. <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
  5. <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4">
  6. <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de ACLs") }}</h2>
  7. <button onclick="toggleAddForm()" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg transition-colors w-full sm:w-auto">
  8. <i class="fas fa-plus mr-2"></i>{{ _("Agregar ACL") }}
  9. </button>
  10. </div>
  11. <!-- Add ACL Form -->
  12. <div id="addAclForm" class="hidden bg-gray-50 p-4 sm:p-6 rounded-lg mb-6">
  13. <h3 class="text-base sm:text-lg font-semibold mb-4">{{ _("Agregar Nueva ACL") }}</h3>
  14. <form method="POST" action="/admin/acls/add" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
  15. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
  16. <div>
  17. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Nombre:") }}</label>
  18. <input type="text" name="name" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  19. </div>
  20. <div>
  21. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Tipo:") }}</label>
  22. <select name="type" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  23. <option value="src">{{ _("src (IP origen)") }}</option>
  24. <option value="dst">{{ _("dst (IP destino)") }}</option>
  25. <option value="dstdomain">{{ _("dstdomain (Dominio destino)") }}</option>
  26. <option value="port">{{ _("port (Puerto)") }}</option>
  27. <option value="time">{{ _("time (Tiempo)") }}</option>
  28. <option value="method">{{ _("method (Método HTTP)") }}</option>
  29. <option value="proxy_auth">{{ _("proxy_auth (Autenticación)") }}</option>
  30. <option value="maxconn">{{ _("maxconn (Conexiones máximas)") }}</option>
  31. </select>
  32. </div>
  33. <div>
  34. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Valor:") }}</label>
  35. <input type="text" name="value" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  36. </div>
  37. <div class="sm:col-span-2 lg:col-span-3 flex flex-col sm:flex-row gap-2 sm:space-x-4 sm:gap-0">
  38. <button type="submit" class="bg-green-500 hover:bg-green-600 text-white px-6 py-2 rounded-lg transition-colors">
  39. <i class="fas fa-save mr-2"></i>{{ _("Guardar ACL") }}
  40. </button>
  41. <button type="button" onclick="toggleAddForm()" class="bg-gray-500 hover:bg-gray-600 text-white px-6 py-2 rounded-lg transition-colors">
  42. <i class="fas fa-times mr-2"></i>{{ _("Cancelar") }}
  43. </button>
  44. </div>
  45. </form>
  46. </div>
  47. <!-- Edit ACL Form -->
  48. <div id="editAclForm" class="hidden bg-yellow-50 p-4 sm:p-6 rounded-lg mb-6">
  49. <h3 class="text-base sm:text-lg font-semibold mb-4">{{ _("Editar ACL") }}</h3>
  50. <form method="POST" action="/admin/acls/edit" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
  51. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
  52. <input type="hidden" id="editAclId" name="id">
  53. <div>
  54. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Nombre:") }}</label>
  55. <input type="text" id="editName" name="name" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  56. </div>
  57. <div>
  58. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Tipo:") }}</label>
  59. <select id="editType" name="type" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  60. <option value="src">{{ _("src (IP origen)") }}</option>
  61. <option value="dst">{{ _("dst (IP destino)") }}</option>
  62. <option value="dstdomain">{{ _("dstdomain (Dominio destino)") }}</option>
  63. <option value="port">{{ _("port (Puerto)") }}</option>
  64. <option value="time">{{ _("time (Tiempo)") }}</option>
  65. <option value="method">{{ _("method (Método HTTP)") }}</option>
  66. <option value="proxy_auth">{{ _("proxy_auth (Autenticación)") }}</option>
  67. <option value="maxconn">{{ _("maxconn (Conexiones máximas)") }}</option>
  68. </select>
  69. </div>
  70. <div>
  71. <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Valor:") }}</label>
  72. <input type="text" id="editValue" name="value" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
  73. </div>
  74. <div class="md:col-span-3 flex space-x-4">
  75. <button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg transition-colors">
  76. <i class="fas fa-save mr-2"></i>{{ _("Actualizar ACL") }}
  77. </button>
  78. <button type="button" onclick="toggleEditForm()" class="bg-gray-500 hover:bg-gray-600 text-white px-6 py-2 rounded-lg transition-colors">
  79. <i class="fas fa-times mr-2"></i>{{ _("Cancelar") }}
  80. </button>
  81. </div>
  82. </form>
  83. </div>
  84. <!-- ACLs List -->
  85. {% if acls and acls|length > 0 %}
  86. <div class="overflow-x-auto -mx-4 sm:mx-0">
  87. <table class="w-full table-auto">
  88. <thead class="bg-gray-50">
  89. <tr>
  90. <th class="px-2 sm:px-4 lg:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Nombre") }}</th>
  91. <th class="px-2 sm:px-4 lg:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider hidden sm:table-cell">{{ _("Tipo") }}</th>
  92. <th class="px-2 sm:px-4 lg:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Valor") }}</th>
  93. <th class="px-2 sm:px-4 lg:px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Acciones") }}</th>
  94. </tr>
  95. </thead>
  96. <tbody class="bg-white divide-y divide-gray-200">
  97. {% for acl in acls %}
  98. <tr class="hover:bg-gray-50">
  99. <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ acl.name }}</td>
  100. <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
  101. <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800">
  102. {{ acl.type }}
  103. </span>
  104. </td>
  105. <td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">{{ acl.value }}</td>
  106. <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
  107. <button onclick="editAcl('{{ acl.id }}', '{{ acl.name }}', '{{ acl.type }}', '{{ acl.value }}')" class="text-blue-600 hover:text-blue-900 mr-3" title="{{ _("Editar") }}">
  108. <i class="fas fa-edit"></i>
  109. </button>
  110. <button onclick="deleteAcl('{{ acl.id }}', '{{ acl.name }}')" class="text-red-600 hover:text-red-900" title="{{ _("Eliminar") }}">
  111. <i class="fas fa-trash"></i>
  112. </button>
  113. </td>
  114. </tr>
  115. {% endfor %}
  116. </tbody>
  117. </table>
  118. </div>
  119. {% else %}
  120. <div class="text-center py-12 bg-gray-50 rounded-lg border-2 border-dashed border-gray-300">
  121. <i class="fas fa-shield-alt text-6xl text-gray-300 mb-4"></i>
  122. <p class="text-gray-500 text-lg font-medium">{{ _("No hay ACLs configuradas") }}</p>
  123. <p class="text-gray-400 text-sm mt-2">{{ _("Las ACLs son fundamentales para controlar el acceso en Squid") }}</p>
  124. <div class="mt-4 bg-blue-50 border border-blue-200 rounded-lg p-4 max-w-md mx-auto">
  125. <div class="flex items-start">
  126. <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
  127. <div class="text-left text-sm">
  128. <p class="font-semibold text-blue-900 mb-1">{{ _("¿Ya tienes ACLs configuradas?") }}</p>
  129. <p class="text-blue-800 mb-2">{{ _("Si tu squid.conf aún no está dividido, puedes") }} <a href="{{ url_for('admin.split_config') }}" class="underline hover:text-blue-600 font-semibold">{{ _("dividir tu configuración") }}</a> {{ _("para una mejor gestión modular.") }}</p>
  130. <p class="text-blue-800">{{ _("Si ya está dividido, verifica que los archivos estén en el directorio correcto o edítalos directamente desde") }} <a href="{{ url_for('admin.view_config') }}" class="underline hover:text-blue-600 font-semibold">{{ _("Configuración") }}</a>.</p>
  131. </div>
  132. </div>
  133. </div>
  134. <button onclick="toggleAddForm()" class="mt-4 bg-green-500 hover:bg-green-600 text-white px-6 py-2 rounded-lg transition-colors">
  135. <i class="fas fa-plus mr-2"></i>{{ _("Crear primera ACL") }}
  136. </button>
  137. </div>
  138. {% endif %}
  139. </div>
  140. </div>
  141. <script>
  142. function toggleAddForm() {
  143. const form = document.getElementById('addAclForm');
  144. const editForm = document.getElementById('editAclForm');
  145. // Ocultar formulario de edición si está visible
  146. if (!editForm.classList.contains('hidden')) {
  147. editForm.classList.add('hidden');
  148. }
  149. form.classList.toggle('hidden');
  150. }
  151. function toggleEditForm() {
  152. const form = document.getElementById('editAclForm');
  153. const addForm = document.getElementById('addAclForm');
  154. // Ocultar formulario de agregar si está visible
  155. if (!addForm.classList.contains('hidden')) {
  156. addForm.classList.add('hidden');
  157. }
  158. form.classList.toggle('hidden');
  159. }
  160. function editAcl(id, name, type, value) {
  161. // Llenar los campos del formulario de edición
  162. document.getElementById('editAclId').value = id;
  163. document.getElementById('editName').value = name;
  164. document.getElementById('editType').value = type;
  165. document.getElementById('editValue').value = value;
  166. // Mostrar el formulario de edición
  167. const editForm = document.getElementById('editAclForm');
  168. const addForm = document.getElementById('addAclForm');
  169. // Ocultar formulario de agregar si está visible
  170. if (!addForm.classList.contains('hidden')) {
  171. addForm.classList.add('hidden');
  172. }
  173. editForm.classList.remove('hidden');
  174. // Hacer scroll hacia el formulario
  175. editForm.scrollIntoView({ behavior: 'smooth' });
  176. }
  177. function deleteAcl(id, name) {
  178. if (confirm(`¿Estás seguro de que quieres eliminar la ACL "${name}"?`)) {
  179. // Crear un formulario dinámico para enviar la solicitud DELETE
  180. const form = document.createElement('form');
  181. form.method = 'POST';
  182. form.action = '/admin/acls/delete';
  183. const idInput = document.createElement('input');
  184. idInput.type = 'hidden';
  185. idInput.name = 'id';
  186. idInput.value = id;
  187. // Add CSRF token
  188. const csrfInput = document.createElement('input');
  189. csrfInput.type = 'hidden';
  190. csrfInput.name = 'csrf_token';
  191. csrfInput.value = '{{ csrf_token() }}';
  192. form.appendChild(idInput);
  193. form.appendChild(csrfInput);
  194. document.body.appendChild(form);
  195. form.submit();
  196. }
  197. }
  198. </script>
  199. {% endblock %}