diff --git a/clash/clash b/clash/clash index b137fe6..b9179c9 100644 Binary files a/clash/clash and b/clash/clash differ diff --git a/clash/clashservice b/clash/clashservice index 548c7d8..53287c6 100644 --- a/clash/clashservice +++ b/clash/clashservice @@ -4,6 +4,24 @@ USE_PROCD=1 START=99 + +getconfig(){ +ccfg=/etc/clash/mark +csh=/bin/clash +if [ ! -f "$ccfg" ]; then +echo mark文件不存在,默认以Redir模式运行! +cat >$ccfg< 0 ];then +run="\033[32m正在运行($redir_mod)\033[0m" +VmRSS=`cat /proc/$uid/status|grep -w VmRSS|awk '{print $2,$3}'` + #获取运行时长 + if [ "$start_time" > 0 ] > /dev/null 2>&1; then + time=$((`date +%s`-$start_time)) + day=$(($time/86400)) + if [[ $day != 0 ]]; then + day=$day天 + else + day="" + fi + time=`date -u -d @${time} +"%-H小时%-M分%-S秒"` + fi +else +run="\033[31m没有运行($redir_mod)\033[0m" +fi +#输出状态 +echo ----------------------------------------------- +echo -e "Clash服务"$run","$auto"" +if [ $uid > 0 ];then +echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" +fi +} + +getyaml(){ +source $ccfg +#前后端订阅服务器地址索引 +Server=`sed -n ""$server_link"p"< /dev/null 2>&1 + +result=$(curl -w %{http_code} -skLo $yamlnew $Https) +if [ "$result" != "200" ];then +echo ----------------------------------------------- +echo 配置文件获取失败!请检查链接或者更换后端地址! +exit; +else + if cat $yamlnew | grep proxies>/dev/null;then +##########需要变更的配置########### +redir='redir-port: 7892' +external='external-controller: 0.0.0.0:9999' +dns='dns: {enable: true, listen: 0.0.0.0:1053, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, nameserver: [tls://dns.rubyfish.cn:853, 127.0.0.1:53], fallback: [tcp://1.1.1.1, tls://dns.google:853]}' +tun='tun: {enable: true, stack: system}' +exper='experimental: {ignore-resolve-fail: true, interface-name: en0}' +################################### + #预删除需要添加的项目 + sed -i '/redir-port:*/'d $yamlnew + sed -i '/external-controller:*/'d $yamlnew + sed -i '/dns:*/'d $yamlnew + sed -i '/tun:*/'d $yamlnew + sed -i '/experimental:*/'d $yamlnew + #添加配置 + sed -i "2a$redir" $yamlnew + sed -i "6a$external" $yamlnew + sed -i "7a$dns" $yamlnew + sed -i "8a$tun" $yamlnew + sed -i "9a$experimental" $yamlnew + sed -i "1,40s/sni: \S*/\1skip-cert-verify: true}/" $yamlnew + #替换文件 + mv $yaml $yaml.bak + mv $yamlnew $yaml + echo 配置文件已生成!正在重启clash使其生效! + #重启clash服务 + /etc/init.d/clash stop + /etc/init.d/clash start + Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` + if [ $Num > 0 ];then + echo ----------------------------------------------- + echo -e "\033[32mclash服务已启动!\033[0m" + echo 可以使用 http://clash.razord.top (IP为网关IP,端口为9999)管理clash内置规则 + clashsh + else + echo ----------------------------------------------- + echo -e "\033[31mclash服务启动失败!请检查配置文件!\033[0m" + clashsh + fi + exit; + else + echo ----------------------------------------------- + echo 囧囧囧 获取到了配置文件,但格式似乎不对 囧囧囧 + echo 请手动输入命令:cat $yamlnew 以检查配置文件信息! + fi + exit; +fi +exit +} +getlink(){ +#设置输入循环 +i=1 +while [ $i -le 5 ] +do +echo ----------------------------------------------- +echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +echo ----------------------------------------------- +echo -e "\033[32m支持批量导入Vmess/SSR/SS格式的订阅链接" +echo -e "支持批量导入Vmess/SSR/SS/Trojan格式的节点链接" +echo -e "多个较短的链接可以用|分隔以一次性输入" +echo -e "多个较长的链接请尽量分多次输入" +echo -e "\033[33m输入回车以结束输入!\033[0m" +echo +read -p "请输入第"$i"个链接 > " url + test=$(echo $url | grep "://") + if [[ "$test" != "" ]];then + if [[ $i == 1 ]];then + Url=$url + else + Url="$Url"\|"$url" + fi + i=$(($i+1)) + elif [ -z $url ];then + if [ -n $Url ];then + echo ----------------------------------------------- + echo 请检查输入的链接是否正确! + echo $Url + read -p "确认导入配置文件?原配置文件将被更名为config.bak![1/0] > " res + if [ "$res" = '1' ]; then + #将用户链接写入mark + sed -i '/Url=*/'d $ccfg + sed -i "6i\Url=\'$Url\'" $ccfg + #获取在线yaml文件 + getyaml + echo 111 + exit; + fi + fi + elif [[ $url == 0 ]];then + clashsh + else + echo ----------------------------------------------- + echo 请输入正确的订阅/分享链接!!! + fi +done +echo ----------------------------------------------- +echo 输入太多啦,可能会导致订阅失败! +echo 请检查输入的链接是否正确:$Url +read -p "确认导入配置文件?原配置文件将被更名为config.bak![1/0] > " res + if [ "$res" = '1' ]; then + #将用户链接写入mark + sed -i '/Url=*/'d $ccfg + sed -i "6i\Url=\'$Url\'" $ccfg + #获取在线yaml文件 + getyaml + echo 222 + exit; + else + echo ----------------------------------------------- + echo 操作已取消!返回上级菜单! + clashlink + fi + } +clashlink(){ +#获取订阅规则 +if [ ! -n "$rule_link" ]; then +sed -i '/rule_link=*/'d $ccfg +sed -i "4i\rule_link=1" $ccfg +rule_link=1 +fi +#获取后端服务器地址 +if [ ! -n "$server_link" ]; then +sed -i '/server_link=*/'d $ccfg +sed -i "5i\server_link=1" $ccfg +server_link=1 +fi +echo ----------------------------------------------- +echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +echo 欢迎使用订阅功能! +echo -e 1 输入订阅链接 +echo -e 2 选取规则模版 +echo -e 3 选择后端地址 +echo -e 4 还原配置文件 +echo -e 5 手动更新订阅 +echo -e 6 设置自动更新(未完成) +echo -e 0 返回上级菜单 +read -p "请输入对应数字 > " num +if [ -z $num ];then + echo ----------------------------------------------- + echo 请输入正确的数字! + clashlink +elif [[ $num == 1 ]];then + getlink +elif [[ $num == 2 ]];then + echo ----------------------------------------------- + echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" + echo 当前使用规则为:$rule_link + echo 1 ACL4SSR默认通用版(推荐) + echo 2 ACL4SSR精简全能版(推荐) + echo 3 ACL4SSR通用版去广告加强 + echo 4 ACL4SSR精简版去广告加强 + echo 5 ACL4SSR通用版无去广告 + echo 0 返回上级菜单 + read -p "请输入对应数字 > " num + if [ -z $num ];then + echo ----------------------------------------------- + echo 请输入正确的数字! + clashlink + else + #将对应标记值写入mark + sed -i '/rule_link*/'d $ccfg + sed -i "4i\rule_link="$num"" $ccfg + echo ----------------------------------------------- + echo 设置成功!返回上级菜单! + clashlink + fi +elif [[ $num == 3 ]];then + echo ----------------------------------------------- + echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" + echo 当前使用后端为:$server_link + echo 1 subconverter-web.now.sh + echo 2 subcon.py6.pw + echo 3 api.dler.io + echo 4 api.wcc.best + echo 0 返回上级菜单 + read -p "请输入对应数字 > " num + if [ -z $num ];then + echo ----------------------------------------------- + echo 请输入正确的数字! + clashlink + else + #将对应标记值写入mark + sed -i '/server_link*/'d $ccfg + sed -i "4i\server_link="$num"" $ccfg + echo ----------------------------------------------- + echo 设置成功!返回上级菜单! + clashlink + fi +elif [[ $num == 4 ]];then + yamlbak=$yaml.bak + if [ ! -f "$yaml".bak ];then + echo ----------------------------------------------- + echo 没有找到配置文件的备份! + else + echo ----------------------------------------------- + echo 备份文件共有`wc -l < $yamlbak`行内容,当前文件共有`wc -l < $yaml`行内容 + read -p "确认还原配置文件?此操作不可逆![1/0] > " res + if [ "$res" = '1' ]; then + mv $yamlbak $yaml + echo ----------------------------------------------- + echo 配置文件已还原!!! + else + echo 操作已取消!返回上级菜单! + fi + fi + clashlink +elif [[ $num == 5 ]];then + if [ ! -n "$Url" ];then + echo ----------------------------------------------- + echo 没有找到你的订阅链接!请先输入链接! + clashlink + else + echo ----------------------------------------------- + echo ----------------------------------------------- + echo 记录的订阅链接为: + echo $Url + echo ----------------------------------------------- + read -p "确认更新配置文件?[1/0] > " res + if [ "$res" = '1' ]; then + getyaml + fi + clashlink + fi +elif [[ $num == 0 ]];then + clashsh +else + echo 请输入正确的数字! + exit; +fi +} clashadv(){ echo ----------------------------------------------- echo -e "\033[33m欢迎使用高级模式菜单:\033[0m" @@ -30,7 +341,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then elif [[ $num == 1 ]]; then echo ----------------------------------------------- - echo -e "当前代理模式为:\033[47;30m $Mark3 \033[0m" + echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0m" echo -e "\033[33m切换模式时会重启clash服务,可能会导致短时间的网络中断!\033[0m" echo "1 Tun模式: 支持UDP转发且延迟低" echo " 但CPU及内存占用更高" @@ -43,22 +354,22 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then if [[ $num == 0 ]]; then clashadv elif [[ $num == 1 ]]; then - if [[ $Mark3 = "Redir模式" ]]; then - sed -i '1,20s/Redir模式/Tun模式/' /bin/clash #修改Mark3标记 - sed -i '1,40s/tun: {enable: false/tun: {enable: true/' /etc/clash/config.yaml #修改配置文件 - if [ $Number1 -gt 0 ];then + if [[ $redir_mod = "Redir模式" ]]; then + sed -i '/redir_mod*/'d $ccfg + sed -i "2i\redir_mod=Tun模式" $ccfg #修改redir_mod标记 + sed -i '1,40s/tun: {enable: false/tun: {enable: true/' $yaml #修改配置文件 + if [ $uid > 0 ];then > /dev/null 2>&1 echo ----------------------------------------------- echo -e "\033[33m正在重启clash进程……\033[0m" /etc/init.d/clash stop > /dev/null 2>&1 fi /etc/init.d/clash start - Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Number2 -gt 0 ];then + Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` + if [ $Num > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo -e "\033[33mclash已成功切换为:\033[47;34m Tun模式! \033[0m" echo -e 可以使用 "\033[32mhttp://clash.razord.top\033[0m"(IP为网关IP,端口为9999)管理clash内置规则 - Mark3="Tun模式" clashsh else echo ----------------------------------------------- @@ -72,22 +383,22 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi elif [[ $num == 2 ]]; then - if [[ $Mark3 = "Tun模式" ]]; then - sed -i '1,20s/Tun模式/Redir模式/' /bin/clash #修改Mark3标记 - sed -i '1,40s/tun: {enable: true/tun: {enable: false/' /etc/clash/config.yaml #修改配置文件 - if [ $Number1 -gt 0 ];then + if [[ $redir_mod = "Tun模式" ]]; then + sed -i '/redir_mod*/'d $ccfg + sed -i "2i\redir_mod=Redir模式" $ccfg #修改redir_mod标记 + sed -i '1,40s/tun: {enable: false/tun: {enable: true/' $yaml #修改配置文件 + if [ $uid > 0 ];then echo ----------------------------------------------- echo -e "\033[33m正在重启clash进程……\033[0m" /etc/init.d/clash stop > /dev/null 2>&1 fi /etc/init.d/clash start - Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Number2 -gt 0 ];then + Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` + if [ $Num > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo -e "\033[33mclash已成功切换为:\033[47;34m Redir模式! \033[0m" echo -e 可以使用 "\033[32mhttp://clash.razord.top\033[0m"(IP为网关IP,端口为9999)管理clash内置规则 - Mark3="Redir模式" clashsh else echo ----------------------------------------------- @@ -111,7 +422,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then /etc/init.d/clash stop rm -rf /etc/clash rm /etc/init.d/clash - rm /bin/clash + rm $csh echo 已卸载clash相关文件! fi exit; @@ -126,14 +437,9 @@ fi exit; } clashsh(){ -Number1=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` -if [ $Number1 -gt 0 ];then -Mark1="\033[32m正在运行($Mark3)\033[0m" -else -Mark1="\033[31m没有运行($Mark3)\033[0m" -fi -echo ----------------------------------------------- -echo -e "Clash服务$Mark1,$Mark2" +############################# +getconfig +############################# echo 1 启动/重启clash服务 echo 2 测试代理服务器连通性 echo 3 停止clash服务 @@ -148,15 +454,15 @@ if [[ $num -le 7 ]] > /dev/null 2>&1; then exit; elif [[ $num == 1 ]]; then - if [ $Number1 -gt 0 ];then + if [ $uid > 0 ];then echo ----------------------------------------------- /etc/init.d/clash stop > /dev/null 2>&1 echo -e "\033[31mClash服务已停止!\033[0m" sleep 1 fi /etc/init.d/clash start - Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` - if [ $Number2 -gt 0 ];then + Num=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l` + if [ $Num > 0 ];then echo ----------------------------------------------- echo -e "\033[32mclash服务已启动!\033[0m" echo 可以使用 http://clash.razord.top (IP为网关IP,端口为9999)管理clash内置规则 @@ -169,20 +475,16 @@ if [[ $num -le 7 ]] > /dev/null 2>&1; then exit; elif [[ $num == 2 ]]; then - echo 注意:连续多次测试可能会导致IP暂时被GitHub封禁! - delay=`curl -kx socks5://127.0.0.1:7891 -o /dev/null -s -w '%{time_total}' 'https://github.com' & { sleep 3 ; kill $! & }` > /dev/null 2>&1 - delay0=`expr length x$delay` - #echo $delay - if [ $delay0 == 1 ];then - echo ---------------------------------------------- - echo '连接超时(>3s),请检查节点信息!' - clashsh - else + echo 注意:测试结果不保证一定准确! + delay=`curl -kx socks5://127.0.0.1:7891 -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1 + delay=`echo |awk "{print $delay*1000}"` > /dev/null 2>&1 echo ----------------------------------------------- - echo 连接成功!响应时间为:$delay秒 - clashsh + if [ `echo ${#delay}` -gt 1 ];then + echo -e "\033[32m连接成功!响应时间为:"$delay" ms\033[0m" + else + echo -e "\033[31m连接超时!请重试或检查节点配置!\033[0m" fi - + clashsh elif [[ $num == 3 ]]; then /etc/init.d/clash stop > /dev/null 2>&1 echo ----------------------------------------------- @@ -192,18 +494,18 @@ if [[ $num -le 7 ]] > /dev/null 2>&1; then elif [[ $num == 4 ]]; then /etc/init.d/clash enable - sed -i '1,20s/1m未/2m已/' /bin/clash + sed -i '/auto_start*/'d $ccfg + sed -i "1i\auto_start=true" $ccfg echo ----------------------------------------------- echo -e "\033[32m已设置Clash开机启动!\033[0m" - Mark2="\033[32m已设置开机启动!\033[0m" clashsh elif [[ $num == 5 ]]; then /etc/init.d/clash disable - sed -i '1,20s/2m已/1m未/' /bin/clash + sed -i '/auto_start*/'d $ccfg + sed -i "1i\auto_start=false" $ccfg echo ----------------------------------------------- echo -e "\033[33m已禁止Clash开机启动!\033[0m" - Mark2="\033[31m未设置开机启动!\033[0m" clashsh elif [[ $num == 6 ]]; then diff --git a/clash/config.yaml b/clash/config.yaml index 383b4ed..eae8c73 100644 --- a/clash/config.yaml +++ b/clash/config.yaml @@ -106,8 +106,6 @@ proxy-groups: # 规则 rules: # Unbreak -#clash面板 -- DOMAIN,clash.razord.top,DIRECT # > Google - DOMAIN-SUFFIX,googletraveladservices.com,DIRECT - DOMAIN,dl.google.com,DIRECT diff --git a/clash/test.ini b/clash/test.ini deleted file mode 100644 index 9daeafb..0000000 --- a/clash/test.ini +++ /dev/null @@ -1 +0,0 @@ -test