4
0

delay_pools.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. {% extends "admin/base.html" %}
  2. {% block content %}
  3. <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
  4. <div class="flex justify-between items-center mb-4 sm:mb-6">
  5. <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de Delay Pools") }}</h2>
  6. <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">
  7. <i class="fas fa-plus mr-2"></i>{{ _("Agregar Pool") }}
  8. </button>
  9. </div>
  10. <!-- RC -->
  11. <div class="mb-6 bg-red-50 border-2 border-red-300 rounded-lg p-6 flex items-start space-x-4">
  12. <i class="fas fa-exclamation-triangle text-red-600 text-3xl mt-1 animate-pulse"></i>
  13. <div class="flex-1">
  14. <p class="font-bold text-red-800 text-lg">{{ _("¡MUY IMPORTANTE!") }}</p>
  15. <p class="text-red-700 mt-2 font-medium">
  16. {{ _("Esta funcionalidad se encuentra en") }} <strong>{{ _("RC") }}</strong>. Puede contener errores y comportamientos inesperados.
  17. </p>
  18. <p class="text-red-700 mt-2">
  19. <strong>{{ _("Por favor, no la uses en producción de momento. Úsala únicamente en un entorno de prueba.") }}</strong>
  20. </p>
  21. </div>
  22. </div>
  23. <!-- Delay Pools Info -->
  24. <div class="mb-4 bg-blue-50 border border-blue-200 rounded-lg p-4">
  25. <div class="flex items-start">
  26. <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
  27. <div class="text-sm text-gray-700">
  28. <p class="font-semibold text-gray-800 mb-1">{{ _("¿Qué son los Delay Pools?") }}</p>
  29. <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>
  30. <p class="font-semibold text-gray-800 mb-1">{{ _("Clases disponibles:") }}</p>
  31. <ul class="list-disc list-inside space-y-1 ml-2 mb-2">
  32. <li><strong>{{ _("Clase 1:") }}</strong> {{ _("Un solo bucket agregado para todos los clientes") }}</li>
  33. <li><strong>{{ _("Clase 2:") }}</strong> {{ _("Bucket agregado + buckets individuales por host (/24)") }}</li>
  34. <li><strong>{{ _("Clase 3:") }}</strong> {{ _("Buckets por subred + buckets individuales por host (/16)") }}</li>
  35. <li><strong>{{ _("Clase 4:") }}</strong> {{ _("Como clase 3 + buckets por usuario autenticado") }}</li>
  36. <li><strong>{{ _("Clase 5:") }}</strong> {{ _("Basado en tags de external_acl_type") }}</li>
  37. </ul>
  38. <p class="font-semibold text-gray-800 mb-1">{{ _("Limitaciones importantes:") }}</p>
  39. <ul class="list-disc list-inside space-y-1 ml-2">
  40. <li>{{ _("No limita overheads como TCP, ICP, DNS, etc.") }}</li>
  41. <li>{{ _("Incompatible con slow aborts; usa quick abort bajo") }}</li>
  42. <li>{{ _("Una conexión puede tomar todo el ancho de banda de un bucket") }}</li>
  43. <li>{{ _("En Squid") }} < 3.1, buckets limitados a 32-bits</li>
  44. </ul>
  45. </div>
  46. </div>
  47. </div>
  48. {% if delay_pools %}
  49. <div class="space-y-4 sm:space-y-6">
  50. {% for pool in delay_pools %}
  51. <div class="border border-gray-200 rounded-lg p-4 sm:p-6 bg-gradient-to-br from-white to-gray-50">
  52. <div class="flex justify-between items-start mb-4">
  53. <div class="flex-1">
  54. <div class="flex items-center mb-2">
  55. <h3 class="text-xl font-bold text-gray-800">{{ _("Pool #") }}{{ pool.pool_number }}</h3>
  56. <span class="ml-3 bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded">
  57. {{ _("Clase") }} {{ pool.class }}
  58. </span>
  59. </div>
  60. <p class="text-sm text-gray-600">
  61. {% if pool.class == '1' %}
  62. <i class="fas fa-stream mr-1"></i> {{ _("Bucket único agregado para todos los clientes") }}
  63. {% elif pool.class == '2' %}
  64. <i class="fas fa-network-wired mr-1"></i> {{ _("Bucket agregado + 255 buckets por host (red /24)") }}
  65. {% elif pool.class == '3' %}
  66. <i class="fas fa-sitemap mr-1"></i> {{ _("Buckets por subred + buckets por host (red /16)") }}
  67. {% elif pool.class == '4' %}
  68. <i class="fas fa-users mr-1"></i> {{ _("Como clase 3 + buckets por usuario autenticado") }}
  69. {% elif pool.class == '5' %}
  70. <i class="fas fa-tags mr-1"></i> {{ _("Buckets basados en tags de external_acl_type") }}
  71. {% endif %}
  72. </p>
  73. </div>
  74. <div class="flex space-x-2">
  75. <button onclick='editPool({{ pool.pool_number }}, "{{ pool.class }}", "{{ pool.parameters }}", {{ pool.access_rules|tojson }})'
  76. class="text-blue-600 hover:text-blue-900 p-2" title="{{ _("Editar") }}">
  77. <i class="fas fa-edit text-lg"></i>
  78. </button>
  79. <button onclick="deletePool('{{ pool.pool_number }}')"
  80. class="text-red-600 hover:text-red-900 p-2" title="{{ _("Eliminar") }}">
  81. <i class="fas fa-trash text-lg"></i>
  82. </button>
  83. </div>
  84. </div>
  85. {% if pool.parameters %}
  86. <div class="bg-gray-50 rounded-lg p-4 mb-4 border border-gray-200">
  87. <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
  88. <i class="fas fa-tachometer-alt mr-2 text-blue-600"></i> {{ _("Parámetros de Velocidad:") }}
  89. </h4>
  90. <div class="font-mono text-sm text-gray-700 bg-white p-3 rounded border border-gray-300">
  91. {{ pool.parameters }}
  92. </div>
  93. <div class="mt-2 text-xs text-gray-600">
  94. {% set params = pool.parameters.split() %}
  95. {% if pool.class == '1' %}
  96. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
  97. {% elif pool.class == '2' %}
  98. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
  99. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Individual (por host):") }} {{ params[1] if params|length > 1 }}</span>
  100. {% elif pool.class in ['3', '4'] %}
  101. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Agregado:") }} {{ params[0] if params|length > 0 }}</span>
  102. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Red:") }} {{ params[1] if params|length > 1 }}</span>
  103. <span class="block"><i class="fas fa-circle text-xs mr-1"></i> {{ _("Individual (por host):") }} {{ params[2] if params|length > 2 }}</span>
  104. {% endif %}
  105. <p class="mt-1 italic">{{ _("Formato: restore/max (bytes por segundo)") }}</p>
  106. </div>
  107. </div>
  108. {% endif %}
  109. {% if pool.access_rules %}
  110. <div class="bg-blue-50 rounded-lg p-4 border border-blue-200">
  111. <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
  112. <i class="fas fa-shield-alt mr-2 text-blue-600"></i> {{ _("Reglas de Acceso:") }}
  113. </h4>
  114. <div class="space-y-2">
  115. {% for rule in pool.access_rules %}
  116. <div class="flex items-center bg-white p-2 rounded border border-gray-200">
  117. {% if rule.action == 'allow' %}
  118. <span class="bg-green-100 text-green-800 text-xs font-semibold px-2 py-1 rounded mr-2">{{ _("ALLOW") }}</span>
  119. {% else %}
  120. <span class="bg-red-100 text-red-800 text-xs font-semibold px-2 py-1 rounded mr-2">{{ _("DENY") }}</span>
  121. {% endif %}
  122. <span class="text-sm text-gray-700 font-mono">{{ rule.acl }}</span>
  123. </div>
  124. {% endfor %}
  125. </div>
  126. </div>
  127. {% endif %}
  128. </div>
  129. {% endfor %}
  130. </div>
  131. {% else %}
  132. {% if not authenticated %}
  133. <div class="text-center py-12">
  134. <i class="fas fa-user-lock text-6xl text-gray-300 mb-4"></i>
  135. <p class="text-gray-500 text-lg">{{ _("Para ver los delay pools debes iniciar sesión.") }}</p>
  136. <p class="text-gray-500 mt-2">{{ _("Inicia sesión con una cuenta de administrador para acceder a esta sección.") }}</p>
  137. <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">
  138. <i class="fas fa-sign-in-alt mr-2"></i> {{ _("Iniciar sesión") }}
  139. </a>
  140. </div>
  141. {% else %}
  142. <div class="text-center py-12">
  143. <i class="fas fa-clock text-6xl text-gray-300 mb-4"></i>
  144. <p class="text-gray-500 text-lg">{{ _("No hay delay pools configurados") }}</p>
  145. <div class="mt-4 bg-blue-50 border border-blue-200 rounded-lg p-4 max-w-md mx-auto">
  146. <div class="flex items-start">
  147. <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
  148. <div class="text-left text-sm">
  149. <p class="font-semibold text-blue-900 mb-1">{{ _("¿Ya tienes delay pools configurados?") }}</p>
  150. <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>
  151. <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>
  152. </div>
  153. </div>
  154. </div>
  155. <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">
  156. <i class="fas fa-plus mr-2"></i>{{ _("Crear primer Pool") }}
  157. </button>
  158. </div>
  159. {% endif %}
  160. {% endif %}
  161. </div>
  162. <!-- Add Modal -->
  163. <div id="addModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
  164. <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
  165. <h3 class="text-2xl font-bold text-gray-800 mb-4">
  166. <i class="fas fa-plus-circle text-blue-600 mr-2"></i>{{ _("Agregar Nuevo Delay Pool") }}
  167. </h3>
  168. <form id="addForm" method="POST" action="/admin/delay-pools/add">
  169. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
  170. <div class="mb-4">
  171. <label class="block text-gray-700 font-semibold mb-2">{{ _("Número de Pool:") }}</label>
  172. <input type="number" name="pool_number" id="addPoolNumber" min="1" max="255"
  173. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
  174. required placeholder="1">
  175. <p class="text-xs text-gray-500 mt-1">{{ _("Número único del pool (1-255)") }}</p>
  176. </div>
  177. <div class="mb-4">
  178. <label class="block text-gray-700 font-semibold mb-2">{{ _("Clase de Pool:") }}</label>
  179. <select name="pool_class" id="addPoolClass" onchange="updateParametersHelp('add')"
  180. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
  181. <option value="">{{ _("Seleccione una clase...") }}</option>
  182. <option value="1">{{ _("Clase 1 - Bucket único agregado") }}</option>
  183. <option value="2">{{ _("Clase 2 - Agregado + por host (/24)") }}</option>
  184. <option value="3">{{ _("Clase 3 - Agregado + red + por host (/16)") }}</option>
  185. <option value="4">{{ _("Clase 4 - Como clase 3 + por usuario") }}</option>
  186. <option value="5">{{ _("Clase 5 - Basado en tags") }}</option>
  187. </select>
  188. </div>
  189. <div id="addParametersSection" class="mb-4 hidden">
  190. <label class="block text-gray-700 font-semibold mb-2">{{ _("Parámetros de Velocidad:") }}</label>
  191. <!-- Clase 1 -->
  192. <div id="addClass1Params" class="hidden space-y-3">
  193. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  194. <strong>{{ _("Clase 1:") }}</strong> {{ _("Un solo bucket agregado para todos los clientes") }}
  195. </div>
  196. <div>
  197. <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max en bytes/seg):") }}</label>
  198. <input type="text" id="addAggregateClass1" placeholder="64000/64000"
  199. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  200. <p class="text-xs text-gray-500 mt-1">{{ _("Ej: 64000/64000 = 512 Kbps") }}</p>
  201. </div>
  202. </div>
  203. <!-- Clase 2 -->
  204. <div id="addClass2Params" class="hidden space-y-3">
  205. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  206. <strong>{{ _("Clase 2:") }}</strong> {{ _("Bucket agregado + 255 buckets individuales por host") }}
  207. </div>
  208. <div>
  209. <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max):") }}</label>
  210. <input type="text" id="addAggregateClass2" placeholder="64000/64000"
  211. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  212. </div>
  213. <div>
  214. <label class="text-sm font-medium text-gray-700">{{ _("Individual por host (restore/max):") }}</label>
  215. <input type="text" id="addIndividualClass2" placeholder="16000/64000"
  216. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  217. <p class="text-xs text-gray-500 mt-1">{{ _("Usa -1/-1 para deshabilitar este bucket") }}</p>
  218. </div>
  219. </div>
  220. <!-- Clase 3/4 -->
  221. <div id="addClass3Params" class="hidden space-y-3">
  222. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  223. <strong id="addClass3Title">{{ _("Clase 3:") }}</strong> <span id="addClass3Desc">{{ _("Buckets por subred + por host") }}</span>
  224. </div>
  225. <div>
  226. <label class="text-sm font-medium text-gray-700">{{ _("Agregado (restore/max):") }}</label>
  227. <input type="text" id="addAggregateClass3" placeholder="64000/64000"
  228. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  229. </div>
  230. <div>
  231. <label class="text-sm font-medium text-gray-700">{{ _("Por red (restore/max):") }}</label>
  232. <input type="text" id="addNetworkClass3" placeholder="8000/64000"
  233. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  234. <p class="text-xs text-gray-500 mt-1">{{ _("Usa -1/-1 para deshabilitar") }}</p>
  235. </div>
  236. <div>
  237. <label class="text-sm font-medium text-gray-700">{{ _("Individual por host (restore/max):") }}</label>
  238. <input type="text" id="addIndividualClass3" placeholder="2000/16000"
  239. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  240. </div>
  241. </div>
  242. <!-- Clase 5 -->
  243. <div id="addClass5Params" class="hidden space-y-3">
  244. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  245. <strong>{{ _("Clase 5:") }}</strong> {{ _("Basado en tags de external_acl_type (un bucket por tag)") }}
  246. </div>
  247. <div>
  248. <label class="text-sm font-medium text-gray-700">{{ _("Parámetros por tag (restore/max):") }}</label>
  249. <input type="text" id="addTagClass5" placeholder="16000/32000"
  250. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  251. </div>
  252. </div>
  253. </div>
  254. <div class="mb-4">
  255. <label class="block text-gray-700 font-semibold mb-2">{{ _("Reglas de Acceso (ACLs):") }}</label>
  256. <div id="addAccessRules" class="space-y-2">
  257. <!-- Las reglas se agregarán dinámicamente -->
  258. </div>
  259. <button type="button" onclick="addAccessRule('add')"
  260. class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
  261. <i class="fas fa-plus-circle mr-1"></i>{{ _("Agregar regla de acceso") }}
  262. </button>
  263. </div>
  264. <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
  265. <button type="button" onclick="closeAddModal()"
  266. class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
  267. {{ _("Cancelar") }}
  268. </button>
  269. <button type="submit"
  270. class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
  271. <i class="fas fa-save mr-2"></i>{{ _("Crear Pool") }}
  272. </button>
  273. </div>
  274. </form>
  275. </div>
  276. </div>
  277. <!-- Edit Modal -->
  278. <div id="editModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
  279. <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
  280. <h3 class="text-2xl font-bold text-gray-800 mb-4">
  281. <i class="fas fa-edit text-blue-600 mr-2"></i>{{ _("Editar Delay Pool") }}
  282. </h3>
  283. <form id="editForm" method="POST" action="/admin/delay-pools/edit">
  284. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
  285. <input type="hidden" name="pool_number" id="editPoolNumber">
  286. <div class="mb-4">
  287. <label class="block text-gray-700 font-semibold mb-2">{{ _("Número de Pool:") }}</label>
  288. <input type="text" id="editPoolNumberDisplay" disabled
  289. class="w-full px-4 py-2 border border-gray-300 rounded-lg bg-gray-100 text-gray-600">
  290. </div>
  291. <div class="mb-4">
  292. <label class="block text-gray-700 font-semibold mb-2">{{ _("Clase de Pool:") }}</label>
  293. <select name="pool_class" id="editPoolClass" onchange="updateParametersHelp('edit')"
  294. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
  295. <option value="1">{{ _("Clase 1 - Bucket único agregado") }}</option>
  296. <option value="2">{{ _("Clase 2 - Agregado + por host (/24)") }}</option>
  297. <option value="3">{{ _("Clase 3 - Agregado + red + por host (/16)") }}</option>
  298. <option value="4">{{ _("Clase 4 - Como clase 3 + por usuario") }}</option>
  299. <option value="5">{{ _("Clase 5 - Basado en tags") }}</option>
  300. </select>
  301. </div>
  302. <div class="mb-4">
  303. <label class="block text-gray-700 font-semibold mb-2">{{ _("Parámetros:") }}</label>
  304. <textarea name="parameters" id="editParameters" rows="2"
  305. 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"
  306. required placeholder="64000/64000 -1/-1 16000/64000"></textarea>
  307. <p class="text-xs text-gray-500 mt-1" id="editParametersHelp">{{ _("Formato: restore/max (bytes/seg)") }}</p>
  308. </div>
  309. <div class="mb-4">
  310. <label class="block text-gray-700 font-semibold mb-2">{{ _("Reglas de Acceso:") }}</label>
  311. <div id="editAccessRules" class="space-y-2">
  312. <!-- Se llenarán dinámicamente -->
  313. </div>
  314. <button type="button" onclick="addAccessRule('edit')"
  315. class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
  316. <i class="fas fa-plus-circle mr-1"></i>{{ _("Agregar regla de acceso") }}
  317. </button>
  318. </div>
  319. <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
  320. <button type="button" onclick="closeEditModal()"
  321. class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
  322. {{ _("Cancelar") }}
  323. </button>
  324. <button type="submit"
  325. class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
  326. <i class="fas fa-save mr-2"></i>{{ _("Guardar Cambios") }}
  327. </button>
  328. </div>
  329. </form>
  330. </div>
  331. </div>
  332. <script>
  333. let addAccessRuleCounter = 0;
  334. let editAccessRuleCounter = 0;
  335. function showAddModal() {
  336. document.getElementById('addModal').classList.remove('hidden');
  337. document.getElementById('addForm').reset();
  338. document.getElementById('addAccessRules').innerHTML = '';
  339. document.getElementById('addParametersSection').classList.add('hidden');
  340. addAccessRuleCounter = 0;
  341. }
  342. function closeAddModal() {
  343. document.getElementById('addModal').classList.add('hidden');
  344. }
  345. function editPool(poolNumber, poolClass, parameters, accessRules) {
  346. document.getElementById('editPoolNumber').value = poolNumber;
  347. document.getElementById('editPoolNumberDisplay').value = 'Pool #' + poolNumber;
  348. document.getElementById('editPoolClass').value = poolClass;
  349. document.getElementById('editParameters').value = parameters || '';
  350. // Update parameters help text
  351. updateParametersHelp('edit');
  352. // Fill access rules
  353. const rulesContainer = document.getElementById('editAccessRules');
  354. rulesContainer.innerHTML = '';
  355. editAccessRuleCounter = 0;
  356. if (accessRules && accessRules.length > 0) {
  357. accessRules.forEach(rule => {
  358. addAccessRule('edit', rule.action, rule.acl);
  359. });
  360. }
  361. document.getElementById('editModal').classList.remove('hidden');
  362. }
  363. function closeEditModal() {
  364. document.getElementById('editModal').classList.add('hidden');
  365. }
  366. function updateParametersHelp(mode) {
  367. const classSelect = document.getElementById(mode + 'PoolClass');
  368. const selectedClass = classSelect.value;
  369. if (mode === 'add') {
  370. // Hide all parameter sections
  371. document.querySelectorAll('[id^="addClass"]').forEach(el => {
  372. if (el.id.includes('Params')) el.classList.add('hidden');
  373. });
  374. // Show parameters section
  375. const paramsSection = document.getElementById('addParametersSection');
  376. if (selectedClass) {
  377. paramsSection.classList.remove('hidden');
  378. // Show specific class parameters
  379. if (selectedClass === '1') {
  380. document.getElementById('addClass1Params').classList.remove('hidden');
  381. } else if (selectedClass === '2') {
  382. document.getElementById('addClass2Params').classList.remove('hidden');
  383. } else if (selectedClass === '3' || selectedClass === '4') {
  384. document.getElementById('addClass3Params').classList.remove('hidden');
  385. if (selectedClass === '4') {
  386. document.getElementById('addClass3Title').textContent = 'Clase 4:';
  387. document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host + por usuario autenticado';
  388. } else {
  389. document.getElementById('addClass3Title').textContent = 'Clase 3:';
  390. document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host';
  391. }
  392. } else if (selectedClass === '5') {
  393. document.getElementById('addClass5Params').classList.remove('hidden');
  394. }
  395. } else {
  396. paramsSection.classList.add('hidden');
  397. }
  398. } else {
  399. // Update edit help text
  400. const helpText = document.getElementById('editParametersHelp');
  401. if (selectedClass === '1') {
  402. helpText.textContent = 'Formato: aggregate_restore/aggregate_max';
  403. } else if (selectedClass === '2') {
  404. helpText.textContent = 'Formato: aggregate_restore/aggregate_max individual_restore/individual_max';
  405. } else if (selectedClass === '3' || selectedClass === '4') {
  406. helpText.textContent = 'Formato: aggregate_restore/aggregate_max network_restore/network_max individual_restore/individual_max';
  407. } else if (selectedClass === '5') {
  408. helpText.textContent = 'Formato: tag_restore/tag_max';
  409. }
  410. }
  411. }
  412. function addAccessRule(mode, action = 'allow', acl = '') {
  413. const container = document.getElementById(mode + 'AccessRules');
  414. const counter = mode === 'add' ? addAccessRuleCounter++ : editAccessRuleCounter++;
  415. const ruleDiv = document.createElement('div');
  416. ruleDiv.className = 'flex items-center space-x-2 bg-gray-50 p-2 rounded border border-gray-200';
  417. ruleDiv.id = mode + 'AccessRule' + counter;
  418. ruleDiv.innerHTML = `
  419. <select name="access_action[]" class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
  420. <option value="allow" ${action === 'allow' ? 'selected' : ''}>allow</option>
  421. <option value="deny" ${action === 'deny' ? 'selected' : ''}>deny</option>
  422. </select>
  423. <input type="text" name="access_acl[]" value="${acl}" placeholder="ACL names (ej: students !local)"
  424. class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  425. <button type="button" onclick="removeAccessRule('${mode}', ${counter})"
  426. class="text-red-600 hover:text-red-800 p-2">
  427. <i class="fas fa-times"></i>
  428. </button>
  429. `;
  430. container.appendChild(ruleDiv);
  431. }
  432. function removeAccessRule(mode, counter) {
  433. const ruleDiv = document.getElementById(mode + 'AccessRule' + counter);
  434. if (ruleDiv) {
  435. ruleDiv.remove();
  436. }
  437. }
  438. function deletePool(poolNumber) {
  439. 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).')) {
  440. const form = document.createElement('form');
  441. form.method = 'POST';
  442. form.action = '/admin/delay-pools/delete';
  443. const poolInput = document.createElement('input');
  444. poolInput.type = 'hidden';
  445. poolInput.name = 'pool_number';
  446. poolInput.value = poolNumber;
  447. const csrfInput = document.createElement('input');
  448. csrfInput.type = 'hidden';
  449. csrfInput.name = 'csrf_token';
  450. csrfInput.value = '{{ csrf_token() }}';
  451. form.appendChild(poolInput);
  452. form.appendChild(csrfInput);
  453. document.body.appendChild(form);
  454. form.submit();
  455. }
  456. }
  457. // Form submission handler for add form
  458. document.getElementById('addForm').addEventListener('submit', function(e) {
  459. e.preventDefault();
  460. const formData = new FormData(this);
  461. const poolClass = formData.get('pool_class');
  462. // Build parameters string based on class
  463. let parameters = '';
  464. if (poolClass === '1') {
  465. parameters = document.getElementById('addAggregateClass1').value;
  466. } else if (poolClass === '2') {
  467. const agg = document.getElementById('addAggregateClass2').value;
  468. const ind = document.getElementById('addIndividualClass2').value;
  469. parameters = `${agg} ${ind}`;
  470. } else if (poolClass === '3' || poolClass === '4') {
  471. const agg = document.getElementById('addAggregateClass3').value;
  472. const net = document.getElementById('addNetworkClass3').value;
  473. const ind = document.getElementById('addIndividualClass3').value;
  474. parameters = `${agg} ${net} ${ind}`;
  475. } else if (poolClass === '5') {
  476. parameters = document.getElementById('addTagClass5').value;
  477. }
  478. // Validate parameters
  479. if (!parameters.trim()) {
  480. alert('Por favor completa los parámetros de velocidad');
  481. return;
  482. }
  483. // Add parameters to form
  484. const paramsInput = document.createElement('input');
  485. paramsInput.type = 'hidden';
  486. paramsInput.name = 'parameters';
  487. paramsInput.value = parameters.trim();
  488. this.appendChild(paramsInput);
  489. this.submit();
  490. });
  491. </script>
  492. {% endblock %}