~继续优化

This commit is contained in:
juewuy
2025-12-20 20:30:50 +08:00
parent 51f5795731
commit 9a2d98a6b8
6 changed files with 78 additions and 80 deletions

View File

@@ -3,23 +3,26 @@
#meta内核vmess入站生成 #meta内核vmess入站生成
[ "$vms_service" = ON ] && { [ "$vms_service" = ON ] && {
cat >>"$TMPDIR"/yamls/listeners.yaml <<EOF cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "vmess-in" - name: "vmess-in"
type: vmess type: vmess
port: $vms_port port: $vms_port
listen: 0.0.0.0 listen:
uuid: $vms_uuid users:
ws-path: $vms_ws_path - uuid: $vms_uuid
alterId: 0
ws-path: $vms_ws_path
EOF EOF
} }
#meta内核ss入站生成 #meta内核ss入站生成
[ "$sss_service" = ON ] && { [ "$sss_service" = ON ] && {
cat >>"$TMPDIR"/yamls/listeners.yaml <<EOF cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "ss-in" - name: "ss-in"
port: $sss_port type: shadowsocks
listen: 0.0.0.0 port: $sss_port
cipher: $sss_cipher listen:
password: $sss_pwd cipher: $sss_cipher
udp: true password: $sss_pwd
udp: true
EOF EOF
} }

View File

@@ -2,18 +2,18 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
[ "$wg_service" = ON ] && { [ "$wg_service" = ON ] && {
cat >>"$TMPDIR"/yamls/proxies.yaml <<EOF cat >>"$TMPDIR"/proxies.yaml <<EOF
- name: "wg" - name: "wg"
type: wireguard type: wireguard
private-key: $wg_private_key private-key: $wg_private_key
server: $wg_server server: $wg_server
port: $wg_port port: $wg_port
ip: $wg_ipv4 ip: $wg_ipv4
ipv6: $wg_ipv6 ipv6: $wg_ipv6
public-key: $wg_public_key public-key: $wg_public_key
allowed-ips: ['0.0.0.0/0', '::/0'] allowed-ips: ['0.0.0.0/0', '::/0']
pre-shared-key: $wg_pre_shared_key pre-shared-key: $wg_pre_shared_key
mtu: 1420 mtu: 1420
udp: true udp: true
EOF EOF
} }

View File

@@ -2,7 +2,7 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
[ "$vms_service" = ON ] && { [ "$vms_service" = ON ] && {
[ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": '"$vms_ws_path"' }' [ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": "'"$vms_ws_path"'" }'
cat >"$TMPDIR"/jsons/vmess-in.json <<EOF cat >"$TMPDIR"/jsons/vmess-in.json <<EOF
{ {
"inbounds": [ "inbounds": [

View File

@@ -1,45 +1,25 @@
#!/bin/sh #!/bin/sh
. "$CRASHDIR"/configs/ShellCrash.cfg
. "$CRASHDIR"/configs/gateway.cfg . "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/web_json.sh
OFFSET=0 OFFSET=0
API="https://api.telegram.org/bot$TG_TOKEN" API="https://api.telegram.org/bot$TG_TOKEN"
STATE_FILE="/tmp/ShellCrash/tgbot_state" STATE_FILE="/tmp/ShellCrash/tgbot_state"
LOGFILE="/tmp/ShellCrash/tgbot.log" LOGFILE="/tmp/ShellCrash/tgbot.log"
### --- 基础函数 --- ### ### --- 基础函数 --- ###
setproxy(){
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@"
[ -z "$mix_port" ] && mix_port=7890
export https_proxy="http://${auth}127.0.0.1:$mix_port"
}
}
webget() {
setproxy
if curl --version >/dev/null 2>&1; then
curl -kfsSl --connect-timeout 3 $1 2>/dev/null
else
wget -Y on -q --timeout=3 -O - $1
fi
}
webpost() {
setproxy
if curl --version >/dev/null 2>&1; then
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json; charset=utf-8" "$1" -d "$2" >/dev/null 2>&1
else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json; charset=utf-8" --body-data="$2" "$1"
fi
}
send_msg() { send_msg() {
TEXT="$1" TEXT="$1"
webpost "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\",\"parse_mode\":\"Markdown\"}" web_json_post "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\",\"parse_mode\":\"Markdown\"}"
} }
send_help(){ send_help(){
TEXT=$(cat <<EOF TEXT=$(cat <<EOF
进群讨论: 进群讨论:
https://t.me/+RKujv98Gbx5zGY-P https://t.me/+6AElkMDzwPxmMmM1
项目地址: 项目地址:
https://github.com/juewuy/ShellCrash https://github.com/juewuy/ShellClash
相关教程: 相关教程:
https://juewuy.github.io https://juewuy.github.io
请喝咖啡: 请喝咖啡:
@@ -93,7 +73,7 @@ EOF
EOF EOF
) )
webpost "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\",\"parse_mode\":\"Markdown\",\"reply_markup\":$MENU}" web_json_post "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\",\"parse_mode\":\"Markdown\",\"reply_markup\":$MENU}"
} }
@@ -129,7 +109,7 @@ do_set_sub() {
### --- 轮询主进程 --- ### ### --- 轮询主进程 --- ###
polling(){ polling(){
while true; do while true; do
UPDATES=$(webget "$API/getUpdates?timeout=25&offset=$OFFSET") UPDATES=$(web_json_get "$API/getUpdates?timeout=25&offset=$OFFSET")
echo "$UPDATES" | grep -q '"update_id"' || continue echo "$UPDATES" | grep -q '"update_id"' || continue
@@ -205,6 +185,6 @@ polling(){
done done
} }
send_menu
polling polling

View File

@@ -2,6 +2,7 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
CFG="$CRASHDIR"/configs/gateway.cfg CFG="$CRASHDIR"/configs/gateway.cfg
touch "$CFG"
. "$CFG" . "$CFG"
gateway(){ #访问与控制主菜单 gateway(){ #访问与控制主菜单
@@ -9,13 +10,13 @@ gateway(){ #访问与控制主菜单
echo -e "\033[30;47m欢迎使用访问与控制菜单\033[0m" echo -e "\033[30;47m欢迎使用访问与控制菜单\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 配置公网访问防火墙" echo -e " 1 配置公网访问防火墙"
echo -e " 2 配置Telegram专属控制机器人" echo -e " 2 配置Telegram专属控制机器人 \033[32m$bot_tg_service\033[0m"
echo -e " 3 配置DDNS自动域名" echo -e " 3 配置DDNS自动域名"
[ "$disoverride" != "1" ] && { [ "$disoverride" != "1" ] && {
echo -e " 4 自定义\033[32m公网Vmess入站\033[0m节点" echo -e " 4 自定义\033[33m公网Vmess入站\033[0m节点 \033[32m$vms_service\033[0m"
echo -e " 5 自定义\033[32m公网ShadowSocks入站\033[0m节点" echo -e " 5 自定义\033[33m公网ShadowSocks入站\033[0m节点 \033[32m$sss_service\033[0m"
echo -e " 6 配置\033[32mTailscale内网穿透\033[0m(限Singbox)" echo -e " 6 配置\033[36mTailscale内网穿透\033[0m(限Singbox) \033[32m$ts_service\033[0m"
echo -e " 7 配置\033[32mWireguard客户端\033[0m" echo -e " 7 配置\033[36mWireguard客户端\033[0m(限Singbox) \033[32m$wg_service\033[0m"
} }
echo -e " 0 返回上级菜单 \033[0m" echo -e " 0 返回上级菜单 \033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@@ -48,12 +49,16 @@ gateway(){ #访问与控制主菜单
else else
echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m" echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m"
sleep 1 sleep 1
checkupdate && setcore
fi fi
gateway gateway
;; ;;
7) 7)
set_wireguard if echo "$crashcore" | grep -q 'sing';then
set_wireguard
else
echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m"
sleep 1
fi
gateway gateway
;; ;;
*) errornum ;; *) errornum ;;
@@ -112,10 +117,9 @@ set_bot_tg_init(){
echo ----------------------------------------------- echo -----------------------------------------------
read -p "我已经发送完成(1/0) > " res read -p "我已经发送完成(1/0) > " res
if [ "$res" = 1 ]; then if [ "$res" = 1 ]; then
url_tg=https://api.telegram.org/bot${TOKEN}/getUpdates . "$CRASHDIR"/libs/web_json.sh #加载web工具
[ -n "$authentication" ] && auth="$authentication@" bot_api=https://api.telegram.org/bot$TOKEN
export https_proxy="http://${auth}127.0.0.1:$mix_port" chat=$(web_json_get "$bot_api/getUpdates" | tail -n -1)
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) [ -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" ] && { [ -z "$chat_ID" ] && {
echo -e "\033[31m无法获取对话ID请确认使用的不是已经被绑定的机器人或手动输入ChatID\033[0m" echo -e "\033[31m无法获取对话ID请确认使用的不是已经被绑定的机器人或手动输入ChatID\033[0m"
@@ -126,15 +130,19 @@ set_bot_tg_init(){
setconfig TG_TOKEN $TOKEN "$CFG" setconfig TG_TOKEN $TOKEN "$CFG"
setconfig TG_CHATID $chat_ID "$CFG" setconfig TG_CHATID $chat_ID "$CFG"
#设置机器人快捷命令 #设置机器人快捷命令
curl -s -X POST "https://api.telegram.org/bot$TOKEN/setMyCommands" \ JSON=$(cat <<EOF
-H "Content-Type: application/json" \ {
-d '{ "commands": [
"commands": [ {"command": "crash", "description": "呼出ShellCrash菜单"},
{"command": "crash", "description": "呼出ShellCrash菜单"}, {"command": "help", "description": "查看帮助"}
{"command": "help", "description": "查看帮助"} ]
] }
}' EOF
echo -e "\033[32m已完成Telegram机器人设置\033[0m" )
TEXT='已完成Telegram机器人设置'
web_json_post "$bot_api/setMyCommands" "$JSON"
web_json_post "$bot_api/sendMessage" '{"chat_id":"'"$chat_ID"'","text":"'"$TEXT"'","parse_mode":"Markdown"}'
echo -e "\033[32m$TEXT\033[0m"
return 0 return 0
else else
echo -e "\033[31m无法获取对话ID请重新配置\033[0m" echo -e "\033[31m无法获取对话ID请重新配置\033[0m"
@@ -143,12 +151,13 @@ set_bot_tg_init(){
fi fi
} }
set_bot_tg_service(){ set_bot_tg_service(){
PID=$(pidof /bin/sh "$CRASHDIR"/menus/bot_tg.sh)
if [ "$bot_tg_service" = ON ];then if [ "$bot_tg_service" = ON ];then
bot_tg_service=OFF bot_tg_service=OFF
PID=$(pidof bot_tg.sh) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1 [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
else else
bot_tg_service=ON bot_tg_service=ON
[ -z "$(pidof bot_tg.sh)" ] && "$CRASHDIR"/components/bot_tg.sh & [ -z "$PID" ] && "$CRASHDIR"/menus/bot_tg.sh &
fi fi
setconfig bot_tg_service "$bot_tg_service" setconfig bot_tg_service "$bot_tg_service"
} }
@@ -172,9 +181,12 @@ set_bot_tg(){
else else
set_bot_tg_init && set_bot_tg_service set_bot_tg_init && set_bot_tg_service
fi fi
sleep 1
set_bot_tg
;; ;;
2) 2)
set_bot_tg_init && set_bot_tg_service set_bot_tg_init && set_bot_tg_service
set_bot_tg
;; ;;
*) *)
errornum errornum

View File

@@ -666,7 +666,7 @@ EOF
for char in $yaml_char; do #将额外配置文件合并 for char in $yaml_char; do #将额外配置文件合并
[ -s "$TMPDIR"/${char}.yaml ] && { [ -s "$TMPDIR"/${char}.yaml ] && {
sed -i "1i\\${char}:" "$TMPDIR"/${char}.yaml sed -i "1i\\${char}:" "$TMPDIR"/${char}.yaml
yaml_add="$yaml_add "$TMPDIR"/${char}.yaml" yaml_add="$yaml_add $TMPDIR/${char}.yaml"
} }
done done
#合并完整配置文件 #合并完整配置文件
@@ -2023,6 +2023,8 @@ afstart() { #启动后
line=$(grep -En "fw.* start" /etc/init.d/firewall | cut -d ":" -f 1) line=$(grep -En "fw.* start" /etc/init.d/firewall | cut -d ":" -f 1)
sed -i "${line}a\\. "$CRASHDIR"/task/affirewall" /etc/init.d/firewall sed -i "${line}a\\. "$CRASHDIR"/task/affirewall" /etc/init.d/firewall
} & } &
#启动TG机器人
[ "$bot_tg_service" = ON ] && "$CRASHDIR"/menus/bot_tg.sh &
else else
start_error start_error
$0 stop $0 stop
@@ -2120,6 +2122,7 @@ stop)
stop_firewall #清理路由策略 stop_firewall #清理路由策略
fi fi
PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1 PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
PID=$(pidof /bin/sh "$CRASHDIR"/menus/bot_tg.sh) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
#清理缓存目录 #清理缓存目录
rm -rf "$TMPDIR"/CrashCore rm -rf "$TMPDIR"/CrashCore
;; ;;