Skip to content
Snippets Groups Projects
Commit 14c0cbfb authored by Martin Strbacka's avatar Martin Strbacka
Browse files

Initial commit of mail_notifier.

parent 292fe638
No related branches found
No related tags found
No related merge requests found
Mail notifier
=====================
Notifier is a script that should be run right after the updater.sh script. It will check notification queue stored in a folder in /tmp and try to send every message to the recipient set in /etc/config/user_notfication file.
#!/bin/sh
base_folder=/tmp/user_notify
msgs_folder=$base_folder/messages
locker_stamp=$base_folder/locked
msg_file=$locker_stamp/msg.mail
msmtp_cfg_file=/tmp/msmtp.cfg
mail_stamp=".sent_by_email"
smtp_enabled=`uci get user_notify.smtp.enable`
wanted_severity=`uci get user_notify.notifications.severity`
news_enabled=`uci get user_notify.notifications.news`
create_msmtp_config() {
username=`uci get user_notify.smtp.username`
password=`uci get user_notify.smtp.password`
server=`uci get user_notify.smtp.server`
port=`uci get user_notify.smtp.port`
security=`uci get user_notify.smtp.security`
from=`uci get user_notify.smtp.from`
echo "account notifier" > $msmtp_cfg_file
echo "host $server" >> $msmtp_cfg_file
if [ $security == "starttls" ]; then
echo "tls on" >> $msmtp_cfg_file
echo "tls_certcheck off" >> $msmtp_cfg_file
fi
echo "port $port" >> $msmtp_cfg_file
echo "auth login" >> $msmtp_cfg_file
echo "from $from" >> $msmtp_cfg_file
echo "user $username" >> $msmtp_cfg_file
echo "password $password" >> $msmtp_cfg_file
echo "account default: notifier" >> $msmtp_cfg_file
}
compose_message() {
mkdir $locker_stamp >/dev/null 2>&1
err_lvl=$?
if [ $err_lvl -ne 0 ]; then
echo "Another instance of notifier is running."
exit 1
fi
echo -e "Subject: Upozorneni od Vaseho routeru Turris\n" > $msg_file
msg_list=`ls $msgs_folder`
for msg in $msg_list; do
echo "Working on message: $msg"
touch $msgs_folder/$msg/$mail_stamp
cat $msgs_folder/$msg/message >> $msg_file
done
rm -rf $locker_stamp
}
send_mail() {
to=`uci get user_notify.smtp.to`
cat $msg_file | msmtp -C $msmtp_cfg_file $to
err_lvl=$?
if [ $err_lvl -eq 0 ]; then
msg_cleanup
fi
}
if [ $smtp_enabled -eq 0 ]; then
echo "User notifications are not enabled."
exit 0
fi
create_msmtp_config
compose_message
send_mail
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment