diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca29c8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/BAK/* +/conf/*.conf +roundcubemail- diff --git a/DOC/roundcube.install b/DOC/roundcube.install index 190267a..cba9705 100644 --- a/DOC/roundcube.install +++ b/DOC/roundcube.install @@ -568,13 +568,14 @@ cat <.' +# - +WEBSITE_NAME="" + +# - IPv4 Address +# - +IPV4="" + +# - IPv6 Address +# - +IPV6="" + +# - Is apache installed from debian package system ? +# - +# - Boolean, possible values are 'true', 'false' +# - +# - Defaults to 'false' +# +#APACHE_DEBIAN_INSTALLATION="" + +# - Apache User +# - +# - If ommitted, script tries to determine the user under which user the webserver +# - is running. If that fails, parameter defaults to 'www-data' +# - +#HTTP_USER="" + +# - Apache Group +# - +# - If ommitted, script tries to determine the user under which group the webserver +# - is running. If that fails, parameter defaults to 'www-data' +# - +#HTTP_GROUP="" + +# - Webmasters E-Mail Address +# - +# - Defaults to 'admin@.' +# - +#WEBMASTER_EMAIL="" + +# - Base Directory of Roundcube Website +# - +# - Note: it's not the 'DocumentRoot' directory, but the directory where +# - the 'DocumentRoot' Directory lives. +# - +# - Defaults to '/var/www/webmail/$WEBSITE_NAME' +# - +#WEBSITE_BASEDIR="" + + +# - Directory for storing temporary files +# - +# - Defaults to '${WEBMAIL_BASEDIR}/temp" +# - +#ROUNDCUBE_TMPDIR="" + +# - Directory, where apache places the log-files for thw webmailers site. +# - +# - Defaults to '/var/log/apache2' +# - +#APACHE_LOG_DIR="" + +# - Directory where certificate and key for the roundcube website +# - are stored. +# - +# - Defaults to +# - '/etc/apache2' if apache is installed from debian package system +# - '/usr/local/apache2/conf' otherwise +# - +#APACHE_CERT_DIR="" + +# - Certificate for the Rounfcube Website +# - +# - Defaults to 'server-bundle.crt' +# - +#APACHE_SERVER_CERT="" + +# - Key File for the Rounfcube Website +# - +# - Defaults to 'server.key' +# - +#APACHE_SERVER_KEY="" + +# - Certification Chain File +# - +# - Deprecated since Apache 2.4 - Leave empty if not present +# - +#CERT_ChainFile="" + +# - Type of PHP installation. +# - +# - Possible values are: 'php_fpm' , 'fcgid' , 'mod_php +# - +# - defaults to 'php_fpm'' +# - +#PHP_TYPE="" + +# - Directory where apache vhosts definitions live. +# - +# - Defaults to +# - '/etc/apache2/sites-available' if installed from debain package system +# - '/usr/local/apache2/conf/vhosts' otherwise +# - +#APACHE_VHOST_DIR="" + +# - Hostname for vacation / absence messages +# - +# - Defaults to 'autoreply.. +# - +#AUTOREPLY_HOSTNAME="" + +# - Database type for Roundcube +# - +# - Possible values are 'pgsql' (PostgeSQL) or 'mysql' (MySQL) +# - +DB_TYPE="" + +# - Host of Roundcube Database +# - +# - Defaults to 'localhost' +# - +#DB_HOST="" + +# - Name of Roundcube Database +# - +# - Defaults to 'roundcubemail' +# - +#DB_NAME= + +# - User of Roundcube Database +# - +# - Defaults to 'roundcube' +# - +#DB_USER="" + +# - Password of Roundcube Database +# - +DB_PASS="" + + +# - Is MySQL installed from debian package system? +# - +# - Only needed, if DB_TYPE is set to 'mysql' +# - +# - Defaults to 'false' +# - +#MYSQL_DEBIAN_INSTALLATION="" + +# - mysql_credential_args (root access to MySQL Database) +# - +# - Example +# - mysql_credential_args="--login-path=local" +# - mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default) +# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf" +# - +# - Defaults to: +# - '/etc/mysql/debian.cnf' if MySQL is installed from debian package system +# - '/usr/local/mysql/sys-maint.cnf' otherwise +# - +#MYSQL_CREDENTIALS="" + +# - Name of the folder where (assumed) junk mails will be stored +# - +# - Defaults to 'Spam' +# - +#SPAM_FOLDER_NAME="" + +# - You can set your own product name to replace the default. +# - +# - Defaults to 'Roundcube Webmail' +# - +#PRODUCT_NAME="" + +# - URL for users, to get in contact if something goes wrong +# - +# - Defaults to 'www..' +# - +#SUPPORT_URL="" + +# - Provide your own logo under this URI +# - +# - Note: this script will NOT place the logo. You have to do this by your own +# - after installation is finisched. +# - +# - Default is empty +# - +#SKIN_LOGO="" + + + +# -------------------- +# - Plugins Configuration +# -------------------- + + +# ========== +# - Settings Postfix Database +# ========== + +# - Database type of +# - +# - used for setting $config['password_db_dsn'] +# - +# - Possible values are 'pgsql' (PostgeSQL) or 'mysql' (MySQL) +# - +POSTFIX_DB_TYPE="pgsql" + +# - Host of Roundcube Database +# - +# - used for setting $config['password_db_dsn'] +# - +# - Defaults to 'localhost' +# - +#POSTFIX_DB_HOST="" + +# - Name of Roundcube Database +# - +# - used for setting $config['password_db_dsn'] +# - +# - Defaults to 'postfix' +# - +#POSTFIX_DB_NAME= + +# - User of Roundcube Database +# - +# - used for setting $config['password_db_dsn'] +# - +# - Defaults to 'postfix' +# - +#POSTFIX_DB_USER="" + +# - Password of Roundcube Database +# - +# - used for setting $config['password_db_dsn'] +# - +POSTFIX_DB_PASSWD='CbX8vg347Vvm' + + +# === +# - Plugin acl +# === + +# - Activate plugin 'acl'? +# - +# - Boolean - possible values are 'true' and 'false' +# - +# - Defaults to 'false' +# - +#INCLUDE_ACL_PLUGIN="" + + +# === +# - Plugin password (change password) +# === + +# - Is current password reqired +# - +# - $config['password_confirm_current'] +# - +# - Boolean - possible values are 'true' and 'false' +# - +# - Defaults to 'true' +# - +#PW_CONFIRM_CURRENT="" + +# - Minimun length if new password +# - +# - $config['password_minimum_length'] +# - +# - Defaults to '10' +# - +#PW_MIN_LENGTH="" + +# - New Password requires nonalpha character +# - +# - $config['password_require_nonalpha'] +# - +# - Boolean - possible values are 'true' and 'false' +# - +# - Defaults to 'true' +# - +#PW_REQUIRE_NONALPHA='' + +# - Default password hashing/crypting algorithm. +# - +# - $config['password_algorithm'] +# - +# - Possible values: des-crypt, ext-des-crypt, md5-crypt, blowfish-crypt, +# - sha256-crypt, sha512-crypt, md5, sha, smd5, ssha, samba, +# - ad, dovecot, clear. +# - +# - Defaults to 'dovecot' +# - +#PW_PASSWD_ALGO='' + +# - Password prefix (e.g. {CRYPT}, {SHA}, {CRAM-MD5}) for passwords generated +# - +# - $config['password_algorithm_prefix'] +# - +# - Defaults to '{CRAM-MD5}' +# - +#PW_PASSWD_ALGO_PREFIX='' + +# - Path for dovecotpw/doveadm-pw +# - +# - $config['password_dovecotpw'] +# - +# - Defaults to '/usr/local/dovecot/bin/doveadm pw' +# - +#PW_DOVEADM_PW='' + +# - Dovecot password scheme. +# - +# - $config['password_dovecotpw_method'] +# - +# - Defaults to 'CRAM-MD5 +# - +#PW_DOVECOT_PW_METHOD= + +# - The SQL query used to change the password. +# - +# - $config['password_query'] +# - +PW_DB_UPDATE_STRING='UPDATE mailbox SET password=%P WHERE username=%u' + + +# ========== +# - Plugin password vacation +# ========== + +# - allow vacation forwarder +# - +# - $rcmail_config['vacation_gui_vacationforwarder'] = FALSE; +# - +# - defaults to 'false' +# - +#VAC_GUI_FORWARDER=false diff --git a/install_roundcube.sh b/install_roundcube.sh new file mode 100755 index 0000000..1dc6f1d --- /dev/null +++ b/install_roundcube.sh @@ -0,0 +1,2850 @@ +#!/usr/bin/env bash + +clear +echo -e "\n\t\033[32mStart script for installation Roundcube Webmailer..\033[m" + +## =================================================================== +## - Install Postfixadmin +## =================================================================== + +## ----------------------------------------------------------------- +## ---------------------------------------------------------------- +## --- +## --- For configurations see file conf/install_roundcube.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_roundcube.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" + echo "" + exit 1 +} + +error(){ + echo "" + echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" + echo "" +} +warn (){ + echo "" + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + echo "" +} +info (){ + echo "" + echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" + echo "" +} + + +echo_ok() { + echo -e "\033[75G[ \033[32mok\033[m ]" +} +echo_failed(){ + echo -e "\033[75G[ \033[1;31mfailed\033[m ]" +} +echo_skipped() { + echo -e "\033[75G[ \033[30m\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 + + +# - Default values +# - +DEFAULT_SPAM_FOLDER_NAME="Spam" +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_ROUNDCUBE_TMPDIR="${DEFAULT_WEBSITE_BASEDIR}/temp" +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_DB_HOST="localhost" +DEFAULT_DB_NAME="roundcubemail" +DEFAULT_DB_USER="roundcube" +DEFAULT_DEBIAN_MYSQL_CREDENTIALS="/etc/mysql/debian.cnf" +DEFAULT_MYSQL_CREDENTIALS="/usr/local/mysql/sys-maint.cnf" + +[[ -n "$ROUNDCUBE_VERSION" ]] || fatal "Roundcube Version (ROUNDCUBE_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##*.} + +[[ -n "$WEBMASTER_EMAIL" ]] || WEBMASTER_EMAIL="admin@${MAIN_DOMAIN}.$TLD" + +[[ -n "$ROUNDCUBE_TMPDIR" ]] || ROUNDCUBE_TMPDIR="$DEFAULT_ROUNDCUBE_TMPDIR" + +[[ -n "$IPV4" ]] || fatal "IPv4 Address (IPV4) not present!" +[[ -n "$IPV6" ]] || fatal "IPv4 Address (IPV6) not present!" + +[[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false + +httpd_binary="`which httpd`" +if [ -z "$httpd_binary" ]; then + httpd_binary="`ps -C httpd -f | grep -e \"^root\" | awk '{print$8}'`" + if [ -z "$httpd_binary" ]; then + if [ -x "/usr/local/apache2/bin/httpd" ]; then + httpd_binary="/usr/local/apache2/bin/httpd" + fi + fi +fi + +if [ -x "$httpd_binary" ];then + + # - Determin websever user + # - + HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" + + [[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER + [[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP + + # - Is webserver running ? + # - + PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') + if [[ "X${PID}X" = "XX" ]] ;then + IS_HTTPD_RUNNING=false + else + IS_HTTPD_RUNNING=true + fi +fi + +[[ -n "$WEBMASTER_EMAIL" ]] || fatal "E-Mail (WEBMASTER_EMAIL) for webmaster not present!" +[[ -n "$WEBSITE_BASEDIR" ]] || WEBSITE_BASEDIR=$DEFAULT_WEBSITE_BASEDIR + +if [[ -z "$APACHE_CERT_DIR" ]] ; then + if $APACHE_DEBIAN_INSTALLATION ; then + APACHE_CERT_DIR="$DEFAULT_DEBIAN_APACHE_CERT_DIR" + else + APACHE_CERT_DIR="$DEFAULT_APACHE_CERT_DIR" + fi +fi + +[[ -n "$APACHE_SERVER_CERT" ]] || APACHE_SERVER_CERT=$DEFAULT_APACHE_SERVER_CERT +[[ -n "$APACHE_SERVER_KEY" ]] || APACHE_SERVER_KEY=$DEFAULT_APACHE_SERVER_KEY + +[[ -n "$APACHE_LOG_DIR" ]] || APACHE_LOG_DIR=$DEFAULT_APACHE_LOG_DIR + +if [[ -z "$PHP_TYPE" ]]; then + PHP_TYPE="php_fpm" +else + [[ "$PHP_TYPE" = "php_fpm" ]] || [[ "$PHP_TYPE" = "fcgid" ]] || [[ "$PHP_TYPE" = "mod_php" ]] || fatal "Wrong type of PHP (PHP_TYPE) given!" +fi + + +if [[ -z "$APACHE_VHOST_DIR" ]] ; then + if $APACHE_DEBIAN_INSTALLATION ; then + APACHE_VHOST_DIR="$DEFAULT_DEBIAN_APACHE_VHOST_DIR" + else + APACHE_VHOST_DIR="$DEFAULT_APACHE_VHOST_DIR" + fi +fi + +[[ -n "$AUTOREPLY_HOSTNAME" ]] || AUTOREPLY_HOSTNAME=autoreply.${MAIN_DOMAIN}.$TLD + + +[[ -n "$DB_TYPE" ]] || fatal "Database Type of Roundcube Database (DB_TYPE) not present!" +[[ -n "$DB_HOST" ]] || DB_HOST="$DEFAULT_DB_HOST" +[[ -n "$DB_NAME" ]] || DB_NAME="$DEFAULT_DB_NAME" +[[ -n "$DB_USER" ]] || DB_USER="$DEFAULT_DB_USER" +[[ -n "$DB_PASS" ]] || fatal "Password of Roundcube Database (DB_PASS) not given!" + +[[ -n "$MYSQL_DEBIAN_INSTALLATION" ]] || MYSQL_DEBIAN_INSTALLATION=false + +if [[ "$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 + [[ "$DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$DB_TYPE' (DB_TYPE)" +fi + +[[ -n "$SPAM_FOLDER_NAME" ]] || SPAM_FOLDER_NAME=$DEFAULT_SPAM_FOLDER_NAME + +[[ -n "$SUPPORT_URL" ]] || SUPPORT_URL="http://www.${MAIN_DOMAIN}.$TLD" + +SKIN_LOGO_PRESENT=false +if [[ -f "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO}" ]]; then + SKIN_LOGO_PRESENT=true + SKIN_LOGO_DIR="$(dirname $SKIN_LOGO)" + SKIN_LOGO_FILE="$(basename $SKIN_LOGO)" + cp -a ${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO} /tmp/ +fi + +# --- +# - Plugins +# -- + +# - Pligin acl +# - +[[ -n "$INCLUDE_ACL_PLUGIN" ]] || INCLUDE_ACL_PLUGIN=false + + +# - Plugin passord +# - +[[ -n "$PW_CONFIRM_CURRENT" ]] || PW_CONFIRM_CURRENT=true +[[ -n "$PW_MIN_LENGTH" ]] || PW_MIN_LENGTH=10 +[[ -n "$PW_REQUIRE_NONALPHA" ]] || PW_REQUIRE_NONALPHA=true +[[ -n "$PW_PASSWD_ALGO" ]] || PW_PASSWD_ALGO="dovecot" +[[ -n "$PW_PASSWD_ALGO_PREFIX" ]] || PW_PASSWD_ALGO_PREFIX="{CRAM-MD5}" + +[[ -n "$POSTFIX_DB_TYPE" ]] || fatal "Plugin password: Database Type for Password Database (POSTFIX_DB_TYPE) not given!" +if [[ "$POSTFIX_DB_TYPE" != "pgsql" ]] && [[ "$POSTFIX_DB_TYPE" != "mysql" ]]; then + fatal "Unknown Database Type '$POSTFIX_DB_TYPE' for Password Database (POSTFIX_DB_TYPE)" +fi +[[ -n "$POSTFIX_DB_HOST" ]] || POSTFIX_DB_HOST="localhost" +[[ -n "$POSTFIX_DB_NAME" ]] || POSTFIX_DB_NAME="postfix" +[[ -n "$POSTFIX_DB_USER" ]] || POSTFIX_DB_USER="postfix" +[[ -n "$POSTFIX_DB_PASSWD" ]] || fatal "Plugin password: Password for Password Database (POSTFIX_DB_PASSWD) not given!" +[[ -n "$PW_DB_UPDATE_STRING" ]] || fatal "Plugin password: No SQL query for changing password present!" +[[ -n "$PW_DOVEADM_PW" ]] || PW_DOVEADM_PW='/usr/local/dovecot/bin/doveadm pw' +[[ -n "$PW_DOVECOT_PW_METHOD" ]] || PW_DOVECOT_PW_METHOD='CRAM-MD5' + +# - Plugin vacation +# - +[[ -n "$VAC_GUI_FORWARDER" ]] || VAC_GUI_FORWARDER=false + + +# - Determin PHP of all installed versions +# - +echononl "\tGet major numbers of all installed PHP versions" +php_major_versions=`find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort` +if [[ -z "$php_major_versions" ]]; then + echo_failed + error "Getting major numbers of installed PHP versions failed! No installed PHP versiond found!" +else + echo_ok +fi + +# - Get the latest PHP version +# - +echononl "\tGet major number of latest installed PHP version" +php_latest_ver="" +if [[ -n "$php_major_versions" ]]; then + for _ver in $php_major_versions ; do + if [[ -z "$php_latest_ver" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then + php_latest_ver=$_ver + elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then + [[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver + fi + done + echo_ok +else + echo_skipped + warn "Getting major number of latest installed PHP version failed! - No installed PHP versiond found!" +fi + +echo "" +echo "" +echo -e "\033[1;32mSettings for installation of \033[1;37mRoundcube Webmail\033[m" +echo "" +echo -e "\tRoundcube Version....................: $ROUNDCUBE_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 Roundcube Website..: $WEBSITE_BASEDIR" +echo "" +echo -e "\tRoundcube TEMP Directory.............: $ROUNDCUBE_TMPDIR" +echo -e "\tRoundcube LOG Directory..............: ${WEBSITE_BASEDIR}/logs" +echo -e "\tType of PHP connection...............: $PHP_TYPE" +echo "" +echo -e "\tInstalled PHP versions...............: $php_major_versions" +echo -e "\tNewest PHP Version...................: $php_latest_ver" +echo "" +if [[ "$DB_TYPE" = "mysql" ]]; then + echo -e "\tDatabase type of Roundcube Database..: MySQL" + echo -e "\tMySQL from Debian Package System.....: $MYSQL_DEBIAN_INSTALLATION" +else + echo -e "\tDatabase type of Roundcube Database..: PostgreSQL" +fi +echo -e "\tHost of Roundcube Database...........: $DB_HOST" +echo -e "\tName of Roundcube Database...........: $DB_NAME" +echo -e "\tUser of Roundcube Database...........: $DB_USER" +echo -e "\tPassword of Roundcube Database.......: $DB_PASS" +if [[ "$DB_TYPE" = "mysql" ]]; then + echo -e "\tMySQL Credentials (root access)......: $MYSQL_CREDENTIALS" +fi +echo "" +echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME" +echo "" +echo -e "\tName of Junk Folder..................: $SPAM_FOLDER_NAME" +echo "" +echo "" +echo -e "\tInclude 'acl' plugin?..................: $INCLUDE_ACL_PLUGIN" + +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 Roundcube Webmailer \033[1;37m$network \033[m" + echo "" +else + fatal "Abort by user request - Answer as not 'YES'" +fi + + + +_log_dir=${_src_base_dir}/log-roundcube-$_version + + +## ---------------------------- +## - Begin Installation + +## - REQUIREMENTS +## - ============ +## - +## - * The Apache, Lighttpd, Cherokee or Hiawatha web server +## - * .htaccess support allowing overrides for DirectoryIndex +## - * PHP Version 5.2.1 or greater including +## - - PCRE, DOM, JSON, XML, Session, Sockets (required) +## - - libiconv (recommended) +## - - mbstring, fileinfo, mcrypt (optional) +## - * PEAR packages distributed with Roundcube or external: +## - - MDB2 2.5.0 or newer +## - - Mail_Mime 1.8.1 or newer +## - - Mail_mimeDecode 1.5.5 or newer +## - - Net_SMTP 1.4.2 or newer +## - - Net_IDNA2 0.1.1 or newer +## - - Auth_SASL 1.0.6 or newer +## - * php.ini options (see .htaccess file): +## - - error_reporting E_ALL & ~E_NOTICE (or lower) +## - - memory_limit > 16MB (increase as suitable to support large attachments) +## - - file_uploads enabled (for attachment upload features) +## - - session.auto_start disabled +## - - zend.ze1_compatibility_mode disabled +## - - suhosin.session.encrypt disabled +## - - mbstring.func_overload disabled +## - - magic_quotes_runtime disabled +## - - magic_quotes_sybase disabled +## - * PHP compiled with OpenSSL to connect to IMAPS and to use the spell checker +## - * A MySQL (4.0.8 or newer), PostgreSQL, MSSQL database engine +## - or the SQLite extension for PHP +## - * One of the above databases with permission to create tables +## - * An SMTP server (recommended) or PHP configured for mail delivery + +needed_php_pear_modules=" + MDB2 + Mail_Mime + Mail_mimeDecode + Net_SMTP + Net_IDNA2 + Auth_SASL" + +if [[ "$DB_TYPE" = "pgsql" ]]; then + needed_php_pear_modules="$needed_php_pear_modules MDB2_Driver_pgsql" +else + needed_php_pear_modules="$needed_php_pear_modules MDB2_Driver_mysql MDB2_Driver_mysqli" +fi + +## - install php PEAR packages +## - +## - !! Take care to do this for all php installations (PHP 5.5/5.6/..) +## - +for _version in $php_major_versions ; do + + echo -e "\n\n\t\033[37m\033[1mInstall modules for PHP Version ${_version}..\033[m\n" + + for _module in $needed_php_pear_modules ; do + echononl "\tInstall Module '$_module'.." + if ! /usr/local/php-${_version}/bin/pear list | grep -q "$_module" 2> /dev/null ; then + /usr/local/php-${_version}/bin/pear install $_module > $log_file 2>&1 + if [[ "$?" = "0" ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + if [[ "$_module" = "Net_IDNA2" ]]; then + echononl "\tInstall (beta) Net_IDNA2-0.1.1 .." + /usr/local/php-${_version}/bin/pear install channel://pear.php.net/Net_IDNA2-0.1.1 > $log_file 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + fi + fi + else + echo_skipped + fi + done +done + + +echo -e "\n\n\t\033[37m\033[1mBase install Roundcube Webmail..\033[m\n" + +# - install roundcube +# - +echononl "\tDownload 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ ! -f "$_src_base_dir/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz" ]]; then + wget -O ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + + +echononl "\tBackup existing source directory 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ -d "${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}" ]] ;then + mv ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} \ + ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.`date +%Y%m%d-%H%M` > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tUnpack 'roundcubemail-${ROUNDCUBE_VERSION}'.." +gunzip < ${_src_base_dir}/roundcubemail-${ROUNDCUBE_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 'roundcubemail-${ROUNDCUBE_VERSION}'.." +if [[ -d "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" ]]; then + mv ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}.`date +%Y%m%d-%H%M` > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tCopy Roundcube to web-directory" +cp -a ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} $WEBSITE_BASEDIR/ > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tSet Permissions 'root:root' on \n\t ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" +chown -R root:root $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tRemove existing symlink '${WEBSITE_BASEDIR}/htdocs'" +if [[ -h "${WEBSITE_BASEDIR}/htdocs" ]]; then + rm ${WEBSITE_BASEDIR}/htdocs + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi +echononl "\tCreate Symlink for DocumentRoot Directory 'htdocs'.." +if [[ ! -h "${WEBSITE_BASEDIR}/htdocs" ]]; then + ln -s roundcubemail-${ROUNDCUBE_VERSION} ${WEBSITE_BASEDIR}/htdocs > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +if $SKIN_LOGO_PRESENT ; then + _failed=false + echononl "\tRestore logo '$SKIN_LOGO_FILE'" + if [[ ! -d "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR}" ]]; then + mkdir ${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR} > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + mv /tmp/$SKIN_LOGO_FILE ${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR}/ >> $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 + +echononl "\tCreate Roundcube LOG directory '${WEBSITE_BASEDIR}/logs'" +if [[ ! -d "${WEBSITE_BASEDIR}/logs" ]]; then + mkdir ${WEBSITE_BASEDIR}/logs > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tSet Permissions on Roundcube LOG directory '${WEBSITE_BASEDIR}/logs'.." +chown -R ${HTTP_USER}:$HTTP_GROUP ${WEBSITE_BASEDIR}/logs > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tCreate Roundcube TMP directory (ROUNDCUBE_TMPDIR)" +if [[ ! -d "$ROUNDCUBE_TMPDIR" ]]; then + mkdir $ROUNDCUBE_TMPDIR > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tSet Permissions on Roundcube TMP directory '${ROUNDCUBE_TMPDIR}'.." +chown -R ${HTTP_USER}:$HTTP_GROUP $ROUNDCUBE_TMPDIR > $log_file 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +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 + +echononl "\tCreate Web-Directory '$WEBSITE_BASEDIR'.." +if [[ ! -d "$WEBSITE_BASEDIR" ]]; then + mkdir $WEBSITE_BASEDIR + 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 < ${WEBSITE_BASEDIR}/conf/fcgid-$_version 2> $log_file +#!/bin/sh +export PHPRC="${WEBSITE_BASEDIR}/conf/" +export TMPDIR="${WEBSITE_BASEDIR}/tmp" +# PHP child process management (PHP_FCGI_CHILDREN) should +# always be disabled with mod_fcgid, which will only route one +# request at a time to application processes it has spawned; +# thus, any child processes created by PHP will not be used +# effectively. (Additionally, the PHP child processes may not +# be terminated properly.) By default, and with the environment +# variable setting PHP_FCGI_CHILDREN=0, PHP child process +# management is disabled. +PHP_FCGI_CHILDREN=0 +export PHP_FCGI_CHILDREN + +exec /usr/local/php-${_version}/bin/php-cgi +EOF + if [[ "$?" = "0" ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf/fcgid-$_version'.." + _failed=false + chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + chmod 750 ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + if ! $_failed ; then + echo_ok + fi + done + + # - Create Symlinks in fcgid's config directory + # - + if [[ "$_version" = "$php_latest_ver" ]]; then + echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/php.ini'.." + if [[ ! -h "${WEBSITE_BASEDIR}/conf/php.ini" ]]; then + ln -s php.ini-$_version ${WEBSITE_BASEDIR}/conf/php.ini > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi + + echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/fcgid'.." + if [[ ! -h "${WEBSITE_BASEDIR}/conf/fcgid" ]]; then + ln -s fcgid-$_version ${WEBSITE_BASEDIR}/conf/fcgid > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi + + fi + + echononl "\tCreate file '${WEBSITE_BASEDIR}/conf/changes.php.ini.txt'.." + cat << EOF > ${WEBSITE_BASEDIR}/conf/changes.php.ini.txt +error_log = "${WEBSITE_BASEDIR}/logs/php_errors.log" +sys_temp_dir = "${WEBSITE_BASEDIR}/tmp" +upload_tmp_dir = "${WEBSITE_BASEDIR}/tmp" +session.save_path = "${WEBSITE_BASEDIR}/sessions" +soap.wsdl_cache_dir = "${WEBSITE_BASEDIR}/tmp" +EOF + if [[ "$?" = "0" ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + echononl "\tCreate file '${WEBSITE_BASEDIR}/logs/php_errors.log'.." + + if [[ ! -f "${WEBSITE_BASEDIR}/logs/php_errors.log" ]]; then + touch ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + chown ${HTTP_USER}:${HTTP_GROUP} ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + if ! $_failed ; then + echo_ok + fi + else + echo_skipped + fi + + _php_ini_file="${WEBSITE_BASEDIR}/conf/php.ini-*" + + echononl "\tAdjust files '${WEBSITE_BASEDIR}/conf/php.ini-*'.." + _failed=false + _key=error_log + _val="${WEBSITE_BASEDIR}/logs/php_errors.log" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1 + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1 + fi + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + + _key="sys_temp_dir" + _val="${WEBSITE_BASEDIR}/tmp" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1 + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1 + fi + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + + _key="upload_tmp_dir" + _val="${WEBSITE_BASEDIR}/tmp" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1 + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1 + fi + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + + _key="session.save_path" + _val="${WEBSITE_BASEDIR}/sessions" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1 + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1 + fi + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + + _key="soap.wsdl_cache_dir" + _val="${WEBSITE_BASEDIR}/tmp" + if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + #sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file + perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1 + elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then + sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1 + fi + if [[ $? -ne 0 ]]; then + _failed=true + error "$(cat $log_file)" + fi + + if ! $_failed ; then + echo_ok + fi + +fi + + +echo -e "\n\n\t\033[37m\033[1mConfigure Apache Webservice\033[m\n" + + +SSLCertificateChainFile="" +# - Create SSCertificateChainFile rule for apache vhost entry +# - +echononl "\tCreate SSCertificateChainFile rule for apache vhost entry" +if [ -n "$CERT_ChainFile" ];then + SSLCertificateChainFile="SSLCertificateChainFile ${APACHE_CERT_DIR}/$CERT_ChainFile" + echo_ok +else + echo_skipped +fi + + +echo "" + +# - Save existing vhost file +# - +echononl "\tSave existing vhost file.." +if [ -f ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ];then + if [[ -f "${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf" ]]; then + mv ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf.`date +%Y%m%d-%H%M` > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi +else + echo_skipped +fi + +echononl "\tCreate VHost Configuration '${WEBSITE_NAME}.conf'.." +_failed=false +cat < ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file +# -- $WEBSITE_NAME -- # + + + + 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 + + + + + + + ServerAdmin $WEBMASTER_EMAIL + + ServerName $WEBSITE_NAME + +EOF +if [[ $? -ne 0 ]]; then + failed=true +fi + +if [[ "$PHP_TYPE" = "mod_php" ]] ; then + cat <> ${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" + php_admin_value session.save_path "${WEBSITE_BASEDIR}/sessions" + + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" +EOF + if [[ $? -ne 0 ]]; then + failed=true + fi +elif [[ "$PHP_TYPE" = "fcgid" ]]; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" + + Require all granted + FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php + + SetHandler fcgid-script + + Options +ExecCGI + +EOF + if [[ $? -ne 0 ]]; then + failed=true + fi +elif [[ "$PHP_TYPE" = "php_fpm" ]]; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" + + + SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1" + + + + DirectoryIndex index.php index.html + +EOF + if [[ $? -ne 0 ]]; then + failed=true + fi +fi +cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + + SSLEngine on + + # - HTTP Strict Transport Security (HSTS) + # - + # - HSTS tells a browser that the website should only be accessed through + # - a secure connection. The HSTS header will be remembered by a standard + # compliant browser for max-age seconds. + # - + # - Remember this settings for 1 year + # - + Header always set Strict-Transport-Security "max-age=31536000" + + SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT + SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY + $SSLCertificateChainFile + + CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined + ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log + + + + +# --- +# --- IPv6 +# --- + + + + 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 + + + + + + + ServerAdmin $WEBMASTER_EMAIL + + ServerName $WEBSITE_NAME + +EOF +if [[ $? -ne 0 ]]; then + _failed=true +fi + +if [[ "$PHP_TYPE" = "mod_php" ]]; then + + cat <> ${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" + php_admin_value session.save_path "${WEBSITE_BASEDIR}/sessions" + + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" +EOF + if [[ $? -ne 0 ]]; then + _failed=true + fi +elif [[ "$PHP_TYPE" = "fcgid" ]]; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" + + Require all granted + FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php + + SetHandler fcgid-script + + Options +ExecCGI + +EOF + if [[ $? -ne 0 ]]; then + _failed=true + fi +elif [[ "$PHP_TYPE" = "php_fpm" ]]; then + cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + DocumentRoot "${WEBSITE_BASEDIR}/htdocs/" + + + SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1" + + + + DirectoryIndex index.php index.html + +EOF + if [[ $? -ne 0 ]]; then + failed=true + fi +fi +cat <> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file + + SSLEngine on + + # - HTTP Strict Transport Security (HSTS) + # - + # - HSTS tells a browser that the website should only be accessed through + # - a secure connection. The HSTS header will be remembered by a standard + # compliant browser for max-age seconds. + # - + # - Remember this settings for 1 year + # - + Header always set Strict-Transport-Security "max-age=31536000" + + SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT + SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY + $SSLCertificateChainFile + + CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined + ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log + + +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 + ## - + ## - .. + ## - 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 + ## - + ## - .. + #vim /etc/apache2/ports.conf + + + ## - enable site webmail.warenform.de + ## - + echononl "\tEnable ${WEBSITE_NAME}.conf" + a2ensite ${WEBSITE_NAME}.conf > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +fi + +echononl "\tCreate 'robots.txt'.." +cat < ${WEBSITE_BASEDIR}/htdocs/robots.txt 2> $log_file +User-agent: * +Disallow: / +EOF +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tRestart Apache Webservice.." +if $APACHE_DEBIAN_INSTALLATION ; then + /etc/init.d/apache2 reload > $log_file 2>&1 +else + /etc/init.d/apache2 restart > $log_file 2>&1 +fi +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +# - Install a cronjob for cleaning up tmp-directory +# - +if [[ "$PHP_TYPE" = "fcgid" ]] ; then + echononl "\tCreate cronjob for cleaning up tmp-directory.." + crontab -l > /tmp/tmp_crontab + if ! grep -q -E "find\s+${WEBSITE_BASEDIR}/tmp\s*-type\s*f" /tmp/tmp_crontab 2> /dev/null ; then + echo "" >> /tmp/tmp_crontab + echo "# - Cleanup tmp directory of the Rounfcube Webmailer" >> /tmp/tmp_crontab + echo "# -" >> /tmp/tmp_crontab + echo "23 3 * * * find $WEBSITE_BASEDIR/tmp -type f -mtime +1 -exec rm -f {} \;" >> /tmp/tmp_crontab + crontab /tmp/tmp_crontab + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + else + echo_skipped + fi + rm /tmp/tmp_crontab +fi + + +# - Logrotate logfiles from webmailer, locatet at $WEBSITE_BASEDIR/logs +# - +echononl "\tCreate logrotate entry.." +if [[ "$PHP_TYPE" = "fcgid" ]] ; then + cat < /etc/logrotate.d/roundcube 2> $log_file +$WEBSITE_BASEDIR/logs/errors +$WEBSITE_BASEDIR/logs/sql +$WEBSITE_BASEDIR/logs/sendmail +$WEBSITE_BASEDIR/logs/*.log { + daily + start 0 + rotate 7 + missingok + notifempty + compress + delaycompress + create 640 www-data www-data + copytruncate +} +EOF + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +elif [[ "$APACHE_LOG_DIR" =~ ${WEBSITE_BASEDIR} ]] ; then + cat < /etc/logrotate.d/roundcube 2> $log_file +$APACHE_LOG_DIR/*.log { + daily + start 0 + rotate 7 + missingok + notifempty + compress + delaycompress + create 640 www-data www-data + copytruncate +} +EOF + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + + +echo -e "\n\n\t\033[37m\033[1mSetup Database '$DB_TYPE'..\033[m\n" + +# - Datenbank etstellen: +# - +# - MySQL/PostgreSQL Datenbank erstellen +# - +# - +echo "" +echononl "\tCreate Database if needed" +_failed=false +if [ "$DB_TYPE" = "mysql" ]; then + if ! mysql -u$_mysql_rootuser -p$_mysql_rootpass -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 -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ + "CREATE DATABASE IF NOT EXISTS $DB_NAME CHARACTER SET utf8 COLLATE utf8_general_ci" + if [[ $0 -ne 0 ]]; then + _failed=true + fi + mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \ + "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'" + if [[ $0 -ne 0 ]]; then + _failed=true + fi + mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e "FLUSH PRIVILEGES" + if [[ $0 -ne 0 ]]; then + _failed=true + fi + if ! $_failed ; then + echo_ok + else + echo_failed + fi + else + echo_skipped + 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 + if [[ $0 -ne 0 ]]; then + _failed=true + fi + su - postgres -c "createdb -E utf8 -O $DB_USER $DB_NAME" + if [[ $0 -ne 0 ]]; then + _failed=true + fi + if ! $_failed ; then + echo_ok + else + echo_failed + fi + else + echo_skipped + fi +else + echo_skipped +fi + + +info "Now browse to the intaller site and continue installation.\n$(cat <>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file + +// ================================== +// Added after basic installation +// ================================== + +// This key is used for encrypting purposes, like storing of imap password +// in the session. For historical reasons it's called DES_key, but it's used +// with any configured cipher_method (see below). +\$config['des_key'] = '$_des_key'; + +// ---------------------------------- +// SYSTEM +// ---------------------------------- + +// Allow browser-autocompletion on login form. +// 0 - disabled, 1 - username and host only, 2 - username, host, password +\$config['login_autocomplete'] = 1; + +// Path to a local mime magic database file for PHPs finfo extension. +// Set to null if the default path should be used. +\$config['mime_magic'] = '/usr/share/misc/magic'; + + +// ---------------------------------- +// USER PREFERENCES +// ---------------------------------- + +// Clear Trash on logout +\$config['logout_purge'] = true; + +// 'Delete always' +// This setting reflects if mail should be always deleted +// when moving to Trash fails. This is necessary in some setups +// when user is over quota and Trash is included in the quota. +\$config['delete_always'] = true; + +EOF +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\n\n\t\033[37m\033[1mEnable Spellcheccking..\033[m\n" + +needed_packages_spell="" +_needed_packages_spell=" + aspell-en + aspell-de + aspell-da + aspell-es + aspell-fr + aspell-it" +for _pkg in $_needed_packages_spell ; do + if aptitude search "$_pkg" | grep " $_pkg " | grep -e "^i" > /dev/null 2>&1 ; then + continue + else + needed_packages_spell="$needed_packages_spell $_pkg" + fi +done +if [[ -n "$needed_packages_spell" ]]; then + DEBIAN_FRONTEND=noninteractive apt-get -y install $needed_packages_spell > /dev/null 2> "$log_file" + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi +else + echo_skipped +fi + +echononl "\tAdjust Roundcube Configuration for specclchecking" +cat <>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file + +// ---------------------------------- +// USER INTERFACE +// ---------------------------------- + +// Make use of the built-in spell checker. It is based on GoogieSpell. +// Since Google only accepts connections over https your PHP installatation +// requires to be compiled with Open SSL support +\$config['enable_spellcheck'] = true; + +// Enables spellchecker exceptions dictionary. +// Setting it to 'shared' will make the dictionary shared by all users. +\$config['spellcheck_dictionary'] = false; + +// Set the spell checking engine. Possible values: +// - 'googie' - the default +// - 'pspell' - requires the PHP Pspell module and aspell installed +// - 'enchant' - requires the PHP Enchant module +// - 'atd' - install your own After the Deadline server or check with the people at http://www.afterthedeadline.com before using their API +// Since Google shut down their public spell checking service, you need to +// connect to a Nox Spell Server when using 'googie' here. Therefore specify the 'spellcheck_uri' +\$config['spellcheck_engine'] = 'pspell'; + +// For locally installed Nox Spell Server or After the Deadline services, +// please specify the URI to call it. +// Get Nox Spell Server from http://orangoo.com/labs/?page_id=72 or +// the After the Deadline package from http://www.afterthedeadline.com. +// Leave empty to use the public API of service.afterthedeadline.com +\$config['spellcheck_uri'] = ''; + +// These languages can be selected for spell checking. +// Configure as a PHP style hash array: array('en'=>'English', 'de'=>'Deutsch'); +// Leave empty for default set of available language. +// +// Take care tha dictionaries for aspell ar installed ! +// for debian: +// apt-get install aspell-en aspell-de aspell-da aspell-es aspell-fr aspell-it +\$config['spellcheck_languages'] = array( + 'en' => 'English', + 'de' => 'Deutsch', + 'da' => 'Dansk', + 'fr' => 'Français', + 'it' => 'Italiano', + 'es' => 'Español', +); +// Makes that words with all letters capitalized will be ignored (e.g. GOOGLE) +\$config['spellcheck_ignore_caps'] = true; + +// Makes that words with numbers will be ignored (e.g. g00gle) +\$config['spellcheck_ignore_nums'] = true; + +// Makes that words with symbols will be ignored (e.g. g@@gle) +\$config['spellcheck_ignore_syms'] = true; + +EOF +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + + +echo -e "\n\n\t\033[37m\033[1mAdd/Configure Plugins..\033[m" +declare -a add_plugin_arr + + +# - acl +# - +if $INCLUDE_ACL_PLUGIN ; then + _plugin="acl" + add_plugin_arr+=("$_plugin") + echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" + echononl "\tCopy default config file to 'config.inc.php'.." + cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + echononl "\tActivate advanced mode.." + _key="acl_advanced_mode" + _val="true" + perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi + + echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + +fi + + +# - archive +# - +_plugin="archive" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echo -e "\tNothing to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - contextmenu +# - +_plugin="contextmenu" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tDownload Pluging '$_plugin'.." +wget -O ${WEBSITE_BASEDIR}/Roundcube-Plugin-Context-Menu-master.zip \ + https://github.com/JohnDoh/Roundcube-Plugin-Context-Menu/archive/master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tUnpack archiv into Plugin Folder" +unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ + ${WEBSITE_BASEDIR}/Roundcube-Plugin-Context-Menu-master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi +echononl "\tCeate Symlink '$_pligin' in plugin folder.." +ln -s Roundcube-Plugin-Context-Menu-master \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - jqueryui +# - +_plugin="jqueryui" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tCopy default config file to 'config.inc.php'.." +cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - login_lang +# - +_plugin="login_lang" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tDownload Pluging '$_plugin' (roundcube-login-language-master)" +wget -O ${WEBSITE_BASEDIR}/roundcube-login-language-master.zip \ + https://github.com/hassansin/roundcube-login-language/archive/master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tUnpack archiv into Plugin Folder" +unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ + ${WEBSITE_BASEDIR}/roundcube-login-language-master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tCeate Symlink '$_pligin' in plugin folder.." +ln -s roundcube-login-language-master \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tCopy default config file to 'config.inc.php'.." +cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tChange default language to 'de_DE'" +_key="language_dropdown_selected" +_val="'de_DE'" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - managesieve +# - +_plugin="managesieve" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tCopy default config file to 'config.inc.php'.." +cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key=managesieve_port +_val="4190" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key=managesieve_default +_val="'/usr/local/dovecot/etc/dovecot/sieve/move-spam.sieve'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="managesieve_disabled_extensions" +_val="array('vacation')" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - markasjunk2 +# - +_plugin="markasjunk2" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tDownload Pluging '$_plugin'.." +wget -O ${WEBSITE_BASEDIR}/Roundcube-Plugin-Mark-as-Junk-2-master.zip \ + https://github.com/JohnDoh/Roundcube-Plugin-Mark-as-Junk-2/archive/master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tUnpack archiv into Plugin Folder" +unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ + ${WEBSITE_BASEDIR}/Roundcube-Plugin-Mark-as-Junk-2-master > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi +echononl "\tCeate Symlink '$_pligin' in plugin folder.." +ln -s Roundcube-Plugin-Mark-as-Junk-2-master \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - password +# - +_plugin="password" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tCopy default config file to 'config.inc.php'.." +cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_driver" +_val="'sql'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_confirm_current" +_val="$PW_CONFIRM_CURRENT" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_minimum_length" +_val="$PW_MIN_LENGTH" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_require_nonalpha" +_val="$PW_REQUIRE_NONALPHA" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_algorithm" +_val="'$PW_PASSWD_ALGO'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_algorithm_prefix" +_val="'$PW_PASSWD_ALGO_PREFIX'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_dovecotpw" +_val="'$PW_DOVEADM_PW'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_dovecotpw_method" +_val="'$PW_DOVECOT_PW_METHOD'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_db_dsn" +_val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="password_query" +_val="'$PW_DB_UPDATE_STRING'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - vacation +# - +_plugin="vacation" +add_plugin_arr+=("$_plugin") + +_config_file="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php" +_backup_file="${_config_file}.$(date +%Y-%m-%d-%H%M)" + +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echononl "\tDownload Pluging '$_plugin'.." +wget -O ${WEBSITE_BASEDIR}/rc-vacation-master.zip \ + https://github.com/bhuisgen/rc-vacation/archive/master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tUnpack archiv into Plugin Folder" +unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \ + ${WEBSITE_BASEDIR}/rc-vacation-master.zip > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tCeate Symlink '$_pligin' in plugin folder.." +ln -s rc-vacation-master \ + ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tCopy default config file to 'config.inc.php'.." +cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_gui_vacationdate" +_val="TRUE" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_subject_default" +_val="'Re: \\\$SUBJECT'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_gui_vacationforwarder" +_val="$VAC_GUI_FORWARDER" +echononl "\tchange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_dateformat" +_val="'Y-m-d'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_jquery_calendar" +_val="TRUE" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_jquery_dateformat" +_val="'yy-m-d'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_forwarder_multiple" +_val="'FALSE'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_forwarder_separator" +_val="','" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +_key="vacation_driver" +_val="'sql'" +echononl "\tChange '$_key' to $_val" +perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \ + $_config_file > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + + +_key="vacation_sql_dsn" +_val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'" +echononl "\tChange '$_key' to $_val" + +failed=false +mv $_config_file $_backup_file > $log_file 2>&1 +if [[ $? -ne 0 ]]; then + _failed=true +fi +_found=false +_found_comment=false +while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*'[^']*'\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = $_val;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true + echo "/*" >> $_config_file + echo "$_line" >> $_config_file + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi + + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+'.+';$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['$_key'] = $_val;" >> $_config_file + _found=false + continue + fi + + echo "$_line" >> $_config_file + +done < "$_backup_file" +if [[ $? -ne 0 ]]; then + _failed=true +fi +if $_failed ; then + echo_failed +else + echo_ok +fi + + +failed=false +mv $_config_file $_backup_file > $log_file 2>&1 +if [[ $? -ne 0 ]]; then + _failed=true +fi +_key="vacation_sql_read" +echononl "\tChange '$_key'.." +_found=false +_found_comment=false +while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = array($;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true + echo "/*" >> $_config_file + echo "$_line" >> $_config_file + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi + + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['${_key}'] = array(" >> $_config_file + + if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then + cat <> $_config_file 2>> $log_file + "SELECT + subject AS vacation_subject, + body AS vacation_message, + date(activefrom) AS vacation_start, + date(activeuntil) AS vacation_end, + CASE WHEN vacation.active = TRUE THEN true ELSE false END AS vacation_enable, + udf_forwarders_out(%username,'${AUTOREPLY_HOSTNAME}',',') AS vacation_forwarder + FROM vacation,alias + WHERE email=%username AND address=%username AND vacation.domain=%email_domain;" +EOF + else + cat <> $_config_file 2>> $log_file + "SELECT subject AS vacation_subject, body AS vacation_message," . + "UNIX_TIMESTAMP(activefrom) AS vacation_start," . + "UNIX_TIMESTAMP(activeuntil) AS vacation_end," . + "vacation.active AS vacation_enable," . + "FORWARDERS_OUT(%username,'${AUTOREPLY_HOSTNAME}',',') AS vacation_forwarder " . + "FROM vacation,alias " . + "WHERE email=%username AND address=%username AND vacation.domain=%email_domain;" +EOF + fi + echo ");" >> $_config_file + _found=false + continue + fi + + echo "$_line" >> $_config_file +done < "$_backup_file" +if [[ $? -ne 0 ]]; then + _failed=true +fi +if $_failed ; then + echo_failed +else + echo_ok +fi + +failed=false +mv $_config_file $_backup_file > $log_file 2>&1 +if [[ $? -ne 0 ]]; then + _failed=true +fi +_key="vacation_sql_write" +echononl "\tChange '$_key'.." +_found=false +_found_comment=false +while IFS='' read -r _line || [[ -n $_line ]] ; do + if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then + echo '//!'"$_line" >> $_config_file + echo "\$config['$_key'] = array($;" >> $_config_file + continue + elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then + _found=true + echo "/*" >> $_config_file + echo "$_line" >> $_config_file + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then + _found_comment=true + fi + + if $_found_comment ; then + echo "$_line" >> $_config_file + if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then + echo "/*" >> $_config_file + _found_comment=false + fi + continue + fi + + if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then + echo "$_line" >> $_config_file + echo "*/" >> $_config_file + echo "\$config['${_key}'] = array(" >> $_config_file + + if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then + if $VAC_GUI_FORWARDER ; then + + # - Database: PostgreSQL + # - Allow vacation forwarder: false + # - + cat <> $_config_file 2>> $log_file + + // Clean up vacation + "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", + + // Cleanup notifications + "DELETE from vacation_notification WHERE on_vacation=%email;", + + // Save entries to table vacation + "INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " . + "VALUES (%email,%email_domain,%vacation_subject,%vacation_message," . + "to_timestamp(%vacation_start - extract(timezone from current_timestamp))," . + "to_timestamp(%vacation_end + 86399 - extract(timezone from current_timestamp))," . + "86400,NOW(),udf_set_active(%vacation_enable));", + + // Update table alias + "UPDATE alias SET goto = udf_forwarders_in(udf_forwarders_out(%email,'${AUTOREPLY_HOSTNAME}',',')," . + "%email,'${AUTOREPLY_HOSTNAME}',',',udf_set_active(%vacation_enable))" . + ", modified = NOW() " . + " WHERE address = %email" +EOF + else + + # - Database: PostgreSQL + # - Allow vacation forwarder: true + # - + cat <> $_config_file 2>> $log_file + + // Clean up vacation + "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", + + // Cleanup notifications + "DELETE from vacation_notification WHERE on_vacation=%email;", + + // Save entries to table vacation + "INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " . + "VALUES (%email,%email_domain,%vacation_subject,%vacation_message," . + "to_timestamp(%vacation_start - extract(timezone from current_timestamp))," . + "to_timestamp(%vacation_end + 86399 - extract(timezone from current_timestamp))," . + "86400,NOW(),udf_set_active(%vacation_enable));", + + // Update table alias + "UPDATE alias SET goto = udf_forwarders_in(%vacation_forwarder," . + "%email,'${AUTOREPLY_HOSTNAME}',',',udf_set_active(%vacation_enable))" . + ", modified = NOW() " . + " WHERE address = %email" +EOF + fi + else + if $VAC_GUI_FORWARDER ; then + + # - Database: MySQL + # - Allow vacation forwarder: FALSE + # - + cat <> $_config_file 2>> $log_file + + // Clean up vacation + "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", + + // Cleanup notifications + "DELETE from vacation_notification WHERE on_vacation=%email;", + + // Save entries to table vacation + "INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " . + "VALUES (%email,%email_domain,%vacation_subject,%vacation_message," . + "CONCAT(DATE(FROM_UNIXTIME(%vacation_start)), ' 00:00:00')," . + "CONCAT(DATE(FROM_UNIXTIME(%vacation_end)), ' 23:59:59')," . + "86400,NOW(),%vacation_enable);", + + // Update table alias + "UPDATE alias SET goto = FORWARDERS_IN(FORWARDERS_OUT(%email,'${AUTOREPLY_HOSTNAME}',',')," . + "%email,'${AUTOREPLY_HOSTNAME}',',',%vacation_enable)" . + ", modified = NOW() " . + " WHERE address = %email" +EOF + else + + # - Database: MySQL + # - Allow vacation forwarder: TRUE + # - + cat <> $_config_file 2>> $log_file + + // Clean up vacation + "DELETE FROM vacation WHERE email=%email AND domain=%email_domain;", + + // Cleanup notifications + "DELETE from vacation_notification WHERE on_vacation=%email;", + + // Save entries to table vacation + "INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " . + "VALUES (%email,%email_domain,%vacation_subject,%vacation_message," . + "CONCAT(DATE(FROM_UNIXTIME(%vacation_start)), ' 00:00:00')," . + "CONCAT(DATE(FROM_UNIXTIME(%vacation_end)), ' 23:59:59')," . + "86400,NOW(),%vacation_enable);", + + // Update table alias + "UPDATE alias SET goto = FORWARDERS_IN(%vacation_forwarder," . + "%email,'${AUTOREPLY_HOSTNAME}',',',%vacation_enable)" . + ", modified = NOW() " . + " WHERE address = %email" +EOF + fi + fi + echo ");" >> $_config_file + _found=false + continue + fi + + echo "$_line" >> $_config_file +done < "$_backup_file" +if [[ $? -ne 0 ]]; then + _failed=true +fi +if $_failed ; then + echo_failed +else + echo_ok +fi + +if [[ "$POSTFIX_DB_TYPE" = 'pgsql' ]] ; then + echononl "\tCreate postfix language plpgsql" + _pgpsql_exists=$(su - postgres -c "psql -t -c \"SELECT EXISTS ( SELECT 1 FROM pg_language WHERE lanname = 'plpgsql');\"") + if [[ "$_pgpsql_exists" =~ t ]]; then + echo_skipped + else + su - postgres -c "psql -t -c \"CREATE LANGUAGE plpgsql;\"" > $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + erro $(cat $log_file) + else + echo_ok + fi + fi + + + # - Create postfix trigger function udf_forwarders_out + # - + _trigger_function="udf_forwarders_out" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped + else + + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file +CREATE FUNCTION udf_forwarders_out(email_str text, vacation_domain text, list_seperator character) RETURNS text + LANGUAGE plpgsql + AS \$\$ + DECLARE + forward_str text; + local_email_part TEXT; + domain_email_part TEXT; + BEGIN + + -- get list of forwarders + -- + SELECT goto INTO forward_str FROM alias WHERE address=email_str; + + -- entferne mailbox emailadresse + -- + forward_str = replace(forward_str, email_str, '' ); + + -- entferne vacation adresse + -- + local_email_part = substring(email_str, 1, position('@' in email_str) - 1); + domain_email_part = substring(email_str, position('@' in email_str) + 1 ); + forward_str = replace(forward_str, local_email_part || '#' || domain_email_part || '@' || vacation_domain, ''); + + -- enferne doppelte seperatorzeichen + -- + WHILE position( list_seperator || list_seperator in forward_str ) > 0 LOOP + forward_str = replace(forward_str, list_seperator || list_seperator , ''); + END LOOP; + + -- entferne erstes zeichen wenn es das seperatorzeichen ist + -- + IF substring(forward_str,1,1) = list_seperator THEN + forward_str = substring(forward_str from 2); + END IF; + + + -- entferne letztes zeichen wenn es das seperatorzeichen ist + -- + IF substring(forward_str from char_length(forward_str)) = list_seperator THEN + forward_str = substring(forward_str, 1, char_length(forward_str) - 1); + END IF; + + + -- forward_str = substring(forward_str from char_length(forward_str)); + + RETURN forward_str; + END; + \$\$; +EOF + if [[ $? -ne 0 ]]; then + _failed=true + fi + + _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + echo "" >> $log_file + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + if $_failed ; then + echo_failed + erro $(cat $log_file) + else + echo_ok + fi + fi + + + # - Create postfix trigger function udf_set_active + # - + _trigger_function="udf_set_active" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped + else + + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file +CREATE FUNCTION udf_set_active(vacation_enable text) RETURNS boolean + LANGUAGE plpgsql + AS \$\$ + DECLARE + return_val boolean; + BEGIN + + return_val = 't'; + + IF vacation_enable = '' THEN + return_val = 'f'; + END IF; + + IF vacation_enable = '0' THEN + return_val = 'f'; + END IF; + + IF lower(vacation_enable) = 'false' THEN + return_val = 'f'; + END IF; + + RETURN return_val; + END; + \$\$; +EOF + if [[ $? -ne 0 ]]; then + _failed=true + fi + + _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + echo "" >> $log_file + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + if $_failed ; then + echo_failed + erro $(cat $log_file) + else + echo_ok + fi + fi + + + # - Create postfix trigger function udf_forwarders_in + # - + _trigger_function="udf_forwarders_in" + echononl "\tCreate postfix trigger function $_trigger_function" + if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then + echo_skipped + else + + _psql_trigger_file="$(mktemp)" + echo "" > $log_file + echo "cat < \$_psql_trigger_file" >> $log_file + echo ".." >> $log_file + echo "EOF" >> $log_file + cat < $_psql_trigger_file 2>> $log_file +CREATE FUNCTION udf_forwarders_in(forewarders_str text, email_str text, vacation_domain text, list_seperator character, vacation_enable boolean) RETURNS text + LANGUAGE plpgsql + AS \$\$ + DECLARE + return_str text; + local_email_part TEXT; + domain_email_part TEXT; + BEGIN + + return_str = email_str; + + IF vacation_enable THEN + local_email_part = substring(email_str, 1, position('@' in email_str) - 1); + domain_email_part = substring(email_str, position('@' in email_str) + 1 ); + return_str = return_str || list_seperator || local_email_part || '#' || domain_email_part || '@' || vacation_domain; + END IF; + + IF char_length(forewarders_str) > 7 THEN + return_str = return_str || list_seperator || forewarders_str; + END IF; + + RETURN return_str; + END; + \$\$; +EOF + if [[ $? -ne 0 ]]; then + _failed=true + fi + + _pgppass_back_file="~/.pgpass.$(date +%Y-%m-%d-%H%M)" + _pgpass_was_present=false + if [[ -f "~/.pgpass" ]]; then + _pgpass_was_present=true + echo "" >> $log_file + echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file + mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + echo "" >> $log_file + echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file + echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file + psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + echo "" >> $log_file + echo "rm $_psql_trigger_file" >> $log_file + rm $_psql_trigger_file >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + + if $_pgpass_was_present ; then + echo "" >> $log_file + echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file + mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1 + if [[ $? -ne 0 ]]; then + _failed=true + fi + fi + + if $_failed ; then + echo_failed + erro $(cat $log_file) + else + echo_ok + fi + fi +else + + echononl "\tCreate function 'FORWARDERS_OUT'" + echo_skipped + echononl "\tCreate function 'FORWARDERS_IN'" + echo_skipped + + warn "Create fubctions 'FORWARDERS_OUT' and 'FORWARDERS_IN' not yet implemented" + +fi + +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +# - zipdownload +# - +_plugin="zipdownload" +add_plugin_arr+=("$_plugin") +echo -e "\n\t\033[32mPlugin '$_plugin'\033[m" +echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.." + + +echo -e "\n\n\t\033[37m\033[1mActivate Plugins..\033[m" + +echo "" +echononl "\tSet a comment bevor existing parameter '$config['plugins']'.." +perl -i -n -p -e "s#(^\s*\\\$config\['plugins'\].*)#//\n// !! Note: This parameter will be overwritten at the end of this file !!\n//\n\1#" $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echononl "\tSet parameter 'config['plugins']' to make plugin's available.." +if [[ ${#add_plugin_arr[@]} -gt 0 ]] ; then + cat <>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file + + +// ---------------------------------- +// PLUGINS +// ---------------------------------- + +// List of active plugins (in plugins/ directory) +\$config['plugins'] = array( +EOF + for _plugin in ${add_plugin_arr[@]} ; do + echo " '$_plugin'," >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php + done + echo ");" >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php + echo "" >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php + + echo_ok +else + echo_skipped +fi + +echo "" +echononl "\tRemove installer Folder.." +rm -r $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/installer > $log_file 2>&1 +if [[ $? -eq 0 ]] ; then + echo_ok +else + echo_failed + error "$(cat $log_file)" +fi + +echo "" +rm -rf $log_file +exit +