~统一缩进

This commit is contained in:
juewuy
2026-03-25 20:15:42 +08:00
parent ab29b5c036
commit 837f99727a
60 changed files with 2846 additions and 2846 deletions

View File

@@ -56,7 +56,7 @@ elif [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm 2>/dev/null)" = "
mv -f "$CRASHDIR"/starts/shellcrash.service "$sysdir"/shellcrash.service 2>/dev/null mv -f "$CRASHDIR"/starts/shellcrash.service "$sysdir"/shellcrash.service 2>/dev/null
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" "$sysdir"/shellcrash.service sed -i "s%/etc/ShellCrash%$CRASHDIR%g" "$sysdir"/shellcrash.service
systemctl daemon-reload systemctl daemon-reload
rm -rf "$CRASHDIR"/starts/shellcrash.procd rm -rf "$CRASHDIR"/starts/shellcrash.procd
elif rc-status -r >/dev/null 2>&1; then elif rc-status -r >/dev/null 2>&1; then
#设为openrc方式启动 #设为openrc方式启动
mv -f "$CRASHDIR"/starts/shellcrash.openrc /etc/init.d/shellcrash mv -f "$CRASHDIR"/starts/shellcrash.openrc /etc/init.d/shellcrash
@@ -65,7 +65,7 @@ elif rc-status -r >/dev/null 2>&1; then
else else
#设为保守模式启动 #设为保守模式启动
setconfig start_old 已开启 setconfig start_old 已开启
rm -rf "$CRASHDIR"/starts/shellcrash.procd rm -rf "$CRASHDIR"/starts/shellcrash.procd
fi fi
rm -rf "$CRASHDIR"/starts/shellcrash.service rm -rf "$CRASHDIR"/starts/shellcrash.service
rm -rf "$CRASHDIR"/starts/shellcrash.openrc rm -rf "$CRASHDIR"/starts/shellcrash.openrc
@@ -116,10 +116,10 @@ else
fi fi
#梅林/Padavan额外设置 #梅林/Padavan额外设置
[ -n "$initdir" ] && { [ -n "$initdir" ] && {
touch "$initdir" touch "$initdir"
sed -i '/ShellCrash初始化/'d "$initdir" sed -i '/ShellCrash初始化/'d "$initdir"
echo "$CRASHDIR/starts/general_init.sh & #ShellCrash初始化脚本" >>"$initdir" echo "$CRASHDIR/starts/general_init.sh & #ShellCrash初始化脚本" >>"$initdir"
chmod 755 "$CRASHDIR"/starts/general_init.sh chmod 755 "$CRASHDIR"/starts/general_init.sh
chmod a+rx "$initdir" 2>/dev/null chmod a+rx "$initdir" 2>/dev/null
setconfig initdir "$initdir" setconfig initdir "$initdir"
} }
@@ -128,14 +128,14 @@ fi
#镜像化OpenWrt(snapshot)额外设置 #镜像化OpenWrt(snapshot)额外设置
if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ]; then if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ]; then
chmod 755 "$CRASHDIR"/starts/snapshot_init.sh chmod 755 "$CRASHDIR"/starts/snapshot_init.sh
if [ "$systype" = "mi_snapshot" ];then if [ "$systype" = "mi_snapshot" ];then
path="/data/shellcrash_init.sh" path="/data/shellcrash_init.sh"
sed -i "s#^CRASHDIR=.*#CRASHDIR=$CRASHDIR#" "$CRASHDIR"/starts/snapshot_init.sh sed -i "s#^CRASHDIR=.*#CRASHDIR=$CRASHDIR#" "$CRASHDIR"/starts/snapshot_init.sh
mv -f "$CRASHDIR"/starts/snapshot_init.sh "$path" mv -f "$CRASHDIR"/starts/snapshot_init.sh "$path"
[ ! -f /data/auto_start.sh ] && echo '#用于自定义需要开机启动的功能或者命令,会在开机后自动运行' > /data/auto_start.sh [ ! -f /data/auto_start.sh ] && echo '#用于自定义需要开机启动的功能或者命令,会在开机后自动运行' > /data/auto_start.sh
else else
path="$CRASHDIR"/starts/snapshot_init.sh path="$CRASHDIR"/starts/snapshot_init.sh
fi fi
uci delete firewall.auto_ssh 2>/dev/null uci delete firewall.auto_ssh 2>/dev/null
uci delete firewall.ShellCrash 2>/dev/null uci delete firewall.ShellCrash 2>/dev/null
uci set firewall.ShellCrash=include uci set firewall.ShellCrash=include
@@ -157,15 +157,15 @@ fi
sed -i "/^PATH=/a\\$CRASHDIR/start.sh init & #ShellCrash初始化脚本" "$dir/asusware.arm/etc/init.d/S50downloadmaster" sed -i "/^PATH=/a\\$CRASHDIR/start.sh init & #ShellCrash初始化脚本" "$dir/asusware.arm/etc/init.d/S50downloadmaster"
#容器环境额外设置 #容器环境额外设置
[ "$systype" = 'container' ] && { [ "$systype" = 'container' ] && {
setconfig userguide '1' setconfig userguide '1'
setconfig crashcore 'meta' setconfig crashcore 'meta'
setconfig dns_mod 'mix' setconfig dns_mod 'mix'
setconfig firewall_area '1' setconfig firewall_area '1'
setconfig firewall_mod 'nftables' setconfig firewall_mod 'nftables'
setconfig release_type 'master' setconfig release_type 'master'
setconfig start_old 'OFF' setconfig start_old 'OFF'
echo "$CRASHDIR/menu.sh" >> /etc/profile echo "$CRASHDIR/menu.sh" >> /etc/profile
cat > /usr/bin/crash <<'EOF' cat > /usr/bin/crash <<'EOF'
#!/bin/sh #!/bin/sh
CRASHDIR=${CRASHDIR:-/etc/ShellCrash} CRASHDIR=${CRASHDIR:-/etc/ShellCrash}
export CRASHDIR export CRASHDIR

View File

@@ -1,17 +1,17 @@
check_autostart(){ check_autostart(){
if [ "$start_old" = ON ];then if [ "$start_old" = ON ];then
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0 [ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && return 0 [ -n "$(find /etc/rc.d -name '*shellcrash')" ] && return 0
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0 [ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif ckcmd systemctl; then elif ckcmd systemctl; then
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && return 0 [ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && return 0
elif grep -q 's6' /proc/1/comm; then elif grep -q 's6' /proc/1/comm; then
[ -f /etc/s6-overlay/s6-rc.d/user/contents.d/afstart ] && return 0 [ -f /etc/s6-overlay/s6-rc.d/user/contents.d/afstart ] && return 0
elif rc-status -r >/dev/null 2>&1; then elif rc-status -r >/dev/null 2>&1; then
rc-update show default | grep -q "shellcrash" && return 0 rc-update show default | grep -q "shellcrash" && return 0
else else
return 1 return 1
fi fi
return 1 return 1
} }

View File

@@ -1,14 +1,14 @@
check_cpucore(){ #自动获取内核架构 check_cpucore(){ #自动获取内核架构
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]') cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5" [ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5"
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs ] && cpucore="armv7" [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs ] && cpucore="armv7"
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64" [ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386" [ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64" [ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
[ "$mipstype" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat" [ "$mipstype" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat"
fi fi
[ -n "$cpucore" ] && setconfig cpucore $cpucore [ -n "$cpucore" ] && setconfig cpucore $cpucore
} }

View File

@@ -1,5 +1,5 @@
#检查目录剩余空间——$1:目标路径 $2:-h参数 #检查目录剩余空间——$1:目标路径 $2:-h参数
dir_avail() { dir_avail() {
df -h >/dev/null 2>&1 && h="$2" df -h >/dev/null 2>&1 && h="$2"
df -P $h "${1:-.}" 2>/dev/null | awk 'NR==2 {print $4}' df -P $h "${1:-.}" 2>/dev/null | awk 'NR==2 {print $4}'
} }

View File

@@ -1,8 +1,8 @@
if echo "$crashcore" | grep -q 'singbox'; then if echo "$crashcore" | grep -q 'singbox'; then
target=singbox target=singbox
format=json format=json
else else
target=clash target=clash
format=yaml format=yaml
fi fi
core_config="$CRASHDIR/${format}s/config.$format" core_config="$CRASHDIR/${format}s/config.$format"

View File

@@ -3,7 +3,7 @@ compare() { #对比文件
return 1 return 1
elif ckcmd cmp; then elif ckcmd cmp; then
cmp -s "$1" "$2" cmp -s "$1" "$2"
return $? return $?
else else
[ "$(cat "$1")" = "$(cat "$2")" ] && return 0 || return 1 [ "$(cat "$1")" = "$(cat "$2")" ] && return 0 || return 1
fi fi

View File

@@ -3,87 +3,87 @@
[ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容 [ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容
core_unzip() { #$1:需要解压的文件 $2:目标文件名 core_unzip() { #$1:需要解压的文件 $2:目标文件名
if echo "$1" |grep -q 'tar.gz$' ;then if echo "$1" |grep -q 'tar.gz$' ;then
[ "$BINDIR" = "$TMPDIR" ] && rm -rf "$TMPDIR"/CrashCore #小闪存模式防止空间不足 [ "$BINDIR" = "$TMPDIR" ] && rm -rf "$TMPDIR"/CrashCore #小闪存模式防止空间不足
[ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容 [ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容
mkdir -p "$TMPDIR"/core_tmp mkdir -p "$TMPDIR"/core_tmp
tar -zxf "$1" ${tar_para} -C "$TMPDIR"/core_tmp/ tar -zxf "$1" ${tar_para} -C "$TMPDIR"/core_tmp/
for file in $(find "$TMPDIR"/core_tmp $find_para 2>/dev/null); do for file in $(find "$TMPDIR"/core_tmp $find_para 2>/dev/null); do
[ -f "$file" ] && [ -n "$(echo $file | sed 's#.*/##' | grep -iE '(CrashCore|sing|meta|mihomo|clash|pre)')" ] && mv -f "$file" "$TMPDIR"/"$2" [ -f "$file" ] && [ -n "$(echo $file | sed 's#.*/##' | grep -iE '(CrashCore|sing|meta|mihomo|clash|pre)')" ] && mv -f "$file" "$TMPDIR"/"$2"
done done
rm -rf "$TMPDIR"/core_tmp rm -rf "$TMPDIR"/core_tmp
elif echo "$1" |grep -q '.gz$' ;then elif echo "$1" |grep -q '.gz$' ;then
gunzip -c "$1" > "$TMPDIR"/"$2" gunzip -c "$1" > "$TMPDIR"/"$2"
elif echo "$1" |grep -q '.upx$' ;then elif echo "$1" |grep -q '.upx$' ;then
ln -sf "$1" "$TMPDIR"/"$2" ln -sf "$1" "$TMPDIR"/"$2"
else else
mv -f "$1" "$TMPDIR"/"$2" mv -f "$1" "$TMPDIR"/"$2"
fi fi
chmod +x "$TMPDIR"/"$2" chmod +x "$TMPDIR"/"$2"
} }
core_find(){ core_find(){
if [ ! -f "$TMPDIR"/CrashCore ];then if [ ! -f "$TMPDIR"/CrashCore ];then
[ -n "$(find "$CRASHDIR"/CrashCore.* $find_para 2>/dev/null)" ] && [ "$CRASHDIR" != "$BINDIR" ] && [ -n "$(find "$CRASHDIR"/CrashCore.* $find_para 2>/dev/null)" ] && [ "$CRASHDIR" != "$BINDIR" ] &&
mv -f "$CRASHDIR"/CrashCore.* "$BINDIR"/ mv -f "$CRASHDIR"/CrashCore.* "$BINDIR"/
core_dir=$(find "$BINDIR"/CrashCore.* $find_para 2>/dev/null | head -n 1) core_dir=$(find "$BINDIR"/CrashCore.* $find_para 2>/dev/null | head -n 1)
[ -n "$core_dir" ] && core_unzip "$core_dir" CrashCore [ -n "$core_dir" ] && core_unzip "$core_dir" CrashCore
fi fi
} }
core_check(){ core_check(){
[ -n "$(pidof CrashCore)" ] && "$CRASHDIR"/start.sh stop #停止内核服务防止内存不足 [ -n "$(pidof CrashCore)" ] && "$CRASHDIR"/start.sh stop #停止内核服务防止内存不足
core_unzip "$1" core_new core_unzip "$1" core_new
sbcheck=$(echo "$crashcore" | grep 'singbox') sbcheck=$(echo "$crashcore" | grep 'singbox')
v='' v=''
if [ -n "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q 'sing-box'; then if [ -n "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q 'sing-box'; then
v=$("$TMPDIR"/core_new version 2>/dev/null | grep version | awk '{print $3}') v=$("$TMPDIR"/core_new version 2>/dev/null | grep version | awk '{print $3}')
COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"' COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"'
elif [ -z "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q '\-t';then elif [ -z "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q '\-t';then
v=$("$TMPDIR"/core_new -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //') v=$("$TMPDIR"/core_new -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
fi fi
if [ -z "$v" ]; then if [ -z "$v" ]; then
rm -rf "$1" "$TMPDIR"/core_new rm -rf "$1" "$TMPDIR"/core_new
return 2 return 2
else else
rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx
if [ -z "$zip_type" ];then if [ -z "$zip_type" ];then
gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz" gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz"
else else
mv -f "$1" "$BINDIR/CrashCore.$zip_type" mv -f "$1" "$BINDIR/CrashCore.$zip_type"
fi fi
if [ "$zip_type" = 'upx' ];then if [ "$zip_type" = 'upx' ];then
rm -f "$1" "$TMPDIR"/core_new rm -f "$1" "$TMPDIR"/core_new
ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore" ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore"
else else
mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore" mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore"
fi fi
core_v="$v" core_v="$v"
setconfig COMMAND "$COMMAND" "$CRASHDIR"/configs/command.env && . "$CRASHDIR"/configs/command.env setconfig COMMAND "$COMMAND" "$CRASHDIR"/configs/command.env && . "$CRASHDIR"/configs/command.env
setconfig crashcore "$crashcore" setconfig crashcore "$crashcore"
setconfig core_v "$core_v" setconfig core_v "$core_v"
setconfig custcorelink "$custcorelink" setconfig custcorelink "$custcorelink"
return 0 return 0
fi fi
} }
core_webget(){ core_webget(){
. "$CRASHDIR"/libs/web_get_bin.sh . "$CRASHDIR"/libs/web_get_bin.sh
. "$CRASHDIR"/libs/check_target.sh . "$CRASHDIR"/libs/check_target.sh
if [ -z "$custcorelink" ];then if [ -z "$custcorelink" ];then
[ -z "$zip_type" ] && zip_type='tar.gz' [ -z "$zip_type" ] && zip_type='tar.gz'
get_bin "$TMPDIR/Coretmp.$zip_type" "bin/$crashcore/${target}-linux-${cpucore}.$zip_type" get_bin "$TMPDIR/Coretmp.$zip_type" "bin/$crashcore/${target}-linux-${cpucore}.$zip_type"
else else
case "$custcorelink" in case "$custcorelink" in
*.tar.gz) zip_type="tar.gz" ;; *.tar.gz) zip_type="tar.gz" ;;
*.gz) zip_type="gz" ;; *.gz) zip_type="gz" ;;
*.upx) zip_type="upx" ;; *.upx) zip_type="upx" ;;
esac esac
[ -n "$zip_type" ] && webget "$TMPDIR/Coretmp.$zip_type" "$custcorelink" [ -n "$zip_type" ] && webget "$TMPDIR/Coretmp.$zip_type" "$custcorelink"
fi fi
#校验内核 #校验内核
if [ "$?" = 0 ];then if [ "$?" = 0 ];then
core_check "$TMPDIR/Coretmp.$zip_type" core_check "$TMPDIR/Coretmp.$zip_type"
else else
rm -f "$TMPDIR/Coretmp.$zip_type" rm -f "$TMPDIR/Coretmp.$zip_type"
return 1 return 1
fi fi
} }

View File

@@ -1,26 +1,26 @@
#生成指定位数的加密秘钥符合ss2022协议 #生成指定位数的加密秘钥符合ss2022协议
gen_random() { gen_random() {
if ckcmd openssl;then if ckcmd openssl;then
openssl rand --base64 "$1" openssl rand --base64 "$1"
elif ckcmd base64;then elif ckcmd base64;then
head -c "$1" /dev/urandom | base64 | tr -d '\n' head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then elif busybox base64 --help >/dev/null 2>&1;then
head -c "$1" /dev/urandom | base64 | tr -d '\n' head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif ckcmd uuencode;then elif ckcmd uuencode;then
head -c "$1" /dev/urandom | uuencode -m - | sed -n '2p' head -c "$1" /dev/urandom | uuencode -m - | sed -n '2p'
else else
return 1 return 1
fi fi
} }
#对指定字符串进行base64转码 #对指定字符串进行base64转码
gen_base64() { gen_base64() {
if ckcmd base64;then if ckcmd base64;then
echo -n "$1" | base64 | tr -d '\n' echo -n "$1" | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then elif busybox base64 --help >/dev/null 2>&1;then
echo -n "$1" | busybox base64 | tr -d '\n' echo -n "$1" | busybox base64 | tr -d '\n'
elif ckcmd openssl;then elif ckcmd openssl;then
echo -n "$1" | openssl base64 -A echo -n "$1" | openssl base64 -A
else else
return 1 return 1
fi fi
} }

View File

@@ -15,8 +15,8 @@ routing_mark=$((fwmark + 2))
[ -z "$table" ] && table=100 [ -z "$table" ] && table=100
[ -z "$dns_nameserver" ] && { [ -z "$dns_nameserver" ] && {
dns_nameserver='223.5.5.5, 1.2.4.8' dns_nameserver='223.5.5.5, 1.2.4.8'
netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1' netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1'
} }
[ -z "$dns_fallback" ] && dns_fallback="1.1.1.1, 8.8.8.8" [ -z "$dns_fallback" ] && dns_fallback="1.1.1.1, 8.8.8.8"
[ -z "$dns_resolver" ] && dns_resolver="223.5.5.5, 2400:3200::1" [ -z "$dns_resolver" ] && dns_resolver="223.5.5.5, 2400:3200::1"

View File

@@ -5,11 +5,11 @@ get_ecs_address() {
ip=$(grep -A1 "^# Interface wan$" "$f" | grep nameserver | awk '{printf "%s ", $2}') ip=$(grep -A1 "^# Interface wan$" "$f" | grep nameserver | awk '{printf "%s ", $2}')
[ -n "$ip" ] && return [ -n "$ip" ] && return
done done
. "$CRASHDIR"/libs/web_get_lite.sh . "$CRASHDIR"/libs/web_get_lite.sh
for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do
ip=$(web_get_lite "$web" 0) ip=$(web_get_lite "$web" 0)
[ -n "$ip" ] && return [ -n "$ip" ] && return
done done
} }
get_ecs_address get_ecs_address
[ -n "$ip" ] && ecs_address="${ip%.*}.0/24" [ -n "$ip" ] && ecs_address="${ip%.*}.0/24"

View File

@@ -1,8 +1,8 @@
load_lang() { load_lang() {
i18n=$(cat "$CRASHDIR"/configs/i18n.cfg 2>/dev/null) i18n=$(cat "$CRASHDIR"/configs/i18n.cfg 2>/dev/null)
[ -z "$i18n" ] && i18n=chs [ -z "$i18n" ] && i18n=chs
file="$CRASHDIR/lang/$i18n/$1.lang" file="$CRASHDIR/lang/$i18n/$1.lang"
[ -s "$file" ] && . "$file" [ -s "$file" ] && . "$file"
} }

View File

@@ -6,13 +6,13 @@ __IS_LIB_LOGGER=1
. "$CRASHDIR"/libs/web_json.sh . "$CRASHDIR"/libs/web_json.sh
#$1日志内容$2显示颜色$3是否推送$4是否覆盖上一条 #$1日志内容$2显示颜色$3是否推送$4是否覆盖上一条
logger() { logger() {
TMPDIR=/tmp/ShellCrash TMPDIR=/tmp/ShellCrash
[ -n "$2" -a "$2" != 0 ] && printf "\033[%sm%s\033[0m\n" "$2" "$1" [ -n "$2" -a "$2" != 0 ] && printf "\033[%sm%s\033[0m\n" "$2" "$1"
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1" log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
[ "$4" = on ] && sed -i "/$1/d" "$TMPDIR"/ShellCrash.log [ "$4" = on ] && sed -i "/$1/d" "$TMPDIR"/ShellCrash.log
echo "$log_text" >>"$TMPDIR"/ShellCrash.log echo "$log_text" >>"$TMPDIR"/ShellCrash.log
[ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 199 ] && sed -i '1,20d' "$TMPDIR"/ShellCrash.log [ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 199 ] && sed -i '1,20d' "$TMPDIR"/ShellCrash.log
#推送远程日志 #推送远程日志
[ "$3" != off ] && { [ "$3" != off ] && {
[ -n "$device_name" ] && log_text="$log_text($device_name)" [ -n "$device_name" ] && log_text="$log_text($device_name)"
[ -n "$push_TG" ] && { [ -n "$push_TG" ] && {
@@ -51,6 +51,6 @@ logger() {
url="${push_ChatURL}/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=${push_ChatTOKEN}" url="${push_ChatURL}/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=${push_ChatTOKEN}"
content="payload={\"text\":\"${log_text}\", \"user_ids\":[${push_ChatUSERID}]}" content="payload={\"text\":\"${log_text}\", \"user_ids\":[${push_ChatUSERID}]}"
web_json_post "$url" "$content" & web_json_post "$url" "$content" &
} }
} & } &
} }

View File

@@ -3,7 +3,7 @@
#meta内核vmess入站生成 #meta内核vmess入站生成
[ "$vms_service" = ON ] && { [ "$vms_service" = ON ] && {
cat >>"$TMPDIR"/listeners.yaml <<EOF cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "vmess-in" - name: "vmess-in"
type: vmess type: vmess
port: $vms_port port: $vms_port
@@ -16,7 +16,7 @@ EOF
} }
#meta内核ss入站生成 #meta内核ss入站生成
[ "$sss_service" = ON ] && { [ "$sss_service" = ON ] && {
cat >>"$TMPDIR"/listeners.yaml <<EOF cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "ss-in" - name: "ss-in"
type: shadowsocks type: shadowsocks
port: $sss_port port: $sss_port

View File

@@ -2,24 +2,24 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
[ "$ts_service" = ON ] && ! grep -q '"tailscale"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && { [ "$ts_service" = ON ] && ! grep -q '"tailscale"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && {
[ "$ts_subnet" = true ] && { [ "$ts_subnet" = true ] && {
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip . "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
advertise_routes=$(echo "$host_ipv4"|sed 's/[[:space:]]\+/", "/g; s/^/"/; s/$/"/') advertise_routes=$(echo "$host_ipv4"|sed 's/[[:space:]]\+/", "/g; s/^/"/; s/$/"/')
} }
[ -z "$ts_exit_node" ] && ts_exit_node=false [ -z "$ts_exit_node" ] && ts_exit_node=false
[ -z "$ts_hostname" ] && ts_hostname='ShellCrash' [ -z "$ts_hostname" ] && ts_hostname='ShellCrash'
cat >"$TMPDIR"/jsons/tailscale.json <<EOF cat >"$TMPDIR"/jsons/tailscale.json <<EOF
{ {
"endpoints": [ "endpoints": [
{ {
"type": "tailscale", "type": "tailscale",
"tag": "ts-ep", "tag": "ts-ep",
"state_directory": "$CRASHDIR/tailscale", "state_directory": "$CRASHDIR/tailscale",
"auth_key": "$ts_auth_key", "auth_key": "$ts_auth_key",
"hostname": "$ts_hostname", "hostname": "$ts_hostname",
"advertise_routes": [$advertise_routes], "advertise_routes": [$advertise_routes],
"advertise_exit_node": $ts_exit_node, "advertise_exit_node": $ts_exit_node,
"udp_timeout": "5m" "udp_timeout": "5m"
} }
] ]
} }
@@ -27,27 +27,27 @@ EOF
} }
[ "$wg_service" = ON ] && ! grep -q '"wireguard"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && { [ "$wg_service" = ON ] && ! grep -q '"wireguard"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && {
[ -n "$wg_ipv6" ] && wg_ipv6_add=", \"$wg_ipv6\"" [ -n "$wg_ipv6" ] && wg_ipv6_add=", \"$wg_ipv6\""
cat >"$TMPDIR"/jsons/wireguard.json <<EOF cat >"$TMPDIR"/jsons/wireguard.json <<EOF
{ {
"endpoints": [ "endpoints": [
{ {
"type": "wireguard", "type": "wireguard",
"tag": "wg-ep", "tag": "wg-ep",
"system": true, "system": true,
"mtu": 1420, "mtu": 1420,
"address": [ "$wg_ipv4"$wg_ipv6_add ], "address": [ "$wg_ipv4"$wg_ipv6_add ],
"private_key": "$wg_private_key", "private_key": "$wg_private_key",
"peers": [ "peers": [
{ {
"address": "$wg_server", "address": "$wg_server",
"port": $wg_port, "port": $wg_port,
"public_key": "$wg_public_key", "public_key": "$wg_public_key",
"pre_shared_key": "$wg_pre_shared_key", "pre_shared_key": "$wg_pre_shared_key",
"allowed_ips": ["0.0.0.0/0", "::/0"] "allowed_ips": ["0.0.0.0/0", "::/0"]
} }
] ]
} }
] ]
} }
EOF EOF

View File

@@ -2,8 +2,8 @@
# 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": [
{ {
@@ -11,7 +11,7 @@
"tag": "vmess-in", "tag": "vmess-in",
"listen": "::", "listen": "::",
"listen_port": $vms_port, "listen_port": $vms_port,
"users": [ "users": [
{ {
"uuid": "$vms_uuid" "uuid": "$vms_uuid"
} }
@@ -23,17 +23,17 @@ EOF
} }
[ "$sss_service" = ON ] && { [ "$sss_service" = ON ] && {
cat >"$TMPDIR"/jsons/ss-in.json <<EOF cat >"$TMPDIR"/jsons/ss-in.json <<EOF
{ {
"inbounds": [ "inbounds": [
{ {
"type": "shadowsocks", "type": "shadowsocks",
"tag": "ss-in", "tag": "ss-in",
"listen": "::", "listen": "::",
"listen_port": $sss_port, "listen_port": $sss_port,
"method": "$sss_cipher", "method": "$sss_cipher",
"password": "$sss_pwd", "password": "$sss_pwd",
} }
] ]
} }
EOF EOF

View File

@@ -1,6 +1,6 @@
#参数1代表变量名参数2代表变量值,参数3即文件路径 #参数1代表变量名参数2代表变量值,参数3即文件路径
setconfig() { setconfig() {
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}" [ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
sed -i "/^${1}=.*/d" "$configpath" sed -i "/^${1}=.*/d" "$configpath"
printf '%s=%s\n' "$1" "$2" >>"$configpath" printf '%s=%s\n' "$1" "$2" >>"$configpath"
} }

View File

@@ -8,32 +8,32 @@ tmpcron=/tmp/cron_tmp
touch "$tmpcron" touch "$tmpcron"
cronadd() { #定时任务工具 cronadd() { #定时任务工具
if crontab -h 2>&1 | grep -q '\-l'; then if crontab -h 2>&1 | grep -q '\-l'; then
crontab "$1" crontab "$1"
elif [ -f "$crondir/$USER" ];then elif [ -f "$crondir/$USER" ];then
cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null
else else
echo "找不到可用的crond或者crontab应用No available crond or crontab application can be found!" echo "找不到可用的crond或者crontab应用No available crond or crontab application can be found!"
fi fi
} }
cronload() { #定时任务工具 cronload() { #定时任务工具
if crontab -h 2>&1 | grep -q '\-l'; then if crontab -h 2>&1 | grep -q '\-l'; then
crontab -l crontab -l
elif [ -f "$crondir/$USER" ];then elif [ -f "$crondir/$USER" ];then
cat "$crondir"/"$USER" 2>/dev/null cat "$crondir"/"$USER" 2>/dev/null
else else
return 1 return 1
fi fi
} }
cronset() { #定时任务设置 cronset() { #定时任务设置
# 参数1代表要移除的关键字,参数2代表要添加的任务语句 # 参数1代表要移除的关键字,参数2代表要添加的任务语句
cronload | grep -v '^$' | grep -vF "$1" >"$tmpcron" cronload | grep -v '^$' | grep -vF "$1" >"$tmpcron"
[ -n "$2" ] && echo "$2" >>"$tmpcron" [ -n "$2" ] && echo "$2" >>"$tmpcron"
cronadd "$tmpcron" cronadd "$tmpcron"
#华硕/Padavan固件存档在本地,其他则删除 #华硕/Padavan固件存档在本地,其他则删除
if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then
mv -f "$tmpcron" "$CRASHDIR"/task/cron mv -f "$tmpcron" "$CRASHDIR"/task/cron
else else
rm -f "$tmpcron" rm -f "$tmpcron"
fi fi
} }

View File

@@ -5,5 +5,5 @@ set_profile() {
echo "alias ${my_alias}=\"$shtype $CRASHDIR/menu.sh\"" >>"$1" #设置快捷命令环境变量 echo "alias ${my_alias}=\"$shtype $CRASHDIR/menu.sh\"" >>"$1" #设置快捷命令环境变量
sed -i '/export CRASHDIR=*/'d "$1" sed -i '/export CRASHDIR=*/'d "$1"
echo "export CRASHDIR=\"$CRASHDIR\"" >>"$1" #设置路径环境变量 echo "export CRASHDIR=\"$CRASHDIR\"" >>"$1" #设置路径环境变量
. "$1" >/dev/null 2>&1 || true . "$1" >/dev/null 2>&1 || true
} }

View File

@@ -1,9 +1,9 @@
setproxy(){ setproxy(){
[ -n "$(pidof CrashCore)" ] && { [ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth="" [ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890 [ -z "$mix_port" ] && mix_port=7890
export https_proxy="http://${auth}127.0.0.1:$mix_port" export https_proxy="http://${auth}127.0.0.1:$mix_port"
export http_proxy="http://${auth}127.0.0.1:$mix_port" export http_proxy="http://${auth}127.0.0.1:$mix_port"
} }
} }

View File

@@ -1,10 +1,10 @@
i=1 i=1
while [ -z "$test" -a "$i" -lt 30 ]; do while [ -z "$test" -a "$i" -lt 30 ]; do
sleep 1 sleep 1
if curl --version >/dev/null 2>&1; then if curl --version >/dev/null 2>&1; then
test=$(curl -s -H "Authorization: Bearer $secret" http://127.0.0.1:${db_port}/proxies | grep -o proxies) test=$(curl -s -H "Authorization: Bearer $secret" http://127.0.0.1:${db_port}/proxies | grep -o proxies)
else else
test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies) test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies)
fi fi
i=$((i + 1)) i=$((i + 1))
done done

View File

@@ -1,77 +1,77 @@
. "$CRASHDIR"/libs/set_proxy.sh . "$CRASHDIR"/libs/set_proxy.sh
webget(){ webget(){
if pidof CrashCore >/dev/null; then if pidof CrashCore >/dev/null; then
setproxy #设置临时代理,【$1】代表下载目录【$2】代表在线地址 setproxy #设置临时代理,【$1】代表下载目录【$2】代表在线地址
url=$(printf '%s\n' "$2" | url=$(printf '%s\n' "$2" |
sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \ sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \
-e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#') -e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
else else
url=$(printf '%s\n' "$2" | url=$(printf '%s\n' "$2" |
sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#') sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#')
fi fi
# =============================================== # ===============================================
#参数【$1】代表下载目录【$2】代表在线地址 #参数【$1】代表下载目录【$2】代表在线地址
#参数【$3】代表输出显示【$4】不启用重定向 #参数【$3】代表输出显示【$4】不启用重定向
#参数【$5】代表验证证书【$6】使用自定义UA #参数【$5】代表验证证书【$6】使用自定义UA
[ -n "$6" ] && agent="--user-agent $6" [ -n "$6" ] && agent="--user-agent $6"
if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress' [ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect='' [ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate='' certificate=''
else else
certificate='--no-check-certificate' certificate='--no-check-certificate'
fi fi
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$1" "$url" && return 0 #成功则退出否则重试 wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$1" "$2" wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$1" "$2"
return $? return $?
elif curl --version >/dev/null 2>&1; then elif curl --version >/dev/null 2>&1; then
if [ "$3" = "echooff" ];then if [ "$3" = "echooff" ];then
progress='-s' progress='-s'
elif echo "$url" | grep -q 'jsdelivr.net';then elif echo "$url" | grep -q 'jsdelivr.net';then
progress='-#' progress='-#'
. "$CRASHDIR"/libs/web_get_curlbar.sh && curl_fsize . "$CRASHDIR"/libs/web_get_curlbar.sh && curl_fsize
else else
progress='-#' progress='-#'
fi fi
[ "$4" = "rediroff" ] && redirect='' || redirect='-L' [ "$4" = "rediroff" ] && redirect='' || redirect='-L'
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate='' certificate=''
else else
certificate='-k' certificate='-k'
fi fi
# curl 特殊版本兼容 # curl 特殊版本兼容
auth_arg="" auth_arg=""
if curl --version | grep -q '^curl 8.' && ckcmd base64; then if curl --version | grep -q '^curl 8.' && ckcmd base64; then
auth_b64=$(printf '%s' "$authentication" | base64) auth_b64=$(printf '%s' "$authentication" | base64)
[ -n "$auth_b64" ] && auth_arg="--proxy-header Proxy-Authorization:Basic $auth_b64" [ -n "$auth_b64" ] && auth_arg="--proxy-header Proxy-Authorization:Basic $auth_b64"
fi fi
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$url" "$fsize_raw" "$agent $auth_arg $redirect $certificate") result=$(execute_curl "$1" "$url" "$fsize_raw" "$agent $auth_arg $redirect $certificate")
else else
result=$(curl $agent $auth_arg -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url") result=$(curl $agent $auth_arg -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url")
fi fi
[ "$result" = "200" ] && return 0 #成功则退出否则重试 [ "$result" = "200" ] && return 0 #成功则退出否则重试
export https_proxy="" export https_proxy=""
export http_proxy="" export http_proxy=""
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$2" "$fsize_raw" "$agent $redirect $certificate") result=$(execute_curl "$1" "$2" "$fsize_raw" "$agent $redirect $certificate")
else else
result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2") result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2")
fi fi
[ "$result" = "200" ] [ "$result" = "200" ]
return $? return $?
elif ckcmd wget;then elif ckcmd wget;then
[ "$3" = "echooff" ] && progress='-q' [ "$3" = "echooff" ] && progress='-q'
wget -Y on $progress -O "$1" "$url" && return 0 #成功则退出否则重试 wget -Y on $progress -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $progress -O "$1" "$2" wget -Y off $progress -O "$1" "$2"
return $? return $?
else else
echo "No Curl or Wget" echo "No Curl or Wget"
return 1 return 1
fi fi
} }

View File

@@ -3,7 +3,7 @@
get_bin() { #专用于项目内部文件的下载 get_bin() { #专用于项目内部文件的下载
[ -z "$update_url" ] && update_url=https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@master [ -z "$update_url" ] && update_url=https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@master
if [ -n "$url_id" ]; then if [ -n "$url_id" ]; then
[ -n "$release_type" ] && rt="$release_type" || rt=master [ -n "$release_type" ] && rt="$release_type" || rt=master
echo "$2" | grep -q '^bin/' && rt=update #/bin文件改为在update分支下载 echo "$2" | grep -q '^bin/' && rt=update #/bin文件改为在update分支下载
echo "$2" | grep -qE '^public/|^rules/' && rt=dev #/public和/rules文件改为在dev分支下载 echo "$2" | grep -qE '^public/|^rules/' && rt=dev #/public和/rules文件改为在dev分支下载
if [ "$url_id" = 101 -o "$url_id" = 104 ]; then if [ "$url_id" = 101 -o "$url_id" = 104 ]; then

View File

@@ -2,46 +2,46 @@
bar_max=42 #进度条长度 bar_max=42 #进度条长度
curl_fsize(){ # 获取文件大小 curl_fsize(){ # 获取文件大小
fsize_raw=0 fsize_raw=0
header=$(curl -sIL --connect-timeout 2 "$url") header=$(curl -sIL --connect-timeout 2 "$url")
# 代理容错 # 代理容错
[ -z "$header" ] && { export https_proxy=""; export http_proxy=""; header=$(curl -sIL --connect-timeout 2 "$url"); } [ -z "$header" ] && { export https_proxy=""; export http_proxy=""; header=$(curl -sIL --connect-timeout 2 "$url"); }
# 提取大小 (优先 Content-Length其次 ETag) # 提取大小 (优先 Content-Length其次 ETag)
fsize_raw=$(echo "$header" | grep -i 'Content-Length' | tail -n 1 | awk '{print $2}' | tr -d '\r' | awk '{print int($1)}') fsize_raw=$(echo "$header" | grep -i 'Content-Length' | tail -n 1 | awk '{print $2}' | tr -d '\r' | awk '{print int($1)}')
if [ -z "$fsize_raw" ] || [ "$fsize_raw" -eq 0 ]; then if [ -z "$fsize_raw" ] || [ "$fsize_raw" -eq 0 ]; then
etag=$(echo "$header" | grep -i 'etag' | tail -n 1 | cut -d '"' -f2 | cut -d '-' -f1) etag=$(echo "$header" | grep -i 'etag' | tail -n 1 | cut -d '"' -f2 | cut -d '-' -f1)
[ -n "$etag" ] && fsize_raw=$(printf "%d" 0x$etag 2>/dev/null) [ -n "$etag" ] && fsize_raw=$(printf "%d" 0x$etag 2>/dev/null)
fi fi
} }
execute_curl(){ # 手搓curl进度条 execute_curl(){ # 手搓curl进度条
local path="$1" target_url="$2" total_size="$3" extra_args="$4" local path="$1" target_url="$2" total_size="$3" extra_args="$4"
rm -f /tmp/webget_res rm -f /tmp/webget_res
# 后台静默下载,状态码写入临时文件 # 后台静默下载,状态码写入临时文件
curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res & curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res &
local pid=$! local pid=$!
# 循环监控 # 循环监控
while kill -0 $pid 2>/dev/null; do while kill -0 $pid 2>/dev/null; do
if [ -f "$path" ]; then if [ -f "$path" ]; then
local curr=$(wc -c < "$path") local curr=$(wc -c < "$path")
local pct=$(awk -v c=$curr -v t=$total_size 'BEGIN {p=(c*100/t); if(p>100)p=100; printf "%.1f", p}') local pct=$(awk -v c=$curr -v t=$total_size 'BEGIN {p=(c*100/t); if(p>100)p=100; printf "%.1f", p}')
local num=$(awk -v p=$pct -v w=$bar_max 'BEGIN {printf "%d", p*w/100}') local num=$(awk -v p=$pct -v w=$bar_max 'BEGIN {printf "%d", p*w/100}')
local bar=$(printf "%${num}s" | tr ' ' '#'); local spc_n=$((bar_max - num)) local bar=$(printf "%${num}s" | tr ' ' '#'); local spc_n=$((bar_max - num))
local spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s") local spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s")
local size=$(( fsize_raw * 100 / 1048576 )) local size=$(( fsize_raw * 100 / 1048576 ))
local fs="$((size / 100)).$((size % 100)) MB" local fs="$((size / 100)).$((size % 100)) MB"
printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2 printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2
fi fi
usleep 200000 2>/dev/null || sleep 1 usleep 200000 2>/dev/null || sleep 1
done done
local code=$(cat /tmp/webget_res 2>/dev/null) local code=$(cat /tmp/webget_res 2>/dev/null)
if [ "$code" = "200" ] || [ "$code" = "206" ]; then if [ "$code" = "200" ] || [ "$code" = "206" ]; then
local full=$(printf "%${bar_max}s" | tr ' ' '#') local full=$(printf "%${bar_max}s" | tr ' ' '#')
printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2 printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2
else else
printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path" printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path"
fi fi
echo "$code" echo "$code"
} }

View File

@@ -1,10 +1,10 @@
. "$CRASHDIR"/libs/set_proxy.sh . "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:禁用proxy #$1:目标地址 $2:禁用proxy
web_get_lite() { web_get_lite() {
[ -z "$2" ] && setproxy [ -z "$2" ] && setproxy
if curl --version >/dev/null 2>&1; then if curl --version >/dev/null 2>&1; then
curl -ksSl --connect-timeout 3 "$1" 2>/dev/null curl -ksSl --connect-timeout 3 "$1" 2>/dev/null
else else
wget -Y on -q --timeout=3 -O - "$1" wget -Y on -q --timeout=3 -O - "$1"
fi fi
} }

View File

@@ -1,10 +1,10 @@
. "$CRASHDIR"/libs/set_proxy.sh . "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:json字符串 #$1:目标地址 $2:json字符串
web_json_post() { web_json_post() {
setproxy setproxy
if curl --version >/dev/null 2>&1; then if curl --version >/dev/null 2>&1; then
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$1" -d "$2" >/dev/null 2>&1 curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$1" -d "$2" >/dev/null 2>&1
else else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1" wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1"
fi fi
} }

View File

@@ -9,12 +9,12 @@ put_save() { #推送面板选择
fi fi
} }
web_restore() { #还原面板选择 web_restore() { #还原面板选择
num=$(cat "$CRASHDIR"/configs/web_save | wc -l) num=$(cat "$CRASHDIR"/configs/web_save | wc -l)
i=1 i=1
while [ "$i" -le "$num" ]; do while [ "$i" -le "$num" ]; do
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' "$CRASHDIR"/configs/web_save | sed 's/ /%20/g') group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' "$CRASHDIR"/configs/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' "$CRASHDIR"/configs/web_save) now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' "$CRASHDIR"/configs/web_save)
put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}" put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}"
i=$((i + 1)) i=$((i + 1))
done done
} }

View File

@@ -9,7 +9,7 @@ get_save() { #获取面板信息
} }
web_save() { #最小化保存面板节点选择 web_save() { #最小化保存面板节点选择
#使用get_save获取面板节点设置 #使用get_save获取面板节点设置
get_save "http://127.0.0.1:${db_port}/proxies" | sed 's/{}//g' | sed 's/:{/\ get_save "http://127.0.0.1:${db_port}/proxies" | sed 's/{}//g' | sed 's/:{/\
/g'| grep -aE '"Selector"' >"$TMPDIR"/web_proxies /g'| grep -aE '"Selector"' >"$TMPDIR"/web_proxies
[ -s "$TMPDIR"/web_proxies ] && while read line; do [ -s "$TMPDIR"/web_proxies ] && while read line; do
def=$(echo $line | grep -oE '"all".*",' | awk -F "[\"]" '{print $4}') def=$(echo $line | grep -oE '"all".*",' | awk -F "[\"]" '{print $4}')
@@ -25,8 +25,8 @@ web_save() { #最小化保存面板节点选择
if [ -s "$TMPDIR/$file" ]; then if [ -s "$TMPDIR/$file" ]; then
. "$CRASHDIR"/libs/compare.sh && compare "$TMPDIR/$file" "$CRASHDIR/configs/$file" . "$CRASHDIR"/libs/compare.sh && compare "$TMPDIR/$file" "$CRASHDIR/configs/$file"
[ "$?" = 0 ] && rm -f "$TMPDIR/$file" || mv -f "$TMPDIR/$file" "$CRASHDIR/configs/$file" [ "$?" = 0 ] && rm -f "$TMPDIR/$file" || mv -f "$TMPDIR/$file" "$CRASHDIR/configs/$file"
else else
> "$CRASHDIR/configs/$file" #空文件时移除旧文件 > "$CRASHDIR/configs/$file" #空文件时移除旧文件
fi fi
done done
} }

View File

@@ -2,8 +2,8 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
CRASHDIR=$( CRASHDIR=$(
cd $(dirname $0) cd $(dirname $0)
pwd pwd
) )
CFG_PATH="$CRASHDIR"/configs/ShellCrash.cfg CFG_PATH="$CRASHDIR"/configs/ShellCrash.cfg
@@ -32,326 +32,326 @@ load_lang common
load_lang menu load_lang menu
checkrestart() { checkrestart() {
comp_box "\033[32m$MENU_RESTART_NOTICE\033[0m" comp_box "\033[32m$MENU_RESTART_NOTICE\033[0m"
btm_box "1) 立即重启" \ btm_box "1) 立即重启" \
"0) 暂不重启" "0) 暂不重启"
read -r -p "$COMMON_INPUT> " res read -r -p "$COMMON_INPUT> " res
if [ "$res" = 1 ]; then if [ "$res" = 1 ]; then
start_service start_service
fi fi
} }
# 检查端口冲突 # 检查端口冲突
checkport() { checkport() {
. "$CRASHDIR"/menus/check_port.sh . "$CRASHDIR"/menus/check_port.sh
while true; do while true; do
local conflict_found=0 local conflict_found=0
local conflict_port="" local conflict_port=""
local conflict_info="" local conflict_info=""
conflict_info=$(check_port_with_info "$mix_port") conflict_info=$(check_port_with_info "$mix_port")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
conflict_found=1 conflict_found=1
conflict_port="$mix_port" conflict_port="$mix_port"
fi fi
if [ "$conflict_found" -eq 0 ]; then if [ "$conflict_found" -eq 0 ]; then
conflict_info=$(check_port_with_info "$redir_port") conflict_info=$(check_port_with_info "$redir_port")
[ $? -ne 0 ] && conflict_found=1 && conflict_port="$redir_port" [ $? -ne 0 ] && conflict_found=1 && conflict_port="$redir_port"
fi fi
if [ "$conflict_found" -eq 0 ]; then if [ "$conflict_found" -eq 0 ]; then
conflict_info=$(check_port_with_info "$((redir_port + 1))") conflict_info=$(check_port_with_info "$((redir_port + 1))")
[ $? -ne 0 ] && conflict_found=1 && conflict_port="$((redir_port + 1))" [ $? -ne 0 ] && conflict_found=1 && conflict_port="$((redir_port + 1))"
fi fi
if [ "$conflict_found" -eq 0 ]; then if [ "$conflict_found" -eq 0 ]; then
conflict_info=$(check_port_with_info "$dns_port") conflict_info=$(check_port_with_info "$dns_port")
[ $? -ne 0 ] && conflict_found=1 && conflict_port="$dns_port" [ $? -ne 0 ] && conflict_found=1 && conflict_port="$dns_port"
fi fi
if [ "$conflict_found" -eq 0 ]; then if [ "$conflict_found" -eq 0 ]; then
conflict_info=$(check_port_with_info "$db_port" tcp) conflict_info=$(check_port_with_info "$db_port" tcp)
[ $? -ne 0 ] && conflict_found=1 && conflict_port="$db_port" [ $? -ne 0 ] && conflict_found=1 && conflict_port="$db_port"
fi fi
if [ "$conflict_found" -eq 1 ]; then if [ "$conflict_found" -eq 1 ]; then
comp_box "$conflict_port】:$MENU_PORT_CONFLICT_TITLE" \ comp_box "$conflict_port】:$MENU_PORT_CONFLICT_TITLE" \
"\033[0m$conflict_info\033[0m" \ "\033[0m$conflict_info\033[0m" \
"\033[36m$MENU_PORT_CONFLICT_HINT\033[0m" "\033[36m$MENU_PORT_CONFLICT_HINT\033[0m"
. "$CRASHDIR"/menus/2_settings.sh && set_adv_config . "$CRASHDIR"/menus/2_settings.sh && set_adv_config
. "$CRASHDIR"/libs/get_config.sh . "$CRASHDIR"/libs/get_config.sh
else else
break break
fi fi
done done
} }
# 脚本启动前检查 # 脚本启动前检查
ckstatus() { ckstatus() {
versionsh=$(cat "$CRASHDIR"/version) versionsh=$(cat "$CRASHDIR"/version)
[ -n "$versionsh" ] && versionsh_l=$versionsh [ -n "$versionsh" ] && versionsh_l=$versionsh
[ -z "$redir_mod" ] && redir_mod="$MENU_PURE_MOD" [ -z "$redir_mod" ] && redir_mod="$MENU_PURE_MOD"
# 获取本机host地址 # 获取本机host地址
[ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
[ -z "$host" ] && host='$MENU_IP_DF' [ -z "$host" ] && host='$MENU_IP_DF'
# dashboard目录位置 # dashboard目录位置
if [ -f /www/clash/index.html ]; then if [ -f /www/clash/index.html ]; then
dbdir=/www/clash dbdir=/www/clash
hostdir=/clash hostdir=/clash
else else
dbdir="$CRASHDIR"/ui dbdir="$CRASHDIR"/ui
hostdir=":$db_port/ui" hostdir=":$db_port/ui"
fi fi
if check_autostart; then if check_autostart; then
auto="\033[32m$MENU_AUTOSTART_ON\033[0m" auto="\033[32m$MENU_AUTOSTART_ON\033[0m"
else else
auto="\033[31m$MENU_AUTOSTART_OFF\033[0m" auto="\033[31m$MENU_AUTOSTART_OFF\033[0m"
fi fi
PID=$(pidof CrashCore | awk '{print $NF}') PID=$(pidof CrashCore | awk '{print $NF}')
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
run="\033[32m$MENU_RUN_ON$redir_mod$MENU_MOD\033[0m" run="\033[32m$MENU_RUN_ON$redir_mod$MENU_MOD\033[0m"
running_status running_status
elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ]; then elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ]; then
run="\033[32m$MENU_RUN_SET$redir_mod$MENU_MOD\033[0m" run="\033[32m$MENU_RUN_SET$redir_mod$MENU_MOD\033[0m"
else else
run="\033[31m$MENU_RUN_OFF$redir_mod$MENU_MOD\033[0m" run="\033[31m$MENU_RUN_OFF$redir_mod$MENU_MOD\033[0m"
# 检测系统端口占用 # 检测系统端口占用
checkport checkport
fi fi
corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/') corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/')
# [ "$firewall_area" = 5 ] && corename='转发' # [ "$firewall_area" = 5 ] && corename='转发'
[ -f "$TMPDIR"/debug.log -o -f "$CRASHDIR"/debug.log -a -n "$PID" ] && auto="\033[33m$MENU_AUTOSTART_DEBUG\033[0m" [ -f "$TMPDIR"/debug.log -o -f "$CRASHDIR"/debug.log -a -n "$PID" ] && auto="\033[33m$MENU_AUTOSTART_DEBUG\033[0m"
# 检查新手引导 # 检查新手引导
if [ -z "$userguide" ]; then if [ -z "$userguide" ]; then
userguide=1 userguide=1
. "$CRASHDIR"/menus/userguide.sh && userguide . "$CRASHDIR"/menus/userguide.sh && userguide
setconfig userguide 1 setconfig userguide 1
. "$CRASHDIR"/configs/ShellCrash.cfg . "$CRASHDIR"/configs/ShellCrash.cfg
fi fi
# 检查执行权限 # 检查执行权限
[ ! -x "$CRASHDIR"/start.sh ] && chmod +x "$CRASHDIR"/start.sh [ ! -x "$CRASHDIR"/start.sh ] && chmod +x "$CRASHDIR"/start.sh
# 检查/tmp内核文件 # 检查/tmp内核文件
for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -Ev ".*(zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box'); do for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -Ev ".*(zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box'); do
comp_box "$MENU_TMP_CORE_FOUND \033[36m/tmp/$file\033[0m" \ comp_box "$MENU_TMP_CORE_FOUND \033[36m/tmp/$file\033[0m" \
"$MENU_TMP_CORE_ASK" "$MENU_TMP_CORE_ASK"
btm_box "1) 立即加载" \ btm_box "1) 立即加载" \
"0) 暂不加载" "0) 暂不加载"
read -r -p "$COMMON_INPUT> " res read -r -p "$COMMON_INPUT> " res
[ "$res" = 1 ] && { [ "$res" = 1 ] && {
zip_type=$(echo "$file" | grep -oE 'tar.gz$|upx$|gz$') zip_type=$(echo "$file" | grep -oE 'tar.gz$|upx$|gz$')
. "$CRASHDIR"/menus/9_upgrade.sh && setcoretype . "$CRASHDIR"/menus/9_upgrade.sh && setcoretype
. "$CRASHDIR"/libs/core_tools.sh && core_check "/tmp/$file" . "$CRASHDIR"/libs/core_tools.sh && core_check "/tmp/$file"
if [ "$?" = 0 ] && [ -n "$crashcore" ]; then if [ "$?" = 0 ] && [ -n "$crashcore" ]; then
msg_alert "\033[32m$MENU_CORE_LOADED_OK\033[0m" msg_alert "\033[32m$MENU_CORE_LOADED_OK\033[0m"
switch_core switch_core
else else
rm -rf /tmp/"$file" rm -rf /tmp/"$file"
msg_alert "\033[33m$MENU_CORE_LOADED_BAD\033[0m" \ msg_alert "\033[33m$MENU_CORE_LOADED_BAD\033[0m" \
"\033[33m$MENU_CORE_REMOVED\033[0m" "\033[33m$MENU_CORE_REMOVED\033[0m"
fi fi
} }
done done
# 检查/tmp配置文件 # 检查/tmp配置文件
for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -iE 'config.yaml$|config.yml$|config.json$'); do for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -iE 'config.yaml$|config.yml$|config.json$'); do
tmp_file=/tmp/$file tmp_file=/tmp/$file
comp_box "$MENU_TMP_CFG_FOUND\033[36m/tmp/$file\033[0m" \ comp_box "$MENU_TMP_CFG_FOUND\033[36m/tmp/$file\033[0m" \
"$MENU_TMP_CFG_ASK" "$MENU_TMP_CFG_ASK"
btm_box "1) 立即加载" \ btm_box "1) 立即加载" \
"0) 暂不加载" "0) 暂不加载"
read -p "$COMMON_INPUT> " res read -p "$COMMON_INPUT> " res
[ "$res" = 1 ] && { [ "$res" = 1 ] && {
if [ -n "$(echo /tmp/$file | grep -iE '.json$')" ]; then if [ -n "$(echo /tmp/$file | grep -iE '.json$')" ]; then
mv -f /tmp/$file "$CRASHDIR"/jsons/config.json mv -f /tmp/$file "$CRASHDIR"/jsons/config.json
else else
mv -f /tmp/$file "$CRASHDIR"/yamls/config.yaml mv -f /tmp/$file "$CRASHDIR"/yamls/config.yaml
fi fi
msg_alert "\033[32m$MENU_CFG_LOADED_OK\033[0m " msg_alert "\033[32m$MENU_CFG_LOADED_OK\033[0m "
} }
done done
# 检查禁用配置覆写 # 检查禁用配置覆写
[ "$disoverride" = "1" ] && { [ "$disoverride" = "1" ] && {
comp_box "\033[33m$MENU_OVERRIDE_WARN\033[0m" \ comp_box "\033[33m$MENU_OVERRIDE_WARN\033[0m" \
"$MENU_OVERRIDE_ASK" "$MENU_OVERRIDE_ASK"
btm_box "1) 是" \ btm_box "1) 是" \
"0) 否" "0) 否"
read -p "$COMMON_INPUT> " res read -p "$COMMON_INPUT> " res
[ "$res" = 1 ] && unset disoverride && setconfig disoverride [ "$res" = 1 ] && unset disoverride && setconfig disoverride
} }
top_box "\033[30;43m$MENU_WELCOME\033[0m\t\t Ver: $versionsh_l" \ top_box "\033[30;43m$MENU_WELCOME\033[0m\t\t Ver: $versionsh_l" \
"$MENU_TG_CHANNEL\033[36;4mhttps://t.me/ShellClash\033[0m" "$MENU_TG_CHANNEL\033[36;4mhttps://t.me/ShellClash\033[0m"
separator_line "-" separator_line "-"
content_line "$corename$run\t $auto" content_line "$corename$run\t $auto"
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
content_line "$MENU_MEM_USED\033[44m$VmRSS\033[0m\t $MENU_RUNNING_TIME\033[46;30m$day\033[44;37m$time\033[0m" content_line "$MENU_MEM_USED\033[44m$VmRSS\033[0m\t $MENU_RUNNING_TIME\033[46;30m$day\033[44;37m$time\033[0m"
fi fi
separator_line "=" separator_line "="
} }
main_menu() { main_menu() {
while true; do while true; do
ckstatus ckstatus
btm_box "1) \033[32m$MENU_MAIN_1\033[0m" \ btm_box "1) \033[32m$MENU_MAIN_1\033[0m" \
"2) \033[36m$MENU_MAIN_2\033[0m" \ "2) \033[36m$MENU_MAIN_2\033[0m" \
"3) \033[31m$MENU_MAIN_3\033[0m" \ "3) \033[31m$MENU_MAIN_3\033[0m" \
"4) \033[33m$MENU_MAIN_4\033[0m" \ "4) \033[33m$MENU_MAIN_4\033[0m" \
"5) \033[32m$MENU_MAIN_5\033[0m" \ "5) \033[32m$MENU_MAIN_5\033[0m" \
"6) \033[36m$MENU_MAIN_6\033[0m" \ "6) \033[36m$MENU_MAIN_6\033[0m" \
"7) \033[33m$MENU_MAIN_7\033[0m" \ "7) \033[33m$MENU_MAIN_7\033[0m" \
"8) $MENU_MAIN_8" \ "8) $MENU_MAIN_8" \
"9) \033[32m$MENU_MAIN_9\033[0m" \ "9) \033[32m$MENU_MAIN_9\033[0m" \
"" \ "" \
"0) $MENU_MAIN_0" "0) $MENU_MAIN_0"
read -r -p "$MENU_MAIN_PROMPT" num read -r -p "$MENU_MAIN_PROMPT" num
case "$num" in case "$num" in
"" | 0) "" | 0)
line_break line_break
exit 0 exit 0
;; ;;
1) 1)
start_service start_service
line_break line_break
exit exit
;; ;;
2) 2)
checkcfg=$(cat "$CFG_PATH") checkcfg=$(cat "$CFG_PATH")
. "$CRASHDIR"/menus/2_settings.sh && settings . "$CRASHDIR"/menus/2_settings.sh && settings
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
checkcfg_new=$(cat "$CFG_PATH") checkcfg_new=$(cat "$CFG_PATH")
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart [ "$checkcfg" != "$checkcfg_new" ] && checkrestart
fi fi
;; ;;
3) 3)
[ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop [ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop
"$CRASHDIR"/start.sh stop "$CRASHDIR"/start.sh stop
sleep 1 sleep 1
msg_alert "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m" msg_alert "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m"
;; ;;
4) 4)
. "$CRASHDIR"/menus/4_setboot.sh && setboot . "$CRASHDIR"/menus/4_setboot.sh && setboot
;; ;;
5) 5)
. "$CRASHDIR"/menus/5_task.sh && task_menu . "$CRASHDIR"/menus/5_task.sh && task_menu
;; ;;
6) 6)
. "$CRASHDIR"/menus/6_core_config.sh && set_core_config . "$CRASHDIR"/menus/6_core_config.sh && set_core_config
;; ;;
7) 7)
GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg
touch "$GT_CFG_PATH" touch "$GT_CFG_PATH"
checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH") checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH")
. "$CRASHDIR"/menus/7_gateway.sh && gateway . "$CRASHDIR"/menus/7_gateway.sh && gateway
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH") checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH")
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart [ "$checkcfg" != "$checkcfg_new" ] && checkrestart
fi fi
;; ;;
8) 8)
. "$CRASHDIR"/menus/8_tools.sh && tools . "$CRASHDIR"/menus/8_tools.sh && tools
;; ;;
9) 9)
checkcfg=$(cat "$CFG_PATH") checkcfg=$(cat "$CFG_PATH")
. "$CRASHDIR"/menus/9_upgrade.sh && upgrade . "$CRASHDIR"/menus/9_upgrade.sh && upgrade
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
checkcfg_new=$(cat "$CFG_PATH") checkcfg_new=$(cat "$CFG_PATH")
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart [ "$checkcfg" != "$checkcfg_new" ] && checkrestart
fi fi
;; ;;
*) *)
errornum errornum
;; ;;
esac esac
done done
} }
case "$1" in case "$1" in
"") "")
main_menu main_menu
;; ;;
-l) -l)
main_menu main_menu
;; ;;
-t) -t)
shtype=sh shtype=sh
[ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash
"$shtype" -x "$CRASHDIR"/menu.sh -l "$shtype" -x "$CRASHDIR"/menu.sh -l
;; ;;
-s) -s)
"$CRASHDIR"/start.sh "$2" "$3" "$4" "$5" "$6" "$CRASHDIR"/start.sh "$2" "$3" "$4" "$5" "$6"
;; ;;
-i) -i)
. "$CRASHDIR"/init.sh 2>/dev/null . "$CRASHDIR"/init.sh 2>/dev/null
;; ;;
-st) -st)
shtype=sh shtype=sh
ckcmd bash && shtype=bash ckcmd bash && shtype=bash
"$shtype" -x "$CRASHDIR"/starts/bfstart.sh "$shtype" -x "$CRASHDIR"/starts/bfstart.sh
. "$CRASHDIR"/starts/start_legacy.sh . "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$COMMAND" 'shellcrash' start_legacy "$COMMAND" 'shellcrash'
"$shtype" -x "$CRASHDIR"/starts/afstart.sh "$shtype" -x "$CRASHDIR"/starts/afstart.sh
"$CRASHDIR"/start.sh stop "$CRASHDIR"/start.sh stop
;; ;;
-d) -d)
shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash
comp_box "$MENU_TEST_RUNNING_1" \ comp_box "$MENU_TEST_RUNNING_1" \
"$MENU_TEST_RUNNING_2\033[36;4mhttps://t.me/ShellClash\033[0m" "$MENU_TEST_RUNNING_2\033[36;4mhttps://t.me/ShellClash\033[0m"
"$shtype" "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh_bug.log "$shtype" "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh_bug.log
"$shtype" -x "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh.log "$shtype" -x "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh.log
cat "$TMPDIR"/debug_sh_bug.log | grep 'start\.sh' >"$TMPDIR"/sh_bug cat "$TMPDIR"/debug_sh_bug.log | grep 'start\.sh' >"$TMPDIR"/sh_bug
if [ -s "$TMPDIR"/sh_bug ]; then if [ -s "$TMPDIR"/sh_bug ]; then
line_break line_break
echo "===========================================================" echo "==========================================================="
while read line; do while read line; do
echo -e "$MENU_ERROR_FOUND\033[33;4m$line\033[0m" echo -e "$MENU_ERROR_FOUND\033[33;4m$line\033[0m"
grep -A 1 -B 3 "$line" "$TMPDIR"/debug_sh.log grep -A 1 -B 3 "$line" "$TMPDIR"/debug_sh.log
echo echo
done <"$TMPDIR"/sh_bug done <"$TMPDIR"/sh_bug
echo "===========================================================" echo "==========================================================="
rm -rf "$TMPDIR"/sh_bug rm -rf "$TMPDIR"/sh_bug
comp_box "\033[32m$MENU_TEST_DONE_FAIL\033[0m" \ comp_box "\033[32m$MENU_TEST_DONE_FAIL\033[0m" \
"$MENU_TEST_LOG_HINT\033[36m$TMPDIR/debug_sh.log\033[0m" "$MENU_TEST_LOG_HINT\033[36m$TMPDIR/debug_sh.log\033[0m"
else else
rm -rf "$TMPDIR"/debug_sh.log rm -rf "$TMPDIR"/debug_sh.log
comp_box "\033[32m$MENU_TEST_DONE_OK\033[0m" comp_box "\033[32m$MENU_TEST_DONE_OK\033[0m"
line_break line_break
fi fi
"$CRASHDIR"/start.sh stop "$CRASHDIR"/start.sh stop
;; ;;
-u) -u)
. "$CRASHDIR"/menus/uninstall.sh && uninstall . "$CRASHDIR"/menus/uninstall.sh && uninstall
;; ;;
*) *)
comp_box "$MENU_WELCOME" comp_box "$MENU_WELCOME"
content_line "-t $MENU_CLI_TEST" content_line "-t $MENU_CLI_TEST"
content_line "-h $MENU_CLI_HELP" content_line "-h $MENU_CLI_HELP"
content_line "-u $MENU_CLI_UNINSTALL" content_line "-u $MENU_CLI_UNINSTALL"
content_line "-i $MENU_CLI_INIT" content_line "-i $MENU_CLI_INIT"
content_line "-d $MENU_CLI_DEBUG" content_line "-d $MENU_CLI_DEBUG"
separator_line "-" separator_line "-"
content_line "crash -s start $MENU_CLI_START" content_line "crash -s start $MENU_CLI_START"
content_line "crash -s stop $MENU_CLI_STOP" content_line "crash -s stop $MENU_CLI_STOP"
content_line "$CRASHDIR/start.sh init $MENU_CLI_BOOT_INIT" content_line "$CRASHDIR/start.sh init $MENU_CLI_BOOT_INIT"
separator_line "-" separator_line "-"
content_line "$MENU_HELP_ONLINE\033[36mhttps://t.me/ShellClash\033[0m" content_line "$MENU_HELP_ONLINE\033[36mhttps://t.me/ShellClash\033[0m"
content_line "$MENU_HELP_BLOG\033[36mhttps://juewuy.github.io\033[0m" content_line "$MENU_HELP_BLOG\033[36mhttps://juewuy.github.io\033[0m"
content_line "$MENU_HELP_GITHUB\033[36mhttps://github.com/juewuy/ShellCrash\033[0m" content_line "$MENU_HELP_GITHUB\033[36mhttps://github.com/juewuy/ShellCrash\033[0m"
separator_line "=" separator_line "="
line_break line_break
;; ;;
esac esac

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@ set_core_config() {
LC_ALL=C awk '{ LC_ALL=C awk '{
f1 = $1 f1 = $1
f2 = $2 f2 = $2
gsub(/\360[\200-\277][\200-\277][\200-\277]/,"",f1) gsub(/\360[\200-\277][\200-\277][\200-\277]/,"",f1)
if (length(f1) > 12) if (length(f1) > 12)
f1 = substr(f1, 1, 8) ".." f1 = substr(f1, 1, 8) ".."
if (length(f2) > 30) if (length(f2) > 30)

File diff suppressed because it is too large Load Diff

View File

@@ -758,7 +758,7 @@ debug() {
. "$CRASHDIR"/libs/core_tools.sh && core_find && "$TMPDIR"/CrashCore merge "$TMPDIR"/debug.json -C "$TMPDIR"/jsons && line_break . "$CRASHDIR"/libs/core_tools.sh && core_find && "$TMPDIR"/CrashCore merge "$TMPDIR"/debug.json -C "$TMPDIR"/jsons && line_break
comp_box "\033[32m$TOOLS_MERGE_OK\033[0m" comp_box "\033[32m$TOOLS_MERGE_OK\033[0m"
[ "$TMPDIR" = "$BINDIR" ] && rm -rf "$TMPDIR"/CrashCore [ "$TMPDIR" = "$BINDIR" ] && rm -rf "$TMPDIR"/CrashCore
debug debug
;; ;;
*) *)
errornum errornum

View File

@@ -1111,7 +1111,7 @@ saveserver() {
setserver() { setserver() {
while true; do while true; do
line_break line_break
LISTFILE="$CRASHDIR"/configs/servers_"$i18n".list LISTFILE="$CRASHDIR"/configs/servers_"$i18n".list
[ -z "$release_type" ] && release_name=$UPG_SOURCE_UNSET [ -z "$release_type" ] && release_name=$UPG_SOURCE_UNSET
[ -n "$release_type" ] && release_name="$release_type$UPG_SOURCE_ROLLBACK_TAG" [ -n "$release_type" ] && release_name="$release_type$UPG_SOURCE_ROLLBACK_TAG"
[ "$release_type" = stable ] && release_name=$UPG_SOURCE_STABLE_TEXT [ "$release_type" = stable ] && release_name=$UPG_SOURCE_STABLE_TEXT

View File

@@ -19,19 +19,19 @@ OFFSET=0
### --- 基础函数 --- ### ### --- 基础函数 --- ###
web_download(){ web_download(){
setproxy setproxy
if curl --version >/dev/null 2>&1; then if curl --version >/dev/null 2>&1; then
curl -kfsSl "$1" -o "$2" curl -kfsSl "$1" -o "$2"
else else
wget -Y on -q --timeout=3 -O "$2" "$1" wget -Y on -q --timeout=3 -O "$2" "$1"
fi fi
} }
web_upload(){ web_upload(){
curl -ksSfl -X POST --connect-timeout 20 "$API/sendDocument" -F "chat_id=$TG_CHATID" -F "document=@$1" >/dev/null curl -ksSfl -X POST --connect-timeout 20 "$API/sendDocument" -F "chat_id=$TG_CHATID" -F "document=@$1" >/dev/null
} }
send_msg(){ send_msg(){
TEXT="$1" TEXT="$1"
web_json_post "$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
@@ -48,18 +48,18 @@ https://dler.pro/auth/register?affid=89698
https://pub.bigmeok.me?code=2PuWY9I7 https://pub.bigmeok.me?code=2PuWY9I7
EOF EOF
) )
send_msg "$TEXT" send_msg "$TEXT"
} }
send_menu(){ send_menu(){
#获取运行状态 #获取运行状态
PID=$(pidof CrashCore | awk '{print $NF}') PID=$(pidof CrashCore | awk '{print $NF}')
if [ -n "$PID" ]; then if [ -n "$PID" ]; then
run="$BOT_TG_RUN_ON" run="$BOT_TG_RUN_ON"
running_status running_status
else else
run="$BOT_TG_RUN_OFF" run="$BOT_TG_RUN_OFF"
fi fi
corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/') corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/')
TEXT=$(cat <<EOF TEXT=$(cat <<EOF
*$BOT_TG_WELCOME*_${versionsh_l}_ *$BOT_TG_WELCOME*_${versionsh_l}_
$corename$BOT_TG_SERVICE$run $corename$BOT_TG_SERVICE$run
@@ -78,7 +78,7 @@ EOF
], ],
[ [
{"text":"$BOT_TG_BTN_LOG","callback_data":"readlog"}, {"text":"$BOT_TG_BTN_LOG","callback_data":"readlog"},
{"text":"$BOT_TG_BTN_TRANSFER","callback_data":"transport"} {"text":"$BOT_TG_BTN_TRANSFER","callback_data":"transport"}
] ]
] ]
} }
@@ -89,31 +89,31 @@ web_json_post "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\"
### --- 文件传输 --- ### ### --- 文件传输 --- ###
send_transport_menu(){ send_transport_menu(){
TEXT="$BOT_TG_SELECT_FILE" TEXT="$BOT_TG_SELECT_FILE"
if echo "$crashcore" | grep -q 'singbox';then if echo "$crashcore" | grep -q 'singbox';then
config_type=json config_type=json
else else
config_type=yaml config_type=yaml
fi fi
if curl -h >/dev/null 2>&1;then if curl -h >/dev/null 2>&1;then
CURL_KB=$(cat <<EOF CURL_KB=$(cat <<EOF
[ [
{"text":"$BOT_TG_BTN_GET_LOG","callback_data":"ts_get_log"}, {"text":"$BOT_TG_BTN_GET_LOG","callback_data":"ts_get_log"},
{"text":"$BOT_TG_BTN_GET_BAK","callback_data":"ts_get_bak"}, {"text":"$BOT_TG_BTN_GET_BAK","callback_data":"ts_get_bak"},
{"text":"$BOT_TG_BTN_GET_CFG","callback_data":"ts_get_ccf"} {"text":"$BOT_TG_BTN_GET_CFG","callback_data":"ts_get_ccf"}
], ],
EOF EOF
) )
else else
CURL_KB='[{"text":"$BOT_TG_NO_CURL","callback_data":"noop"}],' CURL_KB='[{"text":"$BOT_TG_NO_CURL","callback_data":"noop"}],'
fi fi
MENU=$(cat <<EOF MENU=$(cat <<EOF
{ {
"inline_keyboard":[ "inline_keyboard":[
$CURL_KB $CURL_KB
[ [
{"text":"$BOT_TG_BTN_UP_CORE","callback_data":"ts_up_core"}, {"text":"$BOT_TG_BTN_UP_CORE","callback_data":"ts_up_core"},
{"text":"$BOT_TG_BTN_UP_BAK","callback_data":"ts_up_bak"}, {"text":"$BOT_TG_BTN_UP_BAK","callback_data":"ts_up_bak"},
{"text":"$BOT_TG_BTN_UP_CFG","callback_data":"ts_up_ccf"} {"text":"$BOT_TG_BTN_UP_CFG","callback_data":"ts_up_ccf"}
] ]
] ]
@@ -125,54 +125,54 @@ web_json_post "$API/sendMessage" "{\"chat_id\":\"$TG_CHATID\",\"text\":\"$TEXT\"
} }
process_file(){ process_file(){
case "$FILE_TYPE" in case "$FILE_TYPE" in
1) 1)
. "$CRASHDIR"/libs/core_tools.sh . "$CRASHDIR"/libs/core_tools.sh
core_check "$TMPDIR/$FILE_NAME" && res="$BOT_TG_UPLOAD_OK" || res="$BOT_TG_UPLOAD_FAIL" core_check "$TMPDIR/$FILE_NAME" && res="$BOT_TG_UPLOAD_OK" || res="$BOT_TG_UPLOAD_FAIL"
send_msg "$BOT_TG_CORE_UPDATE$res" send_msg "$BOT_TG_CORE_UPDATE$res"
sleep 2 sleep 2
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
;; ;;
2) 2)
tar -zxf "$TMPDIR/$FILE_NAME" -C "$CRASHDIR"/configs && res="$BOT_TG_CFG_RESTORED" || res="$BOT_TG_RESTORE_FAIL" tar -zxf "$TMPDIR/$FILE_NAME" -C "$CRASHDIR"/configs && res="$BOT_TG_CFG_RESTORED" || res="$BOT_TG_RESTORE_FAIL"
send_msg "$res" send_msg "$res"
;; ;;
3) 3)
mv -f "$TMPDIR/$FILE_NAME" "$CRASHDIR/${config_type}s/" && res="$BOT_TG_CFG_UPLOADED" || res="$BOT_TG_UPLOAD_FAIL2" mv -f "$TMPDIR/$FILE_NAME" "$CRASHDIR/${config_type}s/" && res="$BOT_TG_CFG_UPLOADED" || res="$BOT_TG_UPLOAD_FAIL2"
send_msg "$res" send_msg "$res"
;; ;;
esac esac
rm -f "$TMPDIR/$FILE_NAME" rm -f "$TMPDIR/$FILE_NAME"
send_menu send_menu
} }
download_file(){ download_file(){
FILE_NAME=$(echo "$UPDATES" | sed 's/"callback_query".*//g' | grep -o '"file_name":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//' | grep -E '\.(gz|upx|json|yaml)$') FILE_NAME=$(echo "$UPDATES" | sed 's/"callback_query".*//g' | grep -o '"file_name":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//' | grep -E '\.(gz|upx|json|yaml)$')
if [ -n "$FILE_NAME" ];then if [ -n "$FILE_NAME" ];then
FILE_PATH=$(web_get_lite "$API/getFile?file_id=$FILE_ID" | grep -o '"file_path":"[^"]*"' | sed 's/.*:"//;s/"$//') FILE_PATH=$(web_get_lite "$API/getFile?file_id=$FILE_ID" | grep -o '"file_path":"[^"]*"' | sed 's/.*:"//;s/"$//')
API_FILE="https://api.telegram.org/file/bot$TG_TOKEN" API_FILE="https://api.telegram.org/file/bot$TG_TOKEN"
web_download "$API_FILE/$FILE_PATH" "$TMPDIR/$FILE_NAME" web_download "$API_FILE/$FILE_PATH" "$TMPDIR/$FILE_NAME"
if [ "$?" = 0 ];then if [ "$?" = 0 ];then
process_file process_file
else else
send_msg "$BOT_TG_NET_UPLOAD_FAIL" send_msg "$BOT_TG_NET_UPLOAD_FAIL"
fi fi
else else
send_msg "$BOT_TG_FILE_FORMAT_FAIL" send_msg "$BOT_TG_FILE_FORMAT_FAIL"
fi fi
} }
### --- 具体操作函数 --- ### ### --- 具体操作函数 --- ###
do_start_fw(){ do_start_fw(){
[ -z "$redir_mod_bf" ] && redir_mod_bf='Redir' [ -z "$redir_mod_bf" ] && redir_mod_bf='Redir'
redir_mod=$redir_mod_bf redir_mod=$redir_mod_bf
setconfig redir_mod $redir_mod setconfig redir_mod $redir_mod
"$CRASHDIR"/start.sh start_firewall "$CRASHDIR"/start.sh start_firewall
echo "$BOT_TG_FW_ENABLED*$redir_mod_bf*$BOT_TG_FW_ENABLED_SUFFIX" > "$LOGFILE" echo "$BOT_TG_FW_ENABLED*$redir_mod_bf*$BOT_TG_FW_ENABLED_SUFFIX" > "$LOGFILE"
} }
do_stop_fw(){ do_stop_fw(){
redir_mod_bf=$redir_mod redir_mod_bf=$redir_mod
firewall_area=4 firewall_area=4
setconfig firewall_area 4 setconfig firewall_area 4
"$CRASHDIR"/start.sh stop_firewall "$CRASHDIR"/start.sh stop_firewall
echo "$BOT_TG_SWITCH_PURE" > "$LOGFILE" echo "$BOT_TG_SWITCH_PURE" > "$LOGFILE"
} }
do_restart(){ do_restart(){
@@ -185,142 +185,142 @@ do_set_sub(){
} }
transport(){ #文件传输 transport(){ #文件传输
case "$CALLBACK" in case "$CALLBACK" in
"ts_get_log") "ts_get_log")
web_upload "$TMPDIR"/ShellCrash.log web_upload "$TMPDIR"/ShellCrash.log
send_menu send_menu
;; ;;
"ts_get_bak") "ts_get_bak")
now=$(date +%Y%m%d_%H%M%S) now=$(date +%Y%m%d_%H%M%S)
FILE="$TMPDIR/configs_$now.tar.gz" FILE="$TMPDIR/configs_$now.tar.gz"
tar -zcf "$FILE" -C "$CRASHDIR/configs/" . tar -zcf "$FILE" -C "$CRASHDIR/configs/" .
web_upload "$FILE" web_upload "$FILE"
rm -rf "$FILE" rm -rf "$FILE"
send_menu send_menu
;; ;;
"ts_get_ccf") "ts_get_ccf")
FILE="$TMPDIR/$config_type.tar.gz" FILE="$TMPDIR/$config_type.tar.gz"
tar -zcf "$FILE" -C "$CRASHDIR/${config_type}s/" . tar -zcf "$FILE" -C "$CRASHDIR/${config_type}s/" .
web_upload "$FILE" web_upload "$FILE"
rm -rf "$FILE" rm -rf "$FILE"
send_menu send_menu
;; ;;
"ts_up_core") "ts_up_core")
FILE_TYPE=1 FILE_TYPE=1
send_msg "$BOT_TG_SEND_CORE ${corename} $BOT_TG_SEND_CORE_SUFFIX" send_msg "$BOT_TG_SEND_CORE ${corename} $BOT_TG_SEND_CORE_SUFFIX"
;; ;;
"ts_up_bak") "ts_up_bak")
FILE_TYPE=2 FILE_TYPE=2
send_msg "$BOT_TG_SEND_BAK" send_msg "$BOT_TG_SEND_BAK"
;; ;;
"ts_up_ccf") "ts_up_ccf")
FILE_TYPE=3 FILE_TYPE=3
send_msg "$BOT_TG_SEND_CFG .${config_type} $BOT_TG_SEND_CFG_SUFFIX" send_msg "$BOT_TG_SEND_CFG .${config_type} $BOT_TG_SEND_CFG_SUFFIX"
;; ;;
esac esac
} }
### --- 轮询主进程 --- ### ### --- 轮询主进程 --- ###
polling(){ polling(){
while true; do while true; do
UPDATES=$(web_get_lite "$API/getUpdates?timeout=25&offset=$OFFSET") UPDATES=$(web_get_lite "$API/getUpdates?timeout=25&offset=$OFFSET")
echo "$UPDATES" | grep -q '"update_id"' || { echo "$UPDATES" | grep -q '"update_id"' || {
sleep 10 #防止网络不佳时疯狂请求 sleep 10 #防止网络不佳时疯狂请求
continue continue
} }
OFFSET=$(echo "$UPDATES" | grep -o '"update_id":[0-9]*' | tail -n1 | cut -d: -f2) OFFSET=$(echo "$UPDATES" | grep -o '"update_id":[0-9]*' | tail -n1 | cut -d: -f2)
OFFSET=$((OFFSET + 1)) OFFSET=$((OFFSET + 1))
### --- 校验ChatID --- ### ### --- 校验ChatID --- ###
CHATID=$(echo "$UPDATES" | grep -o '"id":[0-9]*' | tail -n1 | cut -d: -f2) CHATID=$(echo "$UPDATES" | grep -o '"id":[0-9]*' | tail -n1 | cut -d: -f2)
[ "$CHATID" != "$TG_CHATID" ] && continue [ "$CHATID" != "$TG_CHATID" ] && continue
### --- 处理按钮事件 --- ### ### --- 处理按钮事件 --- ###
CALLBACK=$(echo "$UPDATES" | grep -o '"data":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//') CALLBACK=$(echo "$UPDATES" | grep -o '"data":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//')
FILE_ID=$(echo "$UPDATES" | sed 's/"callback_query".*//g' | grep -o '"file_id":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//') FILE_ID=$(echo "$UPDATES" | sed 's/"callback_query".*//g' | grep -o '"file_id":"[^"]*"' | head -n1 | sed 's/.*:"//;s/"$//')
[ -n "$FILE_ID" ] && { [ -n "$FILE_ID" ] && {
download_file download_file
continue continue
} }
[ -n "$CALLBACK" ] && case "$CALLBACK" in [ -n "$CALLBACK" ] && case "$CALLBACK" in
"start_redir") "start_redir")
if [ "$firewall_area" = 4 ];then if [ "$firewall_area" = 4 ];then
do_start_fw do_start_fw
send_msg "$BOT_TG_SWITCH_TO$redir_mod_bf" send_msg "$BOT_TG_SWITCH_TO$redir_mod_bf"
else else
send_msg "$BOT_TG_ALREADY$redir_mod" send_msg "$BOT_TG_ALREADY$redir_mod"
fi fi
send_menu send_menu
continue continue
;; ;;
"stop_redir") "stop_redir")
if [ "$firewall_area" != 4 ];then if [ "$firewall_area" != 4 ];then
do_stop_fw do_stop_fw
send_msg "$BOT_TG_SWITCH_PURE" send_msg "$BOT_TG_SWITCH_PURE"
else else
send_msg "$BOT_TG_ALREADY_PURE" send_msg "$BOT_TG_ALREADY_PURE"
fi fi
send_menu send_menu
continue continue
;; ;;
"restart") "restart")
do_restart do_restart
send_msg "$BOT_TG_SERVICE_RESTARTED_SHORT" send_msg "$BOT_TG_SERVICE_RESTARTED_SHORT"
sleep 10 sleep 10
send_menu send_menu
continue continue
;; ;;
"readlog") "readlog")
send_msg "$BOT_TG_LOG_CONTENT\n\`\`\`$(grep -v "$BOT_TG_TASK_WORD" $TMPDIR/ShellCrash.log |tail -n 20)\`\`\`" send_msg "$BOT_TG_LOG_CONTENT\n\`\`\`$(grep -v "$BOT_TG_TASK_WORD" $TMPDIR/ShellCrash.log |tail -n 20)\`\`\`"
sleep 3 sleep 3
send_menu send_menu
continue continue
;; ;;
"transport") "transport")
send_transport_menu send_transport_menu
continue continue
;; ;;
"set_sub") "set_sub")
echo "await_sub" > "$STATE_FILE" echo "await_sub" > "$STATE_FILE"
send_msg "$BOT_TG_INPUT_SUB" send_msg "$BOT_TG_INPUT_SUB"
continue continue
;; ;;
ts_*) ts_*)
transport transport
continue continue
;; ;;
esac esac
### --- 处理订阅输入 --- ### ### --- 处理订阅输入 --- ###
TEXT=$(echo "$UPDATES" | grep -o '"text":"[^"]*"' | tail -n1 | sed 's/.*"text":"//;s/"$//') TEXT=$(echo "$UPDATES" | grep -o '"text":"[^"]*"' | tail -n1 | sed 's/.*"text":"//;s/"$//')
if [ "$(cat "$STATE_FILE" 2>/dev/null)" = "await_sub" ]; then if [ "$(cat "$STATE_FILE" 2>/dev/null)" = "await_sub" ]; then
echo "" > "$STATE_FILE" echo "" > "$STATE_FILE"
do_set_sub "$TEXT" do_set_sub "$TEXT"
send_msg "$BOT_TG_SUB_UPDATED\n$(cat "$LOGFILE")" send_msg "$BOT_TG_SUB_UPDATED\n$(cat "$LOGFILE")"
send_menu send_menu
continue continue
fi fi
### 处理命令 ### ### 处理命令 ###
case "$TEXT" in case "$TEXT" in
/crash) /crash)
send_menu send_menu
;; ;;
/"$my_alias") /"$my_alias")
send_menu send_menu
;; ;;
/help) /help)
send_help send_help
;; ;;
esac esac
done done
} }
[ "$TG_menupush" = ON ] && send_menu [ "$TG_menupush" = ON ] && send_menu

View File

@@ -22,7 +22,7 @@ tg_push_token() {
push_TG="$TOKEN" push_TG="$TOKEN"
setconfig push_TG "$TOKEN" setconfig push_TG "$TOKEN"
setconfig chat_ID "$chat_ID" setconfig chat_ID "$chat_ID"
. "$CRASHDIR"/libs/logger.sh && logger "$BOT_TG_SET_DONE" 32 . "$CRASHDIR"/libs/logger.sh && logger "$BOT_TG_SET_DONE" 32
} }
get_chatid() { get_chatid() {

View File

@@ -1,16 +1,16 @@
. "$CRASHDIR"/libs/set_cron.sh . "$CRASHDIR"/libs/set_cron.sh
bot_tg_start(){ bot_tg_start(){
. "$CRASHDIR"/starts/start_legacy.sh . "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$CRASHDIR/menus/bot_tg.sh" 'bot_tg' start_legacy "$CRASHDIR/menus/bot_tg.sh" 'bot_tg'
} }
bot_tg_stop(){ bot_tg_stop(){
cronload | grep -q 'TG_BOT' && cronset 'TG_BOT' cronload | grep -q 'TG_BOT' && cronset 'TG_BOT'
[ -f "$TMPDIR/bot_tg.pid" ] && kill -TERM "$(cat "$TMPDIR/bot_tg.pid")" 2>/dev/null [ -f "$TMPDIR/bot_tg.pid" ] && kill -TERM "$(cat "$TMPDIR/bot_tg.pid")" 2>/dev/null
killall bot_tg.sh 2>/dev/null killall bot_tg.sh 2>/dev/null
rm -f "$TMPDIR/bot_tg.pid" rm -f "$TMPDIR/bot_tg.pid"
} }
bot_tg_cron(){ bot_tg_cron(){
cronset 'ShellCrash-TG_BOT' "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh bot_tg #ShellCrash-TG_BOT" cronset 'ShellCrash-TG_BOT' "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh bot_tg #ShellCrash-TG_BOT"
} }

View File

@@ -4,46 +4,46 @@
load_lang check_port load_lang check_port
_get_netstat_cmd() { _get_netstat_cmd() {
case "$1" in case "$1" in
tcp) echo "netstat -ntl" ;; tcp) echo "netstat -ntl" ;;
udp) echo "netstat -nul" ;; udp) echo "netstat -nul" ;;
*) echo "netstat -ntul" ;; *) echo "netstat -ntul" ;;
esac esac
} }
check_port() { check_port() {
local port="$1" local port="$1"
local protocol="${2:-all}" local protocol="${2:-all}"
if [ "$port" -gt 65535 ] || [ "$port" -le 1 ]; then if [ "$port" -gt 65535 ] || [ "$port" -le 1 ]; then
msg_alert "\033[31m$CHECK_PORT_RANGE_ERR\033[0m" msg_alert "\033[31m$CHECK_PORT_RANGE_ERR\033[0m"
return 1 return 1
fi fi
local check_cmd local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol") check_cmd=$(_get_netstat_cmd "$protocol")
if $check_cmd 2>/dev/null | grep -q ":${port}[[:space:]]"; then if $check_cmd 2>/dev/null | grep -q ":${port}[[:space:]]"; then
msg_alert "\033[31m$CHECK_PORT_OCCUPIED_ERR\033[0m" msg_alert "\033[31m$CHECK_PORT_OCCUPIED_ERR\033[0m"
return 1 return 1
fi fi
return 0 return 0
} }
check_port_with_info() { check_port_with_info() {
local port="$1" local port="$1"
local protocol="${2:-all}" local protocol="${2:-all}"
local check_cmd local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol") check_cmd=$(_get_netstat_cmd "$protocol")
local conflict_line local conflict_line
conflict_line=$($check_cmd 2>/dev/null | grep ":${port}[[:space:]]" | head -n 1) conflict_line=$($check_cmd 2>/dev/null | grep ":${port}[[:space:]]" | head -n 1)
if [ -n "$conflict_line" ]; then if [ -n "$conflict_line" ]; then
echo "$conflict_line" echo "$conflict_line"
return 1 return 1
fi fi
return 0 return 0
} }

View File

@@ -12,21 +12,21 @@ add_ddns() {
cat >>"$ddns_dir" <<EOF cat >>"$ddns_dir" <<EOF
config service '$service' config service '$service'
option enabled '1' option enabled '1'
option force_unit 'hours' option force_unit 'hours'
option lookup_host '$domain' option lookup_host '$domain'
option service_name '$service_name' option service_name '$service_name'
option domain '$domain' option domain '$domain'
option username '$username' option username '$username'
option use_https '0' option use_https '0'
option use_ipv6 '$use_ipv6' option use_ipv6 '$use_ipv6'
option password '$password' option password '$password'
option ip_source 'web' option ip_source 'web'
option check_unit 'minutes' option check_unit 'minutes'
option check_interval '$check_interval' option check_interval '$check_interval'
option force_interval '$force_interval' option force_interval '$force_interval'
option interface 'wan' option interface 'wan'
option bind_network 'wan' option bind_network 'wan'
EOF EOF
/usr/lib/ddns/dynamic_dns_updater.sh -S "$service" start >/dev/null 2>&1 & /usr/lib/ddns/dynamic_dns_updater.sh -S "$service" start >/dev/null 2>&1 &
sleep 3 sleep 3
@@ -71,12 +71,12 @@ set_ddns() {
set_ddns_service() { set_ddns_service() {
while true; do while true; do
services_dir=/etc/ddns/"$serv" services_dir=/etc/ddns/"$serv"
[ -s "$services_dir" ] || services_dir=/etc/ddns/services [ -s "$services_dir" ] || services_dir=/etc/ddns/services
[ -s "$services_dir" ] || services_dir=/usr/share/ddns/list [ -s "$services_dir" ] || services_dir=/usr/share/ddns/list
[ -s "$services_dir" ] || { [ -s "$services_dir" ] || {
msg_alert "\033[33m$DDNS_LIST_NOT_FOUND\033[0m" msg_alert "\033[33m$DDNS_LIST_NOT_FOUND\033[0m"
ddns service update >/dev/null || msg_alert "\033[31m$DDNS_DOWNLOAD_FAILED\033[0m" ddns service update >/dev/null || msg_alert "\033[31m$DDNS_DOWNLOAD_FAILED\033[0m"
} }
comp_box "\033[32m$DDNS_SELECT_PROVIDER\033[0m" comp_box "\033[32m$DDNS_SELECT_PROVIDER\033[0m"
list=$(awk '/^#/ || !NF {next} {print $1}' "$services_dir") list=$(awk '/^#/ || !NF {next} {print $1}' "$services_dir")

View File

@@ -48,31 +48,31 @@ set_dns_mod() {
msg_alert "\033[36m$DNS_SET_OK$dns_mod\033[0m" msg_alert "\033[36m$DNS_SET_OK$dns_mod\033[0m"
;; ;;
4) 4)
if [ "$dns_protect" = ON ]; then if [ "$dns_protect" = ON ]; then
dns_protect=OFF dns_protect=OFF
else else
dns_protect=ON dns_protect=ON
fi fi
setconfig dns_protect "$dns_protect" setconfig dns_protect "$dns_protect"
common_success common_success
;; ;;
5) 5)
if [ "$hosts_opt" = ON ]; then if [ "$hosts_opt" = ON ]; then
hosts_opt=OFF hosts_opt=OFF
else else
hosts_opt=ON hosts_opt=ON
fi fi
setconfig hosts_opt "$hosts_opt" setconfig hosts_opt "$hosts_opt"
common_success common_success
;; ;;
6) 6)
if [ "$ecs_subnet" = ON ]; then if [ "$ecs_subnet" = ON ]; then
ecs_subnet=OFF ecs_subnet=OFF
else else
ecs_subnet=ON ecs_subnet=ON
fi fi
setconfig ecs_subnet "$ecs_subnet" setconfig ecs_subnet "$ecs_subnet"
common_success common_success
;; ;;
7) 7)
while true; do while true; do

View File

@@ -97,21 +97,21 @@ gen_providers_txt() {
[ -n "$include" ] && include_ele="\"include\": \"$include\"," [ -n "$include" ] && include_ele="\"include\": \"$include\","
if [ -n "$(echo "$2" | grep -E '^./')" ]; then if [ -n "$(echo "$2" | grep -E '^./')" ]; then
cat >>"$TMPDIR"/providers/providers.json <<EOF cat >>"$TMPDIR"/providers/providers.json <<EOF
{ {
"tag": "$tag", "tag": "$tag",
"type": "local", "type": "local",
"path": "$2", "path": "$2",
EOF EOF
else else
cat >>"$TMPDIR"/providers/providers.json <<EOF cat >>"$TMPDIR"/providers/providers.json <<EOF
{ {
"tag": "$tag", "tag": "$tag",
"type": "remote", "type": "remote",
"url": "$2", "url": "$2",
"path": "./providers/$tag.yaml", "path": "./providers/$tag.yaml",
"user_agent": "$ua", "user_agent": "$ua",
"update_interval": "${interval2}h", "update_interval": "${interval2}h",
$exclude_ele $exclude_ele
$include_ele $include_ele
EOF EOF
fi fi
@@ -124,11 +124,11 @@ EOF
"interval": "${interval}m", "interval": "${interval}m",
"timeout": "3s" "timeout": "3s"
}, },
"override_tls": { "override_tls": {
"enabled": true, "enabled": true,
"insecure": $override_tls "insecure": $override_tls
} }
}, },
EOF EOF
# 写入提供者 # 写入提供者
echo '{ "tag": "'"$tag"'", "type": "urltest", "tolerance": 100, "providers": ["'"$tag"'"], "include": ".*" },' >>"$TMPDIR"/providers/outbounds_add.json echo '{ "tag": "'"$tag"'", "type": "urltest", "tolerance": 100, "providers": ["'"$tag"'"], "include": ".*" },' >>"$TMPDIR"/providers/outbounds_add.json

View File

@@ -1,13 +1,13 @@
running_status(){ running_status(){
VmRSS=$(awk '/^VmRSS:/ {printf "%.2f MB\n", ($2 * 1024) / 1000000}' /proc/$PID/status) VmRSS=$(awk '/^VmRSS:/ {printf "%.2f MB\n", ($2 * 1024) / 1000000}' /proc/$PID/status)
#获取运行时长 #获取运行时长
touch "$TMPDIR"/crash_start_time #用于延迟启动的校验 touch "$TMPDIR"/crash_start_time #用于延迟启动的校验
start_time=$(cat "$TMPDIR"/crash_start_time) start_time=$(cat "$TMPDIR"/crash_start_time)
if [ -n "$start_time" ]; then if [ -n "$start_time" ]; then
time=$(($(date +%s) - start_time)) time=$(($(date +%s) - start_time))
day=$((time / 86400)) day=$((time / 86400))
[ "$day" = "0" ] && day='' || day="$dayD" [ "$day" = "0" ] && day='' || day="$dayD"
time=$(date -u -d @${time} +%H:%M:%S) time=$(date -u -d @${time} +%H:%M:%S)
fi fi
} }

View File

@@ -14,118 +14,118 @@
load_lang task_cmd load_lang task_cmd
task_logger(){ task_logger(){
[ "$task_push" = 1 ] && push= || push=off [ "$task_push" = 1 ] && push= || push=off
[ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m" [ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m"
[ "$3" = 'off' ] && push=off [ "$3" = 'off' ] && push=off
echo "$1" |grep -qE "($TASK_CMD_EVERY|$TASK_CMD_HOURLY)([1-9]|[1-9][0-9])$TASK_CMD_MIN" && { echo "$1" |grep -qE "($TASK_CMD_EVERY|$TASK_CMD_HOURLY)([1-9]|[1-9][0-9])$TASK_CMD_MIN" && {
push=off push=off
cover=on cover=on
} }
logger "$1" 0 "$push" "$cover" logger "$1" 0 "$push" "$cover"
} }
#任务命令 #任务命令
check_update(){ #检查更新工具 check_update(){ #检查更新工具
get_bin "$TMPDIR"/crashversion "$1" echooff get_bin "$TMPDIR"/crashversion "$1" echooff
[ "$?" = "0" ] && . "$TMPDIR"/crashversion 2>/dev/null [ "$?" = "0" ] && . "$TMPDIR"/crashversion 2>/dev/null
rm -rf "$TMPDIR"/crashversion rm -rf "$TMPDIR"/crashversion
} }
update_core(){ #自动更新内核 update_core(){ #自动更新内核
#检查版本 #检查版本
check_update bin/version check_update bin/version
crash_v_new=$(eval echo \$${crashcore}_v) crash_v_new=$(eval echo \$${crashcore}_v)
if [ -z "$crash_v_new" -o "$crash_v_new" = "$core_v" ];then if [ -z "$crash_v_new" -o "$crash_v_new" = "$core_v" ];then
task_logger "$TASK_CMD_CORE_SKIP" task_logger "$TASK_CMD_CORE_SKIP"
return 0 return 0
else else
. "$CRASHDIR"/libs/core_tools.sh && core_webget #调用下载工具 . "$CRASHDIR"/libs/core_tools.sh && core_webget #调用下载工具
case "$?" in case "$?" in
0) 0)
task_logger "$TASK_CMD_CORE_DONE" task_logger "$TASK_CMD_CORE_DONE"
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
return 0 return 0
;; ;;
1) 1)
task_logger "$TASK_CMD_CORE_DL_FAIL" task_logger "$TASK_CMD_CORE_DL_FAIL"
return 1 return 1
;; ;;
*) *)
task_logger "$TASK_CMD_CORE_VERIFY_FAIL" task_logger "$TASK_CMD_CORE_VERIFY_FAIL"
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
return 1 return 1
;; ;;
esac esac
fi fi
} }
update_scripts(){ #自动更新脚本 update_scripts(){ #自动更新脚本
#检查版本 #检查版本
check_update version check_update version
if [ -z "$versionsh" -o "$versionsh" = "versionsh_l" ];then if [ -z "$versionsh" -o "$versionsh" = "versionsh_l" ];then
task_logger "$TASK_CMD_SCRIPT_SKIP" task_logger "$TASK_CMD_SCRIPT_SKIP"
return 0 return 0
else else
get_bin "$TMPDIR"/ShellCrash.tar.gz "ShellCrash.tar.gz" get_bin "$TMPDIR"/ShellCrash.tar.gz "ShellCrash.tar.gz"
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
rm -rf "$TMPDIR"/ShellCrash.tar.gz rm -rf "$TMPDIR"/ShellCrash.tar.gz
task_logger "$TASK_CMD_CORE_DL_FAIL" task_logger "$TASK_CMD_CORE_DL_FAIL"
return 1 return 1
else else
#停止服务 #停止服务
"$CRASHDIR"/start.sh stop "$CRASHDIR"/start.sh stop
#解压 #解压
tar -zxf "$TMPDIR"/ShellCrash.tar.gz ${tar_para} -C "$CRASHDIR"/ tar -zxf "$TMPDIR"/ShellCrash.tar.gz ${tar_para} -C "$CRASHDIR"/
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
rm -rf "$TMPDIR"/ShellCrash.tar.gz rm -rf "$TMPDIR"/ShellCrash.tar.gz
task_logger "$TASK_CMD_SCRIPT_UNZIP_FAIL" task_logger "$TASK_CMD_SCRIPT_UNZIP_FAIL"
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
return 1 return 1
else else
. "$CRASHDIR"/init.sh >/dev/null . "$CRASHDIR"/init.sh >/dev/null
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
return 0 return 0
fi fi
fi fi
fi fi
} }
update_mmdb(){ #自动更新数据库 update_mmdb(){ #自动更新数据库
getgeo(){ getgeo(){
#检查版本 #检查版本
check_update bin/version check_update bin/version
geo_v="$(echo $2 | awk -F "." '{print $1}')_v" #获取版本号类型比如Country_v geo_v="$(echo $2 | awk -F "." '{print $1}')_v" #获取版本号类型比如Country_v
geo_v_new=$GeoIP_v geo_v_new=$GeoIP_v
geo_v_now=$(eval echo \$$geo_v) geo_v_now=$(eval echo \$$geo_v)
if [ -z "$geo_v_new" -o "$geo_v_new" = "$geo_v_now" ];then if [ -z "$geo_v_new" -o "$geo_v_new" = "$geo_v_now" ];then
task_logger "$TASK_CMD_DB_SKIP_PREFIX$2$TASK_CMD_DB_SKIP_SUFFIX" task_logger "$TASK_CMD_DB_SKIP_PREFIX$2$TASK_CMD_DB_SKIP_SUFFIX"
else else
#更新文件 #更新文件
get_bin "$TMPDIR"/$1 "bin/geodata/$2" get_bin "$TMPDIR"/$1 "bin/geodata/$2"
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
task_logger "$TASK_CMD_DB_DL_FAIL_PREFIX$2$TASK_CMD_DB_DL_FAIL_SUFFIX" task_logger "$TASK_CMD_DB_DL_FAIL_PREFIX$2$TASK_CMD_DB_DL_FAIL_SUFFIX"
rm -rf "$TMPDIR"/$1 rm -rf "$TMPDIR"/$1
else else
mv -f "$TMPDIR"/$1 "$BINDIR"/$1 mv -f "$TMPDIR"/$1 "$BINDIR"/$1
setconfig $geo_v $GeoIP_v setconfig $geo_v $GeoIP_v
task_logger "$TASK_CMD_DB_OK_PREFIX$2$TASK_CMD_DB_OK_SUFFIX" task_logger "$TASK_CMD_DB_OK_PREFIX$2$TASK_CMD_DB_OK_SUFFIX"
fi fi
fi fi
} }
[ -n "${cn_mini_v}" -a -s "$CRASHDIR"/Country.mmdb ] && getgeo Country.mmdb cn_mini.mmdb [ -n "${cn_mini_v}" -a -s "$CRASHDIR"/Country.mmdb ] && getgeo Country.mmdb cn_mini.mmdb
[ -n "${china_ip_list_v}" -a -s "$CRASHDIR"/cn_ip.txt ] && getgeo cn_ip.txt china_ip_list.txt [ -n "${china_ip_list_v}" -a -s "$CRASHDIR"/cn_ip.txt ] && getgeo cn_ip.txt china_ip_list.txt
[ -n "${china_ipv6_list_v}" -a -s "$CRASHDIR"/cn_ipv6.txt ] && getgeo cn_ipv6.txt china_ipv6_list.txt [ -n "${china_ipv6_list_v}" -a -s "$CRASHDIR"/cn_ipv6.txt ] && getgeo cn_ipv6.txt china_ipv6_list.txt
[ -n "${geosite_v}" -a -s "$CRASHDIR"/GeoSite.dat ] && getgeo GeoSite.dat geosite.dat [ -n "${geosite_v}" -a -s "$CRASHDIR"/GeoSite.dat ] && getgeo GeoSite.dat geosite.dat
[ -n "${geoip_cn_v}" -a -s "$CRASHDIR"/geoip.db ] && getgeo geoip.db geoip_cn.db [ -n "${geoip_cn_v}" -a -s "$CRASHDIR"/geoip.db ] && getgeo geoip.db geoip_cn.db
[ -n "${geosite_cn_v}" -a -s "$CRASHDIR"/geosite.db ] && getgeo geosite.db geosite_cn.db [ -n "${geosite_cn_v}" -a -s "$CRASHDIR"/geosite.db ] && getgeo geosite.db geosite_cn.db
return 0 return 0
} }
reset_firewall(){ #重设透明路由防火墙 reset_firewall(){ #重设透明路由防火墙
"$CRASHDIR"/start.sh stop_firewall "$CRASHDIR"/start.sh stop_firewall
"$CRASHDIR"/start.sh afstart "$CRASHDIR"/start.sh afstart
} }
ntp(){ ntp(){
ckcmd ntpd && ntpd -n -q -p 203.107.6.88 >/dev/null 2>&1 || exit 0 ckcmd ntpd && ntpd -n -q -p 203.107.6.88 >/dev/null 2>&1 || exit 0
} }
web_save_auto(){ web_save_auto(){
. "$CRASHDIR"/libs/web_save.sh && web_save . "$CRASHDIR"/libs/web_save.sh && web_save
} }
update_config() { #更新订阅并重启 update_config() { #更新订阅并重启
. "$CRASHDIR"/starts/core_config.sh && get_core_config && "$CRASHDIR"/start.sh start . "$CRASHDIR"/starts/core_config.sh && get_core_config && "$CRASHDIR"/start.sh start
@@ -139,14 +139,14 @@ hotupdate() { #热更新订阅
} }
case "$1" in case "$1" in
[1-9][0-9][0-9]) [1-9][0-9][0-9])
task_command=$(cat "$CRASHDIR"/task/task.list "$CRASHDIR"/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}') task_command=$(cat "$CRASHDIR"/task/task.list "$CRASHDIR"/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}')
task_name=$(cat "$CRASHDIR"/task/task.list "$CRASHDIR"/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}') task_name=$(cat "$CRASHDIR"/task/task.list "$CRASHDIR"/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}')
#task_logger "任务$task_name 开始执行" #task_logger "任务$task_name 开始执行"
eval $task_command && task_res="$TASK_CMD_RES_OK" || task_res="$TASK_CMD_RES_FAIL" eval $task_command && task_res="$TASK_CMD_RES_OK" || task_res="$TASK_CMD_RES_FAIL"
task_logger "$TASK_CMD_EXEC_PREFIX$2$TASK_CMD_EXEC_MID$task_res" task_logger "$TASK_CMD_EXEC_PREFIX$2$TASK_CMD_EXEC_MID$task_res"
;; ;;
*) *)
"$1" "$1"
;; ;;
esac esac

View File

@@ -16,20 +16,20 @@
. "$CRASHDIR"/libs/web_save.sh . "$CRASHDIR"/libs/web_save.sh
#特殊脚本 #特殊脚本
bfstart(){ bfstart(){
"$CRASHDIR"/starts/bfstart.sh "$CRASHDIR"/starts/bfstart.sh
} }
afstart(){ afstart(){
"$CRASHDIR"/starts/afstart.sh "$CRASHDIR"/starts/afstart.sh
} }
stop_firewall(){ stop_firewall(){
"$CRASHDIR"/starts/fw_stop.sh "$CRASHDIR"/starts/fw_stop.sh
} }
#保守模式启动 #保守模式启动
start_l(){ start_l(){
bfstart && { bfstart && {
. "$CRASHDIR"/starts/start_legacy.sh . "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$COMMAND" 'shellcrash' start_legacy "$COMMAND" 'shellcrash'
} && afstart & } && afstart &
} }
case "$1" in case "$1" in
@@ -37,26 +37,26 @@ case "$1" in
start) start)
[ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例 [ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例
stop_firewall #清理路由策略 stop_firewall #清理路由策略
rm -f "$CRASHDIR"/\.start_error #移除自启失败标记 rm -f "$CRASHDIR"/\.start_error #移除自启失败标记
#使用不同方式启动服务 #使用不同方式启动服务
if [ "$firewall_area" = "5" ]; then #主旁转发 if [ "$firewall_area" = "5" ]; then #主旁转发
. "$CRASHDIR"/starts/fw_start.sh . "$CRASHDIR"/starts/fw_start.sh
elif [ "$start_old" = "ON" ]; then elif [ "$start_old" = "ON" ]; then
start_l start_l
elif [ -f /etc/rc.common ] && grep -q 'procd' /proc/1/comm; then elif [ -f /etc/rc.common ] && grep -q 'procd' /proc/1/comm; then
/etc/init.d/shellcrash start /etc/init.d/shellcrash start
elif [ "$USER" = "root" ] && grep -q 'systemd' /proc/1/comm; then elif [ "$USER" = "root" ] && grep -q 'systemd' /proc/1/comm; then
FragmentPath=$(systemctl show -p FragmentPath shellcrash | sed 's/FragmentPath=//') FragmentPath=$(systemctl show -p FragmentPath shellcrash | sed 's/FragmentPath=//')
[ -f "$FragmentPath" ] && { [ -f "$FragmentPath" ] && {
sed -i "s#^ExecStart=.*#ExecStart=$COMMAND >/dev/null#" "$FragmentPath" sed -i "s#^ExecStart=.*#ExecStart=$COMMAND >/dev/null#" "$FragmentPath"
systemctl daemon-reload systemctl daemon-reload
} }
systemctl start shellcrash.service || . "$CRASHDIR"/starts/start_error.sh systemctl start shellcrash.service || . "$CRASHDIR"/starts/start_error.sh
elif grep -q 's6' /proc/1/comm; then elif grep -q 's6' /proc/1/comm; then
bfstart && /command/s6-svc -u /run/service/shellcrash && { bfstart && /command/s6-svc -u /run/service/shellcrash && {
[ ! -f "$CRASHDIR"/.dis_startup ] && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart [ ! -f "$CRASHDIR"/.dis_startup ] && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
afstart & afstart &
} }
elif rc-status -r >/dev/null 2>&1; then elif rc-status -r >/dev/null 2>&1; then
rc-service shellcrash stop >/dev/null 2>&1 rc-service shellcrash stop >/dev/null 2>&1
rc-service shellcrash start rc-service shellcrash start
@@ -68,9 +68,9 @@ stop)
logger ShellCrash服务即将关闭...... logger ShellCrash服务即将关闭......
[ -n "$(pidof CrashCore)" ] && web_save #保存面板配置 [ -n "$(pidof CrashCore)" ] && web_save #保存面板配置
#清理定时任务 #清理定时任务
cronload | grep -vE '^$|start_legacy_wd.sh|运行时每' > "$TMPDIR"/cron_tmp cronload | grep -vE '^$|start_legacy_wd.sh|运行时每' > "$TMPDIR"/cron_tmp
cronadd "$TMPDIR"/cron_tmp cronadd "$TMPDIR"/cron_tmp
rm -f "$TMPDIR"/cron_tmp rm -f "$TMPDIR"/cron_tmp
#停止tg_bot #停止tg_bot
. "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop
#多种方式结束进程 #多种方式结束进程
@@ -83,8 +83,8 @@ stop)
elif [ -f /etc/rc.common ] && grep -q 'procd' /proc/1/comm; then elif [ -f /etc/rc.common ] && grep -q 'procd' /proc/1/comm; then
/etc/init.d/shellcrash stop >/dev/null 2>&1 /etc/init.d/shellcrash stop >/dev/null 2>&1
elif grep -q 's6' /proc/1/comm; then elif grep -q 's6' /proc/1/comm; then
/command/s6-svc -d /run/service/shellcrash /command/s6-svc -d /run/service/shellcrash
stop_firewall stop_firewall
elif rc-status -r >/dev/null 2>&1; then elif rc-status -r >/dev/null 2>&1; then
rc-service shellcrash stop >/dev/null 2>&1 rc-service shellcrash stop >/dev/null 2>&1
else else

View File

@@ -12,45 +12,45 @@
[ -z "$firewall_area" ] && firewall_area=1 [ -z "$firewall_area" ] && firewall_area=1
#延迟启动 #延迟启动
[ ! -f "$TMPDIR"/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { [ ! -f "$TMPDIR"/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && {
logger "ShellCrash将延迟$start_delay秒启动" 31 logger "ShellCrash将延迟$start_delay秒启动" 31
sleep "$start_delay" sleep "$start_delay"
} }
#设置循环检测面板端口以判定服务启动是否成功 #设置循环检测面板端口以判定服务启动是否成功
. "$CRASHDIR"/libs/start_wait.sh . "$CRASHDIR"/libs/start_wait.sh
if [ -n "$test" -o -n "$(pidof CrashCore)" ]; then if [ -n "$test" -o -n "$(pidof CrashCore)" ]; then
[ "$start_old" = "ON" ] && [ ! -L "$TMPDIR"/CrashCore ] && rm -f "$TMPDIR"/CrashCore #删除缓存目录内核文件 [ "$start_old" = "ON" ] && [ ! -L "$TMPDIR"/CrashCore ] && rm -f "$TMPDIR"/CrashCore #删除缓存目录内核文件
. "$CRASHDIR"/starts/fw_start.sh #配置防火墙流量劫持 . "$CRASHDIR"/starts/fw_start.sh #配置防火墙流量劫持
date +%s >"$TMPDIR"/crash_start_time #标记启动时间 date +%s >"$TMPDIR"/crash_start_time #标记启动时间
#后台还原面板配置 #后台还原面板配置
[ -s "$CRASHDIR"/configs/web_save ] && { [ -s "$CRASHDIR"/configs/web_save ] && {
. "$CRASHDIR"/libs/web_restore.sh . "$CRASHDIR"/libs/web_restore.sh
web_restore >/dev/null 2>&1 & web_restore >/dev/null 2>&1 &
} }
#推送日志 #推送日志
{ {
sleep 5 sleep 5
logger ShellCrash服务已启动 logger ShellCrash服务已启动
} & } &
ckcmd mtd_storage.sh && mtd_storage.sh save >/dev/null 2>&1 #Padavan保存/etc/storage ckcmd mtd_storage.sh && mtd_storage.sh save >/dev/null 2>&1 #Padavan保存/etc/storage
#加载定时任务 #加载定时任务
cronload | grep -v '^$' > "$TMPDIR"/cron_tmp cronload | grep -v '^$' > "$TMPDIR"/cron_tmp
[ -s "$CRASHDIR"/task/cron ] && cat "$CRASHDIR"/task/cron >> "$TMPDIR"/cron_tmp [ -s "$CRASHDIR"/task/cron ] && cat "$CRASHDIR"/task/cron >> "$TMPDIR"/cron_tmp
[ -s "$CRASHDIR"/task/running ] && cat "$CRASHDIR"/task/running >> "$TMPDIR"/cron_tmp [ -s "$CRASHDIR"/task/running ] && cat "$CRASHDIR"/task/running >> "$TMPDIR"/cron_tmp
[ "$bot_tg_service" = ON ] && echo "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh bot_tg #ShellCrash-TG_BOT守护进程" >> "$TMPDIR"/cron_tmp [ "$bot_tg_service" = ON ] && echo "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh bot_tg #ShellCrash-TG_BOT守护进程" >> "$TMPDIR"/cron_tmp
[ "$start_old" = ON ] && echo "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh shellcrash #ShellCrash保守模式守护进程" >> "$TMPDIR"/cron_tmp [ "$start_old" = ON ] && echo "* * * * * /bin/sh $CRASHDIR/starts/start_legacy_wd.sh shellcrash #ShellCrash保守模式守护进程" >> "$TMPDIR"/cron_tmp
awk '!x[$0]++' "$TMPDIR"/cron_tmp > "$TMPDIR"/cron_tmp2 #删除重复行 awk '!x[$0]++' "$TMPDIR"/cron_tmp > "$TMPDIR"/cron_tmp2 #删除重复行
cronadd "$TMPDIR"/cron_tmp2 cronadd "$TMPDIR"/cron_tmp2
rm -f "$TMPDIR"/cron_tmp "$TMPDIR"/cron_tmp2 rm -f "$TMPDIR"/cron_tmp "$TMPDIR"/cron_tmp2
#加载条件任务 #加载条件任务
[ -s "$CRASHDIR"/task/afstart ] && { . "$CRASHDIR"/task/afstart; } & [ -s "$CRASHDIR"/task/afstart ] && { . "$CRASHDIR"/task/afstart; } &
[ -s "$CRASHDIR"/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && { [ -s "$CRASHDIR"/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && {
#注入防火墙 #注入防火墙
line=$(grep -En "fw.* restart" /etc/init.d/firewall | cut -d ":" -f 1) line=$(grep -En "fw.* restart" /etc/init.d/firewall | cut -d ":" -f 1)
sed -i.bak "${line}a\\. $CRASHDIR/task/affirewall" /etc/init.d/firewall sed -i.bak "${line}a\\. $CRASHDIR/task/affirewall" /etc/init.d/firewall
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
} & } &
exit 0 exit 0
else else
. "$CRASHDIR"/starts/start_error.sh . "$CRASHDIR"/starts/start_error.sh
fi fi

View File

@@ -38,8 +38,8 @@ makehtml() { #生成面板跳转文件
<body> <body>
<div style="text-align: center; margin-top: 50px;"> <div style="text-align: center; margin-top: 50px;">
<h1>您还未安装本地面板</h1> <h1>您还未安装本地面板</h1>
<h3>请在脚本更新功能中(9-4)安装<br>或者使用在线面板:</h3> <h3>请在脚本更新功能中(9-4)安装<br>或者使用在线面板:</h3>
<h4>请复制当前地址/ui(不包括)前面的内容填入url位置即可连接</h3> <h4>请复制当前地址/ui(不包括)前面的内容填入url位置即可连接</h3>
<a href="http://board.zash.run.place" style="font-size: 24px;">Zashboard面板(推荐)<br></a> <a href="http://board.zash.run.place" style="font-size: 24px;">Zashboard面板(推荐)<br></a>
<a style="font-size: 21px;"><br>如已安装请使用Ctrl+F5强制刷新此页面<br></a> <a style="font-size: 21px;"><br>如已安装请使用Ctrl+F5强制刷新此页面<br></a>
</div> </div>
@@ -54,19 +54,19 @@ catpac() { #生成pac文件
[ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
cat >"$TMPDIR"/shellcrash_pac <<EOF cat >"$TMPDIR"/shellcrash_pac <<EOF
function FindProxyForURL(url, host) { function FindProxyForURL(url, host) {
if ( if (
isInNet(host, "0.0.0.0", "255.0.0.0")|| isInNet(host, "0.0.0.0", "255.0.0.0")||
isInNet(host, "10.0.0.0", "255.0.0.0")|| isInNet(host, "10.0.0.0", "255.0.0.0")||
isInNet(host, "127.0.0.0", "255.0.0.0")|| isInNet(host, "127.0.0.0", "255.0.0.0")||
isInNet(host, "224.0.0.0", "224.0.0.0")|| isInNet(host, "224.0.0.0", "224.0.0.0")||
isInNet(host, "240.0.0.0", "240.0.0.0")|| isInNet(host, "240.0.0.0", "240.0.0.0")||
isInNet(host, "172.16.0.0", "255.240.0.0")|| isInNet(host, "172.16.0.0", "255.240.0.0")||
isInNet(host, "192.168.0.0", "255.255.0.0")|| isInNet(host, "192.168.0.0", "255.255.0.0")||
isInNet(host, "169.254.0.0", "255.255.0.0") isInNet(host, "169.254.0.0", "255.255.0.0")
) )
return "DIRECT"; return "DIRECT";
else else
return "PROXY $host_pac:$mix_port; DIRECT; SOCKS5 $host_pac:$mix_port" return "PROXY $host_pac:$mix_port; DIRECT; SOCKS5 $host_pac:$mix_port"
} }
EOF EOF
compare "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac compare "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac
@@ -82,61 +82,61 @@ EOF
[ -s "$CRASHDIR"/task/bfstart ] && . "$CRASHDIR"/task/bfstart [ -s "$CRASHDIR"/task/bfstart ] && . "$CRASHDIR"/task/bfstart
#检查内核配置文件 #检查内核配置文件
if [ ! -f "$core_config" ]; then if [ ! -f "$core_config" ]; then
if [ -n "$Url" -o -n "$Https" ]; then if [ -n "$Url" -o -n "$Https" ]; then
logger "未找到配置文件,正在下载!" 33 logger "未找到配置文件,正在下载!" 33
. "$CRASHDIR"/starts/core_config.sh && get_core_config . "$CRASHDIR"/starts/core_config.sh && get_core_config
else else
logger "未找到配置文件链接,请先导入配置文件!" 31 logger "未找到配置文件链接,请先导入配置文件!" 31
exit 1 exit 1
fi fi
fi fi
#检查dashboard文件 #检查dashboard文件
if [ -f "$CRASHDIR"/ui/CNAME -a ! -f "$BINDIR"/ui/CNAME ]; then if [ -f "$CRASHDIR"/ui/CNAME -a ! -f "$BINDIR"/ui/CNAME ]; then
cp -rf "$CRASHDIR"/ui "$BINDIR" cp -rf "$CRASHDIR"/ui "$BINDIR"
fi fi
[ ! -s "$BINDIR"/ui/index.html ] && makehtml #如没有面板则创建跳转界面 [ ! -s "$BINDIR"/ui/index.html ] && makehtml #如没有面板则创建跳转界面
catpac #生成pac文件 catpac #生成pac文件
#内核及内核配置文件检查 #内核及内核配置文件检查
[ "$CRASHDIR" != "$BINDIR" ] && { [ "$CRASHDIR" != "$BINDIR" ] && {
mkdir -p "$BINDIR"/providers mkdir -p "$BINDIR"/providers
ln -sf "$CRASHDIR"/providers/* "$BINDIR"/providers/ ln -sf "$CRASHDIR"/providers/* "$BINDIR"/providers/
} }
if echo "$crashcore" | grep -q 'singbox'; then if echo "$crashcore" | grep -q 'singbox'; then
. "$CRASHDIR"/starts/singbox_check.sh && singbox_check . "$CRASHDIR"/starts/singbox_check.sh && singbox_check
[ -d "$TMPDIR"/jsons ] && rm -rf "$TMPDIR"/jsons/* || mkdir -p "$TMPDIR"/jsons #准备目录 [ -d "$TMPDIR"/jsons ] && rm -rf "$TMPDIR"/jsons/* || mkdir -p "$TMPDIR"/jsons #准备目录
if [ "$disoverride" != "1" ];then if [ "$disoverride" != "1" ];then
. "$CRASHDIR"/starts/singbox_modify.sh && modify_json . "$CRASHDIR"/starts/singbox_modify.sh && modify_json
else else
ln -sf "$core_config" "$TMPDIR"/jsons/config.json ln -sf "$core_config" "$TMPDIR"/jsons/config.json
fi fi
else else
. "$CRASHDIR"/starts/clash_check.sh && clash_check . "$CRASHDIR"/starts/clash_check.sh && clash_check
if [ "$disoverride" != "1" ];then if [ "$disoverride" != "1" ];then
. "$CRASHDIR"/starts/clash_modify.sh && modify_yaml . "$CRASHDIR"/starts/clash_modify.sh && modify_yaml
else else
ln -sf "$core_config" "$TMPDIR"/config.yaml ln -sf "$core_config" "$TMPDIR"/config.yaml
fi fi
fi fi
#检查下载cnip绕过相关文件 #检查下载cnip绕过相关文件
[ "$cn_ip_route" = "ON" ] && [ "$dns_mod" != "fake-ip" ] && { [ "$cn_ip_route" = "ON" ] && [ "$dns_mod" != "fake-ip" ] && {
[ "$firewall_mod" = nftables ] || ckcmd ipset && { [ "$firewall_mod" = nftables ] || ckcmd ipset && {
. "$CRASHDIR"/starts/check_cnip.sh . "$CRASHDIR"/starts/check_cnip.sh
ck_cn_ipv4 ck_cn_ipv4
[ "$ipv6_redir" = "ON" ] && ck_cn_ipv6 [ "$ipv6_redir" = "ON" ] && ck_cn_ipv6
} }
} }
#添加shellcrash用户 #添加shellcrash用户
[ "$firewall_area" = 2 ] || [ "$firewall_area" = 3 ] || [ "$(cat /proc/1/comm)" = "systemd" ] && [ "$firewall_area" = 2 ] || [ "$firewall_area" = 3 ] || [ "$(cat /proc/1/comm)" = "systemd" ] &&
[ -z "$(id shellcrash 2>/dev/null | grep 'root')" ] && { [ -z "$(id shellcrash 2>/dev/null | grep 'root')" ] && {
ckcmd userdel && userdel shellcrash 2>/dev/null ckcmd userdel && userdel shellcrash 2>/dev/null
sed -i '/0:7890/d' /etc/passwd sed -i '/0:7890/d' /etc/passwd
sed -i '/x:7890/d' /etc/group sed -i '/x:7890/d' /etc/group
if ckcmd useradd; then if ckcmd useradd; then
useradd shellcrash -u 7890 useradd shellcrash -u 7890
sed -Ei s/7890:7890/0:7890/g /etc/passwd sed -Ei s/7890:7890/0:7890/g /etc/passwd
else else
echo "shellcrash:x:0:7890:::" >>/etc/passwd echo "shellcrash:x:0:7890:::" >>/etc/passwd
fi fi
} }
#加载系统内核组件 #加载系统内核组件
[ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && ckcmd modprobe && modprobe tun 2>/dev/null [ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && ckcmd modprobe && modprobe tun 2>/dev/null

View File

@@ -5,7 +5,7 @@
check_core() { #检查及下载内核文件 check_core() { #检查及下载内核文件
[ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容 [ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容
[ -z "$(find "$TMPDIR"/CrashCore $find_para 2>/dev/null)" ] && core_find [ -z "$(find "$TMPDIR"/CrashCore $find_para 2>/dev/null)" ] && core_find
[ ! -f "$TMPDIR"/CrashCore ] && { [ ! -f "$TMPDIR"/CrashCore ] && {
logger "未找到【$crashcore】核心,正在下载!" 33 logger "未找到【$crashcore】核心,正在下载!" 33
[ -z "$cpucore" ] && . "$CRASHDIR"/libs/check_cpucore.sh && check_cpucore [ -z "$cpucore" ] && . "$CRASHDIR"/libs/check_cpucore.sh && check_cpucore

View File

@@ -16,15 +16,15 @@ modify_yaml() {
#Meta内核专属配置 #Meta内核专属配置
[ "$crashcore" = 'meta' ] && { [ "$crashcore" = 'meta' ] && {
[ -z "$(grep 'PROCESS' "$CRASHDIR"/yamls/*.yaml)" ] && find_process='find-process-mode: "off"' [ -z "$(grep 'PROCESS' "$CRASHDIR"/yamls/*.yaml)" ] && find_process='find-process-mode: "off"'
#ecs优化 #ecs优化
[ "$ecs_subnet" = ON ] && { [ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh . "$CRASHDIR"/libs/get_ecsip.sh
if [ -n "$ecs_address" ];then if [ -n "$ecs_address" ];then
dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||') dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||')
else else
logger "自动获取ecs网段失败" logger "自动获取ecs网段失败"
fi fi
} }
} }
#dns配置 #dns配置
[ -z "$(cat "$CRASHDIR"/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && { [ -z "$(cat "$CRASHDIR"/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && {
@@ -100,17 +100,17 @@ EOF
if [ "$crashcore" = "meta" ]; then if [ "$crashcore" = "meta" ]; then
echo " 'services.googleapis.cn': services.googleapis.com" >>"$TMPDIR"/hosts.yaml echo " 'services.googleapis.cn': services.googleapis.com" >>"$TMPDIR"/hosts.yaml
fi fi
#加载本机hosts #加载本机hosts
sys_hosts=/etc/hosts sys_hosts=/etc/hosts
[ -f /data/etc/custom_hosts ] && sys_hosts='/etc/hosts /data/etc/custom_hosts' [ -f /data/etc/custom_hosts ] && sys_hosts='/etc/hosts /data/etc/custom_hosts'
cat $sys_hosts | while read line; do cat $sys_hosts | while read line; do
[ -n "$(echo "$line" | grep -oE "([0-9]{1,3}[\.]){3}")" ] && [ -n "$(echo "$line" | grep -oE "([0-9]{1,3}[\.]){3}")" ] &&
[ -z "$(echo "$line" | grep -oE '^#')" ] && [ -z "$(echo "$line" | grep -oE '^#')" ] &&
hosts_ip=$(echo $line | awk '{print $1}') && hosts_ip=$(echo $line | awk '{print $1}') &&
hosts_domain=$(echo $line | awk '{print $2}') && hosts_domain=$(echo $line | awk '{print $2}') &&
[ -z "$(cat "$TMPDIR"/hosts.yaml | grep -oE "$hosts_domain")" ] && [ -z "$(cat "$TMPDIR"/hosts.yaml | grep -oE "$hosts_domain")" ] &&
echo " '$hosts_domain': $hosts_ip" >>"$TMPDIR"/hosts.yaml echo " '$hosts_domain': $hosts_ip" >>"$TMPDIR"/hosts.yaml
done done
fi fi
#分割配置文件 #分割配置文件
yaml_char='proxies proxy-groups proxy-providers rules rule-providers sub-rules listeners' yaml_char='proxies proxy-groups proxy-providers rules rule-providers sub-rules listeners'
@@ -172,10 +172,10 @@ EOF
done done
} }
#添加自定义入站 #添加自定义入站
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && { [ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg . "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/meta_listeners.sh . "$CRASHDIR"/libs/meta_listeners.sh
} }
#节点绕过功能支持 #节点绕过功能支持
sed -i "/#节点绕过/d" "$TMPDIR"/rules.yaml sed -i "/#节点绕过/d" "$TMPDIR"/rules.yaml
[ "$proxies_bypass" = "ON" ] && { [ "$proxies_bypass" = "ON" ] && {

View File

@@ -31,19 +31,19 @@ get_core_config() { #下载内核配置文件
Server_ua=$(grep -aE '^4' "$CRASHDIR"/configs/servers.list | sed -n ""$server_link"p" | awk '{print $4}') Server_ua=$(grep -aE '^4' "$CRASHDIR"/configs/servers.list | sed -n ""$server_link"p" | awk '{print $4}')
Config=$(grep -aE '^5' "$CRASHDIR"/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}') Config=$(grep -aE '^5' "$CRASHDIR"/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}')
gen_ua gen_ua
#如果传来的是Url链接则合成Https链接否则直接使用Https链接 #如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ]; then if [ -z "$Https" ]; then
#Urlencord转码处理保留字符 #Urlencord转码处理保留字符
if ckcmd hexdump;then if ckcmd hexdump;then
Url=$(echo $Url | sed 's/%26/\&/g') #处理分隔符 Url=$(echo $Url | sed 's/%26/\&/g') #处理分隔符
urlencodeUrl="exclude=$(urlencode "$exclude")&include=$(urlencode "$include")&url=$(urlencode "$Url")&config=$(urlencode "$Config")" urlencodeUrl="exclude=$(urlencode "$exclude")&include=$(urlencode "$include")&url=$(urlencode "$Url")&config=$(urlencode "$Config")"
else else
urlencodeUrl="exclude=$exclude&include=$include&url=$Url&config=$Config" urlencodeUrl="exclude=$exclude&include=$include&url=$Url&config=$Config"
fi fi
Https="${Server}/sub?target=${target}&${Server_ua}=${user_agent}&insert=true&new_name=true&scv=true&udp=true&${urlencodeUrl}" Https="${Server}/sub?target=${target}&${Server_ua}=${user_agent}&insert=true&new_name=true&scv=true&udp=true&${urlencodeUrl}"
url_type=true url_type=true
else else
Https=$(echo $Https | sed 's/\\&/\&/g') #还原转义 Https=$(echo $Https | sed 's/\\&/\&/g') #还原转义
fi fi
#输出 #输出
echo "-----------------------------------------------" echo "-----------------------------------------------"
@@ -92,7 +92,7 @@ get_core_config() { #下载内核配置文件
else else
. "$CRASHDIR"/starts/clash_config_check.sh . "$CRASHDIR"/starts/clash_config_check.sh
fi fi
check_config check_config
#如果不同则备份并替换文件 #如果不同则备份并替换文件
if [ -s "$core_config" ]; then if [ -s "$core_config" ]; then
compare "$core_config_new" "$core_config" compare "$core_config_new" "$core_config"

View File

@@ -9,17 +9,17 @@ getlanip() { #获取局域网host地址
[ -n "$host_ipv4" -a -n "$host_ipv6" ] && break [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break
sleep 1 && i=$((i + 1)) sleep 1 && i=$((i + 1))
done done
#Tailscale #Tailscale
[ "$ts_service" = ON ] && { [ "$ts_service" = ON ] && {
ts_host_ipv4=' 100.64.0.0/10' ts_host_ipv4=' 100.64.0.0/10'
ts_host_ipv6=' fd7a:115c:a1e0::/48' ts_host_ipv6=' fd7a:115c:a1e0::/48'
} }
#Wireguard #Wireguard
[ "$wg_service" = ON ] && { [ "$wg_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg . "$CRASHDIR"/configs/gateway.cfg
wg_host_ipv4=' $wg_ipv4' wg_host_ipv4=' $wg_ipv4'
[ -n "$wg_ipv6" ] && wg_host_ipv6=' $wg_ipv6' [ -n "$wg_ipv6" ] && wg_host_ipv6=' $wg_ipv6'
} }
#添加自定义ipv4局域网网段 #添加自定义ipv4局域网网段
if [ "$replace_default_host_ipv4" == "ON" ]; then if [ "$replace_default_host_ipv4" == "ON" ]; then
host_ipv4="$cust_host_ipv4" host_ipv4="$cust_host_ipv4"
@@ -28,9 +28,9 @@ getlanip() { #获取局域网host地址
fi fi
#缺省配置 #缺省配置
[ -z "$host_ipv4" ] && { [ -z "$host_ipv4" ] && {
host_ipv4='192.168.0.0/16 10.0.0.0/12 172.16.0.0/12' host_ipv4='192.168.0.0/16 10.0.0.0/12 172.16.0.0/12'
logger "无法获取本地LAN-IPV4网段请前往流量过滤设置界面设置自定义网段" 31 logger "无法获取本地LAN-IPV4网段请前往流量过滤设置界面设置自定义网段" 31
} }
host_ipv6="fe80::/10 fd00::/8 $host_ipv6$ts_host_ipv6$wg_host_ipv6" host_ipv6="fe80::/10 fd00::/8 $host_ipv6$ts_host_ipv6$wg_host_ipv6"
#获取本机出口IP地址 #获取本机出口IP地址
local_ipv4=$(ip route 2>&1 | grep -Ev 'utun|iot|docker|linkdown' | grep -Eo 'src.*' | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u) local_ipv4=$(ip route 2>&1 | grep -Ev 'utun|iot|docker|linkdown' | grep -Eo 'src.*' | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort -u)

View File

@@ -3,7 +3,7 @@
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
start_ipt_route() { #iptables-route通用工具 start_ipt_route() { #iptables-route通用工具
#$1:iptables/ip6tables $2:所在的表(nat/mangle) $3:所在的链(OUTPUT/PREROUTING) $4:新创建的shellcrash链表 $5:tcp/udp/all #$1:iptables/ip6tables $2:所在的表(nat/mangle) $3:所在的链(OUTPUT/PREROUTING) $4:新创建的shellcrash链表 $5:tcp/udp/all
#区分ipv4/ipv6 #区分ipv4/ipv6
@@ -32,9 +32,9 @@ start_ipt_route() { #iptables-route通用工具
done done
[ "$firewall_area" = 5 ] && "$1" $w -t "$2" -A "$4" -s $bypass_host -j RETURN [ "$firewall_area" = 5 ] && "$1" $w -t "$2" -A "$4" -s $bypass_host -j RETURN
[ -z "$ports" ] && { [ -z "$ports" ] && {
"$1" $w -t "$2" -A "$4" -p tcp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN "$1" $w -t "$2" -A "$4" -p tcp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN
"$1" $w -t "$2" -A "$4" -p udp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN "$1" $w -t "$2" -A "$4" -p udp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN
} }
#跳过目标保留地址及目标本机网段 #跳过目标保留地址及目标本机网段
for ip in $HOST_IP $RESERVED_IP; do for ip in $HOST_IP $RESERVED_IP; do
"$1" $w -t "$2" -A "$4" -d $ip -j RETURN "$1" $w -t "$2" -A "$4" -d $ip -j RETURN
@@ -136,35 +136,35 @@ start_ipt_dns() { #iptables-dns通用工具
"$1" $w -t nat -I "$2" -p udp --dport 53 -j "$3" "$1" $w -t nat -I "$2" -p udp --dport 53 -j "$3"
} }
start_ipt_wan() { #iptables公网防火墙 start_ipt_wan() { #iptables公网防火墙
ipt_wan_accept(){ ipt_wan_accept(){
$iptable -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT $iptable -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT
ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT
} }
ipt_wan_reject(){ ipt_wan_reject(){
$iptable -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT $iptable -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT
ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT
} }
#端口拦截 #端口拦截
reject_ports="$mix_port,$db_port" reject_ports="$mix_port,$db_port"
ipt_wan_reject tcp ipt_wan_reject tcp
ipt_wan_reject udp ipt_wan_reject udp
#端口放行 #端口放行
[ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg [ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg
accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//") accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//")
[ -n "$accept_ports" ] && { [ -n "$accept_ports" ] && {
ipt_wan_accept tcp ipt_wan_accept tcp
ipt_wan_accept udp ipt_wan_accept udp
} }
#局域网请求放行 #局域网请求放行
for ip in $host_ipv4; do for ip in $host_ipv4; do
$iptable -I INPUT -s $ip -j ACCEPT $iptable -I INPUT -s $ip -j ACCEPT
done done
ckcmd ip6tables && for ip in $host_ipv6; do ckcmd ip6tables && for ip in $host_ipv6; do
$ip6table -I INPUT -s $ip -j ACCEPT $ip6table -I INPUT -s $ip -j ACCEPT
done done
#本机请求全放行 #本机请求全放行
$iptable -I INPUT -i lo -j ACCEPT $iptable -I INPUT -i lo -j ACCEPT
ckcmd ip6tables && $ip6table -I INPUT -i lo -j ACCEPT ckcmd ip6tables && $ip6table -I INPUT -i lo -j ACCEPT
} }
start_iptables() { #iptables配置总入口 start_iptables() { #iptables配置总入口
#启动公网访问防火墙 #启动公网访问防火墙

View File

@@ -5,24 +5,24 @@ RESERVED_IP=$(echo $reserve_ipv4 | sed 's/[[:space:]]\+/, /g')
RESERVED_IP6=$(echo "$reserve_ipv6 $host_ipv6" | sed 's/[[:space:]]\+/, /g') RESERVED_IP6=$(echo "$reserve_ipv6 $host_ipv6" | sed 's/[[:space:]]\+/, /g')
add_ip6_route(){ add_ip6_route(){
#过滤保留地址及本机地址 #过滤保留地址及本机地址
nft add rule inet shellcrash $1 ip6 daddr {$RESERVED_IP6} return nft add rule inet shellcrash $1 ip6 daddr {$RESERVED_IP6} return
#仅代理本机局域网网段流量 #仅代理本机局域网网段流量
nft add rule inet shellcrash $1 ip6 saddr != {$HOST_IP6} return nft add rule inet shellcrash $1 ip6 saddr != {$HOST_IP6} return
#绕过CN_IPV6 #绕过CN_IPV6
[ "$dns_mod" != "fake-ip" -a "$cn_ip_route" = "ON" -a -f "$BINDIR"/cn_ipv6.txt ] && { [ "$dns_mod" != "fake-ip" -a "$cn_ip_route" = "ON" -a -f "$BINDIR"/cn_ipv6.txt ] && {
CN_IP6=$(awk '{printf "%s, ",$1}' "$BINDIR"/cn_ipv6.txt) CN_IP6=$(awk '{printf "%s, ",$1}' "$BINDIR"/cn_ipv6.txt)
[ -n "$CN_IP6" ] && { [ -n "$CN_IP6" ] && {
nft add set inet shellcrash cn_ip6 { type ipv6_addr \; flags interval \; } nft add set inet shellcrash cn_ip6 { type ipv6_addr \; flags interval \; }
nft add element inet shellcrash cn_ip6 { $CN_IP6 } nft add element inet shellcrash cn_ip6 { $CN_IP6 }
nft add rule inet shellcrash $1 ip6 daddr @cn_ip6 return nft add rule inet shellcrash $1 ip6 daddr @cn_ip6 return
} }
} }
} }
start_nft_route() { #nftables-route通用工具 start_nft_route() { #nftables-route通用工具
#$1:name $2:hook(prerouting/output) $3:type(nat/mangle/filter) $4:priority(-100/-150) #$1:name $2:hook(prerouting/output) $3:type(nat/mangle/filter) $4:priority(-100/-150)
[ "$common_ports" = "ON" ] && PORTS=$(echo $multiport | sed 's/,/, /g') [ "$common_ports" = "ON" ] && PORTS=$(echo $multiport | sed 's/,/, /g')
[ "$1" = 'prerouting' ] && HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g') [ "$1" = 'prerouting' ] && HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g')
[ "$1" = 'output' ] && HOST_IP="127.0.0.0/8, $(echo $local_ipv4 | sed 's/[[:space:]]\+/, /g')" [ "$1" = 'output' ] && HOST_IP="127.0.0.0/8, $(echo $local_ipv4 | sed 's/[[:space:]]\+/, /g')"
[ "$1" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')" [ "$1" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')"
#添加新链 #添加新链
@@ -39,9 +39,9 @@ start_nft_route() { #nftables-route通用工具
#过滤常用端口 #过滤常用端口
[ -n "$PORTS" ] && { [ -n "$PORTS" ] && {
nft add rule inet shellcrash $1 ip daddr != {28.0.0.0/8} tcp dport != {$PORTS} return nft add rule inet shellcrash $1 ip daddr != {28.0.0.0/8} tcp dport != {$PORTS} return
nft add rule inet shellcrash $1 ip daddr != {28.0.0.0/8} udp dport != {$PORTS} return nft add rule inet shellcrash $1 ip daddr != {28.0.0.0/8} udp dport != {$PORTS} return
nft add rule inet shellcrash $1 ip6 daddr != {fc00::/16} tcp dport != {$PORTS} return nft add rule inet shellcrash $1 ip6 daddr != {fc00::/16} tcp dport != {$PORTS} return
nft add rule inet shellcrash $1 ip6 daddr != {fc00::/16} udp dport != {$PORTS} return nft add rule inet shellcrash $1 ip6 daddr != {fc00::/16} udp dport != {$PORTS} return
} }
#nft add rule inet shellcrash $1 ip saddr 28.0.0.0/8 return #nft add rule inet shellcrash $1 ip saddr 28.0.0.0/8 return
nft add rule inet shellcrash $1 ip daddr {$RESERVED_IP} return #过滤保留地址 nft add rule inet shellcrash $1 ip daddr {$RESERVED_IP} return #过滤保留地址
@@ -76,23 +76,23 @@ start_nft_route() { #nftables-route通用工具
[ "$dns_mod" != "fake-ip" -a "$cn_ip_route" = "ON" -a -f "$BINDIR"/cn_ip.txt ] && { [ "$dns_mod" != "fake-ip" -a "$cn_ip_route" = "ON" -a -f "$BINDIR"/cn_ip.txt ] && {
CN_IP=$(awk '{printf "%s, ",$1}' "$BINDIR"/cn_ip.txt) CN_IP=$(awk '{printf "%s, ",$1}' "$BINDIR"/cn_ip.txt)
[ -n "$CN_IP" ] && { [ -n "$CN_IP" ] && {
nft add set inet shellcrash cn_ip { type ipv4_addr \; flags interval \; } nft add set inet shellcrash cn_ip { type ipv4_addr \; flags interval \; }
nft add element inet shellcrash cn_ip { $CN_IP } nft add element inet shellcrash cn_ip { $CN_IP }
nft add rule inet shellcrash $1 ip daddr @cn_ip return nft add rule inet shellcrash $1 ip daddr @cn_ip return
} }
} }
#局域网ipv6支持 #局域网ipv6支持
if [ "$ipv6_redir" = "ON" -a "$1" = 'prerouting' -a "$firewall_area" != 5 ]; then if [ "$ipv6_redir" = "ON" -a "$1" = 'prerouting' -a "$firewall_area" != 5 ]; then
HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g') HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')
add_ip6_route "$1" add_ip6_route "$1"
elif [ "$ipv6_redir" = "ON" -a "$1" = 'output' -a \( "$firewall_area" = 2 -o "$firewall_area" = 3 \) ]; then elif [ "$ipv6_redir" = "ON" -a "$1" = 'output' -a \( "$firewall_area" = 2 -o "$firewall_area" = 3 \) ]; then
HOST_IP6="::1, $(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')" HOST_IP6="::1, $(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')"
add_ip6_route "$1" add_ip6_route "$1"
else else
nft add rule inet shellcrash $1 meta nfproto ipv6 return nft add rule inet shellcrash $1 meta nfproto ipv6 return
fi fi
#屏蔽quic #屏蔽quic
[ "$quic_rj" = 'ON' -a "$lan_proxy" = true ] && nft add rule inet shellcrash $1 udp dport {443, 8443} return [ "$quic_rj" = 'ON' -a "$lan_proxy" = true ] && nft add rule inet shellcrash $1 udp dport {443, 8443} return
#添加通用路由 #添加通用路由
nft add rule inet shellcrash "$1" "$JUMP" nft add rule inet shellcrash "$1" "$JUMP"
#处理特殊路由 #处理特殊路由
@@ -104,10 +104,10 @@ start_nft_route() { #nftables-route通用工具
#nft add rule inet shellcrash local_tproxy log prefix \"pre\" level debug #nft add rule inet shellcrash local_tproxy log prefix \"pre\" level debug
} }
start_nft_dns() { #nftables-dns start_nft_dns() { #nftables-dns
[ "$1" = 'prerouting' ] && { [ "$1" = 'prerouting' ] && {
HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g') HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g')
HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g') HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')
} }
[ "$1" = 'output' ] && HOST_IP="127.0.0.0/8, $(echo $local_ipv4 | sed 's/[[:space:]]\+/, /g')" [ "$1" = 'output' ] && HOST_IP="127.0.0.0/8, $(echo $local_ipv4 | sed 's/[[:space:]]\+/, /g')"
[ "$1" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')" [ "$1" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')"
nft add chain inet shellcrash "$1"_dns { type nat hook $2 priority -100 \; } nft add chain inet shellcrash "$1"_dns { type nat hook $2 priority -100 \; }
@@ -133,26 +133,26 @@ start_nft_dns() { #nftables-dns
nft add rule inet shellcrash "$1"_dns tcp dport 53 redirect to "$dns_redir_port" nft add rule inet shellcrash "$1"_dns tcp dport 53 redirect to "$dns_redir_port"
} }
start_nft_wan() { #nftables公网防火墙 start_nft_wan() { #nftables公网防火墙
HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g') HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g')
HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g') HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')
nft add chain inet shellcrash input { type filter hook input priority -100 \; } nft add chain inet shellcrash input { type filter hook input priority -100 \; }
nft add rule inet shellcrash input iif lo accept #本机请求全放行 nft add rule inet shellcrash input iif lo accept #本机请求全放行
#端口放行 #端口放行
[ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg [ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg
accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$// ;s/,/, /") accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$// ;s/,/, /")
[ -n "$accept_ports" ] && { [ -n "$accept_ports" ] && {
fw_wan_nfports="{ $(echo "$accept_ports" | sed 's/,/, /g') }" fw_wan_nfports="{ $(echo "$accept_ports" | sed 's/,/, /g') }"
nft add rule inet shellcrash input tcp dport $fw_wan_nfports meta mark set 0x67890 accept nft add rule inet shellcrash input tcp dport $fw_wan_nfports meta mark set 0x67890 accept
nft add rule inet shellcrash input udp dport $fw_wan_nfports meta mark set 0x67890 accept nft add rule inet shellcrash input udp dport $fw_wan_nfports meta mark set 0x67890 accept
} }
#端口拦截 #端口拦截
reject_ports="{ $mix_port, $db_port }" reject_ports="{ $mix_port, $db_port }"
nft add rule inet shellcrash input ip saddr {$HOST_IP} accept nft add rule inet shellcrash input ip saddr {$HOST_IP} accept
nft add rule inet shellcrash input ip6 saddr {$HOST_IP6} accept nft add rule inet shellcrash input ip6 saddr {$HOST_IP6} accept
nft add rule inet shellcrash input tcp dport $reject_ports reject nft add rule inet shellcrash input tcp dport $reject_ports reject
nft add rule inet shellcrash input udp dport $reject_ports reject nft add rule inet shellcrash input udp dport $reject_ports reject
#fw4特殊处理 #fw4特殊处理
nft list chain inet fw4 input >/dev/null 2>&1 && \ nft list chain inet fw4 input >/dev/null 2>&1 && \
nft list chain inet fw4 input | grep -q '67890' || \ nft list chain inet fw4 input | grep -q '67890' || \
nft insert rule inet fw4 input meta mark 0x67890 accept 2>/dev/null nft insert rule inet fw4 input meta mark 0x67890 accept 2>/dev/null
} }

View File

@@ -14,27 +14,27 @@
#设置策略路由 #设置策略路由
[ "$firewall_area" != 4 ] && { [ "$firewall_area" != 4 ] && {
[ "$redir_mod" = "Tproxy" ] && ip route add local default dev lo table $table 2>/dev/null [ "$redir_mod" = "Tproxy" ] && ip route add local default dev lo table $table 2>/dev/null
[ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && { [ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && {
i=1 i=1
while [ -z "$(ip route list | grep utun)" -a "$i" -le 29 ]; do while [ -z "$(ip route list | grep utun)" -a "$i" -le 29 ]; do
sleep 1 sleep 1
i=$((i + 1)) i=$((i + 1))
done done
if [ -z "$(ip route list | grep utun)" ]; then if [ -z "$(ip route list | grep utun)" ]; then
logger "找不到tun模块放弃启动tun相关防火墙规则" 31 logger "找不到tun模块放弃启动tun相关防火墙规则" 31
else else
ip route add default dev utun table $table && tun_statu=true ip route add default dev utun table $table && tun_statu=true
fi fi
} }
[ "$firewall_area" = 5 ] && ip route add default via $bypass_host table $table 2>/dev/null [ "$firewall_area" = 5 ] && ip route add default via $bypass_host table $table 2>/dev/null
[ "$redir_mod" != "Redir" ] && ip rule add fwmark $fwmark table $table 2>/dev/null [ "$redir_mod" != "Redir" ] && ip rule add fwmark $fwmark table $table 2>/dev/null
} }
#添加ipv6路由 #添加ipv6路由
[ "$ipv6_redir" = "ON" -a "$firewall_area" -le 3 ] && { [ "$ipv6_redir" = "ON" -a "$firewall_area" -le 3 ] && {
[ "$redir_mod" = "Tproxy" ] && ip -6 route add local default dev lo table $((table + 1)) 2>/dev/null [ "$redir_mod" = "Tproxy" ] && ip -6 route add local default dev lo table $((table + 1)) 2>/dev/null
[ -n "$(ip route list | grep utun)" ] && ip -6 route add default dev utun table $((table + 1)) 2>/dev/null [ -n "$(ip route list | grep utun)" ] && ip -6 route add default dev utun table $((table + 1)) 2>/dev/null
[ "$redir_mod" != "Redir" ] && ip -6 rule add fwmark $fwmark table $((table + 1)) 2>/dev/null [ "$redir_mod" != "Redir" ] && ip -6 rule add fwmark $fwmark table $((table + 1)) 2>/dev/null
} }
#判断代理用途 #判断代理用途
[ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && local_proxy=true [ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && local_proxy=true
@@ -44,11 +44,11 @@
[ "$firewall_mod" = 'nftables' ] && . "$CRASHDIR"/starts/fw_nftables.sh && start_nftables [ "$firewall_mod" = 'nftables' ] && . "$CRASHDIR"/starts/fw_nftables.sh && start_nftables
#修复部分虚拟机dns查询失败的问题 #修复部分虚拟机dns查询失败的问题
[ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && [ -z "$(grep '127.0.0.1' /etc/resolv.conf 2>/dev/null)" ] && [ "$systype" != 'container' ] && { [ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && [ -z "$(grep '127.0.0.1' /etc/resolv.conf 2>/dev/null)" ] && [ "$systype" != 'container' ] && {
line=$(grep -n 'nameserver' /etc/resolv.conf | awk -F: 'FNR==1{print $1}') line=$(grep -n 'nameserver' /etc/resolv.conf | awk -F: 'FNR==1{print $1}')
sed -i "$line i\nameserver 127.0.0.1 #shellcrash-dns-repair" /etc/resolv.conf >/dev/null 2>&1 sed -i "$line i\nameserver 127.0.0.1 #shellcrash-dns-repair" /etc/resolv.conf >/dev/null 2>&1
} }
#移除openwrt-dnsmasq的DNS重定向 #移除openwrt-dnsmasq的DNS重定向
[ "$(uci get dhcp.@dnsmasq[0].dns_redirect 2>/dev/null)" = 1 ] && { [ "$(uci get dhcp.@dnsmasq[0].dns_redirect 2>/dev/null)" = 1 ] && {
uci del dhcp.@dnsmasq[0].dns_redirect uci del dhcp.@dnsmasq[0].dns_redirect
uci commit dhcp.@dnsmasq[0] uci commit dhcp.@dnsmasq[0]
} }

View File

@@ -14,110 +14,110 @@
accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//") accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//")
#重置iptables相关规则 #重置iptables相关规则
ckcmd iptables && { ckcmd iptables && {
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
#dns #dns
$iptable -t nat -D PREROUTING -p tcp --dport 53 -j shellcrash_dns 2>/dev/null $iptable -t nat -D PREROUTING -p tcp --dport 53 -j shellcrash_dns 2>/dev/null
$iptable -t nat -D PREROUTING -p udp --dport 53 -j shellcrash_dns 2>/dev/null $iptable -t nat -D PREROUTING -p udp --dport 53 -j shellcrash_dns 2>/dev/null
$iptable -t nat -D OUTPUT -p udp --dport 53 -j shellcrash_dns_out 2>/dev/null $iptable -t nat -D OUTPUT -p udp --dport 53 -j shellcrash_dns_out 2>/dev/null
$iptable -t nat -D OUTPUT -p tcp --dport 53 -j shellcrash_dns_out 2>/dev/null $iptable -t nat -D OUTPUT -p tcp --dport 53 -j shellcrash_dns_out 2>/dev/null
#redir #redir
$iptable -t nat -D PREROUTING -p tcp $ports -j shellcrash 2>/dev/null $iptable -t nat -D PREROUTING -p tcp $ports -j shellcrash 2>/dev/null
$iptable -t nat -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash 2>/dev/null $iptable -t nat -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash 2>/dev/null
$iptable -t nat -D OUTPUT -p tcp $ports -j shellcrash_out 2>/dev/null $iptable -t nat -D OUTPUT -p tcp $ports -j shellcrash_out 2>/dev/null
$iptable -t nat -D OUTPUT -p tcp -d 28.0.0.0/8 -j shellcrash_out 2>/dev/null $iptable -t nat -D OUTPUT -p tcp -d 28.0.0.0/8 -j shellcrash_out 2>/dev/null
#vm_dns #vm_dns
$iptable -t nat -D PREROUTING -p tcp --dport 53 -j shellcrash_vm_dns 2>/dev/null $iptable -t nat -D PREROUTING -p tcp --dport 53 -j shellcrash_vm_dns 2>/dev/null
$iptable -t nat -D PREROUTING -p udp --dport 53 -j shellcrash_vm_dns 2>/dev/null $iptable -t nat -D PREROUTING -p udp --dport 53 -j shellcrash_vm_dns 2>/dev/null
#vm_redir #vm_redir
$iptable -t nat -D PREROUTING -p tcp $ports -j shellcrash_vm 2>/dev/null $iptable -t nat -D PREROUTING -p tcp $ports -j shellcrash_vm 2>/dev/null
$iptable -t nat -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash_vm 2>/dev/null $iptable -t nat -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash_vm 2>/dev/null
#TPROXY&tun #TPROXY&tun
$iptable -t mangle -D PREROUTING -p tcp $ports -j shellcrash_mark 2>/dev/null $iptable -t mangle -D PREROUTING -p tcp $ports -j shellcrash_mark 2>/dev/null
$iptable -t mangle -D PREROUTING -p udp $ports -j shellcrash_mark 2>/dev/null $iptable -t mangle -D PREROUTING -p udp $ports -j shellcrash_mark 2>/dev/null
$iptable -t mangle -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash_mark 2>/dev/null $iptable -t mangle -D PREROUTING -p tcp -d 28.0.0.0/8 -j shellcrash_mark 2>/dev/null
$iptable -t mangle -D PREROUTING -p udp -d 28.0.0.0/8 -j shellcrash_mark 2>/dev/null $iptable -t mangle -D PREROUTING -p udp -d 28.0.0.0/8 -j shellcrash_mark 2>/dev/null
$iptable -t mangle -D OUTPUT -p tcp $ports -j shellcrash_mark_out 2>/dev/null $iptable -t mangle -D OUTPUT -p tcp $ports -j shellcrash_mark_out 2>/dev/null
$iptable -t mangle -D OUTPUT -p udp $ports -j shellcrash_mark_out 2>/dev/null $iptable -t mangle -D OUTPUT -p udp $ports -j shellcrash_mark_out 2>/dev/null
$iptable -t mangle -D OUTPUT -p tcp -d 28.0.0.0/8 -j shellcrash_mark_out 2>/dev/null $iptable -t mangle -D OUTPUT -p tcp -d 28.0.0.0/8 -j shellcrash_mark_out 2>/dev/null
$iptable -t mangle -D OUTPUT -p udp -d 28.0.0.0/8 -j shellcrash_mark_out 2>/dev/null $iptable -t mangle -D OUTPUT -p udp -d 28.0.0.0/8 -j shellcrash_mark_out 2>/dev/null
$iptable -t mangle -D PREROUTING -m mark --mark $fwmark -p tcp -j TPROXY --on-port $tproxy_port 2>/dev/null $iptable -t mangle -D PREROUTING -m mark --mark $fwmark -p tcp -j TPROXY --on-port $tproxy_port 2>/dev/null
$iptable -t mangle -D PREROUTING -m mark --mark $fwmark -p udp -j TPROXY --on-port $tproxy_port 2>/dev/null $iptable -t mangle -D PREROUTING -m mark --mark $fwmark -p udp -j TPROXY --on-port $tproxy_port 2>/dev/null
#tun #tun
$iptable -D FORWARD -o utun -j ACCEPT 2>/dev/null $iptable -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC #屏蔽QUIC
[ "$dns_mod" != "fake-ip" ] && [ "$cn_ip_route" != "OFF" ] && set_cn_ip='-m set ! --match-set cn_ip dst' [ "$dns_mod" != "fake-ip" ] && [ "$cn_ip_route" != "OFF" ] && set_cn_ip='-m set ! --match-set cn_ip dst'
$iptable -D INPUT -p udp --dport 443 $set_cn_ip -j REJECT 2>/dev/null $iptable -D INPUT -p udp --dport 443 $set_cn_ip -j REJECT 2>/dev/null
$iptable -D FORWARD -p udp --dport 443 -o utun $set_cn_ip -j REJECT 2>/dev/null $iptable -D FORWARD -p udp --dport 443 -o utun $set_cn_ip -j REJECT 2>/dev/null
#公网访问 #公网访问
$iptable -D INPUT -i lo -j ACCEPT 2>/dev/null $iptable -D INPUT -i lo -j ACCEPT 2>/dev/null
for ip in $host_ipv4; do for ip in $host_ipv4; do
$iptable -D INPUT -s $ip -j ACCEPT 2>/dev/null $iptable -D INPUT -s $ip -j ACCEPT 2>/dev/null
done done
$iptable -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $iptable -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$iptable -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $iptable -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$iptable -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null $iptable -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
$iptable -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null $iptable -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
#清理shellcrash自建表 #清理shellcrash自建表
for text in shellcrash_dns shellcrash shellcrash_out shellcrash_dns_out shellcrash_vm shellcrash_vm_dns; do for text in shellcrash_dns shellcrash shellcrash_out shellcrash_dns_out shellcrash_vm shellcrash_vm_dns; do
$iptable -t nat -F "$text" 2>/dev/null $iptable -t nat -F "$text" 2>/dev/null
$iptable -t nat -X "$text" 2>/dev/null $iptable -t nat -X "$text" 2>/dev/null
done done
for text in shellcrash_mark shellcrash_mark_out; do for text in shellcrash_mark shellcrash_mark_out; do
$iptable -t mangle -F "$text" 2>/dev/null $iptable -t mangle -F "$text" 2>/dev/null
$iptable -t mangle -X "$text" 2>/dev/null $iptable -t mangle -X "$text" 2>/dev/null
done done
} }
#重置ipv6规则 #重置ipv6规则
ckcmd ip6tables && { ckcmd ip6tables && {
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
#dns #dns
$ip6table -t nat -D PREROUTING -p tcp --dport 53 -j shellcrashv6_dns 2>/dev/null $ip6table -t nat -D PREROUTING -p tcp --dport 53 -j shellcrashv6_dns 2>/dev/null
$ip6table -t nat -D PREROUTING -p udp --dport 53 -j shellcrashv6_dns 2>/dev/null $ip6table -t nat -D PREROUTING -p udp --dport 53 -j shellcrashv6_dns 2>/dev/null
#redir #redir
$ip6table -t nat -D PREROUTING -p tcp $ports -j shellcrashv6 2>/dev/null $ip6table -t nat -D PREROUTING -p tcp $ports -j shellcrashv6 2>/dev/null
$ip6table -t nat -D PREROUTING -p tcp -d fc00::/16 -j shellcrashv6 2>/dev/null $ip6table -t nat -D PREROUTING -p tcp -d fc00::/16 -j shellcrashv6 2>/dev/null
$ip6table -t nat -D OUTPUT -p tcp $ports -j shellcrashv6_out 2>/dev/null $ip6table -t nat -D OUTPUT -p tcp $ports -j shellcrashv6_out 2>/dev/null
$ip6table -t nat -D OUTPUT -p tcp -d fc00::/16 -j shellcrashv6_out 2>/dev/null $ip6table -t nat -D OUTPUT -p tcp -d fc00::/16 -j shellcrashv6_out 2>/dev/null
$ip6table -D INPUT -p tcp --dport 53 -j REJECT 2>/dev/null $ip6table -D INPUT -p tcp --dport 53 -j REJECT 2>/dev/null
$ip6table -D INPUT -p udp --dport 53 -j REJECT 2>/dev/null $ip6table -D INPUT -p udp --dport 53 -j REJECT 2>/dev/null
#mark #mark
$ip6table -t mangle -D PREROUTING -p tcp $ports -j shellcrashv6_mark 2>/dev/null $ip6table -t mangle -D PREROUTING -p tcp $ports -j shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -D PREROUTING -p udp $ports -j shellcrashv6_mark 2>/dev/null $ip6table -t mangle -D PREROUTING -p udp $ports -j shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -D PREROUTING -p tcp -d fc00::/16 -j shellcrashv6_mark 2>/dev/null $ip6table -t mangle -D PREROUTING -p tcp -d fc00::/16 -j shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -D PREROUTING -p udp -d fc00::/16 -j shellcrashv6_mark 2>/dev/null $ip6table -t mangle -D PREROUTING -p udp -d fc00::/16 -j shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -D OUTPUT -p tcp $ports -j shellcrashv6_mark_out 2>/dev/null $ip6table -t mangle -D OUTPUT -p tcp $ports -j shellcrashv6_mark_out 2>/dev/null
$ip6table -t mangle -D OUTPUT -p udp $ports -j shellcrashv6_mark_out 2>/dev/null $ip6table -t mangle -D OUTPUT -p udp $ports -j shellcrashv6_mark_out 2>/dev/null
$ip6table -t mangle -D OUTPUT -p tcp -d fc00::/16 -j shellcrashv6_mark_out 2>/dev/null $ip6table -t mangle -D OUTPUT -p tcp -d fc00::/16 -j shellcrashv6_mark_out 2>/dev/null
$ip6table -t mangle -D OUTPUT -p udp -d fc00::/16 -j shellcrashv6_mark_out 2>/dev/null $ip6table -t mangle -D OUTPUT -p udp -d fc00::/16 -j shellcrashv6_mark_out 2>/dev/null
$ip6table -D INPUT -p udp --dport 443 $set_cn_ip -j REJECT 2>/dev/null $ip6table -D INPUT -p udp --dport 443 $set_cn_ip -j REJECT 2>/dev/null
$ip6table -t mangle -D PREROUTING -m mark --mark $fwmark -p tcp -j TPROXY --on-port $tproxy_port 2>/dev/null $ip6table -t mangle -D PREROUTING -m mark --mark $fwmark -p tcp -j TPROXY --on-port $tproxy_port 2>/dev/null
$ip6table -t mangle -D PREROUTING -m mark --mark $fwmark -p udp -j TPROXY --on-port $tproxy_port 2>/dev/null $ip6table -t mangle -D PREROUTING -m mark --mark $fwmark -p udp -j TPROXY --on-port $tproxy_port 2>/dev/null
#tun #tun
$ip6table -D FORWARD -o utun -j ACCEPT 2>/dev/null $ip6table -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC #屏蔽QUIC
[ "$dns_mod" != "fake-ip" ] && [ "$cn_ip_route" != "OFF" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst' [ "$dns_mod" != "fake-ip" ] && [ "$cn_ip_route" != "OFF" ] && set_cn_ip6='-m set ! --match-set cn_ip6 dst'
$ip6table -D INPUT -p udp --dport 443 $set_cn_ip6 -j REJECT 2>/dev/null $ip6table -D INPUT -p udp --dport 443 $set_cn_ip6 -j REJECT 2>/dev/null
$ip6table -D FORWARD -p udp --dport 443 -o utun $set_cn_ip6 -j REJECT 2>/dev/null $ip6table -D FORWARD -p udp --dport 443 -o utun $set_cn_ip6 -j REJECT 2>/dev/null
#公网访问 #公网访问
$ip6table -D INPUT -i lo -j ACCEPT 2>/dev/null $ip6table -D INPUT -i lo -j ACCEPT 2>/dev/null
for ip in $host_ipv6; do for ip in $host_ipv6; do
$ip6table -D INPUT -s $ip -j ACCEPT 2>/dev/null $ip6table -D INPUT -s $ip -j ACCEPT 2>/dev/null
done done
$ip6table -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $ip6table -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$ip6table -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $ip6table -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$ip6table -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null $ip6table -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
$ip6table -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null $ip6table -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
#清理shellcrash自建表 #清理shellcrash自建表
for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do
$ip6table -t nat -F "$text" 2>/dev/null $ip6table -t nat -F "$text" 2>/dev/null
$ip6table -t nat -X "$text" 2>/dev/null $ip6table -t nat -X "$text" 2>/dev/null
done done
for text in shellcrashv6_mark shellcrashv6_mark_out; do for text in shellcrashv6_mark shellcrashv6_mark_out; do
$ip6table -t mangle -F "$text" 2>/dev/null $ip6table -t mangle -F "$text" 2>/dev/null
$ip6table -t mangle -X "$text" 2>/dev/null $ip6table -t mangle -X "$text" 2>/dev/null
done done
$ip6table -t mangle -F shellcrashv6_mark 2>/dev/null $ip6table -t mangle -F shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -X shellcrashv6_mark 2>/dev/null $ip6table -t mangle -X shellcrashv6_mark 2>/dev/null
} }
#清理ipset规则 #清理ipset规则
ipset destroy cn_ip >/dev/null 2>&1 ipset destroy cn_ip >/dev/null 2>&1

View File

@@ -9,22 +9,22 @@ profile=/etc/profile
. "$CRASHDIR"/configs/ShellCrash.cfg . "$CRASHDIR"/configs/ShellCrash.cfg
#padavan和华硕环境变量目录设置 #padavan和华硕环境变量目录设置
if [ -d "/etc/storage/clash" -o -d "/etc/storage/ShellCrash" ]; then if [ -d "/etc/storage/clash" -o -d "/etc/storage/ShellCrash" ]; then
i=1 i=1
while [ ! -w /etc/profile -a "$i" -lt 10 ]; do while [ ! -w /etc/profile -a "$i" -lt 10 ]; do
sleep 3 && i=$((i + 1)) sleep 3 && i=$((i + 1))
done done
[ -w "$profile" ] || profile=/etc_ro/profile [ -w "$profile" ] || profile=/etc_ro/profile
[ "$zip_type" = 'upx' ] || mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式 [ "$zip_type" = 'upx' ] || mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式
sed -i '' "$profile" #将软链接转化为一般文件 sed -i '' "$profile" #将软链接转化为一般文件
elif [ -d "/jffs" ]; then elif [ -d "/jffs" ]; then
sleep 60 sleep 60
[ -w "$profile" ] || profile=$(cat /etc/profile | grep -oE '\-f.*jffs.*profile' | awk '{print $2}') [ -w "$profile" ] || profile=$(cat /etc/profile | grep -oE '\-f.*jffs.*profile' | awk '{print $2}')
fi fi
#写入环境变量 #写入环境变量
set_profile "$profile" set_profile "$profile"
#启动进程或删除守护进程 #启动进程或删除守护进程
if [ -f "$CRASHDIR"/.dis_startup ] || [ -f "$CRASHDIR"/.start_error ];then if [ -f "$CRASHDIR"/.dis_startup ] || [ -f "$CRASHDIR"/.start_error ];then
cronset "保守模式守护进程" cronset "保守模式守护进程"
else else
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
fi fi

View File

@@ -2,8 +2,8 @@
singbox_check() { #singbox启动前检查 singbox_check() { #singbox启动前检查
#检测singboxr专属功能 #检测singboxr专属功能
[ "$crashcore" != "singboxr" ] && [ -n "$(cat "$CRASHDIR"/jsons/*.json | grep -oE '"shadowsocksr"|"providers"')" ] && { [ "$crashcore" != "singboxr" ] && [ -n "$(cat "$CRASHDIR"/jsons/*.json | grep -oE '"shadowsocksr"|"providers"')" ] && {
. "$CRASHDIR"/starts/core_exchange.sh && core_exchange singboxr 'singboxr内核专属功能' . "$CRASHDIR"/starts/core_exchange.sh && core_exchange singboxr 'singboxr内核专属功能'
} }
check_core check_core
#预下载cn.srs数据库 #预下载cn.srs数据库
[ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json && check_geo ruleset/cn.srs srs_geosite_cn.srs [ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json && check_geo ruleset/cn.srs srs_geosite_cn.srs

View File

@@ -39,7 +39,7 @@ parse_singbox_dns() { #dns转换
esac esac
fi fi
# 输出 # 输出
echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"',' echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"','
} }
modify_json() { modify_json() {
#提取配置文件以获得outbounds.json,providers.json及route.json #提取配置文件以获得outbounds.json,providers.json及route.json
@@ -53,11 +53,11 @@ modify_json() {
} }
cat "$TMPDIR"/format.json | sed -n '/"route":/,/^\( "[a-z]\|}\)/p' | sed '$d' >>"$TMPDIR"/jsons/route.json cat "$TMPDIR"/format.json | sed -n '/"route":/,/^\( "[a-z]\|}\)/p' | sed '$d' >>"$TMPDIR"/jsons/route.json
#生成endpoints.json #生成endpoints.json
[ "$ts_service" = ON ] || [ "$wg_service" = ON ] && [ "$zip_type" != upx ] && { [ "$ts_service" = ON ] || [ "$wg_service" = ON ] && [ "$zip_type" != upx ] && {
. "$CRASHDIR"/configs/gateway.cfg . "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_endpoints.sh . "$CRASHDIR"/libs/sb_endpoints.sh
} }
#生成log.json #生成log.json
cat >"$TMPDIR"/jsons/log.json <<EOF cat >"$TMPDIR"/jsons/log.json <<EOF
{ "log": { "level": "info", "timestamp": true } } { "log": { "level": "info", "timestamp": true } }
EOF EOF
@@ -75,7 +75,7 @@ EOF
"path": [ "path": [
$custom_hosts $custom_hosts
"$HOME/.hosts", "$HOME/.hosts",
"/etc/hosts" "/etc/hosts"
], ],
"predefined": { "predefined": {
"localhost": [ "localhost": [
@@ -86,28 +86,28 @@ EOF
"time.facebook.com": "203.107.6.88" "time.facebook.com": "203.107.6.88"
} }
} }
], ],
"rules": [ "rules": [
{ {
"ip_accept_any": true, "ip_accept_any": true,
"server": "hosts" "server": "hosts"
} }
]} ]}
} }
EOF EOF
fi fi
#生成dns.json #生成dns.json
[ "$ipv6_dns" != "OFF" ] && strategy='prefer_ipv4' || strategy='ipv4_only' [ "$ipv6_dns" != "OFF" ] && strategy='prefer_ipv4' || strategy='ipv4_only'
#获取detour出口 #获取detour出口
auto_detour=$(grep -E '"type": "urltest"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '自动' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//') auto_detour=$(grep -E '"type": "urltest"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '自动' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
[ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "urltest"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//') [ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "urltest"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
[ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "selector"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//') [ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "selector"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
[ -z "$auto_detour" ] && auto_detour='"DIRECT"' [ -z "$auto_detour" ] && auto_detour='"DIRECT"'
#ecs优化 #ecs优化
[ "$ecs_subnet" = ON ] && { [ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh . "$CRASHDIR"/libs/get_ecsip.sh
client_subnet='"client_subnet": "'"$ecs_address"'",' client_subnet='"client_subnet": "'"$ecs_address"'",'
} }
#根据dns模式生成 #根据dns模式生成
[ "$dns_mod" = "redir_host" ] && { [ "$dns_mod" = "redir_host" ] && {
global_dns=dns_proxy global_dns=dns_proxy
@@ -133,7 +133,7 @@ EOF
[ "$dns_protect" = "OFF" ] && sed -i 's/"server": "dns_proxy"/"server": "dns_direct"/g' "$TMPDIR"/jsons/route.json [ "$dns_protect" = "OFF" ] && sed -i 's/"server": "dns_proxy"/"server": "dns_direct"/g' "$TMPDIR"/jsons/route.json
#生成add_rule_set.json #生成add_rule_set.json
[ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json && { [ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json && {
[ "$crashcore" = "singboxr" ] && srs_path='"path": "./ruleset/cn.srs",' [ "$crashcore" = "singboxr" ] && srs_path='"path": "./ruleset/cn.srs",'
cat >"$TMPDIR"/jsons/add_rule_set.json <<EOF cat >"$TMPDIR"/jsons/add_rule_set.json <<EOF
{ {
"route": { "route": {
@@ -158,14 +158,14 @@ EOF
{ {
"tag": "dns_proxy", "tag": "dns_proxy",
$(parse_singbox_dns "$dns_fallback") $(parse_singbox_dns "$dns_fallback")
"routing_mark": $routing_mark, "routing_mark": $routing_mark,
"detour": $auto_detour, "detour": $auto_detour,
"domain_resolver": "dns_resolver" "domain_resolver": "dns_resolver"
}, },
{ {
"tag": "dns_direct", "tag": "dns_direct",
$(parse_singbox_dns "$dns_nameserver") $(parse_singbox_dns "$dns_nameserver")
"routing_mark": $routing_mark, "routing_mark": $routing_mark,
"domain_resolver": "dns_resolver" "domain_resolver": "dns_resolver"
}, },
{ {
@@ -177,7 +177,7 @@ EOF
{ {
"tag": "dns_resolver", "tag": "dns_resolver",
$(parse_singbox_dns "$dns_resolver") $(parse_singbox_dns "$dns_resolver")
"routing_mark": $routing_mark "routing_mark": $routing_mark
} }
], ],
"rules": [ "rules": [
@@ -186,14 +186,14 @@ EOF
$fake_ip_filter_domain $fake_ip_filter_domain
$fake_ip_filter_suffix $fake_ip_filter_suffix
$fake_ip_filter_regex $fake_ip_filter_regex
{ "clash_mode": "Global", "query_type": ["A", "AAAA"], "server": "$global_dns", "strategy": "$strategy", "rewrite_ttl": 1 }, { "clash_mode": "Global", "query_type": ["A", "AAAA"], "server": "$global_dns", "strategy": "$strategy", "rewrite_ttl": 1 },
$direct_dns $direct_dns
$proxy_dns $proxy_dns
], ],
"final": "dns_proxy", "final": "dns_proxy",
"strategy": "$strategy", "strategy": "$strategy",
"independent_cache": true, "independent_cache": true,
$client_subnet $client_subnet
"reverse_mapping": true "reverse_mapping": true
} }
} }
@@ -263,10 +263,10 @@ EOF
} }
EOF EOF
#inbounds.json添加自定义入站 #inbounds.json添加自定义入站
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && { [ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg . "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_inbounds.sh . "$CRASHDIR"/libs/sb_inbounds.sh
} }
if [ "$redir_mod" = "Mix" -o "$redir_mod" = "Tun" ]; then if [ "$redir_mod" = "Mix" -o "$redir_mod" = "Tun" ]; then
[ "ipv6_redir" = 'ON' ] && ipv6_address='"fe80::e5c5:2469:d09b:609a/64",' [ "ipv6_redir" = 'ON' ] && ipv6_address='"fe80::e5c5:2469:d09b:609a/64",'
cat >>"$TMPDIR"/jsons/tun.json <<EOF cat >>"$TMPDIR"/jsons/tun.json <<EOF
@@ -299,21 +299,21 @@ EOF
[ -n "$add_direct$add_reject$add_global" ] && cat >"$TMPDIR"/jsons/add_outbounds.json <<EOF [ -n "$add_direct$add_reject$add_global" ] && cat >"$TMPDIR"/jsons/add_outbounds.json <<EOF
{ {
"outbounds": [ "outbounds": [
$add_direct $add_direct
$add_reject $add_reject
$add_global $add_global
] ]
} }
EOF EOF
#生成experimental.json #生成experimental.json
[ "$crashcore" = "singboxr" ] && urltest_unified_delay=',"urltest_unified_delay": true' [ "$crashcore" = "singboxr" ] && urltest_unified_delay=',"urltest_unified_delay": true'
cat >"$TMPDIR"/jsons/experimental.json <<EOF cat >"$TMPDIR"/jsons/experimental.json <<EOF
{ {
"experimental": { "experimental": {
"clash_api": { "clash_api": {
"external_controller": "0.0.0.0:$db_port", "external_controller": "0.0.0.0:$db_port",
"external_ui": "ui", "external_ui": "ui",
"external_ui_download_url": "$external_ui_url", "external_ui_download_url": "$external_ui_url",
"secret": "$secret", "secret": "$secret",
"default_mode": "Rule" "default_mode": "Rule"
}$urltest_unified_delay }$urltest_unified_delay

View File

@@ -8,104 +8,104 @@ crontab -l | grep -v 'start_legacy_wd.sh shellcrash' | crontab -
#防止usb未加载 #防止usb未加载
i=0 i=0
while [ ! -f "$CRASHDIR/configs/ShellCrash.cfg" ]; do while [ ! -f "$CRASHDIR/configs/ShellCrash.cfg" ]; do
[ $i -gt 20 ] && exit 1 [ $i -gt 20 ] && exit 1
i=$((i + 1)) i=$((i + 1))
sleep 3 sleep 3
done done
. "$CRASHDIR"/configs/ShellCrash.cfg . "$CRASHDIR"/configs/ShellCrash.cfg
autoSSH(){ autoSSH(){
#自动开启SSH #自动开启SSH
[ "`uci -c /usr/share/xiaoqiang get xiaoqiang_version.version.CHANNEL`" != 'stable' ] && { [ "`uci -c /usr/share/xiaoqiang get xiaoqiang_version.version.CHANNEL`" != 'stable' ] && {
uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable' uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable'
uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version
} }
[ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && { [ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && {
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
/etc/init.d/dropbear restart /etc/init.d/dropbear restart
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root [ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
} }
#配置nvram #配置nvram
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1 [ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1 [ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1
nvram commit &> /dev/null nvram commit &> /dev/null
#备份还原SSH秘钥 #备份还原SSH秘钥
[ -f "$CRASHDIR"/configs/dropbear_rsa_host_key ] && ln -sf "$CRASHDIR"/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key [ -f "$CRASHDIR"/configs/dropbear_rsa_host_key ] && ln -sf "$CRASHDIR"/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
[ -f "$CRASHDIR"/configs/authorized_keys ] && ln -sf "$CRASHDIR"/configs/authorized_keys /etc/dropbear/authorized_keys [ -f "$CRASHDIR"/configs/authorized_keys ] && ln -sf "$CRASHDIR"/configs/authorized_keys /etc/dropbear/authorized_keys
} }
tunfix(){ tunfix(){
ko_dir=$(modinfo ip_tables | grep -Eo '/lib/modules.*/ip_tables.ko' | sed 's|/ip_tables.ko||' ) ko_dir=$(modinfo ip_tables | grep -Eo '/lib/modules.*/ip_tables.ko' | sed 's|/ip_tables.ko||' )
#在/tmp创建并挂载overlay #在/tmp创建并挂载overlay
mkdir -p /tmp/overlay mkdir -p /tmp/overlay
mkdir -p /tmp/overlay/upper mkdir -p /tmp/overlay/upper
mkdir -p /tmp/overlay/work mkdir -p /tmp/overlay/work
mount -o noatime,lowerdir="$ko_dir",upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" "$ko_dir" mount -o noatime,lowerdir="$ko_dir",upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" "$ko_dir"
#将tun.ko链接到lib #将tun.ko链接到lib
ln -sf "$CRASHDIR"/tools/tun.ko "$ko_dir"/tun.ko ln -sf "$CRASHDIR"/tools/tun.ko "$ko_dir"/tun.ko
} }
tproxyfix(){ tproxyfix(){
sed -i 's/sysctl -w net.bridge.bridge-nf-call-ip/#sysctl -w net.bridge.bridge-nf-call-ip/g' /etc/init.d/qca-nss-ecm sed -i 's/sysctl -w net.bridge.bridge-nf-call-ip/#sysctl -w net.bridge.bridge-nf-call-ip/g' /etc/init.d/qca-nss-ecm
sysctl -w net.bridge.bridge-nf-call-iptables=0 sysctl -w net.bridge.bridge-nf-call-iptables=0
sysctl -w net.bridge.bridge-nf-call-ip6tables=0 sysctl -w net.bridge.bridge-nf-call-ip6tables=0
} }
auto_clean(){ auto_clean(){
#自动清理升级备份文件夹 #自动清理升级备份文件夹
rm -rf /data/etc_bak rm -rf /data/etc_bak
#自动清理被写入闪存的系统日志并禁止服务 #自动清理被写入闪存的系统日志并禁止服务
/etc/init.d/stat_points stop 2>/dev/null /etc/init.d/stat_points stop 2>/dev/null
/etc/init.d/stat_points disable 2>/dev/null /etc/init.d/stat_points disable 2>/dev/null
sed -i '\#/logrotate#{ /^[[:space:]]*#/!s/^/#ShellCrash自动注释 / }' /etc/crontabs/root sed -i '\#/logrotate#{ /^[[:space:]]*#/!s/^/#ShellCrash自动注释 / }' /etc/crontabs/root
sed -i '\#/sec_cfg_bak#{ /^[[:space:]]*#/!s/^/#ShellCrash自动注释 / }' /etc/crontabs/root sed -i '\#/sec_cfg_bak#{ /^[[:space:]]*#/!s/^/#ShellCrash自动注释 / }' /etc/crontabs/root
rm -rf /data/usr/log /data/usr/sec_cfg rm -rf /data/usr/log /data/usr/sec_cfg
} }
auto_start(){ auto_start(){
#设置init.d服务 #设置init.d服务
[ ! -x /etc/init.d/shellcrash ] && { [ ! -x /etc/init.d/shellcrash ] && {
cp -f "$CRASHDIR"/starts/shellcrash.procd /etc/init.d/shellcrash cp -f "$CRASHDIR"/starts/shellcrash.procd /etc/init.d/shellcrash
chmod 755 /etc/init.d/shellcrash chmod 755 /etc/init.d/shellcrash
} }
#初始化环境变量 #初始化环境变量
grep -q '^export CRASHDIR=' '/etc/profile' || { grep -q '^export CRASHDIR=' '/etc/profile' || {
. "$CRASHDIR"/libs/set_profile.sh . "$CRASHDIR"/libs/set_profile.sh
set_profile '/etc/profile' set_profile '/etc/profile'
} }
#启动服务 #启动服务
if [ ! -f "$CRASHDIR"/.dis_startup ] && [ ! -f "$CRASHDIR"/.start_error ]; then if [ ! -f "$CRASHDIR"/.dis_startup ] && [ ! -f "$CRASHDIR"/.start_error ]; then
#AX6S/AX6000修复tun功能 #AX6S/AX6000修复tun功能
[ -s "$CRASHDIR"/tools/tun.ko ] && tunfix [ -s "$CRASHDIR"/tools/tun.ko ] && tunfix
#小米7000/小米万兆修复tproxy #小米7000/小米万兆修复tproxy
[ -f /etc/init.d/qca-nss-ecm ] && echo "$redir_mod" | grep -q 'Tproxy' && tproxyfix [ -f /etc/init.d/qca-nss-ecm ] && echo "$redir_mod" | grep -q 'Tproxy' && tproxyfix
#自动覆盖根证书文件 #自动覆盖根证书文件
[ -s "$CRASHDIR"/tools/ca-certificates.crt ] && cp -f "$CRASHDIR"/tools/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt [ -s "$CRASHDIR"/tools/ca-certificates.crt ] && cp -f "$CRASHDIR"/tools/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
#启动服务 #启动服务
"$CRASHDIR"/start.sh stop "$CRASHDIR"/start.sh stop
/etc/init.d/shellcrash start && /etc/init.d/shellcrash enable /etc/init.d/shellcrash start && /etc/init.d/shellcrash enable
fi fi
} }
init(){ init(){
#等待启动完成 #等待启动完成
while ! ip a| grep -q lan; do while ! ip a| grep -q lan; do
sleep 10 sleep 10
done done
autoSSH #软固化功能 autoSSH #软固化功能
auto_clean #自动清理 auto_clean #自动清理
auto_start auto_start
#启动自定义服务 #启动自定义服务
[ -s /data/auto_start.sh ] && /bin/sh /data/auto_start.sh & [ -s /data/auto_start.sh ] && /bin/sh /data/auto_start.sh &
#兼容auto_ssh脚本 #兼容auto_ssh脚本
[ -s /data/auto_ssh/auto_ssh.sh ] && /bin/sh /data/auto_ssh/auto_ssh.sh & [ -s /data/auto_ssh/auto_ssh.sh ] && /bin/sh /data/auto_ssh/auto_ssh.sh &
} }
case "$1" in case "$1" in
tunfix) tunfix ;; tunfix) tunfix ;;
tproxyfix) tproxyfix ;; tproxyfix) tproxyfix ;;
auto_clean) auto_clean ;; auto_clean) auto_clean ;;
init) init ;; init) init ;;
*) *)
if [ -z "$(pidof CrashCore)" ];then if [ -z "$(pidof CrashCore)" ];then
init & init &
fi fi
;; ;;
esac esac

View File

@@ -1,11 +1,11 @@
if [ "$start_old" != "ON" ] && ckcmd journalctl; then if [ "$start_old" != "ON" ] && ckcmd journalctl; then
journalctl -u shellcrash >"$TMPDIR"/core_test.log journalctl -u shellcrash >"$TMPDIR"/core_test.log
else else
PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 "$PID" >/dev/null 2>&1 PID=$(pidof CrashCore) && [ -n "$PID" ] && kill -9 "$PID" >/dev/null 2>&1
${COMMAND} >"$TMPDIR"/core_test.log 2>&1 & ${COMMAND} >"$TMPDIR"/core_test.log 2>&1 &
sleep 2 sleep 2
kill $! >/dev/null 2>&1 kill $! >/dev/null 2>&1
fi fi
touch "$CRASHDIR"/.start_error #标记启动失败,防止自启 touch "$CRASHDIR"/.start_error #标记启动失败,防止自启
error=$(cat "$TMPDIR"/core_test.log | grep -iEo 'error.*=.*|.*ERROR.*|.*FATAL.*') error=$(cat "$TMPDIR"/core_test.log | grep -iEo 'error.*=.*|.*ERROR.*|.*FATAL.*')

View File

@@ -2,14 +2,14 @@
. "$CRASHDIR"/libs/check_cmd.sh . "$CRASHDIR"/libs/check_cmd.sh
start_legacy(){ start_legacy(){
ckcmd nohup && _nohup=nohup ckcmd nohup && _nohup=nohup
if ckcmd su && grep -q 'shellcrash:x:0:7890' /etc/passwd;then if ckcmd su && grep -q 'shellcrash:x:0:7890' /etc/passwd;then
su shellcrash -c "$_nohup $1 >/dev/null 2>&1 & echo \$! > /tmp/ShellCrash/$2.pid" su shellcrash -c "$_nohup $1 >/dev/null 2>&1 & echo \$! > /tmp/ShellCrash/$2.pid"
elif ckcmd setsid; then elif ckcmd setsid; then
$_nohup setsid $1 >/dev/null 2>&1 & $_nohup setsid $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid" echo $! > "/tmp/ShellCrash/$2.pid"
else else
$_nohup $1 >/dev/null 2>&1 & $_nohup $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid" echo $! > "/tmp/ShellCrash/$2.pid"
fi fi
} }

View File

@@ -7,24 +7,24 @@ LOCKDIR="/tmp/ShellCrash/start_$1.lock"
mkdir "$LOCKDIR" 2>/dev/null || exit 1 mkdir "$LOCKDIR" 2>/dev/null || exit 1
if [ -f "$PIDFILE" ]; then if [ -f "$PIDFILE" ]; then
PID="$(cat "$PIDFILE")" PID="$(cat "$PIDFILE")"
if [ -n "$PID" ] && [ "$PID" -eq "$PID" ] 2>/dev/null; then if [ -n "$PID" ] && [ "$PID" -eq "$PID" ] 2>/dev/null; then
if kill -0 "$PID" 2>/dev/null || [ -d "/proc/$PID" ]; then if kill -0 "$PID" 2>/dev/null || [ -d "/proc/$PID" ]; then
rm -fr "$LOCKDIR" 2>/dev/null rm -fr "$LOCKDIR" 2>/dev/null
exit 0 exit 0
fi fi
else else
rm -f "$PIDFILE" rm -f "$PIDFILE"
fi fi
fi fi
#如果没有进程则拉起 #如果没有进程则拉起
if [ "$1" = "shellcrash" ]; then if [ "$1" = "shellcrash" ]; then
"$CRASHDIR"/start.sh start "$CRASHDIR"/start.sh start
else else
[ -f "$CRASHDIR/starts/start_legacy.sh" ] && . "$CRASHDIR/starts/start_legacy.sh" [ -f "$CRASHDIR/starts/start_legacy.sh" ] && . "$CRASHDIR/starts/start_legacy.sh"
killall bot_tg.sh 2>/dev/null killall bot_tg.sh 2>/dev/null
start_legacy "$CRASHDIR/menus/bot_tg.sh" "$1" start_legacy "$CRASHDIR/menus/bot_tg.sh" "$1"
fi fi
rm -fr "$LOCKDIR" 2>/dev/null rm -fr "$LOCKDIR" 2>/dev/null