~统一缩进

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

View File

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

View File

@@ -1,14 +1,14 @@
check_cpucore(){ #自动获取内核架构
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -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.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
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" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat"
fi
[ -n "$cpucore" ] && setconfig cpucore $cpucore
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -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.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
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" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat"
fi
[ -n "$cpucore" ] && setconfig cpucore $cpucore
}

View File

@@ -1,5 +1,5 @@
#检查目录剩余空间——$1:目标路径 $2:-h参数
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}'
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,8 +15,8 @@ routing_mark=$((fwmark + 2))
[ -z "$table" ] && table=100
[ -z "$dns_nameserver" ] && {
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'
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'
}
[ -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"

View File

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

View File

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

View File

@@ -6,13 +6,13 @@ __IS_LIB_LOGGER=1
. "$CRASHDIR"/libs/web_json.sh
#$1日志内容$2显示颜色$3是否推送$4是否覆盖上一条
logger() {
TMPDIR=/tmp/ShellCrash
TMPDIR=/tmp/ShellCrash
[ -n "$2" -a "$2" != 0 ] && printf "\033[%sm%s\033[0m\n" "$2" "$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
[ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 199 ] && sed -i '1,20d' "$TMPDIR"/ShellCrash.log
#推送远程日志
#推送远程日志
[ "$3" != off ] && {
[ -n "$device_name" ] && log_text="$log_text($device_name)"
[ -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}"
content="payload={\"text\":\"${log_text}\", \"user_ids\":[${push_ChatUSERID}]}"
web_json_post "$url" "$content" &
}
}
} &
}

View File

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

View File

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

View File

@@ -2,8 +2,8 @@
# Copyright (C) Juewuy
[ "$vms_service" = ON ] && {
[ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": "'"$vms_ws_path"'" }'
cat >"$TMPDIR"/jsons/vmess-in.json <<EOF
[ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": "'"$vms_ws_path"'" }'
cat >"$TMPDIR"/jsons/vmess-in.json <<EOF
{
"inbounds": [
{
@@ -11,7 +11,7 @@
"tag": "vmess-in",
"listen": "::",
"listen_port": $vms_port,
"users": [
"users": [
{
"uuid": "$vms_uuid"
}
@@ -23,17 +23,17 @@ EOF
}
[ "$sss_service" = ON ] && {
cat >"$TMPDIR"/jsons/ss-in.json <<EOF
cat >"$TMPDIR"/jsons/ss-in.json <<EOF
{
"inbounds": [
{
"type": "shadowsocks",
"tag": "ss-in",
{
"type": "shadowsocks",
"tag": "ss-in",
"listen": "::",
"listen_port": $sss_port,
"method": "$sss_cipher",
"password": "$sss_pwd",
}
"method": "$sss_cipher",
"password": "$sss_pwd",
}
]
}
EOF

View File

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

View File

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

View File

@@ -5,5 +5,5 @@ set_profile() {
echo "alias ${my_alias}=\"$shtype $CRASHDIR/menu.sh\"" >>"$1" #设置快捷命令环境变量
sed -i '/export CRASHDIR=*/'d "$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(){
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890
export https_proxy="http://${auth}127.0.0.1:$mix_port"
export http_proxy="http://${auth}127.0.0.1:$mix_port"
}
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890
export https_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
while [ -z "$test" -a "$i" -lt 30 ]; do
sleep 1
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)
else
test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies)
fi
i=$((i + 1))
sleep 1
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)
else
test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies)
fi
i=$((i + 1))
done

View File

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

View File

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

View File

@@ -2,46 +2,46 @@
bar_max=42 #进度条长度
curl_fsize(){ # 获取文件大小
fsize_raw=0
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)
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
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)
fi
fsize_raw=0
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)
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
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)
fi
}
execute_curl(){ # 手搓curl进度条
local path="$1" target_url="$2" total_size="$3" extra_args="$4"
rm -f /tmp/webget_res
# 后台静默下载,状态码写入临时文件
curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res &
local pid=$!
local path="$1" target_url="$2" total_size="$3" extra_args="$4"
rm -f /tmp/webget_res
# 后台静默下载,状态码写入临时文件
curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res &
local pid=$!
# 循环监控
while kill -0 $pid 2>/dev/null; do
if [ -f "$path" ]; then
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 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 spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s")
local size=$(( fsize_raw * 100 / 1048576 ))
local fs="$((size / 100)).$((size % 100)) MB"
printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2
fi
usleep 200000 2>/dev/null || sleep 1
done
# 循环监控
while kill -0 $pid 2>/dev/null; do
if [ -f "$path" ]; then
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 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 spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s")
local size=$(( fsize_raw * 100 / 1048576 ))
local fs="$((size / 100)).$((size % 100)) MB"
printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2
fi
usleep 200000 2>/dev/null || sleep 1
done
local code=$(cat /tmp/webget_res 2>/dev/null)
if [ "$code" = "200" ] || [ "$code" = "206" ]; then
local full=$(printf "%${bar_max}s" | tr ' ' '#')
printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2
else
printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path"
fi
echo "$code"
local code=$(cat /tmp/webget_res 2>/dev/null)
if [ "$code" = "200" ] || [ "$code" = "206" ]; then
local full=$(printf "%${bar_max}s" | tr ' ' '#')
printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2
else
printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path"
fi
echo "$code"
}

View File

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

View File

@@ -1,10 +1,10 @@
. "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:json字符串
web_json_post() {
setproxy
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
else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1"
fi
setproxy
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
else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1"
fi
}

View File

@@ -9,12 +9,12 @@ put_save() { #推送面板选择
fi
}
web_restore() { #还原面板选择
num=$(cat "$CRASHDIR"/configs/web_save | wc -l)
i=1
while [ "$i" -le "$num" ]; do
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)
put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}"
i=$((i + 1))
done
num=$(cat "$CRASHDIR"/configs/web_save | wc -l)
i=1
while [ "$i" -le "$num" ]; do
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)
put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}"
i=$((i + 1))
done
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@ set_core_config() {
LC_ALL=C awk '{
f1 = $1
f2 = $2
gsub(/\360[\200-\277][\200-\277][\200-\277]/,"",f1)
gsub(/\360[\200-\277][\200-\277][\200-\277]/,"",f1)
if (length(f1) > 12)
f1 = substr(f1, 1, 8) ".."
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
comp_box "\033[32m$TOOLS_MERGE_OK\033[0m"
[ "$TMPDIR" = "$BINDIR" ] && rm -rf "$TMPDIR"/CrashCore
debug
debug
;;
*)
errornum

View File

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

View File

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

View File

@@ -22,7 +22,7 @@ tg_push_token() {
push_TG="$TOKEN"
setconfig push_TG "$TOKEN"
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() {

View File

@@ -2,15 +2,15 @@
. "$CRASHDIR"/libs/set_cron.sh
bot_tg_start(){
. "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$CRASHDIR/menus/bot_tg.sh" 'bot_tg'
. "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$CRASHDIR/menus/bot_tg.sh" 'bot_tg'
}
bot_tg_stop(){
cronload | grep -q 'TG_BOT' && cronset 'TG_BOT'
[ -f "$TMPDIR/bot_tg.pid" ] && kill -TERM "$(cat "$TMPDIR/bot_tg.pid")" 2>/dev/null
killall bot_tg.sh 2>/dev/null
rm -f "$TMPDIR/bot_tg.pid"
cronload | grep -q 'TG_BOT' && cronset 'TG_BOT'
[ -f "$TMPDIR/bot_tg.pid" ] && kill -TERM "$(cat "$TMPDIR/bot_tg.pid")" 2>/dev/null
killall bot_tg.sh 2>/dev/null
rm -f "$TMPDIR/bot_tg.pid"
}
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
_get_netstat_cmd() {
case "$1" in
tcp) echo "netstat -ntl" ;;
udp) echo "netstat -nul" ;;
*) echo "netstat -ntul" ;;
esac
case "$1" in
tcp) echo "netstat -ntl" ;;
udp) echo "netstat -nul" ;;
*) echo "netstat -ntul" ;;
esac
}
check_port() {
local port="$1"
local protocol="${2:-all}"
local port="$1"
local protocol="${2:-all}"
if [ "$port" -gt 65535 ] || [ "$port" -le 1 ]; then
msg_alert "\033[31m$CHECK_PORT_RANGE_ERR\033[0m"
return 1
fi
if [ "$port" -gt 65535 ] || [ "$port" -le 1 ]; then
msg_alert "\033[31m$CHECK_PORT_RANGE_ERR\033[0m"
return 1
fi
local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol")
local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol")
if $check_cmd 2>/dev/null | grep -q ":${port}[[:space:]]"; then
msg_alert "\033[31m$CHECK_PORT_OCCUPIED_ERR\033[0m"
return 1
fi
if $check_cmd 2>/dev/null | grep -q ":${port}[[:space:]]"; then
msg_alert "\033[31m$CHECK_PORT_OCCUPIED_ERR\033[0m"
return 1
fi
return 0
return 0
}
check_port_with_info() {
local port="$1"
local protocol="${2:-all}"
local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol")
local port="$1"
local protocol="${2:-all}"
local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol")
local conflict_line
conflict_line=$($check_cmd 2>/dev/null | grep ":${port}[[:space:]]" | head -n 1)
local conflict_line
conflict_line=$($check_cmd 2>/dev/null | grep ":${port}[[:space:]]" | head -n 1)
if [ -n "$conflict_line" ]; then
echo "$conflict_line"
return 1
fi
if [ -n "$conflict_line" ]; then
echo "$conflict_line"
return 1
fi
return 0
return 0
}

View File

@@ -12,21 +12,21 @@ add_ddns() {
cat >>"$ddns_dir" <<EOF
config service '$service'
option enabled '1'
option force_unit 'hours'
option lookup_host '$domain'
option service_name '$service_name'
option domain '$domain'
option username '$username'
option use_https '0'
option use_ipv6 '$use_ipv6'
option password '$password'
option ip_source 'web'
option check_unit 'minutes'
option check_interval '$check_interval'
option force_interval '$force_interval'
option interface 'wan'
option bind_network 'wan'
option enabled '1'
option force_unit 'hours'
option lookup_host '$domain'
option service_name '$service_name'
option domain '$domain'
option username '$username'
option use_https '0'
option use_ipv6 '$use_ipv6'
option password '$password'
option ip_source 'web'
option check_unit 'minutes'
option check_interval '$check_interval'
option force_interval '$force_interval'
option interface 'wan'
option bind_network 'wan'
EOF
/usr/lib/ddns/dynamic_dns_updater.sh -S "$service" start >/dev/null 2>&1 &
sleep 3
@@ -71,12 +71,12 @@ set_ddns() {
set_ddns_service() {
while true; do
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" ] || {
msg_alert "\033[33m$DDNS_LIST_NOT_FOUND\033[0m"
ddns service update >/dev/null || msg_alert "\033[31m$DDNS_DOWNLOAD_FAILED\033[0m"
}
[ -s "$services_dir" ] || {
msg_alert "\033[33m$DDNS_LIST_NOT_FOUND\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"
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"
;;
4)
if [ "$dns_protect" = ON ]; then
dns_protect=OFF
else
dns_protect=ON
fi
setconfig dns_protect "$dns_protect"
common_success
if [ "$dns_protect" = ON ]; then
dns_protect=OFF
else
dns_protect=ON
fi
setconfig dns_protect "$dns_protect"
common_success
;;
5)
if [ "$hosts_opt" = ON ]; then
hosts_opt=OFF
else
hosts_opt=ON
fi
setconfig hosts_opt "$hosts_opt"
common_success
if [ "$hosts_opt" = ON ]; then
hosts_opt=OFF
else
hosts_opt=ON
fi
setconfig hosts_opt "$hosts_opt"
common_success
;;
6)
if [ "$ecs_subnet" = ON ]; then
ecs_subnet=OFF
else
ecs_subnet=ON
fi
setconfig ecs_subnet "$ecs_subnet"
common_success
if [ "$ecs_subnet" = ON ]; then
ecs_subnet=OFF
else
ecs_subnet=ON
fi
setconfig ecs_subnet "$ecs_subnet"
common_success
;;
7)
while true; do

View File

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

View File

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

View File

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

View File

@@ -16,20 +16,20 @@
. "$CRASHDIR"/libs/web_save.sh
#特殊脚本
bfstart(){
"$CRASHDIR"/starts/bfstart.sh
"$CRASHDIR"/starts/bfstart.sh
}
afstart(){
"$CRASHDIR"/starts/afstart.sh
"$CRASHDIR"/starts/afstart.sh
}
stop_firewall(){
"$CRASHDIR"/starts/fw_stop.sh
"$CRASHDIR"/starts/fw_stop.sh
}
#保守模式启动
start_l(){
bfstart && {
. "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$COMMAND" 'shellcrash'
} && afstart &
bfstart && {
. "$CRASHDIR"/starts/start_legacy.sh
start_legacy "$COMMAND" 'shellcrash'
} && afstart &
}
case "$1" in
@@ -37,26 +37,26 @@ case "$1" in
start)
[ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例
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
elif [ "$start_old" = "ON" ]; then
start_l
elif [ -f /etc/rc.common ] && grep -q 'procd' /proc/1/comm; then
/etc/init.d/shellcrash start
elif [ "$USER" = "root" ] && grep -q 'systemd' /proc/1/comm; then
FragmentPath=$(systemctl show -p FragmentPath shellcrash | sed 's/FragmentPath=//')
[ -f "$FragmentPath" ] && {
sed -i "s#^ExecStart=.*#ExecStart=$COMMAND >/dev/null#" "$FragmentPath"
systemctl daemon-reload
}
systemctl start shellcrash.service || . "$CRASHDIR"/starts/start_error.sh
FragmentPath=$(systemctl show -p FragmentPath shellcrash | sed 's/FragmentPath=//')
[ -f "$FragmentPath" ] && {
sed -i "s#^ExecStart=.*#ExecStart=$COMMAND >/dev/null#" "$FragmentPath"
systemctl daemon-reload
}
systemctl start shellcrash.service || . "$CRASHDIR"/starts/start_error.sh
elif grep -q 's6' /proc/1/comm; then
bfstart && /command/s6-svc -u /run/service/shellcrash && {
[ ! -f "$CRASHDIR"/.dis_startup ] && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
afstart &
}
bfstart && /command/s6-svc -u /run/service/shellcrash && {
[ ! -f "$CRASHDIR"/.dis_startup ] && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
afstart &
}
elif rc-status -r >/dev/null 2>&1; then
rc-service shellcrash stop >/dev/null 2>&1
rc-service shellcrash start
@@ -68,9 +68,9 @@ stop)
logger ShellCrash服务即将关闭......
[ -n "$(pidof CrashCore)" ] && web_save #保存面板配置
#清理定时任务
cronload | grep -vE '^$|start_legacy_wd.sh|运行时每' > "$TMPDIR"/cron_tmp
cronadd "$TMPDIR"/cron_tmp
rm -f "$TMPDIR"/cron_tmp
cronload | grep -vE '^$|start_legacy_wd.sh|运行时每' > "$TMPDIR"/cron_tmp
cronadd "$TMPDIR"/cron_tmp
rm -f "$TMPDIR"/cron_tmp
#停止tg_bot
. "$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
/etc/init.d/shellcrash stop >/dev/null 2>&1
elif grep -q 's6' /proc/1/comm; then
/command/s6-svc -d /run/service/shellcrash
stop_firewall
/command/s6-svc -d /run/service/shellcrash
stop_firewall
elif rc-status -r >/dev/null 2>&1; then
rc-service shellcrash stop >/dev/null 2>&1
else

View File

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

View File

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

View File

@@ -5,7 +5,7 @@
check_core() { #检查及下载内核文件
[ -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 ] && {
logger "未找到【$crashcore】核心,正在下载!" 33
[ -z "$cpucore" ] && . "$CRASHDIR"/libs/check_cpucore.sh && check_cpucore

View File

@@ -16,15 +16,15 @@ modify_yaml() {
#Meta内核专属配置
[ "$crashcore" = 'meta' ] && {
[ -z "$(grep 'PROCESS' "$CRASHDIR"/yamls/*.yaml)" ] && find_process='find-process-mode: "off"'
#ecs优化
[ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh
if [ -n "$ecs_address" ];then
dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||')
else
logger "自动获取ecs网段失败"
fi
}
#ecs优化
[ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh
if [ -n "$ecs_address" ];then
dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||')
else
logger "自动获取ecs网段失败"
fi
}
}
#dns配置
[ -z "$(cat "$CRASHDIR"/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && {
@@ -100,17 +100,17 @@ EOF
if [ "$crashcore" = "meta" ]; then
echo " 'services.googleapis.cn': services.googleapis.com" >>"$TMPDIR"/hosts.yaml
fi
#加载本机hosts
sys_hosts=/etc/hosts
[ -f /data/etc/custom_hosts ] && sys_hosts='/etc/hosts /data/etc/custom_hosts'
cat $sys_hosts | while read line; do
[ -n "$(echo "$line" | grep -oE "([0-9]{1,3}[\.]){3}")" ] &&
[ -z "$(echo "$line" | grep -oE '^#')" ] &&
hosts_ip=$(echo $line | awk '{print $1}') &&
hosts_domain=$(echo $line | awk '{print $2}') &&
[ -z "$(cat "$TMPDIR"/hosts.yaml | grep -oE "$hosts_domain")" ] &&
echo " '$hosts_domain': $hosts_ip" >>"$TMPDIR"/hosts.yaml
done
#加载本机hosts
sys_hosts=/etc/hosts
[ -f /data/etc/custom_hosts ] && sys_hosts='/etc/hosts /data/etc/custom_hosts'
cat $sys_hosts | while read line; do
[ -n "$(echo "$line" | grep -oE "([0-9]{1,3}[\.]){3}")" ] &&
[ -z "$(echo "$line" | grep -oE '^#')" ] &&
hosts_ip=$(echo $line | awk '{print $1}') &&
hosts_domain=$(echo $line | awk '{print $2}') &&
[ -z "$(cat "$TMPDIR"/hosts.yaml | grep -oE "$hosts_domain")" ] &&
echo " '$hosts_domain': $hosts_ip" >>"$TMPDIR"/hosts.yaml
done
fi
#分割配置文件
yaml_char='proxies proxy-groups proxy-providers rules rule-providers sub-rules listeners'
@@ -172,10 +172,10 @@ EOF
done
}
#添加自定义入站
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/meta_listeners.sh
}
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/meta_listeners.sh
}
#节点绕过功能支持
sed -i "/#节点绕过/d" "$TMPDIR"/rules.yaml
[ "$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}')
Config=$(grep -aE '^5' "$CRASHDIR"/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $3}')
gen_ua
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ]; then
#Urlencord转码处理保留字符
if ckcmd hexdump;then
Url=$(echo $Url | sed 's/%26/\&/g') #处理分隔符
urlencodeUrl="exclude=$(urlencode "$exclude")&include=$(urlencode "$include")&url=$(urlencode "$Url")&config=$(urlencode "$Config")"
else
urlencodeUrl="exclude=$exclude&include=$include&url=$Url&config=$Config"
fi
Url=$(echo $Url | sed 's/%26/\&/g') #处理分隔符
urlencodeUrl="exclude=$(urlencode "$exclude")&include=$(urlencode "$include")&url=$(urlencode "$Url")&config=$(urlencode "$Config")"
else
urlencodeUrl="exclude=$exclude&include=$include&url=$Url&config=$Config"
fi
Https="${Server}/sub?target=${target}&${Server_ua}=${user_agent}&insert=true&new_name=true&scv=true&udp=true&${urlencodeUrl}"
url_type=true
else
Https=$(echo $Https | sed 's/\\&/\&/g') #还原转义
else
Https=$(echo $Https | sed 's/\\&/\&/g') #还原转义
fi
#输出
echo "-----------------------------------------------"
@@ -92,7 +92,7 @@ get_core_config() { #下载内核配置文件
else
. "$CRASHDIR"/starts/clash_config_check.sh
fi
check_config
check_config
#如果不同则备份并替换文件
if [ -s "$core_config" ]; then
compare "$core_config_new" "$core_config"

View File

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

View File

@@ -32,9 +32,9 @@ start_ipt_route() { #iptables-route通用工具
done
[ "$firewall_area" = 5 ] && "$1" $w -t "$2" -A "$4" -s $bypass_host -j RETURN
[ -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 udp -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
}
#跳过目标保留地址及目标本机网段
for ip in $HOST_IP $RESERVED_IP; do
"$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"
}
start_ipt_wan() { #iptables公网防火墙
ipt_wan_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
}
ipt_wan_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
}
#端口拦截
reject_ports="$mix_port,$db_port"
ipt_wan_reject tcp
ipt_wan_reject udp
#端口放行
[ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg
accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//")
ipt_wan_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
}
ipt_wan_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
}
#端口拦截
reject_ports="$mix_port,$db_port"
ipt_wan_reject tcp
ipt_wan_reject udp
#端口放行
[ -f "$CRASHDIR"/configs/gateway.cfg ] && . "$CRASHDIR"/configs/gateway.cfg
accept_ports=$(echo "$fw_wan_ports,$vms_port,$sss_port" | sed "s/,,/,/g ;s/^,// ;s/,$//")
[ -n "$accept_ports" ] && {
ipt_wan_accept tcp
ipt_wan_accept udp
}
#局域网请求放行
for ip in $host_ipv4; do
$iptable -I INPUT -s $ip -j ACCEPT
done
ckcmd ip6tables && for ip in $host_ipv6; do
$ip6table -I INPUT -s $ip -j ACCEPT
done
#本机请求全放行
$iptable -I INPUT -i lo -j ACCEPT
ckcmd ip6tables && $ip6table -I INPUT -i lo -j ACCEPT
ipt_wan_accept tcp
ipt_wan_accept udp
}
#局域网请求放行
for ip in $host_ipv4; do
$iptable -I INPUT -s $ip -j ACCEPT
done
ckcmd ip6tables && for ip in $host_ipv6; do
$ip6table -I INPUT -s $ip -j ACCEPT
done
#本机请求全放行
$iptable -I INPUT -i lo -j ACCEPT
ckcmd ip6tables && $ip6table -I INPUT -i lo -j ACCEPT
}
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')
add_ip6_route(){
#过滤保留地址及本机地址
nft add rule inet shellcrash $1 ip6 daddr {$RESERVED_IP6} return
#仅代理本机局域网网段流量
nft add rule inet shellcrash $1 ip6 saddr != {$HOST_IP6} return
#绕过CN_IPV6
[ "$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)
[ -n "$CN_IP6" ] && {
nft add set inet shellcrash cn_ip6 { type ipv6_addr \; flags interval \; }
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 {$RESERVED_IP6} return
#仅代理本机局域网网段流量
nft add rule inet shellcrash $1 ip6 saddr != {$HOST_IP6} return
#绕过CN_IPV6
[ "$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)
[ -n "$CN_IP6" ] && {
nft add set inet shellcrash cn_ip6 { type ipv6_addr \; flags interval \; }
nft add element inet shellcrash cn_ip6 { $CN_IP6 }
nft add rule inet shellcrash $1 ip6 daddr @cn_ip6 return
}
}
}
start_nft_route() { #nftables-route通用工具
#$1:name $2:hook(prerouting/output) $3:type(nat/mangle/filter) $4:priority(-100/-150)
[ "$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" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')"
#添加新链
@@ -39,9 +39,9 @@ start_nft_route() { #nftables-route通用工具
#过滤常用端口
[ -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} 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} 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 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 ] && {
CN_IP=$(awk '{printf "%s, ",$1}' "$BINDIR"/cn_ip.txt)
[ -n "$CN_IP" ] && {
nft add set inet shellcrash cn_ip { type ipv4_addr \; flags interval \; }
nft add element inet shellcrash cn_ip { $CN_IP }
nft add rule inet shellcrash $1 ip daddr @cn_ip return
}
}
nft add set inet shellcrash cn_ip { type ipv4_addr \; flags interval \; }
nft add element inet shellcrash cn_ip { $CN_IP }
nft add rule inet shellcrash $1 ip daddr @cn_ip return
}
}
#局域网ipv6支持
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"
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')"
add_ip6_route "$1"
add_ip6_route "$1"
else
nft add rule inet shellcrash $1 meta nfproto ipv6 return
fi
#屏蔽quic
[ "$quic_rj" = 'ON' -a "$lan_proxy" = true ] && nft add rule inet shellcrash $1 udp dport {443, 8443} return
#屏蔽quic
[ "$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"
#处理特殊路由
@@ -104,10 +104,10 @@ start_nft_route() { #nftables-route通用工具
#nft add rule inet shellcrash local_tproxy log prefix \"pre\" level debug
}
start_nft_dns() { #nftables-dns
[ "$1" = 'prerouting' ] && {
HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g')
HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')
}
[ "$1" = 'prerouting' ] && {
HOST_IP=$(echo $host_ipv4 | 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" = 'prerouting_vm' ] && HOST_IP="$(echo $vm_ipv4 | sed 's/[[:space:]]\+/, /g')"
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"
}
start_nft_wan() { #nftables公网防火墙
HOST_IP=$(echo $host_ipv4 | sed 's/[[:space:]]\+/, /g')
HOST_IP6=$(echo $host_ipv6 | sed 's/[[:space:]]\+/, /g')
HOST_IP=$(echo $host_ipv4 | 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 rule inet shellcrash input iif lo accept #本机请求全放行
#端口放行
[ -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/,/, /")
#端口放行
[ -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/,/, /")
[ -n "$accept_ports" ] && {
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 udp dport $fw_wan_nfports meta mark set 0x67890 accept
}
#端口拦截
reject_ports="{ $mix_port, $db_port }"
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 tcp dport $reject_ports reject
nft add rule inet shellcrash input udp dport $reject_ports reject
#fw4特殊处理
nft list chain inet fw4 input >/dev/null 2>&1 && \
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 udp dport $fw_wan_nfports meta mark set 0x67890 accept
}
#端口拦截
reject_ports="{ $mix_port, $db_port }"
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 tcp dport $reject_ports reject
nft add rule inet shellcrash input udp dport $reject_ports reject
#fw4特殊处理
nft list chain inet fw4 input >/dev/null 2>&1 && \
nft list chain inet fw4 input | grep -q '67890' || \
nft insert rule inet fw4 input meta mark 0x67890 accept 2>/dev/null
}

View File

@@ -14,27 +14,27 @@
#设置策略路由
[ "$firewall_area" != 4 ] && {
[ "$redir_mod" = "Tproxy" ] && ip route add local default dev lo table $table 2>/dev/null
[ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && {
i=1
while [ -z "$(ip route list | grep utun)" -a "$i" -le 29 ]; do
sleep 1
i=$((i + 1))
done
if [ -z "$(ip route list | grep utun)" ]; then
logger "找不到tun模块放弃启动tun相关防火墙规则" 31
else
ip route add default dev utun table $table && tun_statu=true
fi
}
[ "$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" = "Tproxy" ] && ip route add local default dev lo table $table 2>/dev/null
[ "$redir_mod" = "Tun" -o "$redir_mod" = "Mix" ] && {
i=1
while [ -z "$(ip route list | grep utun)" -a "$i" -le 29 ]; do
sleep 1
i=$((i + 1))
done
if [ -z "$(ip route list | grep utun)" ]; then
logger "找不到tun模块放弃启动tun相关防火墙规则" 31
else
ip route add default dev utun table $table && tun_statu=true
fi
}
[ "$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
}
#添加ipv6路由
[ "$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
[ -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" = "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
[ "$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
@@ -44,11 +44,11 @@
[ "$firewall_mod" = 'nftables' ] && . "$CRASHDIR"/starts/fw_nftables.sh && start_nftables
#修复部分虚拟机dns查询失败的问题
[ "$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}')
sed -i "$line i\nameserver 127.0.0.1 #shellcrash-dns-repair" /etc/resolv.conf >/dev/null 2>&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
}
#移除openwrt-dnsmasq的DNS重定向
[ "$(uci get dhcp.@dnsmasq[0].dns_redirect 2>/dev/null)" = 1 ] && {
uci del dhcp.@dnsmasq[0].dns_redirect
uci commit dhcp.@dnsmasq[0]
uci del dhcp.@dnsmasq[0].dns_redirect
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/,$//")
#重置iptables相关规则
ckcmd iptables && {
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
#dns
$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 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
#redir
$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 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
#vm_dns
$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
#vm_redir
$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
#TPROXY&tun
$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 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 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 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 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
#tun
$iptable -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC
[ "$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 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
for ip in $host_ipv4; do
$iptable -D INPUT -s $ip -j ACCEPT 2>/dev/null
done
$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 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
#清理shellcrash自建表
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 -X "$text" 2>/dev/null
done
for text in shellcrash_mark shellcrash_mark_out; do
$iptable -t mangle -F "$text" 2>/dev/null
$iptable -t mangle -X "$text" 2>/dev/null
done
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
#dns
$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 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
#redir
$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 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
#vm_dns
$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
#vm_redir
$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
#TPROXY&tun
$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 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 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 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 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
#tun
$iptable -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC
[ "$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 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
for ip in $host_ipv4; do
$iptable -D INPUT -s $ip -j ACCEPT 2>/dev/null
done
$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 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
#清理shellcrash自建表
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 -X "$text" 2>/dev/null
done
for text in shellcrash_mark shellcrash_mark_out; do
$iptable -t mangle -F "$text" 2>/dev/null
$iptable -t mangle -X "$text" 2>/dev/null
done
}
#重置ipv6规则
ckcmd ip6tables && {
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
#dns
$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
#redir
$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 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 -D INPUT -p tcp --dport 53 -j REJECT 2>/dev/null
$ip6table -D INPUT -p udp --dport 53 -j REJECT 2>/dev/null
#mark
$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 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 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 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 -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 udp -j TPROXY --on-port $tproxy_port 2>/dev/null
#tun
$ip6table -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC
[ "$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 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
for ip in $host_ipv6; do
$ip6table -D INPUT -s $ip -j ACCEPT 2>/dev/null
done
$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 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
#清理shellcrash自建表
for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do
$ip6table -t nat -F "$text" 2>/dev/null
$ip6table -t nat -X "$text" 2>/dev/null
done
for text in shellcrashv6_mark shellcrashv6_mark_out; do
$ip6table -t mangle -F "$text" 2>/dev/null
$ip6table -t mangle -X "$text" 2>/dev/null
done
$ip6table -t mangle -F shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -X shellcrashv6_mark 2>/dev/null
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
#dns
$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
#redir
$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 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 -D INPUT -p tcp --dport 53 -j REJECT 2>/dev/null
$ip6table -D INPUT -p udp --dport 53 -j REJECT 2>/dev/null
#mark
$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 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 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 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 -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 udp -j TPROXY --on-port $tproxy_port 2>/dev/null
#tun
$ip6table -D FORWARD -o utun -j ACCEPT 2>/dev/null
#屏蔽QUIC
[ "$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 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
for ip in $host_ipv6; do
$ip6table -D INPUT -s $ip -j ACCEPT 2>/dev/null
done
$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 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
#清理shellcrash自建表
for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do
$ip6table -t nat -F "$text" 2>/dev/null
$ip6table -t nat -X "$text" 2>/dev/null
done
for text in shellcrashv6_mark shellcrashv6_mark_out; do
$ip6table -t mangle -F "$text" 2>/dev/null
$ip6table -t mangle -X "$text" 2>/dev/null
done
$ip6table -t mangle -F shellcrashv6_mark 2>/dev/null
$ip6table -t mangle -X shellcrashv6_mark 2>/dev/null
}
#清理ipset规则
ipset destroy cn_ip >/dev/null 2>&1

View File

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

View File

@@ -2,8 +2,8 @@
singbox_check() { #singbox启动前检查
#检测singboxr专属功能
[ "$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
#预下载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
fi
# 输出
echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"','
echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"','
}
modify_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
#生成endpoints.json
[ "$ts_service" = ON ] || [ "$wg_service" = ON ] && [ "$zip_type" != upx ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_endpoints.sh
}
#生成log.json
[ "$ts_service" = ON ] || [ "$wg_service" = ON ] && [ "$zip_type" != upx ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_endpoints.sh
}
#生成log.json
cat >"$TMPDIR"/jsons/log.json <<EOF
{ "log": { "level": "info", "timestamp": true } }
EOF
@@ -75,7 +75,7 @@ EOF
"path": [
$custom_hosts
"$HOME/.hosts",
"/etc/hosts"
"/etc/hosts"
],
"predefined": {
"localhost": [
@@ -86,28 +86,28 @@ EOF
"time.facebook.com": "203.107.6.88"
}
}
],
],
"rules": [
{
"ip_accept_any": true,
"server": "hosts"
}
]}
]}
}
EOF
fi
#生成dns.json
[ "$ipv6_dns" != "OFF" ] && strategy='prefer_ipv4' || strategy='ipv4_only'
#获取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": "selector"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
[ -z "$auto_detour" ] && auto_detour='"DIRECT"'
#ecs优化
[ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh
client_subnet='"client_subnet": "'"$ecs_address"'",'
}
#ecs优化
[ "$ecs_subnet" = ON ] && {
. "$CRASHDIR"/libs/get_ecsip.sh
client_subnet='"client_subnet": "'"$ecs_address"'",'
}
#根据dns模式生成
[ "$dns_mod" = "redir_host" ] && {
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
#生成add_rule_set.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
{
"route": {
@@ -158,14 +158,14 @@ EOF
{
"tag": "dns_proxy",
$(parse_singbox_dns "$dns_fallback")
"routing_mark": $routing_mark,
"detour": $auto_detour,
"routing_mark": $routing_mark,
"detour": $auto_detour,
"domain_resolver": "dns_resolver"
},
{
"tag": "dns_direct",
$(parse_singbox_dns "$dns_nameserver")
"routing_mark": $routing_mark,
"routing_mark": $routing_mark,
"domain_resolver": "dns_resolver"
},
{
@@ -177,7 +177,7 @@ EOF
{
"tag": "dns_resolver",
$(parse_singbox_dns "$dns_resolver")
"routing_mark": $routing_mark
"routing_mark": $routing_mark
}
],
"rules": [
@@ -186,14 +186,14 @@ EOF
$fake_ip_filter_domain
$fake_ip_filter_suffix
$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
$proxy_dns
$proxy_dns
],
"final": "dns_proxy",
"strategy": "$strategy",
"strategy": "$strategy",
"independent_cache": true,
$client_subnet
$client_subnet
"reverse_mapping": true
}
}
@@ -263,10 +263,10 @@ EOF
}
EOF
#inbounds.json添加自定义入站
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_inbounds.sh
}
[ "$vms_service" = ON ] || [ "$sss_service" = ON ] && {
. "$CRASHDIR"/configs/gateway.cfg
. "$CRASHDIR"/libs/sb_inbounds.sh
}
if [ "$redir_mod" = "Mix" -o "$redir_mod" = "Tun" ]; then
[ "ipv6_redir" = 'ON' ] && ipv6_address='"fe80::e5c5:2469:d09b:609a/64",'
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
{
"outbounds": [
$add_direct
$add_reject
$add_global
$add_direct
$add_reject
$add_global
]
}
EOF
#生成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
{
"experimental": {
"clash_api": {
"external_controller": "0.0.0.0:$db_port",
"external_ui": "ui",
"external_ui_download_url": "$external_ui_url",
"external_ui_download_url": "$external_ui_url",
"secret": "$secret",
"default_mode": "Rule"
}$urltest_unified_delay

View File

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

View File

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

View File

@@ -2,14 +2,14 @@
. "$CRASHDIR"/libs/check_cmd.sh
start_legacy(){
ckcmd nohup && _nohup=nohup
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"
elif ckcmd setsid; then
ckcmd nohup && _nohup=nohup
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"
elif ckcmd setsid; then
$_nohup setsid $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid"
else
$_nohup $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid"
fi
else
$_nohup $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid"
fi
}

View File

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