~新增Tproxy模式
  ·tcp
  ·MAC过滤
  ·常用端口过滤
  ·CNIP绕过(已修复)
  ·屏蔽QUIC
  ·ipv6支持
~新增Nftables支持
  ·tcp&udp
  ·MAC过滤
  ·常用端口过滤
  ·CNIP绕过
  ·屏蔽QUIC
  ·ipv6支持(未测试)
  ·本机代理
  ·docker代理(未测试)
~移除部分不可用安装源
~修复版本回退功能不可用的问题
~修复部分Linux设备grep命令报错的问题
~尝试修复部分华硕设备无法正常开机启动的问题
~尝试修复部分设备提示ip6tables报错的问题
~修复部分情况下tun模式无法正常代理的问题
This commit is contained in:
juewuy
2022-11-16 19:49:02 +08:00
parent df153c9be0
commit b863bb6bc4
2 changed files with 57 additions and 41 deletions

View File

@@ -28,7 +28,7 @@ getconfig(){
[ ! -f $clashdir/mac ] && touch $clashdir/mac [ ! -f $clashdir/mac ] && touch $clashdir/mac
#获取本机host地址 #获取本机host地址
[ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E '\ 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
[ -z "$host" ] && host=127.0.0.1 [ -z "$host" ] && host=127.0.0.1
#dashboard目录位置 #dashboard目录位置
[ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui" [ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui"
@@ -369,7 +369,7 @@ setdns(){
} }
checkport(){ checkport(){
for portx in $dns_port $mix_port $redir_port $db_port ;do for portx in $dns_port $mix_port $redir_port $db_port ;do
if [ -n "$(netstat -ntul 2>&1 |grep \:$portx\ )" ];then if [ -n "$(netstat -ntul 2>&1 |grep '\:$portx ')" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "检测到端口【$portx】被以下进程占用clash可能无法正常启动\033[33m" echo -e "检测到端口【$portx】被以下进程占用clash可能无法正常启动\033[33m"
echo $(netstat -ntul | grep :$portx | head -n 1) echo $(netstat -ntul | grep :$portx | head -n 1)
@@ -524,7 +524,7 @@ localproxy(){
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方式配置(部分应用可能无法使用)"
[ -n "$(lsmod | grep ^xt_owner)" ] && echo -e " 3 使用\033[32miptables增强模式\033[0m配置(支持docker)" [ -n "$(lsmod | grep ^xt_owner)" ] && echo -e " 3 使用\033[32miptables增强模式\033[0m配置(支持docker)"
type nft 2> /dev/null && echo -e " 4 使用\033[32mnftables增强模式\033[0m配置(支持docker)" type nft &> /dev/null && echo -e " 4 使用\033[32mnftables增强模式\033[0m配置(支持docker)"
echo -e " 0 返回上级菜单" echo -e " 0 返回上级菜单"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
@@ -604,20 +604,20 @@ clashcfg(){
echo -e "\033[36m已设为 $redir_mod \033[0m" echo -e "\033[36m已设为 $redir_mod \033[0m"
} }
[ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ] && sup_tp=1 [ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ] && sup_tp=1
[ -n "$(lsmod | grep '^tun')" ] && sup_tun=1 #[ -n "$(lsmod | grep '^tun')" ] || ip tuntap &>/dev/null && sup_tun=1
type nft 2> /dev/null && sup_nft=1 type nft &> /dev/null && sup_nft=1
[ -n "$sup_nft" -a -n "$(lsmod | grep 'nft_tproxy')" ] && sup_nft=2 #[ -n "$(lsmod | grep 'nft_tproxy')" ] && sup_nft=2
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0mClash核心为\033[47;30m $clashcore \033[0m" echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0mClash核心为\033[47;30m $clashcore \033[0m"
echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m" echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 1 \033[32mRedir模式\033[0m Redir转发TCP不转发UDP" echo -e " 1 \033[32mRedir模式\033[0m Redir转发TCP不转发UDP"
[ -n "$sup_tun" ] && echo -e " 2 \033[36m混合模式\033[0m Redir转发TCPTun转发UDP" echo -e " 2 \033[36m混合模式\033[0m Redir转发TCPTun转发UDP"
[ -n "$sup_tp" ] && echo -e " 3 \033[32mTproxy混合\033[0m Redir转发TCPTproxy转发UDP" [ -n "$sup_tp" ] && echo -e " 3 \033[32mTproxy混合\033[0m Redir转发TCPTproxy转发UDP"
[ -n "$sup_tun" ] && echo -e " 4 \033[33mTun模式\033[0m 使用Tun转发TCP&UDP(占用高)" echo -e " 4 \033[33mTun模式\033[0m 使用Tun转发TCP&UDP(占用高)"
[ -n "$sup_tp" ] && echo -e " 5 \033[32mTproxy模式\033[0m 使用Tproxy转发TCP&UDP" [ -n "$sup_tp" ] && echo -e " 5 \033[32mTproxy模式\033[0m 使用Tproxy转发TCP&UDP"
[ -n "$sup_nft" ] && echo -e " 6 \033[36mNft基础\033[0m 使用nftables转发TCP不转发UDP" [ -n "$sup_nft" ] && echo -e " 6 \033[36mNft基础\033[0m 使用nftables转发TCP不转发UDP"
[ "$sup_nft" = '2' ] && echo -e " 7 \033[32mNft混合\033[0m 使用nft_tproxy转发TCP&UDP" [ -n "$sup_nft" ] && echo -e " 7 \033[32mNft混合\033[0m 使用nft_tproxy转发TCP&UDP"
echo -e " 8 \033[36m纯净模式\033[0m 不设置流量转发" echo -e " 8 \033[36m纯净模式\033[0m 不设置流量转发"
echo " 0 返回上级菜单" echo " 0 返回上级菜单"
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
@@ -639,8 +639,13 @@ clashcfg(){
set_redir_config set_redir_config
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
if modprobe tun &>/dev/null;then
redir_mod=Tun模式 redir_mod=Tun模式
dns_mod=fake-ip dns_mod=fake-ip
else
read -p "未检测到Tun模块是否强制开启可能导致无法联网(1/0)" res
[ "$res" = '1' ] && redir_mod=Tun模式 && dns_mod=fake-ip
fi
set_redir_config set_redir_config
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
@@ -652,7 +657,12 @@ clashcfg(){
set_redir_config set_redir_config
elif [ "$num" = 7 ]; then elif [ "$num" = 7 ]; then
if modprobe nft_tproxy &>/dev/null;then
redir_mod=Nft混合 redir_mod=Nft混合
else
read -p "未检测到Tproxy模块是否强制开启可能导致无法联网(1/0)" res
[ "$res" = '1' ] && redir_mod=Nft混合
fi
set_redir_config set_redir_config
elif [ "$num" = 8 ]; then elif [ "$num" = 8 ]; then
@@ -956,11 +966,12 @@ clashadv(){
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
if [ "$public_support" = "未开启" ]; then if [ "$public_support" = "未开启" ]; then
echo -e "\033[32m已开启公网访问Dashboard端口及Http/Sock5代理端口\033[0m" echo -e "\033[32m已开启公网访问Dashboard端口,安全起见建议设置面板访问密码\033[0m"
echo -e "\033[33m安全起见建议设置相关访问密码!\033[0m" echo -e "\033[33m如需访问Http/Sock5代理请在端口设置中修改默认端口并设置访问密码!\033[0m"
echo -e "\033[31m如未设置密码或仍使用默认端口将自动拒绝连接\033[0m"
public_support=已开启 public_support=已开启
setconfig public_support $public_support setconfig public_support $public_support
sleep 1 sleep 3
else else
echo -e "\033[32m已禁止公网访问Dashboard端口及Http/Sock5代理端口\033[0m" echo -e "\033[32m已禁止公网访问Dashboard端口及Http/Sock5代理端口\033[0m"
echo -e "\033[33m如果你的防火墙默认放行公网流量可能禁用失败\033[0m" echo -e "\033[33m如果你的防火墙默认放行公网流量可能禁用失败\033[0m"

View File

@@ -235,7 +235,7 @@ EOF`
exit 1 exit 1
fi fi
#检测不支持的加密协议 #检测不支持的加密协议
if cat $yamlnew | grep 'cipher:\ chacha20,' >/dev/null;then if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
echo ----------------------------------------------- echo -----------------------------------------------
logger "已停止支持chacha20加密请更换更安全的节点加密协议" 31 logger "已停止支持chacha20加密请更换更安全的节点加密协议" 31
echo ----------------------------------------------- echo -----------------------------------------------
@@ -259,7 +259,7 @@ EOF`
fi fi
#检测并去除无效节点组 #检测并去除无效节点组
[ -n "$url_type" ] && type xargs >/dev/null 2>&1 && { [ -n "$url_type" ] && type xargs >/dev/null 2>&1 && {
cat $yamlnew | grep -A 8 "\-\ name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/ rules:.*//g' | sed 's/- //g' | grep -E '#DIRECT\ $' | awk -F '#' '{print $1}' > /tmp/clash_proxies_$USER cat $yamlnew | grep -A 8 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/ rules:.*//g' | sed 's/- //g' | grep -E '#DIRECT $' | awk -F '#' '{print $1}' > /tmp/clash_proxies_$USER
while read line ;do while read line ;do
sed -i "/- $line/d" $yamlnew sed -i "/- $line/d" $yamlnew
sed -i "/- name: $line/,/- DIRECT/d" $yamlnew sed -i "/- name: $line/,/- DIRECT/d" $yamlnew
@@ -377,12 +377,12 @@ EOF
cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_proxy > $tmpdir/config.yaml cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_proxy > $tmpdir/config.yaml
#插入自定义规则 #插入自定义规则
sed -i "/#自定义规则/d" $tmpdir/config.yaml sed -i "/#自定义规则/d" $tmpdir/config.yaml
space_rules=$(sed -n '/^rules/{n;p}' $tmpdir/proxy.yaml | grep -oE '^\ *') #获取空格数 space_rules=$(sed -n '/^rules/{n;p}' $tmpdir/proxy.yaml | grep -oE '^ *') #获取空格数
if [ -f $clashdir/rules.yaml ];then if [ -f $clashdir/rules.yaml ];then
sed -i '/^$/d' $clashdir/rules.yaml && echo >> $clashdir/rules.yaml #处理换行 sed -i '/^$/d' $clashdir/rules.yaml && echo >> $clashdir/rules.yaml #处理换行
while read line;do while read line;do
[ -z "$(echo "$line" | grep '#')" ] && \ [ -z "$(echo "$line" | grep '#')" ] && \
[ -n "$(echo "$line" | grep '\-\ ')" ] && \ [ -n "$(echo "$line" | grep '\- ')" ] && \
line=$(echo "$line" | sed 's#/#\\/#') && \ line=$(echo "$line" | sed 's#/#\\/#') && \
sed -i "/^rules:/a\\$space_rules$line #自定义规则" $tmpdir/config.yaml sed -i "/^rules:/a\\$space_rules$line #自定义规则" $tmpdir/config.yaml
done < $clashdir/rules.yaml done < $clashdir/rules.yaml
@@ -390,13 +390,13 @@ EOF
#插入自定义代理 #插入自定义代理
sed -i "/#自定义代理/d" $tmpdir/config.yaml sed -i "/#自定义代理/d" $tmpdir/config.yaml
space=$(sed -n '/^proxies:/{n;p}' $tmpdir/config.yaml | grep -oE '^\ *') #获取空格数 space=$(sed -n '/^proxies:/{n;p}' $tmpdir/config.yaml | grep -oE '^ *') #获取空格数
if [ -f $clashdir/proxies.yaml ];then if [ -f $clashdir/proxies.yaml ];then
sed -i '/^$/d' $clashdir/proxies.yaml && echo >> $clashdir/proxies.yaml #处理换行 sed -i '/^$/d' $clashdir/proxies.yaml && echo >> $clashdir/proxies.yaml #处理换行
while read line;do while read line;do
[ -z "$(echo "$line" | grep '^proxies:')" ] && \ [ -z "$(echo "$line" | grep '^proxies:')" ] && \
[ -z "$(echo "$line" | grep '#')" ] && \ [ -z "$(echo "$line" | grep '#')" ] && \
[ -n "$(echo "$line" | grep '\-\ ')" ] && \ [ -n "$(echo "$line" | grep '\- ')" ] && \
line=$(echo "$line" | sed 's#/#\\/#') && \ line=$(echo "$line" | sed 's#/#\\/#') && \
sed -i "/^proxies:/a\\$space$line #自定义代理" $tmpdir/config.yaml sed -i "/^proxies:/a\\$space$line #自定义代理" $tmpdir/config.yaml
done < $clashdir/proxies.yaml done < $clashdir/proxies.yaml
@@ -404,9 +404,9 @@ EOF
#插入自定义策略组 #插入自定义策略组
sed -i "/#自定义策略组/d" $tmpdir/config.yaml sed -i "/#自定义策略组/d" $tmpdir/config.yaml
space=$(sed -n '/^proxy-groups:/{n;p}' $tmpdir/config.yaml | grep -oE '^\ *') #获取原始配置空格数 space=$(sed -n '/^proxy-groups:/{n;p}' $tmpdir/config.yaml | grep -oE '^ *') #获取原始配置空格数
if [ -f $clashdir/proxy-groups.yaml ];then if [ -f $clashdir/proxy-groups.yaml ];then
c_space=$(sed -n '/^proxy-groups:/{n;p}' $clashdir/proxy-groups.yaml | grep -oE '^\ *') #获取自定义配置空格数 c_space=$(sed -n '/^proxy-groups:/{n;p}' $clashdir/proxy-groups.yaml | grep -oE '^ *') #获取自定义配置空格数
[ -n "$c_space" ] && sed -i "s/$c_space/$space/g" $clashdir/proxy-groups.yaml && echo >> $clashdir/proxy-groups.yaml #处理缩进空格数 [ -n "$c_space" ] && sed -i "s/$c_space/$space/g" $clashdir/proxy-groups.yaml && echo >> $clashdir/proxy-groups.yaml #处理缩进空格数
sed -i '/^$/d' $clashdir/proxy-groups.yaml && echo >> $clashdir/proxy-groups.yaml #处理换行 sed -i '/^$/d' $clashdir/proxy-groups.yaml && echo >> $clashdir/proxy-groups.yaml #处理换行
cat $clashdir/proxy-groups.yaml | awk '{array[NR]=$0} END { for(i=NR;i>0;i--){print array[i];} }' | while IFS= read line;do cat $clashdir/proxy-groups.yaml | awk '{array[NR]=$0} END { for(i=NR;i>0;i--){print array[i];} }' | while IFS= read line;do
@@ -433,7 +433,7 @@ EOF
} }
#设置路由规则 #设置路由规则
cn_ip_route(){ cn_ip_route(){
if [ ! -f $bindir/cn_ip.txt ];then [ ! -f $bindir/cn_ip.txt ] && {
if [ -f $clashdir/cn_ip.txt ];then if [ -f $clashdir/cn_ip.txt ];then
mv $clashdir/cn_ip.txt $bindir/cn_ip.txt mv $clashdir/cn_ip.txt $bindir/cn_ip.txt
else else
@@ -441,7 +441,14 @@ cn_ip_route(){
$0 webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt" $0 webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt"
[ "$?" = "1" ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败!" 31 [ "$?" = "1" ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败!" 31
fi fi
fi }
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" -a -f $bindir/cn_ip.txt -a -z "$(echo $redir_mod|grep -o 'Ntf')" ] && {
echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/cn_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> /tmp/cn_$USER.ipset
ipset -! flush cn_ip 2>/dev/null
ipset -! restore < /tmp/cn_$USER.ipset
rm -rf cn_$USER.ipset
}
} }
start_redir(){ start_redir(){
#获取局域网host地址 #获取局域网host地址
@@ -459,14 +466,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
[ -n "$host_lan" ] && iptables -t nat -A clash -d $host_lan -j RETURN [ -n "$host_lan" ] && iptables -t nat -A clash -d $host_lan -j RETURN
#绕过CN_IP #绕过CN_IP
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" -a -f $bindir/cn_ip.txt ] && { [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/cn_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> /tmp/cn_$USER.ipset
ipset -! flush cn_ip 2>/dev/null
ipset -! restore < /tmp/cn_$USER.ipset
rm -rf cn_$USER.ipset
iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1
}
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
#mac白名单 #mac白名单
for mac in $(cat $clashdir/mac); do for mac in $(cat $clashdir/mac); do
@@ -547,6 +547,7 @@ start_dns_redir(){
} }
start_tproxy(){ start_tproxy(){
modprobe xt_TPROXY & >/dev/null
#获取局域网host地址 #获取局域网host地址
host_lan host_lan
ip rule add fwmark 1 table 100 ip rule add fwmark 1 table 100
@@ -563,7 +564,7 @@ start_tproxy(){
iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN
[ -n "$host_lan" ] && iptables -t mangle -A clash -d $host_lan -j RETURN [ -n "$host_lan" ] && iptables -t mangle -A clash -d $host_lan -j RETURN
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 #绕过大陆IP [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
tproxy_set(){ tproxy_set(){
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
#mac白名单 #mac白名单
@@ -653,12 +654,13 @@ start_output(){
} }
} }
start_tun(){ start_tun(){
modprobe tun &> /dev/null
iptables -I FORWARD -o utun -j ACCEPT
#ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
if [ "$quic_rj" = 已启用 ];then if [ "$quic_rj" = 已启用 ];then
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst' [ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && set_cn_ip='-m set ! --match-set cn_ip dst'
iptables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash QUIC REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1 iptables -I FORWARD -p udp --dport 443 -o utun -m comment --comment "ShellClash-QUIC-REJECT" $set_cn_ip -j REJECT >/dev/null 2>&1
fi fi
iptables -A FORWARD -o utun -j ACCEPT
#ip6tables -A FORWARD -o utun -j ACCEPT > /dev/null 2>&1
} }
start_nft(){ start_nft(){
[ "$common_ports" = "已开启" ] && PORTS=$(echo $multiport | sed 's/,/, /g') [ "$common_ports" = "已开启" ] && PORTS=$(echo $multiport | sed 's/,/, /g')
@@ -674,7 +676,10 @@ start_nft(){
nft add table shellclash 2> /dev/null nft add table shellclash 2> /dev/null
nft flush table shellclash 2> /dev/null nft flush table shellclash 2> /dev/null
[ "$redir_mod" = "Nft基础" ] && nft add chain shellclash prerouting { type nat hook prerouting priority -100 \; } [ "$redir_mod" = "Nft基础" ] && nft add chain shellclash prerouting { type nat hook prerouting priority -100 \; }
[ "$redir_mod" = "Nft混合" ] && nft add chain shellclash prerouting { type filter hook prerouting priority 0 \; } [ "$redir_mod" = "Nft混合" ] && {
modprobe nft_tproxy &> /dev/null
nft add chain shellclash prerouting { type filter hook prerouting priority 0 \; }
}
[ -n "$(echo $redir_mod|grep Nft)" ] && { [ -n "$(echo $redir_mod|grep Nft)" ] && {
#设置DNS转发 #设置DNS转发
nft add chain shellclash dns { type nat hook prerouting priority -100 \; } nft add chain shellclash dns { type nat hook prerouting priority -100 \; }
@@ -886,7 +891,7 @@ catpac(){
#获取本机host地址 #获取本机host地址
[ -n "$host" ] && host_pac=$host [ -n "$host" ] && host_pac=$host
[ -z "$host_pac" ] && host_pac=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) [ -z "$host_pac" ] && host_pac=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E '\ 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
cat > /tmp/clash_pac <<EOF cat > /tmp/clash_pac <<EOF
//如看见此处内容,请重新安装本地面板! //如看见此处内容,请重新安装本地面板!
function FindProxyForURL(url, host) { function FindProxyForURL(url, host) {
@@ -992,10 +997,10 @@ bfstart(){
[ -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
if [ -w /etc/init.d/clash ]; then if [ -w /etc/init.d/clash ]; then
[ -z "$(grep 'procd_set_param\ user\ shellclash' /etc/init.d/clash)" ] && \ [ -z "$(grep 'procd_set_param user shellclash' /etc/init.d/clash)" ] && \
sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellclash' /etc/init.d/clash sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellclash' /etc/init.d/clash
elif [ -w "$servdir" ]; then elif [ -w "$servdir" ]; then
setconfig ExecStart "/bin/su\ shellclash\ -c\ \"$bindir/clash\ -d\ $bindir\"" $servdir setconfig ExecStart "/bin/su shellclash -c \"$bindir/clash -d $bindir\"" $servdir
systemctl daemon-reload >/dev/null systemctl daemon-reload >/dev/null
fi fi
fi fi