v1.0.0beta15.7

~修改了定时任务实现方式,适配更多设备
~修改了配置文件修饰方式
~优化了非root用户体验
~优化脚本结构
This commit is contained in:
juewuy
2020-10-27 09:40:58 +08:00
parent af6922e2da
commit f41440a118
14 changed files with 173 additions and 234 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
clash_v=1.2.0 clash_v=1.2.0
clashpre_v=2020.10.09
GeoIP_v=20201021 GeoIP_v=20201021
versionsh=1.0.0beta15.6 versionsh=123
clashpre_v=2020.10.26.gc025a01

View File

@@ -15,7 +15,7 @@ if [ "$USER" != "root" ];then
echo 当前用户:$USER echo 当前用户:$USER
$echo "\033[31m请尽量使用root用户执行安装!\033[0m" $echo "\033[31m请尽量使用root用户执行安装!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "仍要安装?可能会产生未知错误!(1/0) > " res read -p "仍要安装?可能会产生大量未知错误!(1/0) > " res
[ "$res" != "1" ] && exit [ "$res" != "1" ] && exit
fi fi
webget(){ webget(){

View File

@@ -11,11 +11,12 @@ getconfig(){
#检查/读取标识文件 #检查/读取标识文件
[ ! -f $ccfg ] && echo '#标识clash运行状态的文件不明勿动' > $ccfg [ ! -f $ccfg ] && echo '#标识clash运行状态的文件不明勿动' > $ccfg
source $ccfg source $ccfg
#设置默认端口 #设置默认端口及变量
[ -z "$mix_port" ] && mix_port=7890 [ -z "$mix_port" ] && mix_port=7890
[ -z "$redir_port" ] && redir_port=7892 [ -z "$redir_port" ] && redir_port=7892
[ -z "$db_port" ] && db_port=9999 [ -z "$db_port" ] && db_port=9999
[ -z "$dns_port" ] && dns_port=1053 [ -z "$dns_port" ] && dns_port=1053
[ -z "$local_proxy" ] && local_proxy=未开启
#检查mac地址记录 #检查mac地址记录
[ ! -f $clashdir/mac ] && touch $clashdir/mac [ ! -f $clashdir/mac ] && touch $clashdir/mac
#获取本机host地址 #获取本机host地址
@@ -37,7 +38,7 @@ getconfig(){
#开机自启描述 #开机自启描述
if [ "$start_old" = "已开启" ];then if [ "$start_old" = "已开启" ];then
auto="\033[33m已设置保守模式\033[0m" auto="\033[33m已设置保守模式\033[0m"
auto1="\033[36m设为\033[0m常规模式启动" auto1="代理本机:\033[36m$local_proxy\033[0m"
elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then
auto="\033[32m已设置开机启动\033[0m" auto="\033[32m已设置开机启动\033[0m"
auto1="\033[36m禁用\033[0mclash开机启动" auto1="\033[36m禁用\033[0mclash开机启动"
@@ -46,10 +47,8 @@ getconfig(){
auto1="\033[36m允许\033[0mclash开机启动" auto1="\033[36m允许\033[0mclash开机启动"
fi fi
#获取运行模式 #获取运行模式
if [ -z "$redir_mod" ];then [ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
sed -i "2i\redir_mod=Redir模式" $ccfg [ -z "$redir_mod" ] && redir_mod=纯净模式
redir_mod=Redir模式
fi
#获取运行状态 #获取运行状态
PID=$(pidof clash) PID=$(pidof clash)
if [ -n "$PID" ];then if [ -n "$PID" ];then
@@ -67,14 +66,6 @@ getconfig(){
#检测系统端口占用 #检测系统端口占用
checkport checkport
fi 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
#输出状态 #输出状态
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;46m欢迎使用ShellClash\033[0m 版本:$versionsh_l" echo -e "\033[30;46m欢迎使用ShellClash\033[0m 版本:$versionsh_l"
@@ -92,6 +83,12 @@ getconfig(){
[ "$res" = 1 ] && source $clashdir/getdate.sh && userguide [ "$res" = 1 ] && source $clashdir/getdate.sh && userguide
fi fi
} }
setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=$clashdir/mark || configpath=$3
sed -i "/${1}*/"d $configpath
echo "${1}=${2}" >> $configpath
}
echoerrornum(){ echoerrornum(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m" echo -e "\033[31m请输入正确的数字\033[0m"
@@ -144,8 +141,7 @@ setport(){
echo -e "\033[31m当前端口已被其他进程占用请重新输入\033[0m" echo -e "\033[31m当前端口已被其他进程占用请重新输入\033[0m"
inputport inputport
else else
sed -i "/$xport*/"d $ccfg setconfig $xport $portx
sed -i "1i$xport=$portx" $ccfg
echo -e "\033[32m设置成功\033[0m" echo -e "\033[32m设置成功\033[0m"
setport setport
fi fi
@@ -193,8 +189,7 @@ setport(){
[ "$local_proxy" = "已开启" ] && echo -e "\033[32m请先禁用本机代理功能\033[0m" && setport [ "$local_proxy" = "已开启" ] && echo -e "\033[32m请先禁用本机代理功能\033[0m" && setport
authentication=$(echo $input | grep :) authentication=$(echo $input | grep :)
if [ -n "$authentication" ]; then if [ -n "$authentication" ]; then
sed -i "/authentication*/"d $ccfg setconfig authentication \'$authentication\'
sed -i "1i\authentication=\'$authentication\'" $ccfg
echo -e "\033[32m设置成功\033[0m" echo -e "\033[32m设置成功\033[0m"
else else
echo -e "\033[31m输入有误请重新输入\033[0m" echo -e "\033[31m输入有误请重新输入\033[0m"
@@ -213,8 +208,8 @@ setport(){
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
read -p "请输入面板访问密码(输入0删除密码) > " secret read -p "请输入面板访问密码(输入0删除密码) > " secret
if [ -n "$secret" ]; then if [ -n "$secret" ]; then
sed -i "/secret*/"d $ccfg [ "$secret" = "0" ] && secret=""
[ "$secret" = "0" ] && secret="" || sed -i "1i\secret=$secret" $ccfg setconfig secret $secret
echo -e "\033[32m设置成功\033[0m" echo -e "\033[32m设置成功\033[0m"
fi fi
setport setport
@@ -222,7 +217,7 @@ setport(){
} }
setdns(){ setdns(){
source $ccfg source $ccfg
if [ "$dns_no" = "true" ];then if [ "$dns_no" = "已禁用" ];then
read -p "检测到内置DNS已被禁用是否启用内置DNS(1/0) > " res read -p "检测到内置DNS已被禁用是否启用内置DNS(1/0) > " res
if [ "$res" = "1" ];then if [ "$res" = "1" ];then
sed -i "/dns_no*/"d $ccfg sed -i "/dns_no*/"d $ccfg
@@ -252,16 +247,14 @@ setdns(){
read -p "请输入新的DNS > " dns_nameserver read -p "请输入新的DNS > " dns_nameserver
dns_nameserver=$(echo $dns_nameserver | sed 's/|/\,\ /') dns_nameserver=$(echo $dns_nameserver | sed 's/|/\,\ /')
if [ -n "$dns_nameserver" ]; then if [ -n "$dns_nameserver" ]; then
sed -i "/dns_nameserver*/"d $ccfg setconfig dns_nameserver \'$dns_nameserver\'
sed -i "1i\dns_nameserver=\'$dns_nameserver\'" $ccfg
echo -e "\033[32m设置成功\033[0m" echo -e "\033[32m设置成功\033[0m"
fi fi
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
read -p "请输入新的DNS > " dns_fallback read -p "请输入新的DNS > " dns_fallback
dns_fallback=$(echo $dns_fallback | sed 's/|/\,\ /') dns_fallback=$(echo $dns_fallback | sed 's/|/\,\ /')
if [ -n "$dns_fallback" ]; then if [ -n "$dns_fallback" ]; then
sed -i "/dns_fallback*/"d $ccfg setconfig dns_fallback \'$dns_fallback\'
sed -i "1i\dns_fallback=\'$dns_fallback\'" $ccfg
echo -e "\033[32m设置成功\033[0m" echo -e "\033[32m设置成功\033[0m"
fi fi
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
@@ -273,8 +266,7 @@ setdns(){
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m仅限搭配其他DNS服务(比如dnsmasq、smartDNS)时使用!\033[0m" echo -e "\033[31m仅限搭配其他DNS服务(比如dnsmasq、smartDNS)时使用!\033[0m"
sed -i "/dns_no*/"d $ccfg setconfig dns_no 已禁用
sed -i "1i\dns_no=true" $ccfg
echo -e "\033[33m已禁用内置DNS\033[0m" echo -e "\033[33m已禁用内置DNS\033[0m"
clashadv clashadv
else else
@@ -433,6 +425,27 @@ macfilter(){
macfilter macfilter
fi fi
} }
set_local_proxy(){
echo -----------------------------------------------
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
if [ -n "$authentication" ] && [ "$authentication" != "未设置" ] ;then
echo -e "\033[32m检测到您已经设置了Http/Sock5代理密码请先取消密码\033[0m"
sleep 1
setport
else
local_proxy=已开启
$clashdir/start.sh set_proxy $mix_port $db_port
echo -e "\033[32m已经成功配置本机代理~\033[0m"
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
fi
else
local_proxy=未开启
$clashdir/start.sh unset_proxy
echo -e "\033[33m已经停用本机代理规则\033[0m"
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
fi
setconfig local_proxy $local_proxy
}
clashcfg(){ clashcfg(){
set_redir_mod(){ set_redir_mod(){
echo ----------------------------------------------- echo -----------------------------------------------
@@ -466,10 +479,12 @@ clashcfg(){
if [ "$?" != 0 ];then if [ "$?" != 0 ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m当前设备内核不支持开启Tun/混合模式,请使用其他模式!\033[0m" echo -e "\033[31m当前设备内核不支持开启Tun/混合模式,请使用其他模式!\033[0m"
sleep 1
set_redir_mod set_redir_mod
elif [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then elif [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m" echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
sleep 1
clashcfg clashcfg
else else
redir_mod=Tun模式 redir_mod=Tun模式
@@ -480,10 +495,12 @@ clashcfg(){
if [ "$?" != 0 ];then if [ "$?" != 0 ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m当前设备内核不支持开启Tun/混合模式,请使用其他模式!\033[0m" echo -e "\033[31m当前设备内核不支持开启Tun/混合模式,请使用其他模式!\033[0m"
sleep 1
set_redir_mod set_redir_mod
elif [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then elif [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m" echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
sleep 1
clashcfg clashcfg
else else
redir_mod=混合模式 redir_mod=混合模式
@@ -501,10 +518,8 @@ clashcfg(){
echoerrornum echoerrornum
clashcfg clashcfg
fi fi
sed -i '/redir_mod*/'d $ccfg setconfig redir_mod $redir_mod
sed -i "1i\redir_mod=$redir_mod" $ccfg setconfig dns_mod $dns_mod
sed -i '/dns_mod*/'d $ccfg
sed -i "1i\dns_mod=$dns_mod" $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m已设为 $redir_mod \033[0m" echo -e "\033[36m已设为 $redir_mod \033[0m"
} }
@@ -528,15 +543,11 @@ clashcfg(){
dns_mod=fake-ip dns_mod=fake-ip
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
dns_mod=redir_host dns_mod=redir_host
redir_mod=Redir模式
else else
echoerrornum echoerrornum
clashcfg clashcfg
fi fi
sed -i '/dns_mod*/'d $ccfg setconfig dns_mod $dns_mod
sed -i "1i\dns_mod=$dns_mod" $ccfg
sed -i '/redir_mod*/'d $ccfg
sed -i "1i\redir_mod=$redir_mod" $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m"
} }
@@ -546,7 +557,6 @@ clashcfg(){
[ -z "$common_ports" ] && common_ports=已开启 [ -z "$common_ports" ] && common_ports=已开启
[ -z "$dns_mod" ] && dns_mod=redir_host [ -z "$dns_mod" ] && dns_mod=redir_host
[ -z "$dns_over" ] && dns_over=已开启 [ -z "$dns_over" ] && dns_over=已开启
[ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$(cat $clashdir/mac)" ] && mac_return=未开启 || mac_return=已启用 [ -z "$(cat $clashdir/mac)" ] && mac_return=未开启 || mac_return=已启用
# #
echo ----------------------------------------------- echo -----------------------------------------------
@@ -571,7 +581,13 @@ clashcfg(){
elif [ "$num" = 0 ]; then elif [ "$num" = 0 ]; then
clashsh clashsh
elif [ "$num" = 1 ]; then elif [ "$num" = 1 ]; then
if [ "$USER" != "root" -a "$USER" != "admin" ];then
echo -----------------------------------------------
echo -e "\033[33m非root用户无法启用静态路由仅可以使用纯净模式\033[0m"
sleep 1
else
set_redir_mod set_redir_mod
fi
clashcfg clashcfg
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
@@ -579,75 +595,49 @@ clashcfg(){
clashcfg clashcfg
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
sed -i '/skip_cert*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\skip_cert=已开启" $ccfg
echo -e "\033[33m已设为开启跳过本地证书验证\033[0m" echo -e "\033[33m已设为开启跳过本地证书验证\033[0m"
skip_cert=已开启 skip_cert=已开启
else else
sed -i "1i\skip_cert=未开启" $ccfg
echo -e "\033[33m已设为禁止跳过本地证书验证\033[0m" echo -e "\033[33m已设为禁止跳过本地证书验证\033[0m"
skip_cert=未开启 skip_cert=未开启
fi fi
setconfig skip_cert $skip_cert
clashcfg clashcfg
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
sed -i '/common_ports*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$common_ports" = "未开启" ] > /dev/null 2>&1; then if [ "$common_ports" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\common_ports=已开启" $ccfg echo -e "\033[33m已设为仅代理53,587,465,995,993,143,80,443等常用端口\033[0m"
echo -e "\033[33m已设为仅代理22,53,587,465,995,993,143,80,443等常用端口\033[0m"
common_ports=已开启 common_ports=已开启
else else
sed -i "1i\common_ports=未开启" $ccfg
echo -e "\033[33m已设为代理全部端口\033[0m" echo -e "\033[33m已设为代理全部端口\033[0m"
common_ports=未开启 common_ports=未开启
fi fi
setconfig common_ports $common_ports
clashcfg clashcfg
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
macfilter macfilter
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
sed -i '/dns_over*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$dns_over" = "未开启" ] > /dev/null 2>&1; then if [ "$dns_over" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\dns_over=已开启" $ccfg
echo -e "\033[33m已设置DNS为不走本地dnsmasq服务器\033[0m" echo -e "\033[33m已设置DNS为不走本地dnsmasq服务器\033[0m"
echo -e "可能会对浏览速度产生一定影响,介意勿用!" echo -e "可能会对浏览速度产生一定影响,介意勿用!"
dns_over=已开启 dns_over=已开启
else else
/etc/init.d/clash enable /etc/init.d/clash enable
sed -i "1i\dns_over=未开启" $ccfg
echo -e "\033[32m已设置DNS通过本地dnsmasq服务器\033[0m" echo -e "\033[32m已设置DNS通过本地dnsmasq服务器\033[0m"
echo -e "redir-host模式下部分网站可能会被运营商dns污染导致无法打开" echo -e "redir-host模式下部分网站可能会被运营商dns污染导致无法打开"
dns_over=未开启 dns_over=未开启
fi fi
setconfig dns_over $dns_over
clashcfg clashcfg
elif [ "$num" = 7 ]; then elif [ "$num" = 7 ]; then
sed -i '/local_proxy*/'d $ccfg set_local_proxy
echo -----------------------------------------------
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
if [ -n "$authentication" ] && [ "$authentication" != "未设置" ] ;then
echo -e "\033[32m检测到您已经设置了Http/Sock5代理密码请先取消密码\033[0m"
sleep 1
setport
else
sed -i "1i\local_proxy=已开启" $ccfg
local_proxy=已开启
$clashdir/start.sh set_proxy $mix_port
echo -e "\033[32m已经成功配置本机代理~\033[0m"
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
fi
else
sed -i "1i\local_proxy=未开启" $ccfg
local_proxy=未开启
$clashdir/start.sh unset_proxy
echo -e "\033[33m已经停用本机代理规则\033[0m"
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
fi
sleep 1 sleep 1
clashcfg clashcfg
@@ -675,8 +665,8 @@ clashadv(){
echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定" echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定"
echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务"
echo -e " 4 Redir模式udp转发: \033[36m$tproxy_mod\033[0m ————依赖iptables-mod-tproxy" echo -e " 4 Redir模式udp转发: \033[36m$tproxy_mod\033[0m ————依赖iptables-mod-tproxy"
echo -e " 5 手动指定clash运行端口及秘钥" echo -e " 5 配置内置DNS服务: \033[36m$dns_no\033[0m"
echo -e " 6 手动配置内置DNS服务" echo -e " 6 手动指定clash运行端口及秘钥"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 8 \033[31m重置\033[0m配置文件" echo -e " 8 \033[31m重置\033[0m配置文件"
echo -e " 9 \033[32m重启\033[0mclash服务" echo -e " 9 \033[32m重启\033[0mclash服务"
@@ -690,80 +680,80 @@ clashadv(){
clashsh clashsh
elif [ "$num" = 1 ]; then elif [ "$num" = 1 ]; then
sed -i '/modify_yaml*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$modify_yaml" = "未开启" ] > /dev/null 2>&1; then if [ "$modify_yaml" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\modify_yaml=已开启" $ccfg
echo -e "\033[33m已设为使用用户完全自定义的配置文件" echo -e "\033[33m已设为使用用户完全自定义的配置文件"
echo -e "\033[36m不明白原理的用户切勿随意开启此选项" echo -e "\033[36m不明白原理的用户切勿随意开启此选项"
echo -e "\033[31m必然会导致上不了网!\033[0m" echo -e "\033[31m必然会导致上不了网!\033[0m"
modify_yaml=已开启 modify_yaml=已开启
sleep 3 sleep 3
else else
sed -i "1i\modify_yaml=未开启" $ccfg
echo -e "\033[32m已设为使用脚本内置规则管理config.yaml配置文件\033[0m" echo -e "\033[32m已设为使用脚本内置规则管理config.yaml配置文件\033[0m"
modify_yaml=未开启 modify_yaml=未开启
fi fi
setconfig modify_yaml $modify_yaml
clashadv clashadv
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
sed -i '/ipv6_support*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\ipv6_support=已开启" $ccfg
echo -e "\033[33m已开启对ipv6协议的支持\033[0m" echo -e "\033[33m已开启对ipv6协议的支持\033[0m"
echo -e "Clash对ipv6的支持并不友好如不能使用请静等修复" echo -e "Clash对ipv6的支持并不友好如不能使用请静等修复"
ipv6_support=已开启 ipv6_support=已开启
sleep 2 sleep 2
else else
sed -i "1i\ipv6_support=未开启" $ccfg
echo -e "\033[32m已禁用对ipv6协议的支持\033[0m" echo -e "\033[32m已禁用对ipv6协议的支持\033[0m"
ipv6_support=未开启 ipv6_support=未开启
fi fi
setconfig ipv6_support $ipv6_support
clashadv clashadv
elif [ "$num" = 3 ]; then elif [ "$num" = 3 ]; then
sed -i '/start_old*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\start_old=已开启" $ccfg
echo -e "\033[33m改为使用保守方式启动clash服务\033[0m" echo -e "\033[33m改为使用保守方式启动clash服务\033[0m"
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m" echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m"
start_old=已开启 start_old=已开启
setconfig start_old $start_old
$clashdir/start.sh stop $clashdir/start.sh stop
sleep 2 sleep 2
else else
sed -i "1i\start_old=未开启" $ccfg if [ -f /etc/init.d/clash -o -f /etc/systemd/system -o -f /usr/lib/systemd/system ];then
echo -e "\033[32m改为使用默认方式启动clash服务\033[0m" echo -e "\033[32m改为使用默认方式启动clash服务\033[0m"
start_old=未开启 start_old=未开启
setconfig start_old $start_old
$clashdir/start.sh stop $clashdir/start.sh stop
else
echo -e "\033[31m当前设备不支持以其他模式启动\033[0m"
sleep 1
fi
fi fi
clashadv clashadv
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
sed -i '/tproxy_mod*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$tproxy_mod" = "未开启" ]; then if [ "$tproxy_mod" = "未开启" ]; then
if [ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ];then if [ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ];then
sed -i "1i\tproxy_mod=已开启" $ccfg
tproxy_mod=已开启 tproxy_mod=已开启
echo -e "\033[32m已经为Redir模式启用udp转发功能\033[0m" echo -e "\033[32m已经为Redir模式启用udp转发功能\033[0m"
else else
tproxy_mod=未开启
echo -e "\033[31m您的设备不支持tproxy模式无法开启\033[0m" echo -e "\033[31m您的设备不支持tproxy模式无法开启\033[0m"
fi fi
else else
sed -i "1i\tproxy_mod=未开启" $ccfg
tproxy_mod=未开启 tproxy_mod=未开启
echo -e "\033[33m已经停止使用tproxy转发udp流量\033[0m" echo -e "\033[33m已经停止使用tproxy转发udp流量\033[0m"
fi fi
setconfig tproxy_mod $tproxy_mod
sleep 1 sleep 1
clashadv clashadv
elif [ "$num" = 5 ]; then elif [ "$num" = 5 ]; then
setport setdns
clashadv clashadv
elif [ "$num" = 6 ]; then elif [ "$num" = 6 ]; then
setdns setport
clashadv clashadv
elif [ "$num" = 8 ]; then elif [ "$num" = 8 ]; then
@@ -805,7 +795,7 @@ clashcron(){
elif [ "$num" = 0 ]; then elif [ "$num" = 0 ]; then
clashcron clashcron
elif [ "$num" = 9 ]; then elif [ "$num" = 9 ]; then
sed -i /$cronname/d $cronpath crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && crontab /tmp/conf && rm -f /tmp/conf
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m定时任务$cronname已删除\033[0m" echo -e "\033[31m定时任务$cronname已删除\033[0m"
clashcron clashcron
@@ -845,41 +835,20 @@ clashcron(){
echo 将在$week1的$hour点$min分$cronname(旧的任务会被覆盖) echo 将在$week1的$hour点$min分$cronname(旧的任务会被覆盖)
read -p "是否确认添加定时任务?(1/0) > " res read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
sed -i /$cronname/d $cronpath cronwords="$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname"
echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && echo "$cronwords" >> /tmp/conf && crontab /tmp/conf && rm -f /tmp/conf
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m定时任务已添加\033[0m" echo -e "\033[31m定时任务已添加\033[0m"
chmod 600 $cronpath #修改权限
fi fi
clashcron clashcron
} }
checkcron(){
if [ -z "$cronpath" ];then
echo -----------------------------------------------
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 #检测定时任务文件
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用定时任务功能\033[0m" echo -e "\033[30;47m欢迎使用定时任务功能\033[0m"
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m" echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[33m已添加的定时任务\033[36m" echo -e "\033[33m已添加的定时任务\033[36m"
cat $cronpath | grep -oE ' #.*' crontab -l | grep -oE ' #.*'
echo -e "\033[0m"----------------------------------------------- echo -e "\033[0m"-----------------------------------------------
echo -e " 1 设置\033[33m定时重启\033[0mclash服务" echo -e " 1 设置\033[33m定时重启\033[0mclash服务"
echo -e " 2 设置\033[31m定时停止\033[0mclash服务" echo -e " 2 设置\033[31m定时停止\033[0mclash服务"
@@ -958,10 +927,7 @@ clashsh(){
elif [ "$num" = 4 ]; then elif [ "$num" = 4 ]; then
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$start_old" = "已开启" ];then if [ "$start_old" = "已开启" ];then
sed -i "/start_old*/d" $ccfg set_local_proxy
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m已设为使用默认方式启动clash服务\033[0m"
start_old=未开启
elif [ "$autostart" = "enable_rc" ]; then elif [ "$autostart" = "enable_rc" ]; then
/etc/init.d/clash disable /etc/init.d/clash disable
echo -e "\033[33m已禁止Clash开机启动\033[0m" echo -e "\033[33m已禁止Clash开机启动\033[0m"

View File

@@ -44,9 +44,8 @@ linkconfig(){
echo echo
elif [ "$num" -le 13 ];then elif [ "$num" -le 13 ];then
#将对应标记值写入mark #将对应标记值写入mark
sed -i '/rule_link*/'d $ccfg
sed -i "4i\rule_link="$num"" $ccfg
rule_link=$num rule_link=$num
setconfig rule_link $rule_link
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m设置成功返回上级菜单\033[0m" echo -e "\033[32m设置成功返回上级菜单\033[0m"
fi fi
@@ -70,9 +69,8 @@ linkserver(){
echo echo
elif [ "$num" -le 5 ];then elif [ "$num" -le 5 ];then
#将对应标记值写入mark #将对应标记值写入mark
sed -i '/server_link*/'d $ccfg
sed -i "4i\server_link="$num"" $ccfg
server_link=$num server_link=$num
setconfig server_link $server_link
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m设置成功返回上级菜单\033[0m" echo -e "\033[32m设置成功返回上级菜单\033[0m"
fi fi
@@ -98,8 +96,7 @@ linkfilter(){
exclude='' exclude=''
echo -e "\033[31m 已删除节点过滤关键字!!!\033[0m" echo -e "\033[31m 已删除节点过滤关键字!!!\033[0m"
fi fi
sed -i '/exclude=*/'d $ccfg setconfig exclude \'$exclude\'
sed -i "1i\exclude=\'$exclude\'" $ccfg
linkset linkset
} }
linkfilter2(){ linkfilter2(){
@@ -123,8 +120,7 @@ linkfilter2(){
include='' include=''
echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m" echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m"
fi fi
sed -i '/include=*/'d $ccfg setconfig include \'$include\'
sed -i "1i\include=\'$include\'" $ccfg
linkset linkset
} }
linkset(){ linkset(){
@@ -150,9 +146,8 @@ linkset(){
clashlink clashlink
elif [ "$num" = '1' ]; then elif [ "$num" = '1' ]; then
#将用户链接写入mark #将用户链接写入mark
sed -i '/Url=*/'d $ccfg
sed -i '/Https=*/'d $ccfg sed -i '/Https=*/'d $ccfg
sed -i "6i\Url=\'$Url\'" $ccfg setconfig Url \'$Url\'
Https="" Https=""
#获取在线yaml文件 #获取在线yaml文件
$clashdir/start.sh getyaml $clashdir/start.sh getyaml
@@ -171,17 +166,9 @@ linkset(){
linkserver linkserver
linkset linkset
elif [ "$num" = '6' ]; then elif [ "$num" = '6' ]; then
sed -i '/skip_cert*/'d $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then [ "$skip_cert" = "未开启" ] && skip_cert=已开启 || skip_cert=未开启
sed -i "1i\skip_cert=已开启" $ccfg setconfig skip_cert $skip_cert
#echo -e "\033[33m已设为开启跳过本地证书验证\033[0m"
skip_cert=已开启
else
sed -i "1i\skip_cert=未开启" $ccfg
#echo -e "\033[33m已设为禁止跳过本地证书验证\033[0m"
skip_cert=未开启
fi
linkset linkset
else else
echoerrornum echoerrornum
@@ -255,8 +242,7 @@ getlink2(){
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
#将用户链接写入mark #将用户链接写入mark
sed -i '/Url=*/'d $ccfg sed -i '/Url=*/'d $ccfg
sed -i '/Https=*/'d $ccfg setconfig Https \'$Https\'
sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件 #获取在线yaml文件
$clashdir/start.sh getyaml $clashdir/start.sh getyaml
start_over start_over
@@ -272,16 +258,8 @@ getlink2(){
fi fi
} }
clashlink(){ clashlink(){
#获取订阅规则 [ -z "$rule_link" ] && rule_link=1
if [ -z "$rule_link" ]; then [ -z "$server_link" ] && server_link=1
sed -i "4i\rule_link=1" $ccfg
rule_link=1
fi
#获取后端服务器地址
if [ -z "$server_link" ]; then
sed -i "5i\server_link=1" $ccfg
server_link=1
fi
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m" echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@@ -413,18 +391,17 @@ gettar(){
mv $clashdir/clashservice /etc/init.d/clash mv $clashdir/clashservice /etc/init.d/clash
chmod 777 /etc/init.d/clash chmod 777 /etc/init.d/clash
else else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/ [ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
if [ -n "$sysdir" ];then if [ -n "$sysdir" ];then
#设为systemd方式启动 #设为systemd方式启动
mv $clashdir/clash.service $sysdir/clash.service mv $clashdir/clash.service $sysdir/clash.service
sed -i "s%/etc/clash%$clashdir%g" $sysdir/clash.service sed -i "s%/etc/clash%$clashdir%g" $sysdir/clash.service
systemctl daemon-reload systemctl daemon-reload
rm -rf /etc/init.d/clash
else else
#设为保守模式启动 #设为保守模式启动
sed -i '/start_old=*/'d $clashdir/mark sed -i '/start_old=*/'d $clashdir/mark
sed -i "1i\start_old=已开启" $clashdir/mark echo start_old=已开启 >> $clashdir/mark
fi fi
fi fi
#修饰文件及版本号 #修饰文件及版本号
@@ -432,7 +409,7 @@ gettar(){
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $clashdir/start.sh sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $clashdir/start.sh
chmod 777 $clashdir/start.sh chmod 777 $clashdir/start.sh
sed -i '/versionsh_l=*/'d $clashdir/mark sed -i '/versionsh_l=*/'d $clashdir/mark
sed -i "1i\versionsh_l=$release_new" $clashdir/mark echo versionsh_l=$release_new >> $clashdir/mark
#设置环境变量 #设置环境变量
[ -w ~/.bashrc ] && profile=~/.bashrc [ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile [ -w /etc/profile ] && profile=/etc/profile
@@ -555,10 +532,8 @@ getcore(){
echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m" echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m"
mv /tmp/clash.new $clashdir/clash mv /tmp/clash.new $clashdir/clash
chmod 777 $clashdir/clash #授予权限 chmod 777 $clashdir/clash #授予权限
sed -i '/clashcore=*/'d $ccfg setconfig clashcore $clashcore
sed -i "1i\clashcore=$clashcore" $ccfg setconfig clashv $version
sed -i '/clashv=*/'d $ccfg
sed -i "1i\clashv=$version" $ccfg
rm -rf /tmp/clashversion rm -rf /tmp/clashversion
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m$clashcore核心安装成功\033[0m" echo -e "\033[32m$clashcore核心安装成功\033[0m"
@@ -583,8 +558,7 @@ getgeo(){
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32mGeoIP数据库文件下载成功\033[0m" echo -e "\033[32mGeoIP数据库文件下载成功\033[0m"
mv /tmp/Country.mmdb $clashdir/Country.mmdb mv /tmp/Country.mmdb $clashdir/Country.mmdb
sed -i '/Geo_v=*/'d $ccfg setconfig Geo_v $GeoIP_v
sed -i "1i\Geo_v=$GeoIP_v" $ccfg
rm -rf /tmp/clashversion rm -rf /tmp/clashversion
fi fi
else else
@@ -684,8 +658,7 @@ getdb(){
#如果clash在运行则重启clash服务 #如果clash在运行则重启clash服务
[ "$dbdir" != "/www/clash" ] && [ -n "$PID" ] && $clashdir/start.sh restart [ "$dbdir" != "/www/clash" ] && [ -n "$PID" ] && $clashdir/start.sh restart
#写入配置文件 #写入配置文件
sed -i '/hostdir*/'d $ccfg setconfig hostdir \'$hostdir\'
sed -i "1i\hostdir=\'$hostdir\'" $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m面板安装成功\033[0m" echo -e "\033[32m面板安装成功\033[0m"
echo -e "\033[36m请使用\033[32;4mhttp://$host$hostdir\033[0;36m访问面板\033[0m" echo -e "\033[36m请使用\033[32;4mhttp://$host$hostdir\033[0;36m访问面板\033[0m"
@@ -732,8 +705,7 @@ setserver(){
update update
fi fi
#写入mark文件 #写入mark文件
sed -i '/update_url*/'d $ccfg setconfig update_url \'$update_url\'
sed -i "1i\update_url=\'$update_url\'" $ccfg
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m源地址更新成功\033[0m" echo -e "\033[32m源地址更新成功\033[0m"
release_new="" release_new=""
@@ -869,9 +841,12 @@ testcommand(){
elif [ "$num" = 1 ]; then elif [ "$num" = 1 ]; then
$clashdir/start.sh stop $clashdir/start.sh stop
echo ----------------------------------------------- echo -----------------------------------------------
$clashdir/clash -t -d $clashdir [ -f /tmp/clash/config.yaml ] && confdir='-f /tmp/clash/config.yaml'
$clashdir/clash -t -d $clashdir $confdir
[ "$?" = 0 ] && testover=32m测试通过|| testover=31m出现错误请截图后到TG群询问
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m" echo -e "\033[$testover\033[0m"
exit; exit;
elif [ "$num" = 2 ]; then elif [ "$num" = 2 ]; then
echo ----------------------------------------------- echo -----------------------------------------------

View File

@@ -8,6 +8,8 @@ getconfig(){
ccfg=$clashdir/mark ccfg=$clashdir/mark
[ -f $ccfg ] && source $ccfg [ -f $ccfg ] && source $ccfg
#默认设置 #默认设置
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
[ -z "$redir_mod" ] && redir_mod=纯净模式
[ -z "$skip_cert" ] && skip_cert=已开启 [ -z "$skip_cert" ] && skip_cert=已开启
[ -z "$common_ports" ] && common_ports=已开启 [ -z "$common_ports" ] && common_ports=已开启
[ -z "$dns_mod" ] && dns_mod=redir_host [ -z "$dns_mod" ] && dns_mod=redir_host
@@ -30,7 +32,14 @@ logger(){
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1d' $clashdir/log [ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1d' $clashdir/log
} }
cronset(){
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
crontab -l > /tmp/conf && sed -i "/$1/d" /tmp/conf && echo "$2" >> /tmp/conf && crontab /tmp/conf
rm -f /tmp/conf
}
getyaml(){ getyaml(){
[ -z "$rule_link" ] && rule_link=1
[ -z "$server_link" ] && server_link=1
#前后端订阅服务器地址索引,可在此处添加! #前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF Server=`sed -n ""$server_link"p"<<EOF
subcon.dlj.tf subcon.dlj.tf
@@ -95,7 +104,7 @@ EOF`
server_link=0 server_link=0
fi fi
server_link=$((server_link+1)) server_link=$((server_link+1))
sed -i "1i\server_link=$server_link" $ccfg echo server_link=$server_link >> $ccfg
Https="" Https=""
getyaml getyaml
fi fi
@@ -173,42 +182,42 @@ modify_yaml(){
else else
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
fi fi
################################### ###################################
yaml=$clashdir/config.yaml yaml=$clashdir/config.yaml
#预删除需要添加的项目 #预删除需要添加的项目
a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1) a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1)
b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1) b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1)
b=$((b-1)) b=$((b-1))
sed -i "${a},${b}d" $yaml mkdir -p /tmp/clash > /dev/null
#添加配置 sed "${a},${b}d" $yaml > /tmp/clash/rule.yaml
sed -i "1imixed-port:\ $mix_port" $yaml
sed -i "1aredir-port:\ $redir_port" $yaml
sed -i "2aauthentication:\ \[\"$authentication\"\]" $yaml
sed -i "3a$lan" $yaml
sed -i "4a$mode" $yaml
sed -i "5a$log" $yaml
sed -i "6a$ipv6" $yaml
sed -i "7aexternal-controller:\ :$db_port" $yaml
sed -i "8aexternal-ui:\ $db_ui" $yaml
sed -i "9asecret:\ $secret" $yaml
sed -i "10a$tun" $yaml
sed -i "11a$exper" $yaml
sed -i "12a$dns" $yaml
#跳过本地tls证书验证 #跳过本地tls证书验证
if [ "$skip_cert" = "已开启" ];then [ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' /tmp/clash/rule.yaml
sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $yaml #添加配置
else cat > /tmp/clash/set.yaml <<EOF
sed -i '10,99s/skip-cert-verify: true/skip-cert-verify: false/' $yaml mixed-port: $mix_port
fi redir-port: $redir_port
#禁止fake-ip回环流量 authentication: ["$authentication"]
#sed -i '/198.18.0.0/'d $yaml $lan
#sed -i '/rules:/a \ - IP-CIDR,198.18.0.0/16,REJECT' $yaml $mode
$log
$ipv6
external-controller: :$db_port
external-ui: $db_ui
secret: $secret
$tun
$exper
$dns
EOF
cat /tmp/clash/set.yaml /tmp/clash/rule.yaml > /tmp/clash/config.yaml
cmp -s /tmp/clash/config.yaml $yaml
[ "$?" != 0 ] && mv -f /tmp/clash/config.yaml $yaml || rm -f /tmp/clash/config.yaml
rm -f /tmp/clash/set.yaml
rm -f /tmp/clash/rule.yaml
} }
mark_time(){ mark_time(){
start_time=`date +%s` start_time=`date +%s`
sed -i '/start_time*/'d $clashdir/mark sed -i '/start_time*/'d $clashdir/mark
sed -i "1i\start_time=$start_time" $clashdir/mark echo start_time=$start_time >> $clashdir/mark
} }
start_redir(){ start_redir(){
#流量过滤规则 #流量过滤规则
@@ -307,12 +316,6 @@ start_dns(){
ip6tables -I INPUT -p udp --dport 53 -j REJECT ip6tables -I INPUT -p udp --dport 53 -j REJECT
fi fi
} }
daemon(){
if [ -n "$cronpath" ];then
echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash restart #clash保守模式守护进程' >> $cronpath
chmod 600 $cronpath
fi
}
web_save(){ web_save(){
get_save(){ get_save(){
if curl --version > /dev/null 2>&1;then if curl --version > /dev/null 2>&1;then
@@ -322,7 +325,7 @@ web_save(){
else else
logger 当前系统未安装curl且wget的版本太低无法保存节点配置 logger 当前系统未安装curl且wget的版本太低无法保存节点配置
getconfig getconfig
sed -i /保存节点配置/d $cronpath >/dev/null 2>&1 cronset '保存节点配置'
fi fi
} }
#使用get_save获取面板节点设置 #使用get_save获取面板节点设置
@@ -339,7 +342,7 @@ web_restore(){
if curl --version > /dev/null 2>&1;then if curl --version > /dev/null 2>&1;then
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1" -d "$2" >/dev/null curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1" -d "$2" >/dev/null
else else
wget --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null wget -q --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null
fi fi
} }
#设置循环检测clash面板端口 #设置循环检测clash面板端口
@@ -364,29 +367,27 @@ web_restore(){
done done
exit 0 exit 0
} }
web_save_auto(){
if [ -n "$cronpath" ];then
if [ -z "$(cat $cronpath | grep '保存节点配置')" ];then
echo '*/10 * * * * test -n "$(pidof clash)" && /etc/init.d/clash web_save #每10分钟保存节点配置' >> $cronpath
chmod 600 $cronpath
fi
fi
}
afstart(){ afstart(){
#读取配置文件 #读取配置文件
getconfig getconfig
#修改iptables规则使流量进入clash #修改iptables规则使流量进入clash
[ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "true" ] && start_dns [ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "已禁用" ] && start_dns
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir [ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
[ "$redir_mod" = "Redir模式" ] && [ "$tproxy_mod" = "已开启" ] && start_udp [ "$redir_mod" = "Redir模式" ] && [ "$tproxy_mod" = "已开启" ] && start_udp
#标记启动时间 #标记启动时间
mark_time mark_time
#设置本机代理 #设置本机代理
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port [ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $db_port
#还原面板配置 #启用面板配置自动保存
web_save_auto #启用面板配置自动保存 cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置 [ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
} }
start_old(){
$clashdir/clash -d $clashdir >/dev/null &
sleep 1
cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"$(pidof clash)\" && $clashdir/start.sh restart #clash保守模式守护进程"
afstart
}
case "$1" in case "$1" in
@@ -395,29 +396,29 @@ afstart)
;; ;;
start) start)
getconfig getconfig
[ "$modify_yaml" != "已开启" ] && modify_yaml #使用内置规则强行覆盖config配置文件 #使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#使用不同方式启动clash服务 #使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir >/dev/null 2>&1 & start_old
sleep 1
daemon
afstart
elif [ -f /etc/rc.common ];then elif [ -f /etc/rc.common ];then
/etc/init.d/clash start /etc/init.d/clash start
else elif [ "$USER" = "root" ];then
systemctl start clash.service systemctl start clash.service
else
start_old
fi fi
;; ;;
stop) stop)
getconfig getconfig
web_save #保存面板配置 web_save #保存面板配置
#删除守护进程&面板配置自动保存 #删除守护进程&面板配置自动保存
sed -i /clash保守模式守护进程/d $cronpath >/dev/null 2>&1 cronset "clash保守模式守护进程"
sed -i /保存节点配置/d $cronpath >/dev/null 2>&1 cronset "保存节点配置"
#多种方式结束进程 #多种方式结束进程
if [ -f /etc/rc.common ];then if [ -f /etc/rc.common ];then
/etc/init.d/clash stop >/dev/null 2>&1 /etc/init.d/clash stop >/dev/null 2>&1
else elif [ "$USER" = "root" ];then
systemctl stop clash.service >/dev/null 2>&1 systemctl stop clash.service >/dev/null 2>&1
fi fi
pidof clash | xargs kill -9 >/dev/null 2>&1 pidof clash | xargs kill -9 >/dev/null 2>&1
@@ -433,9 +434,6 @@ getyaml)
getconfig getconfig
getyaml getyaml
;; ;;
daemon)
daemon
;;
web_save) web_save)
getconfig getconfig
web_save web_save
@@ -443,12 +441,12 @@ web_save)
set_proxy) set_proxy)
#GNOME配置 #GNOME配置
if gsettings --version >/dev/null 2>&1 ;then if gsettings --version >/dev/null 2>&1 ;then
gsettings set org.gnome.system.proxy autoconfig-url "http://127.0.0.1:$1/ui/pac" gsettings set org.gnome.system.proxy autoconfig-url "http://127.0.0.1:$3/ui/pac"
gsettings set org.gnome.system.proxy mode "auto" gsettings set org.gnome.system.proxy mode "auto"
[ "$?" = 0 ] && check=$? [ "$?" = 0 ] && check=$?
#KDE配置 #KDE配置
elif kwriteconfig5 -h >/dev/null 2>&1 ;then elif kwriteconfig5 -h >/dev/null 2>&1 ;then
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1:$1/ui/pac" kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1:$3/ui/pac"
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 2 kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 2
[ "$?" = 0 ] && check=$? [ "$?" = 0 ] && check=$?
#环境变量方式 #环境变量方式
@@ -456,7 +454,7 @@ set_proxy)
if [ -z "$check" ];then if [ -z "$check" ];then
[ -w ~/.bashrc ] && profile=~/.bashrc [ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile [ -w /etc/profile ] && profile=/etc/profile
echo 'export all_proxy=http://127.0.0.1:'"$1" >> $profile echo 'export all_proxy=http://127.0.0.1:'"$2" >> $profile
echo 'export ALL_PROXY=$all_proxy' >> $profile echo 'export ALL_PROXY=$all_proxy' >> $profile
fi fi
;; ;;