mailsystem/install_postfixadmin.sh

3429 lines
110 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)"
backup_date="$(date +%Y-%m-%d-%H%M)"
declare -A check_entry_main_cf_arr
# -------------
# - Functions
# -------------
clean_up() {
# Perform program exit housekeeping
rm -f "$log_file"
exit $1
}
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 ""
clean_up 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 ]"
}
detect_os_1 () {
if $(which lsb_release > /dev/null 2>&1) ; then
os_dist="$(lsb_release -i | awk '{print tolower($3)}')"
os_version="$(lsb_release -r | awk '{print tolower($2)}')"
os_codename="$(lsb_release -c | awk '{print tolower($2)}')"
if [[ "$os_dist" = "debian" ]]; then
if $(echo "$os_version" | grep -q '\.') ; then
os_version=$(echo "$os_version" | cut --delimiter='.' -f1)
fi
fi
elif [[ -e "/etc/os-release" ]]; then
. /etc/os-release
os_dist=$ID
os_version=${os_version_ID}
fi
# remove whitespace from os_dist and os_version
os_dist="${os_dist// /}"
os_version="${os_version// /}"
}
# - Is 'systemd' supported on this system
# -
systemd_supported=false
systemd=$(which systemd)
systemctl=$(which systemctl)
if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then
systemd_supported=true
fi
# - Look for systemd service file or sysv init script for apache2 webservice
# -
APACHE_SERVICE_FILE=""
APACHE_INIT_SCRIPT=""
if $systemd_supported ; then
# - Is Service exclusive controlled by systemd
# -
if systemctl -t service list-unit-files \
| grep -e "^apache2.service" \
| grep -q -E "(enabled|disabled)" 2> /dev/null ; then
APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \
| grep -e "^apache2.service" \
| awk '{print$1}')
fi
fi
if [[ -z "$APACHE_SERVICE_FILE" ]] ; then
if [ -x "/etc/init.d/apache2" ]; then
APACHE_INIT_SCRIPT="/etc/init.d/apache2"
elif [ -x "/etc/init.d/apachectl" ]; then
APACHE_INIT_SCRIPT="/etc/init.d/apachectl"
fi
fi
# - Set variable
# - os_dist
# - os_version
# - os_codename
# -
detect_os_1
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
echo -e "\033[32m--\033[m"
echo ""
echo "Version of the Postfixadmin to install"
echo ""
echo ""
PF_ADMIN_VERSION=
while [ "X$PF_ADMIN_VERSION" = "X" ]
do
echononl "Postfixadmin Version: "
read PF_ADMIN_VERSION
if [ "X$PF_ADMIN_VERSION" = "X" ]; then
echo -e "\n\t\033[33m\033[1mA version number is required!\033[m\n"
fi
done
echo ""
echo -e "\033[32m--\033[m"
echo ""
# - 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_PGSQL="/run/postgresql"
if [[ -S "/tmp/mysql.sock" ]] ; then
DEFAULT_POSTFIX_DB_HOST_MYSQL="unix:/tmp/mysql.sock"
else
DEFAULT_POSTFIX_DB_HOST_MYSQL="unix:/run/mysqld/mysqld.sock"
fi
DEFAULT_POSTFIX_DB_NAME="postfix"
DEFAULT_POSTFIX_DB_USER="postfix"
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf"
else
DEFAULT_MYSQL_CREDENTIALS=""
fi
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="/etc/mysql/debian.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 not present!"
[[ -n "$IPV6" ]] || warn "IPv6 Address not present!"
[[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false
[[ -n "$PHP_DEBIAN_INSTALLATION" ]] || PHP_DEBIAN_INSTALLATION=false
httpd_binary="`which httpd`"
if [ -z "$httpd_binary" ]; then
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
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 '"'`"
# - 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 "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
[[ -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 "$POSTFIX_DB_TYPE" ]] || fatal "Database Type of Postfix Database (POSTFIX_DB_TYPE) not present!"
[[ -n "$POSTFIX_DB_HOST_MYSQL" ]] || POSTFIX_DB_HOST_MYSQL="$DEFAULT_POSTFIX_DB_HOST_MYSQL"
[[ -n "$POSTFIX_DB_HOST_PGSQL" ]] ||POSTFIX_DB_HOST_PGSQL="$DEFAULT_POSTFIX_DB_HOST_PGSQL"
[[ -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!"
[[ -n "$AUTOREPLY_HOSTNAME" ]] || AUTOREPLY_HOSTNAME=autoreply.${MAIN_DOMAIN}.$TLD
if [[ "$POSTFIX_DB_HOST_MYSQL" =~ sock$ ]] || [[ "$POSTFIX_DB_HOST_MYSQL" =~ localhost ]]; then
VACATION_DB_HOST_MYSQL="127.0.0.1"
else
VACATION_DB_HOST_MYSQL="$POSTFIX_DB_HOST_MYSQL"
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"
if $PHP_DEBIAN_INSTALLATION ; then
php_major_version="$(php --version | head -1 | cut -d' ' -f2 | cut -d '-' -f1 | cut -d'.' -f1,2)"
else
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
fi
# - Get the latest PHP version
# -
echononl "\tGet major number of latest installed PHP version"
if $PHP_DEBIAN_INSTALLATION ; then
echo_skipped
else
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
fi
# - Get activ PHP version, means that on which is part of $PATH environment
# -
echononl "\tGet PHP version in PATH environment.."
if $(which php > /dev/null 2>&1) ; then
php_version_in_path="$(php --version 2> /dev/null | head -1 | cut -d' ' -f2 | cut -d '-' -f1 2> /dev/null)"
if [[ $? -eq 0 ]] && [[ -n "${php_version_in_path}" ]]; then
echo_ok
else
echo_failed
fatal "Failed getting PHP Version.."
fi
else
echo_skipped
fatal "No PHP binary found in PATH environment.."
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 ""
if $PHP_DEBIAN_INSTALLATION ; then
echo -e "\tInstalled PHP version................: $php_major_version"
else
declare -i index=1
for _ver in $php_major_versions ; do
if [[ $index -eq 1 ]] ; then
echo -en "\tInstalled PHP versions...............: $_ver"
else
echo -en " $_ver"
fi
((index++))
done
echo ""
echo -e "\tNewest PHP Version...................: $php_latest_ver"
echo -e "\tPHP Version of php binary in PATH....: $php_version_in_path"
fi
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"
echo -e "\tHost of Postfix Database.............: $POSTFIX_DB_HOST_MYSQL"
else
echo -e "\tDatabase type of Postfix Database....: PostgreSQL"
echo -e "\tHost of Postfix Database.............: $POSTFIX_DB_HOST_PGSQL"
fi
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_supported"
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
# - Determine major/minor version
# -
MAJOR_VERSION="$(echo $PF_ADMIN_VERSION | cut -d '.' -f1)"
MINOR_VERSION="$(echo $PF_ADMIN_VERSION | cut -d '.' -f2)"
echo -e "\n\n\t\033[37m\033[1mPre-installion tasks ..\033[m\n"
# - Datenbank etstellen:
# -
# - MySQL/PostgreSQL Datenbank erstellen
# -
# -
_failed=false
> $log_file
_actual_config_file=""
_actual_password_hash=""
_actual_pfa_dir=""
if [[ -d "${WEBSITE_BASEDIR}/htdocs" ]] ; then
_actual_pfa_dir="$(realpath "${WEBSITE_BASEDIR}/htdocs")"
fi
echononl "\tKeep passwordhasch from actual installation in mind.."
if [[ -n "$_actual_pfa_dir" && -d "$_actual_pfa_dir" ]] ; then
if [[ -f "${_actual_pfa_dir}/config.local.php" ]]; then
_actual_config_file="${_actual_pfa_dir}/config.local.php"
else
_actual_config_file="${_actual_pfa_dir}/config.inc.php"
fi
fi
if [[ -f "$_actual_config_file" ]]; then
_actual_password_hash="$(grep -E "^\s*\\\$CONF\['setup_password'\]" $_actual_config_file 2> /dev/null \
| grep -v changeme \
| awk -F '=' '{print$2}'\
| awk -F ';' '{print$1}')"
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[![:space:]]*}"}"
# - Remove trailing whitespace characters
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[![:space:]]}"}"
# - Remove leading single quote
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\']*}"}"
# - Remove trailing single quote
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\']}"}"
# - Remove leading double quote
_actual_password_hash="${_actual_password_hash#"${_actual_password_hash%%[!\"]*}"}"
# - Remove trailing double quote
_actual_password_hash="${_actual_password_hash%"${_actual_password_hash##*[!\"]}"}"
echo_ok
else
echo_skipped
fi
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]] ; then
echononl "\tCheck if database '$POSTFIX_DB_NAME' already exists.."
_db_response="$(mysql $MYSQL_CREDENTIALS -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$POSTFIX_DB_NAME'" 2>> $log_file)"
if [[ $? -ne 0 ]] ; then
echo_failed
echo ""
echo -e "\tMaybw your MySQL credentials are wrong. the credentials given were:"
echo ""
echo -e "\t MYSQL_CREDENTIALS: $MYSQL_CREDENTIALS"
echo ""
error "$(cat $log_file)"
fatal "Checking if database exists failed!"
else
echo_ok
fi
if [[ "${_db_response}" = "${POSTFIX_DB_NAME}" ]]; then
database_exists=true
else
database_exists=false
fi
elif [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$POSTFIX_DB_NAME")
if [[ $count -eq 0 ]];then
database_exists=false
else
database_exists=true
fi
else
fatal "Cannot detect database type (value of POSTFIX_DB_TYPE is neither 'mysql' nor 'pgsql')"
fi
if ! $database_exists ; then
echononl "\tCreate Postfix Database '$POSTFIX_DB_NAME'"
if [ "$POSTFIX_DB_TYPE" = "mysql" ]; then
echo -n " (MySQL).."
mysql $MYSQL_CREDENTIALS -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_CREDENTIALS -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_CREDENTIALS -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
elif [ "$POSTFIX_DB_TYPE" = "pgsql" ]; then
echo -n " (PostgreSQL).."
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
fi
else
echononl "\tBackup Postfix Database '$POSTFIX_DB_NAME'"
if [[ ! -d "${WEBSITE_BASEDIR}" ]] ; then
echo_skipped
else
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
echo -n " (MySQL).."
mysqldump $MYSQL_CREDENTIALS --opt $POSTFIX_DB_NAME > ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do
echononl "\033[33mWrong entry!\033[m [\033[1myes/no\033[m]: "
read OK
done
[[ "${OK,,}" = "yes" ]] || fatal "Canceled by user input."
fi
elif [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
echo -n " (PostgreSQL).."
su - postgres -c "pg_dump -c $POSTFIX_DB_NAME" >> ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.${backup_date}.sql 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echo ""
echononl "Continue with this parameters? [\033[1myes/no\033[m]: "
read OK
while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do
echononl "\033[33mWrong entry!\033[m [\033[1myes/no\033[m]: "
read OK
done
[[ "${OK,,}" = "yes" ]] || fatal "Canceled by user input."
fi
fi
fi
fi
# - Synchronise package index files with the repository
# -
echononl "\tSynchronise package index files with the repository.."
apt-get update > "$log_file" 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tInstall needed debian packages.."
needed_packages=""
_needed_packages="
libdbi-perl
libmail-sendmail-perl
libdbi-dev
libemail-sender-perl
libemail-simple-perl
libemail-valid-perl
libtry-tiny-perl
libemail-mime-perl
liblog-log4perl-perl
liblog-dispatch-perl
libgetopt-argvfile-perl
libmime-charset-perl
libmime-encwords-perl
cpanminus"
if [[ $os_version -lt 9 ]] ; then
_needed_packages="$_needed_packages libmail-sender-perl"
fi
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
Mail::Sender"
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
cpanm -q --skip-installed --force $_module >> "$log_file" 2>&1
[[ "$?" -ne 0 ]] && _failed=true
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
# Download location has changed!
#
#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
# Download from github.com..
#
wget -O ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}.tar.gz https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-${PF_ADMIN_VERSION}.tar.gz > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "\tcontinue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/nno]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Script terminated by user input.."
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}.${backup_date}
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}.${backup_date} > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
if [[ ! -d "${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}" ]] ; then
if [[ -d "${_src_base_dir}/postfixadmin-postfixadmin-${PF_ADMIN_VERSION}" ]] ; then
echononl "\tRename source directory 'postfixadmin-postfixadmin-${PF_ADMIN_VERSION}' to 'postfixadmin-${PF_ADMIN_VERSION}'"
mv "${_src_base_dir}/postfixadmin-postfixadmin-${PF_ADMIN_VERSION}" \
"${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "\tcontinue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/nno]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Script terminated by user input.."
fi
fi
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)"
echononl "\tcontinue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/nno]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Script terminated by user input.."
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
if [[ ! -d "${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/templates_c" ]]; then
mkdir ${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/templates_c
if [[ $? -ne 0 ]] ; then
_failed=true
fi
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
if [[ $MAJOR_VERSION -eq 3 && $MINOR_VERSION -gt 1 ]] || [[ $MAJOR_VERSION -gt 3 ]] ; then
ln -s postfixadmin-${PF_ADMIN_VERSION}/public ${WEBSITE_BASEDIR}/htdocs > $log_file 2>&1
else
ln -s postfixadmin-${PF_ADMIN_VERSION} ${WEBSITE_BASEDIR}/htdocs > $log_file 2>&1
fi
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
_create_vhost_config=true
if [[ -n "$IPV6" ]] && [[ -n "$IPV4" ]] ; then
_vhost_ip_string_80="$IPV4:80 [$IPV6]:80"
_vhost_ip_string_443="$IPV4:443 [$IPV6]:443"
elif [[ -n "$IPV4" ]] ; then
_vhost_ip_string_80="$IPV4:80"
_vhost_ip_string_443="$IPV4:443"
elif [[ -n "$IPV6" ]] ; then
_vhost_ip_string_80=" [$IPV6]:80"
_vhost_ip_string_443=" [$IPV6]:443"
else
echo_failed
error "Neither an ipv4 nor an ipv6 address are given.!"
_create_vhost_config=false
fi
if $_create_vhost_config ; then
cat <<EOF > ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
# -- $WEBSITE_NAME -- #
<VirtualHost $_vhost_ip_string_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 $_vhost_ip_string_443>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
# Don't provide users login
#
RewriteEngine on
RewriteRule users(.*) https://%{SERVER_NAME} [R=301,L]
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$>
EOF
if $PHP_DEBIAN_INSTALLATION ; then
php_socket_file="/run/php/php${php_major_version}-fpm.sock"
if [[ -S "/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock" ]]; then
php_socket_file="/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock"
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SetHandler "proxy:unix:${php_socket_file}|fcgi://127.0.0.1"
EOF
else
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
EOF
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
</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
# ==========
# - HTTP security Headers
# ==========
# - X-Frame-Options
# -
# - The X-Frame-Options header (RFC), or XFO header, protects your visitors
# - against clickjacking attacks. An attacker can load up an iframe on their
# - site and set your site as the source, it's quite easy:
# -
# - <iframe src="https://scotthelme.co.uk"></iframe>
# -
# - Using some crafty CSS they can hide your site in the background and create some
# - genuine looking overlays. When your visitors click on what they think is a harmless
# - link, they're actually clicking on links on your website in the background. That
# - might not seem so bad until we realise that the browser will execute those requests
# - in the context of the user, which could include them being logged in and authenticated
# - to your site!
# -
# - Troy Hunt has a great blog on 'Clickjack attack the hidden threat right in front :
# - of you':
# -
# - http://www.troyhunt.com/2013/05/clickjack-attack-hidden-threat-right-in.html
# -
# - Valid values include DENY meaning your site can't be framed, SAMEORIGIN which allows
# - you to frame your own site or ALLOW-FROM https://example.com/ which lets you specify
# -sites that are permitted to frame your own site.
# -
Header always set X-Frame-Options "SAMEORIGIN"
# - X-Xss-Protection
# -
# - This header is used to configure the built in reflective XSS protection found
# - in Internet Explorer, Chrome and Safari (Webkit). Valid settings for the header
# - are 0, which disables the protection, 1 which enables the protection
# - and 1; mode=block which tells the browser to block the response if it
# - detects an attack rather than sanitising the script.
# -
Header always set X-Xss-Protection "1; mode=block"
# - X-Content-Type-Options
# -
# - Nice and easy to configure, this header only has one valid value, nosniff.
# - It prevents Google Chrome and Internet Explorer from trying to mime-sniff
# - the content-type of a response away from the one being declared by the server.
# - It reduces exposure to drive-by downloads and the risks of user uploaded content
# - that, with clever naming, could be treated as a different content-type, like
# - an executable.
# -
Header always set X-Content-Type-Options "nosniff"
# - Content Security Policy
# -
# - The CSP header allows you to define a whitelist of approved sources of content
# - for your site. By restricting the assets that a browser can load for your site,
# - like js and css, CSP can act as an effective countermeasure to XSS attacks. I
# - have covered CSP in a lot more detail in my blog Content Security Policy - An
# - Introduction (https://scotthelme.co.uk/content-security-policy-an-introduction/).
# -
# - Here is a basic policy to enforce TLS on all assets and prevent
# - mixed content warnings.
# -
# - Allow Google Analytics, Google AJAX CDN and Same Origin
# - script-src 'self' www.google-analytics.com ajax.googleapis.com;
# -
# - Emmbedding Google Fonts
# - style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
# -
# - Allow YouTube Videos (iframe embedded)
# - frame-src 'self' https://www.youtube.com
# -
#Header always set Content-Security-Policy "default-src https: data: 'unsafe-inline' 'unsafe-eval' ; object-src 'none'"
Header always set Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' ; img-src 'self'; connect-src 'self'; font-src 'self'; object-src 'self'; media-src 'self' ; frame-src 'self'; worker-src 'self' ; form-action 'self'; base-uri 'self'; frame-ancestors 'self'; upgrade-insecure-requests"
# - Referrer-Policy
# -
# - The HTTP referer (originally a misspelling of referrer[1]) is an HTTP header
# - field that identifies the address of the webpage (i.e. the URI or IRI) that
# - linked to the resource being requested. By checking the referrer, the new
# - webpage can see where the request originated.
# -
Header set Referrer-Policy "strict-origin-when-cross-origin"
# - 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"
SSLEngine on
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
fi # if $_create_vhost_config
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 [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then
if [[ -n "$APACHE_SERVICE_FILE" ]] ; then
systemctl restart $APACHE_SERVICE_FILE > $log_file 2>&1
else
$APACHE_INIT_SCRIPT restart > $log_file 2>&1
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
warn "Neither an init-script nor a service file for 'apache2' webservice found!"
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 > /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.${backup_date} > "$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'"
_vacation_script="$(find ${_src_base_dir}/postfixadmin-${PF_ADMIN_VERSION} -type f -name vacation.pl -print 2>/dev/null)"
if [[ -n "$(trim "$_vacation_script")" ]] ; then
cp -a ${_vacation_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."
# - Vacation script changed. Since Version 3.2 we need another perl regexp.
# - The old one was:
# - perl -i -n -p -e "s/(\s*\'ctype\'\s* =>\s*)\'text\/plain.*$/\1\'text\/plain; charset=iso-8859-1\',/" \
# -
perl -i -n -p -e "s/(\s*\'Content-Type\'\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.${backup_date} > "$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}';
EOF
if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then
cat <<EOF >> /etc/postfixadmin/vacation.conf 2> "$log_file"
\$db_host = '$VACATION_DB_HOST_MYSQL';
EOF
fi
cat <<EOF >> /etc/postfixadmin/vacation.conf 2> "$log_file"
\$vacation_domain = '${AUTOREPLY_HOSTNAME}';
\$syslog = 0;
\$log_to_file = 1;
\$logfile = '/var/log/vacation.log';
\$log_level = 1;
\$interval = 60*60*24;
\$smtp_ssl = '0';
1; # required final line - keeps perl happy.
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_supported ; 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"
if [[ $MAJOR_VERSION -eq 3 ]] && [[ $MINOR_VERSION -gt 0 ]]; then
pfa_conf_file="${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.local.php"
cp -a "${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php" "$pfa_conf_file"
else
pfa_conf_file="${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/config.inc.php"
cp -a "$pfa_conf_file" "${pfa_conf_file}.ORIG"
fi
# - 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
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
_database_type="pgsql"
else
# - database_type 'mysql' uses the deprecated mysql extension , and since PHP 7.0 this extension
# - is no longer available.
# -
# - So use 'mysqli' instead of 'mysql'
# -
_database_type="mysqli"
fi
> $log_file
perl -i -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'] = '$_database_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
if grep -q -E "^\\\$CONF\['dovecotpw'\]\s*=.*" "$pfa_conf_file" 2> /dev/null ; then
perl -i -n -p -e "s#^(\\\$CONF\['dovecotpw'\]\s*=.*)#//!\1\n\\\$CONF['dovecotpw'] = '$DOVEADM_PW';#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
else
cat <<EOF >> $pfa_conf_file
// If you use the dovecot encryption method: where is the dovecotpw binary located?
// for dovecot 1.x
// \$CONF['dovecotpw'] = "/usr/sbin/dovecotpw";
// for dovecot 2.x (dovecot 2.0.0 - 2.0.7 is not supported!)
\$CONF['dovecotpw'] = "$DOVEADM_PW" ;
EOF
fi
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\['language_hook'\]\s*=.*)#//\n//! 'language_hook' will be overridden - see end of configfile\n//\n\1#" \
$pfa_conf_file >> $log_file 2>&1 || _failed=true
perl -i -n -p -e "s#^(\s*\\\$CONF\['password_validation'\]\s*=.*)#//\n//! 'password_validation' 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
// Password validation
// New/changed passwords will be validated using all regular expressions in the array.
// If a password doesn't match one of the regular expressions, the corresponding
// error message from \$PALANG (see languages/*) will be displayed.
// See http://de3.php.net/manual/en/reference.pcre.pattern.syntax.php for details
// about the regular expression syntax.
// If you need custom error messages, you can add them using \$CONF['language_hook'].
// If a \$PALANG text contains a %s, you can add its value after the \$PALANG key
// (separated with a space).
\$CONF['password_validation'] = array(
# minimum length 12 characters
'/.{12}/' => 'password_too_short 12',
# must contain at least 3 characters
'/([a-zA-Z].*){3}/' => 'password_no_characters 3',
# must contain at least 2 digits
'/([0-9].*){2}/' => 'password_no_digits 2',
# must contain at least 1 special character
'/([!?~@#$\\%^&*\\(\\);\\':"\\.,<>{}\\[\\]|=\\-\\+_].*){1}/' => 'x_password_no_special_characters 1',
# must NOT contain
'/^[^¿¡§]*$/' => 'x_password_not_allowed',
);
/*
language_hook example function
Called if \$CONF['language_hook'] == '<name_of_the_function>'
Allows to add or override \$PALANG interface texts.
If you add new texts, please always prefix them with 'x_' (for example
\$PALANG['x_mytext'] = 'foo') to avoid they clash with texts that might be
added to languages/*.lang in future versions of PostfixAdmin.
Please also make sure that all your added texts are included in all
sections - that includes all 'case "XY":' sections and the 'default:'
section (for users that don't have any of the languages specified
in the 'case "XY":' section).
Usually the 'default:' section should contain english text.
If you modify an existing text/translation, please consider to report it
to the bugtracker on http://sf.net/projects/postfixadmin so that all users
can benefit from the corrected text/translation.
Returns: modified \$PALANG array
\$CONF['language_hook'] = "language_hook";
function language_hook(\$PALANG, \$language) {
switch (\$language) {
case "de":
\$PALANG['x_whatever'] = 'foo';
break;
case "fr":
\$PALANG['x_whatever'] = 'bar';
break;
default:
\$PALANG['x_whatever'] = 'foobar';
}
return \$PALANG;
}
*/
// Hook to override or add translations in \$PALANG
// Set to the function name you want to use as hook function (see language_hook example function below)
\$CONF['language_hook'] = "adjust_plang_hook";
function adjust_plang_hook(\$PALANG, \$language) {
switch (\$language) {
case "de":
\$PALANG['x_password_no_special_characters'] = 'Das Passwort muss mindestens %s Sonderzeichen (!~@#$^&*();\\':",.<>[]{}|=-+_) enhalten.';
\$PALANG['x_password_not_allowed'] = 'Die Zeichen \'¿¡§\' sind nicht erlaubt.';
break;
default:
\$PALANG['x_password_no_special_characters'] = 'Your password must contain at least %s special character (!?~@#$^&*();\\':",.<>[]{}|=-+_).';
\$PALANG['x_password_not_allowed'] = 'Characters \'¿¡§\' are not allowed.';
}
return \$PALANG;
}
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
perl -i -n -p -e "s#^(\s*\\\$CONF\['transport_default'\]\s*=.*)#//\n//! \"transport_default\" 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
);
// Transport default
// You should define default transport. It must be in array above.
\$CONF['transport_default'] = 'lmtp:unix:private/dovecot-lmtp';
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_MESSAGE
## - 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_MESSAGE
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
echononl "\tAdd Apache User (${HTTP_USER}) to group 'dovecot'.."
if getent group dovecot 2> /dev/null | grep -q "\b${HTTP_USER}\b" > /dev/null 2>&1 ; then
echo_skipped
else
if ! $(grep dovecot /etc/group > /dev/null) ; then
echo_skipped
warn "Group 'dovecot' not present.!"
else
usermod -a -G dovecot $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
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
# - Take passwordhash from previosly installation
# -
echononl "\tTake passwordhash from previosly installation.."
if [[ -n "$_actual_password_hash" ]] ; then
perl -i -n -p -e "s#^(\s*\\\$CONF\['setup_password'\]\s*=.*)#//!\1\n\\\$CONF['setup_password'] = '$_actual_password_hash';#" \
$pfa_conf_file >> $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
fi
else
echo_skipped
fi
echo ""
# - 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.${backup_date} > $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.${backup_date} > $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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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_HOST_PGSQL
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_MYSQL
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
if ! $(grep -q -E "^\s*\$version\s*=\s*'${PF_ADMIN_VERSION}'" \
"${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/functions.inc.php" 2> /dev/null) ; then
echononl "\tSet correct version number in file 'functions.inc.php'.."
perl -i.ORIG -n -p -e "s#^\s*\\\$version\s+=.*#\\\$version = '${PF_ADMIN_VERSION}';#" \
${WEBSITE_BASEDIR}/postfixadmin-${PF_ADMIN_VERSION}/functions.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat "$log_file")"
fi
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_supported ; 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
# - Start all PHP FPM engines
# -
if [[ -n "$php_major_versions" ]]; then
for _ver in $php_major_versions ; do
echononl "\tRestart PHP FPM engine v${_ver}.."
if [[ -f "/etc/init.d/php-${_ver}-fpm" ]]; then
/etc/init.d/php-${_ver}-fpm restart > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
elif [[ -f "/etc/systemd/system/php-${_ver}-fpm.service" ]] ; then
systemctl restart php-${_ver}-fpm > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
done
else
if $PHP_DEBIAN_INSTALLATION ; then
echononl " Retart PHP FPM engine v${php_major_version}.."
if [[ -f "/etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm" ]] ; then
/etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm restart > $log_file 2>&1
else
echo_skipped
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
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, maybe like this:
\t - Generate setup_password hash and set \033[1m$CONF['setup_password']\033[m
\t in file \033[1mconfig.local.php\033[m as printed out.
\t - Browse to \033[1mhttp://${WEBSITE_NAME}/setup.php\033[m once again to update
\t the database
\t Browse to \033[1mhttp://${WEBSITE_NAME}\033[m and login using an existent admin account
\t[ \033[33m\033[1mNotice\033[m ]: \033[1mScroll back to see if all seems to be fine!\033[m
\t[ \033[33m\033[1mNotice\033[m ]: if password encryption was setup with \033[1m'dovecotpw'\033[m or encrypt backend
with \033[1m'dovecot:SHA512-CRYPT'\033[m continue after installing dovecot.
EOF
)"
echo ""
clean_up 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
## - !!!!!!!!!!