Subscription Conversion Service

This commit is contained in:
心隨緣動 2025-08-29 17:38:23 +08:00 committed by GitHub
parent 01b509c79a
commit d0741f462f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

112
x-ui.sh
View File

@ -1265,118 +1265,6 @@ warp_cloudflare() {
esac
}
# --------- 【订阅转换】模块 ----------
subconverter() {
echo ""
echo -e "${green}==============================================="
echo -e "〔订阅转换〕一键部署"
echo -e "1. 自动申请 SSL 证书"
echo -e "2. 自动安装 Docker + Nginx"
echo -e "3. 自动部署 stilleshan/sub 容器"
echo -e "4. 自动配置反向代理 + SSL 证书"
echo -e "5. 自动检测域名解析是否正确"
echo -e "作者3X-UI中文优化版专属定制"
echo -e "===============================================${plain}"
echo ""
# --------- 域名输入 ----------
read -rp "请输入订阅转换访问域名(例如: sub.xxxxx.com 请务必以sub开头: " SUB_DOMAIN
echo ""
read -rp "请输入订阅后端 API 域名(例如: api.xxxxx.com 请务必以api开头: " API_DOMAIN
echo ""
# --------- 检测域名格式 ----------
domain_regex="^([a-zA-Z0-9][-a-zA-Z0-9]{0,62}\.)+[a-zA-Z]{2,}$"
if [[ ! $SUB_DOMAIN =~ $domain_regex ]]; then
echo -e "${red}错误: 域名格式不正确 → $SUB_DOMAIN${plain}"
exit 1
fi
if [[ ! $API_DOMAIN =~ $domain_regex ]]; then
echo -e "${red}错误: 域名格式不正确 → $API_DOMAIN${plain}"
exit 1
fi
# --------- 获取本机公网 IP ----------
LOCAL_IP=$(curl -s4m8 ip.p3terx.com -k | sed -n 1p)
# --------- 检测域名解析 ----------
echo -e "${yellow}正在检测域名解析情况...${plain}"
SUB_IP=$(dig +short $SUB_DOMAIN | tail -n1)
echo ""
API_IP=$(dig +short $API_DOMAIN | tail -n1)
echo ""
if [[ -z $SUB_IP ]]; then
echo -e "${red}错误: 无法解析订阅转换访问域名 $SUB_DOMAIN,请检查 DNS 设置!${plain}"
exit 1
fi
if [[ -z $API_IP ]]; then
echo -e "${red}错误: 无法解析后端 API 域名 $API_DOMAIN,请检查 DNS 设置!${plain}"
exit 1
fi
if [[ "$SUB_IP" != "$LOCAL_IP" ]]; then
echo -e "${red}错误: 域名 $SUB_DOMAIN 解析到 $SUB_IP,但本机 IP 是 $LOCAL_IP${plain}"
exit 1
fi
if [[ "$API_IP" != "$LOCAL_IP" ]]; then
echo -e "${red}错误: 域名 $API_DOMAIN 解析到 $API_IP,但本机 IP 是 $LOCAL_IP${plain}"
exit 1
fi
echo -e "${green}域名解析检测通过!${plain}"
echo ""
echo -e "订阅转换访问域名: ${yellow}https://${SUB_DOMAIN}:8443${plain}"
echo ""
echo -e "订阅后端 API 域名: ${yellow}https://${API_DOMAIN}:8443${plain}"
echo ""
# --------- 安装 acme.sh ----------
if [ ! -f ~/.acme.sh/acme.sh ]; then
echo -e "${yellow}-------------->>>>>>>>acme.sh 未安装,正在安装...${plain}"
curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --upgrade --auto-upgrade
else
echo -e "${green}检测到 acme.sh 已安装,跳过安装步骤${plain}"
fi
# --------- 申请 SSL 证书standalone 占用 80 端口) ----------
for domain in $SUB_DOMAIN $API_DOMAIN; do
if [ ! -f ~/.acme.sh/${domain}_ecc/${domain}.cer ]; then
echo -e "${yellow}-------------->>>>>>>>为域名 $domain 申请 SSL 证书...${plain}"
~/.acme.sh/acme.sh --issue -d "$domain" --standalone --keylength ec-256
else
echo -e "${green}检测到域名 $domain 已存在证书,跳过申请${plain}"
fi
done
# --------- 安装 Docker ----------
if ! command -v docker &>/dev/null; then
echo -e "${yellow}-------------->>>>>>>>未检测到 Docker正在安装...${plain}"
curl -fsSL https://get.docker.com | bash -s docker
systemctl enable docker
systemctl start docker
else
echo -e "${green}检测到 Docker 已安装,跳过安装步骤${plain}"
fi
# --------- 安装 Nginx ----------
if ! command -v nginx &>/dev/null; then
echo -e "${yellow}-------------->>>>>>>>未检测到 Nginx正在安装...${plain}"
apt update && apt install -y nginx
systemctl enable nginx
systemctl start nginx
else
echo -e "${green}检测到 Nginx 已安装,跳过安装步骤${plain}"
fi
# --------- 部署证书到 Nginx ----------
mkdir -p /etc/nginx/ssl
for domain in $SUB_DOMAIN $API_DOMAIN; do
~/.acme.sh/acme.sh --install-cert -d "$domain" --ecc \
--key-file /etc/nginx/ssl/${domain}.key \
--fullchain-file /etc/nginx/ssl/${domain}.crt \
--reloadcmd "systemctl reload nginx"
done
# --------- 【订阅转换】模块 ----------
subconverter() {
echo ""