| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- {% extends "admin/base.html" %}
- {% block title %}{{ _("Dividir Configuración Squid") }}{% endblock %}
- {% block content %}
- <div class="max-w-7xl mx-auto">
- <!-- Header -->
- <div class="bg-gradient-to-r from-blue-600 to-blue-700 rounded-xl shadow-lg p-6 mb-6 text-white">
- <div class="flex items-center space-x-4">
- <i class="fas fa-code-branch text-4xl"></i>
- <div>
- <h2 class="text-3xl font-bold">{{ _("Dividir Configuración Squid") }}</h2>
- <p class="text-blue-100 mt-1">{{ _("Modulariza tu archivo squid.conf para una gestión más sencilla") }}</p>
- </div>
- </div>
- </div>
- <!-- Info Cards -->
- <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
- <div class="bg-white rounded-lg shadow-md p-6">
- <div class="flex items-center space-x-3">
- <i class="fas fa-file-code text-blue-600 text-2xl"></i>
- <div>
- <p class="text-gray-600 text-sm">{{ _("Archivo de entrada") }}</p>
- <p class="font-semibold text-gray-800 text-sm">{{ input_file }}</p>
- </div>
- </div>
- </div>
- <div class="bg-white rounded-lg shadow-md p-6">
- <div class="flex items-center space-x-3">
- <i class="fas fa-folder text-emerald-600 text-2xl"></i>
- <div>
- <p class="text-gray-600 text-sm">{{ _("Directorio de salida") }}</p>
- <p class="font-semibold text-gray-800 text-sm">{{ output_dir }}</p>
- </div>
- </div>
- </div>
- <div class="bg-white rounded-lg shadow-md p-6">
- <div class="flex items-center space-x-3">
- <i class="fas fa-layer-group text-amber-600 text-2xl"></i>
- <div>
- <p class="text-gray-600 text-sm">{{ _("Estado") }}</p>
- {% if output_exists %}
- <p class="font-semibold text-emerald-600 text-sm">{{ files_count }} {{ _("archivos generados") }}</p>
- {% else %}
- <p class="font-semibold text-gray-600 text-sm">{{ _("No dividido aún") }}</p>
- {% endif %}
- </div>
- </div>
- </div>
- </div>
- <!-- Description -->
- <div class="bg-white rounded-lg shadow-md p-6 mb-6">
- <h3 class="text-xl font-bold text-gray-800 mb-3 flex items-center">
- <i class="fas fa-info-circle text-blue-600 mr-2"></i>
- {{ _("¿Qué hace esta funcionalidad?") }}
- </h3>
- <p class="text-gray-700 mb-4">
- {{ _("Esta herramienta divide tu archivo monolítico") }} <code class="bg-gray-100 px-2 py-1 rounded">squid.conf</code>
- {{ _("en múltiples archivos modulares organizados por categorías. Esto facilita:") }}
- </p>
- <ul class="list-disc list-inside text-gray-700 space-y-2 ml-4">
- <li>{{ _("Gestión y mantenimiento más sencillo de la configuración") }}</li>
- <li>{{ _("Mejor organización de directivas por funcionalidad") }}</li>
- <li>{{ _("Facilita la edición desde la interfaz web") }}</li>
- <li>{{ _("Reduce errores al editar configuraciones complejas") }}</li>
- </ul>
- </div>
- <!-- Files to be generated -->
- <div class="bg-white rounded-lg shadow-md p-6 mb-6">
- <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
- <i class="fas fa-list text-blue-600 mr-2"></i>
- {{ _("Archivos que se generarán") }}
- </h3>
- <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
- {% for filename, description in split_info.items() %}
- <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition-shadow">
- <div class="flex items-start space-x-3">
- <i class="fas fa-file-alt text-blue-500 mt-1"></i>
- <div class="flex-1">
- <p class="font-semibold text-gray-800 text-sm">{{ filename }}</p>
- <p class="text-gray-600 text-xs mt-1">{{ description }}</p>
- </div>
- </div>
- </div>
- {% endfor %}
- </div>
- </div>
- <!-- Actions -->
- <div class="bg-white rounded-lg shadow-md p-6">
- <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
- <i class="fas fa-cogs text-blue-600 mr-2"></i>
- {{ _("Acciones") }}
- </h3>
-
- <!-- 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>
-
- <div class="space-y-4">
- <!-- Strict mode toggle -->
- <div class="flex items-center space-x-3 p-4 bg-gray-50 rounded-lg">
- <input type="checkbox" id="strictMode" class="w-5 h-5 text-blue-600 rounded focus:ring-blue-500">
- <div class="flex-1">
- <label for="strictMode" class="font-medium text-gray-800 cursor-pointer">{{ _("Modo estricto") }}</label>
- <p class="text-sm text-gray-600">{{ _("Abortar si se encuentran directivas desconocidas") }}</p>
- </div>
- </div>
- <!-- Action buttons -->
- <div class="flex flex-col sm:flex-row gap-4">
- <button onclick="confirmSplit()" title="{{ _("Divide squid.conf en archivos modulares y crea respaldo") }}" class="flex-1 bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white font-semibold px-6 py-3 rounded-lg shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-200 flex items-center justify-center">
- <i class="fas fa-code-branch mr-2"></i>
- {{ _("Dividir Configuración") }}
- </button>
-
- {% if output_exists %}
- <button onclick="showFilesModal()" title="{{ _("Abre un modal con los archivos generados por la división") }}" class="flex-1 bg-gradient-to-r from-emerald-600 to-emerald-700 hover:from-emerald-700 hover:to-emerald-800 text-white font-semibold px-6 py-3 rounded-lg shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-200 flex items-center justify-center">
- <i class="fas fa-folder-open mr-2"></i>
- {{ _("Ver Archivos Generados") }}
- </button>
- {% endif %}
- </div>
- </div>
- <!-- Warning -->
- <div class="mt-6 bg-amber-50 border border-amber-200 rounded-lg p-4 flex items-start space-x-3">
- <i class="fas fa-exclamation-triangle text-amber-600 text-xl mt-1"></i>
- <div class="flex-1">
- <p class="font-semibold text-amber-800">{{ _("Advertencia") }}</p>
- <p class="text-sm text-amber-700 mt-1">
- {{ _("Esta operación creará múltiples archivos en el directorio") }} <code class="bg-amber-100 px-2 py-0.5 rounded">{{ output_dir }}</code>.
- Si ya existen archivos en ese directorio, serán sobrescritos.
- </p>
- </div>
- </div>
- </div>
- <!-- Results area (hidden by default) -->
- <div id="resultsArea" class="hidden mt-6 bg-white rounded-lg shadow-md p-6">
- <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
- <i class="fas fa-check-circle text-emerald-600 mr-2"></i>
- {{ _("Resultados") }}
- </h3>
- <div id="resultsContent" class="space-y-3"></div>
- </div>
- </div>
- <!-- Modal para ver archivos generados -->
- <div id="filesModal" 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-2xl max-w-4xl w-full max-h-[90vh] flex flex-col">
- <!-- Modal Header -->
- <div class="bg-gradient-to-r from-emerald-600 to-emerald-700 text-white px-6 py-4 rounded-t-lg flex items-center justify-between">
- <div class="flex items-center space-x-3">
- <i class="fas fa-folder-open text-2xl"></i>
- <h3 class="text-xl font-bold">{{ _("Archivos Generados") }}</h3>
- </div>
- <button onclick="closeFilesModal()" class="text-white hover:text-gray-200 transition-colors">
- <i class="fas fa-times text-2xl"></i>
- </button>
- </div>
- <!-- Modal Body -->
- <div class="flex-1 overflow-y-auto p-6">
- <div id="filesModalContent" class="space-y-4">
- <!-- Loading spinner -->
- <div class="flex items-center justify-center py-8">
- <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-emerald-600"></div>
- </div>
- </div>
- </div>
- <!-- Modal Footer -->
- <div class="bg-gray-50 px-6 py-4 rounded-b-lg flex items-center justify-between border-t">
- <p class="text-sm text-gray-600">
- <i class="fas fa-info-circle mr-1"></i>
- {{ _("Directorio:") }} <code class="bg-gray-200 px-2 py-1 rounded text-xs">{{ output_dir }}</code>
- </p>
- <button onclick="closeFilesModal()" class="bg-gray-600 hover:bg-gray-700 text-white font-semibold px-4 py-2 rounded-lg transition-colors">
- {{ _("Cerrar") }}
- </button>
- </div>
- </div>
- </div>
- <!-- Toastr CSS -->
- <link rel="stylesheet" href="{{ url_for('static', filename='css/toastr.min.css') }}">
- <!-- jQuery (required for Toastr) -->
- <script src="{{ url_for('static', filename='js/jquery-4.0.0.min.js') }}"></script>
- <!-- Toastr JS -->
- <script src="{{ url_for('static', filename='js/toastr.min.js') }}"></script>
- <script>
- // Configure toastr
- toastr.options = {
- closeButton: true,
- progressBar: true,
- positionClass: "toast-top-right",
- timeOut: "5000",
- };
- // Get CSRF token
- function getCsrfToken() {
- return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- }
- // Get current date for backup filename
- function getCurrentDate() {
- const now = new Date();
- const year = now.getFullYear();
- const month = String(now.getMonth() + 1).padStart(2, '0');
- const day = String(now.getDate()).padStart(2, '0');
- const hours = String(now.getHours()).padStart(2, '0');
- const minutes = String(now.getMinutes()).padStart(2, '0');
- return `${year}${month}${day}_${hours}${minutes}`;
- }
- function confirmSplit() {
- const backupFilename = `squid.conf.bak${getCurrentDate()}`;
- const msgEl = document.getElementById('confirmMessage');
- msgEl.replaceChildren();
- const wrapper = document.createElement('div');
- wrapper.className = 'space-y-3';
- const title = document.createElement('div');
- title.className = 'text-base text-gray-900 font-semibold mb-1';
- title.textContent = '¿Está seguro de que desea dividir la configuración de Squid?';
- wrapper.appendChild(title);
- const infoBox = document.createElement('div');
- infoBox.className = 'bg-blue-50 border border-blue-200 rounded-lg p-3 mt-2 text-left';
- const p1 = document.createElement('p');
- p1.className = 'text-sm text-blue-900 mb-2';
- const icon = document.createElement('i');
- icon.className = 'fas fa-info-circle mr-2';
- const strong = document.createElement('strong');
- strong.textContent = 'Esta operación es reversible';
- p1.appendChild(icon);
- p1.appendChild(strong);
- const p2 = document.createElement('p');
- p2.className = 'text-xs text-blue-800';
- p2.append('Se creará automáticamente una copia de seguridad de tu archivo ');
- const code = document.createElement('code');
- code.className = 'bg-blue-100 px-1 py-0.5 rounded';
- code.textContent = 'squid.conf';
- p2.appendChild(code);
- p2.append(' con el nombre:');
- const p3 = document.createElement('p');
- p3.className = 'text-xs text-blue-900 font-mono mt-1 bg-blue-100 px-2 py-1 rounded';
- p3.textContent = backupFilename;
- infoBox.appendChild(p1);
- infoBox.appendChild(p2);
- infoBox.appendChild(p3);
- wrapper.appendChild(infoBox);
- msgEl.appendChild(wrapper);
- openConfirmModal(executeSplit);
- }
- async function executeSplit() {
- const strictMode = document.getElementById('strictMode').checked;
- const resultsArea = document.getElementById('resultsArea');
- const resultsContent = document.getElementById('resultsContent');
- try {
- // Show loading toast
- toastr.info('Dividiendo configuración...', 'Procesando');
- const response = await fetch('/admin/api/split-config', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': getCsrfToken()
- },
- body: JSON.stringify({ strict: strictMode })
- });
- const data = await response.json();
- if (data.status === 'success') {
- toastr.success(data.message, '{{ _('Éxito') }}');
- // Show results
- resultsArea.classList.remove('hidden');
- resultsContent.innerHTML = `
- <div class="bg-emerald-50 border border-emerald-200 rounded-lg p-4">
- <p class="font-semibold text-emerald-800 mb-2">
- <i class="fas fa-check-circle mr-2"></i>
- {{ _('Configuración dividida exitosamente') }}
- </p>
- <p class="text-sm text-emerald-700">
- {{ _('Se generaron') }} <strong>${data.data.total_files}</strong> {{ _('archivos en') }}
- <code class="bg-emerald-100 px-2 py-0.5 rounded">${data.data.output_dir}</code>
- </p>
- </div>
- <div class="mt-4">
- <p class="font-semibold text-gray-800 mb-2">{{ _('Archivos generados:') }}</p>
- <div class="grid grid-cols-1 md:grid-cols-2 gap-2">
- ${Object.entries(data.data.files).map(([filename, lines]) => `
- <div class="flex justify-between items-center bg-gray-50 px-3 py-2 rounded">
- <span class="text-sm text-gray-700">${filename}</span>
- <span class="text-xs text-gray-500">${lines} líneas</span>
- </div>
- `).join('')}
- </div>
- </div>
- `;
- // Reload page after 3 seconds to update the stats
- setTimeout(() => {
- window.location.reload();
- }, 3000);
- } else {
- toastr.error(data.message || 'Error al dividir la configuración', 'Error');
- resultsArea.classList.add('hidden');
- }
- } catch (error) {
- console.error('Error:', error);
- toastr.error('Error de conexión al dividir la configuración', 'Error');
- resultsArea.classList.add('hidden');
- }
- }
- // Función para mostrar el modal de archivos
- async function showFilesModal() {
- const modal = document.getElementById('filesModal');
- const content = document.getElementById('filesModalContent');
-
- // Mostrar modal
- modal.classList.remove('hidden');
-
- // Mostrar loading
- content.innerHTML = `
- <div class="flex items-center justify-center py-8">
- <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-emerald-600"></div>
- </div>
- `;
-
- try {
- const response = await fetch('/admin/api/get-split-files', {
- method: 'GET',
- headers: {
- 'X-CSRFToken': getCsrfToken()
- }
- });
- const data = await response.json();
- if (data.status === 'success') {
- const files = data.data.files;
-
- if (files.length === 0) {
- content.innerHTML = `
- <div class="text-center py-8">
- <i class="fas fa-folder-open text-gray-400 text-6xl mb-4"></i>
- <p class="text-gray-600">No se encontraron archivos en el directorio</p>
- </div>
- `;
- return;
- }
- content.innerHTML = `
- <div class="mb-4 bg-emerald-50 border border-emerald-200 rounded-lg p-4">
- <p class="text-emerald-800">
- <i class="fas fa-check-circle mr-2"></i>
- Se encontraron <strong>${data.data.total_files}</strong> archivo${data.data.total_files !== 1 ? 's' : ''} de configuración
- </p>
- </div>
-
- <div class="space-y-3">
- ${files.map(file => `
- <div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition-shadow bg-white">
- <div class="flex items-start justify-between">
- <div class="flex items-start space-x-3 flex-1">
- <i class="fas fa-file-code text-blue-500 text-xl mt-1"></i>
- <div class="flex-1">
- <p class="font-semibold text-gray-800">${file.filename}</p>
- <div class="mt-2 flex flex-wrap gap-3 text-xs text-gray-600">
- <span class="flex items-center">
- <i class="fas fa-align-left mr-1"></i>
- ${file.lines} línea${file.lines !== 1 ? 's' : ''}
- </span>
- <span class="flex items-center">
- <i class="fas fa-weight-hanging mr-1"></i>
- ${file.size_human}
- </span>
- <span class="flex items-center">
- <i class="fas fa-clock mr-1"></i>
- ${file.modified}
- </span>
- </div>
- </div>
- </div>
- </div>
- </div>
- `).join('')}
- </div>
- `;
- } else {
- content.innerHTML = `
- <div class="bg-red-50 border border-red-200 rounded-lg p-4">
- <p class="text-red-800">
- <i class="fas fa-exclamation-circle mr-2"></i>
- ${data.message || 'Error al obtener los archivos'}
- </p>
- </div>
- `;
- }
- } catch (error) {
- console.error('Error:', error);
- content.innerHTML = `
- <div class="bg-red-50 border border-red-200 rounded-lg p-4">
- <p class="text-red-800">
- <i class="fas fa-exclamation-circle mr-2"></i>
- Error de conexión al obtener los archivos
- </p>
- </div>
- `;
- }
- }
- // Función para cerrar el modal
- function closeFilesModal() {
- const modal = document.getElementById('filesModal');
- modal.classList.add('hidden');
- }
- // Cerrar modal al hacer clic fuera de él
- document.getElementById('filesModal')?.addEventListener('click', function(e) {
- if (e.target === this) {
- closeFilesModal();
- }
- });
- // Cerrar modal con la tecla ESC
- document.addEventListener('keydown', function(e) {
- if (e.key === 'Escape') {
- closeFilesModal();
- }
- });
- </script>
- {% endblock %}
|