| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- {% extends "admin/base.html" %}
- {% block content %}
- <div class="space-y-4 sm:space-y-6">
- <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
- <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4">
- <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de ACLs") }}</h2>
- <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">
- <i class="fas fa-plus mr-2"></i>{{ _("Agregar ACL") }}
- </button>
- </div>
- <!-- Add ACL Form -->
- <div id="addAclForm" class="hidden bg-gray-50 p-4 sm:p-6 rounded-lg mb-6">
- <h3 class="text-base sm:text-lg font-semibold mb-4">{{ _("Agregar Nueva ACL") }}</h3>
- <form method="POST" action="/admin/acls/add" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Nombre:") }}</label>
- <input type="text" name="name" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
- </div>
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Tipo:") }}</label>
- <select name="type" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
- <option value="src">{{ _("src (IP origen)") }}</option>
- <option value="dst">{{ _("dst (IP destino)") }}</option>
- <option value="dstdomain">{{ _("dstdomain (Dominio destino)") }}</option>
- <option value="port">{{ _("port (Puerto)") }}</option>
- <option value="time">{{ _("time (Tiempo)") }}</option>
- <option value="method">{{ _("method (Método HTTP)") }}</option>
- <option value="proxy_auth">{{ _("proxy_auth (Autenticación)") }}</option>
- <option value="maxconn">{{ _("maxconn (Conexiones máximas)") }}</option>
- </select>
- </div>
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Valor:") }}</label>
- <input type="text" name="value" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
- </div>
- <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">
- <button type="submit" class="bg-green-500 hover:bg-green-600 text-white px-6 py-2 rounded-lg transition-colors">
- <i class="fas fa-save mr-2"></i>{{ _("Guardar ACL") }}
- </button>
- <button type="button" onclick="toggleAddForm()" class="bg-gray-500 hover:bg-gray-600 text-white px-6 py-2 rounded-lg transition-colors">
- <i class="fas fa-times mr-2"></i>{{ _("Cancelar") }}
- </button>
- </div>
- </form>
- </div>
- <!-- Edit ACL Form -->
- <div id="editAclForm" class="hidden bg-yellow-50 p-4 sm:p-6 rounded-lg mb-6">
- <h3 class="text-base sm:text-lg font-semibold mb-4">{{ _("Editar ACL") }}</h3>
- <form method="POST" action="/admin/acls/edit" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
- <input type="hidden" id="editAclId" name="id">
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Nombre:") }}</label>
- <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">
- </div>
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Tipo:") }}</label>
- <select id="editType" name="type" required class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
- <option value="src">{{ _("src (IP origen)") }}</option>
- <option value="dst">{{ _("dst (IP destino)") }}</option>
- <option value="dstdomain">{{ _("dstdomain (Dominio destino)") }}</option>
- <option value="port">{{ _("port (Puerto)") }}</option>
- <option value="time">{{ _("time (Tiempo)") }}</option>
- <option value="method">{{ _("method (Método HTTP)") }}</option>
- <option value="proxy_auth">{{ _("proxy_auth (Autenticación)") }}</option>
- <option value="maxconn">{{ _("maxconn (Conexiones máximas)") }}</option>
- </select>
- </div>
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">{{ _("Valor:") }}</label>
- <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">
- </div>
- <div class="md:col-span-3 flex space-x-4">
- <button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg transition-colors">
- <i class="fas fa-save mr-2"></i>{{ _("Actualizar ACL") }}
- </button>
- <button type="button" onclick="toggleEditForm()" class="bg-gray-500 hover:bg-gray-600 text-white px-6 py-2 rounded-lg transition-colors">
- <i class="fas fa-times mr-2"></i>{{ _("Cancelar") }}
- </button>
- </div>
- </form>
- </div>
- <!-- ACLs List -->
- {% if acls and acls|length > 0 %}
- <div class="overflow-x-auto -mx-4 sm:mx-0">
- <table class="w-full table-auto">
- <thead class="bg-gray-50">
- <tr>
- <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>
- <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>
- <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>
- <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>
- </tr>
- </thead>
- <tbody class="bg-white divide-y divide-gray-200">
- {% for acl in acls %}
- <tr class="hover:bg-gray-50">
- <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ acl.name }}</td>
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
- <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800">
- {{ acl.type }}
- </span>
- </td>
- <td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">{{ acl.value }}</td>
- <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
- <button onclick="editAcl('{{ acl.id }}', '{{ acl.name }}', '{{ acl.type }}', '{{ acl.value }}')" class="text-blue-600 hover:text-blue-900 mr-3" title="{{ _("Editar") }}">
- <i class="fas fa-edit"></i>
- </button>
- <button onclick="deleteAcl('{{ acl.id }}', '{{ acl.name }}')" class="text-red-600 hover:text-red-900" title="{{ _("Eliminar") }}">
- <i class="fas fa-trash"></i>
- </button>
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- {% else %}
- <div class="text-center py-12 bg-gray-50 rounded-lg border-2 border-dashed border-gray-300">
- <i class="fas fa-shield-alt text-6xl text-gray-300 mb-4"></i>
- <p class="text-gray-500 text-lg font-medium">{{ _("No hay ACLs configuradas") }}</p>
- <p class="text-gray-400 text-sm mt-2">{{ _("Las ACLs son fundamentales para controlar el acceso en Squid") }}</p>
-
- <div class="mt-4 bg-blue-50 border border-blue-200 rounded-lg p-4 max-w-md mx-auto">
- <div class="flex items-start">
- <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
- <div class="text-left text-sm">
- <p class="font-semibold text-blue-900 mb-1">{{ _("¿Ya tienes ACLs configuradas?") }}</p>
- <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>
- <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>
- </div>
- </div>
- </div>
-
- <button onclick="toggleAddForm()" class="mt-4 bg-green-500 hover:bg-green-600 text-white px-6 py-2 rounded-lg transition-colors">
- <i class="fas fa-plus mr-2"></i>{{ _("Crear primera ACL") }}
- </button>
- </div>
- {% endif %}
- </div>
- </div>
- <script>
- function toggleAddForm() {
- const form = document.getElementById('addAclForm');
- const editForm = document.getElementById('editAclForm');
-
- // Ocultar formulario de edición si está visible
- if (!editForm.classList.contains('hidden')) {
- editForm.classList.add('hidden');
- }
-
- form.classList.toggle('hidden');
- }
- function toggleEditForm() {
- const form = document.getElementById('editAclForm');
- const addForm = document.getElementById('addAclForm');
-
- // Ocultar formulario de agregar si está visible
- if (!addForm.classList.contains('hidden')) {
- addForm.classList.add('hidden');
- }
-
- form.classList.toggle('hidden');
- }
- function editAcl(id, name, type, value) {
- // Llenar los campos del formulario de edición
- document.getElementById('editAclId').value = id;
- document.getElementById('editName').value = name;
- document.getElementById('editType').value = type;
- document.getElementById('editValue').value = value;
-
- // Mostrar el formulario de edición
- const editForm = document.getElementById('editAclForm');
- const addForm = document.getElementById('addAclForm');
-
- // Ocultar formulario de agregar si está visible
- if (!addForm.classList.contains('hidden')) {
- addForm.classList.add('hidden');
- }
-
- editForm.classList.remove('hidden');
-
- // Hacer scroll hacia el formulario
- editForm.scrollIntoView({ behavior: 'smooth' });
- }
- function deleteAcl(id, name) {
- if (confirm(`¿Estás seguro de que quieres eliminar la ACL "${name}"?`)) {
- // Crear un formulario dinámico para enviar la solicitud DELETE
- const form = document.createElement('form');
- form.method = 'POST';
- form.action = '/admin/acls/delete';
-
- const idInput = document.createElement('input');
- idInput.type = 'hidden';
- idInput.name = 'id';
- idInput.value = id;
-
- // Add CSRF token
- const csrfInput = document.createElement('input');
- csrfInput.type = 'hidden';
- csrfInput.name = 'csrf_token';
- csrfInput.value = '{{ csrf_token() }}';
-
- form.appendChild(idInput);
- form.appendChild(csrfInput);
- document.body.appendChild(form);
- form.submit();
- }
- }
- </script>
- {% endblock %}
|