| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- {% extends "admin/base.html" %}
- {% block content %}
- <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
- <div class="flex justify-between items-center mb-4 sm:mb-6">
- <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de Delay Pools") }}</h2>
- <button onclick="showAddModal()" class="bg-blue-600 hover:bg-blue-700 text-white font-semibold px-4 py-2 rounded-lg shadow-md transition-colors">
- <i class="fas fa-plus mr-2"></i>{{ _("Agregar Pool") }}
- </button>
- </div>
-
- <!-- RC -->
- <div class="mb-6 bg-red-50 border-2 border-red-300 rounded-lg p-6 flex items-start space-x-4">
- <i class="fas fa-exclamation-triangle text-red-600 text-3xl mt-1 animate-pulse"></i>
- <div class="flex-1">
- <p class="font-bold text-red-800 text-lg">{{ _("¡MUY IMPORTANTE!") }}</p>
- <p class="text-red-700 mt-2 font-medium">
- {{ _("Esta funcionalidad se encuentra en") }} <strong>{{ _("RC") }}</strong>. Puede contener errores y comportamientos inesperados.
- </p>
- <p class="text-red-700 mt-2">
- <strong>{{ _("Por favor, no la uses en producción de momento. Úsala únicamente en un entorno de prueba.") }}</strong>
- </p>
- </div>
- </div>
-
- <!-- Delay Pools Info -->
- <div class="mb-4 bg-blue-50 border border-blue-200 rounded-lg p-4">
- <div class="flex items-start">
- <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
- <div class="text-sm text-gray-700">
- <p class="font-semibold text-gray-800 mb-1">{{ _("¿Qué son los Delay Pools?") }}</p>
- <p class="mb-2">{{ _("Los delay pools permiten limitar el ancho de banda de ciertas solicitudes basadas en criterios específicos, proporcionando un control justo del tráfico.") }}</p>
- <p class="font-semibold text-gray-800 mb-1">{{ _("Clases disponibles:") }}</p>
- <ul class="list-disc list-inside space-y-1 ml-2 mb-2">
- <li><strong>{{ _("Clase 1:") }}</strong> {{ _("Un solo bucket agregado para todos los clientes") }}</li>
- <li><strong>{{ _("Clase 2:") }}</strong> {{ _("Bucket agregado + buckets individuales por host (/24)") }}</li>
- <li><strong>{{ _("Clase 3:") }}</strong> {{ _("Buckets por subred + buckets individuales por host (/16)") }}</li>
- <li><strong>{{ _("Clase 4:") }}</strong> {{ _("Como clase 3 + buckets por usuario autenticado") }}</li>
- <li><strong>{{ _("Clase 5:") }}</strong> {{ _("Basado en tags de external_acl_type") }}</li>
- </ul>
- <p class="font-semibold text-gray-800 mb-1">{{ _("Limitaciones importantes:") }}</p>
- <ul class="list-disc list-inside space-y-1 ml-2">
- <li>{{ _("No limita overheads como TCP, ICP, DNS, etc.") }}</li>
- <li>{{ _("Incompatible con slow aborts; usa quick abort bajo") }}</li>
- <li>{{ _("Una conexión puede tomar todo el ancho de banda de un bucket") }}</li>
- <li>{{ _("En Squid") }} < 3.1, buckets limitados a 32-bits</li>
- </ul>
- </div>
- </div>
- </div>
-
- {% if delay_pools %}
- <div class="space-y-4 sm:space-y-6">
- {% for pool in delay_pools %}
- <div class="border border-gray-200 rounded-lg p-4 sm:p-6 bg-gradient-to-br from-white to-gray-50">
- <div class="flex justify-between items-start mb-4">
- <div class="flex-1">
- <div class="flex items-center mb-2">
- <h3 class="text-xl font-bold text-gray-800">{{ _("Pool #") }}{{ pool.pool_number }}</h3>
- <span class="ml-3 bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded">
- {{ _("Clase") }} {{ pool.class }}
- </span>
- </div>
- <p class="text-sm text-gray-600">
- {% if pool.class == '1' %}
- <i class="fas fa-stream mr-1"></i> {{ _("Bucket único agregado para todos los clientes") }}
- {% elif pool.class == '2' %}
- <i class="fas fa-network-wired mr-1"></i> {{ _("Bucket agregado + 255 buckets por host (red /24)") }}
- {% elif pool.class == '3' %}
- <i class="fas fa-sitemap mr-1"></i> {{ _("Buckets por subred + buckets por host (red /16)") }}
- {% elif pool.class == '4' %}
- <i class="fas fa-users mr-1"></i> {{ _("Como clase 3 + buckets por usuario autenticado") }}
- {% elif pool.class == '5' %}
- <i class="fas fa-tags mr-1"></i> {{ _("Buckets basados en tags de external_acl_type") }}
- {% endif %}
- </p>
- </div>
- <div class="flex space-x-2">
- <button onclick='editPool({{ pool.pool_number }}, "{{ pool.class }}", "{{ pool.parameters }}", {{ pool.access_rules|tojson }})'
- class="text-blue-600 hover:text-blue-900 p-2" title="{{ _("Editar") }}">
- <i class="fas fa-edit text-lg"></i>
- </button>
- <button onclick="deletePool('{{ pool.pool_number }}')"
- class="text-red-600 hover:text-red-900 p-2" title="{{ _("Eliminar") }}">
- <i class="fas fa-trash text-lg"></i>
- </button>
- </div>
- </div>
-
- {% if pool.parameters %}
- <div class="bg-gray-50 rounded-lg p-4 mb-4 border border-gray-200">
- <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
- <i class="fas fa-tachometer-alt mr-2 text-blue-600"></i> {{ _("Parámetros de Velocidad:") }}
- </h4>
- <div class="font-mono text-sm text-gray-700 bg-white p-3 rounded border border-gray-300">
- {{ pool.parameters }}
- </div>
- <div class="mt-2 text-xs text-gray-600">
- {% set params = pool.parameters.split() %}
- {% if pool.class == '1' %}
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
- {% elif pool.class == '2' %}
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Individual (por host):") }} {{ params[1] if params|length > 1 }}</span>
- {% elif pool.class in ['3', '4'] %}
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Red:") }} {{ params[1] if params|length > 1 }}</span>
- <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Individual (por host):") }} {{ params[2] if params|length > 2 }}</span>
- {% endif %}
- <p class="mt-1 italic">{{ _("Formato: restore/max (bytes por segundo)") }}</p>
- </div>
- </div>
- {% endif %}
-
- {% if pool.access_rules %}
- <div class="bg-blue-50 rounded-lg p-4 border border-blue-200">
- <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
- <i class="fas fa-shield-alt mr-2 text-blue-600"></i> {{ _("Reglas de Acceso:") }}
- </h4>
- <div class="space-y-2">
- {% for rule in pool.access_rules %}
- <div class="flex items-center bg-white p-2 rounded border border-gray-200">
- {% if rule.action == 'allow' %}
- <span class="bg-green-100 text-green-800 text-xs font-semibold px-2 py-1 rounded mr-2">{{ _("ALLOW") }}</span>
- {% else %}
- <span class="bg-red-100 text-red-800 text-xs font-semibold px-2 py-1 rounded mr-2">{{ _("DENY") }}</span>
- {% endif %}
- <span class="text-sm text-gray-700 font-mono">{{ rule.acl }}</span>
- </div>
- {% endfor %}
- </div>
- </div>
- {% endif %}
- </div>
- {% endfor %}
- </div>
- {% else %}
- {% if not authenticated %}
- <div class="text-center py-12">
- <i class="fas fa-user-lock text-6xl text-gray-300 mb-4"></i>
- <p class="text-gray-500 text-lg">{{ _("Para ver los delay pools debes iniciar sesión.") }}</p>
- <p class="text-gray-500 mt-2">{{ _("Inicia sesión con una cuenta de administrador para acceder a esta sección.") }}</p>
- <a href="{{ url_for('auth.login') }}" class="mt-4 inline-flex items-center justify-center bg-blue-600 hover:bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg shadow-md transition-colors">
- <i class="fas fa-sign-in-alt mr-2"></i> {{ _("Iniciar sesión") }}
- </a>
- </div>
- {% else %}
- <div class="text-center py-12">
- <i class="fas fa-clock text-6xl text-gray-300 mb-4"></i>
- <p class="text-gray-500 text-lg">{{ _("No hay delay pools configurados") }}</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 delay pools configurados?") }}</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="showAddModal()" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white font-semibold px-6 py-2 rounded-lg shadow-md transition-colors">
- <i class="fas fa-plus mr-2"></i>{{ _("Crear primer Pool") }}
- </button>
- </div>
- {% endif %}
- {% endif %}
- </div>
- <!-- Add Modal -->
- <div id="addModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
- <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
- <h3 class="text-2xl font-bold text-gray-800 mb-4">
- <i class="fas fa-plus-circle text-blue-600 mr-2"></i>{{ _("Agregar Nuevo Delay Pool") }}
- </h3>
- <form id="addForm" method="POST" action="/admin/delay-pools/add">
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Número de Pool:") }}</label>
- <input type="number" name="pool_number" id="addPoolNumber" min="1" max="255"
- class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
- required placeholder="1">
- <p class="text-xs text-gray-500 mt-1">{{ _("Número único del pool (1-255)") }}</p>
- </div>
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Clase de Pool:") }}</label>
- <select name="pool_class" id="addPoolClass" onchange="updateParametersHelp('add')"
- class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
- <option value="">{{ _("Seleccione una clase...") }}</option>
- <option value="1">{{ _("Clase 1 - Bucket único agregado") }}</option>
- <option value="2">{{ _("Clase 2 - Agregado + por host (/24)") }}</option>
- <option value="3">{{ _("Clase 3 - Agregado + red + por host (/16)") }}</option>
- <option value="4">{{ _("Clase 4 - Como clase 3 + por usuario") }}</option>
- <option value="5">{{ _("Clase 5 - Basado en tags") }}</option>
- </select>
- </div>
-
- <div id="addParametersSection" class="mb-4 hidden">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Parámetros de Velocidad:") }}</label>
-
- <!-- Clase 1 -->
- <div id="addClass1Params" class="hidden space-y-3">
- <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
- <strong>{{ _("Clase 1:") }}</strong> {{ _("Un solo bucket agregado para todos los clientes") }}
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max en bytes/seg):") }}</label>
- <input type="text" id="addAggregateClass1" placeholder="64000/64000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- <p class="text-xs text-gray-500 mt-1">{{ _("Ej: 64000/64000 = 512 Kbps") }}</p>
- </div>
- </div>
-
- <!-- Clase 2 -->
- <div id="addClass2Params" class="hidden space-y-3">
- <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
- <strong>{{ _("Clase 2:") }}</strong> {{ _("Bucket agregado + 255 buckets individuales por host") }}
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max):") }}</label>
- <input type="text" id="addAggregateClass2" placeholder="64000/64000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Individual por host (restore/max):") }}</label>
- <input type="text" id="addIndividualClass2" placeholder="16000/64000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- <p class="text-xs text-gray-500 mt-1">{{ _("Usa -1/-1 para deshabilitar este bucket") }}</p>
- </div>
- </div>
-
- <!-- Clase 3/4 -->
- <div id="addClass3Params" class="hidden space-y-3">
- <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
- <strong id="addClass3Title">{{ _("Clase 3:") }}</strong> <span id="addClass3Desc">{{ _("Buckets por subred + por host") }}</span>
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max):") }}</label>
- <input type="text" id="addAggregateClass3" placeholder="64000/64000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Por red (restore/max):") }}</label>
- <input type="text" id="addNetworkClass3" placeholder="8000/64000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- <p class="text-xs text-gray-500 mt-1">{{ _("Usa -1/-1 para deshabilitar") }}</p>
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Individual por host (restore/max):") }}</label>
- <input type="text" id="addIndividualClass3" placeholder="2000/16000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- </div>
- </div>
-
- <!-- Clase 5 -->
- <div id="addClass5Params" class="hidden space-y-3">
- <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
- <strong>{{ _("Clase 5:") }}</strong> {{ _("Basado en tags de external_acl_type (un bucket por tag)") }}
- </div>
- <div>
- <label class="text-sm font-medium text-gray-700">{{ _("Parámetros por tag (restore/max):") }}</label>
- <input type="text" id="addTagClass5" placeholder="16000/32000"
- class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- </div>
- </div>
- </div>
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Reglas de Acceso (ACLs):") }}</label>
- <div id="addAccessRules" class="space-y-2">
- <!-- Las reglas se agregarán dinámicamente -->
- </div>
- <button type="button" onclick="addAccessRule('add')"
- class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
- <i class="fas fa-plus-circle mr-1"></i>{{ _("Agregar regla de acceso") }}
- </button>
- </div>
-
- <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
- <button type="button" onclick="closeAddModal()"
- class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
- {{ _("Cancelar") }}
- </button>
- <button type="submit"
- class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
- <i class="fas fa-save mr-2"></i>{{ _("Crear Pool") }}
- </button>
- </div>
- </form>
- </div>
- </div>
- <!-- Edit Modal -->
- <div id="editModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
- <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
- <h3 class="text-2xl font-bold text-gray-800 mb-4">
- <i class="fas fa-edit text-blue-600 mr-2"></i>{{ _("Editar Delay Pool") }}
- </h3>
- <form id="editForm" method="POST" action="/admin/delay-pools/edit">
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
- <input type="hidden" name="pool_number" id="editPoolNumber">
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Número de Pool:") }}</label>
- <input type="text" id="editPoolNumberDisplay" disabled
- class="w-full px-4 py-2 border border-gray-300 rounded-lg bg-gray-100 text-gray-600">
- </div>
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Clase de Pool:") }}</label>
- <select name="pool_class" id="editPoolClass" onchange="updateParametersHelp('edit')"
- class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
- <option value="1">{{ _("Clase 1 - Bucket único agregado") }}</option>
- <option value="2">{{ _("Clase 2 - Agregado + por host (/24)") }}</option>
- <option value="3">{{ _("Clase 3 - Agregado + red + por host (/16)") }}</option>
- <option value="4">{{ _("Clase 4 - Como clase 3 + por usuario") }}</option>
- <option value="5">{{ _("Clase 5 - Basado en tags") }}</option>
- </select>
- </div>
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Parámetros:") }}</label>
- <textarea name="parameters" id="editParameters" rows="2"
- class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono text-sm"
- required placeholder="64000/64000 -1/-1 16000/64000"></textarea>
- <p class="text-xs text-gray-500 mt-1" id="editParametersHelp">{{ _("Formato: restore/max (bytes/seg)") }}</p>
- </div>
-
- <div class="mb-4">
- <label class="block text-gray-700 font-semibold mb-2">{{ _("Reglas de Acceso:") }}</label>
- <div id="editAccessRules" class="space-y-2">
- <!-- Se llenarán dinámicamente -->
- </div>
- <button type="button" onclick="addAccessRule('edit')"
- class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
- <i class="fas fa-plus-circle mr-1"></i>{{ _("Agregar regla de acceso") }}
- </button>
- </div>
-
- <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
- <button type="button" onclick="closeEditModal()"
- class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
- {{ _("Cancelar") }}
- </button>
- <button type="submit"
- class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
- <i class="fas fa-save mr-2"></i>{{ _("Guardar Cambios") }}
- </button>
- </div>
- </form>
- </div>
- </div>
- <script>
- let addAccessRuleCounter = 0;
- let editAccessRuleCounter = 0;
- function showAddModal() {
- document.getElementById('addModal').classList.remove('hidden');
- document.getElementById('addForm').reset();
- document.getElementById('addAccessRules').innerHTML = '';
- document.getElementById('addParametersSection').classList.add('hidden');
- addAccessRuleCounter = 0;
- }
- function closeAddModal() {
- document.getElementById('addModal').classList.add('hidden');
- }
- function editPool(poolNumber, poolClass, parameters, accessRules) {
- document.getElementById('editPoolNumber').value = poolNumber;
- document.getElementById('editPoolNumberDisplay').value = 'Pool #' + poolNumber;
- document.getElementById('editPoolClass').value = poolClass;
- document.getElementById('editParameters').value = parameters || '';
-
- // Update parameters help text
- updateParametersHelp('edit');
-
- // Fill access rules
- const rulesContainer = document.getElementById('editAccessRules');
- rulesContainer.innerHTML = '';
- editAccessRuleCounter = 0;
-
- if (accessRules && accessRules.length > 0) {
- accessRules.forEach(rule => {
- addAccessRule('edit', rule.action, rule.acl);
- });
- }
-
- document.getElementById('editModal').classList.remove('hidden');
- }
- function closeEditModal() {
- document.getElementById('editModal').classList.add('hidden');
- }
- function updateParametersHelp(mode) {
- const classSelect = document.getElementById(mode + 'PoolClass');
- const selectedClass = classSelect.value;
-
- if (mode === 'add') {
- // Hide all parameter sections
- document.querySelectorAll('[id^="addClass"]').forEach(el => {
- if (el.id.includes('Params')) el.classList.add('hidden');
- });
-
- // Show parameters section
- const paramsSection = document.getElementById('addParametersSection');
- if (selectedClass) {
- paramsSection.classList.remove('hidden');
-
- // Show specific class parameters
- if (selectedClass === '1') {
- document.getElementById('addClass1Params').classList.remove('hidden');
- } else if (selectedClass === '2') {
- document.getElementById('addClass2Params').classList.remove('hidden');
- } else if (selectedClass === '3' || selectedClass === '4') {
- document.getElementById('addClass3Params').classList.remove('hidden');
- if (selectedClass === '4') {
- document.getElementById('addClass3Title').textContent = 'Clase 4:';
- document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host + por usuario autenticado';
- } else {
- document.getElementById('addClass3Title').textContent = 'Clase 3:';
- document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host';
- }
- } else if (selectedClass === '5') {
- document.getElementById('addClass5Params').classList.remove('hidden');
- }
- } else {
- paramsSection.classList.add('hidden');
- }
- } else {
- // Update edit help text
- const helpText = document.getElementById('editParametersHelp');
- if (selectedClass === '1') {
- helpText.textContent = 'Formato: aggregate_restore/aggregate_max';
- } else if (selectedClass === '2') {
- helpText.textContent = 'Formato: aggregate_restore/aggregate_max individual_restore/individual_max';
- } else if (selectedClass === '3' || selectedClass === '4') {
- helpText.textContent = 'Formato: aggregate_restore/aggregate_max network_restore/network_max individual_restore/individual_max';
- } else if (selectedClass === '5') {
- helpText.textContent = 'Formato: tag_restore/tag_max';
- }
- }
- }
- function addAccessRule(mode, action = 'allow', acl = '') {
- const container = document.getElementById(mode + 'AccessRules');
- const counter = mode === 'add' ? addAccessRuleCounter++ : editAccessRuleCounter++;
-
- const ruleDiv = document.createElement('div');
- ruleDiv.className = 'flex items-center space-x-2 bg-gray-50 p-2 rounded border border-gray-200';
- ruleDiv.id = mode + 'AccessRule' + counter;
-
- ruleDiv.innerHTML = `
- <select name="access_action[]" class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
- <option value="allow" ${action === 'allow' ? 'selected' : ''}>allow</option>
- <option value="deny" ${action === 'deny' ? 'selected' : ''}>deny</option>
- </select>
- <input type="text" name="access_acl[]" value="${acl}" placeholder="ACL names (ej: students !local)"
- class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
- <button type="button" onclick="removeAccessRule('${mode}', ${counter})"
- class="text-red-600 hover:text-red-800 p-2">
- <i class="fas fa-times"></i>
- </button>
- `;
-
- container.appendChild(ruleDiv);
- }
- function removeAccessRule(mode, counter) {
- const ruleDiv = document.getElementById(mode + 'AccessRule' + counter);
- if (ruleDiv) {
- ruleDiv.remove();
- }
- }
- function deletePool(poolNumber) {
- if (confirm('¿Estás seguro de que quieres eliminar el Delay Pool #' + poolNumber + '?\n\nEsto eliminará todas las configuraciones asociadas (clase, parámetros y reglas de acceso).')) {
- const form = document.createElement('form');
- form.method = 'POST';
- form.action = '/admin/delay-pools/delete';
-
- const poolInput = document.createElement('input');
- poolInput.type = 'hidden';
- poolInput.name = 'pool_number';
- poolInput.value = poolNumber;
-
- const csrfInput = document.createElement('input');
- csrfInput.type = 'hidden';
- csrfInput.name = 'csrf_token';
- csrfInput.value = '{{ csrf_token() }}';
-
- form.appendChild(poolInput);
- form.appendChild(csrfInput);
- document.body.appendChild(form);
- form.submit();
- }
- }
- // Form submission handler for add form
- document.getElementById('addForm').addEventListener('submit', function(e) {
- e.preventDefault();
-
- const formData = new FormData(this);
- const poolClass = formData.get('pool_class');
-
- // Build parameters string based on class
- let parameters = '';
- if (poolClass === '1') {
- parameters = document.getElementById('addAggregateClass1').value;
- } else if (poolClass === '2') {
- const agg = document.getElementById('addAggregateClass2').value;
- const ind = document.getElementById('addIndividualClass2').value;
- parameters = `${agg} ${ind}`;
- } else if (poolClass === '3' || poolClass === '4') {
- const agg = document.getElementById('addAggregateClass3').value;
- const net = document.getElementById('addNetworkClass3').value;
- const ind = document.getElementById('addIndividualClass3').value;
- parameters = `${agg} ${net} ${ind}`;
- } else if (poolClass === '5') {
- parameters = document.getElementById('addTagClass5').value;
- }
-
- // Validate parameters
- if (!parameters.trim()) {
- alert('Por favor completa los parámetros de velocidad');
- return;
- }
-
- // Add parameters to form
- const paramsInput = document.createElement('input');
- paramsInput.type = 'hidden';
- paramsInput.name = 'parameters';
- paramsInput.value = parameters.trim();
- this.appendChild(paramsInput);
-
- this.submit();
- });
- </script>
- {% endblock %}
|