diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index acc44c24..41ba1065 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,6 +27,7 @@ jobs: TELEGRAM_USERID: ${{secrets.TELEGRAM_USERID}} WXSENDKEY: ${{secrets.WXSENDKEY}} SENDTYPE: ${{secrets.SENDTYPE}} + BUTTON_URL: ${{secrets.BUTTON_URL}} run: | chmod +x ./revive.sh ./revive.sh diff --git a/keepalive.sh b/keepalive.sh index a00b3d95..f5901221 100644 --- a/keepalive.sh +++ b/keepalive.sh @@ -9,6 +9,7 @@ sendtype=$2 TELEGRAM_TOKEN="$3" TELEGRAM_USERID="$4" WXSENDKEY="$5" +BUTTON_URL="$6" checkHy2Alive() { @@ -58,7 +59,8 @@ makeMsgConfig(){ "telegram_token": "$TELEGRAM_TOKEN", "telegram_userid": "$TELEGRAM_USERID", "wxsendkey": "$WXSENDKEY", - "sendtype": "$sendtype" + "sendtype": "$sendtype", + "button_url: "$BUTTON_URL" } EOF } @@ -217,7 +219,12 @@ else sendtype=$send_type fi -export TELEGRAM_TOKEN TELEGRAM_USERID WXSENDKEY sendtype +if [ -z "$BUTTON_URL" ]; then + echo "从msg.json获取 BUTTON_URL" + BUTTON_URL=$(jq -r ".button_url // empty" msg.json) +fi + +export TELEGRAM_TOKEN TELEGRAM_USERID WXSENDKEY sendtype BUTTON_URL #echo "最终TELEGRAM_TOKEN=$TELEGRAM_TOKEN,TELEGRAM_USERID=$TELEGRAM_USERID" host=$(hostname) diff --git a/revive.sh b/revive.sh index 8ea09781..33388e01 100755 --- a/revive.sh +++ b/revive.sh @@ -20,15 +20,15 @@ for info in "${hosts_info[@]}"; do port=$(echo $info | jq -r ".port") pass=$(echo $info | jq -r ".password") - script="/home/$user/serv00-play/keepalive.sh autoupdate ${SENDTYPE} ${TELEGRAM_TOKEN} ${TELEGRAM_USERID} ${WXSENDKEY}" + script="/home/$user/serv00-play/keepalive.sh autoupdate ${SENDTYPE} ${TELEGRAM_TOKEN} ${TELEGRAM_USERID} ${WXSENDKEY} ${BUTTON_URL}" - output=$(sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p "$port" "$user@$host" "bash -s" <<< "$script") + output=$(sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p "$port" "$user@$host" "bash -s" <<<"$script") echo "output:$output" if echo "$output" | grep -q "更新完毕"; then echo "登录成功" else echo "登录失败" - ./tgsend.sh "主机:$host,用户名:$user,登录失败请检查!" + ./tgsend.sh "Host:$host,user:$user,登录失败请检查!" fi done diff --git a/ssl/cronSSL.sh b/ssl/cronSSL.sh index af4847cb..f3e5f24f 100644 --- a/ssl/cronSSL.sh +++ b/ssl/cronSSL.sh @@ -3,6 +3,7 @@ installpath="$HOME" domain=$1 host="$(hostname | cut -d '.' -f 1)" +user=$(whoami) sno=${host/s/web} webIp=$(devil vhost list public | grep "$sno" | awk '{print $1}') resp=$(devil ssl www add $webIp le le $domain) @@ -18,7 +19,7 @@ if [[ "$resp" =~ .*succesfully.*$ ]]; then TELEGRAM_TOKEN=$(jq -r ".telegram_token" "$config") TELEGRAM_USERID=$(jq -r ".telegram_userid" "$config") if [[ -n "$TELEGRAM_TOKEN" && -n "$TELEGRAM_USERID" ]]; then - msg="你的域名($domain)申请的SSL证书已下发,请查收!" + msg="Host:$host, user:$user, 你的域名($domain)申请的SSL证书已下发,请查收!" cd $installpath/serv00-play export TELEGRAM_TOKEN="$TELEGRAM_TOKEN" TELEGRAM_USERID="$TELEGRAM_USERID" ./tgsend.sh "$msg" diff --git a/tgsend.sh b/tgsend.sh index 4eaa6008..0334d714 100755 --- a/tgsend.sh +++ b/tgsend.sh @@ -1,17 +1,61 @@ #!/bin/bash message_text=$1 -#解析模式,可选HTML或Markdown -MODE='HTML' -#api接口 + +toTGMsg() { + local msg=$1 + local title="*Serv00-play通知*" + local host_icon="🖥️" + local user_icon="👤" + local time_icon="⏰" + local notify_icon="📢" + + # 获取当前时间 + local current_time=$(date "+%Y-%m-%d %H:%M:%S") + + if [[ "$msg" != Host:* ]]; then + local formatted_msg="${title} \n\n" + formatted_msg+="${time_icon} *时间:* ${current_time} \n" + formatted_msg+="${notify_icon} *通知内容:* \n$msg \n\n" + echo -e "$formatted_msg" + return + fi + + local host=$(echo "$msg" | sed -n 's/.*Host:\([^,]*\).*/\1/p' | xargs) + local user=$(echo "$msg" | sed -n 's/.*user:\([^,]*\).*/\1/p' | xargs) + local notify_content=$(echo "$msg" | sed -E 's/.*user:[^,]*,//' | xargs) + + # 格式化消息内容,Markdown 换行使用两个空格 + 换行 + local formatted_msg="${title} \n\n" + formatted_msg+="${host_icon} *主机:* ${host} \n" + formatted_msg+="${user_icon} *用户:* ${user} \n" + formatted_msg+="${time_icon} *时间:* ${current_time} \n\n" + formatted_msg+="${notify_icon} *通知内容:* ${notify_content} \n\n" + + echo -e "$formatted_msg" # 使用 -e 选项以确保换行符生效 +} + telegramBotToken=${TELEGRAM_TOKEN} telegramBotUserId=${TELEGRAM_USERID} - +formatted_msg=$(toTGMsg "$message_text") +button_url=${BUTTON_URL:-"https://www.youtube.com/@frankiejun8965"} URL="https://api.telegram.org/bot${telegramBotToken}/sendMessage" +reply_markup='{ + "inline_keyboard": [ + [ + {"text": "点击查看", "url": "'"${button_url}"'"} + ] + ] + }' + if [[ -z ${telegramBotToken} ]]; then echo "未配置TG推送" else - res=$(timeout 20s curl -s -X POST $URL -d chat_id=${telegramBotUserId} -d parse_mode=${MODE} -d text="${message_text}") + res=$(curl -s -X POST "https://api.telegram.org/bot${telegramBotToken}/sendMessage" \ + -d chat_id="${telegramBotUserId}" \ + -d parse_mode="Markdown" \ + -d text="$formatted_msg" \ + -d reply_markup="$reply_markup") if [ $? == 124 ]; then echo 'TG_api请求超时,请检查网络是否重启完成并是否能够访问TG' exit 1