4
0

acls.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. // ACL Type Information and Examples
  2. const aclTypeInfo = {
  3. // Network / IP
  4. 'src': {
  5. description: 'IP de origen del cliente. Puede incluir direcciones IP individuales, rangos CIDR o subredes.',
  6. example: 'acl localnet src 192.168.1.0/24 10.0.0.0/8',
  7. icon: 'network-wired',
  8. color: 'blue',
  9. slow: false
  10. },
  11. 'dst': {
  12. description: 'IP de destino (requiere búsqueda DNS inversa, puede ser lento).',
  13. example: 'acl servidores dst 10.0.0.5 10.0.0.6',
  14. icon: 'network-wired',
  15. color: 'blue',
  16. slow: true
  17. },
  18. 'localip': {
  19. description: 'IP local de la conexión proxy.',
  20. example: 'acl mipublic localip 203.0.113.45',
  21. icon: 'network-wired',
  22. color: 'blue',
  23. slow: false
  24. },
  25. 'src_as': {
  26. description: 'Autonomous System number de origen.',
  27. example: 'acl mi_as src_as 64512',
  28. icon: 'network-wired',
  29. color: 'blue',
  30. slow: false
  31. },
  32. 'dst_as': {
  33. description: 'Autonomous System number de destino.',
  34. example: 'acl redes_cdn dst_as 16509',
  35. icon: 'network-wired',
  36. color: 'blue',
  37. slow: false
  38. },
  39. // Domains
  40. 'dstdomain': {
  41. description: 'Dominio de destino. Soporta comodines con puntos al inicio.',
  42. example: 'acl sitios_permitidos dstdomain .example.com .google.com',
  43. icon: 'globe',
  44. color: 'green',
  45. slow: false
  46. },
  47. 'srcdomain': {
  48. description: 'Dominio de origen del cliente (requiere DNS inverso, lento).',
  49. example: 'acl red_interna srcdomain .mi-empresa.local',
  50. icon: 'globe',
  51. color: 'green',
  52. slow: true
  53. },
  54. 'dstdom_regex': {
  55. description: 'Expresión regular para coincidencia de dominios de destino.',
  56. example: 'acl redes_sociales dstdom_regex -i (facebook|twitter|instagram)\\.com',
  57. icon: 'globe',
  58. color: 'green',
  59. slow: false
  60. },
  61. 'srcdom_regex': {
  62. description: 'Expresión regular para dominios de origen (requiere DNS inverso).',
  63. example: 'acl externos srcdom_regex -i ^.*\\.external\\.com$',
  64. icon: 'globe',
  65. color: 'green',
  66. slow: true
  67. },
  68. // Ports
  69. 'port': {
  70. description: 'Puerto TCP de destino. Puede ser número o rango.',
  71. example: 'acl Safe_ports port 80 443 8080 21',
  72. icon: 'plug',
  73. color: 'cyan',
  74. slow: false
  75. },
  76. 'localport': {
  77. description: 'Puerto local en el que se recibió la conexión.',
  78. example: 'acl puerto_principal localport 3128',
  79. icon: 'plug',
  80. color: 'cyan',
  81. slow: false
  82. },
  83. 'myportname': {
  84. description: 'Nombre del puerto según http_port.',
  85. example: 'acl transparente myportname proxy_transparente',
  86. icon: 'plug',
  87. color: 'cyan',
  88. slow: false
  89. },
  90. // Time
  91. 'time': {
  92. description: 'Día de la semana y hora. Formato: [SMTWHAS][h1:m1-h2:m2]',
  93. example: 'acl horario_laboral time MTWHF 09:00-18:00',
  94. icon: 'clock',
  95. color: 'orange',
  96. slow: false
  97. },
  98. // URL
  99. 'url_regex': {
  100. description: 'Expresión regular que coincide con la URL completa.',
  101. example: 'acl anuncios url_regex -i \\.gif$ \\.jpg$ banner',
  102. icon: 'link',
  103. color: 'indigo',
  104. slow: false
  105. },
  106. 'urlpath_regex': {
  107. description: 'Expresión regular solo para el path de la URL.',
  108. example: 'acl descarga urlpath_regex -i \\.exe$ \\.zip$ \\.rar$',
  109. icon: 'link',
  110. color: 'indigo',
  111. slow: false
  112. },
  113. 'urllogin': {
  114. description: 'Expresión regular para el componente de login de la URL.',
  115. example: 'acl usuarios_externos urllogin -i ^guest.*',
  116. icon: 'link',
  117. color: 'indigo',
  118. slow: false
  119. },
  120. // Protocol
  121. 'proto': {
  122. description: 'Protocolo de la petición (HTTP, FTP, etc.).',
  123. example: 'acl protocolo_http proto HTTP',
  124. icon: 'exchange-alt',
  125. color: 'teal',
  126. slow: false
  127. },
  128. 'method': {
  129. description: 'Método HTTP de la petición.',
  130. example: 'acl CONNECT method CONNECT',
  131. icon: 'exchange-alt',
  132. color: 'teal',
  133. slow: false
  134. },
  135. 'http_status': {
  136. description: 'Código de estado HTTP en la respuesta.',
  137. example: 'acl errores_server http_status 500 502 503 504',
  138. icon: 'exchange-alt',
  139. color: 'teal',
  140. slow: false
  141. },
  142. // Authentication
  143. 'proxy_auth': {
  144. description: 'Usuario autenticado (requiere autenticación configurada).',
  145. example: 'acl usuarios_premium proxy_auth juan maria pedro',
  146. icon: 'user-lock',
  147. color: 'red',
  148. slow: true
  149. },
  150. 'proxy_auth_regex': {
  151. description: 'Expresión regular para nombre de usuario autenticado.',
  152. example: 'acl admins proxy_auth_regex -i ^admin',
  153. icon: 'user-lock',
  154. color: 'red',
  155. slow: true
  156. },
  157. 'ext_user': {
  158. description: 'Usuario provisto por helper externo.',
  159. example: 'acl usuarios_ldap ext_user juan maria',
  160. icon: 'user-lock',
  161. color: 'red',
  162. slow: true
  163. },
  164. 'ext_user_regex': {
  165. description: 'Expresión regular para usuarios de helper externo.',
  166. example: 'acl grupo_ventas ext_user_regex -i ^ventas_',
  167. icon: 'user-lock',
  168. color: 'red',
  169. slow: true
  170. },
  171. // Content
  172. 'browser': {
  173. description: 'Expresión regular para User-Agent del navegador.',
  174. example: 'acl bots browser -i (bot|crawler|spider)',
  175. icon: 'file-alt',
  176. color: 'yellow',
  177. slow: false
  178. },
  179. 'referer_regex': {
  180. description: 'Expresión regular para el header Referer.',
  181. example: 'acl desde_google referer_regex -i google\\.com',
  182. icon: 'file-alt',
  183. color: 'yellow',
  184. slow: false
  185. },
  186. 'req_mime_type': {
  187. description: 'Tipo MIME en el request.',
  188. example: 'acl upload_imagen req_mime_type image/jpeg image/png',
  189. icon: 'file-alt',
  190. color: 'yellow',
  191. slow: false
  192. },
  193. 'rep_mime_type': {
  194. description: 'Tipo MIME en la respuesta.',
  195. example: 'acl tipo_video rep_mime_type video/mp4 video/mpeg',
  196. icon: 'file-alt',
  197. color: 'yellow',
  198. slow: false
  199. },
  200. 'req_header': {
  201. description: 'Header específico del request.',
  202. example: 'acl api_key req_header X-API-Key',
  203. icon: 'file-alt',
  204. color: 'yellow',
  205. slow: false
  206. },
  207. 'rep_header': {
  208. description: 'Header específico de la respuesta.',
  209. example: 'acl con_cache rep_header Cache-Control',
  210. icon: 'file-alt',
  211. color: 'yellow',
  212. slow: false
  213. },
  214. // SSL/TLS
  215. 'ssl_error': {
  216. description: 'Código de error SSL/TLS.',
  217. example: 'acl ssl_expired ssl_error X509_V_ERR_CERT_HAS_EXPIRED',
  218. icon: 'lock',
  219. color: 'emerald',
  220. slow: false
  221. },
  222. 'server_cert_fingerprint': {
  223. description: 'Fingerprint del certificado del servidor.',
  224. example: 'acl cert_confiable server_cert_fingerprint AA:BB:CC:DD',
  225. icon: 'lock',
  226. color: 'emerald',
  227. slow: false
  228. },
  229. 'ssl::server_name': {
  230. description: 'Server Name Indication (SNI) en conexiones TLS.',
  231. example: 'acl sitio_seguro ssl::server_name .example.com',
  232. icon: 'lock',
  233. color: 'emerald',
  234. slow: false
  235. },
  236. 'ssl::server_name_regex': {
  237. description: 'Expresión regular para SNI.',
  238. example: 'acl bancos ssl::server_name_regex -i banco.*\\.com$',
  239. icon: 'lock',
  240. color: 'emerald',
  241. slow: false
  242. },
  243. // Connections
  244. 'maxconn': {
  245. description: 'Límite máximo de conexiones por IP.',
  246. example: 'acl max_10 maxconn 10',
  247. icon: 'server',
  248. color: 'pink',
  249. slow: false
  250. },
  251. 'max_user_ip': {
  252. description: 'Límite máximo de IPs diferentes por usuario.',
  253. example: 'acl max_3_ips max_user_ip 3',
  254. icon: 'server',
  255. color: 'pink',
  256. slow: false
  257. },
  258. // Advanced
  259. 'external': {
  260. description: 'Helper externo personalizado (puede ser muy lento).',
  261. example: 'acl verificado external checker_script %DST',
  262. icon: 'cogs',
  263. color: 'gray',
  264. slow: true
  265. },
  266. 'random': {
  267. description: 'Probabilidad aleatoria (0.0 a 1.0).',
  268. example: 'acl un_tercio random 0.333',
  269. icon: 'cogs',
  270. color: 'gray',
  271. slow: false
  272. },
  273. 'note': {
  274. description: 'Anotación de transacción.',
  275. example: 'acl tiene_nota note importante',
  276. icon: 'cogs',
  277. color: 'gray',
  278. slow: false
  279. },
  280. 'any-of': {
  281. description: 'Grupo de ACLs con lógica OR (coincide si alguna es verdadera).',
  282. example: 'acl grupo any-of acl1 acl2 acl3',
  283. icon: 'cogs',
  284. color: 'gray',
  285. slow: false
  286. },
  287. 'all-of': {
  288. description: 'Grupo de ACLs con lógica AND (coincide si todas son verdaderas).',
  289. example: 'acl combinado all-of acl1 acl2',
  290. icon: 'cogs',
  291. color: 'gray',
  292. slow: false
  293. }
  294. };
  295. let addValueCounter = 0;
  296. let editValueCounter = 0;
  297. // Show Add Modal
  298. function showAddModal() {
  299. document.getElementById('addModal').classList.remove('hidden');
  300. document.getElementById('addForm').reset();
  301. document.getElementById('addValuesList').innerHTML = '';
  302. document.getElementById('addTypeInfo').classList.add('hidden');
  303. addValueCounter = 0;
  304. addValueInput('add'); // Add one value input by default
  305. }
  306. // Close Add Modal
  307. function closeAddModal() {
  308. document.getElementById('addModal').classList.add('hidden');
  309. }
  310. // Update type information in add modal
  311. function updateAddTypeInfo() {
  312. const typeSelect = document.getElementById('addType');
  313. const selectedType = typeSelect.value;
  314. const infoDiv = document.getElementById('addTypeInfo');
  315. if (!selectedType || !aclTypeInfo[selectedType]) {
  316. infoDiv.classList.add('hidden');
  317. return;
  318. }
  319. const info = aclTypeInfo[selectedType];
  320. document.getElementById('addTypeDesc').textContent = info.description;
  321. document.getElementById('addTypeExample').textContent = 'Ejemplo: ' + info.example;
  322. // Change icon color based on slow/fast
  323. const iconEl = document.getElementById('addTypeIcon');
  324. if (info.slow) {
  325. iconEl.className = 'fas fa-hourglass text-orange-600 mt-1 mr-2';
  326. } else {
  327. iconEl.className = 'fas fa-bolt text-green-600 mt-1 mr-2';
  328. }
  329. infoDiv.classList.remove('hidden');
  330. }
  331. // Add value input field
  332. function addValueInput(mode) {
  333. const listId = mode === 'add' ? 'addValuesList' : 'editValuesList';
  334. const list = document.getElementById(listId);
  335. if (mode === 'add') {
  336. addValueCounter++;
  337. } else {
  338. editValueCounter++;
  339. }
  340. const counter = mode === 'add' ? addValueCounter : editValueCounter;
  341. const div = document.createElement('div');
  342. div.className = 'flex items-center space-x-2';
  343. div.id = `${mode}Value${counter}`;
  344. div.innerHTML = `
  345. <input type="text" name="values[]" required
  346. placeholder="Ingresa un valor (ej: 192.168.1.0/24, .example.com, 80)"
  347. class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm">
  348. <button type="button" onclick="removeValueInput('${mode}', ${counter})"
  349. class="px-3 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg transition-colors">
  350. <i class="fas fa-trash"></i>
  351. </button>
  352. `;
  353. list.appendChild(div);
  354. }
  355. // Remove value input field
  356. function removeValueInput(mode, counter) {
  357. const div = document.getElementById(`${mode}Value${counter}`);
  358. if (div) {
  359. div.remove();
  360. }
  361. }
  362. // Edit ACL
  363. function editAcl(id, name, type, valueList, options, comment) {
  364. document.getElementById('editModal').classList.remove('hidden');
  365. document.getElementById('editId').value = id;
  366. document.getElementById('editName').value = name;
  367. document.getElementById('editType').value = type;
  368. document.getElementById('editTypeDisplay').value = type;
  369. document.getElementById('editComment').value = comment || '';
  370. // Set options checkboxes
  371. document.getElementById('editOptI').checked = options.includes('-i');
  372. document.getElementById('editOptN').checked = options.includes('-n');
  373. document.getElementById('editOptM').checked = options.includes('-m');
  374. // Clear and populate values
  375. const valuesList = document.getElementById('editValuesList');
  376. valuesList.innerHTML = '';
  377. editValueCounter = 0;
  378. if (valueList && valueList.length > 0) {
  379. valueList.forEach(value => {
  380. editValueCounter++;
  381. const div = document.createElement('div');
  382. div.className = 'flex items-center space-x-2';
  383. div.id = `editValue${editValueCounter}`;
  384. div.innerHTML = `
  385. <input type="text" name="values[]" required value="${value}"
  386. class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm">
  387. <button type="button" onclick="removeValueInput('edit', ${editValueCounter})"
  388. class="px-3 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg transition-colors">
  389. <i class="fas fa-trash"></i>
  390. </button>
  391. `;
  392. valuesList.appendChild(div);
  393. });
  394. } else {
  395. addValueInput('edit');
  396. }
  397. }
  398. // Close Edit Modal
  399. function closeEditModal() {
  400. document.getElementById('editModal').classList.add('hidden');
  401. }
  402. // Delete ACL
  403. function deleteAcl(id, name) {
  404. if (!confirm(`¿Estás seguro de que deseas eliminar la ACL "${name}"?\n\nEsto puede afectar las reglas de http_access y delay_pools que la utilicen.`)) {
  405. return;
  406. }
  407. const form = document.createElement('form');
  408. form.method = 'POST';
  409. form.action = '/admin/acls/delete';
  410. // CSRF token
  411. const csrfInput = document.createElement('input');
  412. csrfInput.type = 'hidden';
  413. csrfInput.name = 'csrf_token';
  414. csrfInput.value = document.querySelector('input[name="csrf_token"]').value;
  415. form.appendChild(csrfInput);
  416. // ACL ID
  417. const idInput = document.createElement('input');
  418. idInput.type = 'hidden';
  419. idInput.name = 'id';
  420. idInput.value = id;
  421. form.appendChild(idInput);
  422. document.body.appendChild(form);
  423. form.submit();
  424. }
  425. // Close modals on ESC key
  426. document.addEventListener('keydown', function(event) {
  427. if (event.key === 'Escape') {
  428. closeAddModal();
  429. closeEditModal();
  430. }
  431. });
  432. // Close modals when clicking outside
  433. document.getElementById('addModal')?.addEventListener('click', function(event) {
  434. if (event.target === this) {
  435. closeAddModal();
  436. }
  437. });
  438. document.getElementById('editModal')?.addEventListener('click', function(event) {
  439. if (event.target === this) {
  440. closeEditModal();
  441. }
  442. });