feat: ssl_fallback智能排除已失败的方案

问题描述:
- 用户选择方案2失败后,fallback还推荐方案2
- 用户再次选择方案2,还是会失败
- 浪费时间,用户体验差

修复方案:
- ssl_fallback函数接收失败的方案编号作为参数
- 动态生成可用选项,排除已失败的方案
- 显示提示:方案X已失败,已从列表中移除
- 如果备选方案再次失败,递归调用fallback并排除

改进内容:
1. ssl_fallback($failed_method) - 接收方案编号
2. 动态显示可用选项(排除失败方案)
3. 输入验证:只接受可用选项
4. 递归调用:如果备选方案也失败,继续排除

方案编号映射:
- 1: Certbot
- 2: acme.sh + Let's Encrypt
- 3: acme.sh + ZeroSSL
- 4: acme.sh + Buypass
- 5: 阿里云(未实现)
- 6: 腾讯云(未实现)
- 8: 不配置HTTPS

用户体验改进:
- 避免重复尝试失败的方案
- 清晰提示哪个方案已失败
- 自动缩小选择范围
- 节省用户时间

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
WanWanYun
2025-11-13 01:46:05 +08:00
parent 4a73a8c348
commit a7aca93355

View File

@@ -1134,22 +1134,22 @@ deploy_ssl() {
case $SSL_METHOD in case $SSL_METHOD in
1) 1)
deploy_certbot || ssl_fallback deploy_certbot || ssl_fallback "1"
;; ;;
2) 2)
deploy_acme_letsencrypt || ssl_fallback deploy_acme_letsencrypt || ssl_fallback "2"
;; ;;
3) 3)
deploy_acme_zerossl || ssl_fallback deploy_acme_zerossl || ssl_fallback "3"
;; ;;
4) 4)
deploy_acme_buypass || ssl_fallback deploy_acme_buypass || ssl_fallback "4"
;; ;;
5) 5)
deploy_aliyun_ssl || ssl_fallback deploy_aliyun_ssl || ssl_fallback "5"
;; ;;
6) 6)
deploy_tencent_ssl || ssl_fallback deploy_tencent_ssl || ssl_fallback "6"
;; ;;
7) 7)
deploy_manual_ssl deploy_manual_ssl
@@ -1162,35 +1162,97 @@ deploy_ssl() {
} }
ssl_fallback() { ssl_fallback() {
local failed_method=$1 # 接收失败的方案编号
print_error "SSL证书部署失败" print_error "SSL证书部署失败"
echo "" echo ""
print_warning "建议尝试备选方案:" print_warning "建议尝试备选方案:"
echo -e "${GREEN}[2]${NC} acme.sh + Let's Encrypt (推荐)" echo ""
echo -e "${GREEN}[3]${NC} acme.sh + ZeroSSL"
echo -e "${GREEN}[4]${NC} acme.sh + Buypass" # 动态显示可用选项(排除已失败的)
local available_options=()
# 方案1: Certbot
if [[ "$failed_method" != "1" ]]; then
echo -e "${GREEN}[1]${NC} Certbot (Let's Encrypt官方工具)"
available_options+=("1")
fi
# 方案2: acme.sh + Let's Encrypt
if [[ "$failed_method" != "2" ]]; then
echo -e "${GREEN}[2]${NC} acme.sh + Let's Encrypt"
available_options+=("2")
fi
# 方案3: acme.sh + ZeroSSL
if [[ "$failed_method" != "3" ]]; then
echo -e "${GREEN}[3]${NC} acme.sh + ZeroSSL"
available_options+=("3")
fi
# 方案4: acme.sh + Buypass
if [[ "$failed_method" != "4" ]]; then
echo -e "${GREEN}[4]${NC} acme.sh + Buypass"
available_options+=("4")
fi
# 方案5: 阿里云(注释掉,未实现)
# if [[ "$failed_method" != "5" ]]; then
# echo -e "${GREEN}[5]${NC} 阿里云免费证书"
# available_options+=("5")
# fi
# 方案6: 腾讯云(注释掉,未实现)
# if [[ "$failed_method" != "6" ]]; then
# echo -e "${GREEN}[6]${NC} 腾讯云免费证书"
# available_options+=("6")
# fi
# 方案8: 不配置HTTPS
echo -e "${GREEN}[8]${NC} 暂不配置HTTPS" echo -e "${GREEN}[8]${NC} 暂不配置HTTPS"
available_options+=("8")
echo ""
echo -e "${YELLOW}提示: 方案 $failed_method 已失败,已从列表中移除${NC}"
echo "" echo ""
while true; do while true; do
read -p "请选择备选方案 [2-4/8]: " retry_choice < /dev/tty read -p "请选择备选方案: " retry_choice < /dev/tty
# 检查输入是否在可用选项中
if [[ ! " ${available_options[@]} " =~ " ${retry_choice} " ]]; then
print_error "无效选项或该方案已失败"
continue
fi
case $retry_choice in case $retry_choice in
1)
deploy_certbot && return 0
# 如果再次失败继续调用fallback但排除方案1
ssl_fallback "1"
return $?
;;
2) 2)
deploy_acme_letsencrypt && return 0 deploy_acme_letsencrypt && return 0
# 如果再次失败继续调用fallback但排除方案2
ssl_fallback "2"
return $?
;; ;;
3) 3)
deploy_acme_zerossl && return 0 deploy_acme_zerossl && return 0
ssl_fallback "3"
return $?
;; ;;
4) 4)
deploy_acme_buypass && return 0 deploy_acme_buypass && return 0
ssl_fallback "4"
return $?
;; ;;
8) 8)
print_info "跳过HTTPS配置" print_info "跳过HTTPS配置"
SSL_METHOD=8 SSL_METHOD=8
return 0 return 0
;; ;;
*)
print_error "无效选项"
;;
esac esac
done done
} }