~新增保守方式启动,适配更多设备(小米3HD,以及其他linux系统)
~新增进阶功能菜单
~修复了geoip数据库偶尔丢失的bug(感谢Pan Peter同学提交bug!)
This commit is contained in:
juewuy 2020-08-22 19:05:02 +08:00
parent c61f8fa504
commit d090e2d9a9
3 changed files with 176 additions and 250 deletions

View File

@ -82,6 +82,13 @@ if [ ! -f $clashdir/Country.mmdb ];then
clashstart
fi
}
clashstop(){
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && stop_old
else
/etc/init.d/clash stop > /dev/null 2>&1
fi
}
clashstart(){
if [ ! -f "$yaml" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -90,24 +97,30 @@ clashstart(){
fi
if [ $status -gt 0 ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/etc/init.d/clash stop > /dev/null 2>&1
clashstop
echo -e "\033[31mClash服务已停止\033[0m"
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && start_old
else
/etc/init.d/clash start
sleep 1
status=`ps |grep -w 'clash -d'|grep -v grep|wc -l`
if [[ $status -gt 0 ]];then
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 "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
status=`ps |grep -w 'clash -d'|grep -v grep`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败尝试使用保守方式启动\033[0m"
source $clashdir/start.sh && start_old
fi
fi
sleep 1
status=`ps |grep -w 'clash -d'|grep -v grep`
[ -z "$status" ] && echo -e "\033[31mclash启动失败\033[0m" && exit
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 "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
clashlink(){
#获取订阅规则
@ -270,13 +283,11 @@ else
exit;
fi
}
clashadv(){
clashcfg(){
#获取设置默认显示
[ -z "$skip_cert" ] && skip_cert=已开启
[ -z "$common_ports" ] && common_ports=未开启
[ -z "$dns_mod" ] && dns_mod=redir_host
[ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$dns_over" ] && dns_over=未开启
if [ -z "$(cat $clashdir/mac)" ]; then
mac_return=未开启
@ -285,17 +296,15 @@ else
fi
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用高级模式菜单:\033[0m"
echo -e "\033[33m修改配置后请手动重启clash服务\033[0m"
echo -e "\033[30;47m欢迎使用功能设置菜单:\033[0m"
echo -e "\033[32m修改配置后请手动重启clash服务\033[0m"
echo -----------------------------------------------
echo -e " 1 切换Clash运行模式: \033[36m$redir_mod\033[0m"
echo -e " 2 切换DNS运行模式 \033[36m$dns_mod\033[0m"
echo -e " 3 跳过本地证书验证: \033[36m$skip_cert\033[0m ————解决节点证书验证错误"
echo -e " 4 只代理常用端口: \033[36m$common_ports\033[0m ————用于屏蔽P2P流量"
echo -e " 5 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置"
echo -e " 6 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性且不兼容Fake_ip"
echo -e " 7 过滤局域网mac地址 \033[36m$mac_return\033[0m ————列表内设备不走代理"
echo -e " 8 不使用本地DNS服务 \033[36m$dns_over\033[0m ————防止redir-host模式的dns污染"
echo -e " 5 过滤局域网mac地址 \033[36m$mac_return\033[0m ————列表内设备不走代理"
echo -e " 6 不使用本地DNS服务 \033[36m$dns_over\033[0m ————防止redir-host模式的dns污染"
echo -e " 9 \033[32m重启\033[0mclash服务"
echo -e " 0 返回上级菜单 \033[0m"
read -p "请输入对应数字 > " num
@ -322,16 +331,16 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
elif [[ $num == 0 ]]; then
clashadv
clashcfg
elif [[ $num == 1 ]]; then
redir_mod=Redir模式
elif [[ $num == 2 ]]; then
if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
clashadv
clashcfg
fi
redir_mod=Tun模式
dns_mod=fake-ip
@ -339,13 +348,13 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
clashadv
clashcfg
fi
redir_mod=混合模式
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
fi
sed -i '/redir_mod*/'d $ccfg
sed -i "1i\redir_mod=$redir_mod" $ccfg
@ -353,7 +362,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
sed -i "1i\dns_mod=$dns_mod" $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[36m已设为 $redir_mod \033[0m"
clashadv
clashcfg
elif [[ $num == 2 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -369,9 +378,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
elif [[ $num == 0 ]]; then
clashadv
clashcfg
elif [[ $num == 1 ]]; then
dns_mod=fake-ip
elif [[ $num == 2 ]]; then
@ -380,7 +389,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
fi
sed -i '/dns_mod*/'d $ccfg
sed -i "1i\dns_mod=$dns_mod" $ccfg
@ -388,7 +397,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
sed -i "1i\redir_mod=$redir_mod" $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m"
clashadv
clashcfg
elif [[ $num == 3 ]]; then
sed -i '/skip_cert*/'d $ccfg
@ -402,7 +411,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m已设为禁止跳过本地证书验证\033[0m"
skip_cert=未开启
fi
clashadv
clashcfg
elif [[ $num == 4 ]]; then
sed -i '/common_ports*/'d $ccfg
@ -416,40 +425,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m已设为代理全部端口\033[0m"
common_ports=未开启
fi
clashadv
elif [[ $num == 5 ]]; then
sed -i '/modify_yaml*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$modify_yaml" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\modify_yaml=已开启" $ccfg
echo -e "\033[33m已设为使用用户完成自定义配置文件"
echo -e "\033[0m不明白原理的用户切勿随意开启此选项"
echo -e "\033[33m必然会导致上不了网!\033[0m"
modify_yaml=已开启
else
sed -i "1i\modify_yaml=未开启" $ccfg
echo -e "\033[32m已设为使用脚本内置规则管理config.yaml配置文件\033[0m"
modify_yaml=未开启
fi
clashadv
elif [[ $num == 6 ]]; then
sed -i '/ipv6_support*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\ipv6_support=已开启" $ccfg
echo -e "\033[33m已开启对ipv6协议的支持\033[0m"
echo -e "Clash对ipv6的支持并不友好如不能使用请静等修复"
ipv6_support=已开启
else
sed -i "1i\ipv6_support=未开启" $ccfg
echo -e "\033[32m已禁用对ipv6协议的支持\033[0m"
ipv6_support=未开启
fi
clashadv
clashcfg
elif [[ $num == 7 ]]; then
elif [[ $num == 5 ]]; then
add_mac(){
echo -----------------------------------------------
@ -458,9 +436,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[0m 0 或回车 结束添加"
read -p "请输入对应序号 > " num
if [ -z "$num" ]; then
clashadv
clashcfg
elif [ $num -le 0 ]; then
clashadv
clashcfg
elif [ $num -le $(cat /tmp/dhcp.leases | awk 'END{print NR}') ]; then
macadd=$(cat /tmp/dhcp.leases | awk '{print $2}' | sed -n "$num"p)
if [ -z $(cat $clashdir/mac | grep -E "$macadd") ];then
@ -494,25 +472,25 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
elif [[ $num == 0 ]]; then
clashadv
clashcfg
elif [[ $num == 1 ]]; then
:>$clashdir/mac
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m设备列表已清空\033[0m"
sleep 1
clashadv
clashcfg
elif [[ $num == 2 ]]; then
add_mac
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
clashcfg
fi
elif [[ $num == 8 ]]; then
elif [[ $num == 6 ]]; then
sed -i '/dns_over*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$dns_over" = "未开启" ] > /dev/null 2>&1; then
@ -527,12 +505,92 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "redir-host模式下部分网站可能会被运营商dns污染导致无法打开"
dns_over=未开启
fi
clashadv
clashadv
clashcfg
elif [[ $num == 9 ]]; then
clashstart
clashsh
else
echo -e "\033[31m暂未支持的选项\033[0m"
clashcfg
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
fi
exit;
}
clashadv(){
#获取设置默认显示
[ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$start_old" ] && start_old=未开启
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用进阶模式菜单\033[0m"
echo -e "\033[33m如您不是很了解clash的运行机制请勿更改\033[0m"
echo -e "\033[32m修改配置后请手动重启clash服务\033[0m"
echo -----------------------------------------------
echo -e " 1 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置"
echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性且不兼容Fake_ip"
echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————如正常方式无法启动"
echo -e " 9 \033[32m重启\033[0mclash服务"
echo -e " 0 返回上级菜单 \033[0m"
read -p "请输入对应数字 > " num
if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
sed -i '/modify_yaml*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$modify_yaml" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\modify_yaml=已开启" $ccfg
echo -e "\033[33m已设为使用用户完成自定义配置文件"
echo -e "\033[0m不明白原理的用户切勿随意开启此选项"
echo -e "\033[33m必然会导致上不了网!\033[0m"
modify_yaml=已开启
else
sed -i "1i\modify_yaml=未开启" $ccfg
echo -e "\033[32m已设为使用脚本内置规则管理config.yaml配置文件\033[0m"
modify_yaml=未开启
fi
clashadv
elif [[ $num == 2 ]]; then
sed -i '/ipv6_support*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\ipv6_support=已开启" $ccfg
echo -e "\033[33m已开启对ipv6协议的支持\033[0m"
echo -e "Clash对ipv6的支持并不友好如不能使用请静等修复"
ipv6_support=已开启
else
sed -i "1i\ipv6_support=未开启" $ccfg
echo -e "\033[32m已禁用对ipv6协议的支持\033[0m"
ipv6_support=未开启
fi
clashadv
elif [[ $num == 3 ]]; then
sed -i '/start_old*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\start_old=已开启" $ccfg
echo -e "\033[33m改为使用保守方式启动clash服务\033[0m"
clashstop
echo -e "已停止clash服务请手动启动服务"
start_old=已开启
else
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m改为使用默认方式启动clash服务\033[0m"
start_old=未开启
fi
clashadv
elif [[ $num == 9 ]]; then
[ $status -gt 0 ] && /etc/init.d/clash stop
clashstart
clashsh
else
@ -746,11 +804,12 @@ clashsh(){
getconfig
#############################
echo -e " 1 \033[32m启动/重启\033[0mclash服务"
echo -e " 2 clash\033[33m高级设置\033[0m"
echo -e " 2 clash\033[33m功能设置\033[0m"
echo -e " 3 \033[31m停止\033[0mclash服务"
echo -e " 4 $auto1"
echo -e " 5 设置\033[33m定时任务\033[0m"
echo -e " 6 导入\033[32m节点/订阅\033[0m链接"
echo -e " 7 clash\033[31m进阶设置\033[0m"
echo -e " 8 \033[35m测试菜单\033[0m"
echo -e " 9 \033[36m更新/卸载\033[0m"
echo -e " 0 \033[0m退出脚本\033[0m"
@ -765,10 +824,10 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
exit;
elif [[ $num == 2 ]]; then
clashadv
clashcfg
elif [[ $num == 3 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
clashstop
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31mClash服务已停止\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -790,6 +849,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 6 ]]; then
clashlink
elif [[ $num == 7 ]]; then
clashadv
elif [[ $num == 8 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -5,149 +5,15 @@
USE_PROCD=1
START=92
getconfig(){
#开机加载环境变量保证找到文件路径
source /etc/profile > /dev/null 2>&1
ccfg=$clashdir/mark
if [ ! -f "$ccfg" ]; then
echo mark文件不存在默认以Redir模式运行
cat >$ccfg<<EOF
#标识clash运行状态的文件不明勿动
EOF
#指定一些默认状态
redir_mod=redir模式
modify_yaml=未开启
fi
source $ccfg #加载配置文件
#是否代理常用端口
if [ "$common_ports" = "已开启" ];then
ports='-m multiport --dports 22,53,587,465,995,993,143,80,443 '
fi
#检测系统端口占用
for portx in 1053 7890 7892 9999 ;do
[ -n "$(netstat -ntulp |grep :$portx|grep -v clash)" ] && echo -e "检测到端口:\033[30;47m $portx \033[0m被以下进程占用clash无法启动" && echo $(netstat -ntulp |grep :$portx) && exit;
done
}
modify_yaml(){
##########需要变更的配置###########
mix='mixed-port: 7890'
redir='redir-port: 7892'
lan='allow-lan: true'
mode='mode: Rule'
log='log-level: info'
if [ "$ipv6_support" = "已开启" ];then
ipv6='ipv6: true'
else
ipv6='ipv6: false'
fi
external='external-controller: 0.0.0.0:9999'
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]}'
elif [ "$dns_over" = "已开启" ];then
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, enhanced-mode: redir-host, nameserver: [114.114.114.114, 223.5.5.5], fallback: [1.0.0.1, 8.8.4.4]}'
else
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, enhanced-mode: redir-host, nameserver: [114.114.114.114, 223.5.5.5, 127.0.0.1:53], fallback: [1.0.0.1, 8.8.4.4]}'
fi
if [ "$redir_mod" != "Redir模式" ];then
tun='tun: {enable: true, stack: system}'
else
tun='tun: {enable: false}'
fi
exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
###################################
#预删除需要添加的项目
i=$(grep -n "^proxies:" $clashdir/config.yaml | head -1 | cut -d ":" -f 1)
i=$(($i-1))
sed -i '1,'$i'd' $clashdir/config.yaml
#添加配置
sed -i "1i$mix" $clashdir/config.yaml
sed -i "1a$redir" $clashdir/config.yaml
sed -i "2a$lan" $clashdir/config.yaml
sed -i "3a$mode" $clashdir/config.yaml
sed -i "4a$log" $clashdir/config.yaml
sed -i "5a$ipv6" $clashdir/config.yaml
sed -i "6a$external" $clashdir/config.yaml
sed -i "7a$dns" $clashdir/config.yaml
sed -i "8a$tun" $clashdir/config.yaml
sed -i "9a$exper" $clashdir/config.yaml
#跳过本地tls证书验证
if [ "$skip_cert" != "未开启" ];then
sed -i "10,99s/sni: \S*/\1skip-cert-verify: true}/" $clashdir/config.yaml #跳过trojan本地证书验证
sed -i '10,99s/}}/}, skip-cert-verify: true}/' $clashdir/config.yaml #跳过v2+ssl本地证书验证
fi
}
mark_time(){
start_time=`date +%s`
sed -i '/start_time*/'d $ccfg
sed -i "3i\start_time=$start_time" $ccfg
}
start_redir(){
#修改iptables规则使流量进入clash
iptables -t nat -N clash
iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A clash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A clash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A clash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN
for mac in $(cat $clashdir/mac); do
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
done
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash
if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clash
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash -m mac --mac-source $mac -j RETURN
done
ip6tables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
ip6tables -t nat -A PREROUTING -p tcp -j clash
fi
}
stop_iptables(){
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp -j clash_dns > /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 -F clash_dns > /dev/null 2>&1
iptables -t nat -X clash_dns > /dev/null 2>&1
#重置ipv6规则
ip6tables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp -j clash_dns > /dev/null 2>&1
ip6tables -t nat -F clash > /dev/null 2>&1
ip6tables -t nat -X clash > /dev/null 2>&1
ip6tables -t nat -F clash_dns > /dev/null 2>&1
ip6tables -t nat -X clash_dns > /dev/null 2>&1
}
start_dns(){
#允许tun网卡接受流量
iptables -I FORWARD -o utun -j ACCEPT
ip6tables -I FORWARD -o utun -j ACCEPT
#设置dns转发
iptables -t nat -N clash_dns
for mac in $(cat $clashdir/mac); do
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
iptables -t nat -A PREROUTING -p udp -j clash_dns
#ipv6DNS
ip6tables -t nat -N clash_dns
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done
ip6tables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp -j clash_dns
}
start_service() {
#开机加载环境变量保证找到文件路径
source /etc/profile > /dev/null 2>&1
#加载修饰脚本
source $clashdir/start.sh
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
if [ "$modify_yaml" != "已开启" ];then
modify_yaml
fi
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
procd_open_instance
procd_set_param respawn
@ -155,14 +21,18 @@ start_service() {
procd_set_param stdout 1
procd_set_param command $clashdir/clash -d $clashdir
procd_close_instance
echo $ccfg
#修改iptables规则使流量进入clash
stop_iptables
start_dns
if [ "$redir_mod" != "Tun模式" ];then
start_redir
fi
[ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#标记启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=未开启" $ccfg
}
stop_service() {
source $clashdir/start.sh
stop_iptables
}

View File

@ -42,7 +42,7 @@ echo -e "| \033[0m如长时间没有数据请用ctrl+c退出\033[36m
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m"
#获取在线yaml文件
yaml=$clashdir/config.yaml
yamlnew=$yaml.new
yamlnew=/tmp/config.yaml
rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then
@ -90,9 +90,7 @@ else
fi
fi
#替换文件
if [ -f $yaml ];then
mv $yaml $yaml.bak
fi
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
@ -306,6 +304,7 @@ cpucore=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cpucore | grep -E "linux.*armv.*")" ] && cpucore="armv5"
[ -n "$(echo $cpucore | grep -E "linux.*mips.*")" ] && cpucore="mipsle-softfloat"
[ -n "$(echo $cpucore | grep -E "linux.*x86.*")" ] && cpucore="386"
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="386"
###
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
@ -389,32 +388,19 @@ fi
}
getgeo(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;46m感谢Alecthw大神提供的优质GeoIP数据库\033[0m"
echo -e "\033[33m正在检查更新\033[0m"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "\033[33m请选择下载源\033[0m"
echo -e " 1 默认源:$update_url"
echo -e " 2 Alecthw大神的Github(需开启clash服务)"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z $num ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 0 ]]; then
update
elif [[ $num == 1 ]]; then
geolink="$update_url/bin/Country.mmdb"
#echo $geolink
elif [[ $num == 2 ]]; then
geolink="-x 127.0.0.1:7890 https://raw.githubusercontent.com/alecthw/mmdb_china_ip_list/release/Country.mmdb"
else
echo -e "\033[31m请输入正确的数字\033[0m"
update
exit;
fi
echo -e "当前脚本版本为:\033[33m $Geo_v \033[0m"
echo -e "最新脚本版本为:\033[32m $GeoIP_v \033[0m"
echo -----------------------------------------------
read -p "是否更新数据库文件?[1/0] > " res
if [ "$res" = '1' ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 正在从服务器获取数据库文件…………
result=$(curl -w %{http_code} -kLo $clashdir/Country.mmdb $geolink)
result=$(curl -w %{http_code} -kLo /tmp/Country.mmdb $update_url/bin/Country.mmdb)
if [ "$result" != "200" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m文件下载失败\033[0m"
@ -423,7 +409,15 @@ read -p "请输入对应数字 > " num
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32mGeoIP数据库文件下载成功\033[0m"
mv /tmp/Country.mmdb $clashdir/Country.mmdb
sed -i '/Geo_v=*/'d $ccfg
sed -i "1i\Geo_v=$GeoIP_v" $ccfg
rm -rf /tmp/clashversion
clashsh
fi
else
clashsh
fi
}
getdb(){
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}';)