~日志功能优化,增加推送通道
  ·Telegram推送
  ·Bark推送
  ·Pushover推送
~新手引导优化
~ipv6支持优化
This commit is contained in:
juewuy 2022-12-04 20:54:09 +08:00
parent 9da78cb31d
commit addccfcb12
4 changed files with 252 additions and 68 deletions

View File

@ -32,6 +32,10 @@
——————————<br>
~更多设备支持请提issue或前往TG群反馈需提供设备名称及运行uname -a返回的设备核心信息<br>
## 常见问题:
[ShellClash常见问题 | Juewuy's Blog](https://juewuy.github.io/chang-jian-wen-ti/)
使用方式:
--
~确认路由器设备已经开启SSH并获取root权限带GUI桌面的Linux设备可使用自带终端安装<br>
@ -138,11 +142,6 @@ ubus/iproute-doc 极低 缺少时无法正常获取本机host地址
--
### [TG讨论组](https://t.me/ShellClash)
相关Q&A
--
### [详见博客](https://juewuy.github.io)
## 请喝杯茶:
支付宝 微信

View File

@ -26,6 +26,7 @@ getconfig(){
[ -z "$dns_port" ] && dns_port=1053
[ -z "$multiport" ] && multiport='22,53,587,465,995,993,143,80,443,8080'
[ -z "$local_proxy" ] && local_proxy=未开启
[ -z "$redir_mod" ] && redir_mod=纯净模式
#检查mac地址记录
[ ! -f $clashdir/mac ] && touch $clashdir/mac
#获取本机host地址
@ -132,6 +133,134 @@ checkrestart(){
[ "$res" = 1 ] && clashstart
}
#功能相关
log_pusher(){
[ -n "$push_TG" ] && stat_TG=32m已启用 || stat_TG=33m未启用
[ -n "$push_bark" ] && stat_bark=32m已启用 || stat_bark=33m未启用
[ -n "$push_Po" ] && stat_Po=32m已启用 || stat_Po=33m未启用
echo -----------------------------------------------
echo -e " 1 查看\033[36m运行日志\033[0m"
echo -e " 2 Telegram推送 ——\033[$stat_TG\033[0m"
echo -e " 3 Bark推送-IOS ——\033[$stat_bark\033[0m"
echo -e " 4 Passover推送 ——\033[$stat_Po\033[0m"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
case $num in
1)
echo -----------------------------------------------
cat /tmp/ShellClash_log
exit
;;
2)
echo -----------------------------------------------
if [ -n "$push_TG" ];then
read -p "确认关闭TG日志推送(1/0) > " res
[ "$res" = 1 ] && {
push_TG=
chat_ID=
setconfig push_TG
setconfig chat_ID
}
else
#echo -e "\033[33m详细设置指南请参考 https://juewuy.github.io/ \033[0m"
echo -e "请先通过 \033[32;4mhttps://t.me/BotFather\033[0m 申请TG机器人并获取其\033[36mAPI TOKEN\033[0m"
echo -----------------------------------------------
read -p "请输入你获取到的API TOKEN > " TOKEN
echo -----------------------------------------------
echo -e "\033[32m请通过Telegram的对话窗口向该机器人发送任意消息\033[0m"
echo -----------------------------------------------
read -p "我已经发送完成(1/0) > " res
if [ "$res" = 1 ];then
url_tg=https://api.telegram.org/bot${TOKEN}/getUpdates
[ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port"
if curl --version &> /dev/null;then
chat=$(curl -kfsSl $url_tg 2>/dev/null| tail -n -1)
else
chat=$(wget -Y on -q -O - $url_tg | tail -n -1)
fi
[ -n "$chat" ] && chat_ID=$(echo $chat | grep -oE '"id":.*,"is_bot":false' | sed s'/"id"://'g | sed s'/,"is_bot":false//'g)
if [ -n "$chat_ID" ];then
push_TG=$TOKEN
setconfig push_TG $TOKEN
setconfig chat_ID $chat_ID
$clashdir/start.sh logger "已完成Telegram日志推送设置" 32
else
echo -e "\033[31m无法获取对话ID请重新配置\033[0m"
fi
fi
sleep 1
fi
log_pusher
;;
3)
echo -----------------------------------------------
if [ -n "$push_bark" ];then
read -p "确认关闭Bark日志推送(1/0) > " res
[ "$res" = 1 ] && {
push_bark=
setconfig push_bark
}
else
#echo -e "\033[33m详细设置指南请参考 https://juewuy.github.io/ \033[0m"
echo -e "\033[33mBark推送仅支持IOS系统其他平台请使用其他推送方式\033[0m"
echo -e "\033[32m请安装Bark-IOS客户端并在客户端中找到专属推送链接\033[0m"
echo -----------------------------------------------
read -p "请输入你的Bark推送链接 > " url
if [ -n "$url" ];then
push_bark=$url
setconfig push_bark $url
$clashdir/start.sh logger "已完成Bark日志推送设置" 32
else
echo -e "\033[31m输入错误请重新输入\033[0m"
fi
sleep 1
fi
log_pusher
;;
4)
echo -----------------------------------------------
if [ -n "$push_Po" ];then
read -p "确认关闭Pushover日志推送(1/0) > " res
[ "$res" = 1 ] && {
push_Po=
push_Po_key=
setconfig push_Po
setconfig push_Po_key
}
elif curl --version &> /dev/null;then
#echo -e "\033[33m详细设置指南请参考 https://juewuy.github.io/ \033[0m"
echo -e "请先通过 \033[32;4mhttps://pushover.net/\033[0m 注册账号并获取\033[36mUser Key\033[0m"
echo -----------------------------------------------
read -p "请输入你的User Key > " key
if [ -n "$key" ];then
echo -----------------------------------------------
echo -e "\033[33m请检查注册邮箱完成账户验证\033[0m"
read -p "我已经验证完成(1/0) > "
echo -----------------------------------------------
echo -e "请通过 \033[32;4mhttps://pushover.net/apps/build\033[0m 生成\033[36mAPI Token\033[0m"
echo -----------------------------------------------
read -p "请输入你的API Token > " Token
if [ -n "$Token" ];then
push_Po=$Token
push_Po_key=$key
setconfig push_Po $Token
setconfig push_Po_key $key
$clashdir/start.sh logger "已完成Passover日志推送设置" 32
else
echo -e "\033[31m输入错误请重新输入\033[0m"
fi
else
echo -e "\033[31m输入错误请重新输入\033[0m"
fi
else
echo -e "\033[33mPashover不支持使用wget命令推送请尝试其他推送方式\033[0m"
fi
sleep 1
log_pusher
;;
*) errornum ;;
esac
}
setport(){
source $ccfg
[ -z "$secret" ] && secret=未设置
@ -174,8 +303,7 @@ setport(){
elif [ "$num" = 2 ]; then
echo -----------------------------------------------
echo -e "格式必须是\033[32m 用户名:密码 \033[0m的形式注意用小写冒号分隔"
echo -e "请尽量不要使用特殊符号!可能会产生未知错误!"
echo -e "\033[31m需要使用本机代理功能时请勿设置密码\033[0m"
echo -e "请尽量不要使用特殊符号!避免产生未知错误!"
echo "输入 0 删除密码"
echo -----------------------------------------------
read -p "请输入Http/Sock5用户名及密码 > " input
@ -256,7 +384,6 @@ setport(){
setdns(){
[ -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 "$ipv6_dns" ] && ipv6_dns=已开启
[ -z "$dns_redir" ] && dns_redir=未开启
[ -z "$dns_no" ] && dns_no=未禁用
echo -----------------------------------------------
@ -269,7 +396,6 @@ setdns(){
echo -e " 2 修改\033[36mfallback_DNS\033[0m"
echo -e " 3 \033[33m重置\033[0mDNS配置"
echo -e " 4 一键配置\033[32m加密DNS\033[0m"
echo -e " 5 ipv6_dns解析 \033[36m$ipv6_dns\033[0m ————建议开启"
echo -e " 6 Dnsmasq转发 \033[36m$dns_redir\033[0m ————用于解决dns劫持失败的问题"
echo -e " 7 禁用内置DNS \033[36m$dns_no\033[0m ————不明勿动"
echo -e " 0 返回上级菜单"
@ -324,19 +450,6 @@ setdns(){
rm -rf /tmp/ssl_test
sleep 1
setdns
elif [ "$num" = 5 ]; then
echo -----------------------------------------------
if [ "$ipv6_dns" = "未开启" ]; then
echo -e "\033[32m开启成功\033[0m"
ipv6_dns=已开启
else
echo -e "\033[33m禁用成功\033[0m"
ipv6_dns=未开启
fi
sleep 1
setconfig ipv6_dns $ipv6_dns
setdns
elif [ "$num" = 6 ]; then
echo -----------------------------------------------
@ -369,6 +482,45 @@ setdns(){
setdns
fi
}
setipv6(){
[ -z "$ipv6_support" ] && ipv6_support=已开启
[ -z "$ipv6_redir" ] && ipv6_redir=未开启
[ -z "$ipv6_dns" ] && ipv6_dns=已开启
echo -----------------------------------------------
echo -e " 1 ipv6内核支持: \033[36m$ipv6_support\033[0m ——用于ipv6节点及规则支持"
echo -e " 2 ipv6透明代理: \033[36m$ipv6_redir\033[0m ——代理ipv6流量且不支持绕过CN"
echo -e " 3 ipv6-DNS解析: \033[36m$ipv6_dns\033[0m ——决定内置DNS是否返回ipv6地址"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
case $num in
1)
[ "$ipv6_support" = "未开启" ] && ipv6_support=已开启 || ipv6_support=未开启
setconfig ipv6_support $ipv6_support
setipv6
;;
2)
if [ "$ipv6_redir" = "未开启" ]; then
echo -e "如果启用后导致部分应用加载缓慢,请关闭此功能即可恢复"
echo -e "\033[31m除非特殊需要否则无需开启此功能\033[0m"
ipv6_redir=已开启
sleep 2
else
ipv6_redir=未开启
fi
setconfig ipv6_redir $ipv6_redir
setipv6
;;
3)
[ "$ipv6_dns" = "未开启" ] && ipv6_dns=已开启 || ipv6_dns=未开启
setconfig ipv6_dns $ipv6_dns
setipv6
;;
*)
errornum
;;
esac
}
checkport(){
for portx in $dns_port $mix_port $redir_port $db_port ;do
if [ -n "$(netstat -ntul 2>&1 |grep '\:$portx ')" ];then
@ -1011,7 +1163,6 @@ clashcfg(){
clashadv(){
#获取设置默认显示
[ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$start_old" ] && start_old=未开启
[ -z "$tproxy_mod" ] && tproxy_mod=未开启
[ -z "$public_support" ] && public_support=未开启
@ -1022,7 +1173,7 @@ clashadv(){
echo -e "\033[30;47m欢迎使用进阶模式菜单\033[0m"
echo -e "\033[33m如您并不了解clash的运行机制请勿更改本页面功能\033[0m"
echo -----------------------------------------------
echo -e " 1 代理ipv6流量: \033[36m$ipv6_support\033[0m ————关闭时不会影响本机ipv6"
echo -e " 1 ipv6相关"
#echo -e " 2 配置Meta特性"
echo -e " 4 启用域名嗅探: \033[36m$sniffer\033[0m ————用于流媒体及防DNS污染"
echo -e " 5 启用公网访问: \033[36m$public_support\033[0m ————需要路由拨号+公网IP"
@ -1040,19 +1191,8 @@ clashadv(){
i=
elif [ "$num" = 1 ]; then
echo -----------------------------------------------
if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then
echo -e "\033[33m已开启对ipv6流量的代理\033[0m"
echo -e "如果启用后导致部分应用加载缓慢,请关闭此功能即可恢复"
echo -e "\033[31m除非特殊需要否则无需开启此功能\033[0m"
ipv6_support=已开启
sleep 2
else
echo -e "\033[32m已禁用对ipv6协议的支持\033[0m"
ipv6_support=未开启
fi
setconfig ipv6_support $ipv6_support
clashadv
setipv6
clashadv
elif [ "$num" = 4 ]; then
echo -----------------------------------------------
@ -1264,12 +1404,13 @@ tools(){
echo -e "磁盘占用/所在目录:"
du -sh $clashdir
echo -----------------------------------------------
echo -e " 1 ShellClash测试菜单"
echo " 2 ShellClash新手引导"
[ -f /etc/config/ddns -a -d "/etc/ddns" ] && echo -e " 3 配置DDNS服务(需下载相关脚本)"
echo -e " 1 ShellClash\033[33m测试菜单\033[0m"
echo -e " 2 ShellClash\033[32m新手引导\033[0m"
echo -e " 3 \033[36m日志及推送工具\033[0m"
[ -f /etc/firewall.user ] && echo -e " 4 \033[32m配置\033[0m外网访问SSH"
[ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新"
[ -f /usr/sbin/otapredownload ] && echo -e " 6 小米设备软固化SSH ———— \033[$mi_autoSSH_type \033[0m"
[ -f /data/clash/misnap_init.sh ] && echo -e " 6 小米设备软固化SSH ———— \033[$mi_autoSSH_type \033[0m"
[ -f /etc/config/ddns -a -d "/etc/ddns" ] && echo -e " 7 配置\033[32mDDNS服务\033[0m(需下载相关脚本)"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
echo -----------------------------------------------
@ -1285,12 +1426,16 @@ tools(){
elif [ "$num" = 2 ]; then
source $clashdir/getdate.sh && userguide
elif [ "$num" = 3 ]; then
log_pusher
tools
elif [ "$num" = 4 ]; then
ssh_tools
sleep 1
tools
elif [ "$num" = 3 ]; then
elif [ "$num" = 7 ]; then
echo -----------------------------------------------
if [ ! -f $clashdir/ShellDDNS.sh ];then
echo -e "正在获取在线脚本……"
@ -1314,11 +1459,11 @@ tools(){
sleep 1
tools
elif [ -f /usr/sbin/otapredownload ] && [ "$num" = 6 ]; then
elif [ "$num" = 6 ]; then
if [ "$mi_autoSSH" = "已启用" ];then
mi_autoSSH=禁用
else
if [ "$systype" = "mi_snapshot" -o "$systype" = "mi_snapshot" ];then
if [ "$systype" = "mi_snapshot" ];then
echo -----------------------------------------------
echo -e "\033[33m本功能使用软件命令进行固化不保证100%成功!\033[0m"
echo -e "本功能需依赖clash服务请确保clash为开机启动状态"

View File

@ -1053,6 +1053,12 @@ userguide(){
setconfig authentication \'$authentication\'
fi
fi
#小米设备软固化
if [ "$systype" = "mi_snapshot" ];then
echo -----------------------------------------------
read -p "是否启用软固化SSH(1/0) > " res
[ "$res" = 1 ] && setconfig mi_autoSSH 已启用
fi
#提示导入订阅或者配置文件
echo -----------------------------------------------
echo -e "\033[32m是否导入配置文件\033[0m(这是运行前的最后一步)"
@ -1080,7 +1086,6 @@ testcommand(){
echo " 4 查看clash相关路由规则"
echo " 5 查看config.yaml前30行"
echo " 6 测试代理服务器连通性google.tw)"
echo " 9 查看后台脚本运行日志"
echo -----------------------------------------------
echo " 0 返回上级目录!"
read -p "请输入对应数字 > " num
@ -1150,11 +1155,7 @@ testcommand(){
echo -e "\033[31m连接超时请重试或检查节点配置\033[0m"
fi
clashsh
elif [ "$num" = 9 ]; then
echo -----------------------------------------------
cat $clashdir/log
exit;
else
errornum
clashsh

View File

@ -16,7 +16,8 @@ getconfig(){
[ -z "$redir_mod" ] && redir_mod=纯净模式
[ -z "$skip_cert" ] && skip_cert=已开启
[ -z "$dns_mod" ] && dns_mod=redir_host
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$ipv6_support" ] && ipv6_support=已开启
[ -z "$ipv6_redir" ] && ipv6_redir=未开启
[ -z "$ipv6_dns" ] && ipv6_dns=已开启
[ -z "$mix_port" ] && mix_port=7890
[ -z "$redir_port" ] && redir_port=7892
@ -45,8 +46,36 @@ compare(){
}
logger(){
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m"
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 20 ] && sed -i '1,5d' $clashdir/log
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
echo $log_text >> /tmp/ShellClash_log
[ "$(wc -l /tmp/ShellClash_log | awk '{print $1}')" -gt 99 ] && sed -i '1,5d' /tmp/ShellClash_log
getconfig
[ -n "$(pidof clash)" ] && {
[ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port"
}
[ -n "$push_TG" ] && {
url=https://api.telegram.org/bot${push_TG}/sendMessage
curl_data="-d chat_id=$chat_ID&text=$log_text"
wget_data="--post-data=$chat_ID&text=$log_text"
if curl --version &> /dev/null;then
curl -kfsSl -d "chat_id=$chat_ID&text=$log_text" "$url" >/dev/null
else
wget -Y on -q --post-data="chat_id=$chat_ID&text=$log_text" "$url"
fi
}
[ -n "$push_bark" ] && {
url=${push_bark}/${log_text}
if curl --version &> /dev/null;then
curl -kfsSl "$url" >/dev/null
else
wget -Y on -q "$url"
fi
}
[ -n "$push_Po" ] && {
url=https://api.pushover.net/1/messages.json
curl -kfsSl --form-string "token=$push_Po" --form-string "user=$push_Po_key" --form-string "message=$log_text" "$url" >/dev/null
}
}
croncmd(){
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
@ -141,8 +170,8 @@ EOF`
fi
#输出
echo -----------------------------------------------
echo 正在连接服务器获取配置文件…………链接地址为:
echo -e "\033[4;32m$Https\033[0m"
logger 正在连接服务器获取配置文件…………
echo -e "链接地址为:\033[4;32m$Https\033[0m"
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
#获取在线yaml文件
yaml=$clashdir/config.yaml
@ -161,7 +190,8 @@ EOF`
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
exit 1
elif [ "$retry" = 3 ];then
logger "配置文件获取失败尝试使用http备用服务器获取" 31
retry=4
logger "配置文件获取失败最后尝试使用http备用服务器获取" 31
echo -e "\033[32m如担心安全性请在5s内使用【ctrl+c】退出\033[0m"
sleep 5
server_link=6
@ -172,7 +202,7 @@ EOF`
retry=$((retry+1))
logger "配置文件获取失败!" 31
echo -e "\033[32m尝试使用其他服务器获取配置\033[0m"
logger "正在重试第$retry次/共5次!" 33
logger "正在重试第$retry次/共4次!" 33
sed -i '/server_link=*/'d $ccfg
if [ "$server_link" -ge 5 ]; then
server_link=0
@ -250,7 +280,7 @@ modify_yaml(){
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
[ "$ipv6_dns" = "已开启" ] && dns_v6='ipv6: true' || dns_v6='ipv6: false'
external="external-controller: 0.0.0.0:$db_port"
[ -d $clashdir/ui ] && db_ui=ui
if [ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ];then
@ -442,7 +472,7 @@ start_redir(){
iptables -t nat -A PREROUTING -p tcp $ports -j clash
#设置ipv6转发
ip6_nat=$(ip6tables -t nat -L 2>&1 | grep -o 'Chain')
if [ -n "$ip6_nat" -a "$ipv6_support" = "已开启" ];then
if [ -n "$ip6_nat" -a "$ipv6_redir" = "已开启" ];then
ip6tables -t nat -N clashv6
ip6tables -t nat -A clashv6 -d ::1/128 -j RETURN
ip6tables -t nat -A clashv6 -d fc00::/7 -j RETURN
@ -554,7 +584,7 @@ start_tproxy(){
}
#设置ipv6转发
ip6_nat=$(ip6tables -t mangle -L 2>&1 | grep -o 'Chain')
[ -n "$ip6_nat" -a "$ipv6_support" = "已开启" ] && {
[ -n "$ip6_nat" -a "$ipv6_redir" = "已开启" ] && {
ip -6 rule add fwmark 1 table 101
ip -6 route add local ::/0 dev lo table 101
ip6tables -t mangle -N clashv6
@ -661,7 +691,7 @@ start_nft(){
#过滤常用端口
[ -n "$PORTS" ] && nft add rule inet shellclash prerouting tcp dport != {${PORTS}} return
#ipv6支持
if [ "$ipv6_support" = "已开启" ];then
if [ "$ipv6_redir" = "已开启" ];then
RESERVED_IP6="{::1/128, fc00::/7, fe80::/10}"
ip -6 rule add fwmark 1 table 101 2> /dev/null
ip -6 route add local ::/0 dev lo table 101 2> /dev/null
@ -1099,9 +1129,11 @@ start)
else
start_old
fi
logger clash服务已启动
;;
stop)
getconfig
logger 正在关闭clash服务……
[ -n "$(pidof clash)" ] && [ "$restore" = false ] && web_save #保存面板配置
#删除守护进程&面板配置自动保存
cronset "clash保守模式守护进程"
@ -1123,6 +1155,7 @@ restart)
;;
init)
sleep 30
logger ShellClash正在开机初始化
if [ -d "/etc/storage/clash" ];then
clashdir=/etc/storage/clash
i=1
@ -1151,19 +1184,25 @@ init)
;;
getyaml)
getconfig
getyaml
getyaml && \
logger 配置文件更新成功!
;;
updateyaml)
getconfig
getyaml
modify_yaml
put_save http://localhost:${db_port}/configs "{\"path\":\"${clashdir}/config.yaml\"}"
getyaml && \
modify_yaml && \
put_save http://localhost:${db_port}/configs "{\"path\":\"${clashdir}/config.yaml\"}" && \
logger 配置文件更新成功!
;;
logger)
logger $2 $3
;;
webget)
#设置临时http代理
#设置临时代理
[ -n "$(pidof clash)" ] && {
getconfig
export all_proxy="http://$authentication@127.0.0.1:$mix_port"
[ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port" && export http_proxy="$https_proxy"
}
#参数【$2】代表下载目录【$3】代表在线地址
#参数【$4】代表输出显示【$4】不启用重定向
@ -1174,7 +1213,7 @@ webget)
[ "$6" = "skipceroff" ] && certificate='' || certificate='-k'
#[ -n "$7" ] && agent='-A "clash"'
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3" 2>/dev/null)
[ "$result" != "200" ] && export all_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3")
[ "$result" != "200" ] && export https_proxy="" && result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o "$2" "$3")
else
if wget --version > /dev/null 2>&1;then
[ "$4" = "echooff" ] && progress='-q' || progress='-q --show-progress'