[type/__dma_auth] Send messages

This commit is contained in:
Dennis Camera 2020-05-31 15:18:11 +02:00
parent b848fca929
commit 3f72ca1341
2 changed files with 38 additions and 18 deletions

View file

@ -1,20 +1,31 @@
#!/bin/sh -e
if [ -f "${__object}/parameter/send-test-email" ]; then
SEND_EMAIL="YES"
if test -f "${__object}/parameter/send-test-email"
then
modified=false
if grep -q '^__mail_alias/root:' "${__messages_in}"
then
modified=true
elif grep -q '^__dma_auth/' "${__messages_in}"
then
modified=true
elif grep -q '^__dma/' "${__messages_in}"
then
modified=true
fi
if [ "${SEND_EMAIL}" != "YES" ]; then
exit 0
fi
cat <<EOF
if $modified
then
cat <<-EOF
sendmail root <<EOM
Subject: [cdist] Testing root mail on '${__target_host}'
Subject: [cdist] Testing mail on '${__target_host}'
You can safely ignore this message, it means your system will notify you
You can safely ignore this message. It means your system will notify you
correctly of any relevant messages.
Enjoy!
EOM
EOF
fi
fi

View file

@ -43,12 +43,21 @@ in
test -n "${login}" || { echo '--login must be non-empty' >&2; exit 1 }
mode=1
if test -s "${__object}/explorer/authusers"
then
printf 'set authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
else
printf 'add authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
fi
;;
(absent)
# no matching logins present -> nothing to do
test -s "${__object}/explorer/authusers" || exit 0
mode=0
printf 'delete authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
;;
(*)
printf 'Invalid --state: %s' "${state_should}" >&2