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

47 lines
1.1 KiB
Bash
Raw Normal View History

2023-04-13 10:54:28 +00:00
#!/bin/sh
ifconfig > /tmp/ifconfig
cat /proc/cmdline > /tmp/cmdline
2023-04-25 07:23:15 +00:00
tar -cvf /tmp/zalacznik.tar /tmp/cmdline /tmp/ifconfig
2023-04-13 10:54:28 +00:00
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