mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-12 00:11:31 +00:00
~重写了webget函数,改为优先使用wget命令
~修复setconfig函数式可能导致错误设定的bug ~修复在线获取配置文件功能报错的bug
This commit is contained in:
@@ -153,7 +153,7 @@ setconfig() { #脚本配置工具
|
|||||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||||
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
||||||
if grep -q "^${1}=" "$configpath"; then
|
if grep -q "^${1}=" "$configpath"; then
|
||||||
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
|
sed -i "s#^${1}=.*#${1}=${2}#g" "$configpath"
|
||||||
else
|
else
|
||||||
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ setconfig() {
|
|||||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||||
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
||||||
if grep -q "^${1}=" "$configpath"; then
|
if grep -q "^${1}=" "$configpath"; then
|
||||||
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
|
sed -i "s#^${1}=.*#${1}=${2}#g" "$configpath"
|
||||||
else
|
else
|
||||||
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ setconfig() { #脚本配置工具
|
|||||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||||
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
|
||||||
if grep -q "^${1}=" "$configpath"; then
|
if grep -q "^${1}=" "$configpath"; then
|
||||||
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
|
sed -i "s#^${1}=.*#${1}=${2}#g" "$configpath"
|
||||||
else
|
else
|
||||||
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
printf '%s=%s\n' "$1" "$2" >>"$configpath"
|
||||||
fi
|
fi
|
||||||
@@ -290,15 +290,16 @@ parse_singbox_dns() { #singbox的dns分割工具
|
|||||||
echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"','
|
echo '"type": "'"$type"'", "server": "'"$server"'", "server_port": '"$port"','
|
||||||
}
|
}
|
||||||
urlencode() {
|
urlencode() {
|
||||||
local i c hex
|
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
for i in $(printf '%s' "$1" | od -An -tx1); do
|
printf '%s' "$1" \
|
||||||
case "$i" in
|
| hexdump -v -e '/1 "%02X\n"' \
|
||||||
2d|2e|5f|7e|3[0-9]|4[1-9A-Fa-f]|5[A-Fa-f]|6[1-9A-Fa-f]|7[0-9A-Ea-e])
|
| while read -r hex; do
|
||||||
printf "\\$(printf '%03o' "0x$i")"
|
case "$hex" in
|
||||||
|
2D|2E|5F|7E|3[0-9]|4[1-9A-F]|5[A-F]|6[1-9A-F]|7[0-9A-E])
|
||||||
|
printf "\\$(printf '%03o' "0x$hex")"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf '%%%02X' "0x$i"
|
printf "%%%s" "$hex"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -389,7 +390,11 @@ get_core_config() { #下载内核配置文件
|
|||||||
#如果传来的是Url链接则合成Https链接,否则直接使用Https链接
|
#如果传来的是Url链接则合成Https链接,否则直接使用Https链接
|
||||||
if [ -z "$Https" ]; then
|
if [ -z "$Https" ]; then
|
||||||
#Urlencord转码处理保留字符
|
#Urlencord转码处理保留字符
|
||||||
urlencodeUrl="exclude=$(urlencode "$exclude")&include=$(urlencode "$include")&url=$(urlencode "$Url")&config=$(urlencode "$Config")"
|
if ckcmd hexdump;then
|
||||||
|
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}"
|
Https="${Server}/sub?target=${target}&${Server_ua}=${user_agent}&insert=true&new_name=true&scv=true&udp=true&${urlencodeUrl}"
|
||||||
url_type=true
|
url_type=true
|
||||||
fi
|
fi
|
||||||
@@ -402,7 +407,7 @@ get_core_config() { #下载内核配置文件
|
|||||||
core_config_new="$TMPDIR"/${target}_config.${format}
|
core_config_new="$TMPDIR"/${target}_config.${format}
|
||||||
rm -rf ${core_config_new}
|
rm -rf ${core_config_new}
|
||||||
$0 webget "$core_config_new" "$Https" echoon rediron skipceron "$user_agent"
|
$0 webget "$core_config_new" "$Https" echoon rediron skipceron "$user_agent"
|
||||||
if [ "$?" = "1" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
if [ -z "$url_type" ]; then
|
if [ -z "$url_type" ]; then
|
||||||
echo "-----------------------------------------------"
|
echo "-----------------------------------------------"
|
||||||
logger "配置文件获取失败!" 31
|
logger "配置文件获取失败!" 31
|
||||||
@@ -410,7 +415,7 @@ get_core_config() { #下载内核配置文件
|
|||||||
echo "-----------------------------------------------"
|
echo "-----------------------------------------------"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
if [ "$retry" -ge 3 ]; then
|
if [ -n "$retry" ] && [ "$retry" -ge 3 ]; then
|
||||||
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
|
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
|
||||||
echo -e "\033[32m也可用浏览器下载以上链接后,使用WinSCP手动上传到/tmp目录后执行crash命令本地导入!\033[0m"
|
echo -e "\033[32m也可用浏览器下载以上链接后,使用WinSCP手动上传到/tmp目录后执行crash命令本地导入!\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -2164,48 +2169,51 @@ init)
|
|||||||
;;
|
;;
|
||||||
webget)
|
webget)
|
||||||
#设置临时代理
|
#设置临时代理
|
||||||
if [ -n "$(pidof CrashCore)" ]; then
|
if pidof CrashCore >/dev/null; then
|
||||||
[ -n "$authentication" ] && auth="$authentication@"
|
[ -n "$authentication" ] && auth="$authentication@" || auth=""
|
||||||
export all_proxy="http://${auth}127.0.0.1:$mix_port"
|
export all_proxy="http://${auth}127.0.0.1:$mix_port"
|
||||||
url=$(echo $3 | sed 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' | sed 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
|
url=$(printf '%s\n' "$3" |
|
||||||
else
|
sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \
|
||||||
url=$(echo $3 | sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#')
|
-e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
|
||||||
fi
|
else
|
||||||
|
url=$(printf '%s\n' "$3" |
|
||||||
|
sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#')
|
||||||
|
fi
|
||||||
#参数【$2】代表下载目录,【$3】代表在线地址
|
#参数【$2】代表下载目录,【$3】代表在线地址
|
||||||
#参数【$4】代表输出显示,【$5】不启用重定向
|
#参数【$4】代表输出显示,【$5】不启用重定向
|
||||||
#参数【$6】代表验证证书,【$7】使用自定义UA
|
#参数【$6】代表验证证书,【$7】使用自定义UA
|
||||||
[ -n "$7" ] && agent="--user-agent \"$7\""
|
[ -n "$7" ] && agent="--user-agent \"$7\""
|
||||||
if curl --version >/dev/null 2>&1; then
|
if wget --version >/dev/null 2>&1; then
|
||||||
|
[ "$4" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
||||||
|
[ "$5" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
|
||||||
|
[ "$6" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
|
||||||
|
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$2" "$url" && exit 0 #成功则退出否则重试
|
||||||
|
wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$2" "$3"
|
||||||
|
exit $?
|
||||||
|
elif curl --version >/dev/null 2>&1; then
|
||||||
[ "$4" = "echooff" ] && progress='-s' || progress='-#'
|
[ "$4" = "echooff" ] && progress='-s' || progress='-#'
|
||||||
[ "$5" = "rediroff" ] && redirect='' || redirect='-L'
|
[ "$5" = "rediroff" ] && redirect='' || redirect='-L'
|
||||||
[ "$6" = "skipceroff" ] && certificate='' || certificate='-k'
|
[ "$6" = "skipceroff" ] && certificate='' || certificate='-k'
|
||||||
[ -n "$7" ] && agent="--user-agent \"$7\""
|
|
||||||
if curl --version | grep -q '^curl 8.' && ckcmd base64; then
|
if curl --version | grep -q '^curl 8.' && ckcmd base64; then
|
||||||
auth_b64=$(echo -n "$authentication" | base64)
|
auth_b64=$(printf '%s' "$authentication" | base64)
|
||||||
result=$(curl $agent -w %{http_code} --connect-timeout 3 --proxy-header "Proxy-Authorization: Basic $auth_b64" $progress $redirect $certificate -o "$2" "$url")
|
result=$(curl $agent -w '%{http_code}' --connect-timeout 3 --proxy-header "Proxy-Authorization: Basic $auth_b64" $progress $redirect $certificate -o "$2" "$url")
|
||||||
else
|
else
|
||||||
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$url")
|
result=$(curl $agent -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$2" "$url")
|
||||||
fi
|
fi
|
||||||
[ "$result" != "200" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 5 $progress $redirect $certificate -o "$2" "$3")
|
[ "$result" = "200" ] && exit 0 #成功则退出否则重试
|
||||||
else
|
export all_proxy=""
|
||||||
if wget --version >/dev/null 2>&1; then
|
result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$2" "$3")
|
||||||
[ "$4" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
[ "$result" = "200" ]
|
||||||
[ "$5" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
|
exit $?
|
||||||
[ "$6" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
|
elif ckcmd wget;then
|
||||||
[ -n "$7" ] && agent="--user-agent=\"$7\""
|
|
||||||
timeout='--timeout=5'
|
|
||||||
fi
|
|
||||||
[ "$4" = "echoon" ] && progress=''
|
|
||||||
[ "$4" = "echooff" ] && progress='-q'
|
[ "$4" = "echooff" ] && progress='-q'
|
||||||
wget -Y on $agent $progress $redirect $certificate $timeout -O "$2" "$url"
|
wget -Y on $progress -O "$2" "$url" && exit 0 #成功则退出否则重试
|
||||||
if [ "$?" != "0" ]; then
|
wget -Y off $progress -O "$2" "$3"
|
||||||
wget -Y off $agent $progress $redirect $certificate $timeout -O "$2" "$3"
|
exit $?
|
||||||
[ "$?" = "0" ] && result="200"
|
else
|
||||||
else
|
echo "找不到可用下载工具!!!请安装Curl或Wget!!!"
|
||||||
result="200"
|
exit 1
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
[ "$result" = "200" ] && exit 0 || exit 1
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
"$1" "$2" "$3" "$4" "$5" "$6" "$7"
|
"$1" "$2" "$3" "$4" "$5" "$6" "$7"
|
||||||
|
|||||||
Reference in New Issue
Block a user