#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
cd /www/
function getping
{
str=$*
str=${str//\"/}
str=${str// /}
HOST=`echo "${str}"|awk -F 'server:' '{print $2}'|awk -F ',' '{print $1}'`
[ "${HOST}" == "" ] && HOST=${str}
ping -c 1 -W 1 ${HOST} >/dev/null 2>/dev/null
echo $?
}


S=$(curl -s -kL 'https://skill-note.blogspot.com/2023/09/21-find-isnumber-len-substitute.html'|grep 'Clash-meta 20.37版以后'|awk -F 'Clash-meta 20.37版以后' '{print $2}'|awk -F 'https://drive.google.com' '{print $2}'|awk -F '<' '{print $1}')
S="https://drive.google.com${S}"
curl -kL -s -o /www/sf.yaml.1 "${S}"
[ "`grep 'mixed-port' /www/sf.yaml.1`" != "" ] && mv /www/sf.yaml.1 /www/sf.yaml

cat >/www/v2ray.txt <<EOF
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@bestcf.yzqiang.site:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#bestcf.yzqiang.site
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@usa.visa.com:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#usa.visa.com
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@myanmar.visa.com:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#myanmar.visa.com
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@www.visa.com.tw:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#www.visa.com.tw
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@www.visaeurope.ch:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#www.visaeurope.ch
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@www.visa.com.br:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#www.visa.com.br
vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@www.visasoutheasteurope.com:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#vwww.visasoutheasteurope.com
EOF
S=$(curl -s -kL 'https://skill-note.blogspot.com/2023/09/21-find-isnumber-len-substitute.html'|grep 'Quantumult X订阅'|awk -F 'Quantumult X订阅' '{print $2}'|awk -F 'https://drive.google.com' '{print $2}'|awk -F '<' '{print $1}')
S="https://drive.google.com${S}"
curl -kL -s -o /www/v2ray.txt.1 "${S}"
[ "`grep 'vless:' /www/v2ray.txt.1`" != "" ] && cat  /www/v2ray.txt.1 >>/www/v2ray.txt


DDDD=0

cp /www/clash.yaml.source /www/clash.yaml.tmp
rm -rf NODE_LST.txt SERVER_LST.txt BEST_LST.txt  SF_LST.txt 85LA_LST.txt
echo "">NODE_LST.txt
###BASE=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: c379b284.vs-494.pages.dev, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: c379b284.vs-494.pages.dev}}}'
#BASE=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.yzqiang.site, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.yzqiang.site}}}'
#BASE1=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.yzqiang.site, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.yzqiang.site}}}'
#BASE2=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.yzqiang.dpdns.org, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.yzqiang.dpdns.org}}}'
#BASE3=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.smccb.dpdns.org, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.smccb.dpdns.org}}}'
#BASE4=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.yzqiang.qzz.io, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.yzqiang.qzz.io}}}'
#BASE5=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: v.smccb.qzz.io, client-fingerprint: chrome, ws-opts: {path: "/?ed=2560", headers: {host: v.smccb.qzz.io}}}'
#BASE_arr=("v.yzqiang.site" "v.yzqiang.dpdns.org" "v.smccb.dpdns.org" "v.yzqiang.qzz.io" "v.smccb.qzz.io")
#BASE_arr=("v.yzqiang.dpdns.org" "v.smccb.dpdns.org" "v.yzqiang.qzz.io" "v.smccb.qzz.io")
#SNPATH='/?ed=2560'
#BASE_arr=("aa.yzqiang.site")
#BASE_arr=("aa.yzqiang.dpdns.org" "aa.smccb.dpdns.org" "aa.yzqiang.qzz.io" "aa.smccb.qzz.io")
BASE_arr=("ae.yzqiang.dpdns.org")
SNPATH='/?ed=2048'
BASE_LEN=${#BASE_arr[@]}
BASE_NO=$RANDOM
function getbase 
{
let BASE_NO=${BASE_NO}+1
let NO=${BASE_NO}%${BASE_LEN}
BASE=', port: 443, type: vless, uuid: b940be1b-3998-45d2-bf7b-06e7b6c4987a, network: ws, tls: true, udp: false, sni: '${BASE_arr[${NO}]}', client-fingerprint: chrome, ws-opts: {path: "'${SNPATH}'", headers: {host: '${BASE_arr[${NO}]}'}}}'
}
if true ; then
curl -s -kL http://home1.yzqiang.site:18765/best.txt|while read str
do
  if [ `getping "${str}"` == 0 ] ; then
  getbase
  SSSS="  - {name: ${str}, server: ${str}"
  echo "${SSSS}${BASE}" >>SERVER_LST.txt
  echo "      - ${str}" >>NODE_LST.txt
  echo "      - ${str}" >>BEST_LST.txt  
  fi
#  echo "vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@${}:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#v.yzqiang.site" >>/tmp/v2ray.txt.tmp
  let BB=${BB}+1
done


echo "ct.877774.xyz
bestcf.yzqiang.site
ai.cloudflare.com
workers.cloudflare.com
developers.cloudflare.com
blog.cloudflare.com
#ns.cloudflare.com
www.visa.cn
usa.visa.com
www.visa.com.tw
www.visa.com.hk
www.visa.com.sg
www.shopify.com
icook.hk
www.epicgames.com
www.fortnite.com
#time.is
#cdnjs.com
cloudflare.182682.xyz
#bestcf.onecf.eu.org"|while read str
do
[ "${str}" == "" ] && continue
[ "`echo ${str}|grep '#'`" != "" ] && continue
if [ `getping "${str}"` == 0 ] ; then
getbase
echo "  - {name: ${str}, server: ${str}${BASE}" >>SERVER_LST.txt
echo "      - ${str}" >>NODE_LST.txt  
echo "      - ${str}" >>BEST_LST.txt  
fi 
done



BB=11
#curl -s -kL https://ghproxy.cn/https://raw.githubusercontent.com/ymyuuu/IPDB/refs/heads/main/bestcf.txt|head -14|while read str
curl -s -kL https://raw.githubusercontent.com/ymyuuu/IPDB/refs/heads/main/BestCF/bestcfv4.txt|head -14|while read str
do
  if [ "`grep ${str} NODE_LST.txt`" == "" ] ; then
  if [ `getping "${str}"` == 0 ] ; then
  getbase
  SSSS="  - {name: ${str}, server: ${str}"
  echo "${SSSS}${BASE}" >>SERVER_LST.txt
  echo "      - ${str}" >>NODE_LST.txt
  echo "      - ${str}" >>BEST_LST.txt  
  fi
  fi
#  echo "vless://b940be1b-3998-45d2-bf7b-06e7b6c4987a@${}:443?encryption=none&security=tls&type=ws&host=v.yzqiang.site&sni=v.yzqiang.site&fp=random&path=%2F%3Fed%3D2560#v.yzqiang.site" >>/tmp/v2ray.txt.tmp
  let BB=${BB}+1
done
BB=21
curl -s 'https://api.hostmonit.com/get_optimization_ip' -d '{"key":"iDetkOys"}'|jq '.info[]'|jq -r '[.ip,.speed]|@csv'|tr '"' ' '|tr ',' ' '|sort -rk2 -n|awk '{print $1}'|head -15|while read str
do
  if [ "`grep ${str} NODE_LST.txt`" == "" ] ; then  
  if [ `getping "${str}"` == 0 ] ; then
  getbase
  SSSS="  - {name: ${str}, server: ${str}"
  echo "${SSSS}${BASE}" >>SERVER_LST.txt
  echo "      - ${str}" >>NODE_LST.txt
  fi
  fi
  let BB=${BB}+1

done

fi

if false ; then
cp /dev/null NODE_LST0.txt
cp /dev/null SF_LST0.txt
#grep '{"name"' /www/sf.yaml|grep -E '美国|日本|新加坡|香港|台湾|韩国|俄罗斯'|sort|while read str
#grep '{"name"' /www/sf.yaml|grep trojan|sort|while read str
#grep '{"name"' /www/sf.yaml|sort|while read str
grep '{"name"' /www/sf.yaml|grep -E '美国|日本|新加坡|香港|台湾|韩国|俄罗斯'|sort|while read str
do
#str=`echo -e "${str}"|tr -d '\n'|tr -d '\r'`
#str=${str//YouTube顺丰资源 /}
#str=${str//YouTube顺丰资源/}
#str=${str//Youtube顺丰资源 /}
NAME=$(echo "${str}" |awk -F '"name": "' '{print $2}'|awk -F '"' '{print $1}')

if [ "`grep '${NAME}' NODE_LST.txt`" == "" ] ; then  
if [ `getping "${str}"` == 0 ] ; then
#if [ "`grep ${NAME} NODE_LST0.txt`" == "" ] ; then
echo "  ${str}" >>SERVER_LST.txt
echo "      - ${NAME}"  >>NODE_LST0.txt

echo "      - ${NAME}"  >>SF_LST0.txt
#fi
fi
fi
done
sort NODE_LST0.txt >>NODE_LST.txt
sort SF_LST0.txt >SF_LST.txt


cp /dev/null NODE_LST0.txt
cp /dev/null 85LA_LST0.txt
#https://www.85la.com/internet-access/free-network-nodes
URL=$(curl -s 'https://www.85la.com/internet-access/free-network-nodes' |grep -A 3 -m 1 '<div class="excerpt-sticky title-article list-card item-box 85la 85la">'|grep 'href="'|awk -F '"' '{print $2}')
URL=$(curl -s ${URL}|grep -A 3 'Clash.meta 订阅地址'|grep 'href='|awk -F 'href="' '{print $2}'|awk -F '"' '{print $1}')
curl -s 'https://api.ytools.cc/sub?target=clash&url='${URL}'&config=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2FSleepyHeeead%2Fsubconverter-config%40master%2Fremote-config%2Fspecial%2Fbasic.ini&emoji=false&add_emoji=false&remove_emoji=true&udp=false&insert=true&prepend=true&scv=false&fdn=true'|grep ' - {name:'|grep trojan|grep -v  'CN_'|while read str
do

if [ `getping "${str}"` == 0 ] ; then
str=${str//www.85la.com /85LA_}
str=${str//www.85la.com/85LA_}

NAME=$(echo "${str}" |awk -F 'name: ' '{print $2}'|awk -F ',' '{print $1}')

if [ "`grep ${NAME} NODE_LST0.txt`" == "" ] ; then
echo "  ${str}" >>SERVER_LST.txt
echo "      - ${NAME}"  >>NODE_LST0.txt

echo "      - ${NAME}"  >>85LA_LST0.txt
fi
fi
done
sort NODE_LST0.txt >>NODE_LST.txt
sort 85LA_LST0.txt >85LA_LST.txt

[ $(wc -l 85LA_LST.txt|awk '{print $1}') == 0 ] && grep -E 'US|美国' SF_LST.txt|head -10 >85LA_LST.txt

fi

sed -i '/#SERVER_LST#/r SERVER_LST.txt' /www/clash.yaml.tmp
sed -i '/#NODE_LST#/r NODE_LST.txt' /www/clash.yaml.tmp
sed -i '/#BEST_LST#/r BEST_LST.txt' /www/clash.yaml.tmp
sed -i '/#SF_LST#/r SF_LST.txt' /www/clash.yaml.tmp
sed -i '/#85LA_LST#/r 85LA_LST.txt' /www/clash.yaml.tmp

sed -i '/#SERVER_LST#/d'  /www/clash.yaml.tmp
sed -i '/#NODE_LST#/d'  /www/clash.yaml.tmp
sed -i '/#BEST_LST#/d'  /www/clash.yaml.tmp
sed -i '/#SF_LST#/d'  /www/clash.yaml.tmp
sed -i '/#85LA_LST#/d'  /www/clash.yaml.tmp
cp /www/clash.yaml.tmp /www/clash.yaml

cp /www/clash.yaml /www/openclash.yaml
sed -i  '/备用节点/d'  /www/openclash.yaml


##############TV

#curl -s -kL -o IPTV.txt https://raw.githubusercontent.com/fuxinyi0505/Ku9-IPTV-source/refs/heads/main/Ku9-IPTV-source.txt
#curl -s -o Gather.m3u https://tv.iill.top/m3u/Gather
#curl -s -o mytv.txt https://tv.iill.top/m3u/MyTV
