diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index ab7d4e6..4ec10a7 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/version b/bin/version index 8e64281..06af3c4 100644 --- a/bin/version +++ b/bin/version @@ -1,2 +1,4 @@ GeoIP_v=20201001 -versionsh=1.0.0pre1 +clash_v=1.1.0 +clashpre_v=2020.09.27 +versionsh=1.0.0beta12 diff --git a/install.sh b/install.sh index 5adb069..89dc211 100644 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ # Copyright (C) Juewuy echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo -test=0 +test=1 echo "***********************************************" echo "** 欢迎使用 **" @@ -14,6 +14,7 @@ url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash" if [ $test -ge 1 ];then url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master" [ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" + [ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi" else release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本 fi @@ -25,7 +26,7 @@ gettar(){ result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl) [ "$result" != "200" ] && echo "文件下载失败!" && exit 1 #解压 - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo 开始解压文件! mkdir -p $clashdir > /dev/null tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ @@ -68,17 +69,24 @@ gettar(){ rm -rf $clashdir/clashservice rm -rf $clashdir/clash.service } -#输出 -$echo "最新版本:\033[32m$release_new\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" -$echo "\033[37m支持各种基于openwrt的路由器设备" -$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#下载及安装 +install(){ +echo ----------------------------------------------- +echo 开始从服务器获取安装文件! +echo ----------------------------------------------- +gettar +echo ----------------------------------------------- +echo ShellClash 已经安装成功! +echo ----------------------------------------------- +$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" +echo ----------------------------------------------- +} +setdir(){ +echo ----------------------------------------------- $echo "\033[32m 1 在默认目录(/etc)安装" $echo "\033[33m 2 手动设置安装目录" $echo "\033[0m 0 退出安装" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo ----------------------------------------------- read -p "请输入相应数字 > " num #设置目录 if [ -z $num ];then @@ -87,29 +95,46 @@ if [ -z $num ];then elif [ "$num" = "1" ];then dir=/etc elif [ "$num" = "2" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo '可用路径 剩余空间:' df -h | awk '{print $6,$2}'| sed 1d echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!' read -p "请输入自定义路径 > " dir - if [ -z $dir ];then - echo 路径错误!已取消安装! + if [ -z "$dir" ];then + $echo "\033[31m路径错误!已取消安装!\033[0m" exit; fi else - echo 安装已取消 + echo 安装已取消!!! exit; fi clashdir=$dir/clash -#输出 -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo 开始从服务器获取安装文件! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#下载及安装 -gettar -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo ShellClash 已经安装成功! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +install +} +#输出 +$echo "最新版本:\033[32m$release_new\033[0m" +echo ----------------------------------------------- +$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +$echo "\033[37m支持各种基于openwrt的路由器设备" +$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" + +if [ -n "$clashdir" ];then + echo ----------------------------------------------- + $echo "检测到旧的安装目录\033[36m$clashdir\033[0m,是否覆盖安装?" + $echo "\033[32m覆盖安装时不会移除配置文件!\033[0m" + read -p "覆盖安装/卸载旧版本?(1/0) > " res + if [ "$res" = "1" ];then + install + elif [ "$res" = "0" ];then + rm -rf $clashdir + echo ----------------------------------------------- + $echo "\033[31m 旧版本文件已卸载!\033[0m" + setdir + else + $echo "\033[31m输入错误!已取消安装!\033[0m" + exit; + fi +else + setdir +fi diff --git a/install_cdn.sh b/install_cdn.sh index 5adb069..5d7af9a 100644 --- a/install_cdn.sh +++ b/install_cdn.sh @@ -14,6 +14,7 @@ url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash" if [ $test -ge 1 ];then url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master" [ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" + [ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi" else release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本 fi @@ -25,7 +26,7 @@ gettar(){ result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl) [ "$result" != "200" ] && echo "文件下载失败!" && exit 1 #解压 - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo 开始解压文件! mkdir -p $clashdir > /dev/null tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ @@ -68,17 +69,24 @@ gettar(){ rm -rf $clashdir/clashservice rm -rf $clashdir/clash.service } -#输出 -$echo "最新版本:\033[32m$release_new\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" -$echo "\033[37m支持各种基于openwrt的路由器设备" -$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#下载及安装 +install(){ +echo ----------------------------------------------- +echo 开始从服务器获取安装文件! +echo ----------------------------------------------- +gettar +echo ----------------------------------------------- +echo ShellClash 已经安装成功! +echo ----------------------------------------------- +$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" +echo ----------------------------------------------- +} +setdir(){ +echo ----------------------------------------------- $echo "\033[32m 1 在默认目录(/etc)安装" $echo "\033[33m 2 手动设置安装目录" $echo "\033[0m 0 退出安装" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo ----------------------------------------------- read -p "请输入相应数字 > " num #设置目录 if [ -z $num ];then @@ -87,29 +95,46 @@ if [ -z $num ];then elif [ "$num" = "1" ];then dir=/etc elif [ "$num" = "2" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo '可用路径 剩余空间:' df -h | awk '{print $6,$2}'| sed 1d echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!' read -p "请输入自定义路径 > " dir - if [ -z $dir ];then - echo 路径错误!已取消安装! + if [ -z "$dir" ];then + $echo "\033[31m路径错误!已取消安装!\033[0m" exit; fi else - echo 安装已取消 + echo 安装已取消!!! exit; fi clashdir=$dir/clash -#输出 -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo 开始从服务器获取安装文件! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#下载及安装 -gettar -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo ShellClash 已经安装成功! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +install +} +#输出 +$echo "最新版本:\033[32m$release_new\033[0m" +echo ----------------------------------------------- +$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +$echo "\033[37m支持各种基于openwrt的路由器设备" +$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" + +if [ -n "$clashdir" ];then + echo ----------------------------------------------- + $echo "检测到旧的安装目录\033[36m$clashdir\033[0m,是否覆盖安装?" + $echo "\033[32m覆盖安装时不会移除配置文件!\033[0m" + read -p "覆盖安装/卸载旧版本?(1/0) > " res + if [ "$res" = "1" ];then + install + elif [ "$res" = "0" ];then + rm -rf $clashdir + echo ----------------------------------------------- + $echo "\033[31m 旧版本文件已卸载!\033[0m" + setdir + else + $echo "\033[31m输入错误!已取消安装!\033[0m" + exit; + fi +else + setdir +fi diff --git a/install_test.sh b/install_test.sh index c9a1a15..89dc211 100644 --- a/install_test.sh +++ b/install_test.sh @@ -14,6 +14,7 @@ url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash" if [ $test -ge 1 ];then url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master" [ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" + [ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi" else release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本 fi @@ -25,7 +26,7 @@ gettar(){ result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl) [ "$result" != "200" ] && echo "文件下载失败!" && exit 1 #解压 - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo 开始解压文件! mkdir -p $clashdir > /dev/null tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ @@ -68,17 +69,24 @@ gettar(){ rm -rf $clashdir/clashservice rm -rf $clashdir/clash.service } -#输出 -$echo "最新版本:\033[32m$release_new\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" -$echo "\033[37m支持各种基于openwrt的路由器设备" -$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#下载及安装 +install(){ +echo ----------------------------------------------- +echo 开始从服务器获取安装文件! +echo ----------------------------------------------- +gettar +echo ----------------------------------------------- +echo ShellClash 已经安装成功! +echo ----------------------------------------------- +$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" +echo ----------------------------------------------- +} +setdir(){ +echo ----------------------------------------------- $echo "\033[32m 1 在默认目录(/etc)安装" $echo "\033[33m 2 手动设置安装目录" $echo "\033[0m 0 退出安装" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo ----------------------------------------------- read -p "请输入相应数字 > " num #设置目录 if [ -z $num ];then @@ -87,29 +95,46 @@ if [ -z $num ];then elif [ "$num" = "1" ];then dir=/etc elif [ "$num" = "2" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo ----------------------------------------------- echo '可用路径 剩余空间:' df -h | awk '{print $6,$2}'| sed 1d echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!' read -p "请输入自定义路径 > " dir - if [ -z $dir ];then - echo 路径错误!已取消安装! + if [ -z "$dir" ];then + $echo "\033[31m路径错误!已取消安装!\033[0m" exit; fi else - echo 安装已取消 + echo 安装已取消!!! exit; fi clashdir=$dir/clash -#输出 -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo 开始从服务器获取安装文件! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#下载及安装 -gettar -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo ShellClash 已经安装成功! -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理!!!\033[0m" -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +install +} +#输出 +$echo "最新版本:\033[32m$release_new\033[0m" +echo ----------------------------------------------- +$echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" +$echo "\033[37m支持各种基于openwrt的路由器设备" +$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" + +if [ -n "$clashdir" ];then + echo ----------------------------------------------- + $echo "检测到旧的安装目录\033[36m$clashdir\033[0m,是否覆盖安装?" + $echo "\033[32m覆盖安装时不会移除配置文件!\033[0m" + read -p "覆盖安装/卸载旧版本?(1/0) > " res + if [ "$res" = "1" ];then + install + elif [ "$res" = "0" ];then + rm -rf $clashdir + echo ----------------------------------------------- + $echo "\033[31m 旧版本文件已卸载!\033[0m" + setdir + else + $echo "\033[31m输入错误!已取消安装!\033[0m" + exit; + fi +else + setdir +fi diff --git a/scripts/clash.sh b/scripts/clash.sh index 793e0c8..357b3cd 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -6,8 +6,8 @@ getconfig(){ if [ -f /bin/opkg ];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}';) else - host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g') - [ -z $host ] && host=127.0.0.1 + host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g'|head -n 1) + [ -z "$host" ] && host=127.0.0.1 fi #服务器地址 [ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash @@ -28,7 +28,7 @@ if [ -f /etc/rc.common ];then autostart=disable_rc fi else - if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then + if [ -n "$(systemctl list-unit-files clash.service 2>&1 | grep -o enable)" ];then autostart=enable_sys else autostart=disable_sys @@ -44,6 +44,12 @@ else auto="\033[31m未设置开机启动!\033[0m" auto1="\033[36m允许\033[0mclash开机启动" fi +#获取默认端口 +[ -z "$mix_port" ] && mix_port=7890 +[ -z "$redir_port" ] && redir_port=7892 +[ -z "$db_port" ] && db_port=9999 +[ -z "$dns_port" ] && dns_port=1053 +[ -z "$secret" ] && secret=未设置 #获取运行模式 if [ -z "$redir_mod" ];then sed -i "2i\redir_mod=Redir模式" $ccfg @@ -63,15 +69,17 @@ if [ -n "$PID" ];then else day="" fi - time=`date -u -d @${time} +"%-H小时%-M分%-S秒"` + time=`date -u -d @${time} +%H小时%M分%S秒` fi else run="\033[31m没有运行($redir_mod)\033[0m" + #检测系统端口占用 + checkport fi #输出状态 echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l" +echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l" echo -e "Clash服务"$run","$auto"" if [ -n "$PID" ];then echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" @@ -82,6 +90,7 @@ echo ----------------------------------------------- if [ ! -f $clashdir/clash ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m没有找到核心文件,请先下载clash核心!\033[0m" + checkupdate source $clashdir/getdate.sh getcore fi @@ -89,9 +98,17 @@ fi if [ ! -f $clashdir/Country.mmdb ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m没有找到GeoIP数据库文件,请先下载数据库!\033[0m" + checkupdate source $clashdir/getdate.sh getgeo - clashstart +fi +#检查定时任务配置文件 +if [ -z "$cronpath" ];then + [ -d /etc/crontabs/ ] && cronpath="/etc/crontabs/root" + [ -d /var/spool/cron/ ] && cronpath="/var/spool/cron/root" + [ -d /var/spool/cron/crontabs/ ] && cronpath="/var/spool/cron/crontabs/root" + [ -d /etc/storage/cron/crontabs ] && cronpath="/etc/storage/cron/crontabs/admin" + [ -n "$cronpath" ] && sed -i "1i\cronpath=\'$cronpath\'" $ccfg fi } start_over(){ @@ -100,14 +117,93 @@ start_over(){ if [ -d /www/clash ];then echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则" elif [ -d $clashdir/ui ];then - echo -e "请使用\033[30;47m http://$host:9999/ui \033[0m管理内置规则" + echo -e "请使用\033[30;47m http://$host:$db_port/ui \033[0m管理内置规则" else 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 "Host地址:\033[36m $host \033[0m 端口:\033[36m $db_port \033[0m" echo -e "也可前往更新菜单安装本地Dashboard面板,连接更稳定!\033[0m" echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fi } +setport(){ + inputport(){ + read -p "请输入端口号(1000-65535) > " portx + if [ -z "$portx" ]; then + setport + elif [ $portx -gt 65535 -o $portx -le 999 ]; then + echo -e "\033[31m输入错误!请输入正确的数值(1000-65535)!\033[0m" + inputport + elif [ -n "$(echo $mix_port$redir_port$dns_port$db_port|grep $portx)" ]; then + echo -e "\033[31m输入错误!请不要输入重复的端口!\033[0m" + inputport + elif [ -n "$(netstat -ntul |grep :$portx)" ];then + echo -e "\033[31m当前端口已被其他进程占用,请重新输入!\033[0m" + inputport + else + sed -i "/$xport*/"d $ccfg + sed -i "1i$xport=$portx" $ccfg + echo -e "\033[32m设置成功!!!\033[0m" + setport + fi + } + source $ccfg + if [ -n "$(pidof clash)" ];then + echo ----------------------------------------------- + echo -e "\033[33m检测到clash服务正在运行,需要先停止clash服务!\033[0m" + read -p "是否停止clash服务?(1/0) > " res + if [ "$res" = "1" ];then + $clashdir/start.sh stop + else + clashsh + fi + fi + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e " 1 修改Http/Sock5端口:\033[36m$mix_port\033[0m" + echo -e " 2 修改静态路由端口:\033[36m$redir_port\033[0m" + echo -e " 3 修改DNS监听端口:\033[36m$dns_port\033[0m" + echo -e " 4 修改面板访问端口:\033[36m$db_port\033[0m" + echo -e " 5 修改面板访问密码:\033[36m$secret\033[0m" + echo -e " 0 返回上级菜单" + read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "\033[31m请输入正确的数字!\033[0m" + elif [[ $num == 1 ]]; then + xport=mix_port + inputport + elif [[ $num == 2 ]]; then + xport=redir_port + inputport + elif [[ $num == 3 ]]; then + xport=dns_port + inputport + elif [[ $num == 4 ]]; then + xport=db_port + inputport + elif [[ $num == 5 ]]; then + read -p "请输入面板访问密码 > " secret + if [ -n "$secret" ]; then + sed -i "/secret*/"d $ccfg + sed -i "1i\secret=$secret" $ccfg + echo -e "\033[32m设置成功!!!\033[0m" + fi + setport + fi +} +checkport(){ + for portx in $dns_port $mix_port $redir_port $db_port ;do + if [ -n "$(netstat -ntul |grep :$portx)" ];then + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + echo -e "检测到端口【$portx】被以下进程占用!clash可能无法正常启动!\033[33m" + echo $(netstat -ntulp | grep :$portx | head -n 1) + echo -e "\033[0m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + echo -e "\033[36m请修改默认端口配置!\033[0m" + setport + source $ccfg + checkport + fi + done +} clashstart(){ if [ ! -f "$yaml" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -329,7 +425,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[32m已经设置为纯净模式!\033[0m" echo -e "\033[33m当前模式必须手动在设备WiFi或应用中配置HTTP或sock5代理\033[0m" - echo -e "HTTP/SOCK5代理服务器地址:\033[30;47m$host\033[0m;端口均为:\033[30;47m7890\033[0m" + echo -e "HTTP/SOCK5代理服务器地址:\033[30;47m$host\033[0m;端口均为:\033[30;47m$mix_port\033[0m" echo -e "\033[31m也可以使用PAC自动代理文件,具体使用方法请自行搜索\033[0m" echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ read -p "是否配置自动代理PAC文件(1/0) > " res @@ -518,10 +614,11 @@ 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 ————实验性功能,可能不可用" -echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" -echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————配置本机代理环境变量" +echo -e " 1 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置" +echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不可用" +echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" +echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————配置本机代理环境变量" +echo -e " 5 手动指定clash运行端口" echo ----------------------------------------------- echo -e " 8 \033[31m重置\033[0m配置文件" echo -e " 9 \033[32m重启\033[0mclash服务" @@ -589,7 +686,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then sed -i "1i\local_proxy=已开启" $ccfg local_proxy=已开启 - echo 'export http_proxy=http://127.0.0.1:7890' >> /etc/profile + echo 'export http_proxy=http://127.0.0.1:'"$mix_port" >> /etc/profile echo 'export https_proxy=$http_proxy' >> /etc/profile echo 'export HTTP_PROXY=$http_proxy' >> /etc/profile echo 'export HTTPS_PROXY=$http_proxy' >> /etc/profile @@ -605,6 +702,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then fi source /etc/profile > /dev/null 2>&1 clashadv + elif [[ $num == 5 ]]; then + setport + clashadv elif [[ $num == 8 ]]; then read -p "确认重置配置文件?(1/0) > " res @@ -631,21 +731,27 @@ else fi exit; } -update(){ +checkupdate(){ if [ -z "$release_new" ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo -e "\033[33m正在检查更新!\033[0m" if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then - release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 3 -m 3 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') + release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 5 -m 5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') update_url=$update_url@$release_new fi - [ -z "$release_new" ] && release_new=$(curl -kfsSL --connect-timeout 3 -m 3 $update_url/bin/version | grep "versionsh" | awk -F "=" '{print $2}') - [ -z "$release_new" ] && echo "检查更新失败!" + curl -skL --connect-timeout 5 -m 5 $update_url/bin/version > /tmp/clashversion + source /tmp/clashversion + [ -z "$release_new" ] && release_new=$versionsh fi +} +update(){ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +echo -e "\033[33m正在检查更新!\033[0m" +checkupdate +[ "$clashcore" = "clash" ] && clash_n=$clash_v || clash_n=$clashpre_v echo -e "\033[30;47m欢迎使用更新功能:\033[0m" -[ -n "$release_new" ] && echo -e "当前ShellClash版本:\033[33m $versionsh_l \033[0m" -[ -n "$release_new" ] && echo -e "最新ShellClash版本:\033[32m $release_new \033[0m" +echo ----------------------------------------------- +echo -e "ShellClash 本地版本:\033[33m$versionsh_l \033[0m在线版本:\033[32m$versionsh\033[0m" +echo -e "Geoip数据库 本地版本:\033[33m$Geo_v \033[0m在线版本:\033[32m$GeoIP_v\033[0m" +echo -e "$clashcore核心 本地版本:\033[33m$clashv \033[0m在线版本:\033[32m$clash_n\033[0m" echo ----------------------------------------------- echo -e " 1 更新\033[36m管理脚本\033[0m" echo -e " 2 切换\033[33mclash核心\033[0m" @@ -801,15 +907,23 @@ clashcron(){ clashcron } checkcron(){ - [ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root" - [ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root" - [ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root" - if [ -z $cronpath ];then + if [ -z "$cronpath" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo "找不到定时任务文件,无法添加定时任务!" - clashsh + echo -e "\033[33m找不到定时任务配置文件,无法添加添加定时任务!" + echo -e "\033[0m请手动指定定时任务配置文件,文件位置可以通过【crontab -e】命令查看\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + read -p "请输入crontab文件路径(输入回车返回主菜单) > " path + if [ -z "$path" ];then + clashsh + elif [ -f $path ];then + cronpath=$path + sed -i '/cronpath*/'d $ccfg + sed -i "1i\cronpath=\'$cronpath\'" $ccfg + else + echo -e "\033[33m输入的路径不正确,请重新输入!\033[0m" + checkcron + fi fi - } #定时任务菜单 checkcron #检测定时任务文件 @@ -818,7 +932,7 @@ echo -e "\033[30;47m欢迎使用定时任务功能:\033[0m" echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m" echo ----------------------------------------------- echo -e "\033[33m已添加的定时任务:\033[36m" -cat $cronpath | egrep -o ' #.*' +cat $cronpath | grep -oE ' #.*' echo -e "\033[0m"----------------------------------------------- echo -e " 1 设置\033[33m定时重启\033[0mclash服务" echo -e " 2 设置\033[31m定时停止\033[0mclash服务" @@ -866,7 +980,7 @@ echo -e " 1 \033[32m启动/重启\033[0mclash服务" 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 " 5 设置\033[33m定时任务\033[0m$cronoff" echo -e " 6 导入\033[32m配置文件\033[0m" echo -e " 7 clash\033[31m进阶设置\033[0m" echo -e " 8 \033[35m测试菜单\033[0m" @@ -981,7 +1095,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then exit; elif [[ $num == 6 ]]; then echo 注意:测试结果不保证一定准确! - delay=`curl -kx 127.0.0.1:7890 -o /dev/null -s -w '%{time_starttransfer}' 'https://google.tw' & { sleep 3 ; kill $! & }` > /dev/null 2>&1 + delay=`curl -kx 127.0.0.1:$mix_port -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ `echo ${#delay}` -gt 1 ];then diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 6d95801..2964700 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -307,9 +307,8 @@ clashcore_n=$clashcore #获取设备处理器架构 cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]') [ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5" -[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && cpucore="armv7" -[ -n "$(echo $cputype | grep -E "linux.*aarch64.*")" ] && cpucore="armv8" -[ -n "$(echo $cputype | grep -E "linux.*armv8.*")" ] && cpucore="armv8" +[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && cpucore="armv7" +[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8" [ -n "$(echo $cputype | grep -E "linux.*x86.*")" ] && cpucore="386" [ -n "$(echo $cputype | grep -E "linux.*x86_64.*")" ] && cpucore="amd64" if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then @@ -337,10 +336,13 @@ read -p "请输入对应数字 > " num update elif [[ $num == 1 ]]; then clashcore=clash + version=$claversionsh_l elif [[ $num == 2 ]]; then clashcore=clashpre + version=$clashpre_v elif [[ $num == 3 ]]; then clashcore=clashr + version='1.0(已停止更新)' else echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m请输入正确的数字!\033[0m" @@ -348,13 +350,6 @@ read -p "请输入对应数字 > " num fi #生成链接 corelink="$update_url/bin/$clashcore/clash-linux-$cpucore" -versionlink="$update_url/bin/$clashcore/version" -#检测版本 -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[33m正在检查更新!\033[0m" -result=$(curl -w %{http_code} -skLo /tmp/clashversion $versionlink) -[ "$result" != "200" ] && echo "检查更新失败!" && exit 1 -source /tmp/clashversion echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "当前clash核心:\033[0m $clashcore_n \033[33m$clashv\033[0m" echo -e "最新clash核心:\033[32m $clashcore \033[36m$version\033[0m" @@ -395,12 +390,6 @@ getcore fi } getgeo(){ -echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -echo -e "\033[33m正在检查更新!\033[0m" -#echo $update_url -result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version) -[ "$result" != "200" ] && echo "检查更新失败!" && exit 1 -source /tmp/clashversion echo ----------------------------------------------- echo -e "当前GeoIP版本为:\033[33m $Geo_v \033[0m" echo -e "最新GeoIP版本为:\033[32m $GeoIP_v \033[0m" @@ -436,8 +425,8 @@ echo ----------------------------------------------- echo -e "\033[32m打开管理面板的速度更快且更稳定" echo -e "\033[33m需要占用约500kb的本地空间\033[0m" echo ----------------------------------------------- -echo " 1 在/www/clash目录安装(http://$host/clash,可能安装失败!)" -echo " 2 在$clashdir/ui目录安装(http://$host:9999/ui,安装后需重启clash)" +echo -e " 1 在$clashdir/ui目录安装(推荐!)\033[33m安装后需重启clash服务!!!\033[0m" +echo " 2 在/www/clash目录安装(依赖路由器自带的Nginx服务,可能安装失败!)" echo ----------------------------------------------- echo " 0 返回上级菜单" read -p "请输入对应数字 > " num @@ -445,11 +434,11 @@ read -p "请输入对应数字 > " num if [ -z "$num" ];then update elif [ "$num" = '1' ]; then + dbdir=$clashdir/ui + hostdir=":$db_port/ui\033[0;36m访问面板(需重启clash服务!)" +elif [ "$num" = '2' ]; then dbdir=/www/clash hostdir='/clash\033[0;36m访问面板' -elif [ "$num" = '2' ]; then - dbdir=$clashdir/ui - hostdir=':9999/ui\033[0;36m访问面板(需重启clash服务!)' else update fi @@ -483,8 +472,8 @@ fi tar -zxvf '/tmp/clashdb.tar.gz' -C $dbdir > /dev/null [ $? -ne 0 ] && echo "文件解压失败!" && exit 1 #修改默认host和端口 - sed -i "s/127.0.0.1/$host/g" $dbdir/js/*.js - sed -i "s/9090/9999/g" $dbdir/js/*.js + sed -i "s/127.0.0.1/${host}/g" $dbdir/js/*.js + sed -i "s/9090/${db_port}/g" $dbdir/js/*.js # echo -e "\033[32m面板安装成功!\033[0m" echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -500,7 +489,7 @@ catpac(){ [ ! -d /www/clash -a ! -d $clashdir/ui ]&&echo 未检测到本地Dashboard面板,请先安装面板!&&sleep 1&&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}';) [ -d /www/clash ]&&dir="/www/clash"&&pac=http://$host/clash/pac -[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:9999/ui/pac +[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:$db_port/ui/pac echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[30;47m生成用于设备WIFI或浏览器的自动PAC代理文件\033[0m" echo -e "\033[33m非纯净模式不推荐使用此功能\033[0m" @@ -513,7 +502,7 @@ echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ "$num" = '1' ]; then echo 'function FindProxyForURL(url, host) {' > $dir/pac - echo " return \"SOCKS $host:7890; PROXY $host:7890; DIRECT;\"" >> $dir/pac + echo " return \"SOCKS $host:$mix_port; PROXY $host:$mix_port; DIRECT;\"" >> $dir/pac echo '}' >> $dir/pac echo -e "\033[33mPAC文件已生成!\033[0m" echo -e "PAC地址:\033[32m$pac\033[0m" @@ -547,11 +536,11 @@ elif [[ $num == 1 ]]; then elif [[ $num == 2 ]]; then update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash' elif [[ $num == 3 ]]; then - update_url='-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/ShellClash/master' + update_url='-x 127.0.0.1:'$mix_port' https://raw.githubusercontent.com/juewuy/ShellClash/master' elif [[ $num == 4 ]]; then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ read -p "请输入个人源路径 > " update_url - if [ -n $update_url ];then + if [ -z "$update_url" ];then echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m取消输入,返回上级菜单\033[0m" update diff --git a/scripts/start.sh b/scripts/start.sh index 85801b1..86db39b 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -17,6 +17,10 @@ source $ccfg [ -z "$ipv6_support" ] && ipv6_support=未开启 [ -z "$start_old" ] && start_old=未开启 [ -z "$local_proxy" ] && local_proxy=未开启 +[ -z "$mix_port" ] && mix_port=7890 +[ -z "$redir_port" ] && redir_port=7892 +[ -z "$db_port" ] && db_port=9999 +[ -z "$dns_port" ] && dns_port=1053 #是否代理常用端口 [ "$common_ports" = "已开启" ] && ports='-m multiport --dports 22,53,587,465,995,993,143,80,443 ' } @@ -145,57 +149,47 @@ fi } 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 [ -d $clashdir/ui ];then -external_ui='external-ui: ui' -else -external_ui='external-ui:' -fi -if [ "$dns_mod" = "fake-ip" ];then -dns='dns: {enable: true, listen: 0.0.0.0:1053, use-hosts: true, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, fake-ip-filter: ["*.lan", "time.windows.com", "time.nist.gov", "time.apple.com", "time.asia.apple.com", "*.ntp.org.cn", "*.openwrt.pool.ntp.org", "time1.cloud.tencent.com", "time.ustc.edu.cn", "pool.ntp.org", "ntp.ubuntu.com", "ntp.aliyun.com", "ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com", "time1.aliyun.com", "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com", "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com", "*.time.edu.cn", "time1.apple.com", "time2.apple.com", "time3.apple.com", "time4.apple.com", "time5.apple.com", "time6.apple.com", "time7.apple.com", "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "music.163.com", "*.music.163.com", "*.126.net", "musicapi.taihe.com", "music.taihe.com", "songsearch.kugou.com", "trackercdn.kugou.com", "*.kuwo.cn", "api-jooxtt.sanook.com", "api.joox.com", "joox.com", "y.qq.com", "*.y.qq.com", "streamoc.music.tc.qq.com", "mobileoc.music.tc.qq.com", "isure.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com", "aqqmusic.tc.qq.com", "amobile.music.tc.qq.com", "*.xiami.com", "*.music.migu.cn", "music.migu.cn", "*.msftconnecttest.com", "*.msftncsi.com", "localhost.ptlogin2.qq.com", "*.*.*.srv.nintendo.net", "*.*.stun.playstation.net", "xbox.*.*.microsoft.com", "*.*.xboxlive.com", "proxy.golang.org"], nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}' -elif [ "$dns_over" = "已开启" ];then -dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, use-hosts: true, enhanced-mode: redir-host, nameserver: [114.114.114.114, 223.5.5.5], fallback: [1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}' -else -dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, use-hosts: true, 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], fallback-filter: {geoip: true}}' -fi -if [ "$redir_mod" != "Redir模式" ];then -tun='tun: {enable: true, stack: system}' -else -tun='tun: {enable: false}' -fi +[ "$ipv6_support" = "已开启" ] && ipv6='ipv6: true' || ipv6='ipv6: false' +external="external-controller: 0.0.0.0:$db_port" +[ -d $clashdir/ui ] && db_ui=ui +[ "$redir_mod" != "Redir模式" ] && tun='tun: {enable: true, stack: system}' || tun='tun: {enable: false}' exper='experimental: {ignore-resolve-fail: true, interface-name: en0}' +#dns配置 +if [ "$dns_mod" = "fake-ip" ];then + dns='dns: {enable: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, fake-ip-filter: ["*.lan", "time.windows.com", "time.nist.gov", "time.apple.com", "time.asia.apple.com", "*.ntp.org.cn", "*.openwrt.pool.ntp.org", "time1.cloud.tencent.com", "time.ustc.edu.cn", "pool.ntp.org", "ntp.ubuntu.com", "ntp.aliyun.com", "ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com", "time1.aliyun.com", "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com", "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com", "*.time.edu.cn", "time1.apple.com", "time2.apple.com", "time3.apple.com", "time4.apple.com", "time5.apple.com", "time6.apple.com", "time7.apple.com", "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "music.163.com", "*.music.163.com", "*.126.net", "musicapi.taihe.com", "music.taihe.com", "songsearch.kugou.com", "trackercdn.kugou.com", "*.kuwo.cn", "api-jooxtt.sanook.com", "api.joox.com", "joox.com", "y.qq.com", "*.y.qq.com", "streamoc.music.tc.qq.com", "mobileoc.music.tc.qq.com", "isure.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com", "aqqmusic.tc.qq.com", "amobile.music.tc.qq.com", "*.xiami.com", "*.music.migu.cn", "music.migu.cn", "*.msftconnecttest.com", "*.msftncsi.com", "localhost.ptlogin2.qq.com", "*.*.*.srv.nintendo.net", "*.*.stun.playstation.net", "xbox.*.*.microsoft.com", "*.*.xboxlive.com", "proxy.golang.org"], nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}' +elif [ "$dns_over" = "已开启" ];then + dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: [114.114.114.114, 223.5.5.5], fallback: [1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}' +else + dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, 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], fallback-filter: {geoip: true}}' +fi + ################################### + yaml=$clashdir/config.yaml #预删除需要添加的项目 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 "1,${i}d" $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$external_ui" $clashdir/config.yaml - sed -i "8a$dns" $clashdir/config.yaml - sed -i "9a$tun" $clashdir/config.yaml - sed -i "10a$exper" $clashdir/config.yaml + sed -i "1imixed-port:\ $mix_port" $yaml + sed -i "1aredir-port:\ $redir_port" $yaml + sed -i "2a$lan" $yaml + sed -i "3a$mode" $yaml + sed -i "4a$log" $yaml + sed -i "5a$ipv6" $yaml + sed -i "6aexternal-controller:\ :$db_port" $yaml + sed -i "7aexternal-ui:\ $db_ui" $yaml + sed -i "8asecret:\ $secret" $yaml + sed -i "9a$dns" $yaml + sed -i "10a$tun" $yaml + sed -i "11a$exper" $yaml #跳过本地tls证书验证 if [ "$skip_cert" = "已开启" ];then - sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $clashdir/config.yaml + sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $yaml else - sed -i '10,99s/skip-cert-verify: true/skip-cert-verify: false/' $clashdir/config.yaml + sed -i '10,99s/skip-cert-verify: true/skip-cert-verify: false/' $yaml fi } mark_time(){ @@ -218,7 +212,7 @@ start_redir(){ 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 clash -p tcp $ports-j REDIRECT --to-ports $redir_port iptables -t nat -A PREROUTING -p tcp -j clash #设置ipv6转发 if [ "$ipv6_support" = "已开启" ];then @@ -226,7 +220,7 @@ start_redir(){ for mac in $(cat $clashdir/mac); do ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN done - ip6tables -t nat -A clashv6 -p tcp $ports-j REDIRECT --to-ports 7892 + ip6tables -t nat -A clashv6 -p tcp $ports-j REDIRECT --to-ports $redir_port ip6tables -t nat -A PREROUTING -p tcp -j clashv6 fi } @@ -261,30 +255,33 @@ start_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 clash_dns -p tcp --dport 53 -j REDIRECT --to 1053 + iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to $dns_port + iptables -t nat -A clash_dns -p tcp --dport 53 -j REDIRECT --to $dns_port iptables -t nat -A PREROUTING -p udp -j clash_dns #Google home DNS特殊处理 iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash_dns iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash_dns #ipv6DNS - ip6tables -t nat -N clashv6_dns > /dev/null 2>&1 - for mac in $(cat $clashdir/mac); do - ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1 - done - ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 - ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1 -} -checkcron(){ - [ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root" - [ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root" - [ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root" - [ -z $cronpath ]&&echo "找不到定时任务文件,无法添加定时任务!" + ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'not exist') + if [ -z "ip6_nat" ];then + ip6tables -t nat -N clashv6_dns > /dev/null 2>&1 + for mac in $(cat $clashdir/mac); do + ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1 + done + ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to $dns_port > /dev/null 2>&1 + ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1 + else + ip6tables -I INPUT -p tcp --dport 53 -j DROP + fi } daemon(){ - checkcron - echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash restart #clash守护进程' >> $cronpath - chmod 600 $cronpath + if [ -n "$cronpath" ];then + echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash restart #clash保守模式守护进程' >> $cronpath + chmod 600 $cronpath + else + echo 找不到定时任务配置文件,无法添加守护进程! + echo 请进入定时任务菜单手动指定系统定时任务文件路径!!! + fi } afstart(){ #读取配置文件 @@ -305,10 +302,6 @@ afstart) start) #读取配置文件 getconfig - #检测系统端口占用 - for portx in 1053 7890 7892 9999 ;do - [ -n "$(netstat -ntul |grep :$portx)" ] && echo "检测到端口【$portx】被以下进程占用!clash无法启动!" && echo $(netstat -ntulp |grep :$portx) && exit 1 - done #使用内置规则强行覆盖config配置文件 [ "$modify_yaml" != "已开启" ] && modify_yaml #使用不同方式启动clash服务 @@ -323,9 +316,10 @@ start) fi ;; stop) - #删除守护 - checkcron - sed -i /clash守护进程/d $cronpath >/dev/null 2>&1 + #读取配置文件 + getconfig + #删除守护进程 + sed -i /clash保守模式守护进程/d $cronpath >/dev/null 2>&1 #多种方式结束进程 if [ -f /etc/rc.common ];then /etc/init.d/clash stop >/dev/null 2>&1