conexiones.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. {% from 'macros.html' import format_bandwidth %}
  2. <div class="w-full space-y-6">
  3. {# Tarjetas de estadísticas #}
  4. <div class="flex justify-center mb-8">
  5. <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">
  6. {# Tarjeta de información del Servidor Squid #}
  7. <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">
  8. <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3 flex-shrink-0">
  9. <i class="fas fa-server text-indigo-500 text-lg"></i>
  10. </div>
  11. <div class="min-w-0 flex-1">
  12. <p class="text-gray-500 text-xs truncate">
  13. Servidor Squid:
  14. </p>
  15. <p class="text-lg font-bold truncate" title="{{ squid_version }}">
  16. {{ squid_version }}
  17. </p>
  18. </div>
  19. </div>
  20. {# Tarjeta de Bandwidth Total #}
  21. <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">
  22. <div class="w-10 h-10 rounded-full bg-teal-100 flex items-center justify-center mr-3 flex-shrink-0">
  23. <i class="fas fa-tachometer-alt text-teal-500 text-lg"></i>
  24. </div>
  25. <div class="min-w-0 flex-1">
  26. <p class="text-gray-500 text-xs">Total Bandwidth</p>
  27. <p class="text-lg font-bold truncate">
  28. {% set total_bw = namespace(value=0) %}
  29. {% for user_data in valid_users.values() %}
  30. {% for connection in user_data.connections %}
  31. {% if connection.bandwidth_kbps is defined %}
  32. {% set total_bw.value = total_bw.value + (connection.bandwidth_kbps|float) %}
  33. {% endif %}
  34. {% endfor %}
  35. {% endfor %}
  36. {{ format_bandwidth(total_bw.value) }}
  37. </p>
  38. </div>
  39. </div>
  40. {# Tarjeta de Usuarios Activos #}
  41. <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">
  42. <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 flex-shrink-0">
  43. <i class="fas fa-users text-blue-500 text-lg"></i>
  44. </div>
  45. <div class="min-w-0 flex-1">
  46. <p class="text-gray-500 text-xs">Usuarios Activos</p>
  47. <p class="text-lg font-bold">{{ valid_users|length }}</p>
  48. </div>
  49. </div>
  50. {# Tarjeta de Conexiones Totales #}
  51. <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">
  52. <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-3 flex-shrink-0">
  53. <i class="fas fa-exchange-alt text-green-500 text-lg"></i>
  54. </div>
  55. <div class="min-w-0 flex-1">
  56. <p class="text-gray-500 text-xs">Conexiones Totales</p>
  57. <p class="text-lg font-bold">
  58. {% set total = namespace(value=0) %}
  59. {% for user_data in valid_users.values() %}
  60. {% set total.value = total.value + user_data.connections|length %}
  61. {% endfor %}
  62. {{ total.value }}
  63. </p>
  64. </div>
  65. </div>
  66. {# Tiempo de Actividad de Squid #}
  67. {% if squid_info_stats and squid_info_stats.elapsed_hours %}
  68. <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">
  69. <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-3 flex-shrink-0">
  70. <i class="fas fa-clock text-purple-500 text-lg"></i>
  71. </div>
  72. <div class="min-w-0 flex-1">
  73. <p class="text-gray-500 text-xs">Tiempo Activo</p>
  74. <p class="text-lg font-bold">
  75. {{ squid_info_stats.elapsed_hours }}h
  76. </p>
  77. </div>
  78. </div>
  79. {% endif %}
  80. {# Peticiones HTTP Totales #}
  81. {% if squid_info_stats and squid_info_stats.requests_received %}
  82. <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">
  83. <div class="w-10 h-10 rounded-full bg-red-100 flex items-center justify-center mr-3 flex-shrink-0">
  84. <i class="fas fa-globe text-red-500 text-lg"></i>
  85. </div>
  86. <div class="min-w-0 flex-1">
  87. <p class="text-gray-500 text-xs">Peticiones HTTP</p>
  88. <p class="text-lg font-bold">
  89. {{ squid_info_stats.requests_received | int }}
  90. </p>
  91. </div>
  92. </div>
  93. {% endif %}
  94. {# Promedio de Peticiones por Minuto #}
  95. {% if squid_info_stats and squid_info_stats.avg_requests_per_minute %}
  96. <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">
  97. <div class="w-10 h-10 rounded-full bg-teal-100 flex items-center justify-center mr-3 flex-shrink-0">
  98. <i class="fas fa-chart-line text-teal-500 text-lg"></i>
  99. </div>
  100. <div class="min-w-0 flex-1">
  101. <p class="text-gray-500 text-xs">Peticiones/Min</p>
  102. <p class="text-lg font-bold">
  103. {{ squid_info_stats.avg_requests_per_minute|round(1) }}
  104. </p>
  105. </div>
  106. </div>
  107. {% endif %}
  108. {# Estado de Conexión de Squid #}
  109. {% if squid_info_stats %}
  110. <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">
  111. <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">
  112. <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>
  113. </div>
  114. <div class="min-w-0 flex-1">
  115. <p class="text-gray-500 text-xs">Estado Squid</p>
  116. <p class="text-sm font-bold {% if squid_info_stats.connection_status == 'connected' %}text-green-600{% else %}text-red-600{% endif %} truncate">
  117. {% if squid_info_stats.connection_status == 'connected' %}Conectado
  118. {% elif squid_info_stats.connection_status == 'connected_but_parse_error' %}Error Parsing
  119. {% elif squid_info_stats.connection_status == 'timeout' %}Timeout
  120. {% elif squid_info_stats.connection_status == 'connection_refused' %}Rechazado
  121. {% elif squid_info_stats.connection_status == 'dns_error' %}Error DNS
  122. {% else %}Error
  123. {% endif %}
  124. </p>
  125. </div>
  126. </div>
  127. {% endif %}
  128. {# Tarjeta de Tipo de Sistema #}
  129. <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">
  130. <div class="w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center mr-3 flex-shrink-0">
  131. <i class="fas fa-desktop text-orange-500 text-lg"></i>
  132. </div>
  133. <div class="min-w-0 flex-1">
  134. <p class="text-gray-500 text-xs">Tipo de Sistema</p>
  135. <p class="text-lg font-bold truncate" title="{{ system_type }}">
  136. {{ system_type }}
  137. </p>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. {# El resto del código permanece igual #}
  143. {% if valid_users|length > 0 %}
  144. <div class="flex justify-end mb-4">
  145. <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">
  146. Ver Resumen
  147. </button>
  148. </div>
  149. {% endif %}
  150. <div id="user-accordion-group">
  151. {% for user, user_data in valid_users.items() %}
  152. {% set connections = user_data.connections %}
  153. {% set client_ip = user_data.client_ip %}
  154. <div class="user-accordion bg-white rounded-lg shadow-md mb-3 overflow-hidden">
  155. <div class="w-full text-left p-4 border-b bg-white cursor-pointer" onclick="toggleAccordion({{ loop.index }})" id="header-{{ loop.index }}">
  156. <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between">
  157. <div class="flex items-center mb-3 sm:mb-0">
  158. <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 flex-shrink-0">
  159. <i class="fas fa-user text-blue-600"></i>
  160. </div>
  161. <div class="min-w-0">
  162. <h2 class="text-lg font-bold text-gray-800 truncate" title="{{ user }}">{{ user }}</h2>
  163. </div>
  164. </div>
  165. <div class="flex flex-wrap items-center gap-x-4 gap-y-2">
  166. <div class="flex items-center text-sm text-gray-600" title="IP del Cliente">
  167. <i class="fas fa-network-wired mr-1.5 text-gray-500"></i>
  168. <span class="truncate max-w-[120px]">{{ client_ip }}</span>
  169. </div>
  170. <div class="flex items-center text-sm text-gray-600" title="Conexiones totales de este usuario">
  171. <i class="fas fa-link mr-1.5 text-blue-500"></i>
  172. <span>{{ connections|length }} conexiones</span>
  173. </div>
  174. {% set user_bw = namespace(value=0) %}
  175. {% for connection in connections %}
  176. {% if connection.bandwidth_kbps is defined %}
  177. {% set user_bw.value = user_bw.value + (connection.bandwidth_kbps|float) %}
  178. {% endif %}
  179. {% endfor %}
  180. <div class="flex items-center text-sm text-gray-600" title="Total de velocidad del usuario">
  181. <i class="fas fa-tachometer-alt mr-1.5 text-teal-500"></i>
  182. <span class="truncate max-w-[100px]">
  183. {{ format_bandwidth(user_bw.value) }}
  184. </span>
  185. </div>
  186. {% set total_data = namespace(value=0) %}
  187. {% set total_requests = namespace(value=0) %}
  188. {% for connection in connections %}
  189. {% if connection.fd_total != "N/A" %}
  190. {% set total_data.value = total_data.value + connection.fd_total %}
  191. {% endif %}
  192. {% set total_requests.value = total_requests.value + connection.nrequests %}
  193. {% endfor %}
  194. <div class="hidden md:flex items-center text-sm text-gray-600" title="Total de datos transferidos">
  195. <i class="fas fa-database mr-1.5 text-green-500"></i>
  196. <span>{{ (total_data.value / 1024 / 1024)|round(2) }} MB</span>
  197. </div>
  198. <div class="hidden lg:flex items-center text-sm text-gray-600" title="Total de solicitudes">
  199. <i class="fas fa-bullhorn mr-1.5 text-purple-500"></i>
  200. <span>{{ total_requests.value }} solicitudes</span>
  201. </div>
  202. <div class="w-6 text-center">
  203. <i class="fas fa-chevron-down transition-transform duration-300 rotate-180" id="icon-{{ loop.index }}"></i>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. <div data-accordion-content data-user='{{ user|tojson }}' id="content-{{ loop.index }}">
  209. <div class="overflow-x-auto">
  210. <table class="min-w-full divide-y divide-gray-200">
  211. <thead class="bg-gray-50">
  212. <tr>
  213. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  214. Duración
  215. </th>
  216. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  217. Método
  218. </th>
  219. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  220. URL
  221. </th>
  222. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  223. Datos
  224. </th>
  225. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  226. Velocidad
  227. </th>
  228. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  229. Delay Pool
  230. </th>
  231. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  232. Solicitudes
  233. </th>
  234. <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">
  235. Dir. Remota
  236. </th>
  237. </tr>
  238. </thead>
  239. <tbody class="divide-y divide-gray-200">
  240. {% for connection in connections %}
  241. <tr class="transition-colors duration-200 ease-in-out hover:bg-gray-50">
  242. <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
  243. {% set seconds = connection.elapsed_time|float %}
  244. {% if seconds >= 3600 %}{{ "%.2f"|format(seconds/3600) }} h
  245. {% elif seconds >= 60 %}{{ "%.2f"|format(seconds/60) }} min {% else %}
  246. {{ "%.2f"|format(seconds) }} seg
  247. {% endif %}
  248. </td>
  249. <td class="px-4 py-3 whitespace-nowrap">
  250. {% set method = connection.logType|lower %}
  251. <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 %}">
  252. {{ connection.logType }}
  253. </span>
  254. </td>
  255. <td class="px-4 py-3 max-w-xs">
  256. <div class="truncate text-sm transition-colors duration-200 hover:text-blue-600"
  257. title="{{ connection.uri }}">
  258. {{ connection.uri }}
  259. </div>
  260. </td>
  261. <td class="px-4 py-3 whitespace-nowrap text-sm">
  262. {% if connection.fd_total != "N/A" %}
  263. {{ (connection.fd_total / 1024 / 1024)|round(2) }} MB
  264. {% else %}N/A
  265. {% endif %}
  266. </td>
  267. <td class="px-4 py-3 whitespace-nowrap text-sm">
  268. {{ format_bandwidth(connection.bandwidth_kbps) }}
  269. </td>
  270. <td class="px-4 py-3 whitespace-nowrap">
  271. {% if connection.delay_pool != "N/A" %}
  272. {% set pool = connection.delay_pool|string %}
  273. <span class="px-2 py-1 rounded-full text-xs font-semibold ... {% if pool == '0' %}bg-sky-100 text-sky-800 ... {% endif %}">
  274. Pool {{ connection.delay_pool }}
  275. </span>
  276. {% endif %}
  277. </td>
  278. <td class="px-4 py-3 whitespace-nowrap text-sm font-medium">
  279. {{ connection.nrequests }}
  280. </td>
  281. <td class="px-4 py-3 whitespace-nowrap text-sm font-mono ... hover:text-blue-600">
  282. {{ connection.proxy_local_ip }}
  283. </td>
  284. </tr>
  285. {% endfor %}
  286. </tbody>
  287. </table>
  288. </div>
  289. </div>
  290. </div>
  291. {% endfor %}
  292. </div>
  293. </div>
  294. <script>
  295. function restoreAccordionState() {
  296. // Restaurar el estado de los acordeones desde localStorage
  297. const accordionState = JSON.parse(localStorage.getItem('accordion-state')) || {};
  298. // Iterar sobre todos los elementos de contenido de acordeón
  299. document.querySelectorAll('[data-accordion-content]').forEach(content => {
  300. const user = JSON.parse(content.getAttribute('data-user'));
  301. const index = content.id.replace('content-', '');
  302. const icon = document.getElementById('icon-' + index);
  303. // Por defecto abierto, a menos que esté explícitamente cerrado
  304. const isOpen = accordionState[user] !== false;
  305. if (isOpen) {
  306. content.style.display = '';
  307. icon.classList.add('rotate-180');
  308. } else {
  309. content.style.display = 'none';
  310. icon.classList.remove('rotate-180');
  311. }
  312. });
  313. }
  314. // Ejecutar inmediatamente ya que el script está al final
  315. restoreAccordionState();
  316. function toggleAccordion(index) {
  317. const content = document.getElementById('content-' + index);
  318. const icon = document.getElementById('icon-' + index);
  319. const user = JSON.parse(content.getAttribute('data-user'));
  320. // Alternar display
  321. const isCurrentlyHidden = content.style.display === 'none';
  322. content.style.display = isCurrentlyHidden ? '' : 'none';
  323. icon.classList.toggle('rotate-180');
  324. // Guardar el estado en localStorage
  325. const accordionState = JSON.parse(localStorage.getItem('accordion-state')) || {};
  326. accordionState[user] = content.style.display !== 'none'; // true si está abierto
  327. localStorage.setItem('accordion-state', JSON.stringify(accordionState));
  328. }
  329. </script>