已添加 scripts/components/bot_tg.sh

已添加        scripts/components/ddns_op.sh
已修改        scripts/components/gateway.sh
This commit is contained in:
juewuy
2025-12-14 08:50:18 +08:00
parent 3c302d6e1f
commit 602d454421
3 changed files with 526 additions and 70 deletions

View File

@@ -13,7 +13,7 @@ gateway(){
echo -e " 3 配置DDNS自动域名"
[ "$disoverride" != "1" ] && {
echo -e " 4 自定义公网入站节点"
echo -e " 5 配置\033[32m内网穿透\033[0m(WireGuard/Tailscale)"
echo -e " 5 配置\033[32m内网穿透\033[0m(Tailscale,仅限Singbox)"
}
echo -e " 0 返回上级菜单 \033[0m"
echo -----------------------------------------------
@@ -21,73 +21,160 @@ gateway(){
case "$num" in
0) ;;
1)
setfirewall
set_pub_fw
gateway
;;
2)
settgadvbot
set_bot_tg
gateway
;;
3)
setddns
set_ddns
gateway
;;
4)
setlisteners
set_listeners
gateway
;;
5)
setendpoints
if echo "$crashcore" | grep -q 'sing';then
setendpoints
else
echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m"
sleep 1
checkupdate && setcore
fi
gateway
;;
*) errornum ;;
esac
}
set_pub_fw() { #公网防火墙设置
[ -z "$public_support" ] && public_support=未开启
[ -z "$public_mixport" ] && public_mixport=未开启
echo -----------------------------------------------
echo -e " 1 公网访问Dashboard面板: \033[36m$public_support\033[0m"
echo -e " 2 公网访问Socks/Http代理: \033[36m$public_mixport\033[0m"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
case $num in
1)
if [ "$public_support" = "未开启" ]; then
public_support=已开启
else
public_support=未开启
fi
setconfig public_support $public_support
setfirewall
;;
2)
if [ "$public_mixport" = "未开启" ]; then
if [ "$mix_port" = "7890" -o -z "$authentication" ]; then
echo -----------------------------------------------
echo -e "\033[33m为了安全考虑请先修改默认Socks/Http端口并设置代理密码\033[0m"
sleep 1
setport
else
public_mixport=已开启
fi
else
public_mixport=未开启
fi
setconfig public_mixport $public_mixport
setfirewall
;;
3)
set_cust_host_ipv4
setfirewall
;;
*)
errornum
;;
esac
}
set_bot_tg_init(){
echo -----------------------------------------------
echo -e "请先通过 \033[32;4mhttps://t.me/BotFather\033[0m 申请TG机器人并获取其\033[36mAPI TOKEN\033[0m"
echo -----------------------------------------------
read -p "请输入你获取到的API TOKEN > " TOKEN
echo -----------------------------------------------
echo -e "请向\033[32m你申请的机器人\033[31m而不是BotFather\033[0m发送任意几条消息"
echo -----------------------------------------------
read -p "我已经发送完成(1/0) > " res
if [ "$res" = 1 ]; then
url_tg=https://api.telegram.org/bot${TOKEN}/getUpdates
[ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port"
chat=$(webget $url_tg | tail -n -1)
[ -n "$chat" ] && chat_ID=$(echo $chat | grep -oE '"id":.*,"is_bot":false' | sed s'/"id"://'g | sed s'/,"is_bot":false//'g)
[ -z "$chat_ID" ] && {
echo -e "\033[31m无法获取对话ID请确认使用的不是已经被绑定的机器人或手动输入ChatID\033[0m"
echo -e "通常访问 $url_tg 即可看到ChatID也可以尝试其他方法\033[0m"
read -p "请手动输入ChatID > " chat_ID
}
if [ -n "$chat_ID" ]; then
setconfig TG_TOKEN $TOKEN "$CFG"
setconfig TG_CHATID $chat_ID "$CFG"
#设置机器人快捷命令
curl -s -X POST "https://api.telegram.org/bot$TOKEN/setMyCommands" \
-H "Content-Type: application/json" \
-d '{
"commands": [
{"command": "crash", "description": "呼出ShellCrash菜单"},
{"command": "help", "description": "查看帮助"}
]
}'
echo -e "\033[32m已完成Telegram机器人设置\033[0m"
return 0
else
echo -e "\033[31m无法获取对话ID请重新配置\033[0m"
return 1
fi
fi
}
set_bot_tg_service(){
if [ "$bot_tg_service" = ON ];then
bot_tg_service=OFF
PID=$(pidof bot_tg.sh) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
else
bot_tg_service=ON
[ -z "$(pidof bot_tg.sh)" ] && "$CRASHDIR"/components/bot_tg.sh &
fi
setconfig bot_tg_service "$bot_tg_service"
}
set_bot_tg(){
[ -n "$ts_auth_key" ] && ts_auth_key_info='已设置'
echo -----------------------------------------------
echo -e "\033[31m注意\033[0m由于网络环境原因此机器人仅限服务启动时运行"
echo -e "此机器人与推送机器人互不影响,请尽量不要设置成同一机器人"
echo -----------------------------------------------
echo -e " 1 启用/关闭TG-BOT服务 \033[32m$bot_tg_service\033[0m"
echo -e " 2 TG-BOT绑定设置"
echo -e " 0 返回上级菜单 \033[0m"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
case "$num" in
0) ;;
1)
. "$CFG"
if [ -n "$TG_CHATID" ];then
set_bot_tg_service
else
set_bot_tg_init && set_bot_tg_service
fi
;;
2)
set_bot_tg_init && set_bot_tg_service
;;
*)
errornum
;;
esac
}
set_ddns(){
echo
}
setendpoints(){
setwireguard(){
echo -----------------------------------------------
echo -e "\033[31m注意\033[0m脚本默认内核为了节约内存没有编译WireGuard模块\n如需使用请先前往自定义内核更新完整版内核文件"
echo -----------------------------------------------
echo -e " 1 设置服务器地址"
echo -e " 2 设置服务器端口"
echo -e " 3 设置服务端公钥"
echo -e " 4 设置本地私钥"
echo -e " 5 设置本地IPV4地址"
echo -e " 6 设置本地IPV6地址"
echo -e " 0 返回上级菜单 \033[0m"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
read -p "请输入相应内容 > " text
case "$num" in
0) ;;
1)
setconfig wg_server "$text" "$CFG"
setwireguard
;;
2)
setconfig wg_port "$text" "$CFG"
setwireguard
;;
3)
setconfig wg_publickey "$text" "$CFG"
setwireguard
;;
4)
setconfig wg_privatekey "$text" "$CFG"
setwireguard
;;
5)
setconfig wg_ipv4 "$text" "$CFG"
setwireguard
;;
6)
setconfig wg_ipv6 "$text" "$CFG"
setwireguard
;;
*) errornum ;;
esac
}
settailscale(){
[ -n "$ts_auth_key" ] && ts_auth_key_info='已设置'
echo -----------------------------------------------
@@ -129,24 +216,5 @@ setendpoints(){
*) errornum ;;
esac
}
echo -----------------------------------------------
echo -e "\033[31m注意\033[0m脚本默认内核为了节约内存没有编译WireGuard/Tailscale模块\n如需使用请先前往自定义内核更新完整版内核文件"
echo -----------------------------------------------
echo -e " 1 配置WireGuard客户端"
echo -e " 2 配置Tailscale(仅限Singbox内核)"
echo -e " 0 返回上级菜单"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
case "$num" in
0) ;;
1)
setwireguard
setendpoints
;;
2)
settailscale
setendpoints
;;
*) errornum ;;
esac
settailscale
}