| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- {% from 'macros.html' import format_bandwidth %}
- <div class="w-full space-y-6">
- {# Tarjetas de estadísticas #}
- <div class="flex justify-center mb-8">
- <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-4 gap-3 w-full">
- {# Tarjeta de información del Servidor Squid #}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-server text-indigo-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs truncate">
- Servidor Squid:
- </p>
- <p class="text-lg font-bold truncate" title="{{ squid_version }}">
- {{ squid_version }}
- </p>
- </div>
- </div>
- {# Tarjeta de Bandwidth Total #}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-teal-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-tachometer-alt text-teal-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Total Bandwidth</p>
- <p class="text-lg font-bold truncate">
- {% set total_bw = namespace(value=0) %}
- {% for user_data in valid_users.values() %}
- {% for connection in user_data.connections %}
- {% if connection.bandwidth_kbps is defined %}
- {% set total_bw.value = total_bw.value + (connection.bandwidth_kbps|float) %}
- {% endif %}
- {% endfor %}
- {% endfor %}
- {{ format_bandwidth(total_bw.value) }}
- </p>
- </div>
- </div>
- {# Tarjeta de Usuarios Activos #}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-users text-blue-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Usuarios Activos</p>
- <p class="text-lg font-bold">{{ valid_users|length }}</p>
- </div>
- </div>
- {# Tarjeta de Conexiones Totales #}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-exchange-alt text-green-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Conexiones Totales</p>
- <p class="text-lg font-bold">
- {% set total = namespace(value=0) %}
- {% for user_data in valid_users.values() %}
- {% set total.value = total.value + user_data.connections|length %}
- {% endfor %}
- {{ total.value }}
- </p>
- </div>
- </div>
- {# Tiempo de Actividad de Squid #}
- {% if squid_info_stats and squid_info_stats.elapsed_hours %}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-clock text-purple-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Tiempo Activo</p>
- <p class="text-lg font-bold">
- {{ squid_info_stats.elapsed_hours }}h
- </p>
- </div>
- </div>
- {% endif %}
- {# Peticiones HTTP Totales #}
- {% if squid_info_stats and squid_info_stats.requests_received %}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-red-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-globe text-red-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Peticiones HTTP</p>
- <p class="text-lg font-bold">
- {{ squid_info_stats.requests_received | int }}
- </p>
- </div>
- </div>
- {% endif %}
- {# Promedio de Peticiones por Minuto #}
- {% if squid_info_stats and squid_info_stats.avg_requests_per_minute %}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-teal-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-chart-line text-teal-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Peticiones/Min</p>
- <p class="text-lg font-bold">
- {{ squid_info_stats.avg_requests_per_minute|round(1) }}
- </p>
- </div>
- </div>
- {% endif %}
- {# Estado de Conexión de Squid #}
- {% if squid_info_stats %}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full {% if squid_info_stats.connection_status == 'connected' %}bg-green-100{% else %}bg-red-100{% endif %} flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas {% if squid_info_stats.connection_status == 'connected' %}fa-check-circle text-green-500{% else %}fa-exclamation-triangle text-red-500{% endif %} text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Estado Squid</p>
- <p class="text-sm font-bold {% if squid_info_stats.connection_status == 'connected' %}text-green-600{% else %}text-red-600{% endif %} truncate">
- {% if squid_info_stats.connection_status == 'connected' %}Conectado
- {% elif squid_info_stats.connection_status == 'connected_but_parse_error' %}Error Parsing
- {% elif squid_info_stats.connection_status == 'timeout' %}Timeout
- {% elif squid_info_stats.connection_status == 'connection_refused' %}Rechazado
- {% elif squid_info_stats.connection_status == 'dns_error' %}Error DNS
- {% else %}Error
- {% endif %}
- </p>
- </div>
- </div>
- {% endif %}
- {# Tarjeta de Tipo de Sistema #}
- <div class="bg-white p-3 rounded-lg shadow flex items-center transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-0.5 min-w-0">
- <div class="w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-desktop text-orange-500 text-lg"></i>
- </div>
- <div class="min-w-0 flex-1">
- <p class="text-gray-500 text-xs">Tipo de Sistema</p>
- <p class="text-lg font-bold truncate" title="{{ system_type }}">
- {{ system_type }}
- </p>
- </div>
- </div>
- </div>
- </div>
- {# El resto del código permanece igual #}
- {% if valid_users|length > 0 %}
- <div class="flex justify-end mb-4">
- <button id="toggle-all-button" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded-lg transition-colors duration-300">
- Ver Resumen
- </button>
- </div>
- {% endif %}
- <div id="user-accordion-group">
- {% for user, user_data in valid_users.items() %}
- {% set connections = user_data.connections %}
- {% set client_ip = user_data.client_ip %}
- <div class="user-accordion bg-white rounded-lg shadow-md mb-3 overflow-hidden">
- <div class="w-full text-left p-4 border-b bg-white cursor-pointer" onclick="toggleAccordion({{ loop.index }})" id="header-{{ loop.index }}">
- <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between">
- <div class="flex items-center mb-3 sm:mb-0">
- <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 flex-shrink-0">
- <i class="fas fa-user text-blue-600"></i>
- </div>
- <div class="min-w-0">
- <h2 class="text-lg font-bold text-gray-800 truncate" title="{{ user }}">{{ user }}</h2>
- </div>
- </div>
- <div class="flex flex-wrap items-center gap-x-4 gap-y-2">
- <div class="flex items-center text-sm text-gray-600" title="IP del Cliente">
- <i class="fas fa-network-wired mr-1.5 text-gray-500"></i>
- <span class="truncate max-w-[120px]">{{ client_ip }}</span>
- </div>
- <div class="flex items-center text-sm text-gray-600" title="Conexiones totales de este usuario">
- <i class="fas fa-link mr-1.5 text-blue-500"></i>
- <span>{{ connections|length }} conexiones</span>
- </div>
-
- {% set user_bw = namespace(value=0) %}
- {% for connection in connections %}
- {% if connection.bandwidth_kbps is defined %}
- {% set user_bw.value = user_bw.value + (connection.bandwidth_kbps|float) %}
- {% endif %}
- {% endfor %}
-
- <div class="flex items-center text-sm text-gray-600" title="Total de velocidad del usuario">
- <i class="fas fa-tachometer-alt mr-1.5 text-teal-500"></i>
- <span class="truncate max-w-[100px]">
- {{ format_bandwidth(user_bw.value) }}
- </span>
- </div>
- {% set total_data = namespace(value=0) %}
- {% set total_requests = namespace(value=0) %}
- {% for connection in connections %}
- {% if connection.fd_total != "N/A" %}
- {% set total_data.value = total_data.value + connection.fd_total %}
- {% endif %}
- {% set total_requests.value = total_requests.value + connection.nrequests %}
- {% endfor %}
- <div class="hidden md:flex items-center text-sm text-gray-600" title="Total de datos transferidos">
- <i class="fas fa-database mr-1.5 text-green-500"></i>
- <span>{{ (total_data.value / 1024 / 1024)|round(2) }} MB</span>
- </div>
- <div class="hidden lg:flex items-center text-sm text-gray-600" title="Total de solicitudes">
- <i class="fas fa-bullhorn mr-1.5 text-purple-500"></i>
- <span>{{ total_requests.value }} solicitudes</span>
- </div>
-
- <div class="w-6 text-center">
- <i class="fas fa-chevron-down transition-transform duration-300 rotate-180" id="icon-{{ loop.index }}"></i>
- </div>
- </div>
- </div>
- </div>
- <div data-accordion-content data-user='{{ user|tojson }}' id="content-{{ loop.index }}">
- <div class="overflow-x-auto">
- <table class="min-w-full divide-y divide-gray-200">
- <thead class="bg-gray-50">
- <tr>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Duración
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Método
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- URL
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Datos
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Velocidad
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Delay Pool
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Solicitudes
- </th>
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
- Dir. Remota
- </th>
- </tr>
- </thead>
- <tbody class="divide-y divide-gray-200">
- {% for connection in connections %}
- <tr class="transition-colors duration-200 ease-in-out hover:bg-gray-50">
- <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
- {% set seconds = connection.elapsed_time|float %}
- {% if seconds >= 3600 %}{{ "%.2f"|format(seconds/3600) }} h
- {% elif seconds >= 60 %}{{ "%.2f"|format(seconds/60) }} min {% else %}
- {{ "%.2f"|format(seconds) }} seg
- {% endif %}
- </td>
- <td class="px-4 py-3 whitespace-nowrap">
- {% set method = connection.logType|lower %}
- <span class="px-2 py-1 rounded-full text-xs font-semibold ... {% if method == 'connect' or method == 'tcp_tunnel' %}bg-green-100 text-green-800 ... {% endif %}">
- {{ connection.logType }}
- </span>
- </td>
- <td class="px-4 py-3 max-w-xs">
- <div class="truncate text-sm transition-colors duration-200 hover:text-blue-600"
- title="{{ connection.uri }}">
- {{ connection.uri }}
- </div>
- </td>
- <td class="px-4 py-3 whitespace-nowrap text-sm">
- {% if connection.fd_total != "N/A" %}
- {{ (connection.fd_total / 1024 / 1024)|round(2) }} MB
- {% else %}N/A
- {% endif %}
- </td>
- <td class="px-4 py-3 whitespace-nowrap text-sm">
- {{ format_bandwidth(connection.bandwidth_kbps) }}
- </td>
- <td class="px-4 py-3 whitespace-nowrap">
- {% if connection.delay_pool != "N/A" %}
- {% set pool = connection.delay_pool|string %}
- <span class="px-2 py-1 rounded-full text-xs font-semibold ... {% if pool == '0' %}bg-sky-100 text-sky-800 ... {% endif %}">
- Pool {{ connection.delay_pool }}
- </span>
- {% endif %}
- </td>
- <td class="px-4 py-3 whitespace-nowrap text-sm font-medium">
- {{ connection.nrequests }}
- </td>
- <td class="px-4 py-3 whitespace-nowrap text-sm font-mono ... hover:text-blue-600">
- {{ connection.proxy_local_ip }}
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- </div>
- </div>
- {% endfor %}
- </div>
- </div>
- <script>
- function restoreAccordionState() {
- // Restaurar el estado de los acordeones desde localStorage
- const accordionState = JSON.parse(localStorage.getItem('accordion-state')) || {};
-
- // Iterar sobre todos los elementos de contenido de acordeón
- document.querySelectorAll('[data-accordion-content]').forEach(content => {
- const user = JSON.parse(content.getAttribute('data-user'));
- const index = content.id.replace('content-', '');
- const icon = document.getElementById('icon-' + index);
-
- // Por defecto abierto, a menos que esté explícitamente cerrado
- const isOpen = accordionState[user] !== false;
-
- if (isOpen) {
- content.style.display = '';
- icon.classList.add('rotate-180');
- } else {
- content.style.display = 'none';
- icon.classList.remove('rotate-180');
- }
- });
- }
- // Ejecutar inmediatamente ya que el script está al final
- restoreAccordionState();
- function toggleAccordion(index) {
- const content = document.getElementById('content-' + index);
- const icon = document.getElementById('icon-' + index);
- const user = JSON.parse(content.getAttribute('data-user'));
-
- // Alternar display
- const isCurrentlyHidden = content.style.display === 'none';
- content.style.display = isCurrentlyHidden ? '' : 'none';
- icon.classList.toggle('rotate-180');
-
- // Guardar el estado en localStorage
- const accordionState = JSON.parse(localStorage.getItem('accordion-state')) || {};
- accordionState[user] = content.style.display !== 'none'; // true si está abierto
- localStorage.setItem('accordion-state', JSON.stringify(accordionState));
- }
- </script>
|