From 553529e9b8109f64b834a83295a9cb2973fec69f Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Fri, 22 May 2026 17:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81,=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=BD=E6=95=B0=E6=96=87=E4=BB=B6,=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AEtls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/tls.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bin/tls.sh diff --git a/bin/tls.sh b/bin/tls.sh new file mode 100644 index 0000000..0fc3dc5 --- /dev/null +++ b/bin/tls.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# 生成自签名证书 +create_self_tls_file() { + local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 + local KEY_DIR="$SCRIPT_DIR/../tls/self-tls" # 自签tls证书文件夹 + + # 创建存放证书的目录 + mkdir -p "$KEY_DIR" + + # 生成自签名证书文件 + local DOMAIN="${1:-bing.com}" # 域名,默认为bing.com + openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) \ + -keyout "$KEY_DIR/server.key" \ + -out "$KEY_DIR/server.crt" \ + -subj "/CN=$DOMAIN" \ + -days 36500 +} + +update_self_tls(){ + local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 + local CONFIG_DIR=$(readlink -f "$SCRIPT_DIR/../config") + local CONFIG_FILE="$CONFIG_DIR/config.json" + + # 生成自签名证书, 设置域名 + local DOMAIN="${1:-bing.com}" # 域名,默认为bing.com + create_self_tls "$DOMAIN" + sed -i "s/你的域名/$DOMAIN/g" "$CONFIG_FILE" +} + +update_acme_tls(){ + local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径 + local CONFIG_DIR=$(readlink -f "$SCRIPT_DIR/../config") + local CONFIG_FILE="$CONFIG_DIR/config.json" + + # 获取邮箱 + local USER_EMAIL + read -p "请输入你的邮箱: " USER_EMAIL + if [[ -z "$USER_EMAIL" ]]; then + echo "[错误] 域名不能为空" + read -p "请输入你的邮箱: " USER_EMAIL + fi + + # 获取域名 + local USER_DOMAIN + read -p "请输入你的域名 (例如: example.com): " USER_DOMAIN + while [[ -z "$USER_DOMAIN" ]]; do + echo "[错误] 域名不能为空" + read -p "请输入你的域名: " USER_DOMAIN + done + + # 获取 Cloudflare API Token + local CLOUDFLARE_TOKEN + read -p "请输入你的 Cloudflare API Token: " CLOUDFLARE_TOKEN + while [[ -z "$CLOUDFLARE_TOKEN" ]]; do + echo "[错误] Cloudflare API Token 不能为空" + read -p "请输入你的 Cloudflare API Token: " CLOUDFLARE_TOKEN + done + + sed -i "s/你的邮箱/$USER_EMAIL/g" "$CONFIG_FILE" + sed -i "s/你的域名/$USER_DOMAIN/g" "$CONFIG_FILE" + sed -i "s/你的Cloudflare_API_Token/$CLOUDFLARE_TOKEN/g" "$CONFIG_FILE" +}