diff --git a/wg-client-management.sh b/wg-client-management.sh index efede8e..4db859c 100644 --- a/wg-client-management.sh +++ b/wg-client-management.sh @@ -129,6 +129,39 @@ startsendmail() { 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. # Globals: @@ -297,6 +330,7 @@ if checkroot; then createconf createinfo startsendmail + startsendtlgm fi if [ "${resetforce}" -eq 1 ];then addtologs "restarting wg-quick@${iface_name}..."