~继续优化代码

~bot_tg.sh施工中
This commit is contained in:
juewuy
2025-12-26 17:35:45 +08:00
parent 0b3beca6a9
commit 1f477a5934
12 changed files with 233 additions and 181 deletions

View File

@@ -0,0 +1,16 @@
check_autostart(){
if [ "$start_old" = "已开启" ];then
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && return 0
elif ckcmd systemctl; then
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && return 0
elif grep -q 's6' /proc/1/comm; then
[ -f /etc/s6-overlay/s6-rc.d/user/contents.d/afstart ] && return 0
elif rc-status -r >/dev/null 2>&1; then
rc-update show default | grep -q "shellcrash" && return 0
else
return 1
fi
return 1
}

View File

@@ -1,4 +1,5 @@
#日志工具
. "$CRASHDIR"/libs/web_json.sh
#$1日志内容$2显示颜色$3是否推送
logger() {
TMPDIR=/tmp/ShellCrash
@@ -6,55 +7,44 @@ logger() {
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
echo "$log_text" >>"$TMPDIR"/ShellCrash.log
[ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,50d' "$TMPDIR"/ShellCrash.log
#推送工具
webpush() {
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@"
export https_proxy="http://${auth}127.0.0.1:$mix_port"
}
if curl --version >/dev/null 2>&1; then
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json; charset=utf-8" "$1" -d "$2" >/dev/null 2>&1
elif wget --version >/dev/null 2>&1; then
wget -Y on -q --timeout=3 -O - --method=POST --header="Content-Type: application/json; charset=utf-8" --body-data="$2" "$1" >/dev/null 2>&1
fi
}
#推送远程日志
[ -z "$3" ] && {
[ -n "$device_name" ] && log_text="$log_text($device_name)"
[ -n "$push_TG" ] && {
url="https://api.telegram.org/bot${push_TG}/sendMessage"
[ "$push_TG" = 'publictoken' ] && url='https://tgbot.jwsc.eu.org/publictoken/sendMessage'
content="{\"chat_id\":\"${chat_ID}\",\"text\":\"$log_text\"}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_bark" ] && {
url="${push_bark}"
content="{\"body\":\"${log_text}\",\"title\":\"ShellCrash日志推送\",\"level\":\"passive\",\"badge\":\"1\"}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_Deer" ] && {
url="https://api2.pushdeer.com/message/push"
content="{\"pushkey\":\"${push_Deer}\",\"text\":\"$log_text\"}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_Po" ] && {
url="https://api.pushover.net/1/messages.json"
content="{\"token\":\"${push_Po}\",\"user\":\"${push_Po_key}\",\"title\":\"ShellCrash日志推送\",\"message\":\"$log_text\"}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_PP" ] && {
url="http://www.pushplus.plus/send"
content="{\"token\":\"${push_PP}\",\"title\":\"ShellCrash日志推送\",\"content\":\"$log_text\"}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_Gotify" ] && {
url="${push_Gotify}"
content="{\"title\":\"ShellCrash日志推送\",\"message\":\"$log_text\",\"priority\":5}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
[ -n "$push_SynoChat" ] && {
url="${push_ChatURL}/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=${push_ChatTOKEN}"
content="payload={\"text\":\"${log_text}\", \"user_ids\":[${push_ChatUSERID}]}"
webpush "$url" "$content" &
web_json_post "$url" "$content" &
}
} &
}

18
scripts/libs/web_data.sh Normal file
View File

@@ -0,0 +1,18 @@
. "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:json字符串
web_data_get() {
setproxy
if curl --version >/dev/null 2>&1; then
curl -ksSl --connect-timeout 3 "$1" 2>/dev/null
else
wget -Y on -q --timeout=3 -O - "$1"
fi
}
web_data_post() {
setproxy
if curl --version >/dev/null 2>&1; then
curl -ksSl -X POST --connect-timeout 3 "$1" "$2" >/dev/null 2>&1
else
wget -Y on -q --timeout=3 --header="Content-Type: application/octet-stream" --method=POST --body-file="$2" "$1"
fi
}