Skip to content

Commit 26bd60f

Browse files
committed
fix: correct Cloudflare API validation logic
fix: 修正 Cloudflare API 判断逻辑
1 parent 3194acc commit 26bd60f

1 file changed

Lines changed: 38 additions & 23 deletions

File tree

sba.sh

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# 当前脚本版本号
4-
VERSION='1.1.7 (2025.12.11)'
4+
VERSION='1.1.7 (2026.04.28)'
55

66
# 各变量默认值,Github 反代加速代理,第一个为空相当于直连
77
GITHUB_PROXY=('' 'https://v6.gh-proxy.org/' 'https://gh-proxy.com/' 'https://hub.glowp.xyz/' 'https://proxy.vvvv.ee/' 'https://ghproxy.lvedong.eu.org/')
@@ -29,8 +29,8 @@ E[2]="Project to create Argo tunnels and Sing-box specifically for VPS, detailed
2929
C[2]="本项目专为 VPS 添加 Argo 隧道及 Sing-Box,详细说明: [https://github.com/fscarmen/sba]\n 脚本特点:\n\t • 允许通过 Token, Json 及 临时方式来创建 Argo 隧道,用户通过以下网站轻松获取 json: https://fscarmen.cloudflare.now.cc\n\t • 极速安装方式,大大节省用户时间\n\t • 智能判断操作系统: Ubuntu 、Debian 、CentOS 、Alpine 和 Arch Linux,请务必选择 LTS 系统\n\t • 支持硬件结构类型: AMD 和 ARM\n"
3030
E[3]="Input errors up to 5 times.The script is aborted."
3131
C[3]="输入错误达5次,脚本退出"
32-
E[4]="UUID should be 36 characters, please re-enter \(\$[a-1] times remaining\)"
33-
C[4]="UUID 应为36位字符,请重新输入 \(剩余\$[a-1]次\)"
32+
E[4]="UUID should be 36 characters, please re-enter (\$[a-1] times remaining)"
33+
C[4]="UUID 应为36位字符,请重新输入 (剩余\$[a-1]次)"
3434
E[5]="The script supports Debian, Ubuntu, CentOS, Alpine, Fedora or Arch systems only. Feedback: [https://github.com/fscarmen/sba/issues]"
3535
C[5]="本脚本只支持 Debian、Ubuntu、CentOS、Alpine、Fedora 或 Arch 系统,问题反馈:[https://github.com/fscarmen/sba/issues]"
3636
E[6]="Curren operating system is \$SYS.\\\n The system lower than \$SYSTEM \${MAJOR[int]} is not supported. Feedback: [https://github.com/fscarmen/sba/issues]"
@@ -45,12 +45,12 @@ E[10]="Please input Argo Domain (Default is temporary domain if left blank):"
4545
C[10]="请输入 Argo 域名 (如果没有,可以跳过以使用 Argo 临时域名):"
4646
E[11]="Please enter Argo Token, Argo Json or Cloudflare API\n\n [*] Token: Visit https://dash.cloudflare.com/ , Zero Trust > Networks > Connectors > Create a tunnel > Select Cloudflared\n\n [*] Json: Users can easily obtain it through the following website: https://fscarmen.cloudflare.now.cc\n\n [*] Cloudflare API: Visit https://dash.cloudflare.com/profile/api-tokens > Create Token > Create Custom Token > Add the following permissions:\n - Account > Cloudflare One Connectors: cloudflared > Edit\n - Zone > DNS > Edit\n\n - Account Resources: Include > Required Account\n - Zone Resources: Include > Specific zone > Argo Root Domain"
4747
C[11]="请输入 Argo Token, Argo Json 或者 Cloudflare API\n\n [*] Token: 访问 https://dash.cloudflare.com/ ,Zero Trust > 网络 > 连接器 > 创建隧道 > 选择 Cloudflared\n\n [*] Json: 用户通过以下网站轻松获取: https://fscarmen.cloudflare.now.cc\n\n [*] Cloudflare API: 访问 https://dash.cloudflare.com/profile/api-tokens > 创建令牌 > 创建自定义令牌 > 添加以下权限:\n - 帐户 > Cloudflare One连接器: Cloudflared > 编辑\n - 区域 > DNS > 编辑\n\n - 帐户资源: 包括 > 所需账户\n - 区域资源: 包括 > 特定区域 > 所需域名"
48-
E[12]="Please input Sing-box UUID \(Default is \$UUID_DEFAULT\):"
49-
C[12]="请输入 Sing-box UUID \(默认为 \$UUID_DEFAULT\):"
50-
E[13]="Please input Sing-box WS Path \(Default is \$WS_PATH_DEFAULT\):"
51-
C[13]="请输入 Sing-box WS 路径 \(默认为 \$WS_PATH_DEFAULT\):"
52-
E[14]="Sing-box WS Path only allow uppercase and lowercase letters, numeric characters, hyphens, underscores, dots and @, please re-enter \(\${a} times remaining\):"
53-
C[14]="Sing-box WS 路径只允许英文大小写、数字、连字符、下划线、点和@字符,请重新输入 \(剩余\${a}次\):"
48+
E[12]="Please input Sing-box UUID (Default is \$UUID_DEFAULT):"
49+
C[12]="请输入 Sing-box UUID (默认为 \$UUID_DEFAULT):"
50+
E[13]="Please input Sing-box WS Path (Default is \$WS_PATH_DEFAULT):"
51+
C[13]="请输入 Sing-box WS 路径 (默认为 \$WS_PATH_DEFAULT):"
52+
E[14]="Sing-box WS Path only allow uppercase and lowercase letters, numeric characters, hyphens, underscores, dots and @, please re-enter (\${a} times remaining):"
53+
C[14]="Sing-box WS 路径只允许英文大小写、数字、连字符、下划线、点和@字符,请重新输入 (剩余\${a}次):"
5454
E[15]="sba script has not been installed yet."
5555
C[15]="sba 脚本还没有安装"
5656
E[16]="sba is completely uninstalled."
@@ -119,8 +119,8 @@ E[47]="The script must be run as root, you can enter sudo -i and then download a
119119
C[47]="必须以root方式运行脚本,可以输入 sudo -i 后重新下载运行,问题反馈:[https://github.com/fscarmen/sba/issues]"
120120
E[48]="Downloading the latest version \$APP failed, script exits. Feedback:[https://github.com/fscarmen/sba/issues]"
121121
C[48]="下载最新版本 \$APP 失败,脚本退出,问题反馈:[https://github.com/fscarmen/sba/issues]"
122-
E[49]="Please enter the node name. \(Default is \${NODE_NAME_DEFAULT}\):"
123-
C[49]="请输入节点名称 \(默认为 \${NODE_NAME_DEFAULT}\):"
122+
E[49]="Please enter the node name. (Default is \${NODE_NAME_DEFAULT}):"
123+
C[49]="请输入节点名称 (默认为 \${NODE_NAME_DEFAULT}):"
124124
E[50]="\${APP[@]} services are not enabled, node information cannot be output. Press [y] if you want to open."
125125
C[50]="\${APP[@]} 服务未开启,不能输出节点信息。如需打开请按 [y]: "
126126
E[51]="Install Sing-box multi-protocol scripts [https://github.com/fscarmen/sing-box]"
@@ -133,10 +133,10 @@ E[54]="Warp / warp-go was detected to be running. Please enter the correct serve
133133
C[54]="检测到 warp / warp-go 正在运行,请输入确认的服务器 IP:"
134134
E[55]="The script runs today: \$TODAY. Total: \$TOTAL"
135135
C[55]="脚本当天运行次数: \$TODAY,累计运行次数: \$TOTAL"
136-
E[56]="Please enter the Reality port \(Default is \${REALITY_PORT_DEFAULT}\):"
137-
C[56]="请输入 Reality 的端口号 \(默认为 \${REALITY_PORT_DEFAULT}\):"
138-
E[57]="Please enter VPS IP \(Default is: \${SERVER_IP_DEFAULT}\):"
139-
C[57]="请输入 VPS IP \(默认为: \${SERVER_IP_DEFAULT}\):"
136+
E[56]="Please enter the Reality port (Default is \${REALITY_PORT_DEFAULT}):"
137+
C[56]="请输入 Reality 的端口号 (默认为 \${REALITY_PORT_DEFAULT}):"
138+
E[57]="Please enter VPS IP (Default is: \${SERVER_IP_DEFAULT}):"
139+
C[57]="请输入 VPS IP (默认为: \${SERVER_IP_DEFAULT}):"
140140
E[58]="Install ArgoX scripts (argo + xray) [https://github.com/fscarmen/argox]"
141141
C[58]="安装 ArgoX 脚本 (argo + xray) [https://github.com/fscarmen/argox]"
142142
E[59]="To uninstall Nginx press [y], it is not uninstalled by default:"
@@ -179,8 +179,8 @@ E[77]="Change preferred domain or IP (sb -d)"
179179
C[77]="更换优选域名或 IP (sb -d)"
180180
E[78]="Using Cloudflare API to create Tunnel and handle DNS config..."
181181
C[78]="使用 Cloudflare API 创建 Tunnel 和处理 DNS 配置..."
182-
E[79]="Found existing tunnel with the same name. Tunnel ID: \$EXISTING_TUNNEL_ID. Status: \$EXISTING_TUNNEL_STATUS. Overwrite? [y/N] \(default y\):"
183-
C[79]="发现同名隧道已创建,隧道 ID: \$EXISTING_TUNNEL_ID,状态: \$EXISTING_TUNNEL_STATUS。是否覆盖? [y/N] \(默认为 y\):"
182+
E[79]="Found existing tunnel with the same name. Tunnel ID: \$EXISTING_TUNNEL_ID. Status: \$EXISTING_TUNNEL_STATUS. Overwrite? [y/N] (default y):"
183+
C[79]="发现同名隧道已创建,隧道 ID: \$EXISTING_TUNNEL_ID,状态: \$EXISTING_TUNNEL_STATUS。是否覆盖? [y/N] (默认为 y):"
184184
E[80]="Continue with quick fast tunnel"
185185
C[80]="使用临时隧道继续"
186186
E[81]="Invalid access token. Please roll at https://dash.cloudflare.com/profile/api-tokens to re-generate."
@@ -194,13 +194,29 @@ C[84]="执行 API 失败,返回: \$RESPONSE"
194194
E[85]="API does not have enough permissions. Please check at https://dash.cloudflare.com/profile/api-tokens\n\n [*] Json: Users can easily obtain it through the following website: https://fscarmen.cloudflare.now.cc\n\n [*] Cloudflare API: Visit https://dash.cloudflare.com/profile/api-tokens > Create Token > Create Custom Token > Add the following permissions:\n - Account > Cloudflare One Connectors: cloudflared > Edit\n - Zone > DNS > Edit\n\n - Account Resources: Include > Required Account\n - Zone Resources: Include > Specific zone > Argo Root Domain"
195195
C[85]="API 没有足够权限,请在 https://dash.cloudflare.com/profile/api-tokens 检查 Token 权限配置\n\n [*] Token: 访问 https://dash.cloudflare.com/ ,Zero Trust > 网络 > 连接器 > 创建隧道 > 选择 Cloudflared\n\n [*] Json: 用户通过以下网站轻松获取: https://fscarmen.cloudflare.now.cc\n\n [*] Cloudflare API: 访问 https://dash.cloudflare.com/profile/api-tokens > 创建令牌 > 创建自定义令牌 > 添加以下权限:\n - 帐户 > Cloudflare One连接器: Cloudflared > 编辑\n - 区域 > DNS > 编辑\n\n - 帐户资源: 包括 > 所需账户\n - 区域资源: 包括 > 特定区域 > 所需域名"
196196

197+
# 预处理:扫描 E/C 数组,把含 $ 的条目下标记录到关联数组,避免 text() 每次调用都启动 grep 子进程
198+
declare -A TEXT_NEEDS_EVAL
199+
for _text_i in "${!E[@]}"; do
200+
[[ "${E[${_text_i}]}" == *'$'* || "${C[${_text_i}]}" == *'$'* ]] && TEXT_NEEDS_EVAL[${_text_i}]=1
201+
done
202+
197203
# 自定义字体彩色,read 函数
198204
warning() { echo -e "\033[31m\033[01m$*\033[0m"; } # 红色
199205
error() { echo -e "\033[31m\033[01m$*\033[0m" && exit 1; } # 红色
200206
info() { echo -e "\033[32m\033[01m$*\033[0m"; } # 绿色
201207
hint() { echo -e "\033[33m\033[01m$*\033[0m"; } # 黄色
202208
reading() { read -rp "$(info "$1")" "$2"; }
203-
text() { grep -q '\$' <<< "${E[$*]}" && eval echo "\$(eval echo "\${${L}[$*]}")" || eval echo "\${${L}[$*]}"; }
209+
210+
# text <index>:输出当前语言对应的字符串,含 $ 变量的条目用 eval 展开,其余直接 printf
211+
text() {
212+
local -n _text_arr="${L}"
213+
local _text_val="${_text_arr[$*]}"
214+
if [[ -n "${TEXT_NEEDS_EVAL[$*]}" ]]; then
215+
eval "printf '%s' \"${_text_val}\""
216+
else
217+
printf '%s' "${_text_val}"
218+
fi
219+
}
204220

205221
# 检测是否需要启用 Github CDN,如能直接连通,则不使用
206222
check_cdn() {
@@ -437,7 +453,7 @@ statistics_of_run-times() {
437453
local UPDATE_OR_GET=$1
438454
local SCRIPT=$2
439455
if grep -q 'update' <<< "$UPDATE_OR_GET"; then
440-
{ wget --no-check-certificate -qO- --timeout=3 "https://stat.cloudflare.now.cc/api/updateStats?script=${SCRIPT}" > $TEMP_DIR/statistics 2>/dev/null || true; }&
456+
{ wget --no-check-certificate -qO- --timeout=3 "https://stat.cloudflare.now.cc/updateStats?script=${SCRIPT}" > $TEMP_DIR/statistics 2>/dev/null || true; }&
441457
elif grep -q 'get' <<< "$UPDATE_OR_GET"; then
442458
[ -s $TEMP_DIR/statistics ] && [[ $(cat $TEMP_DIR/statistics) =~ \"todayCount\":([0-9]+),\"totalCount\":([0-9]+) ]] && local TODAY="${BASH_REMATCH[1]}" && local TOTAL="${BASH_REMATCH[2]}" && rm -f $TEMP_DIR/statistics
443459
hint "\n*******************************************\n\n $(text 55) \n"
@@ -665,7 +681,6 @@ get_sing_box_version() {
665681

666682
# 定义 Argo 变量,遇到使用 warp 的话,要求输入正确的 IP
667683
argo_variable() {
668-
local ARGO_AUTH_LENGTH=40
669684
if grep -qi 'cloudflare' <<< "$ASNORG4$ASNORG6"; then
670685
if grep -qi 'cloudflare' <<< "$ASNORG6" && [ -n "$WAN4" ] && ! grep -qi 'cloudflare' <<< "$ASNORG4"; then
671686
SERVER_IP_DEFAULT=$WAN4
@@ -729,7 +744,7 @@ argo_variable() {
729744

730745
if [[ -n "$ARGO_DOMAIN" && -z "$ARGO_AUTH" ]]; then
731746
local a=5
732-
until [[ "$ARGO_AUTH" =~ TunnelSecret || "$ARGO_AUTH" =~ [A-Z0-9a-z=]{120,250}$ || "${#ARGO_AUTH}" = $ARGO_AUTH_LENGTH ]]; do
747+
until [[ "$ARGO_AUTH" =~ TunnelSecret || "$ARGO_AUTH" =~ [A-Z0-9a-z=]{120,250}$ || "${#ARGO_AUTH}" =~ ^[3-6][0-9]$ ]]; do
733748
((a--)) || true
734749
if [ "$a" = 0 ]; then
735750
error "\n $(text 3) \n"
@@ -745,7 +760,7 @@ argo_variable() {
745760
ARGO_JSON=${ARGO_AUTH//[ ]/}
746761
elif [[ "$ARGO_AUTH" =~ [A-Z0-9a-z=]{150,250}$ ]]; then
747762
ARGO_TOKEN=$(awk -F ' ' '{print $NF}' <<< "$ARGO_AUTH")
748-
elif [[ "${#ARGO_AUTH}" = $ARGO_AUTH_LENGTH ]]; then
763+
elif [[ "${#ARGO_AUTH}" =~ ^[3-6][0-9]$ ]]; then
749764
hint "\n $(text 78) \n "
750765
create_argo_tunnel "${ARGO_AUTH}" "${ARGO_DOMAIN}" "${NGINX_PORT}"
751766
if [[ ! "$ARGO_JSON" =~ TunnelSecret ]]; then
@@ -1484,7 +1499,7 @@ create_shortcut() {
14841499
cat > $WORK_DIR/sb.sh << EOF
14851500
#!/usr/bin/env bash
14861501
1487-
bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/fscarmen/sba/main/sba.sh) \$1
1502+
bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/fscarmen/sba/main/sba.sh) \$@
14881503
EOF
14891504
chmod +x $WORK_DIR/sb.sh
14901505
ln -sf $WORK_DIR/sb.sh /usr/bin/sb

0 commit comments

Comments
 (0)