You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
672 B
Bash

#!/bin/bash
# Modified version, original source: https://gitlab.com/snippets/1871482#note_188602535
USERID={{ recipient_id | quote }}
KEY={{ bot_key | quote }}
TIMEOUT={{ timeout | quote }}
URL="https://api.telegram.org/bot$KEY/sendMessage"
if [ "$PAM_SERVICE" == "sshd" -a "$PAM_TYPE" == "open_session" -a "$PAM_USER" != "git" -a -z "$TMUX" ]; then
IP="$PAM_RHOST"
HOSTNAME=$(hostname --fqdn)
TEXT="Successful login from [$IP](https://ipinfo.io/$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
fi