mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-11 16:01:28 +00:00
~继续优化
This commit is contained in:
@@ -3,23 +3,26 @@
|
||||
|
||||
#meta内核vmess入站生成
|
||||
[ "$vms_service" = ON ] && {
|
||||
cat >>"$TMPDIR"/yamls/listeners.yaml <<EOF
|
||||
- name: "vmess-in"
|
||||
type: vmess
|
||||
port: $vms_port
|
||||
listen: 0.0.0.0
|
||||
uuid: $vms_uuid
|
||||
ws-path: $vms_ws_path
|
||||
cat >>"$TMPDIR"/listeners.yaml <<EOF
|
||||
- name: "vmess-in"
|
||||
type: vmess
|
||||
port: $vms_port
|
||||
listen:
|
||||
users:
|
||||
- uuid: $vms_uuid
|
||||
alterId: 0
|
||||
ws-path: $vms_ws_path
|
||||
EOF
|
||||
}
|
||||
#meta内核ss入站生成
|
||||
[ "$sss_service" = ON ] && {
|
||||
cat >>"$TMPDIR"/yamls/listeners.yaml <<EOF
|
||||
- name: "ss-in"
|
||||
port: $sss_port
|
||||
listen: 0.0.0.0
|
||||
cipher: $sss_cipher
|
||||
password: $sss_pwd
|
||||
udp: true
|
||||
cat >>"$TMPDIR"/listeners.yaml <<EOF
|
||||
- name: "ss-in"
|
||||
type: shadowsocks
|
||||
port: $sss_port
|
||||
listen:
|
||||
cipher: $sss_cipher
|
||||
password: $sss_pwd
|
||||
udp: true
|
||||
EOF
|
||||
}
|
||||
@@ -2,18 +2,18 @@
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
[ "$wg_service" = ON ] && {
|
||||
cat >>"$TMPDIR"/yamls/proxies.yaml <<EOF
|
||||
- name: "wg"
|
||||
type: wireguard
|
||||
private-key: $wg_private_key
|
||||
server: $wg_server
|
||||
port: $wg_port
|
||||
ip: $wg_ipv4
|
||||
ipv6: $wg_ipv6
|
||||
public-key: $wg_public_key
|
||||
allowed-ips: ['0.0.0.0/0', '::/0']
|
||||
pre-shared-key: $wg_pre_shared_key
|
||||
mtu: 1420
|
||||
udp: true
|
||||
cat >>"$TMPDIR"/proxies.yaml <<EOF
|
||||
- name: "wg"
|
||||
type: wireguard
|
||||
private-key: $wg_private_key
|
||||
server: $wg_server
|
||||
port: $wg_port
|
||||
ip: $wg_ipv4
|
||||
ipv6: $wg_ipv6
|
||||
public-key: $wg_public_key
|
||||
allowed-ips: ['0.0.0.0/0', '::/0']
|
||||
pre-shared-key: $wg_pre_shared_key
|
||||
mtu: 1420
|
||||
udp: true
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
[ "$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
|
||||
{
|
||||
"inbounds": [
|
||||
|
||||
@@ -1,45 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "$CRASHDIR"/configs/ShellCrash.cfg
|
||||
. "$CRASHDIR"/configs/gateway.cfg
|
||||
. "$CRASHDIR"/libs/web_json.sh
|
||||
|
||||
OFFSET=0
|
||||
API="https://api.telegram.org/bot$TG_TOKEN"
|
||||
STATE_FILE="/tmp/ShellCrash/tgbot_state"
|
||||
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() {
|
||||
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(){
|
||||
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
|
||||
请喝咖啡:
|
||||
@@ -93,7 +73,7 @@ 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(){
|
||||
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
|
||||
|
||||
@@ -205,6 +185,6 @@ polling(){
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
send_menu
|
||||
polling
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
CFG="$CRASHDIR"/configs/gateway.cfg
|
||||
touch "$CFG"
|
||||
. "$CFG"
|
||||
|
||||
gateway(){ #访问与控制主菜单
|
||||
@@ -9,13 +10,13 @@ gateway(){ #访问与控制主菜单
|
||||
echo -e "\033[30;47m欢迎使用访问与控制菜单:\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 1 配置公网访问防火墙"
|
||||
echo -e " 2 配置Telegram专属控制机器人"
|
||||
echo -e " 2 配置Telegram专属控制机器人 \033[32m$bot_tg_service\033[0m"
|
||||
echo -e " 3 配置DDNS自动域名"
|
||||
[ "$disoverride" != "1" ] && {
|
||||
echo -e " 4 自定义\033[32m公网Vmess入站\033[0m节点"
|
||||
echo -e " 5 自定义\033[32m公网ShadowSocks入站\033[0m节点"
|
||||
echo -e " 6 配置\033[32mTailscale内网穿透\033[0m(限Singbox)"
|
||||
echo -e " 7 配置\033[32mWireguard客户端\033[0m"
|
||||
echo -e " 4 自定义\033[33m公网Vmess入站\033[0m节点 \033[32m$vms_service\033[0m"
|
||||
echo -e " 5 自定义\033[33m公网ShadowSocks入站\033[0m节点 \033[32m$sss_service\033[0m"
|
||||
echo -e " 6 配置\033[36mTailscale内网穿透\033[0m(限Singbox) \033[32m$ts_service\033[0m"
|
||||
echo -e " 7 配置\033[36mWireguard客户端\033[0m(限Singbox) \033[32m$wg_service\033[0m"
|
||||
}
|
||||
echo -e " 0 返回上级菜单 \033[0m"
|
||||
echo -----------------------------------------------
|
||||
@@ -48,12 +49,16 @@ gateway(){ #访问与控制主菜单
|
||||
else
|
||||
echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m"
|
||||
sleep 1
|
||||
checkupdate && setcore
|
||||
fi
|
||||
gateway
|
||||
;;
|
||||
7)
|
||||
set_wireguard
|
||||
if echo "$crashcore" | grep -q 'sing';then
|
||||
set_wireguard
|
||||
else
|
||||
echo -e "\033[33m$crashcore内核暂不支持此功能,请先更换内核!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
gateway
|
||||
;;
|
||||
*) errornum ;;
|
||||
@@ -112,10 +117,9 @@ set_bot_tg_init(){
|
||||
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)
|
||||
. "$CRASHDIR"/libs/web_json.sh #加载web工具
|
||||
bot_api=https://api.telegram.org/bot$TOKEN
|
||||
chat=$(web_json_get "$bot_api/getUpdates" | 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"
|
||||
@@ -126,15 +130,19 @@ set_bot_tg_init(){
|
||||
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"
|
||||
JSON=$(cat <<EOF
|
||||
{
|
||||
"commands": [
|
||||
{"command": "crash", "description": "呼出ShellCrash菜单"},
|
||||
{"command": "help", "description": "查看帮助"}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
)
|
||||
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
|
||||
else
|
||||
echo -e "\033[31m无法获取对话ID,请重新配置!\033[0m"
|
||||
@@ -143,12 +151,13 @@ set_bot_tg_init(){
|
||||
fi
|
||||
}
|
||||
set_bot_tg_service(){
|
||||
PID=$(pidof /bin/sh "$CRASHDIR"/menus/bot_tg.sh)
|
||||
if [ "$bot_tg_service" = ON ];then
|
||||
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
|
||||
bot_tg_service=ON
|
||||
[ -z "$(pidof bot_tg.sh)" ] && "$CRASHDIR"/components/bot_tg.sh &
|
||||
[ -z "$PID" ] && "$CRASHDIR"/menus/bot_tg.sh &
|
||||
fi
|
||||
setconfig bot_tg_service "$bot_tg_service"
|
||||
}
|
||||
@@ -172,9 +181,12 @@ set_bot_tg(){
|
||||
else
|
||||
set_bot_tg_init && set_bot_tg_service
|
||||
fi
|
||||
sleep 1
|
||||
set_bot_tg
|
||||
;;
|
||||
2)
|
||||
set_bot_tg_init && set_bot_tg_service
|
||||
set_bot_tg
|
||||
;;
|
||||
*)
|
||||
errornum
|
||||
|
||||
@@ -666,7 +666,7 @@ EOF
|
||||
for char in $yaml_char; do #将额外配置文件合并
|
||||
[ -s "$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
|
||||
#合并完整配置文件
|
||||
@@ -2023,6 +2023,8 @@ afstart() { #启动后
|
||||
line=$(grep -En "fw.* start" /etc/init.d/firewall | cut -d ":" -f 1)
|
||||
sed -i "${line}a\\. "$CRASHDIR"/task/affirewall" /etc/init.d/firewall
|
||||
} &
|
||||
#启动TG机器人
|
||||
[ "$bot_tg_service" = ON ] && "$CRASHDIR"/menus/bot_tg.sh &
|
||||
else
|
||||
start_error
|
||||
$0 stop
|
||||
@@ -2120,6 +2122,7 @@ stop)
|
||||
stop_firewall #清理路由策略
|
||||
fi
|
||||
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
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user