Pernahkah anda berfikiran ingin memantau siapa saja yang login dan mendapat laporan ketika ada user yang masuk ke box Anda ? api telegram solusinya.
Baiklah, pertama tama simak script berikut ini
# simpan file ke /etc/profile.d/
USERID="213567634"
KEY="930289293:AAGn69QpFJKdlwkaJDLWADkladwa"
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="<b>SSH Login!</b>%0A<b>pada:</b> <code>$DATE_EXEC</code>%0A<b>user:</b> ${USER} %0A<b>on hostname:</b> <code>$HOSTNAME</code>%0A<b>ip:</b> (<code>$IPADDR</code>)%0A<b>from:</b> <code>$IP</code>%0A- $ORG, %0A- $CITY, %0A- $REGION, %0A- $COUNTRY <i>%0Aon 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
ubah yang saya beri tanda merah dan sesuaikan dengan bot id telegram anda.
kemudian install jq
root@dns:/var/www/html/bot # apt-get install jq
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libjq1 libonig4
The following NEW packages will be installed:
jq libjq1 libonig4
0 upgraded, 3 newly installed, 0 to remove and 58 not upgraded.
Need to get 305 kB of archives.
After this operation, 964 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirror.rise.ph/raspbian/raspbian stretch/main armhf libonig4 armhf 6.1.3-2 [127 kB]
Get:2 http://mirror.rise.ph/raspbian/raspbian stretch/main armhf libjq1 armhf 1.5+dfsg-1.3 [119 kB]
Get:3 http://mirror.rise.ph/raspbian/raspbian stretch/main armhf jq armhf 1.5+dfsg-1.3 [58.9 kB]
Fetched 305 kB in 1s (161 kB/s)
Selecting previously unselected package libonig4:armhf.
(Reading database ... 45136 files and directories currently installed.)
Preparing to unpack .../libonig4_6.1.3-2_armhf.deb ...
Unpacking libonig4:armhf (6.1.3-2) ...
Selecting previously unselected package libjq1:armhf.
Preparing to unpack .../libjq1_1.5+dfsg-1.3_armhf.deb ...
Unpacking libjq1:armhf (1.5+dfsg-1.3) ...
Selecting previously unselected package jq.
Preparing to unpack .../jq_1.5+dfsg-1.3_armhf.deb ...
Unpacking jq (1.5+dfsg-1.3) ...
Setting up libonig4:armhf (6.1.3-2) ...
Setting up libjq1:armhf (1.5+dfsg-1.3) ...
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up jq (1.5+dfsg-1.3) ...
Jika login dengan ip private nanti pesan balasannya null, null, null, tapi status login tetap diterima.
0 comments:
Post a Comment