From ef4d6f51ebe59ad0e97aebcaae2866c9bf2efef7 Mon Sep 17 00:00:00 2001 From: juewuy Date: Thu, 4 Apr 2024 20:29:46 +0800 Subject: [PATCH] =?UTF-8?q?~=E4=BC=98=E5=8C=96=E4=BA=86=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=EF=BC=8C=E7=8E=B0=E5=9C=A8=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BD=BF=E7=94=A8POST=E6=8E=A5=E5=8F=A3=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=8E=A8=E9=80=81=20~=E6=96=B0=E5=A2=9E=E5=8A=A0=E5=9C=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9A=84=E8=AE=BE=E5=A4=87=E4=B8=8A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA/usr/bin/crash=E5=90=AF=E5=8A=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BB=A5=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=9A=84=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98=20~=E5=B0=86singbox?= =?UTF-8?q?=E7=9A=84=E5=86=85=E7=BD=AEtun=E7=BD=91=E5=8D=A1=E7=BD=91?= =?UTF-8?q?=E6=AE=B5=E6=94=B9=E4=B8=BA172.19.0.1/30=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtun=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=BC=9A?= =?UTF-8?q?=E5=B0=86=E5=9F=9F=E5=90=8D=E9=87=8D=E5=AE=9A=E5=90=91=E5=88=B0?= =?UTF-8?q?127.0.0.1=E7=9A=84bug=20~=E4=BC=98=E5=8C=96=E4=BA=86=E5=BB=B6?= =?UTF-8?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?q?=E4=B8=8D=E6=98=AFsh=20~=E4=BF=AE=E5=A4=8D=E6=96=B0=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E8=B0=83?= =?UTF-8?q?=E7=94=A8iptables=E7=9A=84bug=20~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init.sh | 19 +++++++++---- scripts/menu.sh | 16 ++++------- scripts/start.sh | 69 ++++++++++++++++++++---------------------------- 3 files changed, 48 insertions(+), 56 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index 26a3208..3b81c41 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -160,10 +160,10 @@ else [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then #创建shellcrash用户 - type userdel && userdel shellcrash 2>/dev/null + userdel shellcrash 2>/dev/null sed -i '/0:7890/d' /etc/passwd sed -i '/x:7890/d' /etc/group - if type useradd >/dev/null 2>&1; then + if useradd -h >/dev/null 2>&1; then useradd shellcrash -u 7890 2>/dev/null sed -Ei s/7890:7890/0:7890/g /etc/passwd else @@ -181,8 +181,9 @@ else fi fi #修饰文件及版本号 -command -v bash >/dev/null 2>&1 && shtype=bash || shtype=sh -for file in start.sh task.sh ;do +command -v bash >/dev/null 2>&1 && shtype=bash +[ -x /bin/ash ] && shtype=ash +for file in start.sh task.sh menu.sh;do sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file} chmod 755 ${CRASHDIR}/${file} done @@ -203,7 +204,7 @@ fi setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env #设置防火墙执行模式 [ -z "$(grep firewall_mod $CRASHDIR/configs/ShellClash.cfg 2>/dev/null)" ] && { - ckcmd iptables && firewall_mod=iptables + iptables -j REDIRECT -h >/dev/null 2>&1 && firewall_mod=iptables nft add table inet shellcrash 2>/dev/null && firewall_mod=nftables setconfig firewall_mod $firewall_mod } @@ -233,6 +234,14 @@ if [ -n "$profile" ];then echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc source ~/.zshrc >/dev/null 2>&1 } + #在允许的情况下创建/usr/bin/crash文件 + [ -w /usr/bin ] && { + cat > /usr/bin/crash </dev/null 2>&1 +source ${CRASHDIR}/configs/command.env 2>/dev/null [ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && source ${CRASHDIR}/init.sh >/dev/null 2>&1 [ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR} [ -n "$(tar --help 2>&1|grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容 @@ -25,7 +26,7 @@ ckstatus(){ #检查/读取脚本配置文件 if [ -f $CFG_PATH ];then [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查重复行并去除 - source $CFG_PATH >/dev/null 2>&1 + source $CFG_PATH 2>/dev/null else source ${CRASHDIR}/init.sh >/dev/null 2>&1 fi @@ -270,7 +271,7 @@ log_pusher(){ #日志菜单 echo ----------------------------------------------- read -p "请输入你获取到的API TOKEN > " TOKEN echo ----------------------------------------------- - echo -e "\033[32m请通过Telegram的对话窗口,向该机器人发送任意消息!\033[0m" + echo -e "请向\033[32m你申请的机器人\033[31m而不是BotFather\033[0m,发送任意几条消息!" echo ----------------------------------------------- read -p "我已经发送完成(1/0) > " res if [ "$res" = 1 ];then @@ -342,14 +343,6 @@ log_pusher(){ #日志菜单 if [ -n "$url" ];then push_bark=$url setconfig push_bark $url - echo ----------------------------------------------- - echo -e "\033[32m例: ?group=ShellCrash\033[0m" - read -p "请输入你的Bark请求参数(默认回车为空) > " param - param=$(echo $param | sed 's/\&/\\\&/g') - if [ -n "$param" ];then - bark_param=$param - setconfig bark_param \'$param\' - fi ${CRASHDIR}/start.sh logger "已完成Bark日志推送设置!" 32 else echo -e "\033[31m输入错误,请重新输入!\033[0m" @@ -1651,6 +1644,7 @@ uninstall(){ rm -rf /usr/lib/systemd/system/shellcrash.service rm -rf /www/clash rm -rf /tmp/ShellCrash + rm -rf /usr/bin/crash sed -i '/0:7890/d' /etc/passwd userdel -r shellcrash 2>/dev/null nvram set script_usbmount="" 2>/dev/null diff --git a/scripts/start.sh b/scripts/start.sh index f985b69..9bda8d8 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -80,55 +80,46 @@ logger(){ #日志工具 log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1" echo $log_text >> ${TMPDIR}/ShellCrash.log [ "$(wc -l ${TMPDIR}/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,50d' ${TMPDIR}/ShellCrash.log - [ -z "$3" ] && { - [ -n "$device_name" ] && log_text="$log_text($device_name)" + #推送工具 + webpush(){ [ -n "$(pidof CrashCore)" ] && { [ -n "$authentication" ] && auth="$authentication@" export https_proxy="http://${auth}127.0.0.1:$mix_port" } + 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 + elif wget --version >/dev/null 2>&1;then + wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json; charset=utf-8" --body-data="$2" "$1" + else + echo "找不到有效的curl或wget应用,请先安装!" + fi + } + [ -z "$3" ] && { + [ -n "$device_name" ] && log_text="$log_text($device_name)" [ -n "$push_TG" ] && { url="https://api.telegram.org/bot${push_TG}/sendMessage" - curl_data="-d chat_id=$chat_ID&text=$log_text" - wget_data="--post-data=$chat_ID&text=$log_text" - if curl --version >/dev/null 2>&1;then - curl -kfsSl --connect-timeout 3 -d "chat_id=$chat_ID&text=$log_text" "$url" >/dev/null 2>&1 - else - wget -Y on -q --timeout=3 -t 1 --post-data="chat_id=$chat_ID&text=$log_text" "$url" - fi + content="{\"chat_id\":\"${chat_ID}\",\"text\":\"$log_text\"}" + webpush "$url" "$content" & } [ -n "$push_bark" ] && { - url="${push_bark}/${log_text}${bark_param}" - if curl --version >/dev/null 2>&1;then - curl -kfsSl --connect-timeout 3 "$url" >/dev/null 2>&1 - else - wget -Y on -q --timeout=3 -t 1 "$url" - fi + url="${push_bark}" + content="{\"body\":\"${log_text}\",\"title\":\"ShellCrash日志推送\",\"level\":\"passive\",\"badge\":\"1\"}" + webpush "$url" "$content" & } [ -n "$push_Deer" ] && { - url="https://api2.pushdeer.com/message/push?pushkey=${push_Deer}" - if curl --version >/dev/null 2>&1;then - curl -kfsSl --connect-timeout 3 "$url"\&text="$log_text" >/dev/null 2>&1 - else - wget -Y on -q --timeout=3 -t 1 "$url"\&text="$log_text" - fi + url="https://api2.pushdeer.com/message/push" + content="{\"pushkey\":\"${push_Deer}\",\"text\":\"$log_text\"}" + webpush "$url" "$content" & } [ -n "$push_Po" ] && { url="https://api.pushover.net/1/messages.json" content="{\"token\":\"${push_Po}\",\"user\":\"${push_Po_key}\",\"title\":\"ShellCrash日志推送\",\"message\":\"$log_text\"}" - if curl --version >/dev/null 2>&1;then - curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$url" -d "$content" >/dev/null 2>&1 - else - wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json" --body-data="$content" "$url" - fi + webpush "$url" "$content" & } [ -n "$push_PP" ] && { url="http://www.pushplus.plus/send" content="{\"token\":\"${push_PP}\",\"title\":\"ShellCrash日志推送\",\"content\":\"$log_text\"}" - if curl --version >/dev/null 2>&1;then - curl -sS -X POST --connect-timeout 3 -H "Content-Type: application/json" "$url" -d "$content" >/dev/null 2>&1 - else - wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json" --body-data="$content" "$url" - fi + webpush "$url" "$content" & } } & } @@ -738,12 +729,12 @@ EOF "type": "tun", "tag": "tun-in", "interface_name": "utun", - "inet4_address": "198.18.0.0/16", + "inet4_address": "172.19.0.1/30", "auto_route": false, "stack": "system", $always_resolve_udp "sniff": true, - "sniff_override_destination": true + "sniff_override_destination": $sniffer } ] } @@ -1584,8 +1575,11 @@ singbox_check(){ #singbox启动前检查 } bfstart(){ #启动前 routing_mark=$((fwmark + 2)) - #读取ShellCrash配置 - [ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master + #延迟启动 + [ ! -f ${TMPDIR}/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { + logger "ShellCrash将延迟$start_delay秒启动" 31 pushoff + sleep $start_delay + } [ ! -d ${BINDIR}/ui ] && mkdir -p ${BINDIR}/ui [ -z "$crashcore" ] && crashcore=clash #执行条件任务 @@ -1640,11 +1634,6 @@ bfstart(){ #启动前 } afstart(){ #启动后 [ -z "$firewall_area" ] && firewall_area=1 - #延迟启动 - [ ! -f ${TMPDIR}/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { - logger "ShellCrash将延迟$start_delay秒启动" 31 pushoff - sleep $start_delay - } #设置循环检测面板端口以判定服务启动是否成功 i=1 while [ -z "$test" -a "$i" -lt 5 ];do