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> ##### ~Use curl:<br>
```Shell ```Shell
#Release version - by github #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 export url='https://raw.githubusercontent.com/juewuy/ShellClash/master' && sh -c "$(curl -s $url/install_n.sh)" && source /etc/profile &> /dev/null
#Release version - by jsdelivrCDN #By jsdelivrCDN
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install.sh)" && source /etc/profile &> /dev/null export url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master' && sh -c "$(curl -s $url/install_n.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
``` ```
##### ~Use wget<br> ##### ~Use wget<br>
```sh ```sh
#Release version - by jsdelivrCDN #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 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> ~**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 clash_v=1.6.0
clashpre_v=2021.05.08 clashpre_v=2021.05.08
GeoIP_v=20210611 GeoIP_v=20210611
versionsh=1.3.8 versionsh=1.3.9

View File

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

View File

@@ -520,7 +520,7 @@ setgeo(){
echo ----------------------------------------------- echo -----------------------------------------------
[ "$geotype" = "Country.mmdb" ] && geo_type=全球版 || geo_type=精简版 [ "$geotype" = "Country.mmdb" ] && geo_type=全球版 || geo_type=精简版
[ -n "$geo_type" ] && echo -e "当前使用的是\033[47;30m$geo_type数据库\033[0m" [ -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 -----------------------------------------------
echo -e " 1 由\033[32malecthw\033[0m提供的全球版GeoIP数据库(约4mb)" echo -e " 1 由\033[32malecthw\033[0m提供的全球版GeoIP数据库(约4mb)"
echo -e " 2 由\033[32mHackl0us\033[0m提供的精简版CN-IP数据库(约0.1mb)" echo -e " 2 由\033[32mHackl0us\033[0m提供的精简版CN-IP数据库(约0.1mb)"
@@ -536,10 +536,16 @@ setgeo(){
geotype=cn_mini.mmdb geotype=cn_mini.mmdb
geoname=Country.mmdb geoname=Country.mmdb
getgeo getgeo
elif [ "$num" = '3' ] && [ "$cn_ip_route" = "已开启" ]; then elif [ "$num" = '3' ]; then
geotype=china_ip_list.txt if [ "$cn_ip_route" = "已开启" ]; then
geoname=cn_ip.txt geotype=china_ip_list.txt
getgeo geoname=cn_ip.txt
getgeo
else
echo -----------------------------------------------
echo -e "\033[31m未开启绕过内核功能无需更新CN-IP文件\033[0m"
sleep 1
fi
else else
update update
fi fi
@@ -789,7 +795,7 @@ update(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh\033[0m" 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 " 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 " 4 安装本地\033[35mDashboard\033[0m面板"
echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m" echo -e " 5 安装/更新本地\033[33m根证书文件\033[0m"
echo -e " 6 查看\033[32mPAC\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[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[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[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[32myacd \033[0m作者\033[36m haishanh\033[0m 项目地址:\033[32mhttps://github.com/haishanh/yacd\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m" echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
sleep 2 sleep 2
@@ -928,7 +936,19 @@ userguide(){
setconfig clashcore "clash" setconfig clashcore "clash"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m请选择设置本机代理的方式\033[0m" 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 fi
} }
forwhat forwhat

View File

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