diff --git a/bin/versadm_token.sh b/bin/versadm_token.sh index fe9a4ca..b4fb6a3 100755 --- a/bin/versadm_token.sh +++ b/bin/versadm_token.sh @@ -109,63 +109,58 @@ show_token_help() { dialog --backtitle "${title}" --title "Ayuda sobre tokens de $vcs_name" --msgbox "$help_text" 22 75 } -# Diálogo personalizado para solicitar token con botón de ayuda +# Diálogo para solicitar token utilizando console.lib request_token_with_help() { local vcs_index=$1 local vcs_name=${VCS_TYPES[$vcs_index]} local prompt="Ingrese su token personal de $vcs_name:" local helper="Puede generar un nuevo token en: ${VCS_TOKEN_URLS[$vcs_index]}" - local button=0 local token="" + local continue_loop=true - while [ $button -ne 1 ]; do - # Crear diálogo temporal - tempfile=$(mktemp) + while $continue_loop; do + # Mostrar diálogo de contraseña usando console.lib + dialog_input_pass "$prompt" "$helper" - # Mostrar diálogo con 3 botones (Cancelar, OK, Ayuda) - dialog --backtitle "${title}" --title "${apps_title}" \ - --passwordbox "\n$prompt\n\n$helper" 12 70 \ - --extra-button --extra-label "Ayuda" 2>"$tempfile" + # Verificar resultado + if [ $codex -ne 0 ]; then + # Usuario canceló + return 1 + fi - button=$? + token="$value" - # Procesar resultado según el botón presionado - case $button in - 0) # OK - token=$(cat "$tempfile") - rm -f "$tempfile" - - # Validar el token - if [ -z "$token" ]; then - dialog --backtitle "${title}" --title "${head_error}" --msgbox "El token no puede estar vacío. Por favor ingrese un token válido." 7 60 - button=3 # Mantener el bucle activo - continue - fi - - if [ ${#token} -lt 20 ]; then - dialog_yesno "El token parece ser demasiado corto. Verifique que haya copiado el token completo.\n\n¿Desea continuar de todas formas?" 10 70 - if [ $? -ne 0 ]; then - button=3 # Mantener el bucle activo - continue - fi - fi - - # Devolver el token si es válido - echo "$token" - return 0 - ;; - 1) # Cancelar - rm -f "$tempfile" - return 1 - ;; - 3) # Botón extra (Ayuda) - rm -f "$tempfile" - show_token_help "$vcs_index" - ;; - esac + # Validar el token + if [ -z "$token" ]; then + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "El token no puede estar vacío. Por favor ingrese un token válido." 7 60 + continue + fi + + if [ ${#token} -lt 20 ]; then + dialog_yesno "El token parece ser demasiado corto. Verifique que haya copiado el token completo.\n\n¿Desea continuar de todas formas?" 10 70 + if [ $? -ne 0 ]; then + continue + fi + fi + + # Mostrar opción de ayuda + dialog_yesno "¿Necesita ayuda para obtener un token de $vcs_name?\n\nSeleccione 'Sí' para ver instrucciones detalladas o 'No' para continuar." 10 70 + if [ $? -eq 0 ]; then + show_token_help "$vcs_index" + # Preguntar si desea intentar nuevamente + dialog_yesno "¿Desea ingresar un token diferente?" 7 60 + if [ $? -eq 0 ]; then + continue + fi + fi + + # Token válido, salir del bucle + continue_loop=false done - return 1 + # Devolver el token + echo "$token" + return 0 } # Verificar e instalar CLI si es necesario @@ -187,11 +182,11 @@ check_and_install_cli() { read return $result else - dialog --backtitle "${title}" --title "${head_error}" --msgbox "No se encontró el script de instalación para $vcs_name:\n$installer" 8 70 + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "No se encontró el script de instalación para $vcs_name:\n$installer" 8 70 return 1 fi else - dialog --backtitle "${title}" --title "${head_info}" \ + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_info}" \ --msgbox "El CLI es necesario para interactuar completamente con $vcs_name.\nEl token se guardará de todas formas, pero no podrá verificar la conexión automáticamente." 9 70 return 0 fi @@ -219,11 +214,11 @@ save_encrypted_token() { # Establecer permisos adecuados chmod 600 "$token_file" - dialog --backtitle "${title}" --title "Encriptación Exitosa" \ + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Encriptación Exitosa" \ --msgbox "El token de $vcs_name ha sido encriptado exitosamente en:\n$token_file" 8 70 return 0 else - dialog --backtitle "${title}" --title "${head_error}" \ + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" \ --msgbox "Falló la encriptación del token de $vcs_name." 7 50 return 1 fi @@ -238,7 +233,8 @@ test_connection() { local connection_status="" local connection_message="" - dialog --backtitle "${title}" --title "Prueba de conexión" --infobox "Probando conexión con $vcs_name..." 5 60 + # Usar dialog en modo compatible con console.lib + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Prueba de conexión" --infobox "Probando conexión con $vcs_name..." 5 60 case "$vcs_index" in 0) # GitHub @@ -292,7 +288,8 @@ test_connection() { ;; esac - dialog --backtitle "${title}" --title "Resultado de la prueba" --msgbox "$connection_message" 15 70 + # Usar dialog en modo compatible con console.lib + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Resultado de la prueba" --msgbox "$connection_message" 15 70 } # Función principal para gestionar tokens @@ -318,7 +315,7 @@ manage_vcs_token() { # Verificar índice válido if [ $selection -lt 0 ] || [ $selection -ge ${#VCS_TYPES[@]} ]; then - dialog --backtitle "${title}" --title "${head_error}" --msgbox "Selección inválida." 7 50 + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "${head_error}" --msgbox "Selección inválida." 7 50 return 1 fi @@ -379,7 +376,7 @@ manage_vcs_token() { dialog_yesno "¿Está seguro de que desea eliminar el token de $vcs_name?\nEsta acción no se puede deshacer." 8 60 if [ $? -eq 0 ]; then rm -f "$token_file" - dialog --backtitle "${title}" --title "Token eliminado" --msgbox "El token de $vcs_name ha sido eliminado." 7 50 + dialog --keep-window --begin ${CX} ${CY} --backtitle "${title}" --title "Token eliminado" --msgbox "El token de $vcs_name ha sido eliminado." 7 50 fi ;; esac