misc/ssh_tg_notify: Extract sendMessage method

master
Felix Stupp 2 years ago
parent 07eeba447e
commit 4da0a72682
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -8,6 +8,10 @@ KEY={{ bot_key | quote }}
TIMEOUT={{ timeout | quote }}
URL="https://api.telegram.org/bot$KEY/sendMessage"
sendMessage() {
curl -s --max-time "$TIMEOUT" -d "chat_id=$1" -d "disable_web_page_preview=1" -d "parse_mode=Markdown" -d "text=$2" "$URL" >/dev/null
}
if [[ "$PAM_SERVICE" == "sshd" && "$PAM_TYPE" == "open_session" && "$PAM_USER" != "git" && -z "$TMUX" ]]; then
IP="$PAM_RHOST"
cache_file="${CACHE_DIR}/${IP}-${PAM_USER}"
@ -19,5 +23,5 @@ if [[ "$PAM_SERVICE" == "sshd" && "$PAM_TYPE" == "open_session" && "$PAM_USER" !
fi
HOSTNAME=$(hostname --fqdn)
TEXT="Successful login from [$IP](https://stat.ripe.net/app/$IP) for ${PAM_USER} @ ${HOSTNAME} ($(date "+%Y-%m-%d %H:%M"))"
curl -s --max-time "$TIMEOUT" -d "chat_id=$USERID" -d "disable_web_page_preview=1" -d "parse_mode=Markdown" -d "text=$TEXT" "$URL" > /dev/null
sendMessage "$USERID" "$TEXT"
fi

Loading…
Cancel
Save