base.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!DOCTYPE html>
  2. <html lang="{{ get_locale() }}">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="csrf-token" content="{{ csrf_token() }}">
  7. <title>{% block title %}{{ _("Administrador Squid Proxy") }}{% endblock %}</title>
  8. <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon"/>
  9. <script src="{{ url_for('static', filename='src/tailwind.min.js') }}"></script>
  10. <script src="{{ url_for('static', filename='src/alpine.min.js') }}" defer></script>
  11. <link rel="stylesheet" href="{{ url_for('static', filename='all.min.css') }}">
  12. <link rel="stylesheet" href="{{ url_for('static', filename='css/toastr.min.css') }}">
  13. </head>
  14. <body class="bg-gray-50 min-h-screen" x-data="{ sidebarOpen: false }">
  15. <!-- Navigation -->
  16. <nav class="bg-gradient-to-r from-blue-600 via-blue-700 to-blue-800 text-white shadow-xl border-b border-blue-500">
  17. <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
  18. <div class="flex justify-between items-center py-4">
  19. <div class="flex items-center space-x-3 md:space-x-6">
  20. <!-- Mobile menu button -->
  21. <button @click="sidebarOpen = !sidebarOpen" class="lg:hidden text-white hover:bg-blue-500 p-2 rounded-lg transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-300">
  22. <i class="fas fa-bars text-xl"></i>
  23. </button>
  24. <div class="flex items-center space-x-3">
  25. <img src="{{ url_for('static', filename='squidstats.webp') }}" alt="{{ _("SquidStats logo") }}" class="w-8 h-8 object-contain" />
  26. <i class="fas fa-server text-2xl md:text-3xl text-blue-200"></i>
  27. <div>
  28. <h1 class="text-lg md:text-2xl font-bold hidden sm:block">{{ _("Administrador Squid Proxy") }}</h1>
  29. <h1 class="text-lg font-bold sm:hidden">{{ _("Admin Squid") }}</h1>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="flex items-center space-x-2 sm:space-x-3 md:space-x-4">
  34. <button onclick="reloadSquid()" title="{{ _("Recarga la configuración de Squid sin reiniciar el servicio") }}" class="bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-semibold px-3 sm:px-4 md:px-5 py-2 md:py-2.5 rounded-lg shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-200 flex items-center text-sm md:text-base">
  35. <i class="fas fa-sync-alt mr-2"></i>
  36. <span class="hidden sm:inline">{{ _("Recargar") }}</span>
  37. </button>
  38. <button onclick="restartSquid()" title="{{ _("Reinicia Squid y vuelve a aplicar la configuración desde cero") }}" class="bg-gradient-to-r from-amber-500 to-amber-600 hover:from-amber-600 hover:to-amber-700 text-white font-semibold px-3 sm:px-4 md:px-5 py-2 md:py-2.5 rounded-lg shadow-lg hover:shadow-xl transform hover:scale-105 transition-all duration-200 flex items-center text-sm md:text-base">
  39. <i class="fas fa-power-off mr-2"></i>
  40. <span class="hidden sm:inline">{{ _("Reiniciar") }}</span>
  41. </button>
  42. <div class="relative" x-data="{ langOpen: false }">
  43. <button @click="langOpen = !langOpen" @click.outside="langOpen = false" title="{{ _("Idioma") }}" class="flex items-center space-x-2 text-white bg-blue-800 bg-opacity-60 hover:bg-blue-700 px-4 py-2 rounded-lg shadow-md transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-blue-300">
  44. <i class="fas fa-globe"></i>
  45. <span class="hidden sm:inline uppercase">{{ get_locale() }}</span>
  46. </button>
  47. <div x-show="langOpen" x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0 transform scale-95" x-transition:enter-end="opacity-100 transform scale-100" x-transition:leave="transition ease-in duration-150" x-transition:leave-start="opacity-100 transform scale-100" x-transition:leave-end="opacity-0 transform scale-95" class="absolute right-0 mt-2 w-44 bg-white rounded-lg shadow-xl border border-gray-200 z-50" style="display: none;">
  48. {% for code, name in LANGUAGES.items() %}
  49. <a href="{{ url_for('i18n.set_language', lang=code) }}" class="block px-4 py-3 text-sm text-gray-700 hover:bg-blue-50 hover:text-blue-700 transition-colors {% if get_locale() == code %}bg-blue-50 font-semibold text-blue-700{% endif %}">
  50. {{ name }}
  51. </a>
  52. {% endfor %}
  53. </div>
  54. </div>
  55. <!-- User Dropdown -->
  56. <div class="relative" x-data="{ userMenuOpen: false }">
  57. <button @click="userMenuOpen = !userMenuOpen" @click.away="userMenuOpen = false" class="flex items-center space-x-2 text-white bg-blue-800 bg-opacity-60 hover:bg-blue-700 px-4 py-2 rounded-lg shadow-md transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-blue-300">
  58. <div class="flex items-center space-x-2">
  59. <div class="w-8 h-8 bg-gradient-to-r from-blue-400 to-blue-500 rounded-full flex items-center justify-center">
  60. <i class="fas fa-user text-sm"></i>
  61. </div>
  62. <div class="hidden md:block text-left">
  63. <div class="text-sm font-semibold">{{ session.user.username if session.user else 'Admin' }}</div>
  64. <div class="text-xs text-blue-200">{{ session.user.role if session.user else 'Administrator' }}</div>
  65. </div>
  66. </div>
  67. <i class="fas fa-chevron-down text-sm transition-transform duration-200" :class="userMenuOpen ? 'rotate-180' : ''"></i>
  68. </button>
  69. <!-- Dropdown Menu -->
  70. <div x-show="userMenuOpen" x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0 transform scale-95" x-transition:enter-end="opacity-100 transform scale-100" x-transition:leave="transition ease-in duration-150" x-transition:leave-start="opacity-100 transform scale-100" x-transition:leave-end="opacity-0 transform scale-95" class="absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-xl border border-gray-200 z-50" style="display: none;">
  71. <!-- User Info Header -->
  72. <div class="px-4 py-3 border-b border-gray-200 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-t-lg">
  73. <div class="flex items-center space-x-3">
  74. <div class="w-10 h-10 bg-gradient-to-r from-blue-500 to-indigo-600 rounded-full flex items-center justify-center">
  75. <i class="fas fa-user text-white"></i>
  76. </div>
  77. <div>
  78. <p class="text-sm font-semibold text-gray-800">{{ session.user.username if session.user else 'Admin' }}</p>
  79. <p class="text-xs text-gray-600">{{ session.user.role if session.user else 'Administrator' }}</p>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- Menu Items -->
  84. <div class="py-2">
  85. <a href="{{ url_for('admin.manage_users') }}" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-blue-600 transition-colors">
  86. <i class="fas fa-users mr-3 text-gray-400"></i>
  87. {{ _("Gestionar Usuarios") }}
  88. </a>
  89. <a href="{{ url_for('admin.view_config') }}" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 hover:text-blue-600 transition-colors">
  90. <i class="fas fa-cog mr-3 text-gray-400"></i>
  91. {{ _("Configuración") }}
  92. </a>
  93. <div class="border-t border-gray-200 my-1"></div>
  94. <a href="{{ url_for('auth.logout') }}" class="flex items-center px-4 py-2 text-sm text-red-600 hover:bg-red-50 hover:text-red-700 transition-colors">
  95. <i class="fas fa-sign-out-alt mr-3"></i>
  96. {{ _("Cerrar Sesión") }}
  97. </a>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </nav>
  105. <!-- Sidebar -->
  106. <div class="flex relative">
  107. <!-- Mobile sidebar overlay -->
  108. <div x-show="sidebarOpen" @click="sidebarOpen = false" class="fixed inset-0 bg-black bg-opacity-50 z-40 lg:hidden" x-transition:enter="transition-opacity ease-linear duration-300" x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100" x-transition:leave="transition-opacity ease-linear duration-300" x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" style="display: none;"></div>
  109. <aside class="w-64 bg-white shadow-lg min-h-screen">
  110. <nav class="mt-8">
  111. <div class="px-4 space-y-2">
  112. <a href="{{ url_for('main.index') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  113. <i class="fas fa-home mr-3"></i>{{ _("Dashboard") }}
  114. </a>
  115. <a href="{{ url_for('admin.admin_dashboard') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  116. <i class="fas fa-home mr-3"></i>{{ _("Dashboard Admin") }}
  117. </a>
  118. <a href="{{ url_for('admin.view_config') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  119. <i class="fas fa-cog mr-3"></i>{{ _("Configuración") }}
  120. </a>
  121. <a href="{{ url_for('admin.split_config_view') }}" class="flex items-center justify-between px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  122. <span class="flex items-center">
  123. <i class="fas fa-code-branch mr-3"></i>{{ _("Dividir Squid Config") }}
  124. </span>
  125. <span class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white text-xs font-semibold px-2.5 py-0.5 rounded-full shadow-sm">{{ _("RC") }}</span>
  126. </a>
  127. <a href="{{ url_for('admin.manage_users') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  128. <i class="fas fa-users mr-3"></i>{{ _("Usuarios") }}
  129. </a>
  130. <a href="{{ url_for('admin.ldap_config') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors" title="{{ _("Configuraciones LDAP/Active Directory") }}">
  131. <i class="fas fa-network-wired mr-3"></i>{{ _("LDAP / Active Directory") }}
  132. </a>
  133. <a href="{{ url_for('admin.database_view') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  134. <i class="fas fa-database mr-3"></i>{{ _("Base de Datos") }}
  135. </a>
  136. <a href="{{ url_for('admin.manage_acls') }}" class="flex items-center justify-between px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  137. <span class="flex items-center">
  138. <i class="fas fa-shield-alt mr-3"></i>{{ _("ACLs") }}
  139. </span>
  140. <span class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white text-xs font-semibold px-2.5 py-0.5 rounded-full shadow-sm">{{ _("RC") }}</span>
  141. </a>
  142. <a href="{{ url_for('admin.manage_delay_pools') }}" class="flex items-center justify-between px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  143. <span class="flex items-center">
  144. <i class="fas fa-clock mr-3"></i>{{ _("Delay Pools") }}
  145. </span>
  146. <span class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white text-xs font-semibold px-2.5 py-0.5 rounded-full shadow-sm">{{ _("RC") }}</span>
  147. </a>
  148. <a href="{{ url_for('admin.manage_http_access') }}" class="flex items-center justify-between px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  149. <span class="flex items-center">
  150. <i class="fas fa-key mr-3"></i>{{ _("HTTP Access") }}
  151. </span>
  152. <span class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white text-xs font-semibold px-2.5 py-0.5 rounded-full shadow-sm">{{ _("RC") }}</span>
  153. </a>
  154. <a href="/admin/quota" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors" title="{{ _("Cuotas") }}">
  155. <i class="fas fa-tachometer-alt mr-3"></i>{{ _("Cuotas") }}
  156. <span class="ml-2 text-xs font-semibold text-white bg-yellow-500 px-2 py-0.5 rounded">{{ _("Beta") }}</span>
  157. </a>
  158. <a href="/admin/blacklist" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  159. <i class="fas fa-ban mr-3"></i>{{ _("Blacklist") }}
  160. </a>
  161. <a href="{{ url_for('admin.view_logs') }}" class="flex items-center px-4 py-3 text-gray-700 hover:bg-blue-50 hover:text-blue-600 rounded-lg transition-colors">
  162. <i class="fas fa-file-alt mr-3"></i>{{ _("Logs") }}
  163. </a>
  164. </div>
  165. </nav>
  166. </aside>
  167. <!-- Main Content -->
  168. <main class="flex-1 p-4 sm:p-6 lg:p-8 w-full lg:w-auto">
  169. <!-- Flash Messages -->
  170. {% with messages = get_flashed_messages(with_categories=true) %}
  171. {% if messages %}
  172. <div class="mb-6">
  173. {% for category, message in messages %}
  174. <div class="alert alert-{{ 'success' if category == 'success' else 'warning' }} p-4 rounded-lg mb-4 {% if category == 'success' %}bg-blue-50 text-blue-800 border border-blue-200{% else %}bg-orange-50 text-orange-800 border border-orange-200{% endif %}">
  175. <i class="fas fa-{% if category == 'success' %}check-circle text-blue-600{% else %}exclamation-triangle text-orange-600{% endif %} mr-2"></i>
  176. {{ message }}
  177. </div>
  178. {% endfor %}
  179. </div>
  180. {% endif %}
  181. {% endwith %}
  182. {% block content %}{% endblock %}
  183. </main>
  184. </div>
  185. <!-- Custom Confirm Modal -->
  186. {% include 'components/confirm_modal.html' %}
  187. <script src="{{ url_for('static', filename='js/jquery-4.0.0.min.js') }}"></script>
  188. <script src="{{ url_for('static', filename='js/toastr.min.js') }}"></script>
  189. <script src="{{ url_for('static', filename='js/toastr-config.js') }}"></script>
  190. <script src="{{ url_for('static', filename='js/confirm_modal.js') }}"></script>
  191. <script>
  192. // Get CSRF token from meta tag
  193. function getCsrfToken() {
  194. return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
  195. }
  196. async function reloadSquid() {
  197. showCustomConfirm({{ _('¿Estás seguro de que desea recargar Squid? Esto aplicará los cambios de configuración sin interrumpir el servicio.')|tojson }}, async () => {
  198. try {
  199. const response = await fetch('/api/reload-squid', {
  200. method: 'POST',
  201. headers: {
  202. 'X-CSRFToken': getCsrfToken()
  203. }
  204. });
  205. const data = await response.json();
  206. if (data.status === 'success') {
  207. showNotification(data.message, 'success');
  208. } else {
  209. showNotification(data.message, 'error');
  210. }
  211. } catch (error) {
  212. showNotification({{ _('Error al recargar Squid')|tojson }}, 'error');
  213. }
  214. });
  215. }
  216. async function restartSquid() {
  217. showCustomConfirm({{ _('¿Estás seguro de que desea reiniciar Squid? Esto interrumpirá temporalmente el servicio.')|tojson }}, async () => {
  218. try {
  219. const response = await fetch('/api/restart-squid', {
  220. method: 'POST',
  221. headers: {
  222. 'X-CSRFToken': getCsrfToken()
  223. }
  224. });
  225. const data = await response.json();
  226. if (data.status === 'success') {
  227. showNotification(data.message, 'success');
  228. } else {
  229. showNotification(data.message, 'error');
  230. }
  231. } catch (error) {
  232. showNotification({{ _('Error al reiniciar Squid')|tojson }}, 'error');
  233. }
  234. });
  235. }
  236. function showNotification(message, type) {
  237. if (window.toastr) {
  238. if (type === 'success') {
  239. toastr.success(message);
  240. } else if (type === 'error') {
  241. toastr.error(message);
  242. } else if (type === 'warning') {
  243. toastr.warning(message);
  244. } else {
  245. toastr.info(message);
  246. }
  247. }
  248. }
  249. </script>
  250. </body>
  251. </html>