~增加节点绕过功能
~增加nftables依赖检测及自动安装功能(限OpenWrt)
~优化配置文件生成逻辑
This commit is contained in:
juewuy
2022-12-15 20:49:57 +08:00
parent 5f1b1bc3cc
commit 9aec51a267
2 changed files with 61 additions and 29 deletions

View File

@@ -973,15 +973,20 @@ clashcfg(){
set_redir_config
elif [ "$num" = 6 ]; then
redir_mod=Nft基础
if command -v opkg >/dev/null && [ -z "$(opkg list-installed | grep firewall4)" ];then
read -p "检测到缺少firewall4依赖是否自动安装(1/0)" res
[ "$res" = '1' ] && opkg install firewall4 && redir_mod=Nft基础
else
redir_mod=Nft基础
fi
set_redir_config
elif [ "$num" = 7 ]; then
if [ -n "$(lsmod | grep 'nft_tproxy')" ];then
redir_mod=Nft混合
if command -v opkg >/dev/null && [ -z "$(opkg list-installed | grep kmod-nft-tproxy)" ];then
read -p "检测到缺少kmod-nft-tproxy依赖是否自动安装(1/0)" res
[ "$res" = '1' ] && opkg install kmod-nft-tproxy && redir_mod=Nft混合
else
read -p "未检测到Tproxy模块是否强制开启可能导致无法联网(1/0)" res
[ "$res" = '1' ] && redir_mod=Nft混合
redir_mod=Nft混合
fi
set_redir_config
@@ -1193,7 +1198,7 @@ clashcfg(){
}
clashadv(){
#获取设置默认显示
[ -z "$modify_yaml" ] && modify_yaml=
[ -z "$proxies_bypass" ] && proxies_bypass=未启
[ -z "$start_old" ] && start_old=未开启
[ -z "$tproxy_mod" ] && tproxy_mod=未开启
[ -z "$public_support" ] && public_support=未开启
@@ -1206,6 +1211,7 @@ clashadv(){
echo -----------------------------------------------
echo -e " 1 ipv6相关"
#echo -e " 2 配置Meta特性"
echo -e " 3 启用节点绕过: \033[36m$proxies_bypass\033[0m ————用于防止多设备多重流量"
echo -e " 4 启用域名嗅探: \033[36m$sniffer\033[0m ————用于流媒体及防DNS污染"
echo -e " 5 启用公网访问: \033[36m$public_support\033[0m ————需要路由拨号+公网IP"
echo -e " 6 配置内置DNS服务 \033[36m$dns_no\033[0m"
@@ -1225,6 +1231,20 @@ clashadv(){
setipv6
clashadv
elif [ "$num" = 3 ]; then
echo -----------------------------------------------
if [ "$proxies_bypass" = "未启用" ];then
proxies_bypass=已启用
echo -e "\033[33m仅当ShellClash与子网络同类应用使用相同节点配置时方可生效\033[0m"
sleep 1
else
proxies_bypass=未启用
fi
setconfig proxies_bypass $proxies_bypass
echo -e "\033[32m设置成功\033[0m"
sleep 1
clashadv
elif [ "$num" = 4 ]; then
echo -----------------------------------------------
if [ "$sniffer" = "未启用" ];then

View File

@@ -328,14 +328,35 @@ modify_yaml(){
#预读取变量
mode=$(grep "^mode" $yaml | head -1 | awk '{print $2}')
[ -z "$mode" ] && mode='Rule'
#预删除需要添加的项目
a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1)
b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1)
b=$((b-1))
#分割配置文件
mkdir -p $tmpdir > /dev/null
[ "$b" -gt 0 ] && sed "${a},${b}d" $yaml > $tmpdir/proxy.yaml || cp -f $yaml $tmpdir/proxy.yaml
yaml_p=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1) #获取节点起始行号
yaml_r=$(grep -n "^rule" $yaml | head -1 | cut -d ":" -f 1) #获取规则起始行号
if [ "$yaml_p" -lt "$yaml_r" ];then
sed -n "${yaml_p},${yaml_r}p" $yaml > $tmpdir/proxy.yaml
cat $yaml | sed -n "${yaml_r},\$p" | sed '1d' | sed 's/^ *-/ -/g' > $tmpdir/rule.yaml #切割rule并对齐
else
cat $yaml | sed -n "${yaml_r},${yaml_p}p" | sed '1d' | sed '$d' | sed 's/^ *-/ -/g' > $tmpdir/rule.yaml #切割rule并对齐
sed -n "${yaml_p},\$p" $yaml > $tmpdir/proxy.yaml
sed -n "${yaml_r}p" $yaml >> $tmpdir/proxy.yaml #将rule字段附在末尾
fi
#跳过本地tls证书验证
[ "$skip_cert" = "已开启" ] && sed -i '1,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxy.yaml
[ "$skip_cert" = "已开启" ] && sed -i 's/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxy.yaml
#节点绕过功能支持
[ "$proxies_bypass" = "已启用" ] && {
cat /tmp/clash_$USER/proxy.yaml | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $tmpdir/proxies_bypass
cat /tmp/clash_$USER/proxy.yaml | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $tmpdir/proxies_bypass
sed -i "/#节点绕过/d" $tmpdir/rule.yaml
cat $tmpdir/rule.yaml >> $tmpdir/proxies_bypass
mv -f $tmpdir/proxies_bypass $tmpdir/rule.yaml
}
#插入自定义规则
[ -f $clashdir/rules.yaml ] && {
cat $clashdir/rules.yaml | sed 's/^ *-/ -/g' | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $tmpdir/rules.yaml
sed -i "/#自定义规则/d" $tmpdir/rule.yaml
cat $tmpdir/rule.yaml >> $tmpdir/rules.yaml
mv -f $tmpdir/rules.yaml $tmpdir/rule.yaml
}
#添加配置
###################################
cat > $tmpdir/set.yaml <<EOF
@@ -372,19 +393,9 @@ EOF
[ -f $clashdir/user.yaml ] && yaml_user=$clashdir/user.yaml
[ -f $tmpdir/hosts.yaml ] && yaml_hosts=$tmpdir/hosts.yaml
[ -f $tmpdir/proxy.yaml ] && yaml_proxy=$tmpdir/proxy.yaml
cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_proxy > $tmpdir/config.yaml
#插入自定义规则
sed -i "/#自定义规则/d" $tmpdir/config.yaml
space_rules=$(sed -n '/^rules/{n;p}' $tmpdir/proxy.yaml | grep -oE '^ *') #获取空格数
if [ -f $clashdir/rules.yaml ];then
sed -i '/^$/d' $clashdir/rules.yaml && echo >> $clashdir/rules.yaml #处理换行
while read line;do
[ -z "$(echo "$line" | grep '#')" ] && \
[ -n "$(echo "$line" | grep '\- ')" ] && \
line=$(echo "$line" | sed 's#/#\\/#') && \
sed -i "/^rules:/a\\$space_rules$line #自定义规则" $tmpdir/config.yaml
done < $clashdir/rules.yaml
fi
[ -f $tmpdir/rule.yaml ] && yaml_rule=$tmpdir/rule.yaml
cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_proxy $yaml_rule > $tmpdir/config.yaml
#插入自定义代理
sed -i "/#自定义代理/d" $tmpdir/config.yaml
@@ -423,6 +434,7 @@ EOF
rm -f $tmpdir/set.yaml
rm -f $tmpdir/proxy.yaml
rm -f $tmpdir/hosts.yaml
rm -f $tmpdir/rule.yaml
}
#设置路由规则
cn_ip_route(){
@@ -1040,10 +1052,10 @@ bfstart(){
#检测是否存在高级版规则
if [ "$clashcore" = "clash" -a -n "$(cat $clashdir/config.yaml | grep -E '^script:|proxy-providers|rule-providers|rule-set')" ];then
echo -----------------------------------------------
logger "检测到高级规则将改为使用clashpre核心启动!" 33
logger "检测到高级规则将改为使用clash.meta核心启动!" 33
rm -rf $bindir/clash
clashcore=clashpre
setconfig clashcore clashpre
clashcore=clash.meta
setconfig clashcore clash.meta
echo -----------------------------------------------
fi
#检查clash核心
@@ -1360,7 +1372,7 @@ unset_proxy)
sed -i '/all_proxy/'d $profile
sed -i '/ALL_PROXY/'d $profile
;;
db)
-t)
$2
;;
esac