Add webhook notifications menu to bootloader settings

This commit is contained in:
Ing 2025-06-01 08:49:56 +08:00
parent 6a6551d537
commit 4264d08471
20 changed files with 4001 additions and 3610 deletions

View File

@ -28,7 +28,7 @@ BUS=$(getBus "${LOADER_DISK}")
clear clear
COLUMNS=$(ttysize 2>/dev/null | awk '{print $1}') COLUMNS=$(ttysize 2>/dev/null | awk '{print $1}')
COLUMNS=${COLUMNS:-80} COLUMNS=${COLUMNS:-80}
WTITLE="$(printf "$(TEXT "Welcome to %s")" "$([ -z "${RR_RELEASE}" ] && echo "${RR_TITLE}" || echo "${RR_TITLE}(${RR_RELEASE})")")" WTITLE="$(printf "$(TEXT "Welcome to %s")" "${RR_TITLE}${RR_RELEASE:+(${RR_RELEASE})}")"
DATE="$(date)" DATE="$(date)"
printf "\033[1;44m%*s\n" "${COLUMNS}" "" printf "\033[1;44m%*s\n" "${COLUMNS}" ""
printf "\033[1;44m%*s\033[A\n" "${COLUMNS}" "" printf "\033[1;44m%*s\033[A\n" "${COLUMNS}" ""

View File

@ -38,7 +38,6 @@ function loaderIsConfigured() {
[ ! -f "${MOD_RDGZ_FILE}" ] && return 1 [ ! -f "${MOD_RDGZ_FILE}" ] && return 1
[ -z "$(readConfigKey "zimage-hash" "${USER_CONFIG_FILE}")" ] && return 1 [ -z "$(readConfigKey "zimage-hash" "${USER_CONFIG_FILE}")" ] && return 1
[ -z "$(readConfigKey "ramdisk-hash" "${USER_CONFIG_FILE}")" ] && return 1 [ -z "$(readConfigKey "ramdisk-hash" "${USER_CONFIG_FILE}")" ] && return 1
return 0 # OK return 0 # OK
} }
@ -485,3 +484,18 @@ function copyDSMFiles() {
return 1 return 1
fi fi
} }
###############################################################################
# Send a webhook notification
# 1 - webhook url
# 2 - message (optional)
function sendWebhook() {
local URL="${1}"
local MSGT="Notification from ${RR_TITLE}${RR_RELEASE:+(${RR_RELEASE})}"
local MSGC="${2:-"test at $(date +'%Y-%m-%d %H:%M:%S')"}"
[ -z "${URL}" ] && return 1
curl -skL -X POST -H "Content-Type: application/json" -d "{\"title\":\"${MSGT}\", \"text\":\"${MSGC}\"}" "${URL}" >/dev/null 2>&1
return $?
}

View File

@ -28,7 +28,7 @@ checkBootLoader || die "$(TEXT "The loader is corrupted, please rewrite it!")"
clear clear
COLUMNS=$(ttysize 2>/dev/null | awk '{print $1}') COLUMNS=$(ttysize 2>/dev/null | awk '{print $1}')
COLUMNS=${COLUMNS:-80} COLUMNS=${COLUMNS:-80}
TITLE="$(printf "$(TEXT "Welcome to %s")" "$([ -z "${RR_RELEASE}" ] && echo "${RR_TITLE}" || echo "${RR_TITLE}(${RR_RELEASE})")")" TITLE="$(printf "$(TEXT "Welcome to %s")" "${RR_TITLE}${RR_RELEASE:+(${RR_RELEASE})}")"
DATE="$(date)" DATE="$(date)"
printf "\033[1;44m%*s\n" "${COLUMNS}" "" printf "\033[1;44m%*s\n" "${COLUMNS}" ""
printf "\033[1;44m%*s\033[A\n" "${COLUMNS}" "" printf "\033[1;44m%*s\033[A\n" "${COLUMNS}" ""
@ -262,6 +262,15 @@ if [ "${DSMLOGO}" = "true" ] && [ -c "/dev/fb0" ] && [ ! "LOCALBUILD" = "${LOADE
python3 "${WORK_PATH}/include/functions.py" makeqr -f "${WORK_PATH}/include/qhxg.png" -l "7" -o "${TMP_PATH}/qrcode_qhxg.png" python3 "${WORK_PATH}/include/functions.py" makeqr -f "${WORK_PATH}/include/qhxg.png" -l "7" -o "${TMP_PATH}/qrcode_qhxg.png"
[ -f "${TMP_PATH}/qrcode_qhxg.png" ] && echo | fbv -acufi "${TMP_PATH}/qrcode_qhxg.png" >/dev/null 2>&1 || true [ -f "${TMP_PATH}/qrcode_qhxg.png" ] && echo | fbv -acufi "${TMP_PATH}/qrcode_qhxg.png" >/dev/null 2>&1 || true
fi fi
WEBHOOKURL="$(readConfigKey "webhookurl" "${USER_CONFIG_FILE}")"
if [ -n "${WEBHOOKURL}" ] && [ ! -f "${TMP_PATH}/WebhookSent" ]; then
DMI="$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i')"
IP="$(getIP)"
echo "${IP}" | grep -q "^169\.254\." && IP=""
[ -n "${IP}" ] && URL="http://${IP}:${TTYD:-7681}" || URL="http://rr:${TTYD:-7681}"
sendWebhook "${WEBHOOKURL}" "{\"RR\":\"${RR_TITLE}${RR_RELEASE:+(${RR_RELEASE})}\", \"DATE\":\"$(date +'%Y-%m-%d %H:%M:%S')\", \"DMI\":\"${DMI}\", \"URL\":\"${URL}\"}"
touch "${TMP_PATH}/WebhookSent"
fi
# Check memory # Check memory
RAM="$(awk '/MemTotal:/ {printf "%.0f", $2 / 1024}' /proc/meminfo 2>/dev/null)" RAM="$(awk '/MemTotal:/ {printf "%.0f", $2 / 1024}' /proc/meminfo 2>/dev/null)"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,7 @@ function backtitle() {
if [ "LOCALBUILD" = "${LOADER_DISK}" ]; then if [ "LOCALBUILD" = "${LOADER_DISK}" ]; then
BACKTITLE="LOCAL " BACKTITLE="LOCAL "
fi fi
BACKTITLE+="$([ -z "${RR_RELEASE}" ] && echo "${RR_TITLE}" || echo "${RR_TITLE}(${RR_RELEASE})")" BACKTITLE+="${RR_TITLE}${RR_RELEASE:+(${RR_RELEASE})}"
if [ -n "${MODEL}" ]; then if [ -n "${MODEL}" ]; then
BACKTITLE+=" ${MODEL}(${PLATFORM})" BACKTITLE+=" ${MODEL}(${PLATFORM})"
else else
@ -2204,6 +2204,48 @@ function keymapMenu() {
loadkeys "/usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz" loadkeys "/usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz"
} }
###############################################################################
# Bootloader notifications (Webhook)
function notificationsMenu() {
MSG=""
MSG+="$(TEXT "Please enter the webhook url and content text.\n")"
MSG+="$(TEXT "The webhook url must be a valid URL (Reference https://webhook-test.com/).\n")"
MSG+="$(TEXT "The notify text is not currently supported, please ignore.\n")"
WEBHOOKURL="$(readConfigKey "webhookurl" "${USER_CONFIG_FILE}")"
# NOTIFYTEXT="$(readConfigKey "notifytext" "${USER_CONFIG_FILE}")"
while true; do
DIALOG --title "$(TEXT "Settings")" \
--extra-button --extra-label "$(TEXT "Test")" \
--form "${MSG}" 10 110 2 "webhookurl" 1 1 "${WEBHOOKURL}" 1 12 93 0 "notifytext" 2 1 "${NOTIFYTEXT}" 2 12 93 0 \
2>"${TMP_PATH}/resp"
RET=$?
case ${RET} in
0)
# ok-button
WEBHOOKURL="$(sed -n '1p' "${TMP_PATH}/resp" 2>/dev/null)"
# NOTIFYTEXT="$(sed -n '2p' "${TMP_PATH}/resp" 2>/dev/null)"
writeConfigKey "webhookurl" "${WEBHOOKURL}" "${USER_CONFIG_FILE}"
# writeConfigKey "notifytext" "${NOTIFYTEXT}" "${USER_CONFIG_FILE}"
break
;;
3)
# extra-button
WEBHOOKURL="$(sed -n '1p' "${TMP_PATH}/resp" 2>/dev/null)"
# NOTIFYTEXT="$(sed -n '2p' "${TMP_PATH}/resp" 2>/dev/null)"
sendWebhook "${WEBHOOKURL}"
;;
1)
# cancel-button
break
;;
255)
# ESC
break
;;
esac
done
}
############################################################################### ###############################################################################
# Permits user edit the user config # Permits user edit the user config
function editUserConfig() { function editUserConfig() {
@ -3277,6 +3319,7 @@ function settingsMenu() {
echo "t \"$(TEXT "Choose a timezone")\"" echo "t \"$(TEXT "Choose a timezone")\""
echo "k \"$(TEXT "Choose a keymap")\"" echo "k \"$(TEXT "Choose a keymap")\""
echo "o \"$(TEXT "Show QR logo:") \Z4${DSMLOGO}\Zn\"" echo "o \"$(TEXT "Show QR logo:") \Z4${DSMLOGO}\Zn\""
echo "n \"$(TEXT "Bootloader notifications (Webhook)")\""
echo "p \"$(TEXT "Custom patch script # Developer")\"" echo "p \"$(TEXT "Custom patch script # Developer")\""
echo "u \"$(TEXT "Edit user config file manually")\"" echo "u \"$(TEXT "Edit user config file manually")\""
echo "g \"$(TEXT "Edit grub.cfg file manually")\"" echo "g \"$(TEXT "Edit grub.cfg file manually")\""
@ -3322,6 +3365,10 @@ function settingsMenu() {
writeConfigKey "dsmlogo" "${DSMLOGO}" "${USER_CONFIG_FILE}" writeConfigKey "dsmlogo" "${DSMLOGO}" "${USER_CONFIG_FILE}"
NEXT="o" NEXT="o"
;; ;;
n)
notificationsMenu
NEXT="e"
;;
p) p)
MSG="" MSG=""
MSG+="$(TEXT "This option provides information about custom patch scripts for the ramdisk.\n")" MSG+="$(TEXT "This option provides information about custom patch scripts for the ramdisk.\n")"