v1.3.9-test

~本机代理相关逻辑优化及bug修复
~本机代理功能增加对保守模式的支持
~绕过内核功能增加ipset模块检测
~增加对低版本wget命令的支持
~增加了使用内核保存节点列表的逻辑
This commit is contained in:
juewuy 2021-06-16 18:55:14 +08:00
parent e6bc100326
commit 97cb5479b1
6 changed files with 92 additions and 63 deletions

View File

@ -37,19 +37,17 @@ opkg update && opkg install curl
##### ~Use curl:<br>
```Shell
#Release version - by github
sh -c "$(curl -kfsSl --resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master/install.sh)" && source /etc/profile &> /dev/null
#Release version - by jsdelivrCDN
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install.sh)" && source /etc/profile &> /dev/null
#Test version - by github
sh -c "$(curl -kfsSl --resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master/install.sh)" -s 1 && source /etc/profile &> /dev/null
#By github
export url='https://raw.githubusercontent.com/juewuy/ShellClash/master' && sh -c "$(curl -s $url/install_n.sh)" && source /etc/profile &> /dev/null
#By jsdelivrCDN
export url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master' && sh -c "$(curl -s $url/install_n.sh)" && source /etc/profile &> /dev/null
```
##### ~Use wget<br>
```sh
#Release version - by jsdelivrCDN
wget -q --no-check-certificate -O /tmp/install.sh https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install.sh && sh /tmp/install.sh && source /etc/profile &> /dev/null
#By jsdelivrCDN
export url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master' && wget -q --no-check-certificate -O /tmp/install.sh $url/install_n.sh && sh /tmp/install.sh && source /etc/profile &> /dev/null
```
~**After installation by non-root users**, please execute the following additional commands to read environment variables:<br>

Binary file not shown.

View File

@ -1,4 +1,4 @@
clash_v=1.6.0
clashpre_v=2021.05.08
GeoIP_v=20210611
versionsh=1.3.8
versionsh=1.3.9

View File

@ -464,10 +464,10 @@ macfilter(){
}
localproxy(){
[ -z "$local_proxy" ] && local_proxy='未开启'
[ -z "$local_proxy_type" ] && local_proxy_type='环境变量'
[ -z "$local_type" ] && local_type='环境变量'
[ "$local_proxy" = "已开启" ] && proxy_set='禁用' || proxy_set='启用'
echo -----------------------------------------------
echo -e "\033[33m当前本机代理配置方式为\033[32m$local_proxy_type\033[0m"
echo -e "\033[33m当前本机代理配置方式为\033[32m$local_type\033[0m"
echo -----------------------------------------------
echo -e " 1 \033[36m$proxy_set本机代理\033[0m"
echo -e " 2 使用\033[32m环境变量\033[0m方式配置"
@ -490,39 +490,28 @@ localproxy(){
else
local_proxy=已开启
$clashdir/start.sh set_proxy $mix_port $db_port
echo -e "\033[32m已经成功使用$local_proxy_type方式配置本机代理~\033[0m"
[ "$local_proxy_type" = "环境变量" ] && echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m" && sleep 1
[ "$local_proxy_type" = "iptables增强模式" ] && $clashdir/start.sh start
echo -e "\033[32m已经成功使用$local_type方式配置本机代理~\033[0m"
[ "$local_type" = "环境变量" ] && echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m" && sleep 1
[ "$local_type" = "iptables增强模式" ] && $clashdir/start.sh start
fi
else
local_proxy=未开启
$clashdir/start.sh unset_proxy
echo -e "\033[33m已经停用本机代理规则\033[0m"
[ "$local_proxy_type" = "环境变量" ] && echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m" && sleep 1
$clashdir/start.sh stop
echo -e "\033[33m已经停用本机代理规则并停止clash服务\033[0m"
[ "$local_type" = "环境变量" ] && echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m" && sleep 1
fi
setconfig local_proxy $local_proxy
elif [ "$num" = 2 ]; then
local_proxy_type="环境变量"
setconfig local_proxy_type $local_proxy_type
local_type="环境变量"
setconfig local_type $local_type
localproxy
elif [ "$num" = 3 ]; then
[ -w /etc/systemd/system/clash.service ] && servdir=/etc/systemd/system/clash.service
[ -w /usr/lib/systemd/system/clash.service ] && servdir=/usr/lib/systemd/system/clash.service
[ -x /bin/su ] && servdir=1
if [ -n "$servdir" ];then
#检测用户如无则创建并提权
if [ -z "$(id shellclash 2>/dev/null | grep 'root')" ];then
userdel shellclash 2>/dev/null
useradd shellclash -u 7890
sed -Ei s/7890:7890/0:7890/g /etc/passwd
fi
#停止clash服务
$clashdir/start.sh stop
#修改service文件使用shellclash用户运行clash服务
setconfig ExecStart "su\ shellclash\ -c\ \"$bindir/clash\ -d\ $bindir\"" $servdir
systemctl daemon-reload
#修改模式变量
local_proxy_type="iptables增强模式"
setconfig local_proxy_type $local_proxy_type
local_type="iptables增强模式"
setconfig local_type $local_type
else
echo -e "\033[31m当前设备无法使用增强模式\033[0m"
sleep 1
@ -842,7 +831,10 @@ clashadv(){
elif [ "$num" = 5 ]; then
echo -----------------------------------------------
if [ "$dns_mod" = "fake-ip" ];then
if ipset -v >/dev/null 2>&1;then
echo -e "\033[31m当前设备缺少ipset模块无法启用绕过功能\033[0m"
sleep 1
elif [ "$dns_mod" = "fake-ip" ];then
echo -e "\033[31m不支持fake-ip模式请将DNS模式更换为Redir-host\033[0m"
sleep 1
else

View File

@ -520,7 +520,7 @@ setgeo(){
echo -----------------------------------------------
[ "$geotype" = "Country.mmdb" ] && geo_type=全球版 || geo_type=精简版
[ -n "$geo_type" ] && echo -e "当前使用的是\033[47;30m$geo_type数据库\033[0m"
echo -e "\033[36m请选择需要更新的GeoIP/CN_IP数据库\033[0m"
echo -e "\033[36m请选择需要更新/切换的GeoIP/CN_IP数据库\033[0m"
echo -----------------------------------------------
echo -e " 1 由\033[32malecthw\033[0m提供的全球版GeoIP数据库(约4mb)"
echo -e " 2 由\033[32mHackl0us\033[0m提供的精简版CN-IP数据库(约0.1mb)"
@ -536,10 +536,16 @@ setgeo(){
geotype=cn_mini.mmdb
geoname=Country.mmdb
getgeo
elif [ "$num" = '3' ] && [ "$cn_ip_route" = "已开启" ]; then
geotype=china_ip_list.txt
geoname=cn_ip.txt
getgeo
elif [ "$num" = '3' ]; then
if [ "$cn_ip_route" = "已开启" ]; then
geotype=china_ip_list.txt
geoname=cn_ip.txt
getgeo
else
echo -----------------------------------------------
echo -e "\033[31m未开启绕过内核功能无需更新CN-IP文件\033[0m"
sleep 1
fi
else
update
fi
@ -789,7 +795,7 @@ update(){
echo -----------------------------------------------
echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh\033[0m"
echo -e " 2 切换\033[33mclash核心 \033[33m$clash_v\033[0m > \033[32m$clash_n\033[0m"
echo -e " 3 更新\033[32mGeoIP/CN_IP \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m"
echo -e " 3 更新\033[32mGeoIP/CN-IP \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m"
echo -e " 4 安装本地\033[35mDashboard\033[0m面板"
echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m"
echo -e " 6 查看\033[32mPAC\033[0m自动代理配置"
@ -839,6 +845,8 @@ update(){
echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m"
echo -e "感谢:\033[32msubconverter \033[0m作者\033[36m tindy2013\033[0m 项目地址:\033[32mhttps://github.com/tindy2013/subconverter\033[0m"
echo -e "感谢:\033[32malecthw提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m"
echo -e "感谢:\033[32mHackl0us提供的GeoIP精简数据库\033[0m 项目地址:\033[32mhttps://github.com/Hackl0us/GeoIP2-CN\033[0m"
echo -e "感谢:\033[32m17mon提供的CN-IP列表\033[0m 项目地址:\033[32mhttps://github.com/17mon/china_ip_list\033[0m"
echo -e "感谢:\033[32myacd \033[0m作者\033[36m haishanh\033[0m 项目地址:\033[32mhttps://github.com/haishanh/yacd\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
sleep 2
@ -928,7 +936,19 @@ userguide(){
setconfig clashcore "clash"
echo -----------------------------------------------
echo -e "\033[36m请选择设置本机代理的方式\033[0m"
localproxy
echo -e " 1 使用\033[32m环境变量\033[0m方式配置(不支持部分应用)"
echo -e " 2 使用\033[32miptables增强模式\033[0m配置(不支持OpenWrt)"
echo -e " 0 稍后设置"
read -p "请输入对应数字 > " num
if [ "$num" = 1 ]; then
local_proxy=已开启
local_type=环境变量
elif [ "$num" = 2 ]; then
local_proxy=已开启
local_type=iptables增强模式
fi
setconfig local_proxy $local_proxy
setconfig local_type $local_type
fi
}
forwhat

View File

@ -60,14 +60,18 @@ webget(){
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o $1 $2)
[ "$result" != "200" ] && export all_proxy="" && result=$(curl -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o $1 $2)
else
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
if wget --version > /dev/null 2>&1;then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
[ "$5" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
timeout='--timeout=3'
fi
[ "$3" = "echoon" ] && progress=''
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
[ "$5" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
[ "$3" = "echooff" ] && progress='-q'
[ -n "$6" ] && agent='--user-agent="clash"'
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O $1 $2
wget -Y on $agent $progress $redirect $certificate $timeout -O $1 $2
if [ "$?" != "0" ];then
wget $agent $progress $redirect $certificate --timeout=3 -O $1 $2
wget $agent $progress $redirect $certificate $timeout -O $1 $2
[ "$?" = "0" ] && result="200"
else
result="200"
@ -276,7 +280,7 @@ secret: $secret
$tun
$exper
$dns
store-selected: false
store-selected: $restore
EOF
###################################
[ -f $clashdir/user.yaml ] && yaml_user=$clashdir/user.yaml
@ -531,10 +535,6 @@ web_save(){
curl -s -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1"
elif [ -n "$(wget --help 2>&1|grep '\-\-method')" ];then
wget -q --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" -O - "$1"
else
logger 当前系统未安装curl且wget的版本太低无法保存节点配置 31
getconfig
cronset '保存节点配置'
fi
}
#使用get_save获取面板节点设置
@ -555,7 +555,7 @@ web_restore(){
put_save(){
if curl --version > /dev/null 2>&1;then
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1" -d "$2" >/dev/null
else
elif wget --version > /dev/null 2>&1;then
wget -q --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null
fi
}
@ -642,7 +642,12 @@ bfstart(){
if [ -f $clashdir/ui/index.html -a ! -f $bindir/ui/index.html ];then
cp -rf $clashdir/ui $bindir
fi
catpac #生成pac文件
#检查curl或wget支持
curl --version > /dev/null 2>&1
[ "$?" = 1 ] && wget --version > /dev/null 2>&1
[ "$?" = 1 ] && restore=true || restore=false
#生成pac文件
catpac
#检查yaml配置文件
if [ ! -f $clashdir/config.yaml ];then
if [ -n "$Url" -o -n "$Https" ];then
@ -654,6 +659,18 @@ bfstart(){
exit 1
fi
fi
#本机代理准备
if [ "$local_proxy" = "已开启" -a "$local_type" = "iptables增强模式" ];then
if [ -z "$(id shellclash 2>/dev/null | grep 'root')" ];then
userdel shellclash 2>/dev/null
useradd shellclash -u 7890
sed -Ei s/7890:7890/0:7890/g /etc/passwd
fi
if [ "$start_old" != "已开启" ];then
setconfig ExecStart "/bin/su\ shellclash\ -c\ \"$bindir/clash\ -d\ $bindir\"" $servdir
systemctl daemon-reload >/dev/null
fi
fi
}
afstart(){
@ -673,8 +690,10 @@ afstart(){
#加载定时任务
[ -f $clashdir/cron ] && crontab $clashdir/cron
#启用面板配置自动保存
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
if [ "$restore" = false ];then
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
fi
else
logger "clash服务启动失败请查看报错信息" 31
$bindir/clash -t -d $bindir
@ -685,7 +704,11 @@ afstart(){
}
start_old(){
#使用传统后台执行二进制文件的方式执行
$bindir/clash -d $bindir >/dev/null &
if [ "$local_proxy" = "已开启" -a "$local_type" = "iptables增强模式" ];then
su shellclash -c "$bindir/clash -d $bindir >/dev/null" &
else
$bindir/clash -d $bindir >/dev/null &
fi
afstart
$0 daemon
}
@ -719,7 +742,7 @@ start)
;;
stop)
getconfig
[ -n "$(pidof clash)" ] && web_save #保存面板配置
[ -n "$(pidof clash)" ] && [ "$restore" = false ] && web_save #保存面板配置
#删除守护进程&面板配置自动保存
cronset "clash保守模式守护进程"
cronset "保存节点配置"
@ -731,7 +754,7 @@ stop)
fi
PID=$(pidof clash) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
stop_iptables #清理iptables
[ "$local_proxy" = "已开启" ] && $0 unset_proxy #禁用本机代理
$0 unset_proxy #禁用本机代理
;;
restart)
$0 stop
@ -772,11 +795,7 @@ cronset)
;;
set_proxy)
getconfig
#iptables增强模式
if [ "$local_proxy_type" = "iptables增强模式" ];then
start_output
#环境变量方式
else
if [ "$local_type" = "环境变量" ];then
[ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile
echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >> $profile