postfixadmin/install_postfixadmin.sh

2817 lines
88 KiB
Bash
Executable File

#!/usr/bin/env bash
clear
echo -e "\n\t\033[32mStart script for installation Postfix Admin and vacation script..\033[m"
## ===================================================================
## - Install Postfixadmin
## ===================================================================
## -----------------------------------------------------------------
## ----------------------------------------------------------------
## ---
## --- For configurations see file conf/install_postfixadmin.conf
## ---
## --- Dont make changes here!
## ---
## -----------------------------------------------------------------
## -----------------------------------------------------------------
# -------------
# - Settings
# -------------
_src_base_dir="$(realpath $(dirname $0))"
#_src_base_dir=/usr/local/src/postfixadmin
conf_file="${_src_base_dir}/conf/install_postfixadmin.conf"
curdir=`pwd`
log_file="$(mktemp)"
declare -A check_entry_main_cf_arr
# -------------
# - Functions
# -------------
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
fatal(){
echo ""
echo -e "\t[ \033[31m\033[1mFatal\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m"
echo ""
exit 1
}
error(){
echo ""
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
echo ""
}
warn (){
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
}
info (){
echo ""
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
}
# - remove leading/trailling whitespaces
# -
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
echo_ok() {
echo -e "\033[75G[ \033[32mok\033[m ]"
## echo -e " [ ok ]"
}
echo_failed(){
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
## echo -e " [ failed ]"
}
echo_skipped() {
echo -e "\033[75G[ \033[30m\033[1mskipped\033[m ]"
}
if [ "$POSTFIX_DB_TYPE" = "postgres" -o "$POSTFIX_DB_TYPE" = "postgresql" -o "$POSTFIX_DB_TYPE" = "pgsql" -o "$POSTFIX_DB_TYPE" = "psql" ];then
POSTFIX_DB_TYPE=pgsql
fi
echo
echononl "\tInclude Configuration file.."
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'"
else
source $conf_file
echo_ok
fi
# - Default values
# -
DEFAULT_HTTP_USER="www-data"
DEFAULT_HTTP_GROUP="www-data"
DEFAULT_APACHE_LOG_DIR="/var/log/apache2"
DEFAULT_WEBSITE_BASEDIR="/var/www/${WEBSITE_NAME}"
DEFAULT_DEBIAN_APACHE_CERT_DIR="/etc/apache2"
DEFAULT_APACHE_CERT_DIR="/usr/local/apache2/conf"
DEFAULT_APACHE_SERVER_CERT="server-bundle.crt"
DEFAULT_APACHE_SERVER_KEY="server.key"
DEFAULT_DEBIAN_APACHE_VHOST_DIR="/etc/apache2/sites-available"
DEFAULT_APACHE_VHOST_DIR="/usr/local/apache2/conf/vhosts"
DEFAULT_POSTFIX_DB_HOST="localhost"
DEFAULT_POSTFIX_DB_NAME="postfix"
DEFAULT_POSTFIX_DB_USER="postfix"
DEFAULT_POSTFIX_DB_SOCKET_PG="/var/run/postgresql"
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="/etc/mysql/debian.cnf"
DEFAULT_MYSQL_CREDENTIALS="/usr/local/mysql/sys-maint.cnf"
DEFAULT_DOVEADM_PW="/usr/local/dovecot/bin/doveadm pw"
DEFAULT_DELETED_MAILBOX_DIR="/var/deleted-maildirs"
DEFAULT_DELETED_DOMAINS_DIR="/var/deleted-maildomains"
DEFAULT_VACATION_USER="vacation"
DEFAULT_VACATION_GROUP="vacation"
[[ -n "$PF_ADMIN_VERSION" ]] || fatal "Version of Postfix Admin to install (PF_ADMIN_VERSION) not present!"
[[ -n "$WEBSITE_NAME" ]] || fatal "Website's name (WEBSITE_NAME) not present!"
TLD=${WEBSITE_NAME##*.}
_tmp_string=${WEBSITE_NAME%.*}
MAIN_DOMAIN=${_tmp_string##*.}
DOMAIN="${MAIN_DOMAIN}.$TLD"
[[ -n "$WEBMASTER_EMAIL" ]] || WEBMASTER_EMAIL="admin@${MAIN_DOMAIN}.$TLD"
[[ -n "$IPV4" ]] || fatal "IPv4 Address (IPV4) not present!"
[[ -n "$IPV6" ]] || fatal "IPv4 Address (IPV6) not present!"
[[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false
httpd_binary="`which httpd`"
if [ -z "$httpd_binary" ]; then
httpd_binary="`ps -C httpd -f | grep -e \"^root\" | awk '{print$8}'`"
if [ -z "$httpd_binary" ]; then
if [ -x "/usr/local/apache2/bin/httpd" ]; then
httpd_binary="/usr/local/apache2/bin/httpd"
fi
fi
fi
if [ -x "$httpd_binary" ];then
# - Determin websever user
# -
HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
# - Is webserver running ?
# -
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
if [[ "X${PID}X" = "XX" ]] ;then
IS_HTTPD_RUNNING=false
else
IS_HTTPD_RUNNING=true
fi
fi
[[ -n "$WEBMASTER_EMAIL" ]] || fatal "E-Mail (WEBMASTER_EMAIL) for webmaster not present!"
[[ -n "$WEBSITE_BASEDIR" ]] || WEBSITE_BASEDIR=$DEFAULT_WEBSITE_BASEDIR
if [[ -z "$APACHE_CERT_DIR" ]] ; then
if $APACHE_DEBIAN_INSTALLATION ; then
APACHE_CERT_DIR="$DEFAULT_DEBIAN_APACHE_CERT_DIR"
else
APACHE_CERT_DIR="$DEFAULT_APACHE_CERT_DIR"
fi
fi
[[ -n "$APACHE_SERVER_CERT" ]] || APACHE_SERVER_CERT=$DEFAULT_APACHE_SERVER_CERT
[[ -n "$APACHE_SERVER_KEY" ]] || APACHE_SERVER_KEY=$DEFAULT_APACHE_SERVER_KEY
[[ -n "$APACHE_LOG_DIR" ]] || APACHE_LOG_DIR=$DEFAULT_APACHE_LOG_DIR
if [[ -z "$PHP_TYPE" ]]; then
PHP_TYPE="php_fpm"
else
[[ "$PHP_TYPE" = "php_fpm" ]] || [[ "$PHP_TYPE" = "fcgid" ]] || [[ "$PHP_TYPE" = "mod_php" ]] || fatal "Wrong type of PHP (PHP_TYPE) given!"
fi
if [[ -z "$APACHE_VHOST_DIR" ]] ; then
if $APACHE_DEBIAN_INSTALLATION ; then
APACHE_VHOST_DIR="$DEFAULT_DEBIAN_APACHE_VHOST_DIR"
else
APACHE_VHOST_DIR="$DEFAULT_APACHE_VHOST_DIR"
fi
fi
[[ -n "$AUTOREPLY_HOSTNAME" ]] || AUTOREPLY_HOSTNAME=autoreply.${MAIN_DOMAIN}.$TLD
[[ -n "$AUTOREPLY_HOSTNAME" ]] || AUTOREPLY_HOSTNAME=autoreply.${MAIN_DOMAIN}.$TLD
[[ -n "$POSTFIX_DB_TYPE" ]] || fatal "Database Type of Postfix Database (POSTFIX_DB_TYPE) not present!"
[[ -n "$POSTFIX_DB_HOST" ]] || POSTFIX_DB_HOST="$DEFAULT_POSTFIX_DB_HOST"
[[ -n "$POSTFIX_DB_NAME" ]] || POSTFIX_DB_NAME="$DEFAULT_POSTFIX_DB_NAME"
[[ -n "$POSTFIX_DB_USER" ]] || POSTFIX_DB_USER="$DEFAULT_POSTFIX_DB_USER"
[[ -n "$POSTFIX_DB_PASS" ]] || fatal "Password of Postfix Database (POSTFIX_DB_PASS) not given!"
if [[ -n "$POSTFIX_DB_SOCKET" ]]; then
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
fatal "MySQL Socket (POSTFIX_DB_SOCKET) is not supported by this script"
fi
else
POSTFIX_DB_SOCKET="$DEFAULT_POSTFIX_DB_SOCKET_PG"
fi
[[ -n "$MYSQL_DEBIAN_INSTALLATION" ]] || MYSQL_DEBIAN_INSTALLATION=false
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
if $MYSQL_DEBIAN_INSTALLATION ; then
[[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_DEBIAN_MYSQL_CREDENTIALS"
else
[[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_MYSQL_CREDENTIALS"
fi
else
[[ "$POSTFIX_DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$POSTFIX_DB_TYPE' (POSTFIX_DB_TYPE)"
fi
[[ -n "$ENCRYPTION_METHOD" ]] || fatal "Encryption method for Passwords (ENCRYPTION_METHOD) not set!"
if [[ "$ENCRYPTION_METHOD" =~ dovecot ]]; then
[[ -n "$DOVEADM_PW" ]] || DOVEADM_PW=$DEFAULT_DOVEADM_PW
fi
[[ -n "$DELETED_MAILBOX_DIR" ]] || DELETED_MAILBOX_DIR=$DEFAULT_DELETED_MAILBOX_DIR
[[ -n "$DELETED_DOMAINS_DIR" ]] || DELETED_DOMAINS_DIR=$DEFAULT_DELETED_DOMAINS_DIR
# - Vacation
# -
[[ -n "$VACATION_USER" ]] || VACATION_USER=$DEFAULT_VACATION_USER
[[ -n "$VACATION_GROUP" ]] || VACATION_GROUP=$DEFAULT_VACATION_GROUP
# - Determin PHP of all installed versions
# -
echononl "\tGet major numbers of all installed PHP versions"
php_major_versions=`find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort`
if [[ -z "$php_major_versions" ]]; then
echo_failed
error "Getting major numbers of installed PHP versions failed! No installed PHP versiond found!"
else
echo_ok
fi
# - Get the latest PHP version
# -
echononl "\tGet major number of latest installed PHP version"
php_latest_ver=""
if [[ -n "$php_major_versions" ]]; then
for _ver in $php_major_versions ; do
if [[ -z "$php_latest_ver" ]] ; then
php_latest_ver=$_ver
elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then
php_latest_ver=$_ver
elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then
[[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver
fi
done
echo_ok
else
echo_skipped
warn "Getting major number of latest installed PHP version failed! - No installed PHP versiond found!"
fi
# - Is 'systemd' supported on this system
# -
if [ "X`which systemd`" = "X" ]; then
SYSTEMD_EXISTS=false
else
SYSTEMD_EXISTS=true
fi
echo ""
echo ""
echo -e "\033[1;32mSettings for installation of \033[1;37mPostfix Admin / Vacation\033[m"
echo ""
echo -e "\tPostfix Admin Version................: $PF_ADMIN_VERSION"
echo ""
echo -e "\tName of the Website..................: $WEBSITE_NAME"
echo ""
echo -e "\tIPv4 Address.........................: $IPV4"
echo -e "\tIPv6 Address.........................: $IPV6"
echo ""
echo -e "\tApache from Debian Package System....: $APACHE_DEBIAN_INSTALLATION"
echo -e "\tApache User..........................: $HTTP_USER"
echo -e "\tApache Group.........................: $HTTP_GROUP"
echo -e "\tApache VHOST Directory...............: $APACHE_VHOST_DIR"
echo -e "\tApache LOG Directory.................: $APACHE_LOG_DIR"
echo ""
echo -e "\tApache Cert directory................: $APACHE_CERT_DIR"
echo -e "\tWebsite Certificate..................: $APACHE_SERVER_CERT"
if [[ -n "$CERT_ChainFile" ]] ; then
echo -e "\tCertificate Chain File...............: $CERT_ChainFile"
fi
echo -e "\tWebsite Key..........................: $APACHE_SERVER_KEY"
echo ""
echo -e "\tWebmasters E-Mail Address............: $WEBMASTER_EMAIL"
echo -e "\tBase Directory of PFA Website........: $WEBSITE_BASEDIR"
echo ""
echo -e "\tType of PHP connection...............: $PHP_TYPE"
echo ""
echo -e "\tInstalled PHP versions...............: $php_major_versions"
echo -e "\tNewest PHP Version...................: $php_latest_ver"
echo ""
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
echo -e "\tDatabase type of Postfix Database....: MySQL"
echo -e "\tMySQL from Debian Package System.....: $MYSQL_DEBIAN_INSTALLATION"
else
echo -e "\tDatabase type of Postfix Database....: PostgreSQL"
fi
echo -e "\tHost of Postfix Database.............: $POSTFIX_DB_HOST"
echo -e "\tName of Postfix Database.............: $POSTFIX_DB_NAME"
echo -e "\tUser of Postfix Database.............: $POSTFIX_DB_USER"
echo -e "\tPassword of Postfix Database.........: $POSTFIX_DB_PASS"
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
echo -e "\tMySQL Credentials (root access)......: $MYSQL_CREDENTIALS"
fi
echo ""
echo -e "\tEncryption Method used for Passwords.: $ENCRYPTION_METHOD"
if [[ "$ENCRYPTION_METHOD" =~ dovecot ]]; then
echo -e "\t'doveadm' binary.....................: $DOVEADM_PW"
fi
echo ""
echo -e "\tDirectory for deleted mailboxes......: $DELETED_MAILBOX_DIR"
echo -e "\tDirectory for deleted mail domains...: $DELETED_DOMAINS_DIR"
echo ""
echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME"
echo -e "\tUser of vacation script..............: $VACATION_USER"
echo -e "\tGroup of vacation script.............: $VACATION_GROUP"
echo ""
echo -e "\tSystem supports systemd..............: $SYSTEMD_EXISTS"
echo ""
echo ""
echo ""
echo -n "Type upper case 'YES' to continue executing with this parameters: "
read OK
if [[ "$OK" = "YES" ]] ; then
echo ""
echo ""
echo -e "\t\033[1;32mGoing to install Postfix Admin / Vacation \033[1;37m\033[m"
else
fatal "Abort by user request - Answer as not 'YES'"
fi
_log_dir=${_src_base_dir}/log-postfixadmin-$_version
echo -e "\n\n\t\033[37m\033[1mPre-installion tasks ..\033[m\n"
# - Datenbank etstellen:
# -
# - MySQL/PostgreSQL Datenbank erstellen
# -
# -
_failed=false
> $log_file
echononl "\tCreate Postfix Database '$POSTFIX_DB_NAME'"
if [ "$POSTFIX_DB_TYPE" = "mysql" ]; then
echo -n " (MySQL).."
if ! mysql $mysql_credential_args -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$POSTFIX_DB_NAME'" 2>> $log_file \
| grep $POSTFIX_DB_NAME >> $log_file 2>&1 ; then
mysql $mysql_credential_args -N -s -e \
"CREATE DATABASE IF NOT EXISTS $POSTFIX_DB_NAME CHARACTER SET utf8 COLLATE utf8_general_ci" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
mysql $mysql_credential_args -N -s -e \
"GRANT ALL ON $POSTFIX_DB_NAME.* TO '$POSTFIX_DB_USER'@'localhost' IDENTIFIED BY '$POSTFIX_DB_PASS'" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
mysql $mysql_credential_args -N -s -e "FLUSH PRIVILEGES" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
if $_failed; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
elif [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
echo -n " (PostgreSQL).."
count=`su - postgres -c "psql -q -A -t -l" | grep -c -e "^$POSTFIX_DB_NAME"`
if [ $count -eq 0 ];then
echo "CREATE ROLE $POSTFIX_DB_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$POSTFIX_DB_PASS'" \
| su - postgres -c "psql" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
su - postgres -c "createdb -E utf8 -O $POSTFIX_DB_USER $POSTFIX_DB_NAME" >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
if $_failed; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
fi
echononl "\tInstall needed debian packages.."
needed_packages=""
_needed_packages="
libdbi-perl
libmime-encwords-perl
libemail-valid-perl
libmail-sendmail-perl
liblog-log4perl-perl
libmail-sender-perl
libdbi-dev
cpanminus"
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]] ; then
_needed_packages="$_needed_packages
libdbd-pgsql
libdbd-pg-perl
libdbi-perl
libdbi-dev"
else
_needed_packages="$_needed_packages
libdbd-mysql
libdbd-mysql-perl"
fi
for _pkg in $_needed_packages ; do
if aptitude search "$_pkg" | grep " $_pkg " | grep -e "^i" > /dev/null 2>&1 ; then
continue
else
needed_packages="$needed_packages $_pkg"
fi
done
if [[ -n "$needed_packages" ]]; then
DEBIAN_FRONTEND=noninteractive apt-get -y install $needed_packages > /dev/null 2> "$log_file"
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tInstall database related CPAN Modules"
_failed=false
> $log_file
_needed_cpan_modules="
CPAN
DBI"
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]] ; then
_needed_cpan_modules="$_needed_cpan_modules
DBD::Pg"
else
_needed_cpan_modules="$_needed_cpan_modules
DBD::mysql"
fi
for _module in $_needed_cpan_modules ; do
cpanm -q --skip-installed $_module >> "$log_file" 2>&1
if [[ "$?" -ne 0 ]] ; then
error "$(cat $tmp_err_msg)"
fi
done
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
echo -e "\n\n\t\033[37m\033[1mBase install Postfixadmin..\033[m\n"
# - Get postfixadmin sources if not yet downloaded
# -
echononl "\tDownload 'postfixadmin-${PF_ADMIN_VERSION}'.."
if [[ ! -f "${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz" ]];then
wget -O ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-${PF_ADMIN_VERSION}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tBackup existing source directory 'postfixadmin-${PF_ADMIN_VERSION}'.."
if [[ -d "${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}" ]]; then
mv ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION} \
${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.$(date +%Y%m%d-%H%M)
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tUnpack 'postfixadmin-${PF_ADMIN_VERSION}.."
gunzip < ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz | tar -C ${_src_base_dir} -xf - 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate '$WEBSITE_BASEDIR'.."
if [[ ! -d "$WEBSITE_BASEDIR" ]]; then
mkdir $WEBSITE_BASEDIR > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tBackup existing web-directory 'postfixadmin-${PF_ADMIN_VERSION}'.."
if [[ -d "${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}" ]]; then
mv ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION} \
${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}.`date +%Y%m%d-%H%M` > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCopy Postfix Admin Directory to web-directory"
cp -a ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION} ${WEBSITE_BASEDIR}/
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_failed=false
echononl "\tSet Permissions on \n\t ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}"
find ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION} -type f -print0 2> $log_file \
| xargs -0 chmod 640 2>> $log_file
if [[ $? -ne 0 ]] ; then
_failed=true
fi
find ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION} -type f -print0 2>> $log_file \
| xargs -0 chown root:$HTTP_GROUP 2>> $log_file
if [[ $? -ne 0 ]] ; then
_failed=true
fi
find ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION} -type d -print0 2>> $log_file \
| xargs -0 chown root:$HTTP_GROUP 2>> $log_file
if [[ $? -ne 0 ]] ; then
_failed=true
fi
chown -R ${HTTP_USER}:$HTTP_GROUP ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/templates_c >> $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
if $_failed; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
echononl "\tRemove existing symlink '${WEBSITE_BASEDIR}/htdocs'"
if [[ -h "${WEBSITE_BASEDIR}/htdocs" ]]; then
rm ${WEBSITE_BASEDIR}/htdocs
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate Symlink for DocumentRoot Directory 'htdocs'.."
if [[ ! -h "${WEBSITE_BASEDIR}/htdocs" ]]; then
ln -s postfixadmin-${PF_ADMIN_VERSION} ${WEBSITE_BASEDIR}/htdocs > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for FastCGI PHP Connections (mod_fcgid)..\033[m\n"
elif [[ "$PHP_TYPE" = "php_fpm" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for PHP-FPM Connection ..\033[m\n"
elif [[ "$PHP_TYPE" = "mod_php" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for PHP Connection using Apache's mod_php..\033[m\n"
else
fatal "Wrong PHP Type '$PHP_TYPE' (PHP_TYPE)!"
fi
echononl "\tCreate Log Directory '$APACHE_LOG_DIR'.."
if [[ ! -d "$APACHE_LOG_DIR" ]]; then
mkdir $APACHE_LOG_DIR > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
_dirs="${WEBSITE_BASEDIR}/sessions ${WEBSITE_BASEDIR}/tmp ${WEBSITE_BASEDIR}/logs"
for _dir in $_dirs ; do
echononl "\tCreate Directory '$_dir'"
if [[ ! -d "$_dir" ]]; then
mkdir $_dir > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissons on '$_dir'.."
chown ${HTTP_USER}:${HTTP_GROUP} $_dir > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
done
echononl "\tCreate directory '${WEBSITE_BASEDIR}/conf'.."
if [[ ! -d "${WEBSITE_BASEDIR}/conf" ]]; then
mkdir ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 750 ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
for _version in $php_major_versions ; do
echononl "\tPlace file '${WEBSITE_BASEDIR}/conf/php.ini-$_version'"
cp /usr/local/php-${_version}/etc/php.ini ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 640 ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/conf/fcgid-$_version'.."
cat <<EOF > ${WEBSITE_BASEDIR}/conf/fcgid-$_version 2> $log_file
#!/bin/sh
export PHPRC="${WEBSITE_BASEDIR}/conf/"
export TMPDIR="${WEBSITE_BASEDIR}/tmp"
# PHP child process management (PHP_FCGI_CHILDREN) should
# always be disabled with mod_fcgid, which will only route one
# request at a time to application processes it has spawned;
# thus, any child processes created by PHP will not be used
# effectively. (Additionally, the PHP child processes may not
# be terminated properly.) By default, and with the environment
# variable setting PHP_FCGI_CHILDREN=0, PHP child process
# management is disabled.
PHP_FCGI_CHILDREN=0
export PHP_FCGI_CHILDREN
exec /usr/local/php-${_version}/bin/php-cgi
EOF
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf/fcgid-$_version'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 750 ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
done
# - Create Symlinks in fcgid's config directory
# -
if [[ "$_version" = "$php_latest_ver" ]]; then
echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/php.ini'.."
if [[ ! -h "${WEBSITE_BASEDIR}/conf/php.ini" ]]; then
ln -s php.ini-$_version ${WEBSITE_BASEDIR}/conf/php.ini > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/fcgid'.."
if [[ ! -h "${WEBSITE_BASEDIR}/conf/fcgid" ]]; then
ln -s fcgid-$_version ${WEBSITE_BASEDIR}/conf/fcgid > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/conf/changes.php.ini.txt'.."
cat << EOF > ${WEBSITE_BASEDIR}/conf/changes.php.ini.txt
error_log = "${WEBSITE_BASEDIR}/logs/php_errors.log"
sys_temp_dir = "${WEBSITE_BASEDIR}/tmp"
upload_tmp_dir = "${WEBSITE_BASEDIR}/tmp"
session.save_path = "${WEBSITE_BASEDIR}/sessions"
soap.wsdl_cache_dir = "${WEBSITE_BASEDIR}/tmp"
EOF
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/logs/php_errors.log'.."
if [[ ! -f "${WEBSITE_BASEDIR}/logs/php_errors.log" ]]; then
touch ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chown ${HTTP_USER}:${HTTP_GROUP} ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
else
echo_skipped
fi
_php_ini_file="${WEBSITE_BASEDIR}/conf/php.ini-*"
echononl "\tAdjust files '${WEBSITE_BASEDIR}/conf/php.ini-*'.."
_failed=false
_key=error_log
_val="${WEBSITE_BASEDIR}/logs/php_errors.log"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="sys_temp_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="upload_tmp_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="session.save_path"
_val="${WEBSITE_BASEDIR}/sessions"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="soap.wsdl_cache_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
fi
echo -e "\n\n\t\033[37m\033[1mConfigure Apache Webservice\033[m\n"
SSLCertificateChainFile=""
# - Create SSCertificateChainFile rule for apache vhost entry
# -
echononl "\tCreate SSCertificateChainFile rule for apache vhost entry"
if [ -n "$CERT_ChainFile" ];then
SSLCertificateChainFile="SSLCertificateChainFile ${APACHE_CERT_DIR}/$CERT_ChainFile"
echo_ok
else
echo_skipped
fi
echo ""
# - Save existing vhost file
# -
echononl "\tSave existing vhost file.."
if [ -f ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ];then
if [[ -f "${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf" ]]; then
mv ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf.`date +%Y%m%d-%H%M` > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
else
echo_skipped
fi
echononl "\tCreate VHost Configuration '${WEBSITE_NAME}.conf'.."
_failed=false
cat <<EOF > ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
# -- $WEBSITE_NAME -- #
<VirtualHost $IPV4:80>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
<VirtualHost $IPV4:443>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
if [[ "$PHP_TYPE" = "mod_php" ]] ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
## -
php_admin_value upload_tmp_dir "${WEBSITE_BASEDIR}/tmp/"
php_admin_flag log_errors on
php_admin_value error_log "${WEBSITE_BASEDIR}/logs/php_error.log"
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
elif [[ "$PHP_TYPE" = "fcgid" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<Directory "${WEBSITE_BASEDIR}/htdocs">
Require all granted
FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
elif [[ "$PHP_TYPE" = "php_fpm" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SSLEngine on
# - HTTP Strict Transport Security (HSTS)
# -
# - HSTS tells a browser that the website should only be accessed through
# - a secure connection. The HSTS header will be remembered by a standard
# compliant browser for max-age seconds.
# -
# - Remember this settings for 1 year
# -
Header always set Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY
$SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
# ---
# --- IPv6
# ---
<VirtualHost [$IPV6]:80>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
<VirtualHost [$IPV6]:443>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if [[ "$PHP_TYPE" = "mod_php" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
## -
php_admin_value upload_tmp_dir "${WEBSITE_BASEDIR}/tmp/"
php_admin_flag log_errors on
php_admin_value error_log "${WEBSITE_BASEDIR}/logs/php_error.log"
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
elif [[ "$PHP_TYPE" = "fcgid" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<Directory "${WEBSITE_BASEDIR}/htdocs">
Require all granted
FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
elif [[ "$PHP_TYPE" = "php_fpm" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SSLEngine on
# - HTTP Strict Transport Security (HSTS)
# -
# - HSTS tells a browser that the website should only be accessed through
# - a secure connection. The HSTS header will be remembered by a standard
# compliant browser for max-age seconds.
# -
# - Remember this settings for 1 year
# -
Header always set Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY
$SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
if $APACHE_DEBIAN_INSTALLATION ; then
## - add to /etc/apache2/ports.conf
## -
## - NameVirtualHost 46.4.73.217:80
## - NameVirtualHost [2a01:4f8:140:34c1::4]:80
## - Listen 46.4.73.217:80
## - Listen [2a01:4f8:140:34c1::4]:80
## - <IfModule mod_ssl.c>
## - ..
## - NameVirtualHost 46.4.73.217:443
## - NameVirtualHost [2a01:4f8:140:34c1::4]:443
## - Listen 46.4.73.217:443
## - Listen [2a01:4f8:140:34c1::4]:443
## - </IfModule>
## - ..
#vim /etc/apache2/ports.conf
## - enable site webmail.warenform.de
## -
echononl "\tEnable ${WEBSITE_NAME}.conf"
a2ensite ${WEBSITE_NAME}.conf > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
echononl "\tCreate 'robots.txt'.."
cat <<EOF > ${WEBSITE_BASEDIR}/htdocs/robots.txt 2> $log_file
User-agent: *
Disallow: /
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tRestart Apache Webservice.."
if $APACHE_DEBIAN_INSTALLATION ; then
/etc/init.d/apache2 reload > $log_file 2>&1
else
/etc/init.d/apache2 restart > $log_file 2>&1
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\n\n\t\033[37m\033[1mInstall Vacation\033[m\n"
echononl "\tCreate system group '$VACATION_GROUP'"
if ! grep -q "$VACATION_GROUP" /etc/group /etc/group > /dev/null 2>&1 ; then
addgroup --system --gid 65501 $VACATION_GROUP > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl "\tCreate system user '$VACATION_USER'"
if ! grep -q "$VACATION_USER" /etc/passwd > /dev/null 2>&1 ; then
adduser --system --home /var/spool/vacation --no-create-home --uid 65501 --gid 65501 --shell /usr/sbin/nologin $VACATION_USER > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl "\tCreate directory '/var/spool/vacation'"
if [[ ! -d "/var/spool/vacation" ]]; then
mkdir /var/spool/vacation > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl "\tSet Permissions on directoy '/var/spool/vacation'"
chown -R ${VACATION_USER}:$VACATION_GROUP /var/spool/vacation > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
echononl "\tBackup existing script 'vacation.pl'"
if [[ -f "/var/spool/vacation/vacation.pl" ]] ; then
mv /var/spool/vacation/vacation.pl /var/spool/vacation/vacation.pl.$(date +%Y%m%d-%H%M) > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl "\tCopy vacation script to '/var/spool/vacation/vacation.pl'"
_vacacion_script="$(find ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION} -type f -name vacation.pl -print 2>/dev/null)"
if [[ -z "$(trim "$_vatacion_script")" ]] ; then
cp -a ${_vacacion_script} /var/spool/vacation/ > "$log_file" 2>&1
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
error "Vacation script not found!"
fi
# - Encoding does not work as exspected.
# -
# - NOTE:
# - this IS NOT a fix, but a workaround
# -
echononl "\tWorkaround, because encoding does not work as exspected."
perl -i -n -p -e "s/(\s*\'ctype\'\s* =>\s*)\'text\/plain.*$/\1\'text\/plain; charset=iso-8859-1\',/" \
/var/spool/vacation/vacation.pl > "$log_file" 2>&1
if [[ $? -eq 0 ]];then
echo_ok
info "This IS NOT a fix, but a workaround."
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permission on vacation script"
_failed=false
chown ${VACATION_USER}:$VACATION_GROUP /var/spool/vacation/vacation.pl > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
chmod 700 /var/spool/vacation/vacation.pl > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ;then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
# - Script vacation.pl tries to reads setting from
# -
# - /etc/mail/postfixadmin/vacation.conf
# - /etc/postfixadmin/vacation.conf
# -
# - Instead of changing this script, we put the needed entries
# - to file /etc/postfixadmin/vacation.conf:
# -
echononl "\tCreate directory '/etc/postfixadmin' "
if [[ ! -d "/etc/postfixadmin" ]]; then
mkdir /etc/postfixadmin > "$log_file" 2>&1
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tBackup existing file '/etc/postfixadmin/vacation.conf'"
if [[ -f "/etc/postfixadmin/vacation.conf" ]]; then
mv /etc/postfixadmin/vacation.conf /etc/postfixadmin/vacation.conf.$(date +%Y%m%d-%H%M) > "$log_file" 2>&1
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - Create configuration file '/etc/postfixadmin/vacation.conf'
# -
echononl "\tCreate configuration file '/etc/postfixadmin/vacation.conf'"
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
_db_type="Pg"
else
_db_type="mysql"
fi
cat <<EOF > /etc/postfixadmin/vacation.conf 2> "$log_file"
\$db_type = '$_db_type';
\$db_username = '${POSTFIX_DB_USER}';
\$db_password = '${POSTFIX_DB_PASS}';
\$db_name = '${POSTFIX_DB_NAME}';
\$vacation_domain = '${AUTOREPLY_HOSTNAME}';
\$syslog = 0;
\$log_to_file = 1;
\$logfile = '/var/log/vacation.log';
\$log_level = 1;
\$interval = 60*60*24;
EOF
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate logfile /var/log/vacation.log"
touch /var/log/vacation.log > "$log_file" 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet permissions on /var/log/vacation.log"
chown ${VACATION_USER}:$VACATION_GROUP /var/log/vacation.log > "$log_file" 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tConfigure logrotation for '/var/log/vacation.log'"
cat <<EOF > /etc/logrotate.d/vacation 2> "$log_file"
/var/log/vacation.log {
daily
start 0
rotate 7
missingok
compress
delaycompress
notifempty
create 640 vacation vacation
copytruncate
}
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# - Create an entry in /etc/hosts for the (non-existant domain)
# - $AUTOREPLY_HOSTNAME
# -
# - add:
# -
# - 127.0.0.1 $AUTOREPLY_HOSTNAME
# -
echononl "\tCreate entry in /etc/hosts for '$AUTOREPLY_HOSTNAME'"
if ! grep -q "$AUTOREPLY_HOSTNAME" /etc/hosts > $log_file 2>&1 ; then
perl -i -n -p -e"s#(^\s*127.0.0.1\s+localhost.*)#\1\n\n127.0.0.1 ${AUTOREPLY_HOSTNAME}" /etc/hosts > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - Define the transport type in the Postfix master file
# - /etc/postfix/master.cf
# -
# - vacation unix - n n - - pipe
# - flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}
# -
echononl "\tDefine transport for vacation in /etc/postfix/master.cf"
if ! grep -q -E "^\s*vacation\s+unix" /etc/postfix/master.cf > $log_file 2>&1 ; then
cat <<EOF >> /etc/postfix/master.cf
vacation unix - n n - - pipe
flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f \${sender} -- \${recipient}
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - Setup the transport maps file /etc/postfix/transport
# -
# - add line:
# -
# - $AUTOREPLY_HOSTNAME vacation:
# -
echononl "\tSetup the transport maps for vacation domain in '/etc/postfix/transport'"
if ! grep -q -E "^\s*$AUTOREPLY_HOSTNAME\s+vacation:" /etc/postfix/transport > $log_file 2>&1 ; then
_failed=false
echo "$AUTOREPLY_HOSTNAME vacation:" >> /etc/postfix/transport 2> $log_file
if [[ $? -ne 0 ]] ; then
_failed=true
fi
postmap btree:/etc/postfix/transport > $log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
fi
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ;then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
check_entry_main_cf_arr["transport_maps"]="btree:/etc/postfix/transport"
# - Add 'btree:/etc/postfix/transport' ton parameter transport_maps in /etc/postfix/main.cf
# -
# - take care the entry for transport_maps in /etc/postfix/main.cf
# - contains "btree:/etc/postfix/transport"
# -
echononl "\tAdd 'btree:/etc/postfix/transport' to parameter transport_maps"
if ! grep -q "btree:/etc/postfix/transport" /etc/postfix/main.cf > $log_file 2>&1 ; then
perl -i -n -p -e "s#(^transport_maps\s+=.*)#\1\n btree:/etc/postfix/transport#" /etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tReload/Restart postfix"
if $SYSTEMD_EXISTS ; then
systemctl reload postfix > $log_file 2>&1
else
/etc/init.d/postfix reload > $log_file 2>&1
fi
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\n\n\t\033[37m\033[1mConfigure Postfix Admin\033[m\n"
pfa_conf_file=${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php
# - Use 'Re: $SUBJECT' as the default subject template for vacation
# - in postfixadmin
# -
echononl "\tUse 'Re: \$SUBJECT' as default subject of autorespons messages"
perl -i -n -p -e "s#(^\s*\\\$PALANG\['pUsersVacation_subject_text'\].*$)#\#\1\n\\\$PALANG['pUsersVacation_subject_text'] = 'Re: \\\$SUBJECT';#" ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/languages/*.lang > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tAdjust file 'languages/de.lang'"
perl -i -n -p -e "s#^(\s*\\\$PALANG\['reply_every_mail'\]\s+=.*)#\1\n\\\$PALANG['reply_once_per_day'] = 'Einmal pro Tag antworten';#" \
${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/languages/de.lang >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$PALANG\['reply_every_mail'\]\s+=.*)#\1\n\\\$PALANG['reply_once_per_day'] = 'Reply once per day';#" \
${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/languages/en.lang >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
## - Adjust Postfix Admin's Configuration - Part 1
## -
## - configure postfixadmin
## -
## - edit file config.inc.php
## -
## - set:
## -
## - $CONF['default_language'] = 'de';
## - $CONF['database_type'] = '$POSTFIX_DB_TYPE';
## - $CONF['database_host'] = 'localhost';
## - $CONF['database_user'] = '$POSTFIX_DB_USER';
## - $CONF['database_password'] = '$POSTFIX_DB_PASS';
## - $CONF['database_name'] = '$POSTFIX_DB_NAME';
## - $CONF['database_prefix'] = '';
## - $CONF['admin_email'] = '$WEBMASTER_EMAIL';
## - $CONF['encrypt'] = '$ENCRYPTION_METHOD';
## - $CONF['dovecotpw'] = "$DOVEADM_PW";
## -
echo ""
echononl "\tAdjust Postfix Admin's Configuration - Part 1"
_failed=false
> $log_file
perl -i.ORIG -n -p -e "s#^(\s*\\\$CONF\['default_language'\]\s*=.*)#//!\1\n\\\$CONF['default_language'] = 'de';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_type'\]\s*=.*)#//!\1\n\\\$CONF['database_type'] = '$POSTFIX_DB_TYPE';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_host'\]\s*=.*)#//!\1\n\\\$CONF['database_host'] = 'localhost';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_user'\]\s*=.*)#//!\1\n\\\$CONF['database_user'] = '$POSTFIX_DB_USER';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_password'\]\s*=.*)#//!\1\n\\\$CONF['database_password'] = '$POSTFIX_DB_PASS';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_name'\]\s*=.*)#//!\1\n\\\$CONF['database_name'] = '$POSTFIX_DB_NAME';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_prefix'\]\s*=.*)#//!\1\n\\\$CONF['database_prefix'] = '';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['admin_email'\]\s*=.*)#//!\1\n\\\$CONF['admin_email'] = '$WEBMASTER_EMAIL';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['encrypt'\]\s*=.*)#//!\1\n\\\$CONF['encrypt'] = '$ENCRYPTION_METHOD';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['dovecotpw'\]\s*=.*)#//!\1\n\\\$CONF['dovecotpw'] = '$DOVEADM_PW';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
## - Adjust Postfix Admin's Configuration - Part 2
## -
## - $CONF['default_aliases'] = array (
## - 'abuse' => 'postmaster@$DOMAIN',
## - 'postmaster' => 'postmaster@$DOMAIN',
## - );
## - $CONF['domain_path'] = 'YES';
## - $CONF['domain_in_mailbox'] = 'NO';
## - $CONF['aliases'] = '100';
## - $CONF['mailboxes'] = '100';
## - $CONF['maxquota'] = '0';
## - $CONF['domain_quota_default'] = '0';
## - $CONF['quota'] = 'YES';
## - $CONF['domain_quota'] = 'Yes';
## - $CONF['quota_multiplier'] = '1048576';
## -
echononl "\tAdjust Postfix Admin's Configuration - Part 2"
_failed=false
> $log_file
perl -i -n -p -e "s#^(\s*\\\$CONF\['default_aliases'\]\s*=.*)#//\n//! 'default_aliases' will be overridden - see end of configfile\n//\n\1#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
cat <<EOF >> $pfa_conf_file 2> $log_file
// Default Aliases
// The default aliases that need to be created for all domains.
// You can specify the target address in two ways:
// a) a full mail address
// b) only a localpart ('postmaster' => 'admin') - the alias target will point to the same domain
//
\$CONF['default_aliases'] = array (
'abuse' => 'postmaster@$DOMAIN',
'postmaster' => 'postmaster@$DOMAIN'
);
EOF
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_path'\]\s*=.*)#//!\1\n\\\$CONF['domain_path'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_in_mailbox'\]\s*=.*)#//!\1\n\\\$CONF['domain_in_mailbox'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['aliases'\]\s*=.*)#//!\1\n\\\$CONF['aliases'] = '100';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['mailboxes'\]\s*=.*)#//!\1\n\\\$CONF['mailboxes'] = '100';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['maxquota'\]\s*=.*)#//!\1\n\\\$CONF['maxquota'] = '0';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_quota_default'\]\s*=.*)#//!\1\n\\\$CONF['domain_quota_default'] = '0';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['quota'\]\s*=.*)#//!\1\n\\\$CONF['quota'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_quota'\]\s*=.*)#//!\1\n\\\$CONF['domain_quota'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['quota_multiplier'\]\s*=.*)#//!\1\n\\\$CONF['quota_multiplier'] = '1048576';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
## - Adjust Postfix Admin's Configuration - Part 3
## -
## - $CONF['transport_options'] = array (
## - 'lmtp:unix:private/dovecot-lmtp', // for virtual accounts
## - 'local', // for system accounts
## - 'relay' // for backup mx
## - );
## - $CONF['transport_default'] = 'lmtp:unix:private/dovecot-lmtp';
## - $CONF['vacation'] = 'YES';
## - $CONF['vacation_domain'] = '$AUTOREPLY_HOSTNAME';
## -
echononl "\tAdjust Postfix Admin's Configuration - Part 3"
_failed=false
> $log_file
perl -i -n -p -e "s#^(\s*\\\$CONF\['transport_options'\]\s*=.*)#//\n//! \"transport_options\" will be overridden - see end of configfile\n//\n\1#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
cat <<EOF >> $pfa_conf_file 2> $log_file
// Transport options
// If you want to define additional transport options put them in array below.
//
\$CONF['transport_options'] = array (
'lmtp:unix:private/dovecot-lmtp', // for virtual accounts
'local', // for system accounts
'relay' // for backup mx
);
EOF
perl -i -n -p -e "s#^(\s*\\\$CONF\['vacation'\]\s*=.*)#//!\1\n\\\$CONF['vacation'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['vacation_domain'\]\s*=.*)#//!\1\n\\\$CONF['vacation_domain'] = '$AUTOREPLY_HOSTNAME';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
## - Adjust Postfix Admin's Configuration - Part 4
## -
## - $CONF['vacation_choice_of_reply'] = array (
## - 0 => 'reply_once', // Sends only Once the message during Out of Office
## - 1 => 'reply_every_mail', // Reply on every email
## - 60*60*24 => 'reply_once_per_day', // Reply if last autoreply was at least one day ago
## - 60*60*24*7 => 'reply_once_per_week' // Reply if last autoreply was at least a week ago
## - );
## -
echononl "\tAdjust Postfix Admin's Configuration - Part 4"
_failed=false
> $log_file
perl -i -n -p -e "s#^(\s*\\\$CONF\['vacation_choice_of_reply'\]\s*=.*)#//\n//! 'vacation_choice_of_reply' will be overridden - see end of configfile\n//\n\1#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
cat <<EOF >> $pfa_conf_file 2> $log_file
// ReplyType options
// If you want to define additional reply options put them in array below.
// The array has the format seconds between replies => $PALANG text
// Special values for seconds are:
// 0 => only reply to the first mail while on vacation
// 1 => reply on every mail
// 60*60*24*7 => Reply if last autoreply was at least a week ago
//
//! ckubu added:
// - 60*60*24 => 'reply_once_per_day',
// ADD also "languages/de.lang":
//
// $PALANG['reply_once_per_day'] = 'Einmal pro Tag antworten';
//
\$CONF['vacation_choice_of_reply'] = array (
0 => 'reply_once', // Sends only Once the message during Out of Office
1 => 'reply_every_mail', // Reply on every email
60*60*24 => 'reply_once_per_day', // Reply if last autoreply was at least one day ago
60*60*24*7 => 'reply_once_per_week' // Reply if last autoreply was at least a week ago
);
EOF
perl -i -n -p -e "s#^(\s*\\\$CONF\['welcome_text'\]\s*=.*)#//\n//! 'welcome_text' will be overridden - see end of configfile\n//\n\1#" \
$pfa_conf_file >> $log_file 2>&1
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
## - $CONF['welcome_text'] = <<<EOM
## - $_welcome_email
## - EOM;
## -
echononl "\tCreate welcome message.."
if [[ -n "$WELCOME_MESSAGE" ]] ; then
cat <<EOF >> $pfa_conf_file 2> $log_file
// Welcome Message
// This message is send to every newly created mailbox.
// Change the text between EOM.
\$CONF['welcome_text'] = <<<EOM
$_welcome_email
EOM;
EOF
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_failed
fi
## - Adjust Postfix Admin's Configuration - Part 5
## -
## - $CONF['alias_control_admin'] = 'YES';
## - $CONF['alias_control'] = 'YES';
## - $CONF['special_alias_control'] = 'NO';
## - $CONF['backup'] = 'YES';
## - $CONF['fetchmail'] = 'NO';
## - $CONF['user_footer_link'] = "https://${WEBSITE_NAME}/main.php";
## - $CONF['footer_text'] = "Main Menu";
## - $CONF['footer_link'] = "http://${WEBSITE_NAME}/main.php";
## - $CONF['emailcheck_resolve_domain']='NO';
## - $CONF['show_status']='YES';
## - $CONF['show_status_key']='YES';
## - $CONF['show_undeliverable']='NO';
## - $CONF['show_popimap']='NO';
## -
## - $CONF['used_quotas'] = 'YES';
## - $CONF['new_quota_table'] = 'YES';
## -
echononl "\tAdjust Postfix Admin's Configuration - Part 5"
_failed=false
> $log_file
perl -i -n -p -e "s#^(\s*\\\$CONF\['alias_control_admin'\]\s+=.*)#//!\1\n\\\$CONF['alias_control_admin'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['alias_control'\]\s*=.*)#//!\1\n\\\$CONF['alias_control'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['special_alias_control'\]\s*=.*)#//!\1\n\\\$CONF['special_alias_control'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['backup'\]\s*=.*)#//!\1\n\\\$CONF['backup'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['fetchmail'\]\s*=.*)#//!\1\n\\\$CONF['fetchmail'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['user_footer_link'\]\s+=.*)#//!\1\n\\\$CONF['user_footer_link'] = 'https://${WEBSITE_NAME}/main.php';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['footer_text'\]\s+=.*)#//!\1\n\\\$CONF['footer_text'] = 'Main Menu';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['footer_link'\]\s+=.*)#//!\1\n\\\$CONF['footer_link'] = 'http://${WEBSITE_NAME}/main.php';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['emailcheck_resolve_domain'\]\s*=.*)#//!\1\n\\\$CONF['emailcheck_resolve_domain'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_status'\]\s*=.*)#//!\1\n\\\$CONF['show_status'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_status_key'\]\s*=.*)#//!\1\n\\\$CONF['show_status_key'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_undeliverable'\]\s*=.*)#//!\1\n\\\$CONF['show_undeliverable'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_popimap'\]\s*=.*)#//!\1\n\\\$CONF['show_popimap'] = 'NO';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['used_quotas'\]\s*=.*)#//!\1\n\\\$CONF['used_quotas'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['new_quota_table'\]\s*=.*)#//!\1\n\\\$CONF['new_quota_table'] = 'YES';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
# - After finished, you must alos change the value of $CONF['configured']
# - to 'true'
# -
# - $CONF['configured'] = true;
echononl "\tSet '\$CONF['configured'] = true'"
perl -i -n -p -e "s#^(\s*\\\$CONF\['configured'\]\s*=.*)#//!\1\n\\\$CONF['configured'] = true;#" \
$pfa_conf_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
fi
# - AFTER DELETION MAILBOX
# -
# - activate script for moving a mailbox from the mailboxdirectory
# - and save it to the backupb directory /var/deleted-maildirs
# -
echo -e "\n\t\033[32mMailbox post-deletion script\033[m"
echononl "\tCreate folder '${DELETED_MAILBOX_DIR}"
if [[ ! -d "${DELETED_MAILBOX_DIR}" ]] ; then
mkdir $DELETED_MAILBOX_DIR > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tChange permissions on '${DELETED_MAILBOX_DIR}"
_failed=false
chown vmail:vmail $DELETED_MAILBOX_DIR > $log_file 2>&1 || _failed=true
chmod 700 $DELETED_MAILBOX_DIR >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
echononl "\tBackup existing post-deletion script"
if [[ -f "/usr/local/bin/postfixadmin-mailbox-postdeletion.sh" ]]; then
mv /usr/local/bin/postfixadmin-mailbox-postdeletion.sh \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh.$(date +%Y%m%d-%H%M) > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCopy 'postfixadmin-mailbox-postdeletion.sh' to /usr/local/bin/"
cp -a ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/ADDITIONS/postfixadmin-mailbox-postdeletion.sh \
/usr/local/bin/ > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on 'postfixadmin-mailbox-postdeletion.sh'"
chmod 755 /usr/local/bin/postfixadmin-mailbox-postdeletion.sh > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# - Change the posdeletion scripts to your needs:
# -
# - set:
# - basedir=/var/vmail
# - trashbase=$DELETED_MAILBOX_DIR
# -
# - trashdir="${trashbase}/$2/`date +%F_$H-%M`_${subdir}"
# -
echononl "\tAdjust 'postfixadmin-mailbox-postdeletion.sh'"
_failed=false
> $log_file 2>&1
perl -i -n -p -e "s#^(\s*)(basedir=.*)#\#\1\2\n\1basedir=/var/vmail#" \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*)(trashbase=.*)#\#\1\2\n\1trashbase=${DELETED_MAILBOX_DIR}#" \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*)(trashdir=.*)#\#\1\2\n\1trashdir=\"\\\${trashbase}/\\\$2/\`date +%F_%H-%M\`_\\\${subdir}\"#" \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
# - Edit ${WEBSITE_BASEDIR}/htdocs/config.inc.php
# -
# - in section add line
# - $CONF['mailbox_postdeletion_script']='sudo -u vmail /usr/local/bin/postfixadmin-mailbox-postdeletion.sh';
# -
echononl "\tAdjust 'config.inc.php' to make script available"
perl -i -n -p -e "s#^(\s*[/*]?\s*\\\$CONF\['mailbox_postdeletion_script'\]\s*=.*)#//!\1\n\\\$CONF['mailbox_postdeletion_script'] = 'sudo -u vmail /usr/local/bin/postfixadmin-mailbox-postdeletion.sh';#" \
$pfa_conf_file > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fi
## - !! Notice:
## - Have a look at ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php
## - and see if changes affected
## -
# - You need also an entry in /etc/sudores
# -
# - ues visudo-command to add:
# - www-data ALL=(vmail) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
# -
_failed=false
echononl "\tCreate needed entry in '/etc/sudores'"
if ! grep -q -E "${HTTP_USER}.*NOPASSWD:\s*/usr/local/bin/postfixadmin-mailbox-postdeletion.sh" /etc/sudoers ; then
touch /etc/sudoers.tmp >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
cat /etc/sudoers > /tmp/sudoers.new 2>> $log_file
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> /tmp/sudoers.new
echo "${HTTP_USER} ALL=(vmail) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh" >> /tmp/sudoers.new 2>> $log_file
if [[ $? -ne 0 ]]; then
_failed=true
fi
visudo -c -f /tmp/sudoers.new >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
else
cp /tmp/sudoers.new /etc/sudoers >> $log_file 2>&1
if [ $? -ne 0 ]; then
_failed=true
fi
fi
rm /etc/sudoers.tmp >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
rm -f /tmp/sudoers.new
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
# - AFTER DELETION MAILDOMIAN
# -
# - activate script for moving a mailbox from the mailboxdirectory
# - and save it to the backupb directory $DELETED_DOMAINS_DIR
# -
echo -e "\n\t\033[32mMaildomain post-deletion script\033[m"
echononl "\tCreate folder '${DELETED_DOMAINS_DIR}"
if [[ ! -d "${DELETED_DOMAINS_DIR}" ]] ; then
mkdir $DELETED_DOMAINS_DIR > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tChange permissions on '${DELETED_DOMAINS_DIR}"
_failed=false
chown vmail:vmail $DELETED_DOMAINS_DIR > $log_file 2>&1 || _failed=true
chmod 700 $DELETED_DOMAINS_DIR >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
echononl "\tBackup existing post-deletion script"
if [[ -f "/usr/local/bin/postfixadmin-domain-postdeletion.sh" ]]; then
mv /usr/local/bin/postfixadmin-domain-postdeletion.sh \
/usr/local/bin/postfixadmin-domain-postdeletion.sh.$(date +%Y%m%d-%H%M) > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCopy 'postfixadmin-domain-postdeletion.sh' to /usr/local/bin/"
cp -a ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/ADDITIONS/postfixadmin-domain-postdeletion.sh \
/usr/local/bin/ > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on 'postfixadmin-domain-postdeletion.sh'"
chmod 755 /usr/local/bin/postfixadmin-domain-postdeletion.sh > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# - Change the posdeletion scripts to your needs:
# -
# - set:
# - basedir=/var/vmail
# - trashbase=$DELETED_DOMAINS_DIR
# -
# - trashdir="${trashbase}/`date +%F_%H-%M`_$1"
# -
echononl "\tAdjust 'postfixadmin-domain-postdeletion.sh'"
_failed=false
> $log_file 2>&1
perl -i -n -p -e "s#^(\s*)(basedir=.*)#\#\1\2\n\1basedir=/var/vmail#" \
/usr/local/bin/postfixadmin-domain-postdeletion.sh >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*)(trashbase=.*)#\#\1\2\n\1trashbase=${DELETED_DOMAINS_DIR}#" \
/usr/local/bin/postfixadmin-domain-postdeletion.sh >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*)(trashdir=.*)#\#\1\2\n\1trashdir=\"\\\${trashbase}/\`date +%F_%H-%M\`_\\\$1\"#" \
/usr/local/bin/postfixadmin-domain-postdeletion.sh >> $log_file 2>&1 || _failed=true
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
# - edit ${WEBSITE_BASEDIR}/htdocs/config.inc.php
# -
# - in section add line
# - $CONF['domain_postdeletion_script']='sudo -u vmail /usr/local/bin/postfixadmin-domain-postdeletion.sh';
# -
echononl "\tAdjust 'config.inc.php' to make script available"
perl -i -n -p -e "s#^(\s*[/*]?\s*\\\$CONF\['domain_postdeletion_script'\]\s*=.*)#//!\1\n\\\$CONF['domain_postdeletion_script'] = 'sudo -u vmail /usr/local/bin/postfixadmin-domain-postdeletion.sh';#" \
$pfa_conf_file >> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fi
## - !! Notice:
## - Have a look at ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php
## - and see if changes affected
## -
# - You need also an entry in /etc/sudores
# -
# - ues visudo-command to add:
# - www-data ALL=(vmail) NOPASSWD: /usr/local/bin/postfixadmin-domain-postdeletion.sh
# -
_failed=false
echononl "\tCreate needed entry in '/etc/sudores'"
if ! grep -q -E "${HTTP_USER}.*NOPASSWD:\s*/usr/local/bin/postfixadmin-domain-postdeletion.sh" /etc/sudoers ; then
touch /etc/sudoers.tmp >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
cat /etc/sudoers > /tmp/sudoers.new 2>> $log_file
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> /tmp/sudoers.new
echo "${HTTP_USER} ALL=(vmail) NOPASSWD: /usr/local/bin/postfixadmin-domain-postdeletion.sh" >> /tmp/sudoers.new 2>> $log_file
if [[ $? -ne 0 ]]; then
_failed=true
fi
visudo -c -f /tmp/sudoers.new >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
else
cp /tmp/sudoers.new /etc/sudoers >> $log_file 2>&1
if [ $? -ne 0 ]; then
_failed=true
fi
fi
rm /etc/sudoers.tmp >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
rm -f /tmp/sudoers.new
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
else
echo_skipped
fi
## - Using Postfixadmin, all changes (create/delete maildomains, mailboxes,
## - aliases, etc..) will result in concerning entries in the tables of the
## - specified database.
## -
## - Now you have to setup Postfix to recognize all these entries. To do so,
## - you must specify database requests (in different files) and load them
## - into Postfix configuration. In particular that are the following files:
## -
## - pgsql_relay-domain-maps.cf
## - pgsql_sender_login_maps.cf
## - pgsql_transport_maps.cf
## - pgsql_virtual_alias_domain_catchall_maps.cf
## - pgsql_virtual_alias_domain_mailbox_maps.cf
## - pgsql_virtual_alias_domain_maps.cf
## - pgsql_virtual_alias_maps.cf
## - pgsql_virtual_domains_maps.cf
## - pgsql_virtual_mailbox_limit_maps.cf
## - pgsql_virtual_mailbox_maps.cf
## -
echo -e "\n\t\033[32mSetup Postfix\033[m"
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf 2> $log_file
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf 2> $log_file
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT domain FROM domain WHERE domain = "%s" AND backupmx = 1
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["relay_domains"]="proxy:$POSTFIX_DB_TYPE:/etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf"
# - /etc/postfix/main.cf
# -
# - add to relay_domains:
# - proxy:$POSTFIX_DB_TYPE:/etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(relay_domains\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_relay-domain-maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf 2> $log_file
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT username AS allowedUser FROM mailbox WHERE username='%s' AND active = true UNION SELECT goto FROM alias WHERE address='%s' AND active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf 2> $log_file
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT username AS allowedUser FROM mailbox WHERE username="%s" AND active = 1 UNION SELECT goto FROM alias WHERE address="%s" AND active = 1
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["smtpd_sender_login_maps"]="proxy:$POSTFIX_DB_TYPE:/etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf"
# - /etc/postfix/main.cf
# -
# - add to smtpd_sender_login_maps:
# - proxy:$POSTFIX_DB_TYPE:/etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(smtpd_sender_login_maps\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_sender_login_maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
## -
#table = domain
#select_field = transport
#where_field = domain
query = SELECT transport FROM domain WHERE domain ='%s';
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
## -
#table = domain
#select_field = transport
#where_field = domain
query = SELECT transport FROM domain WHERE domain ='%s';
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["transport_maps"]="proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf"
# - /etc/postfix/main.cf
# -
# - add to transport_maps:
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(transport_maps\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_transport_maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias WHERE address='%s' AND active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = '%u' || '@' || alias_domain.target_domain AND alias.active = true AND alias_domain.active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = '@' || alias_domain.target_domain AND alias.active = true AND alias_domain.active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["virtual_alias_maps"]="proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf,proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf,proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf"
# - Edit /etc/postfix/main.cf
# -
# - add to virtual_alias_maps:
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf
# - ## - mailman
# - #hash:/var/lib/mailman/data/virtual-mailman
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(virtual_alias_maps\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = '%u' || '@' || alias_domain.target_domain AND mailbox.active = true AND alias_domain.active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["virtual_mailbox_maps"]="proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf,proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf"
# - Edit /etc/postfix/main.cf
# -
# - add to virtual_mailbox_maps:
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(virtual_mailbox_maps\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_mailbox_maps.cf\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_mailbox_maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT domain FROM domain WHERE domain = '%s' AND active = true
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["virtual_mailbox_domains"]="proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf"
# - Edit /etc/postfix/main.cf
# -
# - Add to virtual_mailbox_domains:
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#\s*(virtual_mailbox_domains\s*=.*$)#\1\n proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_domains_maps.cf#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - address-extension with delimeter "-"
# -
echononl "\tCreate file '/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf'"
if [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf
## - this address rewriting acts as address extension
## - with delimeter "-"
## -
hosts = $POSTFIX_DB_SOCKET
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT username FROM mailbox WHERE domain = '%d' AND '%u' LIKE local_part || '-%%' AND active = true ORDER BY username DESC LIMIT 1;
EOF
elif [ "$POSTFIX_DB_TYPE" = "mysql" ];then
cat <<EOF > /etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf
hosts = $POSTFIX_DB_HOST
user = $POSTFIX_DB_USER
password = $POSTFIX_DB_PASS
dbname = $POSTFIX_DB_NAME
query = SELECT username FROM mailbox WHERE domain = '%d' AND '%u' LIKE CONCAT(local_part, '-%%') AND active = '1' ORDER BY username DESC LIMIT 1;
EOF
else
echo "[ FATAL ]: Unknown database type $POSTFIX_DB_TYPE"
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
check_entry_main_cf_arr["virtual_alias_maps"]="${check_entry_main_cf_arr['virtual_alias_maps']},proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf"
# - Edit /etc/postfix/main.cf
# -
# - NOTICE!!
# - add this entry to virtual_alias_maps AT THE END, BUT BEFOR CATCH-ALL MAPS
# - if exists
# -
# - might look like this:
# - virtual_alias_maps =
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_maps.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_maps.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf,
# - proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf
# - ## - mailman
# - #hash:/var/lib/mailman/data/virtual-mailman
# -
echononl "\tUpdate '/etc/postfix/main.cf'"
if ! grep -q "proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf" /etc/postfix/main.cf > /dev/null 2>&1 ; then
perl -i -n -p -e "s#(\s*proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_domain_catchall_maps.cf.*$)# proxy:${POSTFIX_DB_TYPE}:/etc/postfix/${POSTFIX_DB_TYPE}_virtual_alias_address_rewriting.cf\n\1#" \
/etc/postfix/main.cf > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echo -e "\n\n\t\033[37m\033[1mSome final checks\033[m\n"
# - Check, if previously created entries in /etc/postfix/main.cf are really present
# -
echononl "\tCheck /etc/postfix/main.cf"
first_err=true
_found_err=false
for _key in ${!check_entry_main_cf_arr[@]} ; do
IFS=',' read -a _val_arr <<< "${check_entry_main_cf_arr[$_key]}"
for _val in ${_val_arr[@]} ; do
if ! grep "$_val" /etc/postfix/main.cf > /dev/null 2>&1 ; then
if $first_err ; then
echo_failed
first_err=false
fi
_found_err=true
error "No Entry '${_val}' found for parameter '${_key}' in /etc/postfix/main.cf"
fi
done
done
if ! $_found_err ; then
echo_ok
fi
echo ""
echononl "\tReload/Restart postfix"
if $SYSTEMD_EXISTS ; then
systemctl reload postfix > $log_file 2>&1
else
/etc/init.d/postfix reload > $log_file 2>&1
fi
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo ""
info "Browse to \033[1mhttp://${WEBSITE_NAME}/setup.php\033[m to create a 'setup password'\n$(cat <<EOF
\t If this is a fresh new installation, you have also to ceate one (ore more)
\t superadmin account(s).
\t Instructions on how to do this are pointed out at the setup site.
\t[ \033[33m\033[1mNotice\033[m ]: \033[1mScroll back to see if all seems to be fine!\033[m
EOF
)"
echo ""
exit 0
# =========================================================================================
# =========================================================================================
# =========================================================================================
## - Afterwords you have to change configuration vaiable $CONF['setup_password']
## - Setup password: EadGl15E
## - $CONF['setup_password'] = '5ae65a138fad97191ebdb7c4ed3a1826:5ae467dac6075eed6f5573d40286a65bf1ddd554';
## - Now create admin account
## -
## - admin account:
## - user......: admin@warenform.net
## - password..: dbddhkpuka
vim ${WEBSITE_BASEDIR}/htdocs/config.inc.php
## - !!!!!!!!!!
## - !! Notice:
## - to play with the following quota configuration for virtual mailboxes
## - you need to install the "vda"-patch
## -
cat <<EOF > /etc/postfix/pgsql_virtual_mailbox_limit_maps.cf
hosts = /var/run/postgresql
user = postfix
password = FKt4z55FxMZp
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s' AND active = true
EOF
## - add configuration parameter virtual_mailbox_limit_maps
## - in Postfix /etc/postfix/main.cf
## -
## - add:
## - virtual_mailbox_limit_maps = proxy:pgsql:/etc/postfix/pgsql_virtual_mailbox_limit_maps.cf
## -
vim /etc/postfix/main.cf
## - !!!!!!!!!!