added sending config to telegram

This commit is contained in:
Pavel Muhortov 2024-01-06 09:37:22 +03:00
parent cd2450cf72
commit 1cfe3156bb

View File

@ -129,6 +129,39 @@ startsendmail() {
addtologs "sent mail with subject '${subj}' to ${dest}" addtologs "sent mail with subject '${subj}' to ${dest}"
} }
#######################################
# Send telegram notification about client config.
# Globals:
# clientname
# faqprofile
# ovpncfgdir
# API_KEY
# CHAT_ID
# THRD_ID
# Arguments:
# None
#######################################
# shellcheck disable=SC2030,2031
startsendtlgm() {
(
API_URL="https://api.telegram.org/bot${API_KEY}/sendMediaGroup?chat_id=${CHAT_ID}"
if grep -q "_" <<< "${CHAT_ID}"; then
THRD_ID=$(printf "%s\n" "${CHAT_ID}" | cut -d_ -f2)
CHAT_ID=$(printf "%s\n" "${CHAT_ID}" | cut -d_ -f1)
fi
if [ -n "${THRD_ID}" ]; then
API_URL="${API_URL}&message_thread_id=${THRD_ID}"
fi
curl "${API_URL}" \
-F "media=[{\"type\": \"document\", \"media\": \"attach://qr\", \"caption\": \"${faqprofile}\", \"parse_mode\": \"Markdown\"}, {\"type\": \"document\", \"media\": \"attach://cf\" }]" \
-F "qr=@/etc/wireguard/${clientname}.png" \
-F "cf=@/etc/wireguard/${clientname}.conf"
) > /dev/null 2>&1
addtologs "sent telegram media with ${clientname}.conf client profile to ${CHAT_ID}"
}
####################################### #######################################
# Create wireguard client certificates. # Create wireguard client certificates.
# Globals: # Globals:
@ -297,6 +330,7 @@ if checkroot; then
createconf createconf
createinfo createinfo
startsendmail startsendmail
startsendtlgm
fi fi
if [ "${resetforce}" -eq 1 ];then if [ "${resetforce}" -eq 1 ];then
addtologs "restarting wg-quick@${iface_name}..." addtologs "restarting wg-quick@${iface_name}..."