kerberos_config.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. {% extends 'admin/base.html' %}
  2. {% block title %}{{ _('Kerberos / SPNEGO | Admin Squid') }}{% endblock %}
  3. {% block content %}
  4. {% set settings = kerberos.settings %}
  5. {% set preflight = kerberos.preflight %}
  6. {% set docker_config = preflight.get('docker_config') %}
  7. {% set squid_writes_manual = preflight.config.get('write_mode') == 'manual' %}
  8. <div class="max-w-7xl mx-auto space-y-6">
  9. <div class="bg-white rounded-lg border border-gray-200 shadow p-6">
  10. <div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
  11. <div>
  12. <h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
  13. <i class="fas fa-ticket-alt text-indigo-600"></i>
  14. {{ _('Autenticación Kerberos / SPNEGO') }}
  15. </h2>
  16. <p class="mt-1 text-sm text-gray-600">
  17. {{ _('Configura el helper Negotiate de Squid. LDAP del panel y Kerberos del proxy son configuraciones independientes.') }}
  18. </p>
  19. </div>
  20. {% if kerberos.detected and kerberos.managed %}
  21. <span class="inline-flex items-center gap-2 rounded-full bg-emerald-100 px-3 py-1.5 text-sm font-semibold text-emerald-800">
  22. <i class="fas fa-check-circle"></i>{{ _('Administrado por SquidStats') }}
  23. </span>
  24. {% elif kerberos.detected %}
  25. <span class="inline-flex items-center gap-2 rounded-full bg-amber-100 px-3 py-1.5 text-sm font-semibold text-amber-800">
  26. <i class="fas fa-exclamation-triangle"></i>{{ _('Configuración manual detectada') }}
  27. </span>
  28. {% else %}
  29. <span class="inline-flex items-center gap-2 rounded-full bg-gray-100 px-3 py-1.5 text-sm font-semibold text-gray-700">
  30. <i class="fas fa-minus-circle"></i>{{ _('No configurado') }}
  31. </span>
  32. {% endif %}
  33. </div>
  34. </div>
  35. <div class="rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900 flex gap-3">
  36. <i class="fas fa-shield-alt mt-0.5 text-blue-600"></i>
  37. <p>{{ _('El keytab no se sube, no se copia ni se muestra aquí. Debe existir ya en el runtime donde se ejecuta Squid (host o contenedor); este formulario solo guarda su ruta en squid.conf.') }}</p>
  38. </div>
  39. {% if squid_writes_manual %}
  40. <div class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 flex gap-3">
  41. <i class="fas fa-lock mt-0.5"></i>
  42. <p>{{ _('Este despliegue está en modo manual para squid.conf. La unidad Debian incluida usa este modo para proteger /etc/squid; puedes generar y copiar la vista previa para aplicarla mediante el procedimiento administrativo controlado. Los botones de escritura permanecen deshabilitados.') }}</p>
  43. </div>
  44. {% endif %}
  45. {% if kerberos.configuration_error %}
  46. <div class="rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800 flex gap-3">
  47. <i class="fas fa-exclamation-circle mt-0.5"></i>
  48. <p>{{ kerberos.configuration_error }}</p>
  49. </div>
  50. {% endif %}
  51. {% if kerberos.form_error %}
  52. <div class="rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800 flex gap-3" role="alert">
  53. <i class="fas fa-exclamation-circle mt-0.5"></i>
  54. <p>{{ kerberos.form_error }}</p>
  55. </div>
  56. {% endif %}
  57. {% if kerberos.unmanaged_negotiate %}
  58. <div class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 flex gap-3">
  59. <i class="fas fa-exclamation-triangle mt-0.5"></i>
  60. <p>{{ _('Se detectó una directiva Negotiate que no administra SquidStats. Revisa su fuente: esta pantalla solo puede reemplazar de forma segura squid.conf o 50_auth.conf; un include distinto debe migrarse manualmente antes de aplicar.') }}</p>
  61. </div>
  62. {% endif %}
  63. {% if kerberos.inactive_conventional_sources %}
  64. <div class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 flex gap-3">
  65. <i class="fas fa-unlink mt-0.5"></i>
  66. <p>{{ _('Se encontraron bloques Kerberos en módulos que no están incluidos activamente:') }} <code>{{ kerberos.inactive_conventional_sources|join(', ') }}</code>. {{ _('No se están aplicando; revisa el include antes de activarlos o elimina los bloques obsoletos.') }}</p>
  67. </div>
  68. {% endif %}
  69. {% if kerberos.other_auth_schemes %}
  70. <div class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 flex gap-3">
  71. <i class="fas fa-exclamation-triangle mt-0.5"></i>
  72. <p>{{ _('Se detectaron helpers de autenticación alternativos:') }} <code>{{ kerberos.other_auth_schemes|join(', ') }}</code>. {{ _('La pantalla Kerberos no los combina automáticamente; revísalos antes de aplicar.') }}</p>
  73. </div>
  74. {% endif %}
  75. <div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
  76. <section class="xl:col-span-2 bg-white rounded-lg border border-gray-200 shadow p-6">
  77. <form id="kerberos-config-form" method="POST" class="space-y-6">
  78. <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
  79. <input type="hidden" name="action" value="apply" />
  80. <div class="flex items-start gap-3 rounded-lg bg-gray-50 p-4">
  81. <input type="hidden" name="enabled" value="false" />
  82. <input id="kerberos-enabled" name="enabled" value="true" type="checkbox"
  83. {% if settings.enabled %}checked{% endif %}
  84. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  85. <div>
  86. <label for="kerberos-enabled" class="font-semibold text-gray-800">{{ _('Habilitar Kerberos / Negotiate') }}</label>
  87. <p class="mt-1 text-sm text-gray-600">{{ _('Requiere un proxy explícito, DNS/FQDN y un SPN que coincidan con el keytab.') }}</p>
  88. </div>
  89. </div>
  90. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  91. <div>
  92. <label for="helper-path" class="mb-1 block text-sm font-medium text-gray-700">{{ _('Ruta del helper') }}</label>
  93. <input id="helper-path" name="helper_path" type="text" autocomplete="off" data-kerberos-required
  94. value="{{ settings.helper_path }}" placeholder="/usr/lib/squid/negotiate_kerberos_auth"
  95. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm font-mono focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  96. <p class="mt-1 text-xs text-gray-500">{{ _('En RHEL suele ser /usr/lib64/squid/…; comprueba la ruta instalada.') }}</p>
  97. </div>
  98. <div>
  99. <label for="keytab-path" class="mb-1 block text-sm font-medium text-gray-700">{{ _('Ruta del keytab existente') }}</label>
  100. <input id="keytab-path" name="keytab_path" type="text" autocomplete="off" data-kerberos-required
  101. value="{{ settings.keytab_path }}" placeholder="/var/run/squid/HTTP.keytab"
  102. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm font-mono focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  103. <p class="mt-1 text-xs text-gray-500">{{ _('Usa una ruta persistente si /var/run se limpia al reiniciar.') }}</p>
  104. </div>
  105. <div class="md:col-span-2">
  106. <label for="service-principal" class="mb-1 block text-sm font-medium text-gray-700">{{ _('SPN del servicio') }}</label>
  107. <input id="service-principal" name="service_principal" type="text" autocomplete="off" spellcheck="false" data-kerberos-required
  108. value="{{ settings.service_principal }}" placeholder="HTTP/inutil.cu@INUTIL.CU"
  109. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm font-mono focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  110. <p class="mt-1 text-xs text-gray-500">{{ _('Usa el SPN completo recomendado (HTTP/proxy.ejemplo@REALM). HTTP/proxy.ejemplo sin realm solo sirve si Kerberos resuelve el realm predeterminado; no uses barras de escape.') }}</p>
  111. </div>
  112. </div>
  113. <fieldset class="rounded-lg border border-gray-200 p-4">
  114. <legend class="px-1 text-sm font-semibold text-gray-800">{{ _('Procesos del helper') }}</legend>
  115. <div class="mt-2 grid grid-cols-1 sm:grid-cols-3 gap-4">
  116. <div>
  117. <label for="children" class="mb-1 block text-sm text-gray-700">children</label>
  118. <input id="children" name="children" type="number" min="1" max="128" value="{{ settings.children }}" data-kerberos-required
  119. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  120. </div>
  121. <div>
  122. <label for="startup" class="mb-1 block text-sm text-gray-700">startup</label>
  123. <input id="startup" name="startup" type="number" min="0" max="128" value="{{ settings.startup }}" data-kerberos-required
  124. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  125. </div>
  126. <div>
  127. <label for="idle" class="mb-1 block text-sm text-gray-700">idle</label>
  128. <input id="idle" name="idle" type="number" min="0" max="128" value="{{ settings.idle }}" data-kerberos-required
  129. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  130. </div>
  131. </div>
  132. <p class="mt-3 text-xs text-gray-500">{{ _('startup e idle no pueden superar children. Ajusta la capacidad después de medir la carga real.') }}</p>
  133. </fieldset>
  134. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  135. <div>
  136. <label for="acl-name" class="mb-1 block text-sm font-medium text-gray-700">{{ _('Nombre de ACL') }}</label>
  137. <input id="acl-name" name="acl_name" type="text" autocomplete="off" value="{{ settings.acl_name }}" data-kerberos-required
  138. class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm font-mono focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-200" />
  139. </div>
  140. <div class="space-y-3 pt-1">
  141. <div class="flex items-start gap-2">
  142. <input type="hidden" name="keep_alive" value="false" />
  143. <input id="keep-alive" name="keep_alive" value="true" type="checkbox" {% if settings.keep_alive %}checked{% endif %}
  144. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  145. <label for="keep-alive" class="text-sm text-gray-700">{{ _('Mantener conexiones del helper activas (keep_alive)') }}</label>
  146. </div>
  147. <div class="flex items-start gap-2">
  148. <input type="hidden" name="strip_realm" value="false" />
  149. <input id="strip-realm" name="strip_realm" value="true" type="checkbox" {% if settings.strip_realm %}checked{% endif %}
  150. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  151. <label for="strip-realm" class="text-sm text-gray-700">{{ _('Quitar el realm del usuario devuelto (-r)') }}</label>
  152. </div>
  153. <p class="text-xs text-gray-500">{{ _('Con -r, logs y cuotas usan normalmente usuario; sin -r usan normalmente usuario@REALM.') }}</p>
  154. </div>
  155. </div>
  156. <fieldset class="rounded-lg border border-indigo-100 bg-indigo-50 p-4 space-y-3">
  157. <legend class="px-1 text-sm font-semibold text-indigo-900">{{ _('Política de acceso') }}</legend>
  158. <div class="flex items-start gap-2">
  159. <input type="hidden" name="enforce_auth" value="false" />
  160. <input id="enforce-auth" name="enforce_auth" value="true" type="checkbox" {% if settings.enforce_auth %}checked{% endif %}
  161. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  162. <label for="enforce-auth" class="text-sm text-indigo-950">
  163. {{ _('Exigir autenticación antes de las reglas allow de clientes') }}
  164. <span class="block mt-1 text-xs text-indigo-700">{{ _('Genera http_access deny !ACL después de los deny de seguridad y antes del primer allow de clientes; conserva la política de autorización que ya existe.') }}</span>
  165. </label>
  166. </div>
  167. <div class="flex items-start gap-2">
  168. <input type="hidden" name="replace_existing_negotiate" value="false" />
  169. <input id="replace-existing" name="replace_existing_negotiate" value="true" type="checkbox" {% if settings.replace_existing_negotiate %}checked{% endif %}
  170. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  171. <label for="replace-existing" class="text-sm text-indigo-950">
  172. {{ _('Reemplazar directivas Negotiate existentes') }}
  173. <span class="block mt-1 text-xs text-indigo-700">{{ _('Úsalo solo después de revisar una configuración manual detectada. Reemplaza también la ACL REQUIRED y la regla http_access con el mismo nombre; no combina helpers alternativos.') }}</span>
  174. </label>
  175. </div>
  176. <div class="flex items-start gap-2">
  177. <input type="hidden" name="reload_squid" value="false" />
  178. <input id="reload-squid" name="reload_squid" value="true" type="checkbox" {% if settings.reload_squid %}checked{% endif %}
  179. class="mt-1 h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />
  180. <label for="reload-squid" class="text-sm text-indigo-950">
  181. {{ _('Validar y recargar Squid al aplicar') }}
  182. <span class="block mt-1 text-xs text-indigo-700">{{ _('Si el proceso no tiene permisos para recargar, desmárcalo y haz la recarga manualmente después de validar.') }}</span>
  183. </label>
  184. </div>
  185. </fieldset>
  186. <div class="flex flex-col-reverse gap-3 sm:flex-row sm:justify-between">
  187. <button id="update-preview" type="button" class="rounded-lg border border-indigo-300 bg-white px-4 py-2.5 text-sm font-semibold text-indigo-700 hover:bg-indigo-50">
  188. <i class="fas fa-code mr-1"></i>{{ _('Actualizar vista previa') }}
  189. </button>
  190. <div class="flex flex-col gap-3 sm:flex-row">
  191. <button type="submit" name="action" value="apply"
  192. class="rounded-lg bg-indigo-600 px-4 py-2.5 text-sm font-semibold text-white shadow hover:bg-indigo-700 disabled:cursor-not-allowed disabled:opacity-50"
  193. {% if squid_writes_manual %}disabled aria-disabled="true" title="{{ _('La unidad Debian está en modo manual para squid.conf.') }}"{% endif %}>
  194. <i class="fas fa-save mr-1"></i>{{ _('Validar y aplicar') }}
  195. </button>
  196. <button type="submit" name="action" value="disable" formnovalidate
  197. class="rounded-lg border border-red-300 bg-white px-4 py-2.5 text-sm font-semibold text-red-700 hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-50"
  198. {% if squid_writes_manual %}disabled aria-disabled="true" title="{{ _('La unidad Debian está en modo manual para squid.conf.') }}"{% endif %}
  199. onclick="return confirm({{ _('¿Retirar solo los bloques Kerberos administrados?')|tojson }});">
  200. <i class="fas fa-power-off mr-1"></i>{{ _('Deshabilitar y retirar bloques') }}
  201. </button>
  202. </div>
  203. </div>
  204. <p class="text-xs text-gray-500">{{ _('Deshabilitar elimina solamente los bloques administrados y requiere reiniciar Squid para descargar el esquema de autenticación.') }}</p>
  205. </form>
  206. </section>
  207. <aside class="space-y-6">
  208. <section class="bg-white rounded-lg border border-gray-200 shadow p-5">
  209. <h3 class="font-semibold text-gray-800 flex items-center gap-2"><i class="fas fa-stethoscope text-indigo-600"></i>{{ _('Comprobaciones del servidor') }}</h3>
  210. <dl class="mt-4 space-y-3 text-sm">
  211. <div class="flex justify-between gap-3"><dt class="text-gray-500">squid.conf</dt><dd class="text-right font-mono text-xs text-gray-800 break-all">{{ preflight.config.path }}</dd></div>
  212. <div class="flex justify-between gap-3">
  213. <dt class="text-gray-500">{{ _('Fuente Kerberos') }}</dt>
  214. <dd class="text-right text-xs text-gray-800 break-all">
  215. {% if kerberos.detected %}
  216. <code class="font-mono">{{ kerberos.source }}</code>
  217. <span class="ml-1 {{ 'text-emerald-700' if kerberos.managed else 'text-amber-700' }}">{{ _('Administrada') if kerberos.managed else _('Manual') }}</span>
  218. {% else %}
  219. <span class="text-gray-500">{{ _('No se detectaron directivas activas') }}</span>
  220. {% endif %}
  221. </dd>
  222. </div>
  223. <div class="flex justify-between gap-3">
  224. <dt class="text-gray-500">{{ _('Destino administrado') }}</dt>
  225. <dd class="text-right font-mono text-xs text-gray-800 break-all">{{ '50_auth.conf + 120_http_access.conf' if preflight.config.modular else 'squid.conf' }}</dd>
  226. </div>
  227. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Escritura') }}</dt><dd class="font-medium {{ 'text-amber-700' if squid_writes_manual else 'text-emerald-700' if preflight.config.writable else 'text-red-700' }}">{{ _('Solo manual') if squid_writes_manual else _('Disponible') if preflight.config.writable else _('Sin permiso') }}</dd></div>
  228. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Formato') }}</dt><dd class="font-medium text-gray-800">{{ _('Modular') if preflight.config.modular else _('Único archivo') }}</dd></div>
  229. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Usuario de Squid') }}</dt><dd class="text-right font-medium text-gray-800">{{ preflight.squid_user or _('No declarado') }}{% if preflight.squid_user_source == 'build_default' %}<span class="block text-xs font-normal text-gray-500">{{ _('predeterminado compilado') }}</span>{% endif %}</dd></div>
  230. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Runtime Squid') }}</dt><dd class="text-right font-medium {{ 'text-emerald-700' if preflight.runtime.available else 'text-amber-700' }}">{% if not preflight.runtime.available %}{{ _('No detectado') }}{% elif preflight.runtime.kind == 'docker' %}Docker{% if preflight.runtime.container %}: {{ preflight.runtime.container }}{% endif %}{% else %}{{ _('Local') }}{% endif %}</dd></div>
  231. {% if preflight.runtime.kind == 'docker' or docker_config %}
  232. <div class="flex justify-between gap-3">
  233. <dt class="text-gray-500">{{ _('Montaje Docker') }}</dt>
  234. <dd class="text-right font-medium {{ 'text-emerald-700' if docker_config and docker_config.mapped is true else 'text-red-700' if docker_config and docker_config.mapped is false else 'text-amber-700' }}">
  235. {% if docker_config and docker_config.mapped is true %}{{ _('Verificado') }}{% elif docker_config and docker_config.mapped is false %}{{ _('No coincide') }}{% else %}{{ _('Sin comprobar') }}{% endif %}
  236. </dd>
  237. </div>
  238. {% if docker_config and docker_config.container_config_path %}
  239. <div class="flex justify-between gap-3">
  240. <dt class="text-gray-500">{{ _('Squid carga en Docker') }}</dt>
  241. <dd class="text-right font-mono text-xs text-gray-800 break-all">{{ docker_config.container_config_path }}</dd>
  242. </div>
  243. {% endif %}
  244. {% if docker_config and docker_config.container_path and docker_config.container_path != docker_config.container_config_path %}
  245. <div class="flex justify-between gap-3">
  246. <dt class="text-gray-500">{{ _('El volumen expone') }}</dt>
  247. <dd class="text-right font-mono text-xs text-red-700 break-all">{{ docker_config.container_path }}</dd>
  248. </div>
  249. {% endif %}
  250. {% if docker_config and docker_config.symlink %}
  251. <div class="text-xs text-gray-500">{{ _('El squid.conf del host es un enlace simbólico; se comprobó su destino resuelto.') }}</div>
  252. {% endif %}
  253. {% endif %}
  254. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Versión Squid') }}</dt><dd class="font-medium {{ 'text-red-700' if preflight.squid_version.supports_auth_param is false else 'text-gray-800' }}">{% if preflight.squid_version.version %}{{ preflight.squid_version.version }}{% elif preflight.squid_version.checked %}{{ _('No reconocida') }}{% else %}{{ _('Sin comprobar') }}{% endif %}</dd></div>
  255. <div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Proxy explícito') }}</dt><dd class="font-medium {{ 'text-red-700' if preflight.proxy_mode.explicit_proxy_available is false else 'text-emerald-700' }}">{% if preflight.proxy_mode.explicit_proxy_available is none %}{{ _('Sin comprobar') }}{% elif preflight.proxy_mode.explicit_proxy_available %}{{ _('Sí') }}{% else %}{{ _('No') }}{% endif %}</dd></div>
  256. {% if preflight.proxy_mode.incompatible_ports %}<div class="flex justify-between gap-3"><dt class="text-gray-500">{{ _('Puertos no compatibles') }}</dt><dd class="font-medium text-red-700">{{ preflight.proxy_mode.incompatible_ports }}</dd></div>{% endif %}
  257. </dl>
  258. </section>
  259. {% if preflight.helper or preflight.keytab %}
  260. <section class="bg-white rounded-lg border border-gray-200 shadow p-5">
  261. <h3 class="font-semibold text-gray-800 flex items-center gap-2"><i class="fas fa-key text-indigo-600"></i>{{ _('Helper y keytab') }}</h3>
  262. <dl class="mt-4 space-y-3 text-sm">
  263. <div><dt class="text-gray-500">{{ _('Helper') }}</dt><dd class="mt-1 break-all font-mono text-xs text-gray-800">{{ preflight.helper.path }}</dd><dd class="mt-1 {{ 'text-emerald-700' if preflight.helper.exists and preflight.helper.executable else 'text-red-700' }}">{{ _('Existe y es ejecutable') if preflight.helper.exists and preflight.helper.executable else _('No disponible o no ejecutable') }}</dd>{% if preflight.helper.checked_in_runtime %}<dd class="mt-1 text-xs text-gray-500">{{ _('Comprobado dentro del contenedor') }}</dd>{% endif %}</div>
  264. <div><dt class="text-gray-500">Keytab</dt><dd class="mt-1 break-all font-mono text-xs text-gray-800">{{ preflight.keytab.path }}</dd><dd class="mt-1 {{ 'text-emerald-700' if preflight.keytab.exists and preflight.keytab.regular_file else 'text-red-700' }}">{{ _('Archivo encontrado') if preflight.keytab.exists and preflight.keytab.regular_file else _('Archivo no encontrado') }}</dd>{% if preflight.keytab.checked_in_runtime %}<dd class="mt-1 text-xs text-gray-500">{{ _('Comprobado dentro del contenedor') }}</dd>{% endif %}{% if preflight.keytab.mode %}<dd class="mt-1 text-xs text-gray-500">{{ _('Modo') }} {{ preflight.keytab.mode }}</dd>{% endif %}{% if preflight.keytab.squid_user_readable is not none %}<dd class="mt-1 text-xs {{ 'text-emerald-700' if preflight.keytab.squid_user_readable else 'text-amber-700' }}">{{ _('Acceso Unix para') }} {{ preflight.keytab.squid_user }}: {{ _('probable') if preflight.keytab.squid_user_readable else _('revisar permisos') }}</dd>{% endif %}</div>
  265. <div><dt class="text-gray-500">SPN</dt><dd class="mt-1 {{ 'text-emerald-700' if preflight.keytab.spn_present else 'text-amber-700' }}">{% if preflight.keytab.spn_checked %}{{ _('Presente') if preflight.keytab.spn_present else _('No encontrado') }}{% else %}{{ _('No comprobado con klist') }}{% endif %}</dd></div>
  266. </dl>
  267. </section>
  268. {% endif %}
  269. {% if preflight.errors %}
  270. <section class="rounded-lg border border-red-200 bg-red-50 p-5 text-sm text-red-800">
  271. <h3 class="font-semibold flex items-center gap-2"><i class="fas fa-times-circle"></i>{{ _('Bloqueos antes de aplicar') }}</h3>
  272. <ul class="mt-3 list-disc pl-5 space-y-1">{% for error in preflight.errors %}<li>{{ error }}</li>{% endfor %}</ul>
  273. </section>
  274. {% endif %}
  275. {% if preflight.warnings %}
  276. <section class="rounded-lg border border-amber-200 bg-amber-50 p-5 text-sm text-amber-900">
  277. <h3 class="font-semibold flex items-center gap-2"><i class="fas fa-exclamation-triangle"></i>{{ _('Revisiones manuales') }}</h3>
  278. <ul class="mt-3 list-disc pl-5 space-y-1">{% for warning in preflight.warnings %}<li>{{ warning }}</li>{% endfor %}</ul>
  279. </section>
  280. {% endif %}
  281. <section id="draft-preflight" class="hidden rounded-lg border border-indigo-200 bg-indigo-50 p-5 text-sm text-indigo-950" aria-live="polite">
  282. <h3 class="font-semibold flex items-center gap-2"><i class="fas fa-vial text-indigo-600"></i>{{ _('Comprobación de valores sin guardar') }}</h3>
  283. <ul id="draft-preflight-summary" class="mt-3 space-y-1.5"></ul>
  284. <div id="draft-preflight-errors" class="hidden mt-4 border-t border-red-200 pt-3 text-red-800">
  285. <p class="font-semibold">{{ _('Bloqueos antes de aplicar') }}</p>
  286. <ul id="draft-preflight-error-list" class="mt-1 list-disc pl-5 space-y-1"></ul>
  287. </div>
  288. <div id="draft-preflight-warnings" class="hidden mt-4 border-t border-amber-200 pt-3 text-amber-900">
  289. <p class="font-semibold">{{ _('Revisiones manuales') }}</p>
  290. <ul id="draft-preflight-warning-list" class="mt-1 list-disc pl-5 space-y-1"></ul>
  291. </div>
  292. </section>
  293. </aside>
  294. </div>
  295. <section class="bg-slate-900 rounded-lg shadow overflow-hidden">
  296. <div class="flex items-center justify-between gap-4 border-b border-slate-700 px-5 py-3">
  297. <h3 class="font-semibold text-white"><i class="fas fa-terminal mr-2 text-indigo-300"></i>{{ _('Vista previa de bloques gestionados') }}</h3>
  298. <span id="preview-state" class="text-xs text-slate-300">{{ _('Configuración guardada') }}</span>
  299. </div>
  300. <p id="preview-error" class="hidden border-b border-red-800 bg-red-950 px-5 py-3 text-sm text-red-200" role="alert" aria-live="polite"></p>
  301. <pre id="kerberos-preview" class="overflow-x-auto p-5 text-xs leading-6 text-emerald-200 whitespace-pre-wrap">{{ kerberos.preview }}</pre>
  302. </section>
  303. </div>
  304. <script>
  305. (() => {
  306. const form = document.getElementById('kerberos-config-form');
  307. const button = document.getElementById('update-preview');
  308. const preview = document.getElementById('kerberos-preview');
  309. const previewError = document.getElementById('preview-error');
  310. const previewState = document.getElementById('preview-state');
  311. const enabled = document.getElementById('kerberos-enabled');
  312. const requiredFields = document.querySelectorAll('[data-kerberos-required]');
  313. const draftPreflight = document.getElementById('draft-preflight');
  314. const draftSummary = document.getElementById('draft-preflight-summary');
  315. const draftErrors = document.getElementById('draft-preflight-errors');
  316. const draftErrorList = document.getElementById('draft-preflight-error-list');
  317. const draftWarnings = document.getElementById('draft-preflight-warnings');
  318. const draftWarningList = document.getElementById('draft-preflight-warning-list');
  319. const labels = {
  320. available: {{ _('Disponible')|tojson }},
  321. unavailable: {{ _('No disponible')|tojson }},
  322. manual: {{ _('Solo manual')|tojson }},
  323. notChecked: {{ _('Sin comprobar')|tojson }},
  324. enabled: {{ _('Habilitado')|tojson }},
  325. disabled: {{ _('Deshabilitado')|tojson }},
  326. found: {{ _('Archivo encontrado')|tojson }},
  327. notFound: {{ _('Archivo no encontrado')|tojson }},
  328. executable: {{ _('Existe y es ejecutable')|tojson }},
  329. notExecutable: {{ _('No disponible o no ejecutable')|tojson }},
  330. present: {{ _('Presente')|tojson }},
  331. notPresent: {{ _('No encontrado')|tojson }},
  332. likelyReadable: {{ _('probable')|tojson }},
  333. reviewPermissions: {{ _('revisar permisos')|tojson }},
  334. squidUser: {{ _('Usuario de Squid')|tojson }},
  335. yes: {{ _('Sí')|tojson }},
  336. no: {{ _('No')|tojson }},
  337. local: {{ _('Local')|tojson }},
  338. notDetected: {{ _('No detectado')|tojson }},
  339. compiledDefault: {{ _('predeterminado compilado')|tojson }},
  340. managedDestination: {{ _('Destino administrado')|tojson }},
  341. modularTargets: '50_auth.conf + 120_http_access.conf',
  342. dockerMount: {{ _('Montaje Docker')|tojson }},
  343. mountVerified: {{ _('Verificado')|tojson }},
  344. mountMismatch: {{ _('No coincide')|tojson }},
  345. expected: {{ _('Esperado')|tojson }},
  346. exposedAs: {{ _('El volumen expone')|tojson }},
  347. resolvedSymlink: {{ _('enlace simbólico resuelto')|tojson }},
  348. responseUnavailable: {{ _('El servidor no devolvió un resultado legible. Comprueba tu sesión y el token CSRF.')|tojson }}
  349. };
  350. function setRequiredFields() {
  351. requiredFields.forEach((field) => {
  352. field.required = enabled.checked;
  353. });
  354. }
  355. function addDraftStatus(label, value, state = 'neutral') {
  356. const item = document.createElement('li');
  357. const labelNode = document.createElement('span');
  358. const valueNode = document.createElement('span');
  359. labelNode.className = 'text-indigo-800';
  360. labelNode.textContent = `${label}: `;
  361. valueNode.textContent = value;
  362. if (state === 'ok') valueNode.className = 'font-medium text-emerald-700';
  363. if (state === 'error') valueNode.className = 'font-medium text-red-700';
  364. if (state === 'warning') valueNode.className = 'font-medium text-amber-700';
  365. item.append(labelNode, valueNode);
  366. draftSummary.append(item);
  367. }
  368. function renderDraftMessages(container, list, messages) {
  369. list.replaceChildren();
  370. messages.forEach((message) => {
  371. const item = document.createElement('li');
  372. item.textContent = message;
  373. list.append(item);
  374. });
  375. container.classList.toggle('hidden', messages.length === 0);
  376. }
  377. function updateDraftPreflight(preflight, settings) {
  378. draftPreflight.classList.remove('hidden');
  379. draftSummary.replaceChildren();
  380. const config = preflight.config || {};
  381. const runtime = preflight.runtime || {};
  382. const version = preflight.squid_version || {};
  383. const proxyMode = preflight.proxy_mode || {};
  384. const dockerConfig = preflight.docker_config || {};
  385. const helper = preflight.helper;
  386. const keytab = preflight.keytab;
  387. const runtimeName = !runtime.available
  388. ? labels.notDetected
  389. : runtime.kind === 'docker'
  390. ? `Docker${runtime.container ? `: ${runtime.container}` : ''}`
  391. : labels.local;
  392. addDraftStatus('Kerberos', settings.enabled ? labels.enabled : labels.disabled, settings.enabled ? 'ok' : 'neutral');
  393. addDraftStatus('squid.conf', config.path || labels.notChecked);
  394. addDraftStatus(labels.managedDestination, config.modular ? labels.modularTargets : 'squid.conf');
  395. const manualWriteMode = config.write_mode === 'manual';
  396. addDraftStatus({{ _('Escritura')|tojson }}, manualWriteMode ? labels.manual : (config.writable ? labels.available : labels.unavailable), manualWriteMode ? 'warning' : (config.writable ? 'ok' : 'error'));
  397. addDraftStatus({{ _('Runtime Squid')|tojson }}, runtimeName, runtime.available ? 'ok' : 'warning');
  398. if (preflight.squid_user) {
  399. const userSource = preflight.squid_user_source === 'build_default'
  400. ? ` (${labels.compiledDefault})`
  401. : '';
  402. addDraftStatus(labels.squidUser, `${preflight.squid_user}${userSource}`);
  403. }
  404. if (runtime.kind === 'docker' || dockerConfig.checked || dockerConfig.container_config_path) {
  405. const expectedPath = dockerConfig.container_config_path || '';
  406. let mountValue = labels.notChecked;
  407. let mountState = 'warning';
  408. if (dockerConfig.mapped === true) {
  409. mountValue = `${labels.mountVerified}${expectedPath ? `: ${expectedPath}` : ''}`;
  410. if (dockerConfig.symlink) mountValue += ` (${labels.resolvedSymlink})`;
  411. mountState = 'ok';
  412. } else if (dockerConfig.mapped === false) {
  413. mountValue = `${labels.mountMismatch}${expectedPath ? ` — ${labels.expected}: ${expectedPath}` : ''}`;
  414. if (dockerConfig.container_path) mountValue += ` — ${labels.exposedAs}: ${dockerConfig.container_path}`;
  415. mountState = 'error';
  416. }
  417. addDraftStatus(labels.dockerMount, mountValue, mountState);
  418. }
  419. addDraftStatus({{ _('Versión Squid')|tojson }}, version.version || (version.checked ? labels.unavailable : labels.notChecked), version.supports_auth_param === false ? 'error' : 'neutral');
  420. const explicit = proxyMode.explicit_proxy_available;
  421. addDraftStatus({{ _('Proxy explícito')|tojson }}, explicit === null || explicit === undefined ? labels.notChecked : (explicit ? labels.yes : labels.no), explicit === false ? 'error' : 'neutral');
  422. if (proxyMode.incompatible_ports) {
  423. addDraftStatus({{ _('Puertos no compatibles')|tojson }}, String(proxyMode.incompatible_ports), 'error');
  424. }
  425. if (helper && keytab) {
  426. const helperReady = helper.check_available && helper.exists && helper.executable;
  427. const keytabReady = keytab.check_available && keytab.exists && keytab.regular_file;
  428. addDraftStatus({{ _('Helper')|tojson }}, `${helper.path} — ${!helper.check_available ? labels.notChecked : (helperReady ? labels.executable : labels.notExecutable)}`, helperReady ? 'ok' : 'error');
  429. addDraftStatus('Keytab', `${keytab.path} — ${!keytab.check_available ? labels.notChecked : (keytabReady ? labels.found : labels.notFound)}`, keytabReady ? 'ok' : 'error');
  430. if (keytab.squid_user_readable !== null && keytab.squid_user_readable !== undefined) {
  431. addDraftStatus(`Keytab / ${labels.squidUser}`, `${keytab.squid_user || labels.notChecked}: ${keytab.squid_user_readable ? labels.likelyReadable : labels.reviewPermissions}`, keytab.squid_user_readable ? 'ok' : 'warning');
  432. }
  433. addDraftStatus('SPN', !keytab.spn_checked ? labels.notChecked : (keytab.spn_present ? labels.present : labels.notPresent), keytab.spn_checked && !keytab.spn_present ? 'error' : 'neutral');
  434. }
  435. renderDraftMessages(draftErrors, draftErrorList, preflight.errors || []);
  436. renderDraftMessages(draftWarnings, draftWarningList, preflight.warnings || []);
  437. }
  438. enabled.addEventListener('change', setRequiredFields);
  439. setRequiredFields();
  440. button.addEventListener('click', async () => {
  441. const values = {};
  442. new FormData(form).forEach((value, key) => {
  443. if (key !== 'csrf_token' && key !== 'action') values[key] = value;
  444. });
  445. button.disabled = true;
  446. previewState.textContent = {{ _('Generando…')|tojson }};
  447. previewError.classList.add('hidden');
  448. try {
  449. const response = await fetch({{ url_for('admin.kerberos_preview')|tojson }}, {
  450. method: 'POST',
  451. credentials: 'same-origin',
  452. headers: {
  453. 'Content-Type': 'application/json',
  454. 'X-CSRFToken': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || ''
  455. },
  456. body: JSON.stringify(values)
  457. });
  458. const responseBody = await response.text();
  459. let result;
  460. try {
  461. result = responseBody ? JSON.parse(responseBody) : {};
  462. } catch (_error) {
  463. throw new Error(labels.responseUnavailable);
  464. }
  465. if (!response.ok || result.status !== 'success') {
  466. throw new Error(result.message || {{ _('No se pudo generar la vista previa.')|tojson }});
  467. }
  468. preview.textContent = result.preview;
  469. updateDraftPreflight(result.preflight || {}, result.settings || {});
  470. previewState.textContent = {{ _('Vista previa sin guardar')|tojson }};
  471. } catch (error) {
  472. previewError.textContent = error.message || labels.responseUnavailable;
  473. previewError.classList.remove('hidden');
  474. previewState.textContent = {{ _('Corrige los campos')|tojson }};
  475. } finally {
  476. button.disabled = false;
  477. }
  478. });
  479. })();
  480. </script>
  481. {% endblock %}