2020-05-27 16:34:06 +00:00
|
|
|
#!/bin/sh -e
|
2020-09-28 15:30:53 +00:00
|
|
|
#
|
|
|
|
# 2020 Dennis Camera (dennis.camera@ssrq-sds-fds.ch)
|
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2020-05-27 16:34:06 +00:00
|
|
|
|
2020-09-28 14:54:21 +00:00
|
|
|
drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
|
|
|
|
2020-06-01 15:07:35 +00:00
|
|
|
CONF_PATH=/etc/dma # set in Makefile
|
|
|
|
|
2020-06-01 17:21:41 +00:00
|
|
|
# Determine mailname
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/mailname"
|
2020-06-01 17:21:41 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
mailname=$(cat "${__object:?}/parameter/mailname")
|
2020-06-01 17:21:41 +00:00
|
|
|
else
|
2020-09-28 15:37:41 +00:00
|
|
|
case $(cat "${__global:?}/explorer/os")
|
2020-06-01 17:21:41 +00:00
|
|
|
in
|
|
|
|
(debian|devuan|ubuntu)
|
|
|
|
# On Debian-like systems use /etc/mailname unless --mailname is used
|
|
|
|
mailname='/etc/mailname'
|
|
|
|
;;
|
|
|
|
(*)
|
2020-09-28 15:37:41 +00:00
|
|
|
mailname=${__target_fqdn:?}
|
2020-06-01 17:21:41 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-06-11 15:01:22 +00:00
|
|
|
# Generate "should" values for config
|
2020-06-01 15:07:35 +00:00
|
|
|
conf_should=$(
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -s "${__object:?}/parameter/smarthost"
|
2020-06-01 15:07:35 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
printf 'SMARTHOST %s\n' "$(cat "${__object:?}/parameter/smarthost")"
|
2020-06-01 17:21:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
printf 'MAILNAME %s\n' "${mailname}"
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -s "${__object:?}/explorer/auth_conf"
|
2020-06-01 17:21:41 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
printf "AUTHPATH %s\n" "$(cat "${__object:?}/explorer/auth_conf")"
|
2020-06-01 15:07:35 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
case $(cat "${__object:?}/parameter/security")
|
2020-06-01 15:07:35 +00:00
|
|
|
in
|
|
|
|
(ssl|tls)
|
|
|
|
default_smtp_port=465
|
|
|
|
echo 'SECURETRANSFER'
|
|
|
|
;;
|
|
|
|
(starttls)
|
|
|
|
default_smtp_port=587
|
|
|
|
echo 'SECURETRANSFER'
|
|
|
|
echo 'STARTTLS'
|
|
|
|
;;
|
|
|
|
(opportunistic)
|
|
|
|
default_smtp_port=25 # XXX: correct?
|
|
|
|
echo 'SECURETRANSFER'
|
|
|
|
echo 'STARTTLS'
|
|
|
|
echo 'OPPORTUNISTIC_TLS'
|
|
|
|
;;
|
|
|
|
(insecure)
|
|
|
|
default_smtp_port=25
|
|
|
|
echo 'INSECURE'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -s "${__object:?}/parameter/port"
|
2020-06-01 15:07:35 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
printf 'PORT %u\n' "$(cat "${__object:?}/parameter/port")"
|
2020-06-11 15:01:22 +00:00
|
|
|
elif test "${default_smtp_port}" -ne 25 # DMA uses port 25 by default
|
2020-06-01 15:07:35 +00:00
|
|
|
then
|
|
|
|
printf 'PORT %u\n' "${default_smtp_port}"
|
|
|
|
fi
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/masquerade"
|
2020-06-01 15:07:35 +00:00
|
|
|
then
|
|
|
|
while read -r line
|
|
|
|
do
|
|
|
|
printf 'MASQUERADE %s\n' "${line}"
|
2020-09-28 15:37:41 +00:00
|
|
|
done <"${__object:?}/parameter/masquerade"
|
2020-06-01 15:07:35 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/defer"
|
2020-06-01 15:23:31 +00:00
|
|
|
then
|
|
|
|
echo 'DEFER'
|
|
|
|
fi
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/fullbounce"
|
2020-06-01 15:23:31 +00:00
|
|
|
then
|
|
|
|
echo 'FULLBOUNCE'
|
|
|
|
fi
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/nullclient"
|
2020-06-01 15:23:31 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
test -s "${__object:?}/parameter/smarthost" || {
|
2020-06-09 12:51:11 +00:00
|
|
|
echo '--nullclient requires a --smarthost to be defined' >&2
|
2020-06-01 15:23:31 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
echo 'NULLCLIENT'
|
|
|
|
fi
|
2020-06-01 15:07:35 +00:00
|
|
|
)
|
2020-06-11 15:01:22 +00:00
|
|
|
# Sort conf_should to compare against "conf_is"
|
2020-09-28 15:37:41 +00:00
|
|
|
conf_should=$(echo "${conf_should}" | sort -s -k 1,1)
|
2020-06-01 15:07:35 +00:00
|
|
|
|
|
|
|
config_updated=false
|
2020-09-28 15:37:41 +00:00
|
|
|
if ! echo "${conf_should}" | cmp -s "${__object:?}/explorer/conf" -
|
2020-06-01 15:07:35 +00:00
|
|
|
then
|
|
|
|
# config needs to be updated
|
2020-09-28 14:54:21 +00:00
|
|
|
dma_conf="${CONF_PATH:?}/dma.conf"
|
2020-06-11 15:01:22 +00:00
|
|
|
|
|
|
|
# The following AWK script will output the new config file to be stored on
|
|
|
|
# disk. To do so it reads the current dma.conf file and the config options
|
|
|
|
# that should be set (from stdin).
|
|
|
|
# Note that the path to the current dma.conf is passed to AWK twice, because
|
|
|
|
# the new file cannot be generated in one pass.
|
|
|
|
|
|
|
|
# The logic tries to place options at a sensible location, that is:
|
|
|
|
# a) if the option is already used in the config file:
|
|
|
|
# group all similar options (e.g. MASQUERADE) at one place in the order
|
|
|
|
# they are listed in stdin.
|
|
|
|
# b) if it is a new option and a "default comment" (e.g. "#PORT 25") exists:
|
|
|
|
# place options grouped directly after the comment (the comment is left
|
|
|
|
# alone)
|
|
|
|
# c) otherwise:
|
|
|
|
# options are grouped by word (the first word in the line) and appended
|
|
|
|
# at the end of the file.
|
|
|
|
|
2020-09-28 14:54:21 +00:00
|
|
|
cat <<CODE
|
2020-09-28 15:37:41 +00:00
|
|
|
awk '$(drop_awk_comments "${__type:?}/files/update_dma_conf.awk")' '${dma_conf}' '${dma_conf}' <<'EOF' >'${dma_conf}.tmp' \
|
2020-09-28 14:54:21 +00:00
|
|
|
&& cat '${dma_conf}.tmp' >'${dma_conf}'
|
|
|
|
${conf_should}
|
2020-06-01 15:07:35 +00:00
|
|
|
EOF
|
2020-09-28 14:54:21 +00:00
|
|
|
rm '${dma_conf}.tmp'
|
|
|
|
CODE
|
2020-06-01 15:07:35 +00:00
|
|
|
|
|
|
|
config_updated=true
|
2020-09-28 15:37:41 +00:00
|
|
|
echo 'config updated' >>"${__messages_out:?}"
|
2020-06-01 15:07:35 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-09-28 15:37:41 +00:00
|
|
|
if test -f "${__object:?}/parameter/send-test-email"
|
2020-05-31 13:18:11 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
if grep -q '^__mail_alias/root:' "${__messages_in:?}" \
|
|
|
|
|| grep -q '^__dma_auth/' "${__messages_in:?}" \
|
2020-06-11 15:01:22 +00:00
|
|
|
|| $config_updated
|
2020-05-31 13:18:11 +00:00
|
|
|
then
|
2020-09-28 15:37:41 +00:00
|
|
|
cat <<-CODE
|
|
|
|
sendmail root <<'EOF'
|
|
|
|
Subject: [cdist] Test mail from '${__target_fqdn:?}'
|
2020-05-27 16:34:06 +00:00
|
|
|
|
2020-06-01 17:24:32 +00:00
|
|
|
Hi,
|
|
|
|
|
|
|
|
you can ignore this message.
|
2020-09-28 15:37:41 +00:00
|
|
|
Its sole purpose is to notify you that root mail on ${__target_fqdn:?}
|
2020-06-01 17:24:32 +00:00
|
|
|
will be redirected to you.
|
2020-05-27 16:34:06 +00:00
|
|
|
|
2020-05-31 13:18:11 +00:00
|
|
|
Enjoy!
|
|
|
|
EOF
|
2020-09-28 15:37:41 +00:00
|
|
|
CODE
|
2020-05-31 13:18:11 +00:00
|
|
|
fi
|
|
|
|
fi
|