Commits

Zhang Huangbin committed 9c33fcf

Sync to latest iRedMail repo.

Comments (0)

Files changed (6)

extra/migration/dump_openldap_to_xml.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+# Author:   Zhang Huangbin <zhb@iredmail.org>
+# Purpose:  Dump mail accounts from OpenLDAP in XML format.
+# Date:     2011-08-11
+
+import sys
+import ldap
+from ldap.controls import SimplePagedResultsControl
+
+# Note: bind_dn must have write privilege on LDAP server.
+uri = 'ldap://127.0.0.1:389'
+basedn = 'o=domains,dc=example,dc=com'
+bind_dn = 'cn=Manager,dc=example,dc=com'
+bind_pw = 'www'
+xml_file = 'accounts.xml'
+
+# ==== Do NOT modify below settings. ====
+filter = '(|(objectClass=mailDomain)(objectClass=mailAdmin)(objectClass=mailUser)(objectClass=mailAlias)(objectClass=mailList)(objectClass=mailExternalUser))'
+page_size = 100
+
+# Dump object of mail domain in XML format.
+def dump_ldap_entry_in_xml(entry):
+    objectClasses = entry.get('objectClass')
+    if 'mailDomain' in objectClasses:
+        f = open('domains.temp.xml', 'a')
+        f.write('\t\t<domain>\n')
+
+        # Attributes with single value.
+        for attr in ['domainName', 'accountStatus', 'cn', 'mtaTransport', \
+                  'domainBackupMX', \
+                  'domainMaxQuotaSize', 'domainMaxUserNumber', \
+                  'domainMaxAliasNumber', 'domainMaxListNumber', \
+                  'domainDefaultUserQuota', 'disclaimer', 'description', \
+                  'street', 'expiredDate', \
+                 ]:
+            if attr in entry:
+                f.write('\t\t\t<%s>%s</%s>\n' % (attr, entry.get(attr)[0], attr))
+
+        # Attributes with multi value.
+        for attr in ['domainAliasName', 'enabledService', 'accountSetting', \
+                     'domainSenderBccAddress', 'domainRecipientBccAddress', \
+                     'telephoneNumber', 'facsimileTelephoneNumber', \
+                     'domainWhitelistIP', 'domainWhitelistSender', \
+                     'domainBlacklistIP', 'domainBlacklistSender', \
+                    ]:
+            if attr in entry:
+                f.write('\t\t\t<%s>\n' % attr)
+                for i in entry.get(attr):
+                    f.write('\t\t\t\t<value>%s</value>\n' % i)
+                f.write('\t\t\t</%s>\n' % attr)
+        
+        f.write('\t\t</domain>\n')
+        f.close()
+
+        '''
+        f.write('\t<name>%s</name>\n' % entry.get('domainName')[0])
+
+        if 'accountStatus' in entry:
+            f.write('\t<status>%s</status>\n' % entry.get('accountStatus')[0])
+
+        if 'domainAliasName' in entry:
+            f.write('\t<aliases>\n')
+            for a in entry.get('domainAliasName'):
+                f.write('\t\t<name>%s</name>\n' % a)
+            f.write('\t</aliases>\n')
+
+        if 'domainAdmin' in entry:
+            f.write('\t<admins>\n')
+            for a in entry.get('domainAdmin'):
+                f.write('\t\t<mail>%s</mail>\n' % a)
+            f.write('\t</admins>\n')
+
+        if 'cn' in entry:
+            f.write('\t<company>%s</company>\n' % entry.get('cn')[0])
+
+        if 'mtaTransport' in entry:
+            f.write('\t<transport>%s</transport>\n' % entry.get('mtaTransport')[0])
+
+        '''
+
+    elif 'mailAdmin' in objectClasses:
+        pass
+    elif 'mailUser' in objectClasses:
+        f = open('users.temp.xml', 'a')
+        f.write('\t\t<user>\n')
+
+        # Attributes with single value.
+        for attr in ['mail', 'uid', 'accountStatus', 'cn', 'mtaTransport', \
+                     'storageBaseDirectory', 'mailMessageStore', 'homeDirectory', \
+                     'mailQuota', 'mailQuotaMessageLimit', 'userPassword', \
+                     'expiredDate', 'preferredLanguage', 'disclaimer', \
+                    ]:
+            if attr in entry:
+                f.write('\t\t\t<%s>%s</%s>\n' % (attr, entry.get(attr)[0], attr))
+
+        # Attributes with multi value.
+        for attr in ['enabledService', 'accountSetting', 'telephoneNumber', \
+                     'mailForwardingAddress', 'shadowAddress', 'memberOfGroup', \
+                     'telephoneNumber', 'title', \
+                     'userRecipientBccAddress', 'userSenderBccAddress', \
+                     'mailWhitelistRecipient', 'mailBlacklistRecipient', \
+                    ]:
+            if attr in entry:
+                f.write('\t\t\t<%s>\n' % attr)
+                for i in entry.get(attr):
+                    f.write('\t\t\t\t<value>%s</value>\n' % i)
+                f.write('\t\t\t</%s>\n' % attr)
+
+        f.write('\t\t</user>\n')
+        f.close()
+        
+    elif 'mailList' in objectClasses:
+        pass
+    elif 'mailAlias' in objectClasses:
+        pass
+    elif 'mailExternalUser' in objectClasses:
+        pass
+    else:
+        pass
+
+# Initialize LDAP connection.
+print >> sys.stderr, "* Connecting to LDAP server: %s" % uri
+conn = ldap.initialize(uri=uri, trace_level=0,)
+conn.protocol_version = 3
+conn.bind_s(bind_dn, bind_pw)
+
+# Start paged control, 100 objects per page.
+paged_controller = SimplePagedResultsControl(ldap.LDAP_CONTROL_PAGE_OID, True, (page_size, ''))
+
+# Send search request
+msgid = conn.search_ext(basedn, ldap.SCOPE_SUBTREE, filter, serverctrls=[paged_controller],)
+
+pages = 0
+
+# Create or empty existing xml file.
+open(xml_file, 'w').close()
+open('domains.temp.xml', 'w').close()
+open('admins.temp.xml', 'w').close()
+open('users.temp.xml', 'w').close()
+open('maillists.temp.xml', 'w').close()
+open('aliases.temp.xml', 'w').close()
+
+while True:
+    pages += 1
+    print "Getting page %d" % (pages,)
+    rtype, rdata, rmsgid, serverctrls = conn.result3(msgid)
+    print '%d results' % len(rdata)
+    for dn, entry in rdata:
+        dump_ldap_entry_in_xml(entry)
+
+    pctrls = [c for c in serverctrls if c.controlType == ldap.LDAP_CONTROL_PAGE_OID]
+    if pctrls:
+        est, cookie = pctrls[0].controlValue
+        if cookie:
+            paged_controller.controlValue = (page_size, cookie)
+            msgid = conn.search_ext(basedn, ldap.SCOPE_SUBTREE, filter, serverctrls=[paged_controller],)
+        else:
+            break
+    else:
+        print "Warning:  Server ignores RFC 2696 control."
+        break

iRedMail/dialog/optional_components.sh

 " 20 76 8 \
     "SPF Validation" "Sender Policy Framework" "on" \
     "DKIM signing/verification" "DomainKeys Identified Mail" "on" \
-    "iRedAdmin" "Official web-based iRedMail Admin Panel" "on" \
+    "iRedAdmin" "Official web-based Admin Panel" "on" \
     "Roundcubemail" "WebMail program (PHP, AJAX)" "on" \
     "phpLDAPadmin" "Web-based OpenLDAP management tool" "on" \
     "phpMyAdmin" "Web-based MySQL management tool" "on" \
     "DKIM signing/verification" "DomainKeys Identified Mail" "on" \
     "Roundcubemail" "WebMail program (PHP, AJAX)" "on" \
     "phpMyAdmin" "Web-based MySQL management tool" "on" \
-    "iRedAdmin" "Official web-based iRedMail Admin Panel" "on" \
+    "iRedAdmin" "Official web-based Admin Panel" "on" \
     "Awstats" "Advanced web and mail log analyzer" "on" \
     "Fail2ban" "Ban IP with too many password failures" "on" \
     2>${tmp_config_optional_components}

iRedMail/functions/awstats.sh

 
     # Move awstats.pl to ${AWSTATS_CGI_DIR} on Debian/Ubuntu, so that it won't
     # conflict with other cgi programs, e.g. mailman.
-    if [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" -o X"${DISTRO}" == X"SUSE" ]; then
-        mkdir -p ${AWSTATS_CGI_DIR}/awstats/ 2>/dev/null
-        mv ${AWSTATS_CGI_DIR}/awstats.pl ${AWSTATS_CGI_DIR}/awstats/ 2>/dev/null
-        export AWSTATS_CGI_DIR="${AWSTATS_CGI_DIR}/awstats"
-    fi
+    #if [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" -o X"${DISTRO}" == X"SUSE" ]; then
+    #    mkdir -p ${AWSTATS_CGI_DIR}/awstats/ 2>/dev/null
+    #    mv ${AWSTATS_CGI_DIR}/awstats.pl ${AWSTATS_CGI_DIR}/awstats/ 2>/dev/null
+    #    export AWSTATS_CGI_DIR="${AWSTATS_CGI_DIR}/awstats"
+    #fi
 
     cat > ${AWSTATS_HTTPD_CONF} <<EOF
 ${CONF_MSG}

iRedMail/functions/managesieve.sh

     if [ X"${USE_MANAGESIEVE}" == X"YES" ]; then
         if [ X"${DOVECOT_VERSION}" == X"1.1" ]; then
             # Dovecot is patched on Debian/Ubuntu, ships managesieve protocal.
-            perl -pi -e 's#^(protocols =.*)#${1} managesieve#' ${DOVECOT_CONF}
             cat >> ${DOVECOT_CONF} <<EOF
 protocol managesieve {
     # IP or host address where to listen in for connections.
 }
 EOF
         elif [ X"${DOVECOT_VERSION}" == X"1.2" ]; then
-            perl -pi -e 's#^(protocols =.*)#${1} managesieve#' ${DOVECOT_CONF}
             cat >> ${DOVECOT_CONF} <<EOF
 # ManageSieve service. http://wiki.dovecot.org/ManageSieve
 protocol managesieve {

iRedMail/functions/packages.sh

         DISABLED_SERVICES="${DISABLED_SERVICES} clamav-milter spamd spampd"
 
     elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
-        ALL_PKGS="${ALL_PKGS} amavisd-new libcrypt-openssl-rsa-perl libmail-dkim-perl clamav-freshclam clamav-daemon spamassassin altermime"
+        ALL_PKGS="${ALL_PKGS} amavisd-new libcrypt-openssl-rsa-perl libmail-dkim-perl clamav-freshclam clamav-daemon spamassassin altermime arj zoo nomarch cpio lzop cabextract p7zip rpm unrar-free ripole"
         ENABLED_SERVICES="${ENABLED_SERVICES} ${AMAVISD_RC_SCRIPT_NAME} clamav-daemon clamav-freshclam"
         DISABLED_SERVICES="${DISABLED_SERVICES} spamassassin"
     else

iRedMail/samples/iredmail.sql

     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (username),
     INDEX (passwordlastchange),
     INDEX (expired),
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (address),
     INDEX (domain),
     INDEX (expired),
     -- Disclaimer text. Used by Amavisd + AlterMIME.
     disclaimer TEXT NOT NULL DEFAULT '',
     -- Max alias accounts in this domain. e.g. 10.
-    aliases INT(10) NOT NULL DEFAULT '0',
+    aliases INT(10) NOT NULL DEFAULT 0,
     -- Max mail accounts in this domain. e.g. 100.
-    mailboxes INT(10) NOT NULL DEFAULT '0',
+    mailboxes INT(10) NOT NULL DEFAULT 0,
     -- Max mailbox quota in this domain. e.g. 1073741824 (1GB).
-    maxquota BIGINT(20) NOT NULL DEFAULT '0',
-    quota BIGINT(20) NOT NULL DEFAULT '0',
+    maxquota BIGINT(20) NOT NULL DEFAULT 0,
+    quota BIGINT(20) NOT NULL DEFAULT 0,
     -- Per-domain transport. e.g. dovecot, smtp:[192.168.1.1]:25
     transport VARCHAR(255) NOT NULL DEFAULT 'dovecot',
-    backupmx TINYINT(1) NOT NULL DEFAULT '0',
+    backupmx TINYINT(1) NOT NULL DEFAULT 0,
     -- Default quota size for newly created mail account.
     defaultuserquota BIGINT(20) NOT NULL DEFAULT '1024',
     -- List of mail alias addresses, Newly created user will be
     -- Default password scheme. e.g. md5, plain.
     defaultpasswordscheme VARCHAR(10) NOT NULL DEFAULT '',
     -- Minimal password length, per-domain setting.
-    minpasswordlength INT(10) NOT NULL DEFAULT '0',
+    minpasswordlength INT(10) NOT NULL DEFAULT 0,
     -- Max password length, per-domain setting.
-    maxpasswordlength INT(10) NOT NULL DEFAULT '0',
+    maxpasswordlength INT(10) NOT NULL DEFAULT 0,
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (domain),
     INDEX (backupmx),
     INDEX (expired),
 CREATE TABLE IF NOT EXISTS `alias_domain` (
     alias_domain VARCHAR(255) NOT NULL,
     target_domain VARCHAR(255) NOT NULL,
-    created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
-    modified datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
-    active tinyint(1) NOT NULL DEFAULT '1',
+    created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
+    modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (alias_domain),
     INDEX (target_domain),
     INDEX (active)
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (username,domain),
     INDEX (username),
     INDEX (domain),
     department VARCHAR(255) NOT NULL DEFAULT '',
     rank VARCHAR(255) NOT NULL DEFAULT 'normal',
     employeeid VARCHAR(255) DEFAULT '',
-    enablesmtp TINYINT(1) NOT NULL DEFAULT '1',
-    enablesmtpsecured TINYINT(1) NOT NULL DEFAULT '1',
-    enablepop3 TINYINT(1) NOT NULL DEFAULT '1',
-    enablepop3secured TINYINT(1) NOT NULL DEFAULT '1',
-    enableimap TINYINT(1) NOT NULL DEFAULT '1',
-    enableimapsecured TINYINT(1) NOT NULL DEFAULT '1',
-    enabledeliver TINYINT(1) NOT NULL DEFAULT '1',
-    enablelda TINYINT(1) NOT NULL DEFAULT '1',
-    enablemanagesieve TINYINT(1) NOT NULL DEFAULT '1',
-    enablemanagesievesecured TINYINT(1) NOT NULL DEFAULT '1',
-    enablesieve TINYINT(1) NOT NULL DEFAULT '1',
-    enablesievesecured TINYINT(1) NOT NULL DEFAULT '1',
-    enableinternal TINYINT(1) NOT NULL DEFAULT '1',
+    enablesmtp TINYINT(1) NOT NULL DEFAULT 1,
+    enablesmtpsecured TINYINT(1) NOT NULL DEFAULT 1,
+    enablepop3 TINYINT(1) NOT NULL DEFAULT 1,
+    enablepop3secured TINYINT(1) NOT NULL DEFAULT 1,
+    enableimap TINYINT(1) NOT NULL DEFAULT 1,
+    enableimapsecured TINYINT(1) NOT NULL DEFAULT 1,
+    enabledeliver TINYINT(1) NOT NULL DEFAULT 1,
+    enablelda TINYINT(1) NOT NULL DEFAULT 1,
+    enablemanagesieve TINYINT(1) NOT NULL DEFAULT 1,
+    enablemanagesievesecured TINYINT(1) NOT NULL DEFAULT 1,
+    enablesieve TINYINT(1) NOT NULL DEFAULT 1,
+    enablesievesecured TINYINT(1) NOT NULL DEFAULT 1,
+    enableinternal TINYINT(1) NOT NULL DEFAULT 1,
     lastlogindate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
-    lastloginipv4 INT(4) UNSIGNED NOT NULL DEFAULT '0',
+    lastloginipv4 INT(4) UNSIGNED NOT NULL DEFAULT 0,
     lastloginprotocol CHAR(255) NOT NULL DEFAULT '',
     disclaimer TEXT NOT NULL DEFAULT '',
     passwordlastchange DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     local_part VARCHAR(255) NOT NULL DEFAULT '', -- Required by PostfixAdmin
     PRIMARY KEY (username),
     INDEX (domain),
     INDEX (enableimap),
     INDEX (enableimapsecured),
     INDEX (enabledeliver),
+    INDEX (enablelda),
     INDEX (enablemanagesieve),
     INDEX (enablemanagesievesecured),
     INDEX (enablesieve),
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (domain),
     INDEX (bcc_address),
     INDEX (expired),
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (username),
     INDEX (bcc_address),
     INDEX (domain),
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (domain),
     INDEX (bcc_address),
     INDEX (expired),
     created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
     expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
-    active TINYINT(1) NOT NULL DEFAULT '1',
+    active TINYINT(1) NOT NULL DEFAULT 1,
     PRIMARY KEY (username),
     INDEX (bcc_address),
     INDEX (expired),