Commits

Zhang Huangbin committed 0c48fa0

Code cleanup.

  • Participants
  • Parent commits 4b87d19

Comments (0)

Files changed (10)

File iRedMail/conf/core

 EOF
 }
 
+# Add alias entry in Postfix /etc/postfix/aliases.
+add_postfix_alias()
+{
+    # Usage: add_postfix_alias nobody root
+    # File /path/to/aliases will be created if not exist.
+    export alias_orig="${1}"
+    export alias_dest="${2}"
+
+    if [ ! -f ${POSTFIX_FILE_ALIASES} ]; then
+        if [ -f /etc/aliases ]; then
+            cp -f /etc/aliases ${POSTFIX_FILE_ALIASES}
+        else
+            # Create an empty file
+            touch ${POSTFIX_FILE_ALIASES}
+        fi
+    fi
+
+    # If alias_orig exists, comment it out
+    if grep "^${alias_orig}:" ${POSTFIX_FILE_ALIASES} >/dev/null 2>&1; then
+        perl -pi -e 's/^($ENV{alias_orig}:.*)/#${1}/' ${POSTFIX_FILE_ALIASES}
+    fi
+
+    # Add new alias
+    echo "${alias_orig}: ${alias_dest}" >> ${POSTFIX_FILE_ALIASES}
+
+    postalias hash:${POSTFIX_FILE_ALIASES} >/dev/null 2>&1
+    unset alias_orig
+    unset alias_dest
+}
+
 # Install/Remove binary packages on RHEL/CentOS.
 install_pkg_rhel()
 {

File iRedMail/functions/amavisd.sh

 EOF
 
     # Add postfix alias for user: amavis.
-    echo "${AMAVISD_SYS_USER}: ${SYS_ROOT_USER}" >> ${POSTFIX_FILE_ALIASES}
-    postalias hash:${POSTFIX_FILE_ALIASES} &>/dev/null
+    add_postfix_alias ${AMAVISD_SYS_USER} ${SYS_ROOT_USER}
 
     # Make sure that clamav is configured to init supplementary
     # groups when it drops priviledges, and that you add the

File iRedMail/functions/apache_php.sh

 EOF
 
     if [ X"${DISTRO}" != X'OPENBSD' ]; then
-        echo "${HTTPD_USER}: ${SYS_ROOT_USER}" >> ${POSTFIX_FILE_ALIASES}
-        postalias hash:${POSTFIX_FILE_ALIASES} &>/dev/null
+        add_postfix_alias ${HTTPD_USER} ${SYS_ROOT_USER}
     fi
 
     if [ X"${DISTRO}" == X'OPENBSD' ]; then

File iRedMail/functions/awstats.sh

     AuthMySQLUser ${VMAIL_DB_BIND_USER}
     AuthMySQLPassword ${VMAIL_DB_BIND_PASSWD}
     AuthMySQLDB ${VMAIL_DB}
-    AuthMySQLUserTable admin
+    AuthMySQLUserTable mailbox
     AuthMySQLNameField username
     AuthMySQLPasswordField password
     AuthMySQLUserCondition "isadmin=1 AND isglobaladmin=1"
     AuthUserFile /dev/null
 
     # Database related.
-    AuthMySQL_Password_Table admin
+    AuthMySQL_Password_Table mailbox
     Auth_MySQL_Username_Field username
     Auth_MySQL_Password_Field password
 
     AuthMySQL_Empty_Passwords off
     AuthMySQL_Encryption_Types Crypt_MD5
     Auth_MySQL_Authoritative On
+    #AuthMySQLUserCondition "isadmin=1 AND isglobaladmin=1"
 EOF
 
             # Set file permission.
     Auth_PG_database ${VMAIL_DB}
     Auth_PG_user ${VMAIL_DB_BIND_USER}
     Auth_PG_pwd ${VMAIL_DB_BIND_PASSWD}
-    Auth_PG_pwd_table admin
-    #Auth_PG_pwd_whereclause 'AND xxx'
+    Auth_PG_pwd_table mailbox
+    Auth_PG_pwd_whereclause 'AND isadmin=1 AND isglobaladmin=1'
     Auth_PG_uid_field username
     Auth_PG_pwd_field password
     Auth_PG_lowercase_uid on

File iRedMail/functions/clamav.sh

     freebsd_enable_service_in_rc_conf 'clamav_clamd_enable' 'YES'
     freebsd_enable_service_in_rc_conf 'clamav_freshclam_enable' 'YES'
 
+    # Add user alias in Postfix
+    add_postfix_alias ${CLAMAV_USER} ${SYS_ROOT_USER}
+
     cat >> ${TIP_FILE} <<EOF
 ClamAV:
     * Configuration files:

File iRedMail/functions/cleanup.sh

 
     cat <<EOF
 ********************************************************************
-* URLs of your web applications:
+* URLs of installed web applications:
 *
 EOF
 

File iRedMail/functions/cluebringer.sh

     #
     # DSN
     if [ X"${BACKEND}" == X"OPENLDAP" -o X"${BACKEND}" == X"MYSQL" ]; then
-        perl -pi -e 's/^#(DSN=DBI:mysql:).*/${1}host=$ENV{MYSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
+        perl -pi -e 's/^(#*)(DSN=DBI:mysql:).*/${2}host=$ENV{MYSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
         perl -pi -e 's/^(DB_Type=).*/${1}mysql/' ${CLUEBRINGER_CONF}
         perl -pi -e 's/^(DB_Host=).*/${1}$ENV{MYSQL_SERVER}/' ${CLUEBRINGER_CONF}
         perl -pi -e 's/^(DB_Port=).*/${1}$ENV{MYSQL_SERVER_PORT}/' ${CLUEBRINGER_CONF}
     elif [ X"${BACKEND}" == X"PGSQL" ]; then
-        perl -pi -e 's/^(DSN=DBI:Pg:).*/${1}host=$ENV{PGSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
-        # Commentted out
-        perl -pi -e 's/^#(DSN=DBI:Pg:).*/${1}host=$ENV{PGSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
+        perl -pi -e 's/^(#*)(DSN=DBI:Pg:).*/${2}host=$ENV{PGSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
+
         perl -pi -e 's/^(DB_Type=).*/${1}pgsql/' ${CLUEBRINGER_CONF}
         perl -pi -e 's/^(DB_Host=).*/${1}$ENV{PGSQL_SERVER}/' ${CLUEBRINGER_CONF}
         perl -pi -e 's/^(DB_Port=).*/${1}$ENV{PGSQL_SERVER_PORT}/' ${CLUEBRINGER_CONF}
-
-        # FreeBSD
-        if [ X"${DISTRO}" == X'RHEL' -o X"${DISTRO}" == X'FREEBSD' ]; then
-            perl -pi -e 's/^(DSN=DBI:).*/${1}Pg:host=$ENV{PGSQL_SERVER};database=$ENV{CLUEBRINGER_DB_NAME};user=$ENV{CLUEBRINGER_DB_USER};password=$ENV{CLUEBRINGER_DB_PASSWD}/' ${CLUEBRINGER_CONF}
-        fi
     fi
 
     # Database
     fi
 
     # Add postfix alias.
-    echo "${CLUEBRINGER_USER}: ${SYS_ROOT_USER}" >> ${POSTFIX_FILE_ALIASES}
-    postalias hash:${POSTFIX_FILE_ALIASES} 2>/dev/null
+    add_postfix_alias ${CLUEBRINGER_USER} ${SYS_ROOT_USER}
 
     # Tips.
     cat >> ${TIP_FILE} <<EOF
     DirectoryIndex index.php
     Options ExecCGI
     Order allow,deny
-    allow from ${CLUEBRINGER_BIND_HOST}
-    #allow from all
+    #allow from ${CLUEBRINGER_BIND_HOST}
+    allow from all
 
     AuthType basic
     AuthName "Authorization Required"
 
     elif [ X"${BACKEND}" == X"PGSQL" ]; then
         # Use mod_auth_pgsql.
-        if [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
-            cat >> ${CLUEBRINGER_HTTPD_CONF} <<EOF
+        cat >> ${CLUEBRINGER_HTTPD_CONF} <<EOF
     Auth_PG_authoritative on
     Auth_PG_host ${PGSQL_SERVER}
     Auth_PG_port ${PGSQL_SERVER_PORT}
     Auth_PG_database ${VMAIL_DB}
     Auth_PG_user ${VMAIL_DB_BIND_USER}
     Auth_PG_pwd ${VMAIL_DB_BIND_PASSWD}
-    Auth_PG_pwd_table admin
-    #Auth_PG_pwd_whereclause 'AND xxx'
+    Auth_PG_pwd_table mailbox
+    Auth_PG_pwd_whereclause 'AND isadmin=1 AND isglobaladmin=1'
     Auth_PG_uid_field username
     Auth_PG_pwd_field password
     Auth_PG_lowercase_uid on
     Auth_PG_encrypted on
     Auth_PG_hash_type CRYPT
 EOF
-        fi
 
         # Set file permission.
         chmod 0600 ${CLUEBRINGER_HTTPD_CONF}

File iRedMail/functions/policyd.sh

     chmod 0600 ${CRON_SPOOL_DIR}/${POLICYD_USER}
 
     # Add postfix alias.
-    echo "${POLICYD_USER}: ${SYS_ROOT_USER}" >> ${POSTFIX_FILE_ALIASES}
-    postalias hash:${POSTFIX_FILE_ALIASES} 2>/dev/null
+    add_postfix_alias ${POLICYD_USER} ${SYS_ROOT_USER}
 
     # Tips.
     cat >> ${TIP_FILE} <<EOF

File iRedMail/functions/postfix.sh

     # Allow recipient address start with '-'.
     postconf -e allow_min_user='no'
 
-    # Postfix aliases file.
-    if  [ ! -f ${POSTFIX_FILE_ALIASES} ]; then
-        if [ -f /etc/aliases ]; then
-            cp -f /etc/aliases ${POSTFIX_FILE_ALIASES}
-        else
-            touch ${POSTFIX_FILE_ALIASES}
-        fi
-    fi
-
-    # Comment out default aliases for root
-    perl -pi -e 's/^(root:.*)/#${1}/g' ${POSTFIX_FILE_ALIASES}
+    # Update Postfix aliases file.
+    add_postfix_alias nobody ${SYS_ROOT_USER}
+    add_postfix_alias ${VMAIL_USER_NAME} ${SYS_ROOT_USER}
+    add_postfix_alias ${SYS_ROOT_USER} ${FIRST_USER}@${FIRST_DOMAIN}
 
     postconf -e alias_maps="hash:${POSTFIX_FILE_ALIASES}"
     postconf -e alias_database="hash:${POSTFIX_FILE_ALIASES}"
-    postalias hash:${POSTFIX_FILE_ALIASES} 2>/dev/null
-    newaliases >/dev/null 2>&1
 
     # Set message_size_limit.
     postconf -e message_size_limit="${MESSAGE_SIZE_LIMIT}"

File iRedMail/pkgs/get_all.sh

 prepare_dirs
 
 if [ X"${DISTRO}" == X"RHEL" ]; then
+    # Clean metadata
+    ECHO_INFO "Clean metadata of yum repositories."
+    yum clean metadata
+
+    # Create yum repository.
+    create_repo_rhel
+
     # Check required commands, install related package if command doesn't exist.
     check_pkg ${BIN_WHICH} ${PKG_WHICH} && \
     check_pkg ${BIN_WGET} ${PKG_WGET} && \
-
-    # Create yum repository.
-    create_repo_rhel
 elif [ X"${DISTRO}" == X"SUSE" ]; then
-    create_repo_suse
-
     ECHO_INFO "Clean metadata of zypper repositories."
     zypper clean --metadata --raw-metadata
 
+    create_repo_suse
+
     ECHO_INFO "Refresh zypper repositories."
     zypper refresh
 elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then