57 lines
1.3 KiB
Bash
57 lines
1.3 KiB
Bash
#! /bin/sh
|
|
|
|
API_URL="$(grep "API_URL=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
SILENCE="$(grep "SILENCE=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
CHAT_ID="$(grep "CHAT_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
THRD_ID="$(grep "THRD_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
|
|
TXT_MSG="[Authorization] $(cat /etc/hostname): ${USER}"
|
|
|
|
SESSION=$(who | grep "${USER}")
|
|
if [ -n "${SESSION}" ]; then
|
|
TXT_MSG=$(cat <<-END
|
|
${TXT_MSG}
|
|
--- GDE/SSH:
|
|
${SESSION}
|
|
END
|
|
)
|
|
fi
|
|
|
|
SESSION=$(lsof -a -i -u "${USER}" -sTCP:ESTABLISHED | grep 'vnc' \
|
|
| awk '{print $3,$9,$10}')
|
|
if [ -n "${SESSION}" ]; then
|
|
TXT_MSG=$(cat <<-END
|
|
${TXT_MSG}
|
|
--- VNC:
|
|
${SESSION}
|
|
END
|
|
)
|
|
fi
|
|
|
|
SESSION=$(ps -ef -u "${USER}" | grep '[s]shd:.*@notty' \
|
|
| awk '{$2=$3=$4=$6=$7=""; print $0}')
|
|
if [ -n "${SESSION}" ]; then
|
|
TXT_MSG=$(cat <<-END
|
|
${TXT_MSG}
|
|
--- SFTP:
|
|
${SESSION}
|
|
END
|
|
)
|
|
fi
|
|
|
|
(
|
|
if [ -z "${THRD_ID}" ]; then
|
|
curl -s -o /dev/null -X POST \
|
|
-d chat_id="${CHAT_ID}" \
|
|
-d text="${TXT_MSG}" \
|
|
-d disable_notification="${SILENCE}" \
|
|
"${API_URL}"
|
|
else
|
|
curl -s -o /dev/null -X POST \
|
|
-d chat_id="${CHAT_ID}" \
|
|
-d text="$TXT_MSG" \
|
|
-d disable_notification="${SILENCE}" \
|
|
-d message_thread_id="$THRD_ID" \
|
|
"${API_URL}"
|
|
fi
|
|
)
|