mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-04-25 20:10:42 +00:00
~全面适配容器环境,并支持S6守护进程
~移除了部分已移除功能的冗余代码 ~修复自定义策略组总是对齐失败的bug
This commit is contained in:
@@ -16,8 +16,8 @@ getconfig() { #读取配置及全局变量
|
||||
#加载配置文件
|
||||
. "$CRASHDIR"/configs/ShellCrash.cfg >/dev/null
|
||||
#缺省值
|
||||
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
|
||||
[ -z "$redir_mod" ] && redir_mod=纯净模式
|
||||
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod='Redir模式'
|
||||
[ -z "$redir_mod" ] && firewall_area='4'
|
||||
[ -z "$skip_cert" ] && skip_cert=已开启
|
||||
[ -z "$dns_mod" ] && dns_mod=fake-ip
|
||||
[ -z "$ipv6_redir" ] && ipv6_redir=未开启
|
||||
@@ -570,10 +570,10 @@ EOF
|
||||
sed -i "/#自定义策略组/d" "$TMPDIR"/proxy-groups.yaml
|
||||
[ -n "$(grep -Ev '^#' "$CRASHDIR"/yamls/proxy-groups.yaml 2>/dev/null)" ] && {
|
||||
#获取空格数
|
||||
space_name=$(grep -aE '^ *- name: ' "$TMPDIR"/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
|
||||
space_proxy=$(grep -A 1 'proxies:$' "$TMPDIR"/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *')
|
||||
space_name=$(grep -aE '^ *- \{?name: ' "$TMPDIR"/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
|
||||
space_proxy="$space_name "
|
||||
#合并自定义策略组到proxy-groups.yaml
|
||||
cat "$CRASHDIR"/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" >"$TMPDIR"/proxy-groups_add.yaml
|
||||
cat "$CRASHDIR"/yamls/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" | sed "s/^ *- {name: /${space_name}- {name: /g" >"$TMPDIR"/proxy-groups_add.yaml
|
||||
cat "$TMPDIR"/proxy-groups.yaml >>"$TMPDIR"/proxy-groups_add.yaml
|
||||
mv -f "$TMPDIR"/proxy-groups_add.yaml "$TMPDIR"/proxy-groups.yaml
|
||||
oldIFS="$IFS"
|
||||
@@ -1461,10 +1461,10 @@ start_nft_wan() { #nftables公网防火墙
|
||||
}
|
||||
start_nftables() { #nftables配置总入口
|
||||
#初始化nftables
|
||||
nft add table inet shellcrash
|
||||
nft flush table inet shellcrash
|
||||
nft add table inet shellcrash 2>/dev/null
|
||||
nft flush table inet shellcrash 2>/dev/null
|
||||
#公网访问防火墙
|
||||
start_nft_wan
|
||||
[ "$systype" != 'container' ] && start_nft_wan
|
||||
#启动DNS劫持
|
||||
[ "$dns_no" != "已禁用" -a "$dns_redir" != "已开启" -a "$firewall_area" -le 3 ] && {
|
||||
[ "$lan_proxy" = true ] && start_nft_dns prerouting prerouting #局域网dns转发
|
||||
@@ -1704,7 +1704,7 @@ stop_firewall() { #还原防火墙配置
|
||||
#还原防火墙文件
|
||||
[ -s /etc/init.d/firewall.bak ] && mv -f /etc/init.d/firewall.bak /etc/init.d/firewall
|
||||
#others
|
||||
sed -i '/shellcrash-dns-repair/d' /etc/resolv.conf
|
||||
[ "$systype" != 'container' ] && sed -i '/shellcrash-dns-repair/d' /etc/resolv.conf >/dev/null 2>&1
|
||||
}
|
||||
#启动相关
|
||||
web_save() { #最小化保存面板节点选择
|
||||
@@ -2043,20 +2043,6 @@ hotupdate() { #热更新订阅
|
||||
put_save http://127.0.0.1:${db_port}/configs "{\"path\":\""$CRASHDIR"/config.$format\"}"
|
||||
rm -rf "$TMPDIR"/CrashCore
|
||||
}
|
||||
set_proxy() { #设置环境变量
|
||||
if [ "$local_type" = "环境变量" ]; then
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >>$profile
|
||||
echo 'export ALL_PROXY=$all_proxy' >>$profile
|
||||
fi
|
||||
}
|
||||
unset_proxy() { #卸载环境变量
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/all_proxy/'d $profile
|
||||
sed -i '/ALL_PROXY/'d $profile
|
||||
}
|
||||
|
||||
getconfig #读取配置及全局变量
|
||||
|
||||
@@ -2066,7 +2052,7 @@ start)
|
||||
[ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例
|
||||
stop_firewall #清理路由策略
|
||||
#使用不同方式启动服务
|
||||
if [ "$firewall_area" = "5" ]; then #主旁转发
|
||||
if [ "$firewall_area" = "5" ]; then #主旁转发
|
||||
start_firewall
|
||||
elif [ "$start_old" = "已开启" ]; then
|
||||
bfstart && start_old
|
||||
@@ -2079,15 +2065,14 @@ start)
|
||||
systemctl daemon-reload
|
||||
systemctl start shellcrash.service || start_error
|
||||
}
|
||||
elif grep -q 's6' /proc/1/comm; then
|
||||
bfstart && /command/s6-svc -u /run/service/shellcrash && afstart &
|
||||
elif rc-status -r >/dev/null 2>&1; then
|
||||
rc-service shellcrash stop >/dev/null 2>&1
|
||||
rc-service shellcrash start
|
||||
else
|
||||
bfstart && start_old
|
||||
fi
|
||||
if [ "$2" = "infinity" ]; then #增加容器自启方式,请将CMD设置为"$CRASHDIR"/start.sh start infinity
|
||||
sleep infinity
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
logger ShellCrash服务即将关闭……
|
||||
@@ -2102,11 +2087,13 @@ stop)
|
||||
systemctl stop shellcrash.service >/dev/null 2>&1
|
||||
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
|
||||
/etc/init.d/shellcrash stop >/dev/null 2>&1
|
||||
elif grep -q 's6' /proc/1/comm; then
|
||||
/command/s6-svc -d /run/service/shellcrash
|
||||
stop_firewall
|
||||
elif rc-status -r >/dev/null 2>&1; then
|
||||
rc-service shellcrash stop >/dev/null 2>&1
|
||||
else
|
||||
stop_firewall #清理路由策略
|
||||
unset_proxy #禁用本机代理
|
||||
fi
|
||||
PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
|
||||
#清理缓存目录
|
||||
|
||||
Reference in New Issue
Block a user