~优化文件结构,清理工作目录
 -/configs————脚本配置文件相关
 -/yamls————clash配置文件相关
 -/tools————脚本工具相关
 -卸载时增加是否保留配置文件确认
 -更新时将自动清理部分无用文件
~配置文件覆写代码优化
 -增加去重逻辑,防止user.yaml内容冲突
 -现在生成的配置直接在缓存中执行
 -修复自定义配置出错时无法正确还原配置文件的问题
 -修复others.yaml不会被正确读取的bug
~增加公共维护列表/public,欢迎提交pr
 -servers.list————用于维护内置订阅转换规则/服务器、更新服务器
 -fake_ip_filter.list————用于fake-ip地址过滤
 -fallback-filter.list————用于fallback-DNS域名解析筛选
 -在线配置生成后端部分地址替换
~重写DNS生成逻辑
 -尝试使用fake-ip模拟redir-host,以兼容更多内核
 -兼容fake_ip_filter.list及fallback-filter.list
 -修复bing、领英官网自动跳转cn的问题
~新手引导增加自动配置ipv6路由
~屏蔽QUIC功能增加ipv6支持
~修复局域网过滤功能不会提示重启的bug
~修复公网访问功能导致iptables不停累加的bug
This commit is contained in:
juewuy 2023-07-30 09:49:41 +08:00
parent 72b75b422f
commit 2d00da175f
8 changed files with 552 additions and 388 deletions

139
public/fake_ip_filter.list Normal file
View File

@ -0,0 +1,139 @@
#LAN
*.lan
*.localdomain
*.example
*.invalid
*.localhost
*.test
*.local
*.home.arpa
#放行NTP服务
time.*.com
time.*.gov
time.*.edu.cn
time.*.apple.com
time-ios.apple.com
time1.*.com
time2.*.com
time3.*.com
time4.*.com
time5.*.com
time6.*.com
time7.*.com
ntp.*.com
ntp1.*.com
ntp2.*.com
ntp3.*.com
ntp4.*.com
ntp5.*.com
ntp6.*.com
ntp7.*.com
*.time.edu.cn
*.ntp.org.cn
+.pool.ntp.org
time1.cloud.tencent.com
#放行网易云音乐
music.163.com
*.music.163.com
*.126.net
#百度音乐
musicapi.taihe.com
music.taihe.com
#酷狗音乐
songsearch.kugou.com
trackercdn.kugou.com
#酷我音乐
*.kuwo.cn
#JOOX音乐
api-jooxtt.sanook.com
api.joox.com
joox.com
#QQ音乐
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
#win10本地连接检测
+.msftconnecttest.com
+.msftncsi.com
#QQ登录
localhost.ptlogin2.qq.com
localhost.sec.qq.com
+.qq.com
+.tencent.com
#Game
#Nintendo Switch
+.srv.nintendo.net
*.n.n.srv.nintendo.net
#Sony PlayStation
+.stun.playstation.net
#Microsoft Xbox
xbox.*.*.microsoft.com
*.*.xboxlive.com
xbox.*.microsoft.com
xnotify.xboxlive.com
#Wotgame
+.battlenet.com.cn
+.wotgame.cn
+.wggames.cn
+.wowsgame.cn
+.wargaming.net
#Golang
proxy.golang.org
#STUN
stun.*.*
stun.*.*.*
+.stun.*.*
+.stun.*.*.*
+.stun.*.*.*.*
+.stun.*.*.*.*.*
#Linksys Router
heartbeat.belkin.com
*.linksys.com
*.linksyssmartwifi.com
#ASUS Router
*.router.asus.com
#Apple Software Update Service
mesu.apple.com
swscan.apple.com
swquery.apple.com
swdownload.apple.com
swcdn.apple.com
swdist.apple.com
#Google
lens.l.google.com
stun.l.google.com
na.b.g-tun.com
#Netflix
+.nflxvideo.net
#FinalFantasy XIV Worldwide Server & CN Server
*.square-enix.com
*.finalfantasyxiv.com
*.ffxiv.com
*.ff14.sdo.com
ff.dorado.sdo.com
#Bilibili
*.mcdn.bilivideo.cn
#Disney Plus
+.media.dssott.com
#shark007 Codecs
shark007.net
#Mijia
Mijia Cloud
#招商银行
+.cmbchina.com
+.cmbimg.com
#AdGuard
local.adguard.org
#迅雷
+.sandai.net
+.n0808.com

32
public/servers.list Normal file
View File

@ -0,0 +1,32 @@
# ID&类型 说明 地址 其他说明 (类型100-稳定源;200-测试源;300-基础sub;400-meta_sub;500-规则地址)
101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash 稳定版
102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash 稳定版
201 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master 公测版
202 ShellClash私人源1 https://gh.jwsc.eu.org/master 公测版
203 ShellClash私人源2 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellClash 公测版
204 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash/master 公测版
205 (请加TG讨论组:\033[4;36mhttps://t.me/ShellClash\033[0m) http://t.jwsc.eu.org 内测版
206 wwng2333自建源 https://mirrors.csgo.ovh/ShellClash 公测版
301 墙洞提供 https://api.dler.io
302 SUB作者提供 https://sub.xeton.dev
303 猫熊提供 https://sub.maoxiongnet.com
401 肥羊提供,支持vless|hy https://sub.d1.mk
402 品云提供,支持vless|hy https://v.id9.cc
403 作者提供,支持vless|hy https://sub.jwsc.eu.org
499 作者提供,未加密仅备用 http://sub2.jwsc.eu.org
501 Acl4SSR全能优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash.ini (推荐)
502 Acl4SSR精简优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Mini.ini (推荐)
503 Acl4SSR全能优化+去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Block.ini
504 Acl4SSR极简版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Nano.ini (适合自建节点)
505 Acl4SSR分流&游戏增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full.ini
506 Acl4SSR分流&游戏&去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full_Block.ini (低性能设备慎用)
507 洞主规则精简版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
508 洞主规则重度完整版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
509 Acl4SSR多国精简 https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiCountry.ini
510 Acl4SSR回国专用 https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_BackCN.ini

View File

@ -1,12 +1,13 @@
#!/bin/sh
# Copyright (C) Juewuy
CFG_PATH=$clashdir/mark
tmpdir=/tmp/clash_$USER && [ ! -f $tmpdir ] && mkdir -p $tmpdir
CFG_PATH=$clashdir/configs/ShellClash.cfg
YAMLSDIR=$clashdir/yamls
TMPDIR=/tmp/clash_$USER && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
#读取配置相关
setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=$clashdir/mark || configpath=$3
[ -z "$3" ] && configpath=$CFG_PATH || configpath=$3
[ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
}
ckcmd(){
@ -16,14 +17,18 @@ ckstatus(){
#服务器缺省地址
[ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellClash
#检查/读取标识文件
[ ! -f $CFG_PATH ] && echo '#标识clash运行状态的文件不明勿动' > $CFG_PATH
#检查重复行并去除
[ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH
#检查时间戳
touch $tmpdir/clash_start_time
#使用source加载配置文件
source $CFG_PATH > /dev/null
#检查/读取脚本配置文件
if [ -f $CFG_PATH ];then
#检查重复行并去除
[ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH
#检查时间戳
touch $TMPDIR/clash_start_time
#使用source加载配置文件
source $CFG_PATH > /dev/null
else
mkdir -p $clashdir/configs
echo '#标识clash运行状态的文件不明勿动' > $CFG_PATH
fi
versionsh=$(cat $clashdir/init.sh | grep -E ^version= | head -n 1 | sed 's/version=//')
[ -n "$versionsh" ] && versionsh_l=$versionsh
#设置默认核心资源目录
@ -37,7 +42,7 @@ ckstatus(){
[ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$redir_mod" ] && redir_mod=纯净模式
#检查mac地址记录
[ ! -f $clashdir/mac ] && touch $clashdir/mac
[ ! -f $clashdir/configs/mac ] && touch $clashdir/configs/mac
#获取本机host地址
[ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
@ -68,8 +73,8 @@ ckstatus(){
run="\033[32m正在运行$redir_mod\033[0m"
VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
#获取运行时长
touch $tmpdir/clash_start_time #用于延迟启动的校验
start_time=$(cat $tmpdir/clash_start_time)
touch $TMPDIR/clash_start_time #用于延迟启动的校验
start_time=$(cat $TMPDIR/clash_start_time)
if [ -n "$start_time" ]; then
time=$((`date +%s`-start_time))
day=$((time/86400))
@ -132,9 +137,9 @@ ckstatus(){
file=/tmp/$file
$bindir/clash -t -d $bindir -f $file &>/dev/null && {
echo -e "发现可用的YAML配置文件 \033[36m$file\033[0m "
read -p "加载为config.yaml配置文件/或者移除该文件?(1/0) > " res
read -p "加载为yaml配置文件/或者移除该文件?(1/0) > " res
[ "$res" = 1 ] && {
mv -f $file $clashdir/config.yaml
mv -f $file $clashdir/yamls/config.yaml
echo -e "\033[32m配置文件加载完成\033[0m "
sleep 1
}
@ -177,7 +182,7 @@ startover(){
}
clashstart(){
#检查yaml配置文件
if [ ! -f "$clashdir/config.yaml" ];then
if [ ! -f $clashdir/yamls/config.yaml ];then
echo -----------------------------------------------
echo -e "\033[31m没有找到配置文件请先导入配置文件\033[0m"
source $clashdir/getdate.sh && clashlink
@ -213,7 +218,7 @@ log_pusher(){
case $num in
1)
echo -----------------------------------------------
cat $tmpdir/ShellClash_log
cat $TMPDIR/ShellClash_log
exit
;;
2)
@ -756,7 +761,7 @@ macfilter(){
add_mac(){
echo -----------------------------------------------
echo 已添加的mac地址
cat $clashdir/mac
cat $clashdir/configs/mac
echo -----------------------------------------------
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m"
cat $dhcpdir | awk '{print " "NR" "$3,$2,$4}'
@ -767,9 +772,9 @@ macfilter(){
read -p "请输入对应序号或直接输入mac地址 > " num
if [ -z "$num" -o "$num" = 0 ]; then
i=
elif [ -n "$(echo $num | grep -E '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then
if [ -z "$(cat $clashdir/mac | grep -E "$num")" ];then
echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> $clashdir/mac
elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then
if [ -z "$(cat $clashdir/configs/mac | grep -E "$num")" ];then
echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> $clashdir/configs/mac
else
echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
@ -777,8 +782,8 @@ macfilter(){
add_mac
elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then
macadd=$(cat $dhcpdir | awk '{print $2}' | sed -n "$num"p)
if [ -z "$(cat $clashdir/mac | grep -E "$macadd")" ];then
echo $macadd >> $clashdir/mac
if [ -z "$(cat $clashdir/configs/mac | grep -E "$macadd")" ];then
echo $macadd >> $clashdir/configs/mac
else
echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
@ -792,12 +797,12 @@ macfilter(){
}
del_mac(){
echo -----------------------------------------------
if [ -z "$(cat $clashdir/mac)" ];then
if [ -z "$(cat $clashdir/configs/mac)" ];then
echo -e "\033[31m列表中没有需要移除的设备\033[0m"
else
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[0m"
i=1
for mac in $(cat $clashdir/mac); do
for mac in $(cat $clashdir/configs/mac); do
dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00'
dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac
dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备'
@ -809,8 +814,8 @@ macfilter(){
read -p "请输入需要移除的设备的对应序号 > " num
if [ -z "$num" ]||[ "$num" -le 0 ]; then
n=
elif [ $num -le $(cat $clashdir/mac | wc -l) ];then
sed -i "${num}d" $clashdir/mac
elif [ $num -le $(cat $clashdir/configs/mac | wc -l) ];then
sed -i "${num}d" $clashdir/configs/mac
echo -----------------------------------------------
echo -e "\033[32m对应设备已移除\033[0m"
del_mac
@ -839,11 +844,11 @@ macfilter(){
echo -e "\033[30;47m请在此添加或移除设备\033[0m"
echo -e "当前过滤方式为:\033[33m$macfilter_type模式\033[0m"
echo -e "仅列表内设备\033[36m$macfilter_scrip经过\033[0mClash内核"
if [ -n "$(cat $clashdir/mac)" ]; then
if [ -n "$(cat $clashdir/configs/mac)" ]; then
echo -----------------------------------------------
echo -e "当前已过滤设备为:\033[36m"
echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m"
for mac in $(cat $clashdir/mac); do
for mac in $(cat $clashdir/configs/mac); do
dev_ip=$(cat $dhcpdir | grep $mac | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip='000.000.00.00'
dev_mac=$(cat $dhcpdir | grep $mac | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$mac
dev_name=$(cat $dhcpdir | grep $mac | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备'
@ -874,7 +879,7 @@ macfilter(){
del_mac
macfilter
elif [ "$num" = 4 ]; then
:>$clashdir/mac
:>$clashdir/configs/mac
echo -----------------------------------------------
echo -e "\033[31m设备列表已清空\033[0m"
macfilter
@ -1210,26 +1215,30 @@ clashcfg(){
echo -e "示例:*.b.com"
echo -e "示例:*.*.b.com\033[0m"
echo -----------------------------------------------
if [ -f $clashdir/fake_ip_filter ];then
if [ -s $clashdir/configs/fake_ip_filter ];then
echo -e "\033[33m已添加Fake-ip过滤地址\033[0m"
cat $clashdir/fake_ip_filter | awk '{print NR" "$1}'
cat $clashdir/configs/fake_ip_filter | awk '{print NR" "$1}'
else
echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m"
fi
echo -----------------------------------------------
echo -e "\033[32m输入数字直接移除对应地址输入地址直接添加\033[0m"
read -p "请输入数字或地址 > " input
if [ -z "$input" -o "input" = 0 ];then
i=
elif [ "$input" -le "$(cat $clashdir/fake_ip_filter | wc -l)" ];then
sed -i "${input}d" $clashdir/fake_ip_filter 2>/dev/null
case $input in
0) ;;
'') ;;
[0-99])
sed -i "${input}d" $clashdir/configs/fake_ip_filter 2>/dev/null
echo -e "\033[32m移除成功\033[0m"
fake_ip_filter
else
;;
*)
echo -e "你输入的地址是:\033[32m$input\033[0m"
read -p "确认添加?(1/0) > " res
[ "$res" = 1 ] && echo $input >> $clashdir/fake_ip_filter || fake_ip_filter
fi
[ "$res" = 1 ] && echo $input >> $clashdir/configs/fake_ip_filter
fake_ip_filter
;;
esac
}
#获取设置默认显示
[ -z "$skip_cert" ] && skip_cert=已开启
@ -1239,7 +1248,7 @@ clashcfg(){
[ -z "$cn_ip_route" ] && cn_ip_route=未开启
[ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$quic_rj" ] && quic_rj=未开启
[ -z "$(cat $clashdir/mac)" ] && mac_return=未开启 || mac_return=已启用
[ -z "$(cat $clashdir/configs/mac)" ] && mac_return=未开启 || mac_return=已启用
#
echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用功能设置菜单\033[0m"
@ -1315,10 +1324,10 @@ clashcfg(){
clashcfg
elif [ "$num" = 5 ]; then
checkcfg_mac=$(cat $clashdir/mac)
checkcfg_mac=$(cat $clashdir/configs/mac)
macfilter
if [ -n "$PID" ];then
checkcfg_mac_new=$(cat $clashdir/mac)
checkcfg_mac_new=$(cat $clashdir/configs/mac)
[ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart
fi
clashcfg
@ -1357,7 +1366,6 @@ clashcfg(){
echo -----------------------------------------------
if [ "$dns_mod" = "fake-ip" ];then
fake_ip_filter
clashcfg
else
if [ -n "$(ipset -v 2>/dev/null)" -o -n "$(echo $redir_mod | grep Nft)" ];then
if [ "$cn_ip_route" = "未开启" ]; then
@ -1501,8 +1509,8 @@ autoSSH(){
echo -e "\033[33m如有问题请加群反馈\033[36;4mhttps://t.me/ShellClash\033[0m"
read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd
mi_autoSSH=已配置
cp -f /etc/dropbear/dropbear_rsa_host_key $clashdir/dropbear_rsa_host_key 2>/dev/null
cp -f /etc/dropbear/authorized_keys $clashdir/authorized_keys 2>/dev/null
cp -f /etc/dropbear/dropbear_rsa_host_key $clashdir/configs/dropbear_rsa_host_key 2>/dev/null
cp -f /etc/dropbear/authorized_keys $clashdir/configs/authorized_keys 2>/dev/null
ckcmd nvram && {
nvram set ssh_en=1
nvram set telnet_en=1
@ -1583,7 +1591,7 @@ tools(){
#获取设置默认显示
[ -n "$(cat /etc/crontabs/root 2>&1| grep otapredownload)" ] && mi_update=禁用 || mi_update=启用
[ "$mi_autoSSH" = "已配置" ] && mi_autoSSH_type=32m已配置 || mi_autoSSH_type=31m未配置
[ -f $clashdir/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用
[ -f $clashdir/configs/tun.ko ] && mi_tunfix=32m已启用 || mi_tunfix=31m未启用
#
echo -----------------------------------------------
echo -e "\033[30;47m欢迎使用其他工具菜单\033[0m"
@ -1625,17 +1633,17 @@ tools(){
elif [ "$num" = 7 ]; then
echo -----------------------------------------------
if [ ! -f $clashdir/ShellDDNS.sh ];then
if [ ! -f $clashdir/tools/ShellDDNS.sh ];then
echo -e "正在获取在线脚本……"
$clashdir/start.sh webget $tmpdir/ShellDDNS.sh $update_url/tools/ShellDDNS.sh
$clashdir/start.sh webget $TMPDIR/ShellDDNS.sh $update_url/tools/ShellDDNS.sh
if [ "$?" = "0" ];then
mv -f $tmpdir/ShellDDNS.sh $clashdir/ShellDDNS.sh
source $clashdir/ShellDDNS.sh
mv -f $TMPDIR/ShellDDNS.sh $clashdir/tools/ShellDDNS.sh
source $clashdir/tools/ShellDDNS.sh
else
echo -e "\033[31m文件下载失败\033[0m"
fi
else
source $clashdir/ShellDDNS.sh
source $clashdir/tools/ShellDDNS.sh
fi
sleep 1
tools
@ -1655,10 +1663,10 @@ tools(){
fi
tools
elif [ "$num" = 8 ]; then
if [ -f $clashdir/tun.ko ];then
if [ -f $clashdir/configs/tun.ko ];then
read -p "是否禁用此功能并移除相关补丁?(1/0) > " res
[ "$res" = 1 ] && {
rm -rf $clashdir/tun.ko
rm -rf $clashdir/configs/tun.ko
echo -e "\033[33m补丁文件已移除请立即重启设备以防止出错\033[0m"
}
elif [ -z "$(modinfo tun)" ];then
@ -1670,9 +1678,9 @@ tools(){
tunfixlink="${update_url}/bin/fix/tun.ko"
echo -----------------------------------------------
echo 正在连接服务器获取Tun模块补丁文件…………
$clashdir/start.sh webget $tmpdir/tun.ko $tunfixlink
$clashdir/start.sh webget $TMPDIR/tun.ko $tunfixlink
if [ "$?" = "0" ];then
mv -f $tmpdir/tun.ko $clashdir && \
mv -f $TMPDIR/tun.ko $clashdir && \
$clashdir/misnap_init.sh tunfix && \
echo -e "\033[32m设置成功请重启clash服务\033[0m"
else
@ -1730,7 +1738,7 @@ clashcron(){
read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then
cronwords="$min $hour * * $week $cronset #$week1的$hour点$min分$cronname"
tmpcron=$tmpdir/cron_$USER
tmpcron=$TMPDIR/cron_$USER
croncmd -l > $tmpcron
sed -i "/$cronname/d" $tmpcron
sed -i '/^$/d' $tmpcron
@ -1760,9 +1768,9 @@ clashcron(){
elif [ "$num" = 0 ]; then
i=
elif [ "$num" = 9 ]; then
croncmd -l > $tmpdir/conf && sed -i "/$cronname/d" $tmpdir/conf && croncmd $tmpdir/conf
croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf
sed -i "/$cronname/d" $clashdir/cron 2>/dev/null
rm -f $tmpdir/conf
rm -f $TMPDIR/conf
echo -----------------------------------------------
echo -e "\033[31m定时任务$cronname已删除\033[0m"
elif [ "$num" = 8 ]; then
@ -1844,9 +1852,9 @@ clashcron(){
read -p "请输入备注的关键词 > " txt
[ -n "$txt" ] && {
cronname=$txt
croncmd -l > $tmpdir/conf && sed -i "/$cronname/d" $tmpdir/conf && croncmd $tmpdir/conf
croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf
sed -i "/$cronname/d" $clashdir/cron 2>/dev/null
rm -f $tmpdir/conf
rm -f $TMPDIR/conf
echo -----------------------------------------------
echo -e "所有关键词\033[32m$cronname\033[0m匹配的定时任务均已删除\033[0m"
sleep 1
@ -1980,8 +1988,18 @@ case "$1" in
$shtype -x $clashdir/start.sh $2 $3 $4 $5 $6
;;
-u)
read -p "确认卸载ShellClash(警告:该操作不可逆!)[1/0] " res
read -p "确认卸载ShellClash(警告:该操作不可逆!)[1/0] > " res
if [ "$res" = '1' ]; then
read -p "是否保留脚本配置及订阅文件?[1/0] > " res
if [ "$res" = '1' ]; then
mv -f $clashdir/configs /tmp/clash_$USER
mv -f $clashdir/yamls /tmp/clash_$USER
rm -rf $clashdir/*
mv -f /tmp/clash_$USER/configs $clashdir
mv -f /tmp/clash_$USER/yamls $clashdir
else
rm -rf $clashdir
fi
$clashdir/start.sh stop
$clashdir/start.sh cronset "clash服务"
$clashdir/start.sh cronset "订阅链接"
@ -1996,7 +2014,6 @@ case "$1" in
sed -i '/ShellClash初始化/'d /etc/storage/started_script.sh 2>/dev/null
sed -i '/ShellClash初始化/'d /jffs/.asusrouter 2>/dev/null
rm -rf $bindir
rm -rf $clashdir
rm -rf /etc/init.d/clash
rm -rf /etc/systemd/system/clash.service
rm -rf /usr/lib/systemd/system/clash.service

View File

@ -8,7 +8,7 @@ USE_PROCD=1
#获取目录
DIR=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}')
[ -z "$DIR" ] && DIR=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}')
BINDIR=$(cat $DIR/mark | grep bindir | awk -F "=" '{print $2}')
BINDIR=$(cat $DIR/configs/ShellClash.cfg | grep bindir | awk -F "=" '{print $2}')
[ -z "$BINDIR" ] && BINDIR=$DIR
TMPDIR=/tmp/clash_$USER

View File

@ -12,17 +12,8 @@ dir_avail(){
#导入订阅、配置文件相关
linkconfig(){
echo -----------------------------------------------
echo 当前使用规则为:$rule_link
echo " 1 Acl4SSR全能优化版(推荐)"
echo " 2 Acl4SSR精简优化版(推荐)"
echo " 3 Acl4SSR全能优化+去广告增强"
echo " 4 Acl4SSR极简版(适合自建)"
echo " 5 Acl4SSR分流&游戏增强"
echo " 6 Acl4SSR分流&游戏&去广告增强"
echo " 7 洞主规则精简版"
echo " 8 洞主规则重度完整版"
echo " 9 Acl4SSR多国精简"
echo " 10 Acl4SSR回国专用"
echo 当前使用规则为:$(grep -aE '^5' $clashdir/configs/servers.list | sed -n ""$rule_link"p" | awk '{print $2}')
grep -aE '^5' $clashdir/configs/servers.list | awk '{print " "NR" "$2$4}'
echo -----------------------------------------------
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
@ -42,12 +33,8 @@ linkserver(){
echo -----------------------------------------------
echo -e "\033[36m以下为互联网采集的第三方服务器具体安全性请自行斟酌\033[0m"
echo -e "\033[32m感谢以下作者的无私奉献\033[0m"
echo 当前使用后端为:$server_link
echo 1 api.dler.io (墙洞提供)
echo 2 api.v1.mk (肥羊提供,支持vless
echo 3 sub.xeton.dev SUB作者提供
echo 4 v.id9.cc (品云提供,支持vless
echo 5 sub.maoxiongnet.com (猫熊提供)
echo 当前使用后端为:$(grep -aE '^5' $clashdir/configs/servers.list | sed -n ""$server_link"p" | awk '{print $2}')
grep -aE '^3|^4' $clashdir/configs/servers.list | awk '{print " "NR" "$3" "$2}'
echo -----------------------------------------------
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
@ -268,7 +255,7 @@ setrules(){
rule_group_set=$(echo $rule_group|cut -d'#' -f$num)
rule_all="- ${rule_type_set},${rule_state_set},${rule_group_set}"
[ -n "$(echo IP-CIDR SRC-IP-CIDR IP-CIDR6|grep "$rule_type_set")" ] && rule_all="${rule_all},no-resolve"
echo $rule_all >> $clashdir/rules.yaml
echo $rule_all >> $YAMLSDIR/rules.yaml
echo -----------------------------------------------
echo -e "\033[32m添加成功\033[0m"
fi
@ -280,8 +267,8 @@ setrules(){
}
del_rule_type(){
echo -e "输入对应数字即可移除相应规则:"
sed -i '/^ *$/d' $clashdir/rules.yaml
cat $clashdir/rules.yaml | grep -Ev '^#' | awk -F "#" '{print " "NR" "$1$2$3}'
sed -i '/^ *$/d' $YAMLSDIR/rules.yaml
cat $YAMLSDIR/rules.yaml | grep -Ev '^#' | awk -F "#" '{print " "NR" "$1$2$3}'
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@ -289,8 +276,8 @@ setrules(){
0) ;;
'') ;;
*)
if [ $num -le $(cat $clashdir/rules.yaml | grep -Ev '^#' | grep -Ev '^ *$' | wc -l) ];then
sed -i "$num{/^\s*[^#]/d}" $clashdir/rules.yaml
if [ $num -le $(cat $YAMLSDIR/rules.yaml | grep -Ev '^#' | grep -Ev '^ *$' | wc -l) ];then
sed -i "$num{/^\s*[^#]/d}" $YAMLSDIR/rules.yaml
del_rule_type
else
errornum
@ -300,7 +287,7 @@ setrules(){
}
echo -----------------------------------------------
echo -e "\033[33m你可以在这里快捷管理自定义规则\033[0m"
echo -e "\033[36m如需批量操作请手动编辑$clashdir/rules.yaml\033[0m"
echo -e "\033[36m如需批量操作请手动编辑$YAMLSDIR/rules.yaml\033[0m"
echo -----------------------------------------------
echo -e " 1 新增自定义规则"
echo -e " 2 管理自定义规则"
@ -311,13 +298,13 @@ setrules(){
case $num in
1)
rule_type="DOMAIN-SUFFIX DOMAIN-KEYWORD IP-CIDR SRC-IP-CIDR DST-PORT SRC-PORT GEOIP GEOSITE IP-CIDR6 DOMAIN MATCH"
rule_group="DIRECT#REJECT$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/- name: /#/g' | tr -d '\n')"
rule_group="DIRECT#REJECT$(cat $YAMLSDIR/proxy-groups.yaml $YAMLSDIR/config.yaml | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/- name: /#/g' | tr -d '\n')"
set_rule_type
setrules
;;
2)
echo -----------------------------------------------
if [ -s $clashdir/rules.yaml ];then
if [ -s $YAMLSDIR/rules.yaml ];then
del_rule_type
else
echo -e "请先添加自定义规则!"
@ -327,7 +314,7 @@ setrules(){
;;
3)
read -p "确认清空全部自定义规则?(1/0) > " res
[ "$res" = "1" ] && sed -i '/^\s*[^#]/d' $clashdir/rules.yaml
[ "$res" = "1" ] && sed -i '/^\s*[^#]/d' $YAMLSDIR/rules.yaml
setrules
;;
4)
@ -354,7 +341,7 @@ setgroups(){
echo -----------------------------------------------
echo -e "\033[33m注意策略组名称必须和【自定义规则】或【自定义节点】功能中指定的策略组一致\033[0m"
echo -e "\033[33m建议先创建策略组之后可在【自定义规则】或【自定义节点】功能中智能指定\033[0m"
echo -e "\033[33m如需在当前策略组下添加节点请手动编辑$clashdir/proxy-groups.yaml\033[0m"
echo -e "\033[33m如需在当前策略组下添加节点请手动编辑$YAMLSDIR/proxy-groups.yaml\033[0m"
read -p "请输入自定义策略组名称(不支持纯数字) > " new_group_name
echo -----------------------------------------------
echo -e "\033[32m请选择策略组【$new_group_name】的类型!\033[0m"
@ -371,7 +358,7 @@ setgroups(){
fi
set_group_add
#添加自定义策略组
cat >> $clashdir/proxy-groups.yaml <<EOF
cat >> $YAMLSDIR/proxy-groups.yaml <<EOF
- name: $new_group_name
type: $new_group_type
$new_group_url
@ -379,7 +366,7 @@ setgroups(){
proxies:
- DIRECT
EOF
sed -i "/^ *$/d" $clashdir/proxy-groups.yaml
sed -i "/^ *$/d" $YAMLSDIR/proxy-groups.yaml
echo -----------------------------------------------
echo -e "\033[32m添加成功\033[0m"
@ -411,7 +398,7 @@ EOF
}
echo -----------------------------------------------
echo -e "\033[33m你可以在这里快捷管理自定义策略组\033[0m"
echo -e "\033[36m如需修改或批量操作请手动编辑$clashdir/proxy-groups.yaml\033[0m"
echo -e "\033[36m如需修改或批量操作请手动编辑$YAMLSDIR/proxy-groups.yaml\033[0m"
echo -----------------------------------------------
echo -e " 1 添加自定义策略组"
echo -e " 2 查看自定义策略组"
@ -422,18 +409,18 @@ EOF
1)
group_type="select url-test fallback load-balance"
group_type_cn="手动选择 自动选择 故障转移 负载均衡"
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml 2>/dev/null| sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
proxy_group="$(cat $YAMLSDIR/proxy-groups.yaml $YAMLSDIR/config.yaml 2>/dev/null| sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
set_group_type
setgroups
;;
2)
echo -----------------------------------------------
cat $clashdir/proxy-groups.yaml
cat $YAMLSDIR/proxy-groups.yaml
setgroups
;;
3)
read -p "确认清空全部自定义策略组?(1/0) > " res
[ "$res" = "1" ] && echo '#用于添加自定义策略组' > $clashdir/proxy-groups.yaml
[ "$res" = "1" ] && echo '#用于添加自定义策略组' > $YAMLSDIR/proxy-groups.yaml
setgroups
;;
*)
@ -468,7 +455,7 @@ setproxies(){
rule_group_add="${rule_group_add}#${rule_group_set}"
done
if [ -n "$rule_group_add" ];then
echo "- {$proxy_state_set}$rule_group_add" >> $clashdir/proxies.yaml
echo "- {$proxy_state_set}$rule_group_add" >> $YAMLSDIR/proxies.yaml
echo -----------------------------------------------
echo -e "\033[32m添加成功\033[0m"
unset rule_group_add
@ -480,7 +467,7 @@ setproxies(){
}
echo -----------------------------------------------
echo -e "\033[33m你可以在这里快捷管理自定义节点\033[0m"
echo -e "\033[36m如需批量操作请手动编辑$clashdir/proxies.yaml\033[0m"
echo -e "\033[36m如需批量操作请手动编辑$YAMLSDIR/proxies.yaml\033[0m"
echo -----------------------------------------------
echo -e " 1 添加自定义节点"
echo -e " 2 管理自定义节点"
@ -491,21 +478,21 @@ setproxies(){
case $num in
1)
proxy_type="DOMAIN-SUFFIX DOMAIN-KEYWORD IP-CIDR SRC-IP-CIDR DST-PORT SRC-PORT GEOIP GEOSITE IP-CIDR6 DOMAIN MATCH"
proxy_group="$(cat $clashdir/proxy-groups.yaml $clashdir/config.yaml 2>/dev/null | sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
proxy_group="$(cat $YAMLSDIR/proxy-groups.yaml $YAMLSDIR/config.yaml 2>/dev/null | sed "/#自定义策略组开始/,/#自定义策略组结束/d" | grep -Ev '^#' | grep -o '\- name:.*' | sed 's/#.*//' | sed 's/- name: /#/g' | tr -d '\n' | sed 's/#//')"
set_proxy_type
setproxies
;;
2)
echo -----------------------------------------------
sed -i '/^ *$/d' $clashdir/proxies.yaml 2>/dev/null
if [ -s $clashdir/proxies.yaml ];then
sed -i '/^ *$/d' $YAMLSDIR/proxies.yaml 2>/dev/null
if [ -s $YAMLSDIR/proxies.yaml ];then
echo -e "当前已添加的自定义节点为:"
cat $clashdir/proxies.yaml | grep -Ev '^#' | awk -F '[,,}]' '{print NR, $1, $NF}' | sed 's/- {//g'
cat $YAMLSDIR/proxies.yaml | grep -Ev '^#' | awk -F '[,,}]' '{print NR, $1, $NF}' | sed 's/- {//g'
echo -----------------------------------------------
echo -e "\033[33m输入节点对应数字可以移除对应节点\033[0m"
read -p "请输入对应数字 > " num
if [ $num -le $(cat $clashdir/proxies.yaml | grep -Ev '^#' | wc -l) ];then
sed -i "$num{/^\s*[^#]/d}" $clashdir/proxies.yaml
if [ $num -le $(cat $YAMLSDIR/proxies.yaml | grep -Ev '^#' | wc -l) ];then
sed -i "$num{/^\s*[^#]/d}" $YAMLSDIR/proxies.yaml
else
errornum
fi
@ -517,7 +504,7 @@ setproxies(){
;;
3)
read -p "确认清空全部自定义节点?(1/0) > " res
[ "$res" = "1" ] && sed -i '/^\s*[^#]/d' $clashdir/proxies.yaml 2>/dev/null
[ "$res" = "1" ] && sed -i '/^\s*[^#]/d' $YAMLSDIR/proxies.yaml 2>/dev/null
setproxies
;;
4)
@ -583,12 +570,12 @@ override(){
override
;;
5)
[ ! -f $clashdir/user.yaml ] && cat > $clashdir/user.yaml <<EOF
[ ! -f $YAMLSDIR/user.yaml ] && cat > $YAMLSDIR/user.yaml <<EOF
#用于编写自定义设定(可参考https://lancellc.gitbook.io/clash/clash-config-file/general 或 https://docs.metacubex.one/function/general)
#端口之类请在脚本中修改,否则不会加载
#port: 7890
EOF
[ ! -f $clashdir/others.yaml ] && cat > $clashdir/others.yaml <<EOF
[ ! -f $YAMLSDIR/others.yaml ] && cat > $YAMLSDIR/others.yaml <<EOF
#用于编写自定义的锚点、入站、proxy-providers、sub-rules、rule-set、script等功能
#可参考 https://github.com/MetaCubeX/Clash.Meta/blob/Meta/docs/config.yaml 或 https://lancellc.gitbook.io/clash/clash-config-file/an-example-configuration-file
#此处内容会被添加在配置文件的“proxy-group”模块的末尾与“rules”模块之前的位置
@ -601,10 +588,10 @@ EOF
#listeners:
EOF
echo -----------------------------------------------
echo -e "\033[32m已经创建自定义设定文件$clashdir/user.yaml \033[0m"
echo -e "\033[32m已经创建自定义设定文件$YAMLSDIR/user.yaml \033[0m"
echo -e "\033[33m可用于编写自定义的DNS等功能\033[0m"
echo -----------------------------------------------
echo -e "\033[32m已经创建自定义功能文件$clashdir/others.yaml \033[0m"
echo -e "\033[32m已经创建自定义功能文件$YAMLSDIR/others.yaml \033[0m"
echo -e "\033[33m可用于编写自定义的锚点、入站、proxy-providers、sub-rules、rule-set、script等功能\033[0m"
echo -----------------------------------------------
echo -e "Windows下请\n使用\033[33mWinSCP软件\033[0m进行编辑\033[0m"
@ -686,16 +673,16 @@ clashlink(){
fi
;;
3)
if [ ! -f $clashdir/config.yaml.bak ];then
if [ ! -f $YAMLSDIR/config.yaml.bak ];then
echo -----------------------------------------------
echo -e "\033[31m没有找到配置文件的备份\033[0m"
clashlink
else
echo -----------------------------------------------
echo -e 备份文件共有"\033[32m`wc -l < $clashdir/config.yaml.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $clashdir/config.yaml`\033[0m"行内容
echo -e 备份文件共有"\033[32m`wc -l < $YAMLSDIR/config.yaml.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < $YAMLSDIR/config.yaml`\033[0m"行内容
read -p "确认还原配置文件?此操作不可逆![1/0] > " res
if [ "$res" = '1' ]; then
mv $clashdir/config.yaml.bak $clashdir/config.yaml
mv $YAMLSDIR/config.yaml.bak $YAMLSDIR/config.yaml
echo -----------------------------------------------
echo -e "\033[32m配置文件已还原请手动重启clash服务\033[0m"
sleep 1
@ -1194,45 +1181,24 @@ setserver(){
echo -e "\033[30;47m切换ShellClash版本及更新源地址\033[0m"
echo -e "当前源地址:\033[4;32m$update_url\033[0m"
echo -----------------------------------------------
echo -e " 1 \033[33m稳定版\033[0m&Jsdelivr-CDN源"
echo -e " 2 \033[33m稳定版\033[0m&Github源(须clash服务启用)"
echo -e " 3 \033[32m公测版\033[0m&Github源(须clash服务启用)"
echo -e " 4 \033[32m公测版\033[0m&ShellClash私人源"
echo -e " 5 \033[32m公测版\033[0m&Jsdelivr-CDN源(推荐)"
echo -e " 7 \033[31m内测版\033[0m(请加TG讨论组:\033[4;36mhttps://t.me/ShellClash\033[0m)"
echo -e " 8 自定义源地址(用于本地源或自建源)"
echo -e " 9 \033[31m版本回退\033[0m"
grep -aE '^1|^2' $clashdir/configs/servers.list | awk '{print " "NR" "$4" "$2}'
echo -----------------------------------------------
echo -e " a 自定义源地址(用于本地源或自建源)"
echo -e " b \033[31m版本回退\033[0m"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
errornum
elif [ "$num" = 1 ]; then
release_url='https://fastly.jsdelivr.net/gh/juewuy/ShellClash'
case $num in
[0-99])
release_type=$(grep -aE '^1|^2' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $4}')
if [ "release_type" = "稳定版" ];then
release_url=$(grep -aE '^1' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $3}')
else
update_url=$(grep -aE '^1|^2' $clashdir/configs/servers.list | sed -n ""$num"p" | awk '{print $3}')
unset release_url
fi
saveserver
elif [ "$num" = 2 ]; then
release_url='https://raw.githubusercontent.com/juewuy/ShellClash'
saveserver
elif [ "$num" = 3 ]; then
update_url='https://raw.githubusercontent.com/juewuy/ShellClash/master'
release_url=''
saveserver
elif [ "$num" = 4 ]; then
update_url='https://gh.jwsc.eu.org/master'
release_url=''
saveserver
elif [ "$num" = 5 ]; then
update_url='https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master'
release_url=''
saveserver
elif [ "$num" = 6 ]; then
update_url='https://raw.staticdn.net/juewuy/ShellClash/master'
release_url=''
saveserver
elif [ "$num" = 7 ]; then
update_url='http://t.jwsc.eu.org'
release_url=''
saveserver
elif [ "$num" = 8 ]; then
;;
a)
echo -----------------------------------------------
read -p "请输入个人源路径 > " update_url
if [ -z "$update_url" ];then
@ -1240,9 +1206,10 @@ setserver(){
echo -e "\033[31m取消输入返回上级菜单\033[0m"
else
saveserver
release_url=''
unset release_url
fi
elif [ "$num" = 9 ]; then
;;
b)
echo -----------------------------------------------
echo -e "\033[33m如无法连接请务必先启用clash服务\033[0m"
$clashdir/start.sh webget $tmpdir/clashrelease https://raw.githubusercontent.com/juewuy/ShellClash/master/bin/release_version echooff rediroff 2>$tmpdir/clashrelease
@ -1256,15 +1223,17 @@ setserver(){
release_version=$(cat $tmpdir/clashrelease | awk '{print $1}' | sed -n "$num"p)
update_url="https://raw.githubusercontent.com/juewuy/ShellClash/$release_version"
saveserver
release_url=''
unset release_url
else
echo -----------------------------------------------
echo -e "\033[31m输入有误请重新输入\033[0m"
fi
rm -rf $tmpdir/clashrelease
else
;;
*)
errornum
fi
;;
esac
}
#检查更新
checkupdate(){
@ -1613,7 +1582,7 @@ testcommand(){
exit;
elif [ "$num" = 5 ]; then
echo -----------------------------------------------
sed -n '1,40p' $clashdir/config.yaml
sed -n '1,40p' $YAMLSDIR/config.yaml
echo -----------------------------------------------
exit;
elif [ "$num" = 6 ]; then

View File

@ -230,7 +230,21 @@ fi
rm -rf /tmp/*lash*gz
rm -rf /tmp/SC_tmp
#转换&清理旧版本文件
mkdir -p $clashdir/yamls
mkdir -p $clashdir/configs
mkdir -p $clashdir/tools
for file in config.yaml config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do
mv -f $clashdir/$file $clashdir/yamls/$file
done
for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do
mv -f $clashdir/$file $clashdir/configs/$file
done
mv -f $clashdir/mark $clashdir/configs/ShellClash.cfg
for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do
mv -f $clashdir/$file $clashdir/tools/$file
done
for file in log clash.service mark? mark.bak;do
rm -rf $clashdir/$file
done
sleep 1
echo -e "\033[32m脚本初始化完成,请输入\033[30;47m clash \033[0;33m命令开始使用\033[0m"

View File

@ -21,8 +21,8 @@ autoSSH(){
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1
nvram commit &> /dev/null
#备份还原SSH秘钥
[ -f $clashdir/dropbear_rsa_host_key ] && ln -sf $clashdir/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
[ -f $clashdir/authorized_keys ] && ln -sf $clashdir/authorized_keys /etc/dropbear/authorized_keys
[ -f $clashdir/configs/dropbear_rsa_host_key ] && ln -sf $clashdir/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
[ -f $clashdir/configs/authorized_keys ] && ln -sf $clashdir/configs/authorized_keys /etc/dropbear/authorized_keys
#自动清理升级备份文件夹
rm -rf /data/etc_bak
}
@ -34,7 +34,7 @@ tunfix(){
mkdir -p /tmp/overlay/work
mount -o noatime,lowerdir=${ko_dir},upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" ${ko_dir}
#将tun.ko链接到lib
ln -s $clashdir/tun.ko ${ko_dir}/tun.ko
ln -s $clashdir/configs/tun.ko ${ko_dir}/tun.ko
}
init(){
#等待启动完成
@ -57,7 +57,7 @@ init(){
#启动服务
if [ ! -f $clashdir/.dis_startup ]; then
#AX6S/AX6000修复tun功能
[ -f $clashdir/tun.ko ] && tunfix
[ -f $clashdir/configs/tun.ko ] && tunfix
#启动服务
/etc/init.d/clash start
/etc/init.d/clash enable

View File

@ -6,11 +6,12 @@
[ -d "/jffs/clash" ] && clashdir=/jffs/clash
[ -z "$clashdir" ] && clashdir=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}')
[ -z "$clashdir" ] && clashdir=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}')
tmpdir=/tmp/clash_$USER && [ ! -f $tmpdir ] && mkdir -p $tmpdir
CFG_PATH=$clashdir/configs/ShellClash.cfg
TMPDIR=/tmp/clash_$USER && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
#脚本内部工具
getconfig(){
#加载配置文件
source $clashdir/mark &> /dev/null
source $CFG_PATH &> /dev/null
#默认设置
[ -z "$bindir" ] && bindir=$clashdir
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
@ -32,6 +33,8 @@ getconfig(){
[ -z "$common_ports" ] && common_ports=已开启
[ -z "$multiport" ] && multiport='22,53,80,123,143,194,443,465,587,853,993,995,5222,8080,8443'
[ "$common_ports" = "已开启" ] && ports="-m multiport --dports $multiport"
#yaml
[ -z "$yaml" ] && yaml=$clashdir/yamls/config.yaml
}
setconfig(){
#参数1代表变量名参数2代表变量值,参数3即文件路径
@ -54,8 +57,8 @@ logger(){
#$1日志内容$2显示颜色$3是否推送
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m"
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
echo $log_text >> $tmpdir/ShellClash_log
[ "$(wc -l $tmpdir/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' $tmpdir/ShellClash_log
echo $log_text >> $TMPDIR/ShellClash_log
[ "$(wc -l $TMPDIR/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' $TMPDIR/ShellClash_log
[ -z "$3" ] && {
getconfig
[ -n "$device_name" ] && log_text="$log_text($device_name)"
@ -110,7 +113,7 @@ croncmd(){
}
cronset(){
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
tmpcron=$tmpdir/cron_$USER
tmpcron=$TMPDIR/cron_$USER
croncmd -l > $tmpcron
sed -i "/$1/d" $tmpcron
sed -i '/^$/d' $tmpcron
@ -133,7 +136,7 @@ put_save(){
fi
}
mark_time(){
echo `date +%s` > $tmpdir/clash_start_time
echo `date +%s` > $TMPDIR/clash_start_time
}
getlanip(){
i=1
@ -141,7 +144,7 @@ getlanip(){
host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -v 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' ) #ipv4局域网网段
host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段
[ -n "$host_ipv4" -a -n "$host_ipv6" ] && break
[ -f $tmpdir/ShellClash_log ] && break
[ -f $TMPDIR/ShellClash_log ] && break
sleep 2 && i=$((i+1))
done
#添加自定义ipv4局域网网段
@ -160,31 +163,12 @@ getlanip(){
getyaml(){
[ -z "$rule_link" ] && rule_link=1
[ -z "$server_link" ] && server_link=1
#前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF
https://api.dler.io
https://sub.d1.mk
https://sub.xeton.dev
https://v.id9.cc
https://sub.maoxiongnet.com
http://sub2.jwsc.eu.org
EOF`
Config=`sed -n ""$rule_link"p"<<EOF
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash.ini
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Mini.ini
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Block.ini
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Nano.ini
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full.ini
https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full_Block.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiCountry.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_BackCN.ini
EOF`
Server=$(grep -aE '^3|^4' $clashdir/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
[ -n "$(echo $Url | grep -oE 'vless:|hysteria:')" ] && Server=$(grep -aE '^4' $clashdir/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
[ "$retry" = 4 ] && Server=$(grep -aE '^499' $clashdir/servers.list | awk '{print $3}')
Config=$(grep -aE '^5' $clashdir/servers.list | sed -n ""$server_link"p" | awk '{print $3}')
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ];then
[ -n "$(echo $Url | grep -oE 'vless:')" -a -z "$retry" ] && Server='https://sub.d1.mk'
[ -n "$(echo $Url | grep -oE 'hysteria:')" -a -z "$retry" ] && Server='https://sub.jwsc.eu.org'
Https="$Server/sub?target=clash&insert=true&new_name=true&scv=true&udp=true&exclude=$exclude&include=$include&url=$Url&config=$Config"
url_type=true
fi
@ -194,8 +178,7 @@ EOF`
echo -e "链接地址为:\033[4;32m$Https\033[0m"
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
#获取在线yaml文件
yaml=$clashdir/config.yaml
yamlnew=$tmpdir/clash_config_$USER.yaml
yamlnew=$TMPDIR/clash_config_$USER.yaml
rm -rf $yamlnew
$0 webget $yamlnew $Https
if [ "$?" = "1" ];then
@ -208,14 +191,13 @@ EOF`
else
if [ "$retry" = 4 ];then
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
echo -e "\033[32m你也可以尝试使用浏览器下载配置文件后使用WinSCP手动上传到$tmpdir目录\033[0m"
echo -e "\033[32m你也可以尝试使用浏览器下载配置文件后使用WinSCP手动上传到$TMPDIR目录\033[0m"
exit 1
elif [ "$retry" = 3 ];then
retry=4
logger "配置文件获取失败将尝试使用http协议备用服务器获取" 31
echo -e "\033[32m如担心数据安全请在5s内使用【ctrl+c】退出\033[0m"
sleep 5
server_link=6
echo -e "\033[32m如担心数据安全请在3s内使用【Ctrl+c】退出\033[0m"
sleep 3
Https=""
getyaml
else
@ -262,12 +244,12 @@ EOF`
fi
#检测并去除无效节点组
[ -n "$url_type" ] && ckcmd xargs && {
cat $yamlnew | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > $tmpdir/clash_proxies_$USER
cat $yamlnew | sed '/^rules:/,$d' | grep -A 15 "\- name:" | xargs | sed 's/- name: /\n/g' | sed 's/ type: .*proxies: /#/g' | sed 's/- //g' | grep -E '#DIRECT $|#DIRECT$' | awk -F '#' '{print $1}' > $TMPDIR/clash_proxies_$USER
while read line ;do
sed -i "/- $line/d" $yamlnew
sed -i "/- name: $line/,/- DIRECT/d" $yamlnew
done < $tmpdir/clash_proxies_$USER
rm -rf $tmpdir/clash_proxies_$USER
done < $TMPDIR/clash_proxies_$USER
rm -rf $TMPDIR/clash_proxies_$USER
}
#使用核心内置test功能检测
if [ -x $bindir/clash ];then
@ -294,14 +276,9 @@ modify_yaml(){
[ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5'
[ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4'
[ -z "$skip_cert" ] && skip_cert=已开启
#默认fake-ip过滤列表
fake_ft_df='"*.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","*.sgcc.com.cn","*.alicdn.com","*.aliyuncs.com"'
lan='allow-lan: true'
log='log-level: info'
[ "$ipv6_support" = "已开启" ] && ipv6='ipv6: true' || ipv6='ipv6: false'
[ "$ipv6_dns" = "已开启" ] && dns_v6='ipv6: true' || dns_v6='ipv6: false'
[ "$ipv6_dns" = "已开启" ] && dns_v6='true' || dns_v6='false'
external="external-controller: 0.0.0.0:$db_port"
[ -d $clashdir/ui ] && db_ui=ui
if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ];then
[ "$clashcore" = 'clash.meta' ] && tun_meta=', device: utun, auto-route: false'
tun="tun: {enable: true, stack: system$tun_meta}"
@ -314,128 +291,64 @@ modify_yaml(){
find_process='find-process-mode: "off"'
}
#dns配置
[ -z "$(cat $clashdir/user.yaml 2>/dev/null | grep '^dns:')" ] && {
[ "$clashcore" = 'clash.meta' ] && dns_default_meta=', https://1.0.0.1/dns-query, https://223.5.5.5/dns-query'
dns_default="114.114.114.114, 223.5.5.5$dns_default_meta"
if [ -f $clashdir/fake_ip_filter ];then
while read line;do
fake_ft_ad=$fake_ft_ad,\"$line\"
done < $clashdir/fake_ip_filter
fi
[ -z "$(cat $clashdir/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && {
[ "$clashcore" = 'clash.meta' ] && dns_default_meta='- https://223.5.5.5/dns-query'
cat > $TMPDIR/dns.yaml <<EOF
dns:
enable: true
listen: 0.0.0.0:$dns_port
use-hosts: true
ipv6: $dns_v6
default-nameserver:
- 114.114.114.114
- 223.5.5.5
$dns_default_meta
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
EOF
if [ "$dns_mod" = "fake-ip" ];then
dns='dns: {enable: true, '$dns_v6', 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: ['${fake_ft_df}${fake_ft_ad}'], default-nameserver: ['$dns_default', 127.0.0.1:53], nameserver: ['$dns_nameserver', 127.0.0.1:53], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
cat $clashdir/configs/fake_ip_filter.list $clashdir/configs/fake_ip_filter | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml
else
dns='dns: {enable: true, '$dns_v6', listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, default-nameserver: ['$dns_default', 127.0.0.1:53], nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
echo " - '+.*'" >> $TMPDIR/dns.yaml
fi
}
cat >> $TMPDIR/dns.yaml <<EOF
nameserver: [$dns_nameserver]
fallback: [$dns_fallback]
fallback-filter:
geoip: true
EOF
[ -s $clashdir/configs/fallback_filter.list ] && {
echo " domain:" >> $TMPDIR/dns.yaml
cat $clashdir/configs/fallback_filter.list | grep '\.' | sed "s/^/ - '/" | sed "s/$/'/" >> $TMPDIR/dns.yaml
}
}
#域名嗅探配置
[ "$sniffer" = "已启用" ] && [ "$clashcore" = "clash.meta" ] && sniffer_set="sniffer: {enable: true, skip-domain: [Mijia Cloud], sniff: {tls: {ports: [443, 8443]}, http: {ports: [80, 8080-8880]}}}"
[ "$clashcore" = "clashpre" ] && [ "$dns_mod" = "redir_host" ] && exper="experimental: {ignore-resolve-fail: true, interface-name: en0, sniff-tls-sni: true}"
#设置目录
yaml=$clashdir/config.yaml
#分割配置文件
yaml_char='proxies proxy-groups proxy-providers rules rule-providers'
for char in $yaml_char;do
sed -n "/^$char:/,/^[a-z]/ { /^[a-z]/d; p; }" $yaml > $tmpdir/${char}.yaml
done
#跳过本地tls证书验证
[ "$skip_cert" = "已开启" ] && sed -i 's/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxies.yaml || \
sed -i 's/skip-cert-verify: true/skip-cert-verify: false/' $tmpdir/proxies.yaml
#插入自定义策略组
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $tmpdir/proxy-groups.yaml
sed -i "/#自定义策略组/d" $tmpdir/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/proxy-groups.yaml 2>/dev/null)" ] && {
#获取空格数
space_name=$(grep -E '^ *- name: ' $tmpdir/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
space_proxy=$(grep -A 1 'proxies:$' $tmpdir/proxy-groups.yaml | grep -E '^ *- ' | head -n 1 | grep -oE '^ *')
#合并自定义策略组到proxy-groups.yaml
cat $clashdir/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > $tmpdir/proxy-groups_add.yaml
cat $tmpdir/proxy-groups.yaml >> $tmpdir/proxy-groups_add.yaml
mv -f $tmpdir/proxy-groups_add.yaml $tmpdir/proxy-groups.yaml
oldIFS="$IFS"
grep "\- name: " $clashdir/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group
new_group=$(echo $line | grep -Eo '^ *- name:.*#' | cut -d'#' -f1 | sed 's/.*name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#"
for name in $proxy_groups; do
line_a=$(grep -n "\- name: $name" $tmpdir/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
[ -n "$line_a" ] && {
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${new_group} #自定义策略组" $tmpdir/proxy-groups.yaml
}
done
IFS="$oldIFS"
done
}
#插入自定义代理
sed -i "/#自定义代理/d" $tmpdir/proxies.yaml
sed -i "/#自定义代理/d" $tmpdir/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/proxies.yaml 2>/dev/null)" ] && {
space_proxy=$(cat $tmpdir/proxies.yaml | grep -E '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数
cat $clashdir/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $tmpdir/proxies.yaml #插入节点
oldIFS="$IFS"
cat $clashdir/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group
proxy_name=$(echo $line | grep -Eo 'name: .+, ' | cut -d',' -f1 | sed 's/name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#"
for name in $proxy_groups; do
line_a=$(grep -n "\- name: $name" $tmpdir/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
[ -n "$line_a" ] && {
line_b=$(grep -A 8 "\- name: $name" $tmpdir/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
space=$(sed -n "$((line_c + 1))p" $tmpdir/proxy-groups.yaml | grep -oE '^ *') #获取空格数
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${proxy_name} #自定义代理" $tmpdir/proxy-groups.yaml
}
done
IFS="$oldIFS"
done
}
#节点绕过功能支持
sed -i "/#节点绕过/d" $tmpdir/rules.yaml
[ "$proxies_bypass" = "已启用" ] && {
cat $tmpdir/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT #节点绕过|g' >> $tmpdir/proxies_bypass
cat $tmpdir/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $tmpdir/proxies_bypass
cat $tmpdir/rules.yaml >> $tmpdir/proxies_bypass
mv -f $tmpdir/proxies_bypass $tmpdir/rules.yaml
}
#插入自定义规则
sed -i "/#自定义规则/d" $tmpdir/rules.yaml
[ -f $clashdir/rules.yaml ] && {
cat $clashdir/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $tmpdir/rules.add
cat $tmpdir/rules.yaml >> $tmpdir/rules.add
mv -f $tmpdir/rules.add $tmpdir/rules.yaml
}
#对齐rules中的空格
sed -i 's/^ *-/ -/g' $tmpdir/rules.yaml
#添加配置
###################################
cat > $tmpdir/set.yaml <<EOF
#生成set.yaml
cat > $TMPDIR/set.yaml <<EOF
mixed-port: $mix_port
redir-port: $redir_port
tproxy-port: $tproxy_port
authentication: ["$authentication"]
$lan
mode: $mode
$log
allow-lan: true
mode: Rule
log-level: info
$ipv6
external-controller: :$db_port
external-ui: $db_ui
external-ui: ui
secret: $secret
$tun
$exper
$dns
$sniffer_set
store-selected: $restore
$find_process
EOF
###################################
#读取本机hosts并生成配置文件
if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -E '^hosts:' $clashdir/user.yaml 2>/dev/null)" ];then
if [ "$hosts_opt" != "未启用" ] && [ -z "$(grep -aE '^hosts:' $clashdir/user.yaml 2>/dev/null)" ];then
#NTP劫持
cat >> $tmpdir/hosts.yaml <<EOF
cat >> $TMPDIR/hosts.yaml <<EOF
hosts:
'time.android.com': 203.107.6.88
'time.facebook.com': 203.107.6.88
@ -448,41 +361,121 @@ EOF
[ -z "$(echo "$line" | grep -oE '^#')" ] && \
hosts_ip=$(echo $line | awk '{print $1}') && \
hosts_domain=$(echo $line | awk '{print $2}') && \
[ -z "$(cat $tmpdir/hosts.yaml | grep -oE "$hosts_domain")" ] && \
echo " '$hosts_domain': $hosts_ip" >> $tmpdir/hosts.yaml
[ -z "$(cat $TMPDIR/hosts.yaml | grep -oE "$hosts_domain")" ] && \
echo " '$hosts_domain': $hosts_ip" >> $TMPDIR/hosts.yaml
done < $sys_hosts
fi
fi
#分割配置文件
yaml_char='proxies proxy-groups proxy-providers rules rule-providers'
for char in $yaml_char;do
sed -n "/^$char:/,/^[a-z]/ { /^[a-z]/d; p; }" $yaml > $TMPDIR/${char}.yaml
done
#跳过本地tls证书验证
[ "$skip_cert" = "已开启" ] && sed -i 's/skip-cert-verify: false/skip-cert-verify: true/' $TMPDIR/proxies.yaml || \
sed -i 's/skip-cert-verify: true/skip-cert-verify: false/' $TMPDIR/proxies.yaml
#插入自定义策略组
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml
sed -i "/#自定义策略组/d" $TMPDIR/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/proxy-groups.yaml 2>/dev/null)" ] && {
#获取空格数
space_name=$(grep -aE '^ *- name: ' $TMPDIR/proxy-groups.yaml | head -n 1 | grep -oE '^ *')
space_proxy=$(grep -A 1 'proxies:$' $TMPDIR/proxy-groups.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *')
#合并自定义策略组到proxy-groups.yaml
cat $clashdir/proxy-groups.yaml | sed "/^#/d" | sed "s/#.*//g" | sed '1i\ #自定义策略组开始' | sed '$a\ #自定义策略组结束' | sed "s/^ */${space_name} /g" | sed "s/^ *- /${space_proxy}- /g" | sed "s/^ *- name: /${space_name}- name: /g" > $TMPDIR/proxy-groups_add.yaml
cat $TMPDIR/proxy-groups.yaml >> $TMPDIR/proxy-groups_add.yaml
mv -f $TMPDIR/proxy-groups_add.yaml $TMPDIR/proxy-groups.yaml
oldIFS="$IFS"
grep "\- name: " $clashdir/proxy-groups.yaml | sed "/^#/d" | while read line;do #将自定义策略组插入现有的proxy-group
new_group=$(echo $line | grep -Eo '^ *- name:.*#' | cut -d'#' -f1 | sed 's/.*name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#"
for name in $proxy_groups; do
line_a=$(grep -n "\- name: $name" $TMPDIR/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
[ -n "$line_a" ] && {
line_b=$(grep -A 8 "\- name: $name" $TMPDIR/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
space=$(sed -n "$((line_c + 1))p" $TMPDIR/proxy-groups.yaml | grep -oE '^ *') #获取空格数
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${new_group} #自定义策略组" $TMPDIR/proxy-groups.yaml
}
done
IFS="$oldIFS"
done
}
#插入自定义代理
sed -i "/#自定义代理/d" $TMPDIR/proxies.yaml
sed -i "/#自定义代理/d" $TMPDIR/proxy-groups.yaml
[ -n "$(grep -Ev '^#' $clashdir/proxies.yaml 2>/dev/null)" ] && {
space_proxy=$(cat $TMPDIR/proxies.yaml | grep -aE '^ *- ' | head -n 1 | grep -oE '^ *') #获取空格数
cat $clashdir/proxies.yaml | sed "s/^ *- /${space_proxy}- /g" | sed "/^#/d" | sed "/^ *$/d" | sed 's/#.*/ #自定义代理/g' >> $TMPDIR/proxies.yaml #插入节点
oldIFS="$IFS"
cat $clashdir/proxies.yaml | sed "/^#/d" | while read line;do #将节点插入proxy-group
proxy_name=$(echo $line | grep -Eo 'name: .+, ' | cut -d',' -f1 | sed 's/name: //g')
proxy_groups=$(echo $line | grep -Eo '#.*' | sed "s/#//" )
IFS="#"
for name in $proxy_groups; do
line_a=$(grep -n "\- name: $name" $TMPDIR/proxy-groups.yaml | awk -F: '{print $1}') #获取group行号
[ -n "$line_a" ] && {
line_b=$(grep -A 8 "\- name: $name" $TMPDIR/proxy-groups.yaml | grep -n "proxies:$" | awk -F: '{print $1}') #获取proxies行号
line_c=$((line_a + line_b - 1)) #计算需要插入的行号
space=$(sed -n "$((line_c + 1))p" $TMPDIR/proxy-groups.yaml | grep -oE '^ *') #获取空格数
[ "$line_c" -gt 2 ] && sed -i "${line_c}a\\${space}- ${proxy_name} #自定义代理" $TMPDIR/proxy-groups.yaml
}
done
IFS="$oldIFS"
done
}
#节点绕过功能支持
sed -i "/#节点绕过/d" $TMPDIR/rules.yaml
[ "$proxies_bypass" = "已启用" ] && {
cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '!a[$0]++' | sed 's/^/\ -\ IP-CIDR,/g' | sed 's|$|/32,DIRECT #节点绕过|g' >> $TMPDIR/proxies_bypass
cat $TMPDIR/proxies.yaml | sed '/^proxy-/,$d' | sed '/^rule-/,$d' | grep -v '^\s*#' | grep -vE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'| awk '!a[$0]++' | sed 's/^/\ -\ DOMAIN,/g' | sed 's/$/,DIRECT #节点绕过/g' >> $TMPDIR/proxies_bypass
cat $TMPDIR/rules.yaml >> $TMPDIR/proxies_bypass
mv -f $TMPDIR/proxies_bypass $TMPDIR/rules.yaml
}
#插入自定义规则
sed -i "/#自定义规则/d" $TMPDIR/rules.yaml
[ -f $clashdir/rules.yaml ] && {
cat $clashdir/rules.yaml | sed "/^#/d" | sed '$a\' | sed 's/$/ #自定义规则/g' > $TMPDIR/rules.add
cat $TMPDIR/rules.yaml >> $TMPDIR/rules.add
mv -f $TMPDIR/rules.add $TMPDIR/rules.yaml
}
#对齐rules中的空格
sed -i 's/^ *-/ -/g' $TMPDIR/rules.yaml
#合并文件
[ -s $clashdir/user.yaml ] && yaml_user=$clashdir/user.yaml
[ -s $tmpdir/hosts.yaml ] && yaml_hosts=$tmpdir/hosts.yaml
[ -s $tmpdir/others.yaml ] && yaml_others=$clashdir/others.yaml
[ -s $clashdir/user.yaml ] && {
yaml_user=$clashdir/user.yaml
#set和user去重,且优先使用user.yaml
cp -f $TMPDIR/set.yaml $TMPDIR/set_bak.yaml
for char in mode allow-lan log-level tun experimental interface-name dns store-selected;do
[ -n "$(grep -E "^$char" $yaml_user)" ] && sed -i "/^$char/d" $TMPDIR/set.yaml
done
}
[ -s $TMPDIR/dns.yaml ] && yaml_dns=$TMPDIR/dns.yaml
[ -s $TMPDIR/hosts.yaml ] && yaml_hosts=$TMPDIR/hosts.yaml
[ -s $TMPDIR/others.yaml ] && yaml_others=$clashdir/others.yaml
yaml_add=
for char in $yaml_char;do #将额外配置文件合并
[ -s $tmpdir/${char}.yaml ] && {
sed -i "1i\\${char}:" $tmpdir/${char}.yaml
yaml_add="$yaml_add $tmpdir/${char}.yaml"
[ -s $TMPDIR/${char}.yaml ] && {
sed -i "1i\\${char}:" $TMPDIR/${char}.yaml
yaml_add="$yaml_add $TMPDIR/${char}.yaml"
}
done
cut -c 1- $tmpdir/set.yaml $yaml_hosts $yaml_user $yaml_others $yaml_add > $tmpdir/config.yaml
#合并完整配置文件
cut -c 1- $TMPDIR/set.yaml $yaml_dns $yaml_hosts $yaml_user $yaml_others $yaml_add > $TMPDIR/config.yaml
#测试自定义配置文件
$bindir/clash -t -d $bindir -f $tmpdir/config.yaml >/dev/null
$bindir/clash -t -d $bindir -f $TMPDIR/config.yaml >/dev/null
if [ "$?" != 0 ];then
logger "$($bindir/clash -t -d $bindir -f $tmpdir/config.yaml | grep -Eo 'error.*=.*')" 31
logger "$($bindir/clash -t -d $bindir -f $TMPDIR/config.yaml | grep -Eo 'error.*=.*')" 31
logger "自定义配置文件校验失败!将使用基础配置文件启动!" 33
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $tmpdir/proxy-groups.yaml
cut -c 1- $tmpdir/set.yaml $yaml_add > $tmpdir/config.yaml
sed -i "/#自定义/d" $tmpdir/config.yaml
sed -i "/#自定义策略组开始/,/#自定义策略组结束/d" $TMPDIR/proxy-groups.yaml
mv -f $TMPDIR/set_bak.yaml $TMPDIR/set.yaml &>/dev/null
#合并基础配置文件
cut -c 1- $TMPDIR/set.yaml $yaml_dns $yaml_add > $TMPDIR/config.yaml
sed -i "/#自定义/d" $TMPDIR/config.yaml
fi
#存档
# if [ "$clashdir" = "$bindir" ];then
# cmp -s $tmpdir/config.yaml $yaml >/dev/null 2>&1
# [ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml
# elif [ "$tmpdir" != "$bindir" ];then
# mv -f $tmpdir/config.yaml $bindir/config.yaml
# fi
#清理缓存
for char in $yaml_char set hosts;do
rm -f $tmpdir/${char}.yaml
for char in $yaml_char set set_bak dns hosts;do
rm -f $TMPDIR/${char}.yaml
done
}
#设置路由规则
@ -497,10 +490,10 @@ cn_ip_route(){
fi
}
[ -f $bindir/cn_ip.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && {
echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > $tmpdir/cn_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> $tmpdir/cn_$USER.ipset
echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > $TMPDIR/cn_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> $TMPDIR/cn_$USER.ipset
ipset -! flush cn_ip 2>/dev/null
ipset -! restore < $tmpdir/cn_$USER.ipset
ipset -! restore < $TMPDIR/cn_$USER.ipset
rm -rf cn_$USER.ipset
}
}
@ -516,10 +509,10 @@ cn_ipv6_route(){
}
[ -f $bindir/cn_ipv6.txt -a -z "$(echo $redir_mod|grep 'Nft')" ] && {
#ipv6
echo "create cn_ip6 hash:net family inet6 hashsize 1024 maxelem 65536" > $tmpdir/cn6_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' $bindir/cn_ipv6.txt >> $tmpdir/cn6_$USER.ipset
echo "create cn_ip6 hash:net family inet6 hashsize 1024 maxelem 65536" > $TMPDIR/cn6_$USER.ipset
awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' $bindir/cn_ipv6.txt >> $TMPDIR/cn6_$USER.ipset
ipset -! flush cn_ip6 2>/dev/null
ipset -! restore < $tmpdir/cn6_$USER.ipset
ipset -! restore < $TMPDIR/cn6_$USER.ipset
rm -rf cn6_$USER.ipset
}
}
@ -535,12 +528,12 @@ start_redir(){
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \
iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
iptables -t nat -A clash -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -561,12 +554,12 @@ start_redir(){
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \
ip6tables -t nat -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
ip6tables -t nat -A clashv6 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -586,12 +579,12 @@ start_ipt_dns(){
}
#设置dns转发
iptables -t nat -N clash_dns
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
iptables -t nat -A clash_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done
iptables -t nat -A clash_dns -p udp -j REDIRECT --to $dns_port
@ -600,12 +593,12 @@ start_ipt_dns(){
#ipv6DNS
if [ -n "$(lsmod | grep 'ip6table_nat')" -a -n "$(lsmod | grep 'xt_nat')" ];then
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
ip6tables -t nat -A clashv6_dns -p udp -m mac --mac-source $mac -j REDIRECT --to $dns_port
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN
done
ip6tables -t nat -A clashv6_dns -p udp -j REDIRECT --to $dns_port
@ -633,12 +626,12 @@ start_tproxy(){
iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#tcp&udp分别进代理链
tproxy_set(){
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
iptables -t mangle -A clash -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -671,14 +664,14 @@ start_tproxy(){
ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#tcp&udp分别进代理链
tproxy_set6(){
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
#mac白名单
for mac in $(cat $clashdir/mac); do
for mac in $(cat $clashdir/configs/mac); do
ip6tables -t mangle -A clashv6 -p $1 -m mac --mac-source $mac -j TPROXY --on-port $tproxy_port --tproxy-mark $fwmark
done
else
#mac黑名单
for mac in $(cat $clashdir/mac); do
for mac in $(cat $clashdir/configs/mac); do
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -769,12 +762,12 @@ start_tun(){
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && \
iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN 2>/dev/null
#局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
iptables -t mangle -A clash -m mac --mac-source $mac -j MARK --set-mark $fwmark
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -798,12 +791,12 @@ start_tun(){
[ "$dns_mod" = "redir_host" -a "$cn_ipv6_route" = "已开启" ] && \
ip6tables -t mangle -A clashv6 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null
#局域网设备过滤
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
for mac in $(cat $clashdir/mac); do #mac白名单
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/configs/mac)" ];then
for mac in $(cat $clashdir/configs/mac); do #mac白名单
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j MARK --set-mark $fwmark
done
else
for mac in $(cat $clashdir/mac); do #mac黑名单
for mac in $(cat $clashdir/configs/mac); do #mac黑名单
ip6tables -t mangle -A clashv6 -m mac --mac-source $mac -j RETURN
done
#仅代理本机局域网网段流量
@ -833,8 +826,8 @@ start_nft(){
}
[ -n "$(echo $redir_mod|grep Nft)" ] && {
#过滤局域网设备
[ -n "$(cat $clashdir/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/mac)
[ -n "$(cat $clashdir/configs/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/configs/mac)
[ "$macfilter_type" = "黑名单" ] && \
nft add rule inet shellclash prerouting ether saddr {$MAC} return || \
nft add rule inet shellclash prerouting ether saddr != {$MAC} return
@ -902,8 +895,8 @@ start_nft(){
start_nft_dns(){
nft add chain inet shellclash dns { type nat hook prerouting priority -100 \; }
#过滤局域网设备
[ -n "$(cat $clashdir/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/mac)
[ -n "$(cat $clashdir/configs/mac)" ] && {
MAC=$(awk '{printf "%s, ",$1}' $clashdir/configs/mac)
[ "$macfilter_type" = "黑名单" ] && \
nft add rule inet shellclash dns ether saddr {$MAC} return || \
nft add rule inet shellclash dns ether saddr != {$MAC} return
@ -979,7 +972,7 @@ stop_firewall(){
iptables -t mangle -F clash 2> /dev/null
iptables -t mangle -X clash 2> /dev/null
#公网访问
for ip in $host_ipv4 $local_ipv4;do
for ip in $host_ipv4 $local_ipv4 $reserve_ipv4;do
iptables -D INPUT -p tcp -s $ip --dport $mix_port -j ACCEPT 2> /dev/null
iptables -D INPUT -p tcp -s $ip --dport $db_port -j ACCEPT 2> /dev/null
done
@ -1045,19 +1038,19 @@ stop_firewall(){
#面板配置保存相关
web_save(){
#使用get_save获取面板节点设置
get_save http://127.0.0.1:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' > $tmpdir/clash_web_check_$USER
get_save http://127.0.0.1:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -aE '^"all".*"Selector"' > $TMPDIR/clash_web_check_$USER
while read line ;do
def=$(echo $line | awk -F "[[,]" '{print $2}')
now=$(echo $line | grep -oE '"now".*",' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/,//g')
[ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> $tmpdir/clash_web_save_$USER
done < $tmpdir/clash_web_check_$USER
rm -rf $tmpdir/clash_web_check_$USER
[ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g' | sed 's/"type":.*//g' | sed 's/"//g' >> $TMPDIR/clash_web_save_$USER
done < $TMPDIR/clash_web_check_$USER
rm -rf $TMPDIR/clash_web_check_$USER
#对比文件,如果有变动且不为空则写入磁盘,否则清除缓存
if [ -s $tmpdir/clash_web_save_$USER ];then
compare $tmpdir/clash_web_save_$USER $clashdir/web_save
[ "$?" = 0 ] && rm -rf $tmpdir/clash_web_save_$USER || mv -f $tmpdir/clash_web_save_$USER $clashdir/web_save
if [ -s $TMPDIR/clash_web_save_$USER ];then
compare $TMPDIR/clash_web_save_$USER $clashdir/configs/web_save
[ "$?" = 0 ] && rm -rf $TMPDIR/clash_web_save_$USER || mv -f $TMPDIR/clash_web_save_$USER $clashdir/configs/web_save
else
echo > $clashdir/web_save
echo > $clashdir/configs/web_save
fi
}
web_restore(){
@ -1074,11 +1067,11 @@ web_restore(){
i=$((i+1))
done
#发送数据
num=$(cat $clashdir/web_save | wc -l)
num=$(cat $clashdir/configs/web_save | wc -l)
i=1
while [ "$i" -le "$num" ];do
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $clashdir/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save)
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $clashdir/configs/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/configs/web_save)
put_save http://127.0.0.1:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
i=$((i+1))
done
@ -1089,7 +1082,7 @@ catpac(){
[ -n "$host" ] && host_pac=$host
[ -z "$host_pac" ] && host_pac=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
[ -z "$host_pac" ] && host_pac=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
cat > $tmpdir/clash_pac <<EOF
cat > $TMPDIR/clash_pac <<EOF
//如看见此处内容,请重新安装本地面板!
//之后返回上一级页面,清理浏览器缓存并刷新页面!
function FindProxyForURL(url, host) {
@ -1108,8 +1101,8 @@ function FindProxyForURL(url, host) {
return "PROXY $host_pac:$mix_port; DIRECT; SOCKS5 $host_pac:$mix_port"
}
EOF
compare $tmpdir/clash_pac $bindir/ui/pac
[ "$?" = 0 ] && rm -rf $tmpdir/clash_pac || mv -f $tmpdir/clash_pac $bindir/ui/pac
compare $TMPDIR/clash_pac $bindir/ui/pac
[ "$?" = 0 ] && rm -rf $TMPDIR/clash_pac || mv -f $TMPDIR/clash_pac $bindir/ui/pac
}
bfstart(){
#读取配置文件
@ -1117,7 +1110,7 @@ bfstart(){
[ ! -d $bindir/ui ] && mkdir -p $bindir/ui
[ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master
#检查yaml配置文件
if [ ! -f $clashdir/config.yaml ];then
if [ ! -f $yaml ];then
if [ -n "$Url" -o -n "$Https" ];then
logger "未找到配置文件,正在下载!" 33
getyaml
@ -1128,7 +1121,7 @@ bfstart(){
fi
fi
#检测vless/hysteria协议
if [ -n "$(cat $clashdir/config.yaml | grep -oE 'type: vless|type: hysteria')" ] && [ "$clashcore" != "clash.meta" ];then
if [ -n "$(cat $yaml | grep -oE 'type: vless|type: hysteria')" ] && [ "$clashcore" != "clash.meta" ];then
echo -----------------------------------------------
logger "检测到vless/hysteria协议将改为使用clash.meta核心启动" 33
rm -rf $bindir/clash
@ -1137,7 +1130,7 @@ bfstart(){
echo -----------------------------------------------
fi
#检测是否存在高级版规则
if [ "$clashcore" = "clash" -a -n "$(cat $clashdir/config.yaml | grep -E '^script:|proxy-providers|rule-providers|rule-set')" ];then
if [ "$clashcore" = "clash" -a -n "$(cat $yaml | grep -aE '^script:|proxy-providers|rule-providers|rule-set')" ];then
echo -----------------------------------------------
logger "检测到高级规则将改为使用clash.meta核心启动" 33
rm -rf $bindir/clash
@ -1195,7 +1188,7 @@ bfstart(){
#生成pac文件
catpac
#预下载GeoSite数据库
if [ "$clashcore" = "clash.meta" ] && [ ! -f $bindir/GeoSite.dat ] && [ -n "$(cat $clashdir/config.yaml|grep -Ei 'geosite')" ];then
if [ "$clashcore" = "clash.meta" ] && [ ! -f $bindir/GeoSite.dat ] && [ -n "$(cat $yaml|grep -Ei 'geosite')" ];then
[ -f $clashdir/geosite.dat ] && mv -f $clashdir/geosite.dat $clashdir/GeoSite.dat
if [ -f $clashdir/GeoSite.dat ];then
mv -f $clashdir/GeoSite.dat $bindir/GeoSite.dat
@ -1224,7 +1217,7 @@ bfstart(){
[ -z "$(grep 'procd_set_param user shellclash' /etc/init.d/clash)" ] && \
sed -i '/procd_close_instance/i\\t\tprocd_set_param user shellclash' /etc/init.d/clash
elif [ -w "$servdir" ]; then
setconfig ExecStart "/bin/su shellclash -c \"$bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null\"" $servdir
setconfig ExecStart "/bin/su shellclash -c \"$bindir/clash -d $bindir -f $TMPDIR/config.yaml >/dev/null\"" $servdir
systemctl daemon-reload >/dev/null
fi
fi
@ -1235,7 +1228,7 @@ afstart(){
#读取配置文件
getconfig
#延迟启动
[ ! -f $tmpdir/clash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && {
[ ! -f $TMPDIR/clash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && {
logger "clash将延迟$start_delay秒启动" 31 pushoff
sleep $start_delay
}
@ -1285,7 +1278,7 @@ afstart(){
[ -f $clashdir/cron ] && croncmd $clashdir/cron
#启用面板配置自动保存
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
[ -f $clashdir/configs/web_save ] && web_restore & #后台还原面板配置
#推送日志
{ sleep 5;logger Clash服务已启动;} &
#同步本机时间
@ -1301,10 +1294,10 @@ start_old(){
#使用传统后台执行二进制文件的方式执行
if [ "$local_proxy" = "已开启" -a -n "$(echo $local_type | grep '增强模式')" ];then
ckcmd su && su=su
$su shellclash -c "$bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null" &
$su shellclash -c "$bindir/clash -d $bindir -f $TMPDIR/config.yaml >/dev/null" &
else
ckcmd nohup && nohup=nohup
$nohup $bindir/clash -d $bindir -f $tmpdir/config.yaml >/dev/null 2>&1 &
$nohup $bindir/clash -d $bindir -f $TMPDIR/config.yaml >/dev/null 2>&1 &
fi
afstart
$0 daemon
@ -1325,7 +1318,7 @@ start)
bfstart
stop_firewall #清理路由策略
#使用内置规则强行覆盖config配置文件
[ "$disoverride" != "1" ] && modify_yaml || ln -s $clashdir/config.yaml $tmpdir/config.yaml
[ "$disoverride" != "1" ] && modify_yaml || ln -s $yaml $TMPDIR/config.yaml
#使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then
start_old