v0.8.0更新

~大幅度优化脚本UI及层级
~增加在线更新脚本功能
~增加在线更新、替换clash核心功能
~内置dns增加redir-host支持,解决了部分应用无法连接的bug
~优化了配置文件修饰途径,现在支持通过scp上传任意yaml配置文件
~增加了直接导入完整订阅链接的选项(待测试)
~增加了更多的订阅后端服务器
This commit is contained in:
juewuy
2020-08-06 19:57:28 +08:00
parent 39246316ca
commit bd455f222e
3 changed files with 107 additions and 113 deletions

Binary file not shown.

View File

@@ -29,11 +29,12 @@ fi
modifyyaml(){ modifyyaml(){
##########需要变更的配置########### ##########需要变更的配置###########
redir='redir-port: 7892' redir='redir-port: 7892'
ipv6='ipv6: true'
external='external-controller: 0.0.0.0:9999' external='external-controller: 0.0.0.0:9999'
if [ "$dns_mod" = "fake-ip" ];then if [ "$dns_mod" = "fake-ip" ];then
dns='dns: {enable: true, listen: 0.0.0.0:1053, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4]}' dns='dns: {enable: true, listen: 0.0.0.0:1053, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4]}'
else else
dns='dns: {enable: true, listen: 0.0.0.0:1053, enhanced-mode: redir-host, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [1.0.0.1, 8.8.4.4]}' dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, enhanced-mode: redir-host, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [1.0.0.1, 8.8.4.4]}'
fi fi
if [ "$redir_mod" = "Tun模式" ];then if [ "$redir_mod" = "Tun模式" ];then
tun='tun: {enable: true, stack: system}' tun='tun: {enable: true, stack: system}'
@@ -44,12 +45,14 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
################################### ###################################
#预删除需要添加的项目 #预删除需要添加的项目
sed -i '/^redir-port:*/'d $clashdir/config.yaml sed -i '/^redir-port:*/'d $clashdir/config.yaml
sed -i '/^ipv6: true:*/'d $clashdir/config.yaml
sed -i '/^external-controller:*/'d $clashdir/config.yaml sed -i '/^external-controller:*/'d $clashdir/config.yaml
sed -i '/^dns:*/'d $clashdir/config.yaml sed -i '/^dns:*/'d $clashdir/config.yaml
sed -i '/^tun:*/'d $clashdir/config.yaml sed -i '/^tun:*/'d $clashdir/config.yaml
sed -i '/^experimental:*/'d $clashdir/config.yaml sed -i '/^experimental:*/'d $clashdir/config.yaml
#添加配置 #添加配置
sed -i "2a$redir" $clashdir/config.yaml sed -i "2a$redir" $clashdir/config.yaml
sed -i "5a$ipv6" $clashdir/config.yaml
sed -i "6a$external" $clashdir/config.yaml sed -i "6a$external" $clashdir/config.yaml
sed -i "7a$dns" $clashdir/config.yaml sed -i "7a$dns" $clashdir/config.yaml
sed -i "8a$tun" $clashdir/config.yaml sed -i "8a$tun" $clashdir/config.yaml
@@ -78,6 +81,7 @@ start_redir(){
iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892 iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash iptables -t nat -A PREROUTING -p tcp -j clash
#ip6tables -t nat -A PREROUTING -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
} }
@@ -87,17 +91,12 @@ stop_redir(){
iptables -t nat -F clash > /dev/null 2>&1 iptables -t nat -F clash > /dev/null 2>&1
iptables -t nat -X clash > /dev/null 2>&1 iptables -t nat -X clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
#ip6tables -t nat -A PREROUTING -p tcp $ports-j REDIRECT --to-ports 7892 > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
} }
start_tun(){ start_tun(){
#修改iptables规则使流量进入clash #允许tun网卡接受流量
iptables -I FORWARD -o utun -j ACCEPT iptables -I FORWARD -o utun -j ACCEPT
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_tun(){
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
} }
start_service() { start_service() {
getconfig getconfig
@@ -110,21 +109,11 @@ start_service() {
procd_set_param command $clashdir/clash -d $clashdir procd_set_param command $clashdir/clash -d $clashdir
procd_close_instance procd_close_instance
#修改iptables规则使流量进入clash #修改iptables规则使流量进入clash
if [[ "$redir_mod" = "Tun模式" ]];then stop_redir
stop_tun start_tun
start_tun start_redir
mark_time mark_time
else
stop_redir
start_redir
mark_time
fi
} }
stop_service() { stop_service() {
getconfig stop_redir
if [[ "$redir_mod" = "Tun模式" ]];then
stop_tun
else
stop_redir
fi
} }

View File

@@ -22,7 +22,8 @@ https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_On
EOF` EOF`
#如果传来的是Url链接则合成Https链接否则直接使用Https链接 #如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z $Https ];then if [ -z $Https ];then
Https="https://$Server/sub?target=clashr&new_name=true&url=$Url&insert=false&config=$Config" Https="https://$Server/sub?target=clashr&new_name=true&url=$Url&insert=false&config=$Config"
markhttp=1
fi fi
# #
echo ----------------------------------------------- echo -----------------------------------------------
@@ -39,64 +40,68 @@ yamlnew=$yaml.new
rm -rf $yamlnew > /dev/null 2>&1 rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https) result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then if [ "$result" != "200" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m配置文件获取失败\033[0m" echo -e "\033[31m配置文件获取失败\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo echo
read -p "是否更换后端地址后重试?[1/0] > " res if [ -z $markhttp ];then
if [ "$res" = '1' ]; then exit;
sed -i '/server_link=*/'d $ccfg else
if [ "$server_link" = '7' ]; then read -p "是否更换后端地址后重试?[1/0] > " res
server_link=0 if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [ "$server_link" = '7' ]; then
server_link=0
fi
server_link=$(($server_link + 1))
#echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
getyaml
fi
exit;
fi fi
server_link=$(($server_link + 1))
#echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
getyaml
fi
exit;
else else
if cat $yamlnew | grep ', server:' >/dev/null;then if cat $yamlnew | grep ', server:' >/dev/null;then
#替换文件 #替换文件
mv $yaml $yaml.bak mv $yaml $yaml.bak
mv $yamlnew $yaml mv $yamlnew $yaml
echo 配置文件已生成正在重启clash使其生效 echo 配置文件已生成正在重启clash使其生效
#重启clash服务 #重启clash服务
/etc/init.d/clash restart /etc/init.d/clash restart
sleep 1 sleep 1
status=`ps |grep -w 'clash -d'|grep -v grep|wc -l` status=`ps |grep -w 'clash -d'|grep -v grep|wc -l`
if [[ $status -gt 0 ]];then if [[ $status -gt 0 ]];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m" echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理clash内置规则" echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理clash内置规则"
host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
echo -e "Host地址:\033[30;46m $host \033[0m;端口:\033[30;46m 9999 \033[0m" echo -e "Host地址:\033[30;46m $host \033[0m;端口:\033[30;46m 9999 \033[0m"
#将用户链接写入mark #将用户链接写入mark
sed -i '/Https=*/'d $ccfg sed -i '/Https=*/'d $ccfg
sed -i "7i\Https=\'$Https\'" $ccfg sed -i "7i\Https=\'$Https\'" $ccfg
clashsh clashsh
else else
echo ----------------------------------------------- echo -----------------------------------------------
if [ -f $yaml.bak ];then if [ -f $yaml.bak ];then
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m" echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
mv $yaml.bak $yaml mv $yaml.bak $yaml
/etc/init.d/clash start /etc/init.d/clash start
clashsh clashsh
else else
echo -e "\033[31mclash服务启动失败请利用测试菜单排查问题\033[0m" echo -e "\033[31mclash服务启动失败请利用测试菜单排查问题\033[0m"
clashsh clashsh
fi fi
fi fi
else else
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m" echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,20p' $yamlnew sed -n '1,20p' $yamlnew
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请检查如上配置文件信息:\033[0m" echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
fi fi
exit; exit;
fi fi
exit exit
} }
@@ -181,31 +186,31 @@ echo -e "\033[31m注意如节点使用了chacha20加密协议需将核心更
echo -e "\033[33m0 返回上级目录!\033[0m" echo -e "\033[33m0 返回上级目录!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入完整链接 > " Https read -p "请输入完整链接 > " Https
test=$(echo $Https | grep "://") test=$(echo $Https | grep "://")
Https=`echo ${Https/\ \(*\)/''}` #删除恶心的超链接内容 Https=`echo ${Https/\ \(*\)/''}` #删除恶心的超链接内容
Https=`echo ${Https//\&/\%26}` #将分隔符 & 替换成Httpscode%26 #Https=`echo ${Https//\&/\%26}` #将分隔符 & 替换成Httpscode%26
if [ -n $Https ];then if [ -n $Https ];then
if [ -n $test ];then if [ -n $test ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e 请检查输入的链接是否正确: echo -e 请检查输入的链接是否正确:
echo -e "\033[4m$Https\033[0m" echo -e "\033[4m$Https\033[0m"
read -p "确认导入配置文件原配置文件将被更名为config.yaml.bak![1/0] > " res read -p "确认导入配置文件原配置文件将被更名为config.yaml.bak![1/0] > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
#将用户链接写入mark #将用户链接写入mark
sed -i '/Url=*/'d $ccfg sed -i '/Url=*/'d $ccfg
sed -i '/Https=*/'d $ccfg sed -i '/Https=*/'d $ccfg
sed -i "6i\Https=\'$Https\'" $ccfg sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件 #获取在线yaml文件
getyaml getyaml
fi fi
clashlink
fi
elif [[ $Https == 0 ]];then
clashlink clashlink
fi else
elif [[ $Https == 0 ]];then echo -----------------------------------------------
clashlink echo -e "\033[31m请输入正确的链接地址\033[0m"
else fi
echo -----------------------------------------------
echo -e "\033[31m请输入正确的链接地址\033[0m"
fi
} }
getsh(){ getsh(){
echo ----------------------------------------------- echo -----------------------------------------------
@@ -263,7 +268,7 @@ else
fi fi
fi fi
cpucore=armv5 cpucore=armv7
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$version\033[0m" echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$version\033[0m"
echo -e "\033[32m请选择需要下载的核心版本\033[0m" echo -e "\033[32m请选择需要下载的核心版本\033[0m"
@@ -306,21 +311,21 @@ echo -e "-----------------------------------------------\033[0m"
#获取在线clash核心文件 #获取在线clash核心文件
result=$(curl -w %{http_code} -kLo /tmp/clash.new $corelink) result=$(curl -w %{http_code} -kLo /tmp/clash.new $corelink)
if [ "$result" != "200" ];then if [ "$result" != "200" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m核心文件下载失败\033[0m" echo -e "\033[31m核心文件下载失败\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
getcore getcore
else else
echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m" echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m"
mv /tmp/clash.new $clashdir/clash mv /tmp/clash.new $clashdir/clash
chmod 777 $clashdir/clash #授予权限 chmod 777 $clashdir/clash #授予权限
sed -i '/clashcore*/'d $ccfg sed -i '/clashcore*/'d $ccfg
sed -i "1i\clashcore=$clashcore" $ccfg sed -i "1i\clashcore=$clashcore" $ccfg
#sed -i '/version*/'d $ccfg #sed -i '/version*/'d $ccfg
#sed -i "1i\version=$version" $ccfg #sed -i "1i\version=$version" $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m$clashcore核心替换成功请手动启动clash服务\033[0m" echo -e "\033[32m$clashcore核心替换成功请手动启动clash服务\033[0m"
clashsh clashsh
fi fi
} }