Skip to content

Instantly share code, notes, and snippets.

@banghasan
Created October 27, 2016 05:39
Show Gist options
  • Save banghasan/3dc267bb8a00885d9ab2bcee784950ad to your computer and use it in GitHub Desktop.
Save banghasan/3dc267bb8a00885d9ab2bcee784950ad to your computer and use it in GitHub Desktop.
Peringatan Jika Login SSH ke Telegram
# simpan file ke /etc/profile.d/
USERID="ID USER atau GROUP" #contoh 213567634
KEY="TOKENBOT" #contoh 123456789:AASDFASDW21casgW4hjtRLp4GH5wMnWlpT7Eg
TIMEOUT="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
DATE_EXEC="$(date "+%d %b %Y %H:%M")"
TMPFILE='/tmp/ipinfo-$DATE_EXEC.txt'
if [ -n "$SSH_CLIENT" ]; then
IP=$(echo $SSH_CLIENT | awk '{print $1}')
PORT=$(echo $SSH_CLIENT | awk '{print $3}')
HOSTNAME=$(hostname -f)
IPADDR=$(hostname -I | awk '{print $1}')
curl http://ipinfo.io/$IP -s -o $TMPFILE
CITY=$(cat $TMPFILE | jq '.city' | sed 's/"//g')
REGION=$(cat $TMPFILE | jq '.region' | sed 's/"//g')
COUNTRY=$(cat $TMPFILE | jq '.country' | sed 's/"//g')
ORG=$(cat $TMPFILE | jq '.org' | sed 's/"//g')
TEXT="SSH Login! <b>DigitalOcean</b> <code>$DATE_EXEC</code>: <b>${USER}</b> logged in to <code>$HOSTNAME</code> (<code>$IPADDR</code>) from <code>$IP</code> - $ORG - $CITY, $REGION, $COUNTRY <i>on port</i> $PORT"
curl -s --max-time $TIMEOUT -d "chat_id=$USERID&parse_mode=HTML&disable_web_page_preview=1&text=$TEXT" $URL > /dev/null
rm $TMPFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment