~重写本机代理部分逻辑,修复相关死循环bug
~安装时现在默认会自动清理多余的旧目录
~现在在linux设备上默认使用保守模式而不是systemd
~singbox默认启用sniff以匹配规则,但不会覆写域名
~修复使用systemd启动时,无法正确配置防火墙的bug
~修复在线生成时导入包含@符号的链接时,无法正确转换的bug
~修复singbox对ipv6-tun模式的支持
This commit is contained in:
juewuy 2024-01-24 16:09:10 +08:00
parent 85558022fa
commit 5c8cfd7b71
10 changed files with 45 additions and 43 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5,4 +5,4 @@ meta_v=v1.18.0
singbox_v=1.7.8
GeoIP_v=20240120
versionsh=1.8.8c
versionsh=1.8.8d

View File

@ -661,12 +661,12 @@ set_core_config(){ #配置文件功能
echo -----------------------------------------------
echo -e "\033[30;47m ShellCrash配置文件管理\033[0m"
echo -----------------------------------------------
echo -e " 1 在线\033[32m生成内核配置文件\033[0m"
echo -e " 1 在线\033[32m生成$crashcore配置文件\033[0m"
echo -e " 2 导入\033[33m外部配置文件链接\033[0m"
echo -e " 3 \033[36m管理\033[0m配置文件"
echo -e " 4 \033[33m更新\033[0m配置文件"
echo -e " 5 设置\033[36m自动更新\033[0m"
echo -e " 6 配置文件\033[32m覆写\033[0m"
echo -e " 6 \033[32m自定义\033[0m配置文件"
echo -----------------------------------------------
[ "$inuserguide" = 1 ] || echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@ -871,15 +871,15 @@ switch_core(){
setconfig geosite_cn_v
}
read -p "是否保留$core_old相关配置文件(1/0) > " res
[ "$res" = '0' ] && [ "$core_old" = "clash" ] && rm -rf ${CRASHDIR}/yamls
[ "$res" = '0' ] && [ "$core_old" = "singbox" ] && rm -rf ${CRASHDIR}/jsons
[ "$res" = '0' ] && [ "$core_old" = "clash" ] && rm -rf ${CRASHDIR}/yamls/*
[ "$res" = '0' ] && [ "$core_old" = "singbox" ] && rm -rf ${CRASHDIR}/jsons/*
}
if [ "$crashcore" = singbox ];then
COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"'
else
COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
fi
setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env
setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env && source ${CRASHDIR}/configs/command.env
}
getcore(){
[ -z "$crashcore" ] && crashcore=clashpre

View File

@ -1,7 +1,7 @@
#!/bin/sh
# Copyright (C) Juewuy
version=1.8.8c
version=1.8.8d
setdir(){
dir_avail(){
@ -159,15 +159,24 @@ else
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then
#设为systemd方式启动
#创建shellcrash用户并赋予root权限
if type userdel useradd groupmod; then
userdel shellcrash 2>/dev/null
useradd shellcrash -u 7890 2>/dev/null
groupmod shellcrash -g 7890
sed -Ei s/7890:7890/0:7890/g /etc/passwd
else
sed -i '/0:7890/d' /etc/passwd
echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >> /etc/passwd
fi
#配置systemd
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
rm -rf $sysdir/clash.service #旧版文件清理
systemctl daemon-reload
else
#设为保守模式启动
setconfig start_old 已开启
fi
#设为保守模式启动
setconfig start_old 已开启
fi
#修饰文件及版本号
command -v bash &>/dev/null && shtype=bash || shtype=sh
@ -272,11 +281,8 @@ done
chmod 755 ${CRASHDIR}/task/task.sh
#旧版文件清理
rm -rf /etc/init.d/clash
rm -rf $CRASHDIR/clashservice
rm -rf $CRASHDIR/core.new
rm -rf $CRASHDIR/shellcrash.rc
rm -rf $CRASHDIR/clash.sh
for file in log shellcrash.service mark? mark.bak;do
[ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/clash
for file in clash.sh shellcrash.rc core.new clashservice log shellcrash.service mark? mark.bak;do
rm -rf ${CRASHDIR}/$file
done
#旧版变量改名

View File

@ -1371,7 +1371,7 @@ normal_set(){ #基础设置
local_proxy=未开启
setconfig local_proxy $local_proxy
setconfig local_type
sed -i '/user shellcrash/d' /etc/init.d/clash 2>/dev/null
[ -w /etc/init.d/shellcrash ] && sed -i 's/procd_set_param user shellcrash/procd_set_param user root/' /etc/init.d/shellcrash
echo -e "\033[33m已经停用本机代理规则,请尽快重启服务!!\033[0m"
fi
sleep 1

View File

@ -16,6 +16,7 @@ start_service() {
if [ "$?" = "0" ];then
#使用procd创建clash后台进程
procd_open_instance
procd_set_param user root
procd_set_param respawn
procd_set_param command $COMMAND
procd_set_param stderr 0

View File

@ -4,15 +4,13 @@ After=network.target
[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
User=shellcrash
ExecStartPre=/etc/ShellCrash/start.sh bfstart
ExecStart=/etc/ShellCrash/CrashCore run -D /etc/ShellCrash -c /tmp/ShellCrash/config.json
ExecStartPost=/etc/ShellCrash/start.sh afstart
ExecStartPost=/etc/ShellCrash/start.sh afstart >/dev/null &
ExecStopPost=/etc/ShellCrash/start.sh stop_firewall ; /etc/ShellCrash/start.sh unset_proxy
Restart=on-failure
RestartSec=5s
Restart=on-abnormal
RestartSec=10s
LimitNOFILE=infinity

View File

@ -246,7 +246,7 @@ get_core_config(){ #下载内核配置文件
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ];then
#Urlencord转码处理保留字符
Url=$(echo $Url | sed 's/;/\%3B/g; s|/|\%2F|g; s/?/\%3F/g; s/:/\%3A/g; s/@/\%4O/g; s/=/\%3D/g; s/&/\%26/g')
Url=$(echo $Url | sed 's/;/\%3B/g; s|/|\%2F|g; s/?/\%3F/g; s/:/\%3A/g; s/@/\%40/g; s/=/\%3D/g; s/&/\%26/g')
Https="${Server}/sub?target=${target}&insert=true&new_name=true&scv=true&udp=true&exclude=${exclude}&include=${include}&url=${Url}&config=${Config}"
url_type=true
fi
@ -628,14 +628,14 @@ EOF
"tag": "redirect-in",
"listen": "::",
"listen_port": $redir_port,
"sniff": $sniffer,
"sniff": true,
"sniff_override_destination": $sniffer
}, {
"type": "tproxy",
"tag": "tproxy-in",
"listen": "::",
"listen_port": $tproxy_port,
"sniff": $sniffer,
"sniff": true,
"sniff_override_destination": $sniffer
EOF
if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ];then
@ -647,7 +647,7 @@ EOF
"inet4_address": "198.18.0.0/16",
"auto_route": false,
"stack": "system",
"sniff": $sniffer,
"sniff": true,
"sniff_override_destination": $sniffer
}
],
@ -1028,7 +1028,7 @@ start_tun(){ #iptables-tun
[ "$1" = "all" ] && iptables -t mangle -A PREROUTING -p tcp $ports -j shellcrash
#设置ipv6转发
[ "$ipv6_redir" = "已开启" -a "$crashcore" = "meta" ] && {
[ "$ipv6_redir" = "已开启" ] && [ "$crashcore" = "singbox" -o "$crashcore" = "meta" ] && {
ip -6 route add default dev utun table 101
ip -6 rule add fwmark $fwmark table 101
ip6tables -t mangle -N shellcrashv6
@ -1538,21 +1538,18 @@ bfstart(){ #启动前
if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then
#添加shellcrash用户
if [ -z "$(id shellcrash 2>/dev/null | grep 'root')" ];then
sed -i '/0:7890/d' /etc/passwd
grep -qw shellcrash /etc/passwd || echo "shellcrash:x:0:7890:::" >> /etc/passwd
fi
#修改启动文件
if [ "$start_old" != "已开启" ];then
[ -w /etc/systemd/system/shellcrash.service ] && servdir=/etc/systemd/system/shellcrash.service
[ -w /usr/lib/systemd/system/shellcrash.service ] && servdir=/usr/lib/systemd/system/shellcrash.service
if [ -w /etc/init.d/shellcrash ]; then
[ -z "$(grep 'procd_set_param user shellcrash' /etc/init.d/shellcrash)" ] && \
sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellcrash' /etc/init.d/shellcrash
elif [ -w "$servdir" ]; then
setconfig User shellcrash $servdir
systemctl daemon-reload >/dev/null
if ckcmd userdel useradd groupmod; then
userdel shellcrash 2>/dev/null
useradd shellcrash -u 7890
groupmod shellcrash -g 7890
sed -Ei s/7890:7890/0:7890/g /etc/passwd
else
sed -i '/0:7890/d' /etc/passwd
echo "shellcrash:x:0:7890:::" >> /etc/passwd
fi
fi
#修改procd启动文件
[ "$start_old" != "已开启" -a -w /etc/init.d/shellcrash ] && sed -i 's/procd_set_param user root/procd_set_param user shellcrash/' /etc/init.d/shellcrash
fi
#清理debug日志
rm -rf ${TMPDIR}/debug.log
@ -1603,8 +1600,8 @@ afstart(){ #启动后
#设置本机代理
[ "$local_proxy" = "已开启" ] && {
[ "$local_type" = "环境变量" ] && $0 set_proxy $mix_port $db_port
[ "$local_type" = "iptables增强模式" ] && start_output
[ "$local_type" = "nftables增强模式" ] && [ "$redir_mod" = "纯净模式" ] && start_nft
[ "$local_type" = "iptables增强模式" ] && [ -n "$(grep '0:7890' /etc/passwd)" ] && start_output
[ "$local_type" = "nftables增强模式" ] && [ -n "$(grep '0:7890' /etc/passwd)" ] && [ "$redir_mod" = "纯净模式" ] && start_nft
}
ckcmd iptables && start_wan #本地防火墙
mark_time #标记启动时间