增加对hysteria2协议的分享链接生成支持
This commit is contained in:
+63
-6
@@ -1,14 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
print_share_link() {
|
||||
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local CONFIG_DIR=$(readlink -f "$SCRIPT_DIR/../config")
|
||||
|
||||
# 检查jq是否安装
|
||||
check_jq
|
||||
|
||||
CONFIG_FILE="$CONFIG_DIR/config.json"
|
||||
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 TYPE=$(jq -r '.inbounds[0].type' "$CONFIG_FILE")
|
||||
if [ "$TYPE" = "tuic" ]; then
|
||||
print_tuic_share_link
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$TYPE" = "hysteria2" ]; then
|
||||
print_hysteria_share_link
|
||||
return 0
|
||||
fi
|
||||
|
||||
red "error: 不支持的协议类型: $TYPE"
|
||||
}
|
||||
|
||||
print_tuic_share_link() {
|
||||
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 UUID=$(jq -r '.inbounds[0].users[0].uuid' "$CONFIG_FILE")
|
||||
@@ -31,7 +48,7 @@ print_share_link() {
|
||||
local INSECURE=1 # 是否允许不安全连接,1表示允许,0表示不允许
|
||||
|
||||
# 检查是否使用ACME申请证书
|
||||
if jq -e '.inbounds[0].tls.acme' "$CONFIG_DIR/config.json" > /dev/null 2>&1; then
|
||||
if jq -e '.inbounds[0].tls.acme' "$CONFIG_FILE" > /dev/null 2>&1; then
|
||||
ALLOW_INSECURE=0 # 不跳过证书验证
|
||||
INSECURE=0
|
||||
fi
|
||||
@@ -52,3 +69,43 @@ print_share_link() {
|
||||
echo -e "\033[0m"
|
||||
}
|
||||
|
||||
|
||||
print_hysteria_share_link(){
|
||||
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 insecure=1
|
||||
local allow_insecure=1
|
||||
|
||||
# 检查是否使用ACME申请证书
|
||||
if jq -e '.inbounds[0].tls.acme' "$config_file" > /dev/null 2>&1; then
|
||||
allow_insecure=0 # 不跳过证书验证
|
||||
insecure=0
|
||||
fi
|
||||
|
||||
# 读取配置文件内容
|
||||
local config=$(cat "$config_file")
|
||||
|
||||
# 提取所需信息
|
||||
local ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null")
|
||||
local port=$(echo "$config" | jq -r '.inbounds[0].listen_port')
|
||||
local sni=$(echo "$config" | jq -r '.inbounds[0].tls.server_name')
|
||||
local password=$(echo "$config" | jq -r '.inbounds[0].users[0].password')
|
||||
local obfs_type=$(echo "$config" | jq -r '.inbounds[0].obfs.type')
|
||||
local obfs_password=$(echo "$config" | jq -r '.inbounds[0].obfs.password')
|
||||
|
||||
# 构建分享链接
|
||||
local share_link="hysteria2://${password}@${ipv4}:${port}/?sni=${sni}&insecure=${insecure}&obfs=${obfs_type}&obfs-password=${obfs_password}&allowInsecure=${allow_insecure}#Hysteria2节点"
|
||||
|
||||
# 输出分享链接
|
||||
echo -e "\033[32m"
|
||||
echo "IPV4: $ipv4"
|
||||
echo "port: $port"
|
||||
echo "password: $password"
|
||||
echo "sni: $sni"
|
||||
echo "obfs: $obfs_type"
|
||||
echo "混淆密码: $obfs_password"
|
||||
echo ""
|
||||
echo "分享链接: $share_link"
|
||||
echo -e "\033[0m"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user