Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
title/usr/local/bin/tgbot.sh
#!/bin/bash
# place this following line at the bottom of /etc/pam.d/login
# session optional pam_exec.so type=open_session seteuid /usr/local/bin/tgbot.sh
# This file itself in /usr/local/bin/
KEY="759894103:AAFXn1w3hWf6musLjg854awTMBZN602b5Pw==Api Token=="
URL="https://api.telegram.org/bot$KEY/sendMessage"
TARGET="150817324==xxxxxx==" # Telegram ID of the conversation with the bot, get it from /getUpdates API

TEXT="User *$PAM_USER* logged in on *$HOSTNAME* at $(date '+%Y-%m-%d %H:%M:%S %Z')
Remote host: $PAM_RHOST
Remote user: $PAM_RUSER
Service: $PAM_SERVICE
TTY: $PAM_TTY"

PAYLOAD="chat_id=$TARGET&text=$TEXT&parse_mode=Markdown&disable_web_page_preview=true"

# Run in background so the script could return immediately without blocking PAM
curl -s --max-time 10 --retry 5 --retry-delay 2 --retry-max-time 10 -d "$PAYLOAD" $URL > /dev/null 2>&1 &

...