notification/templates/sendmail-login.sh

49 lines
1.1 KiB
Bash

#! /bin/sh
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
(
python3 /usr/local/bin/sendmail.py \
-u "$(grep "from=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
-p "$(grep "pass=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
-d "$(grep "dest=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
--smtp "$(grep "smtp=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
--port "$(grep "port=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
--stls "True" \
--subj "[Authorization] $(cat /etc/hostname): ${USER}" \
--text "${TXT_MSG}" \
>> /dev/null 2>&1 &
)