$re = '/\$([^{("\\\\\'\/])([a-zA-Z0-9_]*)([^}\/ \t\'"\n.\]:(=\\\\-]*)/m';
$str = 'amavis_permissions_status=$(find -H $amavis_state_dir -maxdepth 3 -a \\( \\! -user amavis -o \\! -group amavis \\))
if [[ -n $amavis_permissions_status ]]
then
_notify \'inf\' "Fixing $amavis_state_dir permissions"
chown -hR amavis:amavis $amavis_state_dir
else
_notify \'inf\' "Permissions in $amavis_state_dir look OK"
return 0
fi
}
function _fix_cleanup_clamav()
{
_notify \'task\' \'Cleaning up disabled Clamav\'
rm -f /etc/logrotate.d/clamav-*
rm -f /etc/cron.d/clamav-freshclam
}
function _fix_cleanup_spamassassin()
{
_notify \'task\' \'Cleaning up disabled spamassassin\'
rm -f /etc/cron.daily/spamassassin
}
##########################################################################
# << Fix Stack
##########################################################################
##########################################################################
# >> Misc Stack
#
# Description: Place functions that do not fit in the sections above here
##########################################################################
function misc()
{
_notify \'taskgrp\' \'Starting Misc\'
for _func in "${FUNCS_MISC[@]}"
do
if ! $_func
then
_defunc
fi
done
}
function _misc_save_states()
{
# consolidate all states into a single directory (`/var/mail-state`) to allow persistence using docker volumes
statedir=/var/mail-state
if [[ $ONE_DIR -eq 1 ]] && [[ -d $statedir ]]
then
_notify \'inf\' "Consolidating all state onto $statedir"
local FILES=(
/var/spool/postfix
/var/lib/postfix
/var/lib/amavis
/var/lib/clamav
/var/lib/spamassassin
/var/lib/fail2ban
/var/lib/postgrey
/var/lib/dovecot
)
for d in "${FILES[@]}"
do
dest="$statedir/$(echo "$d" | sed -e \'s/.var.//; s/\\//-/g\')"
if [[ -d $dest ]]
then
_notify \'inf\' " Destination $dest exists, linking $d to it"
rm -rf "$d"
ln -s "$dest" "$d"
elif [[ -d $d ]]
then
_notify \'inf\' " Moving contents of $d to $dest:" "$(ls "$d")"
mv "$d" "$dest"
ln -s "$dest" "$d"
else
_notify \'inf\' " Linking $d to $dest"
mkdir -p "$dest"
ln -s "$dest" "$d"
fi
done
_notify \'inf\' \'Fixing /var/mail-state/* permissions\'
chown -R clamav /var/mail-state/lib-clamav
chown -R postfix /var/mail-state/lib-postfix
chown -R postgrey /var/mail-state/lib-postgrey
chown -R debian-spamd /var/mail-state/lib-spamassassin
chown -R postfix /var/mail-state/spool-postfix
fi
}
##########################################################################
# >> Start Daemons
##########################################################################
function start_daemons()
{
_notify \'taskgrp\' \'Starting mail server\'
for _func in "${DAEMONS_START[@]}"
do
if ! $_func
then
_defunc
fi
done
}
function _start_daemons_cron()
{
_notify \'task\' \'Starting cron\' \'n\'
supervisorctl start cron
}
function _start_daemons_rsyslog()
{
_notify \'task\' \'Starting rsyslog \' \'n\'
supervisorctl start rsyslog
}
function _start_daemons_saslauthd()
{
_notify \'task\' \'Starting saslauthd\' \'n\'
supervisorctl start "saslauthd_${SASLAUTHD_MECHANISMS}"
}
function _start_daemons_fail2ban()
{
_notify \'task\' \'Starting fail2ban \' \'n\'
touch /var/log/auth.log
# delete fail2ban.sock that probably was left here after container restart
if [[ -e /var/run/fail2ban/fail2ban.sock ]]
then
rm /var/run/fail2ban/fail2ban.sock
fi
supervisorctl start fail2ban
}
function _start_daemons_opendkim()
{
_notify \'task\' \'Starting opendkim \' \'n\'
supervisorctl start opendkim
}
function _start_daemons_opendmarc()
{
_notify \'task\' \'Starting opendmarc \' \'n\'
supervisorctl start opendmarc
}
function _start_daemons_postsrsd()
{
_notify \'task\' \'Starting postsrsd \' \'n\'
supervisorctl start postsrsd
}
function _start_daemons_postfix()
{
_notify \'task\' \'Starting postfix\' \'n\'
supervisorctl start postfix
}
function _start_daemons_dovecot()
{
# Here we are starting sasl and imap, not pop3 because it\'s disabled by default
_notify \'task\' \'Starting dovecot services\' \'n\'
if [[ $ENABLE_POP3 -eq 1 ]]
then
_notify \'task\' \'Starting pop3 services\' \'n\'
mv /etc/dovecot/protocols.d/pop3d.protocol.disab /etc/dovecot/protocols.d/pop3d.protocol
fi
if [[ -f /tmp/docker-mailserver/dovecot.cf ]]
then
cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf
fi
supervisorctl start dovecot
# TODO fix: on integration test
# doveadm: Error: userdb lookup: connect(/var/run/dovecot/auth-userdb) failed: No such file or directory
# doveadm: Fatal: user listing failed
# if [[ $ENABLE_LDAP -ne 1 ]]
# then
# echo "Listing users"
# /usr/sbin/dovecot user \'*\'
# fi
}
function _start_daemons_fetchmail()
{
_notify \'task\' \'Starting fetchmail\' \'n\'
/usr/local/bin/setup-fetchmail
supervisorctl start fetchmail
}
function _start_daemons_clamav()
{
_notify \'task\' \'Starting clamav\' \'n\'
supervisorctl start clamav
}
function _start_daemons_postgrey()
{
_notify \'task\' \'Starting postgrey\' \'n\'
rm -f /var/run/postgrey/postgrey.pid
supervisorctl start postgrey
}
function _start_daemons_amavis()
{
_notify \'task\' \'Starting amavis\' \'n\'
supervisorctl start amavis
}
##########################################################################
# << Start Daemons
##########################################################################
##########################################################################
# Start check for update postfix-accounts and postfix-virtual
##########################################################################
function _start_changedetector()
{
_notify \'task\' \'Starting changedetector\' \'n\'
supervisorctl start changedetector
}
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ! CARE --> DON\'T CHANGE, unless you exactly know what you are doing
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# shellcheck source=/dev/null
. /usr/local/bin/helper_functions.sh
if [[ ${DEFAULT_VARS["DMS_DEBUG"]} -eq 1 ]]
then
_notify \'taskgrp\' ""
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "# ENV"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' ""
printenv
fi
_notify \'taskgrp\' ""
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "# docker-mailserver"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' ""
register_functions
check
setup
fix
misc
start_daemons
_notify \'taskgrp\' ""
_notify \'taskgrp\' "#"
_notify \'taskgrp\' "# $HOSTNAME is up and running"
_notify \'taskgrp\' "#"
_notify \'taskgrp\' ""
touch /var/log/mail/mail.log
tail -fn 0 /var/log/mail/mail.log
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ! CARE --> DON\'T CHANGE, unless you exactly know what you are doing
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exit 0
';
$subst = "${$1$2$3}";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php