#!/usr/bin/env bash # ============================================================================== # 模块:多协议配置生成器 (VLESS-Reality / Hysteria2 / TUIC / VMess / AnyTLS) # ============================================================================== # 获取或生成统一 UUID get_or_create_uuid() { local uuid="${1:-}" if [[ -z "$uuid" ]]; then if command -v "${BIN_PATH}" >/dev/null 2>&1; then uuid=$("${BIN_PATH}" generate uuid 2>/dev/null) fi if [[ -z "$uuid" && -f /proc/sys/kernel/random/uuid ]]; then uuid=$(cat /proc/sys/kernel/random/uuid) fi if [[ -z "$uuid" ]]; then uuid=$(openssl rand -hex 16 | sed -E 's/(.{8})(.{4})(.{4})(.{4})(.{12})/\1-\2-\3-\4-\5/') fi fi echo "$uuid" } # 1. 组装 VLESS-Reality 入站 JSON build_vless_inbound() { local port="$1" local uuid="$2" local sni="$3" local priv_key="$4" local short_id="$5" cat </dev/null || openssl rand -hex 4) short_id=$(echo "$short_id" | tr -d ' "\r\n') fi local inbounds_arr=() local meta_protocols="{}" case "$mode" in all) local p_vless="${1:-443}" local p_hy2="${2:-8443}" local p_tuic="${3:-9443}" local p_vmess="${4:-8080}" local p_anytls="${5:-10443}" inbounds_arr+=("$(build_vless_inbound "$p_vless" "$uuid" "$reality_sni" "$priv_key" "$short_id")") inbounds_arr+=("$(build_hy2_inbound "$p_hy2" "$uuid")") inbounds_arr+=("$(build_tuic_inbound "$p_tuic" "$uuid")") inbounds_arr+=("$(build_vmess_inbound "$p_vmess" "$uuid")") inbounds_arr+=("$(build_anytls_inbound "$p_anytls" "$uuid")") meta_protocols=$(cat < "${CONFIG_FILE}" </dev/null 2>&1; then log_error "生成的配置文件未能通过 Sing-box 语法检测!请检查端口是否有冲突或参数错误。" return 1 fi # 写入持久化元数据 cat > "${META_FILE}" <