delay_pools.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. <div class="text-center py-12">
  133. <i class="fas fa-clock text-6xl text-gray-300 mb-4"></i>
  134. <p class="text-gray-500 text-lg">No hay delay pools configurados</p>
  135. <div class="mt-4 bg-blue-50 border border-blue-200 rounded-lg p-4 max-w-md mx-auto">
  136. <div class="flex items-start">
  137. <i class="fas fa-info-circle text-blue-600 mt-1 mr-3"></i>
  138. <div class="text-left text-sm">
  139. <p class="font-semibold text-blue-900 mb-1">¿Ya tienes delay pools configurados?</p>
  140. <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>
  141. <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>
  142. </div>
  143. </div>
  144. </div>
  145. <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">
  146. <i class="fas fa-plus mr-2"></i>Crear primer Pool
  147. </button>
  148. </div>
  149. {% endif %}
  150. </div>
  151. <!-- Add Modal -->
  152. <div id="addModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
  153. <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
  154. <h3 class="text-2xl font-bold text-gray-800 mb-4">
  155. <i class="fas fa-plus-circle text-blue-600 mr-2"></i>Agregar Nuevo Delay Pool
  156. </h3>
  157. <form id="addForm" method="POST" action="/admin/delay-pools/add">
  158. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
  159. <div class="mb-4">
  160. <label class="block text-gray-700 font-semibold mb-2">Número de Pool:</label>
  161. <input type="number" name="pool_number" id="addPoolNumber" min="1" max="255"
  162. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
  163. required placeholder="1">
  164. <p class="text-xs text-gray-500 mt-1">Número único del pool (1-255)</p>
  165. </div>
  166. <div class="mb-4">
  167. <label class="block text-gray-700 font-semibold mb-2">Clase de Pool:</label>
  168. <select name="pool_class" id="addPoolClass" onchange="updateParametersHelp('add')"
  169. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
  170. <option value="">Seleccione una clase...</option>
  171. <option value="1">Clase 1 - Bucket único agregado</option>
  172. <option value="2">Clase 2 - Agregado + por host (/24)</option>
  173. <option value="3">Clase 3 - Agregado + red + por host (/16)</option>
  174. <option value="4">Clase 4 - Como clase 3 + por usuario</option>
  175. <option value="5">Clase 5 - Basado en tags</option>
  176. </select>
  177. </div>
  178. <div id="addParametersSection" class="mb-4 hidden">
  179. <label class="block text-gray-700 font-semibold mb-2">Parámetros de Velocidad:</label>
  180. <!-- Clase 1 -->
  181. <div id="addClass1Params" class="hidden space-y-3">
  182. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  183. <strong>Clase 1:</strong> Un solo bucket agregado para todos los clientes
  184. </div>
  185. <div>
  186. <label class="text-sm font-medium text-gray-700">Agregado (restore/max en bytes/seg):</label>
  187. <input type="text" id="addAggregateClass1" placeholder="64000/64000"
  188. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  189. <p class="text-xs text-gray-500 mt-1">Ej: 64000/64000 = 512 Kbps</p>
  190. </div>
  191. </div>
  192. <!-- Clase 2 -->
  193. <div id="addClass2Params" class="hidden space-y-3">
  194. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  195. <strong>Clase 2:</strong> Bucket agregado + 255 buckets individuales por host
  196. </div>
  197. <div>
  198. <label class="text-sm font-medium text-gray-700">Agregado (restore/max):</label>
  199. <input type="text" id="addAggregateClass2" placeholder="64000/64000"
  200. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  201. </div>
  202. <div>
  203. <label class="text-sm font-medium text-gray-700">Individual por host (restore/max):</label>
  204. <input type="text" id="addIndividualClass2" placeholder="16000/64000"
  205. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  206. <p class="text-xs text-gray-500 mt-1">Usa -1/-1 para deshabilitar este bucket</p>
  207. </div>
  208. </div>
  209. <!-- Clase 3/4 -->
  210. <div id="addClass3Params" class="hidden space-y-3">
  211. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  212. <strong id="addClass3Title">Clase 3:</strong> <span id="addClass3Desc">Buckets por subred + por host</span>
  213. </div>
  214. <div>
  215. <label class="text-sm font-medium text-gray-700">Agregado (restore/max):</label>
  216. <input type="text" id="addAggregateClass3" placeholder="64000/64000"
  217. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  218. </div>
  219. <div>
  220. <label class="text-sm font-medium text-gray-700">Por red (restore/max):</label>
  221. <input type="text" id="addNetworkClass3" placeholder="8000/64000"
  222. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  223. <p class="text-xs text-gray-500 mt-1">Usa -1/-1 para deshabilitar</p>
  224. </div>
  225. <div>
  226. <label class="text-sm font-medium text-gray-700">Individual por host (restore/max):</label>
  227. <input type="text" id="addIndividualClass3" placeholder="2000/16000"
  228. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  229. </div>
  230. </div>
  231. <!-- Clase 5 -->
  232. <div id="addClass5Params" class="hidden space-y-3">
  233. <div class="bg-blue-50 p-3 rounded border border-blue-200 text-sm text-gray-700">
  234. <strong>Clase 5:</strong> Basado en tags de external_acl_type (un bucket por tag)
  235. </div>
  236. <div>
  237. <label class="text-sm font-medium text-gray-700">Parámetros por tag (restore/max):</label>
  238. <input type="text" id="addTagClass5" placeholder="16000/32000"
  239. class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  240. </div>
  241. </div>
  242. </div>
  243. <div class="mb-4">
  244. <label class="block text-gray-700 font-semibold mb-2">Reglas de Acceso (ACLs):</label>
  245. <div id="addAccessRules" class="space-y-2">
  246. <!-- Las reglas se agregarán dinámicamente -->
  247. </div>
  248. <button type="button" onclick="addAccessRule('add')"
  249. class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
  250. <i class="fas fa-plus-circle mr-1"></i>Agregar regla de acceso
  251. </button>
  252. </div>
  253. <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
  254. <button type="button" onclick="closeAddModal()"
  255. class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
  256. Cancelar
  257. </button>
  258. <button type="submit"
  259. class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
  260. <i class="fas fa-save mr-2"></i>Crear Pool
  261. </button>
  262. </div>
  263. </form>
  264. </div>
  265. </div>
  266. <!-- Edit Modal -->
  267. <div id="editModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
  268. <div class="bg-white rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto">
  269. <h3 class="text-2xl font-bold text-gray-800 mb-4">
  270. <i class="fas fa-edit text-blue-600 mr-2"></i>Editar Delay Pool
  271. </h3>
  272. <form id="editForm" method="POST" action="/admin/delay-pools/edit">
  273. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
  274. <input type="hidden" name="pool_number" id="editPoolNumber">
  275. <div class="mb-4">
  276. <label class="block text-gray-700 font-semibold mb-2">Número de Pool:</label>
  277. <input type="text" id="editPoolNumberDisplay" disabled
  278. class="w-full px-4 py-2 border border-gray-300 rounded-lg bg-gray-100 text-gray-600">
  279. </div>
  280. <div class="mb-4">
  281. <label class="block text-gray-700 font-semibold mb-2">Clase de Pool:</label>
  282. <select name="pool_class" id="editPoolClass" onchange="updateParametersHelp('edit')"
  283. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" required>
  284. <option value="1">Clase 1 - Bucket único agregado</option>
  285. <option value="2">Clase 2 - Agregado + por host (/24)</option>
  286. <option value="3">Clase 3 - Agregado + red + por host (/16)</option>
  287. <option value="4">Clase 4 - Como clase 3 + por usuario</option>
  288. <option value="5">Clase 5 - Basado en tags</option>
  289. </select>
  290. </div>
  291. <div class="mb-4">
  292. <label class="block text-gray-700 font-semibold mb-2">Parámetros:</label>
  293. <textarea name="parameters" id="editParameters" rows="2"
  294. 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"
  295. required placeholder="64000/64000 -1/-1 16000/64000"></textarea>
  296. <p class="text-xs text-gray-500 mt-1" id="editParametersHelp">Formato: restore/max (bytes/seg)</p>
  297. </div>
  298. <div class="mb-4">
  299. <label class="block text-gray-700 font-semibold mb-2">Reglas de Acceso:</label>
  300. <div id="editAccessRules" class="space-y-2">
  301. <!-- Se llenarán dinámicamente -->
  302. </div>
  303. <button type="button" onclick="addAccessRule('edit')"
  304. class="mt-2 text-blue-600 hover:text-blue-800 text-sm font-medium">
  305. <i class="fas fa-plus-circle mr-1"></i>Agregar regla de acceso
  306. </button>
  307. </div>
  308. <div class="flex space-x-2 justify-end mt-6 pt-4 border-t">
  309. <button type="button" onclick="closeEditModal()"
  310. class="px-5 py-2 bg-gray-300 hover:bg-gray-400 text-gray-800 rounded-lg transition-colors font-medium">
  311. Cancelar
  312. </button>
  313. <button type="submit"
  314. class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors font-medium">
  315. <i class="fas fa-save mr-2"></i>Guardar Cambios
  316. </button>
  317. </div>
  318. </form>
  319. </div>
  320. </div>
  321. <script>
  322. let addAccessRuleCounter = 0;
  323. let editAccessRuleCounter = 0;
  324. function showAddModal() {
  325. document.getElementById('addModal').classList.remove('hidden');
  326. document.getElementById('addForm').reset();
  327. document.getElementById('addAccessRules').innerHTML = '';
  328. document.getElementById('addParametersSection').classList.add('hidden');
  329. addAccessRuleCounter = 0;
  330. }
  331. function closeAddModal() {
  332. document.getElementById('addModal').classList.add('hidden');
  333. }
  334. function editPool(poolNumber, poolClass, parameters, accessRules) {
  335. document.getElementById('editPoolNumber').value = poolNumber;
  336. document.getElementById('editPoolNumberDisplay').value = 'Pool #' + poolNumber;
  337. document.getElementById('editPoolClass').value = poolClass;
  338. document.getElementById('editParameters').value = parameters || '';
  339. // Update parameters help text
  340. updateParametersHelp('edit');
  341. // Fill access rules
  342. const rulesContainer = document.getElementById('editAccessRules');
  343. rulesContainer.innerHTML = '';
  344. editAccessRuleCounter = 0;
  345. if (accessRules && accessRules.length > 0) {
  346. accessRules.forEach(rule => {
  347. addAccessRule('edit', rule.action, rule.acl);
  348. });
  349. }
  350. document.getElementById('editModal').classList.remove('hidden');
  351. }
  352. function closeEditModal() {
  353. document.getElementById('editModal').classList.add('hidden');
  354. }
  355. function updateParametersHelp(mode) {
  356. const classSelect = document.getElementById(mode + 'PoolClass');
  357. const selectedClass = classSelect.value;
  358. if (mode === 'add') {
  359. // Hide all parameter sections
  360. document.querySelectorAll('[id^="addClass"]').forEach(el => {
  361. if (el.id.includes('Params')) el.classList.add('hidden');
  362. });
  363. // Show parameters section
  364. const paramsSection = document.getElementById('addParametersSection');
  365. if (selectedClass) {
  366. paramsSection.classList.remove('hidden');
  367. // Show specific class parameters
  368. if (selectedClass === '1') {
  369. document.getElementById('addClass1Params').classList.remove('hidden');
  370. } else if (selectedClass === '2') {
  371. document.getElementById('addClass2Params').classList.remove('hidden');
  372. } else if (selectedClass === '3' || selectedClass === '4') {
  373. document.getElementById('addClass3Params').classList.remove('hidden');
  374. if (selectedClass === '4') {
  375. document.getElementById('addClass3Title').textContent = 'Clase 4:';
  376. document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host + por usuario autenticado';
  377. } else {
  378. document.getElementById('addClass3Title').textContent = 'Clase 3:';
  379. document.getElementById('addClass3Desc').textContent = 'Buckets por subred + por host';
  380. }
  381. } else if (selectedClass === '5') {
  382. document.getElementById('addClass5Params').classList.remove('hidden');
  383. }
  384. } else {
  385. paramsSection.classList.add('hidden');
  386. }
  387. } else {
  388. // Update edit help text
  389. const helpText = document.getElementById('editParametersHelp');
  390. if (selectedClass === '1') {
  391. helpText.textContent = 'Formato: aggregate_restore/aggregate_max';
  392. } else if (selectedClass === '2') {
  393. helpText.textContent = 'Formato: aggregate_restore/aggregate_max individual_restore/individual_max';
  394. } else if (selectedClass === '3' || selectedClass === '4') {
  395. helpText.textContent = 'Formato: aggregate_restore/aggregate_max network_restore/network_max individual_restore/individual_max';
  396. } else if (selectedClass === '5') {
  397. helpText.textContent = 'Formato: tag_restore/tag_max';
  398. }
  399. }
  400. }
  401. function addAccessRule(mode, action = 'allow', acl = '') {
  402. const container = document.getElementById(mode + 'AccessRules');
  403. const counter = mode === 'add' ? addAccessRuleCounter++ : editAccessRuleCounter++;
  404. const ruleDiv = document.createElement('div');
  405. ruleDiv.className = 'flex items-center space-x-2 bg-gray-50 p-2 rounded border border-gray-200';
  406. ruleDiv.id = mode + 'AccessRule' + counter;
  407. ruleDiv.innerHTML = `
  408. <select name="access_action[]" class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
  409. <option value="allow" ${action === 'allow' ? 'selected' : ''}>allow</option>
  410. <option value="deny" ${action === 'deny' ? 'selected' : ''}>deny</option>
  411. </select>
  412. <input type="text" name="access_acl[]" value="${acl}" placeholder="ACL names (ej: students !local)"
  413. class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono">
  414. <button type="button" onclick="removeAccessRule('${mode}', ${counter})"
  415. class="text-red-600 hover:text-red-800 p-2">
  416. <i class="fas fa-times"></i>
  417. </button>
  418. `;
  419. container.appendChild(ruleDiv);
  420. }
  421. function removeAccessRule(mode, counter) {
  422. const ruleDiv = document.getElementById(mode + 'AccessRule' + counter);
  423. if (ruleDiv) {
  424. ruleDiv.remove();
  425. }
  426. }
  427. function deletePool(poolNumber) {
  428. 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).')) {
  429. const form = document.createElement('form');
  430. form.method = 'POST';
  431. form.action = '/admin/delay-pools/delete';
  432. const poolInput = document.createElement('input');
  433. poolInput.type = 'hidden';
  434. poolInput.name = 'pool_number';
  435. poolInput.value = poolNumber;
  436. const csrfInput = document.createElement('input');
  437. csrfInput.type = 'hidden';
  438. csrfInput.name = 'csrf_token';
  439. csrfInput.value = '{{ csrf_token() }}';
  440. form.appendChild(poolInput);
  441. form.appendChild(csrfInput);
  442. document.body.appendChild(form);
  443. form.submit();
  444. }
  445. }
  446. // Form submission handler for add form
  447. document.getElementById('addForm').addEventListener('submit', function(e) {
  448. e.preventDefault();
  449. const formData = new FormData(this);
  450. const poolClass = formData.get('pool_class');
  451. // Build parameters string based on class
  452. let parameters = '';
  453. if (poolClass === '1') {
  454. parameters = document.getElementById('addAggregateClass1').value;
  455. } else if (poolClass === '2') {
  456. const agg = document.getElementById('addAggregateClass2').value;
  457. const ind = document.getElementById('addIndividualClass2').value;
  458. parameters = `${agg} ${ind}`;
  459. } else if (poolClass === '3' || poolClass === '4') {
  460. const agg = document.getElementById('addAggregateClass3').value;
  461. const net = document.getElementById('addNetworkClass3').value;
  462. const ind = document.getElementById('addIndividualClass3').value;
  463. parameters = `${agg} ${net} ${ind}`;
  464. } else if (poolClass === '5') {
  465. parameters = document.getElementById('addTagClass5').value;
  466. }
  467. // Validate parameters
  468. if (!parameters.trim()) {
  469. alert('Por favor completa los parámetros de velocidad');
  470. return;
  471. }
  472. // Add parameters to form
  473. const paramsInput = document.createElement('input');
  474. paramsInput.type = 'hidden';
  475. paramsInput.name = 'parameters';
  476. paramsInput.value = parameters.trim();
  477. this.appendChild(paramsInput);
  478. this.submit();
  479. });
  480. </script>
  481. {% endblock %}