postfixadmin/install_postfixadmin.sh
2017-02-27 03:47:21 +01:00

1318 lines
49 KiB
Bash
Executable File

#!/usr/bin/env bash
echo -e "\n\tScript is not yet ready for running.\n"
exit # It's not ready for running
## ===================================================================
## - 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)"
# -------------
# - Functions
# -------------
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
fatal(){
echo ""
echo -e "\t[ \033[31m\033[1mFatal\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m"
echo ""
exit 1
}
error(){
echo ""
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
echo ""
}
warn (){
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
}
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[33m\033[1mskipped\033[m ]"
}
if [ "$_db_type" = "postgres" -o "$_db_type" = "postgresql" -o "$_db_type" = "pgsql" -o "$_db_type" = "psql" ];then
_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
_log_dir=${_src_base_dir}/log-postfixadmin-$_version
## - Create temp directory for php
## -
mkdir -p ${APACHE_BASE_WEBDIR}/${HOSTNAME}/{logs,sessions,tmp}
chown ${APACHE_USER}:${APACHE_GROUP} ${APACHE_BASE_WEBDIR}/${HOSTNAME}/{sessions,tmp}
# - Determin PHP all Versions
# -
_php_major_versions=`find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort`
# - Get the lates PHP version
# -
php_apache_ver=""
for _ver in $_php_major_versions ; do
if [[ -z "$php_apache_ver" ]] ; then
php_apache_ver=$_ver
elif [[ "${_ver%.*}" -gt "${php_apache_ver%.*}" ]] ; then
php_apache_ver=$_ver
elif [[ "${_ver%.*}" -eq "${php_apache_ver%.*}" ]] ; then
[[ "${_ver#*.}" -gt "${php_apache_ver#*.}" ]] && php_apache_ver=$_ver
fi
done
if $_use_mod_fcgid ; then
mkdir -p ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf
chown root:$APACHE_USER ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf
chmod 750 ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf
for _version in $_php_major_versions ; do
cp /usr/local/php-${_version}/etc/php.ini ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/php.ini-$_version
chown root:$APACHE_USER ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/php.ini-$_version
chmod 640 ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/php.ini-$_version
cat <<EOF > ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid-$_version
#!/bin/sh
export PHPRC="${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/"
export TMPDIR="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
chown root:$APACHE_USER ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid-$_version
chmod 750 ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid-$_version
done
ln -s php.ini-$_version ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/php.ini
ln -s fcgid-$_version ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid
cat << EOF > ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/changes.php.ini.txt
error_log = "${APACHE_BASE_WEBDIR}/${HOSTNAME}/logs/php_errors.log"
sys_temp_dir = "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
upload_tmp_dir = "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
session.save_path = "${APACHE_BASE_WEBDIR}/${HOSTNAME}/sessions"
soap.wsdl_cache_dir = "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
EOF
touch ${APACHE_BASE_WEBDIR}/${HOSTNAME}/logs/php_errors.log
chown ${APACHE_USER}:${APACHE_GROUP} ${APACHE_BASE_WEBDIR}/${HOSTNAME}/logs/php_errors.log
_php_ini_file="${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/php.ini-*"
_key=error_log
_val="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
_retval=$?
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
_retval=$?
fi
_key="sys_temp_dir"
_val="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
_retval=$?
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
_retval=$?
fi
_key="upload_tmp_dir"
_val="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
_retval=$?
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
_retval=$?
fi
_key="session.save_path"
_val="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
_retval=$?
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
_retval=$?
fi
_key="soap.wsdl_cache_dir"
_val="${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
_retval=$?
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
_retval=$?
fi
fi
## - DocumentRoot
## -
mkdir -p ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs
#chown ${APACHE_USER}:$APACHE_GROUP ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs
cat <<EOF > ${APACHE_VHOST_DIR}/$HOSTNAME.conf
# -- ${HOSTNAME} -- #
<VirtualHost ${IPV4}:80>
ServerAdmin $ADMIN_EMAIL
ServerName $HOSTNAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${HOSTNAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${HOSTNAME}-error.log
</VirtualHost>
<VirtualHost ${IPV4}:443>
ServerAdmin $ADMIN_EMAIL
ServerName $HOSTNAME
EOF
if $_use_mod_php_fpm ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_apache_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
elif $_use_mod_php ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
php_admin_value sys_temp_dir "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
php_admin_value upload_tmp_dir "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
php_admin_flag log_errors on
php_admin_value error_log "${APACHE_BASE_WEBDIR}/${HOSTNAME}/logs/php_error.log"
php_admin_value session.save_path "${APACHE_BASE_WEBDIR}/${HOSTNAME}/sessions"
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
EOF
else
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
<Directory "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/">
Require all granted
FCGIWrapper ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
SSLEngine on
## - HTTP Strict Transport Security (HSTS)
## -
## - HSTS tells a browser that the website should only be accessed through
## - a secure connection. The HSTS header will be remembered by a standard
## compliant browser for max-age seconds.
## -
## - Remember this settings for 1 year
## -
Header add Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CONF_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CONF_DIR}/$APACHE_SERVER_KEY
$_SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${HOSTNAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${HOSTNAME}-error.log
</VirtualHost>
## ------
## - IPv6
## ------
# -- ${HOSTNAME} -- #
<VirtualHost [${IPV6}]:80>
ServerAdmin $ADMIN_EMAIL
ServerName $HOSTNAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${HOSTNAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${HOSTNAME}-error.log
</VirtualHost>
<VirtualHost [${IPV6}]:443>
ServerAdmin $ADMIN_EMAIL
ServerName $HOSTNAME
EOF
if $_use_mod_php_fpm ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_apache_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
elif $_use_mod_php ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
php_admin_value sys_temp_dir "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
php_admin_value upload_tmp_dir "${APACHE_BASE_WEBDIR}/${HOSTNAME}/tmp"
php_admin_flag log_errors on
php_admin_value error_log "${APACHE_BASE_WEBDIR}/${HOSTNAME}/logs/php_error.log"
php_admin_value session.save_path "${APACHE_BASE_WEBDIR}/${HOSTNAME}/sessions"
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
EOF
else
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
DocumentRoot "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/"
<Directory "${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/">
Require all granted
FCGIWrapper ${APACHE_BASE_WEBDIR}/${HOSTNAME}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/$HOSTNAME.conf
SSLEngine on
## - HTTP Strict Transport Security (HSTS)
## -
## - HSTS tells a browser that the website should only be accessed through
## - a secure connection. The HSTS header will be remembered by a standard
## compliant browser for max-age seconds.
## -
## - Remember this settings for 1 year
## -
Header add Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CONF_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CONF_DIR}/$APACHE_SERVER_KEY
$_SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${HOSTNAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${HOSTNAME}-error.log
</VirtualHost>
EOF
debian_installed_apache=false
if $debian_installed_apache ; then
a2ensite $HOSTNAME
fi
apachectl configtest
apachectl graceful
## - Datenbank etstellen:
## -
## - MySQL/PostgreSQL Datenbank erstellen
## -
## -
if [ "$_db_type" = "mysql" ]; then
if ! mysql $mysql_credential_args -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$_db_name'" 2>/dev/null \
| grep $_db_name > /dev/null 2>&1 ; then
mysql $mysql_credential_args -N -s -e \
"CREATE DATABASE IF NOT EXISTS $_db_name CHARACTER SET utf8 COLLATE utf8_general_ci"
mysql $mysql_credential_args -N -s -e \
"GRANT ALL ON $_db_name.* TO '$_db_user'@'localhost' IDENTIFIED BY '$_db_pass'"
mysql $mysql_credential_args -N -s -e "FLUSH PRIVILEGES"
fi
elif [ "$_db_type" = "pgsql" ]; then
count=`su - postgres -c "psql -q -A -t -l" | grep -c -e "^$_db_name"`
if [ $count -eq 0 ];then
echo "CREATE ROLE $_db_user WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$_db_pass'" \
| su - postgres -c "psql" > /dev/null
su - postgres -c "createdb -E utf8 -O $_db_user $_db_name"
fi
fi
## - Get postfixadmin sources if not yet downloaded
## -
cd $_src_base_dir
if [ ! -f postfixadmin-${_pf_admin_version}.tar.gz ];then
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-${_pf_admin_version}/postfixadmin-${_pf_admin_version}.tar.gz
fi
if [ -d postfixadmin-${_pf_admin_version} ]; then
mv postfixadmin-${_pf_admin_version} postfixadmin-${_pf_admin_version}.`date "+%Y%m%d-%H%M"`
fi
gunzip < postfixadmin-${_pf_admin_version}.tar.gz | tar -xf -
## - Get postfixadmin patch if not yet downloaded
## -
## - That patch adds the capability to include the subject of the original mail in the
## - subject of the vacation message.
## - A good vacation subject could be: 'Re: $SUBJECT'
## - Also corrected log entry about "Already informed ..." to show the $orig_from, not $email
## -
## - !! Note:
## - Since Postfixadmin version 2.9.1, this patch is already included
## -
#if [ ! -f /usr/local/src/mailsystem/tarballs/vacation.pl_SUBJECT.patch ];then
# cd /usr/local/src/mailsystem/tarballs
# wget http://sourceforge.net/p/postfixadmin/patches/_discuss/thread/69a7ce85/b4e9/attachment/vacation.pl_SUBJECT.patch
# cd /usr/local/src/mailsystem
#fi
## - Apply patch
## -
#patch -p0 /usr/local/src/mailsystem/postfixadmin-${_pf_admin_version}/VIRTUAL_VACATION/vacation.pl \
# /usr/local/src/mailsystem/tarballs/vacation.pl_SUBJECT.patch
## - postfixadmin, version 2.91 is broken if database backend is PostgreSQL
## -
## - I have written a pacth, which fixes that errors
## -
#patch /usr/local/src/mailsystem/postfixadmin-${_pf_admin_version}/VIRTUAL_VACATION/vacation.pl \
# /usr/local/src/mailsystem/tarballs/vacation-4.0r1.pl_PGSQL.patch
if [ -f /var/spool/vacation/vacation.pl ]; then
mv /var/spool/vacation/vacation.pl /var/spool/vacation/vacation.pl.`date "+%Y%m%d-%H%M"`
fi
cp ${_src_base_dir}/postfixadmin-${_pf_admin_version}/VIRTUAL_VACATION/vacation.pl \
/var/spool/vacation/vacation.pl
## - Encoding does not work as exspected.
## -
## - NOTE:
## - this IS NOT a fix, but a workaround
## -
perl -i -n -p -e "s/(\s*\'ctype\'\s* =>\s*)\'text\/plain.*$/\1\'text\/plain; charset=iso-8859-1\',/" \
/var/spool/vacation/vacation.pl
chown ${vacation_user}:${vacation_group} /var/spool/vacation/vacation.pl
chmod 700 /var/spool/vacation/vacation.pl
## - Use 'Re: $SUBJECT' as the default subject template in postfixadmin
## -
perl -i -n -p -e "s#(^\s*\\\$PALANG\['pUsersVacation_subject_text'\].*$)#\#\1\n\\\$PALANG['pUsersVacation_subject_text'] = 'Re: \\\$SUBJECT';#" ${_src_base_dir}/postfixadmin-${_pf_admin_version}/languages/*.lang
cp -a ${_src_base_dir}/postfixadmin-${_pf_admin_version} ${APACHE_BASE_WEBDIR}/$HOSTNAME
cd ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}
find -type f -print0 | xargs -0 chmod 640
find -type f -print0 | xargs -0 chown root:$APACHE_GROUP
find -type d -print0 | xargs -0 chown root:$APACHE_GROUP
chown -R ${APACHE_USER}:$APACHE_GROUP templates_c
mkdir -p ${APACHE_BASE_WEBDIR}/$HOSTNAME/logs
cd ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}
## - configure postfixadmin
## -
## - edit file config.inc.php
## -
## - set:
## -
## - $CONF['postfix_admin_url'] = 'https://$HOSTNAME';
## -
## - $CONF['default_language'] = 'de';
## - $CONF['database_type'] = '$_db_type';
## - $CONF['database_host'] = 'localhost';
## - $CONF['database_user'] = '$_db_user';
## - $CONF['database_password'] = '$_db_pass';
## - $CONF['database_name'] = '$_db_name';
## - $CONF['database_prefix'] = '';
## - $CONF['admin_email'] = '$ADMIN_EMAIL';
## - $CONF['encrypt'] = '$_encrypt';
## - $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';
## - $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_domain';
## -
## - $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
## - );
## -
## - $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://${HOSTNAME}/main.php";
## - $CONF['footer_text'] = "Main Menu";
## - $CONF['footer_link'] = "http://${HOSTNAME}/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';
## -
## - $CONF['welcome_text'] = <<<EOM
## - $_welcome_email
## - EOM;
## -
## - after finished, you must also change the value of $CONF['configured']
## - to 'true'
## -
## - $CONF['configured'] = true;
perl -i.ORIG -n -p -e "s#^(\s*\\\$CONF\['postfix_admin_url'\]\s*=.*)#//!\1\n\\\$CONF['postfix_admin_url'] = 'https://$HOSTNAME';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['default_language'\]\s*=.*)#//!\1\n\\\$CONF['default_language'] = 'de';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_type'\]\s*=.*)#//!\1\n\\\$CONF['database_type'] = '$_db_type';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_host'\]\s*=.*)#//!\1\n\\\$CONF['database_host'] = 'localhost';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_user'\]\s*=.*)#//!\1\n\\\$CONF['database_user'] = '$_db_user';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_password'\]\s*=.*)#//!\1\n\\\$CONF['database_password'] = '$_db_pass';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_name'\]\s*=.*)#//!\1\n\\\$CONF['database_name'] = '$_db_name';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['database_prefix'\]\s*=.*)#//!\1\n\\\$CONF['database_prefix'] = '';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['admin_email'\]\s*=.*)#//!\1\n\\\$CONF['admin_email'] = '$ADMIN_EMAIL';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['encrypt'\]\s*=.*)#//!\1\n\\\$CONF['encrypt'] = '$_encrypt';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['default_aliases'\]\s*=.*)#//\n//! 'default_aliases' will be overridden - see end of configfile\n//\n\1#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
echo -e "\n\n\$CONF['default_aliases'] = array (\n 'abuse' => 'postmaster@$DOMAIN',\n 'postmaster' => 'postmaster@$DOMAIN'\n);\n" >> ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_path'\]\s*=.*)#//!\1\n\\\$CONF['domain_path'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_in_mailbox'\]\s*=.*)#//!\1\n\\\$CONF['domain_in_mailbox'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['aliases'\]\s*=.*)#//!\1\n\\\$CONF['aliases'] = '100';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['mailboxes'\]\s*=.*)#//!\1\n\\\$CONF['mailboxes'] = '100';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['maxquota'\]\s*=.*)#//!\1\n\\\$CONF['maxquota'] = '0';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_quota_default'\]\s*=.*)#//!\1\n\\\$CONF['domain_quota_default'] = '0';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['quota'\]\s*=.*)#//!\1\n\\\$CONF['quota'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['domain_quota'\]\s*=.*)#//!\1\n\\\$CONF['domain_quota'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['quota_multiplier'\]\s*=.*)#//!\1\n\\\$CONF['quota_multiplier'] = '1048576';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['transport_options'\]\s*=.*)#//\n//! \"transport_options\" will be overridden - see end of configfile\n//\n\1#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
echo -e "\n\n\$CONF['transport_options'] = array (\n 'lmtp:unix:private/dovecot-lmtp', // for virtual accounts\n 'local', // for system accounts\n 'relay' // for backup mx\n);\n\$CONF['transport_default'] = 'lmtp:unix:private/dovecot-lmtp';\n" >> ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['transport_default'\]\s*=.*)#//!\1\n\\\$CONF['transport_default'] = 'lmtp:unix:private/dovecot-lmtp';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['vacation'\]\s*=.*)#//!\1\n\\\$CONF['vacation'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['vacation_domain'\]\s*=.*)#//!\1\n\\\$CONF['vacation_domain'] = '$_autoreply_domain';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
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#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
cat <<EOF >> ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
// 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#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
cat <<EOF >> ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
// Welcome Message
// This message is send to every newly created mailbox.
// Change the text between EOM.
\$CONF['welcome_text'] = <<<EOM
$_welcome_email
EOM;
EOF
perl -i -n -p -e "s#^(\s*\\\$PALANG\['reply_every_mail'\]\s+=.*)#\1\n\\\$PALANG['reply_once_per_day'] = 'Einmal pro Tag antworten';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/languages/de.lang
perl -i -n -p -e "s#^(\s*\\\$PALANG\['reply_every_mail'\]\s+=.*)#\1\n\\\$PALANG['reply_once_per_day'] = 'Reply once per day';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/languages/en.lang
perl -i -n -p -e "s#^(\s*\\\$CONF\['alias_control_admin'\]\s+=.*)#//!\1\n\\\$CONF['alias_control_admin'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['alias_control'\]\s*=.*)#//!\1\n\\\$CONF['alias_control'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['special_alias_control'\]\s*=.*)#//!\1\n\\\$CONF['special_alias_control'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['backup'\]\s*=.*)#//!\1\n\\\$CONF['backup'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['fetchmail'\]\s*=.*)#//!\1\n\\\$CONF['fetchmail'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['user_footer_link'\]\s+=.*)#//!\1\n\\\$CONF['user_footer_link'] = 'https://${HOSTNAME}/main.php';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['footer_text'\]\s+=.*)#//!\1\n\\\$CONF['footer_text'] = 'Main Menu';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['footer_link'\]\s+=.*)#//!\1\n\\\$CONF['footer_link'] = 'http://${HOSTNAME}/main.php';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['emailcheck_resolve_domain'\]\s*=.*)#//!\1\n\\\$CONF['emailcheck_resolve_domain'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_status'\]\s*=.*)#//!\1\n\\\$CONF['show_status'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_status_key'\]\s*=.*)#//!\1\n\\\$CONF['show_status_key'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_undeliverable'\]\s*=.*)#//!\1\n\\\$CONF['show_undeliverable'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['show_popimap'\]\s*=.*)#//!\1\n\\\$CONF['show_popimap'] = 'NO';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['used_quotas'\]\s*=.*)#//!\1\n\\\$CONF['used_quotas'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
perl -i -n -p -e "s#^(\s*\\\$CONF\['new_quota_table'\]\s*=.*)#//!\1\n\\\$CONF['new_quota_table'] = 'YES';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
## - after finished, you must alos change the value of $CONF['configured']
## - to 'true'
## -
## - $CONF['configured'] = true;
perl -i -n -p -e "s#^(\s*\\\$CONF\['configured'\]\s*=.*)#//!\1\n\\\$CONF['configured'] = true;#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
## - AFTER DELETION MAILBOX
## -
## - activate script for moving a mailbox from the mailboxdirectory
## - and save it to the backupb directory /var/deleted-maildirs
## -
mkdir -p $deleted_maildirs
chown vmail:vmail $deleted_maildirs
chmod 700 $deleted_maildirs
if [ -f /usr/local/bin/postfixadmin-mailbox-postdeletion.sh ]; then
mv /usr/local/bin/postfixadmin-mailbox-postdeletion.sh \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh.`date "+%Y%m%d-%H%M"`
fi
cp ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/ADDITIONS/postfixadmin-mailbox-postdeletion.sh \
/usr/local/bin/
chmod 755 /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
## - chnage the posdeletion scripts to your needs:
## -
## - set:
## - basedir=/var/vmail
## - trashbase=$deleted_maildirs
## -
## - trashdir="${trashbase}/$2/`date +%F_$H-%M`_${subdir}"
## -
perl -i -n -p -e "s#^(\s*)(basedir=.*)#\#\1\2\n\1basedir=/var/vmail#" \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh
perl -i -n -p -e "s#^(\s*)(trashbase=.*)#\#\1\2\n\1trashbase=${deleted_maildirs}#" \
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh
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
## - edit ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/config.inc.php
## -
## - in section add line
## - $CONF['mailbox_postdeletion_script']='sudo -u vmail /usr/local/bin/postfixadmin-mailbox-postdeletion.sh';
## -
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';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
## - !! Notice:
## - Have a look at ${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
## -
visudo
## - AFTER DELETION MAILDOMIAN
## -
## - activate script for moving a mailbox from the mailboxdirectory
## - and save it to the backupb directory $deleted_maildomains
## -
mkdir -p $deleted_maildomains
chown vmail:vmail $deleted_maildomains
chmod 700 $deleted_maildomains
if [ -f /usr/local/bin/postfixadmin-domain-postdeletion.sh ]; then
mv /usr/local/bin/postfixadmin-domain-postdeletion.sh \
/usr/local/bin/postfixadmin-domain-postdeletion.sh.`date "+%Y%m%d-%H%M"`
fi
cp ${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/ADDITIONS/postfixadmin-domain-postdeletion.sh \
/usr/local/bin/
chmod 755 /usr/local/bin/postfixadmin-domain-postdeletion.sh
## - chnage the posdeletion scripts to your needs:
## -
## - set:
## - basedir=/var/vmail
## - trashbase=$deleted_maildomains
## -
## - trashdir="${trashbase}/`date +%F_%H-%M`_$1"
## -
perl -i -n -p -e "s#^(\s*)(basedir=.*)#\#\1\2\n\1basedir=/var/vmail#" \
/usr/local/bin/postfixadmin-domain-postdeletion.sh
perl -i -n -p -e "s#^(\s*)(trashbase=.*)#\#\1\2\n\1trashbase=${deleted_maildomains}#" \
/usr/local/bin/postfixadmin-domain-postdeletion.sh
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
## - edit ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/config.inc.php
## -
## - in section add line
## - $CONF['domain_postdeletion_script']='sudo -u vmail /usr/local/bin/postfixadmin-domain-postdeletion.sh';
## -
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';#" \
${APACHE_BASE_WEBDIR}/${HOSTNAME}/postfixadmin-${_pf_admin_version}/config.inc.php
## - !! Notice:
## - Have a look at ${APACHE_BASE_WEBDIR}/${HOSTNAME}/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
## -
visudo
cd ${APACHE_BASE_WEBDIR}/$HOSTNAME
if [ -h ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs ]; then
rm ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs
elif [ -d ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs -o -f ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs ]; then
mv ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs.`date +%Y%m%d-%H%M`
fi
ln -s postfixadmin-${_pf_admin_version} htdocs
## - Configure Postfixadmin - this will also create tables in database postfix
## -
http://${HOSTNAME}/setup.php
## - 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 ${APACHE_BASE_WEBDIR}/${HOSTNAME}/htdocs/config.inc.php
## - 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
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_relay-domain-maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = true
EOF
elif [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_relay-domain-maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT domain FROM domain WHERE domain = "%s" AND backupmx = 1
EOF
else
echo "[ FATAL ]: Unknown database type $_db_type"
fi
## - /etc/postfix/main.cf
## -
## - add to relay_domains:
## - proxy:$_db_type:/etc/postfix/$_db_type_relay-domain-maps.cf
## -
perl -i -n -p -e "s#\s*(relay_domains\s*=.*$)#\1\n proxy:${_db_type}:/etc/postfix/${_db_type}_relay-domain-maps.cf#" /etc/postfix/main.cf
## ---
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_sender_login_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_sender_login_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 $_db_type"
fi
## - /etc/postfix/main.cf
## -
## - add to smtpd_sender_login_maps:
## - proxy:$_db_type:/etc/postfix/${_db_type}_sender_login_maps.cf
## -
perl -i -n -p -e "s#\s*(smtpd_sender_login_maps\s*=.*$)#\1 proxy:${_db_type}:/etc/postfix/${_db_type}_sender_login_maps.cf#" /etc/postfix/main.cf
## ---
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_transport_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
## -
#table = domain
#select_field = transport
#where_field = domain
query = SELECT transport FROM domain WHERE domain ='%s';
EOF
elif [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_transport_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
## -
#table = domain
#select_field = transport
#where_field = domain
query = SELECT transport FROM domain WHERE domain ='%s';
EOF
fi
## - /etc/postfix/main.cf
## -
## - add to transport_maps:
## - proxy:${_db_type}:/etc/postfix/${_db_type}_transport_maps.cf
## -
perl -i -n -p -e "s#\s*(transport_maps\s*=.*$)#\1\n proxy:${_db_type}:/etc/postfix/${_db_type}_transport_maps.cf#" /etc/postfix/main.cf
## ---
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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
fi
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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
fi
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT goto FROM alias WHERE address='%s' AND active = true
EOF
elif [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
EOF
fi
## - Edit /etc/postfix/main.cf
## -
## - add to virtual_alias_maps:
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_maps.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_maps.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf
## - ## - mailman
## - #hash:/var/lib/mailman/data/virtual-mailman
## -
perl -i -n -p -e "s#\s*(virtual_alias_maps\s*=.*$)#\1\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_maps.cf\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_maps.cf\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf#" /etc/postfix/main.cf
## ---
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_mailbox_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = true
EOF
elif [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_mailbox_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
EOF
fi
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_mailbox_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_domain_mailbox_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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
fi
## - for the last 2 definitions write concerning entries
## - to virtual_mailbox_maps in /etc/postfix/main.cf
## -
## - might look like this:
## - virtual_mailbox_maps =
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_mailbox_maps.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_mailbox_maps.cf
## -
perl -i -n -p -e "s#\s*(virtual_mailbox_maps\s*=.*$)#\1\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_mailbox_maps.cf\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_mailbox_maps.cf#" /etc/postfix/main.cf
## ---
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_domains_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT domain FROM domain WHERE domain = '%s' AND active = true
EOF
elif [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_domains_maps.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_db_name
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
EOF
fi
## - Edit /etc/postfix/main.cf
## -
## - Add to virtual_mailbox_domains:
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_domains_maps.cf
## -
perl -i -n -p -e "s#\s*(virtual_mailbox_domains\s*=.*$)#\1\n proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_domains_maps.cf#" /etc/postfix/main.cf
## ---
## - address-extension with delimeter "-"
## -
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_address_rewriting.cf
## - this address rewriting acts as address extension
## - with delimeter "-"
## -
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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 [ "$_db_type" = "mysql" ];then
cat <<EOF > /etc/postfix/${_db_type}_virtual_alias_address_rewriting.cf
hosts = $_db_host
user = $_db_user
password = $_db_pass
dbname = $_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
fi
## - 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:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_maps.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_maps.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_address_rewriting.cf,
## - proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf
## - ## - mailman
## - #hash:/var/lib/mailman/data/virtual-mailman
## -
perl -i -n -p -e "s#(\s*proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_domain_catchall_maps.cf.*$)# proxy:${_db_type}:/etc/postfix/${_db_type}_virtual_alias_address_rewriting.cf\n\1#" /etc/postfix/main.cf
## ---
## - add a cronjob for analyzing and reindexing the postfix tables
## -
## - create a script doing tha staff
## -
mkdir -p /root/bin
if [ "$_db_type" = "pgsql" ]; then
cat <<EOF > /root/bin/analyze_reindex_pg-databases.sh
#!/bin/bash
curdir=\`pwd\`
cd /tmp
psql=\`which psql\`
grep=\`which grep\`
awk=\`which awk\`
DATABASES=\`/bin/su postgres -c "\$psql -lt" | \$grep -v -e"^\$" | \$grep -v -e "^\s*[:|]" | \$awk '{print\$1}'\`
for db in \$DATABASES ; do
if [ "\$db" == "template0" ]; then
continue
fi
#echo "Database...: \$db"
TABLES=\`/bin/su postgres -c "\$psql -t -q -c \"\dt \" \$db" | awk '{print\$3}'\`
#echo
for tbl in \$TABLES ; do
#echo -e "\tvacuum analyze table $tbl .."
/bin/su postgres -c "\$psql -q -c \"VACUUM ANALYZE \$tbl\" \$db"
[[ \$? -gt 0 ]] && echo "[ERROR]: vacuum/analyzing table \"\${tbl}\" of database \"\$db\" failed !!"
#echo -e "\treindex table \$tbl ..\n"
/bin/su postgres -c "\$psql -q -c \"REINDEX TABLE \$tbl\" \$db"
[[ \$? -gt 0 ]] && echo "[ERROR]: reindexing table \"\${tbl}\" of database \"\$db\" failed !!"
done
#echo
done
cd \$curdir
exit
EOF
chmod 755 /root/bin/analyze_reindex_pg-databases.sh
## - add crontab entry
## -
crontab -l > /tmp/tmp_crontab
cat <<EOF >> /tmp/tmp_crontab
## - analyze/reindex postgres tables and backup
## -
45 02 * * * /root/bin/analyze_reindex_pg-databases.sh
EOF
crontab /tmp/tmp_crontab
rm /tmp/tmp_crontab
fi
## - !!!!!!!!!!
## - !! 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
## - !!!!!!!!!!