Zdalne-systemy-z-kit-uVPN/configs/sendmail.sh

65 lines
1.3 KiB
Bash
Raw Normal View History

2023-04-13 10:54:28 +00:00
#!/bin/sh
cat <<EOF > /etc/msmtprc
account notification
host smtp.mkedziora.pl
port 587
timeout 15
protocol smtp
domain mkedziora.pl
auth on
user test
from test@mkedziora.pl
2023-04-21 14:42:15 +00:00
password
2023-04-13 10:54:28 +00:00
tls on
syslog on
tls_starttls on
EOF
ifconfig > /tmp/ifconfig
cat /proc/cmdline > /tmp/cmdline
tar -cvf /tmp/zalacznik.tar /tmp/cmdline /tmp/ifconfig
xz -v /tmp/zalacznik.tar
MAILFILE=`mktemp /tmp/mailfile.XXXXXX`
BOUNDARY=`head -c 24 /dev/urandom |base64`
NOW=`date "+%Y-%m-%d %H:%M:%S"`
ATTACHEMENT=/tmp/attachement_`date +'%Y:%m:5d_%H%M%S'`.tar.xz
cat /tmp/zalacznik.tar.xz >$ATTACHEMENT
cat >$MAILFILE <<EOF
From: test@mkedziora.pl
To: admin@mkedziora.pl
Subject: Uruchomiono maszynę
Date: $NOW
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=$BOUNDARY
--$BOUNDARY
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: utf8
Content-Disposition: inline
Dzień dobry!
Uruchomiono maszynę o tokenie: $(sed 's/.*token=//;s/ .*//' /proc/cmdline)
w załączniku ip i konfiguracja kernela.
--$BOUNDARY
Content-Type: application/x-xz; name="report.tar.xz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="report.tar.xz"
EOF
cat $ATTACHEMENT|base64 >>$MAILFILE
cat >>$MAILFILE <<EOF
--$BOUNDARY--
EOF
cat $MAILFILE |msmtp -C /etc/msmtprc -a notification admin@mkedziora.pl
rm -f $ATTACHEMENT $MAILFILE