File: //var/packages/MailPlus-Server/scripts/start-stop-status
#!/bin/bash
. /var/packages/MailPlus-Server/target/backend_hook/hookUtils.conf
. /var/packages/MailPlus-Server/target/scripts/DsmVersionUtil.sh
. /var/packages/MailPlus-Server/scripts/UpgradeUtil.sh
. /var/packages/MailPlus-Server/scripts/KillUtil.sh
# customized items of package
PACKAGE_NAME=$SYNOPKG_PKGNAME
PACKAGE_VER=$SYNOPKG_PKGVER
PRIVATE_LOCATION="/var/packages/MailPlus-Server/target"
PKG_APP_PATH="${PRIVATE_LOCATION}/app"
PKG_INDEXDB_PATH="${PRIVATE_LOCATION}/indexdb"
APP_PATH="/usr/syno/synoman/webman/3rdparty/MailPlus-Server"
# links
SENDMAIL_SRC="${PRIVATE_LOCATION}/sbin/sendmail"
SENDMAIL_LINK="/usr/sbin/sendmail"
#TODO: remove these once the domain user problem, Bug #924, is fixed
PAM_SMTP_LINK="/etc/pam.d/smtp_mps"
PAM_DOVECOT_LINK="/etc/pam.d/dovecot_mps"
# general routines
DSM_CONFIG="/etc.defaults/synoinfo.conf"
DSM_INDEX_ADD="/usr/syno/bin/pkgindexer_add"
DSM_INDEX_DEL="/usr/syno/bin/pkgindexer_del"
MAILPLUS_SERVER_ENABLED="/var/packages/${PACKAGE_NAME}/mailplus_server_enabled"
#
VOLUME=`/usr/bin/readlink ${PRIVATE_LOCATION} | /usr/bin/cut -d'/' -f2`
MAILPLUS_SERVER_BACKEND_BINARY="${PRIVATE_LOCATION}/bin/syno_mailserver_backend"
VOLUME_MAILPLUS_SERVER_PATH=/${VOLUME}/@MailPlus-Server
MAILPLUS_SERVER_TMP_PATH=/var/services/tmp/mailplus_server
MAILPLUS_SERVER_POSTFIX=${VOLUME_MAILPLUS_SERVER_PATH}/postfix
VOLUME_CLAMAV=${VOLUME_MAILPLUS_SERVER_PATH}/clamav
VOLUME_MIMEDEFANG_QUARANTINE=${VOLUME_MAILPLUS_SERVER_PATH}/MD-Quarantine
VOLUME_RSPAMD=${VOLUME_MAILPLUS_SERVER_PATH}/rspamd
RSPAMD_TMP_PATH=${MAILPLUS_SERVER_TMP_PATH}/rspamd
VOLUME_BITDEFENDER=${VOLUME_MAILPLUS_SERVER_PATH}/bitdefender
PERL5_SITE_DIR="/lib/perl5/site_perl/5.8.6"
PERL5_SITE_MODS="Mail/SpamAssassin Mail/SpamAssassin.pm"
SHARE_CLAMAV="/var/packages/MailPlus-Server/target/share/clamav"
ALIAS_BKP_FOLDER="/var/spool/@MailPlus-Server/alias_bkp"
DISCLAIMER_CONTENT_FOLDER="/var/packages/MailPlus-Server/etc/disclaimer_content"
FTS_DECODER_TMP_PATH=${MAILPLUS_SERVER_TMP_PATH}/fts_decoder
# syno_mailserverd
MAIL_PLUS_DAEMON_SCRIPT=${PRIVATE_LOCATION}/scripts/daemon/syno_mailserverd.sh
MPSMigratePID="/var/run/mailplus_server/migration.pid"
#maillog
SYSLOG_NG_CONF_DEST_FOLDER="/usr/local/etc/syslog-ng/patterndb.d/"
MAILPLUS_SERVER_MAIL_LOG_CONF="${SYSLOG_NG_CONF_DEST_FOLDER}mailplus_server_mail_log.conf"
MAILPLUS_SERVER_OFFLINE_LOG_CONF="${SYSLOG_NG_CONF_DEST_FOLDER}offlineimap_syslog.conf"
MAILPLUS_SERVER_BITDEFENDER_LOG_CONF="${SYSLOG_NG_CONF_DEST_FOLDER}bitdefender_log.conf"
MAILPLUS_SERVER_NOT_2_MSG_CONF="${SYSLOG_NG_CONF_DEST_FOLDER}include/not2msg/mailplus_server_not_2_msg.conf"
MAILPLUS_SERVER_LOG_ROTATE_CONF="/usr/local/etc/logrotate.d/mailplus_server_rotate.conf"
MAILLOG_CLIENT_CONF_DEST="/usr/local/etc/syslog-ng/patterndb.d/mailserver_log_client.conf"
MAILLOG_COLLECTOR_CONF_DEST="/usr/local/etc/syslog-ng/patterndb.d/mailserver_log_collector.conf"
LOG_DAEMON_SCRIPT="${PRIVATE_LOCATION}/scripts/daemon/syno_mailloggerd.sh"
SYSLOG_DAEMON_SCRIPT="${PRIVATE_LOCATION}/scripts/daemon/syslog.sh"
SYSLOG_CA_PATH="/var/packages/MailPlus-Server/etc/syslog_ca"
LINK_FOR_COMMON_LOG="/${VOLUME}/@maillog/link_for_common_log"
#backup restore
RESTORE_FLAG="${PRIVATE_LOCATION}/restore_flag"
RESTORE_UPGRADE_ACTIVATE_MEMBER_DB_200_FLAG="${PRIVATE_LOCATION}/restore_upgrade_activate_member_db_0200"
BACKUP_RESTORE_TOOL="${PRIVATE_LOCATION}/bin/syno_config_backup_restore"
BACKUP_RESTORE_TEMP_DIR="${PRIVATE_LOCATION}/backup_restore_temp"
#license
UPGRADE_LICENSE_FLAG="/tmp/mailplus_server.upgrade_to_license_version"
LICENSE_TOOL="/var/packages/MailPlus-Server/target/bin/syno_license_tool"
ACTIVEDB_DUMP_FILE="${PRIVATE_LOCATION}/mailplus_server.active_list.dump"
UPGRADE_ACTIVE_DB_TOOL="${PRIVATE_LOCATION}/hook/syno_upgrade_active_db_tool.py"
LICENSE_ACTIVE_DB="/var/packages/MailPlus-Server/etc/active_list.db"
LICENSE_ACTIVE_DB_BKP="/var/packages/MailPlus-Server/etc/active_list.db.bkp"
#user group policy
USERGROUPPOLICY_TOOL="/var/packages/MailPlus-Server/target/bin/syno_personal_policy"
#delegation
DELEGATION_TOOL="/var/packages/MailPlus-Server/target/bin/syno_delegation"
#multiple domains
MULTIPLE_DOMAIN_TOOL="/var/packages/MailPlus-Server/target/bin/syno_multiple_domains"
#disclaimer upgrade
DISCLAIMER_UPGRADE_TOOL="/var/packages/MailPlus-Server/target/bin/syno_disclaimer_upgrade"
UPGRADE_QUARANTINE="/var/packages/MailPlus-Server/target/bin/upgrade_quarantine.pl"
# upgrade mcp quarantine
MCP_QUARANTINE_UPGRADE_FLAG="/var/packages/MailPlus-Server/etc/upgrade_mcp_quarantine"
MCP_QUARANTINE_UPGRADE_PID="/var/run/mailplus_server/mcp_quarantine_upgrade.pid"
# upgrade virus quarantine
VIRUS_QUARANTINE_UPGRADE_FLAG="/var/packages/MailPlus-Server/etc/upgrade_virus_quarantine"
VIRUS_QUARANTINE_UPGRADE_PID="/var/run/mailplus_server/virus_quarantine_upgrade.pid"
# upgrade mimedefang runkey for rspamd
MIMEDEFANG_RUNKEY_UPGRADE_FLAG="/tmp/mailplus_server.upgrade_mimedefang_runkey"
# upgrade relay to multi source
RELAY_TO_MULTI_SOURCE_FLAG="/tmp/mailplus_server.relay_to_multi_source"
# upgrade related settings for multiple domains
UPGRADE_RELATED_SETTINGS_FOR_MULTIPLE_DOMAINS_FLAG="/tmp/mailplus_server.upgrade_related_settings_for_multiple_domain"
# upgrade disclaimer
UPGRADE_DISCLAIMER_FLAG="/tmp/mailplus_server.upgrade_disclaimer_flag"
# upgrade sharedmailbox acl
UPGRADE_SHAREDMAILBOX_ACL_FLAG="/tmp/mailplus_server.upgrade_sharedmailbox_acl_flag"
UIStringDir="$PRIVATE_LOCATION/app/texts"
CLUSTER_SCRIPT="${PRIVATE_LOCATION}/scripts/ClusterDaemon.sh"
GO_UTILS="${PRIVATE_LOCATION}/usr/bin/syno-mailplus-server-go-utils backend-command"
SYNO_ACTION="/var/packages/MailPlus-Server/target/bin/syno_action"
SHAREDMAILBOX_ACL_UPGRADE_SCRIPT="${PRIVATE_LOCATION}/scripts/SharedMailboxACLUpgrade.sh"
# tinymce
PACKAGE_TINYMCE_PATH="${PRIVATE_LOCATION}/app/tinymce_plugins"
DSM_TINYMCE_PATH="/usr/syno/synoman/webman/modules/TinyMCE/js/tinymce/plugins"
#sha daemon
MAILLPLUS_SHA_DAEMON_SCRIPT="${PRIVATE_LOCATION}/scripts/daemon/syno_mailplus_server_sha_daemon.sh"
# Contacts hook scripts
CONTACTS_HOOK_INSTALL_SCRIPT="/var/packages/Contacts/target/scripts/mailplus_server_hook.sh"
# mailbox tool
MAILBOX_TOOL="${PRIVATE_LOCATION}/bin/syno_mailbox"
LinkTinyMCEPlugins()
{
for entry in "${PACKAGE_TINYMCE_PATH}"/syno_mps_*
do
if [ -d $entry ]; then
ln -sf ${entry} ${DSM_TINYMCE_PATH}
fi
done
}
UnlinkTinyMCEPlugins()
{
rm -rf ${DSM_TINYMCE_PATH}/syno_mps_*
}
GenerateMessage()
{
local section=$1
local key=$2
local lang=${SYNOPKG_DSM_LANGUAGE}
if [ ! -e "${UIStringDir}/${lang}/strings" ]; then
lang="enu"
fi
echo $(sed -n '/^\['$section'\]/,/^'$key'/s/'$key'.*=.*"\(.*\)"/\1/p' "${UIStringDir}/${lang}/strings") > "${SYNOPKG_TEMP_LOGFILE}"
}
SetCrontab()
{
if ! grep -q "/var/packages/MailPlus-Server/target/bin/syno_clean_junk --clean" "/etc/crontab"; then
cat "/etc/crontab" > "/etc/crontab.$$"
echo "0 0 * * * root /var/packages/MailPlus-Server/target/bin/syno_clean_junk --clean" >> "/etc/crontab.$$"
mv "/etc/crontab.$$" "/etc/crontab"
killByPidFile "HUP" "/var/run/crond.pid"
fi
# set schedule task for anti-virus auto-update
local antiVirusEnable="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal anti_virus_enable)"
local antiVirusAutoUpdate="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal anti_virus_auto_update)"
if [ -z "${antiVirusAutoUpdate}" ]; then
# The key do not exist in old version, so set it to default value and hook script will add schedule task
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "anti_virus_auto_update" "yes"
else
if [[ "${antiVirusEnable}" == "yes" ]] && [[ "${antiVirusAutoUpdate}" == "yes" ]]; then
${SYNO_ACTION} "setAntiVirusUpdateTask" 0
fi
fi
# add schedule task for spam auto-learning
local spamLearnEnable="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_auto_learn)"
if [ x"${spamLearnEnable}" = x"yes" ]; then
${SYNO_ACTION} "addSpamLearnTask" 0
fi
# set schedule task for spam rule auto-update
local spamEnable="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_enable)"
local spamUpdateEnable="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_rule_auto_update)"
local spamUpdateHour="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_rule_update_hour)"
local spamUpdateMinute="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_rule_update_minute)"
if [ -z "${spamUpdateHour}" ] || [ -z "${spamUpdateMinute}" ]; then
# The two keys do not exist in old version, so we need to create a random time for it
local hour=$((RANDOM % 6))
local minute=$((RANDOM % 4 * 15))
# Just set the keys here and the hook script will add schedule task
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "spam_rule_update_hour" "${hour}"
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "spam_rule_update_minute" "${minute}"
else
if [[ "${spamEnable}" == "yes" ]] && [[ "${spamUpdateEnable}" == "yes" ]]; then
${SYNO_ACTION} "setSpamRuleUpdateTask" 0
fi
fi
# add schedule task to check security status (anti spam / anti virus / dnsbl)
${SYNO_ACTION} "addSecurityCheckTask" 0
# set schedule task to update phishing blacklist and whitelist
${SYNO_ACTION} "setPhishingUpdateTask" 0
# set maintain task of report learn
${SYNO_ACTION} "setReportLearnMaintainTask" 0
# set hourly learn all task of report learn
${SYNO_ACTION} "setReportAutoLearnTask" 0
}
UnSetCrontab()
{
local log_rotate_config="/usr/syno/etc/synocron.d/mailserver_rotate_schedule.conf"
local mps_log_rotate_config="/usr/syno/etc/synocron.d/mps_log_rotate_schedule.conf"
local need_reload_synocrond=0
if grep -q "/var/packages/MailPlus-Server/target/bin/syno_clean_junk --clean" "/etc/crontab"; then
grep -v "syno_clean_junk --clean" "/etc/crontab" > "/etc/crontab.$$"
mv "/etc/crontab.$$" "/etc/crontab"
killByPidFile "HUP" "/var/run/crond.pid"
fi
#antivirus engine update
${SYNO_ACTION} "removeAntiVirusUpdateTask" 0
#report task
if grep -q "/var/packages/MailPlus-Server/target/bin/syno_send_report" "/etc/crontab"; then
grep -v "syno_send_report" "/etc/crontab" > "/etc/crontab.$$"
mv "/etc/crontab.$$" "/etc/crontab"
killByPidFile "HUP" "/var/run/crond.pid"
fi
#log rotate task
if [ -e $log_rotate_config ]; then
rm -f $log_rotate_config
need_reload_synocrond=1
fi
if [ -e $mps_log_rotate_config ]; then
rm -f $mps_log_rotate_config
need_reload_synocrond=1
fi
if [ "${need_reload_synocrond}" -eq 1 ]; then
if isDSM7OrAbove; then
/usr/syno/bin/synosystemctl reload synocrond
else
/sbin/reload synocrond
fi
fi
#log archive task
${SYNO_ACTION} "removeLogScheduleTask" 0
# remove schedule task for spam auto-learning
${SYNO_ACTION} "removeSpamLearnTask" 0
# remove schedule task for spam rule auto-update
${SYNO_ACTION} "removeSpamRuleUpdateTask" 0
# remove schedule task to check security status (anti spam / anti virus / dnsbl)
${SYNO_ACTION} "removeSecurityCheckTask" 0
# remove schedule task to update phishing blacklist and whitelist
${SYNO_ACTION} "removePhishingUpdateTask" 0
# remove maintain task of report learn
${SYNO_ACTION} "removeReportLearnMaintainTask" 0
# remove hourly learn all task of report learn
${SYNO_ACTION} "removeReportAutoLearnTask" 0
}
MailQueueChown()
{
chown -R postfix:root /var/packages/MailPlus-Server/target/var/spool/@MailPlus-Server/postfix
chown -R postfix:maildrop /var/packages/MailPlus-Server/target/var/spool/@MailPlus-Server/postfix/maildrop
chown -R postfix:maildrop /var/packages/MailPlus-Server/target/var/spool/@MailPlus-Server/postfix/public
chown root:root /var/packages/MailPlus-Server/target/var/spool/@MailPlus-Server/postfix/pid
}
CheckDir()
{
local directory="$1"
if [ ! -d "${directory}" ]; then
mkdir -p "${directory}"
fi
}
CheckEnv()
{
MailQueueChown
if [ ! -d ${MAILPLUS_SERVER_POSTFIX} ]; then
/bin/rm -rf ${MAILPLUS_SERVER_POSTFIX} 2>/dev/null
mkdir -p ${VOLUME_MAILPLUS_SERVER_PATH}
chown MailPlus-Server:MailPlus-Server ${VOLUME_MAILPLUS_SERVER_PATH}
cp -a ${PRIVATE_LOCATION}/var/spool/@MailPlus-Server/postfix ${MAILPLUS_SERVER_POSTFIX}
fi
chmod +x ${MAILPLUS_SERVER_POSTFIX}/public
# mimedefang
if [ ! -d ${VOLUME_MIMEDEFANG_QUARANTINE} ]; then
mkdir -p ${VOLUME_MIMEDEFANG_QUARANTINE}
fi
chown -R MailPlus-Server:MailPlus-Server ${VOLUME_MIMEDEFANG_QUARANTINE}
# clamav
if [ ! -d ${VOLUME_CLAMAV} ]; then
mkdir -p ${VOLUME_CLAMAV}
chown -R MailPlus-Server:MailPlus-Server ${VOLUME_CLAMAV}
fi
#chown clamav:clamav ${VOLUME_CLAMAV}
ln -sfn "${VOLUME_CLAMAV}" "${SHARE_CLAMAV}"
# clamav cache
local CLAMAV_CACHE_DIR="${PRIVATE_LOCATION}/var/cache/clamav"
mkdir -p ${CLAMAV_CACHE_DIR}
chmod 755 ${CLAMAV_CACHE_DIR}
chown MailPlus-Server:MailPlus-Server ${CLAMAV_CACHE_DIR}
# MailPlus Server tmp folder
CheckDir "${MAILPLUS_SERVER_TMP_PATH}"
chown -R MailPlus-Server:MailPlus-Server "${MAILPLUS_SERVER_TMP_PATH}"
# fts decoder
CheckDir "${FTS_DECODER_TMP_PATH}"
chown -R MailPlus-Server:MailPlus-Server "${FTS_DECODER_TMP_PATH}"
chmod 600 "${FTS_DECODER_TMP_PATH}"
# rspamd
CheckDir "${VOLUME_RSPAMD}"
CheckDir "${VOLUME_RSPAMD}"/hs_cache
CheckDir "${VOLUME_RSPAMD}"/sa_rules/conf/mcp
chown -R MailPlus-Server:MailPlus-Server "${VOLUME_RSPAMD}"
CheckDir "${RSPAMD_TMP_PATH}"
chown -R MailPlus-Server:MailPlus-Server "${RSPAMD_TMP_PATH}"
# BitDefender
local BITDEFENDER_CACHE_DIR="${PRIVATE_LOCATION}/var/cache/bitdefender"
CheckDir "${BITDEFENDER_CACHE_DIR}"
chmod 755 ${BITDEFENDER_CACHE_DIR}
chown MailPlus-Server:MailPlus-Server ${BITDEFENDER_CACHE_DIR}
CheckDir "${VOLUME_BITDEFENDER}"
CheckDir "${VOLUME_BITDEFENDER}"/antimalware
CheckDir "${VOLUME_BITDEFENDER}"/antispam
CheckDir "${VOLUME_BITDEFENDER}"/log
CheckDir "${VOLUME_BITDEFENDER}"/tmp
chown -R MailPlus-Server:MailPlus-Server "${VOLUME_BITDEFENDER}"
# McAfee
local SYNOAV_MCAFEE_CACHE_DIR="${PRIVATE_LOCATION}/var/cache/synoav_mcafee"
CheckDir "${SYNOAV_MCAFEE_CACHE_DIR}"
chmod 755 ${SYNOAV_MCAFEE_CACHE_DIR}
chown MailPlus-Server:MailPlus-Server ${SYNOAV_MCAFEE_CACHE_DIR}
}
CreateLinks()
{
# create sendmail link for vacation binary
ln -sf ${SENDMAIL_SRC} ${SENDMAIL_LINK}
# create dovecot link for pam.d login
# ==> move to 'DaemonConfSet.sh smtp'
# clear /var/spool/mail, make sure the mail system will work fine
rm -rf "/var/spool/mail"
local path=$(GetMailPlusSharePath)
if [ x"${path}" != x"" ]; then
ln -sf "${path}" "/var/spool/mail"
fi
}
LogInit()
{
local size=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal postfix_log_rotate_size`
: ${size:="30"}
local internel_size=5
if [ -d "/usr/local/etc/syslog-ng/patterndb.d/" ]; then
mkdir -p /${VOLUME}/@maillog
chown -R MailPlus-Server:MailPlus-Server /${VOLUME}/@maillog
chmod 755 "/${VOLUME}/@maillog"
[ -e ${LINK_FOR_COMMON_LOG} ] && /bin/rm -f ${LINK_FOR_COMMON_LOG}
ln -s "/var/log/mailplus_server.log" ${LINK_FOR_COMMON_LOG}
mkdir -p /var/spool/@MailPlus-Server/aggr_log
chown -R MailPlus-Server:MailPlus-Server /var/spool/@MailPlus-Server/aggr_log
chmod 755 /var/spool/@MailPlus-Server/aggr_log
mkdir -p /var/spool/@MailPlus-Server/aggr_log/forwarded
chown -R MailPlus-Server:MailPlus-Server /var/spool/@MailPlus-Server/aggr_log/forwarded
chmod 755 /var/spool/@MailPlus-Server/aggr_log/forwarded
mkdir -p ${SYSLOG_CA_PATH}
chown -R MailPlus-Server:MailPlus-Server ${SYSLOG_CA_PATH}
chmod 755 ${SYSLOG_CA_PATH}
chown root:root ${PRIVATE_LOCATION}/etc/mailserver_rotate.conf
cp -a ${PRIVATE_LOCATION}/etc/offlineimap_syslog.conf ${MAILPLUS_SERVER_OFFLINE_LOG_CONF}
cp -a ${PRIVATE_LOCATION}/etc/bitdefender_log.conf ${MAILPLUS_SERVER_BITDEFENDER_LOG_CONF}
cp -a ${PRIVATE_LOCATION}/etc/mailplus_server_not_2_msg.conf ${MAILPLUS_SERVER_NOT_2_MSG_CONF}
echo -e "destination d_maillog { file(\"/${VOLUME}/@maillog/maillog\" owner(\"MailPlus-Server\") group(\"system\") perm(0644) suppress(0)); };
destination d_mailplus_server_common_log { file(\"${LINK_FOR_COMMON_LOG}\" owner(\"MailPlus-Server\") group(\"system\") perm(0644) suppress(0) template(\"\$PRIORITY\\\t\$YEAR/\$MONTH/\$DAY \$HOUR:\$MIN:\$SEC\\\t\$MESSAGE\\\n\"));};
destination d_imap_err { file(\"/${VOLUME}/@maillog/imap_err.log\" owner(\"MailPlus-Server\") group(\"system\") perm(0644) suppress(0)); };
filter f_mailplus_go_log {filter(f_mail) and program(\"^MailPlus-Server\") };
filter f_mailplus_server_misc_process {
program(\"^synoscgi_SYNO\\\\.MailPlusServer\\\\.\") or
program(\"^syno_mailserver_backend$\") or
program(\"^syno_set_config$\") or
program(\"^syno_mailserverd\");
};
filter f_mailplus_server_misc_log {filter(f_local1) and filter(f_mailplus_server_misc_process); };
filter f_mailplus_server_common_log {
filter(f_mailplus_go_log) or
filter(f_mailplus_server_misc_log);
};
filter f_mail_log { level(info..emerg) and not filter(f_mailplus_server_common_log) and not message(\"SYNOACCOUNTDBSQLExecGetData:\") and not message(\"^[{]\\\"id\\\":\\\"SYNOMailPlus-Server\\\"\"); };
filter f_imap_error { facility(mail) and message(\"imap\") and message(\"Error\"); };
log { source(src); filter(f_mail); filter(f_mail_log); destination(d_maillog); };
log { source(src); filter(f_mailplus_server_common_log); destination(d_mailplus_server_common_log); };
log { source(src); filter(f_imap_error); destination(d_imap_err); };" > ${MAILPLUS_SERVER_MAIL_LOG_CONF}
echo -e "/${VOLUME}/@maillog/maillog
{
size ${size}M
missingok
postrotate
${SYSLOG_DAEMON_SCRIPT} reload || true
endscript
}
${LINK_FOR_COMMON_LOG}
{
size 1M
missingok
notifempty
postrotate
if [ ! -L \${1} ]; then
LOG_VOLUME=\$(echo \${1} | cut -d '/' -f2)
/bin/rm -f ${1}
ln -s "/var/log/mailplus_server.log" \${1}
fi
${SYSLOG_DAEMON_SCRIPT} reload || true
endscript
}
/${VOLUME}/@maillog/clusterScript.log
{
size ${internel_size}M
missingok
postrotate
${SYSLOG_DAEMON_SCRIPT} reload || true
endscript
}
/${VOLUME}/@maillog/redis.log
{
size ${internel_size}M
missingok
postrotate
${SYSLOG_DAEMON_SCRIPT} reload || true
endscript
}
/${VOLUME}/@maillog/imap_err.log
{
size 1M
missingok
postrotate
${SYSLOG_DAEMON_SCRIPT} reload || true
endscript
}" > ${MAILPLUS_SERVER_LOG_ROTATE_CONF}
chown root:root ${MAILPLUS_SERVER_LOG_ROTATE_CONF}
chmod 644 ${MAILPLUS_SERVER_LOG_ROTATE_CONF}
${SYSLOG_DAEMON_SCRIPT} reload
fi
}
LogStop()
{
local ROTATE_CONF_DEST_FOLDER="/usr/local/etc/logrotate.d/"
local SCHEDULE_CONF_DEST_FOLDER="/usr/syno/etc/synocron.d/"
local AGGR_LOG_CONF="${ROTATE_CONF_DEST_FOLDER}/mailplus_server_aggr_maillog.conf"
local FORWARD_LOG_CONF="${ROTATE_CONF_DEST_FOLDER}/mailplus_server_forward_log.conf"
#remove syslog-ng config
if [ -d "${SYSLOG_NG_CONF_DEST_FOLDER}" ]; then
rm -rf ${MAILPLUS_SERVER_MAIL_LOG_CONF}
rm -rf ${MAILLOG_CLIENT_CONF_DEST}
rm -rf ${MAILLOG_COLLECTOR_CONF_DEST}
rm -rf ${MAILPLUS_SERVER_OFFLINE_LOG_CONF}
rm -rf ${MAILPLUS_SERVER_BITDEFENDER_LOG_CONF}
rm -rf ${MAILPLUS_SERVER_NOT_2_MSG_CONF}
fi
[ -e ${LINK_FOR_COMMON_LOG} ] && /bin/rm -f ${LINK_FOR_COMMON_LOG}
${SYSLOG_DAEMON_SCRIPT} reload
#remove logrotate config
if [ -d "${ROTATE_CONF_DEST_FOLDER}" ]; then
rm -rf ${MAILPLUS_SERVER_LOG_ROTATE_CONF}
rm -rf ${AGGR_LOG_CONF}
rm -rf ${FORWARD_LOG_CONF}
fi
#remove schdule for rotate log database
if [ -d "${SCHEDULE_CONF_DEST_FOLDER}" ]; then
rm -rf "${SCHEDULE_CONF_DEST_FOLDER}/mailserver_rotate_schedule.conf"
rm -rf "${SCHEDULE_CONF_DEST_FOLDER}/mps_log_rotate_schedule.conf"
fi
${LOG_DAEMON_SCRIPT} stop
}
ClearLinks()
{
# remove links
rm -rf ${SENDMAIL_LINK}
rm -rf ${PAM_SMTP_LINK}
rm -rf ${PAM_DOVECOT_LINK}
rm -rf "/var/spool/mail"
}
ClearTmpDir()
{
rm -rf "${MAILPLUS_SERVER_TMP_PATH}"
}
UpdateConf()
{
#truncate dovecot extra_plugin
local DOVECOT_MAIL_PLUGIN="/var/packages/MailPlus-Server/etc/extra_plugins"
if [ -e "${DOVECOT_MAIL_PLUGIN}" ]; then
printf "" > "${DOVECOT_MAIL_PLUGIN}"
fi
}
IsHARunning()
{
if "${MAILPLUS_SERVER_BACKEND_BINARY}" --isSHA; then
echo "running"
else
echo "not_running"
fi
}
ApplyFirewall()
{
local ip=
local nodeIPs=
local clusterNodes=
local nodeID=""
clusterNodes="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal cluster_peers)"
if [ "${clusterNodes}" == "" ]; then
return 0
fi
# Change to IP
for nodeID in ${clusterNodes}; do
local key="node_ip_list-${nodeID}"
ipList="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal ${key})"
nodeIPs="${nodeIPs} ${ipList}"
done
${PRIVATE_LOCATION}/scripts/firewall.sh start "${nodeIPs}"
}
checkClusterSettings()
{
local node_num=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getPeersNum)
local mapping_table="/var/packages/MailPlus-Server/etc/mailconf.d/mapping_table"
local self_id
#fix broken mapping table when there is only one node.
if [ "${node_num}" -eq 1 ] && [ ! -s "${mapping_table}" ]; then
self_id=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostID)
if [ -n "${self_id}" ]; then
echo -n "{\"mapping_table/${self_id}\": \"127.0.0.1\"}" > "${mapping_table}"
chown MailPlus-Server:MailPlus-Server "${mapping_table}"
chmod 644 "${mapping_table}"
fi
fi
## To handle the situation that sometimes the redis.conf may be corrupted,
## we re-generate the redis.conf when start-up every time.
${SYNO_ACTION} update_backend_env ""
#check internal cert for server
if [ ! -s "/var/packages/MailPlus-Server/etc/internal-ssl/server.crt" ] || [ ! -s "/var/packages/MailPlus-Server/etc/internal-ssl/server.key" ] ; then
GenerateInternalCert "onlyCert";
fi
}
CheckVlanChange()
{
local host_if=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostIF)
local host_id=
local pure_if=${host_if/.*/} #remove every thing after .
local matched=0
local vlan_settings
if [ -z "${host_if}" ]; then
err_log "empty host interface, abort check vlan setting"
return
fi
vlan_settings=$(synonet --vlan_enum | sed 1d)
while read -r fullname ori_name vlan_id
do
if [ "${pure_if}" == "${ori_name}" ]; then
if [ "${host_if}" != "${fullname}" ]; then
host_id=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostID)
if [ -z "${host_id}" -o -z "${fullname}" ]; then
err_log "empty host_id[${host_id}] or interface[${fullname}], so abort update vlan information"
else
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "node_bind_if-${host_id}" "${fullname}"
fi
fi
matched=1
break
fi
done <<< "${vlan_settings}"
if [ "${matched}" != "1" -a "${host_if}" != "${pure_if}" ]; then
host_id=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostID)
if [ -n "${host_id}" ]; then
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "node_bind_if-${host_id}" "${pure_if}"
else
err_log "empty host_id, so abort remove vlan from host interface"
fi
fi
}
CheckIPChange()
{
# check if the ip is change when package stop
local HOST_IF=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostIF)
local HOST_IP=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostIP)
local HOST_ID=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostID)
local IF_IP="$(getInterfaceIP ${HOST_IF})"
local HOST_IP_LIST="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostIPList)"
local KEY="node_ip_list-${HOST_ID}"
local NODE_IP_LIST="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal ${key})"
local IS_LIST_IDENTICAL=true
#check and update mapping_table
if [ ! -z "${HOST_IF}" ] && [ ! -z "${IF_IP}" ] && [ ! -z "${HOST_IP}" ]; then
if [ "${IF_IP}" != "${HOST_IP}" ]; then
## update certificate have to before mappingRegen to avoid get old certificate
if ! GenerateInternalCert "onlyCert"; then
err_log "Failed to regen certificate according new IP"
fi
## update backend config and mapping table
if ! ${MAILPLUS_SERVER_BACKEND_BINARY} --mappingRegen "${IF_IP}"; then
err_log "Failed to regen mailplus server id-ip mapping table"
fi
${CLUSTER_SCRIPT} watcher_restart
IS_LIST_IDENTICAL=false
fi
fi
local STORED_HOST_IF="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal node_bind_if-${HOST_ID})"
if [ -z "${STORED_HOST_IF}" ] && [ ! -z ${HOST_ID} ] && [ ! -z ${HOST_IF} ] ; then
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "node_bind_if-${HOST_ID}" ${HOST_IF}
fi
#check and update node_ip_list
for IP_HOST in ${HOST_IP_LIST}
do
if [[ ! "${NODE_IP_LIST}" =~ (^| )"${IP_HOST}"($| ) ]]; then
IS_LIST_IDENTICAL=false
break
fi
done
if [ -n "${HOST_ID}" -a "${IS_LIST_IDENTICAL}" != "true" ]; then
if ! ${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "${KEY}" "${HOST_IP_LIST}"; then
err_log "Failed to update node ip list [${key}] to [${hostIPList}] when starting"
fi
fi
}
PrepareMailClientHook()
{
local dir=$1
rm -rf "${dir}"
mkdir -p "${dir}"
chown MailPlus-Server:system "${dir}"
chmod 755 "${dir}"
}
start()
{
# add user 'postfix' into group 'MailPlus-Server'
synogroup --member MailPlus-Server postfix
# check "/lib/perl5"
if [ ! -e "/lib/perl5" ]; then
GenerateMessage "error" "restart_perl"
exit 1;
fi;
local caPath="/var/packages/MailPlus-Server/etc/internal-ca-ssl/ca.crt"
## Check system time older than certificate generate time
if [ -f "${caPath}" ]; then
local certTime="$(openssl x509 -startdate -noout -in ${caPath}| awk -F"=" '{print $2}' | xargs -I{} date -d "{}" +%s)"
local nowTime="$(date +%s)"
if [ "${certTime}" -gt "${nowTime}" ]; then
GenerateMessage "error" "system_time_error"
exit 1
fi
fi
CreatePreBuildDir
local userCheckTmpDir="/var/run/mailplus_server/user_check"
mkdir -p "${userCheckTmpDir}"
chmod 777 "${userCheckTmpDir}"
chown MailPlus-Server:MailPlus-Server "${userCheckTmpDir}"
chown -R MailPlus-Server:MailPlus-Server /usr/syno/etc/packages/MailPlus-Server
/bin/touch ${MAILPLUS_SERVER_ENABLED}
chown MailPlus-Server:MailPlus-Server ${MAILPLUS_SERVER_ENABLED}
chmod 644 ${MAILPLUS_SERVER_ENABLED}
chown root:root /var/packages/MailPlus-Server/target/bin/syno_mail_privilege_internal
chmod +s /var/packages/MailPlus-Server/target/bin/syno_mail_privilege_internal
chown root:root /var/packages/MailPlus-Server/target/bin/syno_mail_sync
chmod +s /var/packages/MailPlus-Server/target/bin/syno_mail_sync
chown MailPlus-Server:MailPlus-Server /var/packages/MailPlus-Server/target/bin/syno_mcp_hook
chmod +s /var/packages/MailPlus-Server/target/bin/syno_mcp_hook
chown MailPlus-Server:MailPlus-Server /var/packages/MailPlus-Server/target/bin/syno_virus_hook
chmod +s /var/packages/MailPlus-Server/target/bin/syno_virus_hook
PrepareMailClientHook "${PRIVATE_LOCATION}/hook/mailclient_smtp_change_hook/"
PrepareMailClientHook "${PRIVATE_LOCATION}/hook/mailclient_valid_user_list_hook/"
PrepareMailClientHook "${PRIVATE_LOCATION}/hook/mailclient_user_smtp_change_hook/"
if [ -f "${CONTACTS_HOOK_INSTALL_SCRIPT}" ]; then
${CONTACTS_HOOK_INSTALL_SCRIPT} --install
fi
#set permission
chgrp maildrop "/var/packages/MailPlus-Server/target/sbin/postqueue"
chgrp maildrop "/var/packages/MailPlus-Server/target/sbin/postdrop"
chmod g+s "/var/packages/MailPlus-Server/target/sbin/postqueue" "/var/packages/MailPlus-Server/target/sbin/postdrop"
# setuid-root for lda since mimedefang needs to put mail to ham/spam report mailbox
chown root:MailPlus-Server "/var/packages/MailPlus-Server/target/libexec/dovecot/dovecot-lda-setuid"
chmod 04750 "/var/packages/MailPlus-Server/target/libexec/dovecot/dovecot-lda-setuid"
# setuid-root for the tool to release mail from quarantine
chown root:MailPlus-Server "/var/packages/MailPlus-Server/target/bin/release_mail.pl"
chmod 04750 "/var/packages/MailPlus-Server/target/bin/release_mail.pl"
# setuid-root for the tool to upgrade quarantine
chown root:MailPlus-Server "/var/packages/MailPlus-Server/target/bin/upgrade_quarantine.pl"
chmod 04750 "/var/packages/MailPlus-Server/target/bin/upgrade_quarantine.pl"
# to fix MailPlusServer #498
# "/lib/perl5" should be a symoblic link
if [ ! -L "/lib/perl5" ]; then
GenerateMessage "error" "restart_perl"
rm -rf "/lib/perl5"
exit 1;
fi
if isPackageEnable "MailServer"; then
GenerateMessage "error" "stop_mailserver_pkg"
exit 1;
fi
local HA_RUNNING=$(IsHARunning)
local NODE_NUM=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getPeersNum)
if [ x"running" == x"${HA_RUNNING}" ]; then
if isDSM62OrAbove; then
if [ "${NODE_NUM}" -eq 2 ]; then
GenerateMessage "error" "stop_ha"
exit 1
elif [ "${NODE_NUM}" -eq 1 ]; then
"${MAILLPLUS_SHA_DAEMON_SCRIPT}" start
fi
else
GenerateMessage "error" "stop_ha"
exit 1;
fi
else
"${MAILLPLUS_SHA_DAEMON_SCRIPT}" stop
fi
local mailserver_ver=""
if [ -e "/var/packages/MailServer/INFO" ]; then
mailserver_ver=`get_key_value /var/packages/MailServer/INFO version | cut -d '-' -f2`
if [ 0459 -gt ${mailserver_ver} ]; then
GenerateMessage "error" "upgrade_mailserver"
exit 1;
fi
fi
# gen haproxy crt
if isDSM7OrAbove; then
/usr/local/share/certificate.d/MailPlus-Server gen_cert_only
else
/usr/local/libexec/certificate.d/MailPlus-Server gen_cert_only
fi
# create links
CreateLinks
LinkTinyMCEPlugins
# index help and add help to dsm
${DSM_INDEX_ADD} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
${DSM_INDEX_ADD} ${PKG_APP_PATH}/helptoc.conf ${PKG_INDEXDB_PATH}/helpindexdb
# move postfix queue folder to volume
CheckEnv
# update configs
UpdateConf
LogInit
#create migration data dir
if [ -d "/var/spool/@MailPlus-Server/" ]; then
local MIGRATION_DATA_DIR="/var/spool/@MailPlus-Server/migration_data"
mkdir -p "${MIGRATION_DATA_DIR}"
chmod 755 "${MIGRATION_DATA_DIR}"
chown MailPlus-Server:MailPlus-Server "${MIGRATION_DATA_DIR}"
fi
## License login first
${LICENSE_TOOL} "licenseLogin"
${MAILPLUS_SERVER_BACKEND_BINARY} "--isClusterInit"
local is_cluster_init=$?
if [ 0 -eq ${is_cluster_init} ]; then
checkClusterSettings
fi
## Start cluster
${CLUSTER_SCRIPT} start
##########################################
# Restore Hook Check
##########################################
if [ -e ${RESTORE_FLAG} ]; then
${BACKUP_RESTORE_TOOL} restore ${BACKUP_RESTORE_TEMP_DIR}
if [ 0 -ne $? ]; then
err_log "Restore config fail, so start fail"
GenerateMessage "error" "config_restore_fail"
exit 1
fi
rm -rf ${RESTORE_FLAG}
rm -rf ${BACKUP_RESTORE_TEMP_DIR}
#Upgrade activate db for restore
if [ -e ${RESTORE_UPGRADE_ACTIVATE_MEMBER_DB_200_FLAG} ]; then
if [ -e ${LICENSE_ACTIVE_DB} ]; then
err_log "config restore, upgrade to active_db new version, generate active_db dump file"
/bin/sqlite3 ${LICENSE_ACTIVE_DB} "SELECT * FROM active_member_table" > "${ACTIVEDB_DUMP_FILE}"
mv ${LICENSE_ACTIVE_DB} "${LICENSE_ACTIVE_DB_BKP}"
fi
rm ${RESTORE_UPGRADE_ACTIVATE_MEMBER_DB_200_FLAG}
fi
fi
##########################################
# Multiple Domains Upgrade Hook Check
##########################################
if [ -e ${UPGRADE_RELATED_SETTINGS_FOR_MULTIPLE_DOMAINS_FLAG} ]; then
info_log "prepare [upgrade related settings for multiple domains]"
info_log "prepare [upgrade related db for multiple domains]"
${MULTIPLE_DOMAIN_TOOL} "upgrade_related_db"
if [ 0 -ne $? ]; then
err_log "upgrade_related_db, so start fail"
exit 1
fi
info_log "done [upgrade related db for multiple domains]"
# Upgrade primary domain for multiple domains
if [ 0 -eq ${is_cluster_init} ]; then
info_log "prepare [upgrade primary domain for multiple domains]"
${MULTIPLE_DOMAIN_TOOL} "init_env"
if [ 0 -ne $? ]; then
# Jake: workaround for #2138, should find root cause
err_log "failed to [upgrade primary domain for multiple domains]"
# err_log "failed to [upgrade primary domain for multiple domains], so start fail"
# exit 1
fi
info_log "done [upgrade primary domain for multiple domains]"
fi
# Upgrade disclaimer for multiple domains
info_log "prepare [upgrade disclaimer for multiple domains]"
local DisclaimerList=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal mimedefang_disclaimers`
if [ -n "${DisclaimerList}" ] && [ x"${DisclaimerList:3:15}" != x"disclaimer_list" ]; then
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "mimedefang_disclaimers" "[{\"disclaimer_list\":${DisclaimerList}, \"domain_id\":1}]\n"
fi
info_log "done [upgrade disclaimer for multiple domains]"
# Upgrade dkim sign for multiple domains
info_log "prepare [upgrade dkim sign for multiple domains]"
local DKIMSignEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal enable_dkim_sign`
local DKIMSignSelector=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal dkim_selector`
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "enable_dkim_sign-1" ${DKIMSignEnable}
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "dkim_selector-1" ${DKIMSignSelector}
if [ -e "/var/packages/MailPlus-Server/etc/dkim.key/dkim.private" ]; then
mv "/var/packages/MailPlus-Server/etc/dkim.key/dkim.private" "/var/packages/MailPlus-Server/etc/dkim.key/dkim.private-1"
fi
if [ -e "/var/packages/MailPlus-Server/etc/dkim.key/dkim.public" ]; then
mv "/var/packages/MailPlus-Server/etc/dkim.key/dkim.public" "/var/packages/MailPlus-Server/etc/dkim.key/dkim.public-1"
fi
info_log "done [upgrade dkim sign for multiple domains]"
info_log "done [upgrade related settings for multiple domains]"
rm ${UPGRADE_RELATED_SETTINGS_FOR_MULTIPLE_DOMAINS_FLAG}
else
${MULTIPLE_DOMAIN_TOOL} "refresh"
fi
#create diclaimer_content_folder
if [ ! -e ${DISCLAIMER_CONTENT_FOLDER} ]; then
mkdir -p ${DISCLAIMER_CONTENT_FOLDER}
chmod 755 ${DISCLAIMER_CONTENT_FOLDER}
chown MailPlus-Server:MailPlus-Server ${DISCLAIMER_CONTENT_FOLDER}
fi
##########################################
# Disclaimer Upgrade Hook Check
##########################################
if [ -e ${UPGRADE_DISCLAIMER_FLAG} ]; then
info_log "upgrade disclaimer settings"
${DISCLAIMER_UPGRADE_TOOL} "upgrade"
if [ 0 -ne $? ]; then
err_log "upgrade disclaimer settings fail"
exit 1
fi
chown -R MailPlus-Server:MailPlus-Server ${DISCLAIMER_CONTENT_FOLDER}
rm -f ${UPGRADE_DISCLAIMER_FLAG}
fi
##########################################
# Disclaimer Upgrade Hook Check_v2
##########################################
if [ -e ${UPGRADE_DISCLAIMER_FLAG_V2} ]; then
info_log "upgrade_v2 disclaimer settings"
${DISCLAIMER_UPGRADE_TOOL} "upgrade_v2"
if [ 0 -ne $? ]; then
err_log "upgrade_v2 disclaimer settings fail"
exit 1
fi
rm -f ${UPGRADE_DISCLAIMER_FLAG_V2}
fi
##########################################
# License Version Upgrade Hook Check
##########################################
if [ -e ${UPGRADE_LICENSE_FLAG} ]; then
err_log "upgrade to license version, set related configs"
${LICENSE_TOOL} "setLicenseDefaultConfigs"
if [ 0 -ne $? ]; then
err_log "Set default license configs fail"
exit 1
fi
rm -rf ${UPGRADE_LICENSE_FLAG}
fi
##########################################
# Active DB Upgrade Hook
##########################################
if [ -e ${ACTIVEDB_DUMP_FILE} ]; then
${UPGRADE_ACTIVE_DB_TOOL} ${ACTIVEDB_DUMP_FILE}
${LICENSE_TOOL} "refreshUserGroupName"
if [ 0 -ne $? ]; then
err_log "upgrade active db fail"
exit 1
fi
rm -f ${ACTIVEDB_DUMP_FILE}
rm -f ${LICENSE_ACTIVE_DB_BKP}
rm -rf /var/spool/@MailPlus-Server/alias_bkp/*_active_list_db
fi
##########################################
# User group policy Upgrade Hook Check
##########################################
if [ 0 -eq ${is_cluster_init} ]; then
${USERGROUPPOLICY_TOOL} "refresh"
fi
if [ 0 -eq ${is_cluster_init} ]; then
${DELEGATION_TOOL} "refresh"
${MAILBOX_TOOL} "refresh_account_db"
fi
# Upgrade mimedefang runkey
if [ -e ${MIMEDEFANG_RUNKEY_UPGRADE_FLAG} ]; then
if [ 0 -eq ${is_cluster_init} ]; then
local AntiVirusEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal anti_virus_enable`
local SpamEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_enable`
local MCPEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal mcp_enable`
local ContentScanEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal enable_dangerous_content_scan`
if [ x"${SpamEnable}" = x"yes" -o x"${AntiVirusEnable}" = x"yes" -o x"${MCPEnable}" = x"yes" -o x"${ContentScanEnable}" = x"yes" ]; then
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "mimedefang_enable" "yes"
fi
rm ${MIMEDEFANG_RUNKEY_UPGRADE_FLAG}
fi
fi
# Upgrade relay to multi source
if [ -e ${RELAY_TO_MULTI_SOURCE_FLAG} ]; then
if [ x`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_enabled` = x"yes" ]; then
local RelayEnable=true
else
local RelayEnable=false
fi
local RelayServer=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_server`
local RelayPort=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_server_port`
if [ x`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_secure_conn` = x"yes" ]; then
local RelaySecureConn=true
else
local RelaySecureConn=false
fi
if [ x`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_auth_enabled` = x"yes" ]; then
local RelayAuthEnable=true
else
local RelayAuthEnable=false
fi
local RelayAuthAcc=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_account`
local RelayAuthPass=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_password`
# Convert from 1.4, add empty service_name in 'smtp_relay_client_single'
local RelayServerName=""
# To fix 2.0.0 relay bug, set keys when:
# 1. Upgrade from 1.4: redis key 'smtp_relay_client_host_type' doest not exist
# 2. Upgrade from 2.0.0 and relay settings is corrupted: still single relay, and the enable filed is missing
SmtpRelayClientSingle=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKey smtp_relay_client_single`
SmtpRelayClientHostType=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_relay_client_host_type`
hasEnable=`echo ${SmtpRelayClientSingle} | jq 'has("enable")'`
if [ -z "${SmtpRelayClientHostType}" ] || \
[[ ( "false" == "${hasEnable}" ) && ( "{\"host_type\":\"single\"}" == "${SmtpRelayClientHostType}" ) ]]; then
if [ "true" = "${RelayEnable}" ]; then
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "smtp_relay_client_host_type" "{\"host_type\":\"single\"}"
else
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "smtp_relay_client_host_type" "{\"host_type\":\"none\"}"
fi
${MAILPLUS_SERVER_BACKEND_BINARY} --setConfKeyVal "smtp_relay_client_single" "{\"server\":\"${RelayServer}\",\"port\":${RelayPort},\"security_connection\":${RelaySecureConn},\"enable_auth\":${RelayAuthEnable},\"auth_name\":\"${RelayAuthAcc}\",\"auth_password\":\"${RelayAuthPass}\",\"enable\":${RelayEnable},\"service_name\":\"${RelayServerName}\"}"
fi
rm ${RELAY_TO_MULTI_SOURCE_FLAG}
fi
CheckVlanChange
CheckIPChange
# install default main.cf and master.cf, for postmap and postalias
cp ${PRIVATE_LOCATION}/etc/template/main.template ${PRIVATE_LOCATION}/etc/main.cf
cp ${PRIVATE_LOCATION}/etc/template/master.template ${PRIVATE_LOCATION}/etc/master.cf
# install empty auth-master.conf.ext, delete master-users file
[ -f "${PRIVATE_LOCATION}/etc/dovecot/conf.d/master-users" ] && /bin/rm -f "${PRIVATE_LOCATION}/etc/dovecot/conf.d/master-users"
[ -f "${PRIVATE_LOCATION}/etc/dovecot/conf.d/auth-master.conf.ext" ] && /bin/rm -f "${PRIVATE_LOCATION}/etc/dovecot/conf.d/auth-master.conf.ext"
touch "${PRIVATE_LOCATION}/etc/dovecot/conf.d/auth-master.conf.ext"
chown --reference="${PRIVATE_LOCATION}/etc/template/auth-master.template" "${PRIVATE_LOCATION}/etc/dovecot/conf.d/auth-master.conf.ext"
chmod --reference="${PRIVATE_LOCATION}/etc/template/auth-master.template" "${PRIVATE_LOCATION}/etc/dovecot/conf.d/auth-master.conf.ext"
${PRIVATE_LOCATION}/bin/syno_db_util update mailserver
${PRIVATE_LOCATION}/bin/syno_db_util update alias
# generate default config and import old setting
${PRIVATE_LOCATION}/bin/syno_set_config smtp
${PRIVATE_LOCATION}/bin/syno_set_config rspamd
${PRIVATE_LOCATION}/bin/syno_set_config mimedefang
${PRIVATE_LOCATION}/bin/syno_set_config dovecot
${PRIVATE_LOCATION}/bin/syno_set_config init_empty_conf
${PRIVATE_LOCATION}/bin/syno_gen_login_map
${PRIVATE_LOCATION}/bin/syno_bcc_map
${PRIVATE_LOCATION}/bin/syno_set_config filter
${PRIVATE_LOCATION}/bin/syno_set_config global_access
${PRIVATE_LOCATION}/bin/syno_set_config dkim_sign_whitelist
# start mail server
# if service is enable, start daemon
SmtpEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal smtp_enabled`
if [ "$SmtpEnable" = "yes" ]; then
# start postfix server in background
# postfix will check if all the queue files are in right place before mail server can run.
# when there are huge mount of mails stuck in queue, it will take a long time to check.
# It might cost too much time to boot.
${PRIVATE_LOCATION}/scripts/PostfixCollection.sh start&
fi
# always start dovecot
${PRIVATE_LOCATION}/scripts/daemon/dovecot.sh start
##########################################
# Mailbox Seen-ACL Change Hook Check
##########################################
if [ -e ${UPGRADE_SHAREDMAILBOX_ACL_FLAG} ]; then
${SHAREDMAILBOX_ACL_UPGRADE_SCRIPT} &
rm -f ${UPGRADE_SHAREDMAILBOX_ACL_FLAG}
fi
local AntiVirusEnable="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal anti_virus_enable)"
local AntiVirusEngine="$(${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal anti_virus_engine)"
if [[ "${AntiVirusEnable}" == "yes" ]] && [[ "${AntiVirusEngine}" == "clamav" ]]; then
${PRIVATE_LOCATION}/scripts/daemon/clamav.sh start
elif [[ "${AntiVirusEnable}" == "yes" ]] && [[ "${AntiVirusEngine}" == "synoav-mcafee" ]]; then
${PRIVATE_LOCATION}/scripts/daemon/synoav_mcafee.sh start
elif [[ "${AntiVirusEnable}" == "yes" ]] && [[ "${AntiVirusEngine}" == "bitdefender" ]]; then
${PRIVATE_LOCATION}/scripts/daemon/bdamserver.sh start
fi
local SpamEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal spam_enable`
local MCPEnable=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal mcp_enable`
if [ x"${SpamEnable}" = x"yes" -o x"${AntiVirusEnable}" = x"yes" -o x"${MCPEnable}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/rspamd_redis.sh start
${PRIVATE_LOCATION}/scripts/daemon/rspamd.sh start
fi
local enable_dkim=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal enable_dkim`
if [ x"${enable_dkim}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/opendkim_verify.sh start
fi
local domain_id_list=`${MAILPLUS_SERVER_BACKEND_BINARY} --getDomainIDList`
local enable_dkim_sign="no"
for domain_id in ${domain_id_list}; do
local enable_domain_dkim_sign=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal enable_dkim_sign-$domain_id`
if [ x"${enable_domain_dkim_sign}" = x"yes" ]; then
enable_dkim_sign="yes"
break
fi
done
if [ x"${enable_dkim_sign}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/opendkim_sign.sh start
fi
# Default start mimedefang
local enable_mimedefang=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal mimedefang_enable`
if [ x"${enable_mimedefang}" != x"no" ]; then
${PRIVATE_LOCATION}/scripts/daemon/mimedefang.sh start
fi
local enable_dmarc=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal enable_dmarc`
if [ x"${enable_dmarc}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/opendmarc.sh start
fi
local enable_sender_quota=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal reject_sasl_sender_rate_exceed`
if [ x"${enable_sender_quota}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/memcached.sh start
fi
local enable_greylist=`${MAILPLUS_SERVER_BACKEND_BINARY} --getConfKeyVal greylist_enable`
if [ x"${enable_greylist}" = x"yes" ]; then
${PRIVATE_LOCATION}/scripts/daemon/greylist.sh start
fi
echo "Starting MailPlusServer Daemon..."
${MAIL_PLUS_DAEMON_SCRIPT} start
SetCrontab
#restore migration schedule task
${PRIVATE_LOCATION}/bin/syno_migration_task_util restore_all_schedule
ApplyFirewall
if [ 0 -eq ${is_cluster_init} ]; then
${LICENSE_TOOL} "checkMyDSLogin"
if [ 0 -eq $? ]; then
${LICENSE_TOOL} "upgradeMyDSAccountInAA"
${LICENSE_TOOL} "online_check"
else
${LICENSE_TOOL} "offline_check"
fi
${MAILPLUS_SERVER_BACKEND_BINARY} "--setVersion"
fi
# upgrade mcp quarantine
if [ -e ${MCP_QUARANTINE_UPGRADE_FLAG} ] && [ ! -e ${MCP_QUARANTINE_UPGRADE_PID} ]; then
if [ 0 -eq ${is_cluster_init} ]; then
${UPGRADE_QUARANTINE} "mcp" &
fi
fi
# upgrade virus quarantine
if [ -e ${VIRUS_QUARANTINE_UPGRADE_FLAG} ] && [ ! -e ${VIRUS_QUARANTINE_UPGRADE_PID} ]; then
if [ 0 -eq ${is_cluster_init} ]; then
${UPGRADE_QUARANTINE} "virus" &
fi
fi
update_process "/var/packages/MailPlus-Server/target/bin/poststart_updater"
clear_upgeade_file
}
stop()
{
# stop mcp quarantine upgration if it is running
killByPidFile "TERM" "${MCP_QUARANTINE_UPGRADE_PID}"
# stop virus quarantine upgration if it is running
killByPidFile "TERM" "${VIRUS_QUARANTINE_UPGRADE_PID}"
if ${CLUSTER_SCRIPT} status; then
## Remove "service_change" to avoid service forever syncing
${BACKEND_BINARY} "backend-command" --command del_dir --key "service_change"
fi
${CLUSTER_SCRIPT} stop
echo "Stop MailPlusServer Daemon..."
${MAIL_PLUS_DAEMON_SCRIPT} stop
echo "Stop Migrate daemon"
killByPidFile "TERM" "${MPSMigratePID}"
#stop migration task
${PRIVATE_LOCATION}/bin/syno_migration_task_util stop_all
#remove migration schedule task
${PRIVATE_LOCATION}/bin/syno_migration_task_util remove_all_schedule
#stop search task
${PRIVATE_LOCATION}/bin/stop_all_search
# stop mail server
${PRIVATE_LOCATION}/scripts/PostfixCollection.sh stop
${PRIVATE_LOCATION}/scripts/daemon/dovecot.sh stop
${PRIVATE_LOCATION}/scripts/daemon/director.sh stop
${PRIVATE_LOCATION}/scripts/daemon/haproxy.sh stop
${PRIVATE_LOCATION}/scripts/daemon/jieba.sh stop
${PRIVATE_LOCATION}/scripts/daemon/clamav.sh stop
${PRIVATE_LOCATION}/scripts/daemon/synoav_mcafee.sh stop
${PRIVATE_LOCATION}/scripts/daemon/bdamserver.sh stop
${PRIVATE_LOCATION}/scripts/daemon/greylist.sh stop
${PRIVATE_LOCATION}/scripts/daemon/rspamd_redis.sh stop
${PRIVATE_LOCATION}/scripts/daemon/rspamd.sh stop
${PRIVATE_LOCATION}/scripts/daemon/quota_clone.sh stop
# remove index and help entry
${DSM_INDEX_DEL} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
${DSM_INDEX_DEL} ${PKG_APP_PATH}/helptoc.conf ${PKG_INDEXDB_PATH}/helpindexdb
${PRIVATE_LOCATION}/scripts/daemon/opendkim_verify.sh stop
${PRIVATE_LOCATION}/scripts/daemon/opendkim_sign.sh stop
${PRIVATE_LOCATION}/scripts/daemon/mimedefang.sh stop
${PRIVATE_LOCATION}/scripts/daemon/opendmarc.sh stop
${PRIVATE_LOCATION}/scripts/daemon/memcached.sh stop
# remove mailserver firewall
${PRIVATE_LOCATION}/scripts/firewall.sh stop
UnSetCrontab
# clear links
ClearLinks
ClearTmpDir
UnlinkTinyMCEPlugins
LogStop
local NODE_NUM=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getPeersNum)
if [ ${NODE_NUM} -gt 1 ]; then
# Set interface blocked when there is a cluster
inet=$(${MAILPLUS_SERVER_BACKEND_BINARY} --getHostIF)
synonet --set_block ${inet} mailplus true
fi
/bin/rm ${MAILPLUS_SERVER_ENABLED}
RemovePreBuildDir
# remove user 'postfix' out of group 'MailPlus-Server'
synogroup --member MailPlus-Server
"${MAILLPLUS_SHA_DAEMON_SCRIPT}" stop
}
case $1 in
start)
isPackageEnable || exit 0
# start routine
start
exit 0
;;
stop)
stop
exit 0
;;
status)
if [ -e ${APP_PATH} ]; then
exit 0
else
exit 1
fi
;;
killall)
;;
log)
exit 0
;;
esac