diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 8eb2890a..3e1f57d7 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -209,6 +209,61 @@ class EEStackController(CementBaseController): self.app.render((data), 'dovecot.mustache', out=ee_dovecot) ee_dovecot.close() + # Custom Postfix configuration needed with Dovecot + # Changes in master.cf + # TODO: Find alternative for sed in Python + EEShellExec.cmd_exec("sed -i 's/#submission/submission/'" + "/etc/postfix/master.cf") + EEShellExec.cmd_exec("sed -i 's/#smtps/smtps/'" + " /etc/postfix/master.cf") + + EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_type = " + "dovecot\"") + EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_path = " + "private/auth\"") + EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_auth_enable = " + "yes\"") + EEShellExec.cmd_exec("postconf -e \"smtpd_relay_restrictions =" + " permit_sasl_authenticated, " + "permit_mynetworks, " + "reject_unauth_destination\"") + EEShellExec.cmd_exec("postconf -e \"smtpd_tls_mandatory_" + "protocols = !SSLv2,!SSLv3\"") + EEShellExec.cmd_exec("postconf -e \"smtp_tls_mandatory_" + "protocols = !SSLv2,!SSLv3\"") + EEShellExec.cmd_exec("postconf -e \"smtpd_tls_protocols " + "= !SSLv2,!SSLv3\"") + EEShellExec.cmd_exec("postconf -e \"smtp_tls_protocols " + "= !SSLv2,!SSLv3\"") + EEShellExec.cmd_exec("postconf -e \"mydestination " + "= localhost\"") + EEShellExec.cmd_exec("postconf -e \"virtual_transport " + "= lmtp:unix:private/dovecot-lmtp\"") + EEShellExec.cmd_exec("postconf -e \"virtual_uid_maps " + "= static:5000\"") + EEShellExec.cmd_exec("postconf -e \"virtual_gid_maps " + "= static:500\"") + EEShellExec.cmd_exec("postconf -e \"virtual_mailbox_domains = " + "mysql:/etc/postfix/mysql/virtual_" + "domains_maps.cf\"") + EEShellExec.cmd_exec("postconf -e \"virtual_mailbox_maps = " + "mysql:/etc/postfix/mysql/virtual_" + "mailbox_maps.cf\"") + EEShellExec.cmd_exec("postconf -e \"virtual_alias_maps = " + "mysql:/etc/postfix/mysql/virtual_" + "alias_maps.cf\"") + EEShellExec.cmd_exec("openssl req -new -x509 -days 3650 -nodes" + " -subj /commonName={HOSTNAME}/emailAddre" + "ss={EMAIL} -out /etc/ssl/certs/postfix." + "pem -keyout /etc/ssl/private/postfix.pem" + .format(HOSTNAME=EEVariables.ee_fqdn, + EMAIL=EEVariables.ee_email)) + EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/postfix.pem") + EEShellExec.cmd_exec("postconf -e smtpd_tls_cert_file = " + "/etc/ssl/certs/postfix.pem") + EEShellExec.cmd_exec("postconf -e smtpd_tls_key_file = " + "/etc/ssl/private/postfix.pem") + if len(packages): if any('/usr/bin/wp' == x[1] for x in packages): EEShellExec.cmd_exec("chmod +x /usr/bin/wp") diff --git a/ee/cli/templates/virtual_alias_maps.mustache b/ee/cli/templates/virtual_alias_maps.mustache new file mode 100644 index 00000000..f155569d --- /dev/null +++ b/ee/cli/templates/virtual_alias_maps.mustache @@ -0,0 +1,5 @@ +user = vimbadmin +password = {{password}} +hosts = 127.0.0.1 +dbname = vimbadmin +query = SELECT goto FROM alias WHERE address = '%s' AND active = '1' diff --git a/ee/cli/templates/virtual_domains_maps.mustache b/ee/cli/templates/virtual_domains_maps.mustache new file mode 100644 index 00000000..5ca23900 --- /dev/null +++ b/ee/cli/templates/virtual_domains_maps.mustache @@ -0,0 +1,5 @@ +user = vimbadmin +password = {{password}} +hosts = 127.0.0.1 +dbname = vimbadmin +query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = '0' AND active = '1' diff --git a/ee/cli/templates/virtual_mailbox_maps.mustache b/ee/cli/templates/virtual_mailbox_maps.mustache new file mode 100644 index 00000000..bb2e8b1b --- /dev/null +++ b/ee/cli/templates/virtual_mailbox_maps.mustache @@ -0,0 +1,7 @@ +user = vimbadmin +password = {{password}} +hosts = 127.0.0.1 +dbname = vimbadmin +table = mailbox +select_field = maildir +where_field = username diff --git a/ee/core/variables.py b/ee/core/variables.py index d67f4028..5f39abb5 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -3,6 +3,7 @@ import platform import socket import configparser import os +import sys class EEVariables(): @@ -19,8 +20,12 @@ class EEVariables(): ee_fqdn = socket.getfqdn() # Get git user name and EMail - ee_user = config['user']['name'] - ee_email = config['user']['email'] + try: + ee_user = config['user']['name'] + ee_email = config['user']['email'] + except KeyError as e: + print("Unable to find GIT user name and Email") + sys.exit(1) # EasyEngine stack installation varibales # Nginx repo and packages @@ -58,7 +63,7 @@ class EEVariables(): ee_dovecot = ["dovecot-core", "dovecot-imapd", "dovecot-pop3d", "dovecot-lmtpd", "dovecot-mysql", "dovecot-sieve", - "dovecot-managesieved"] + "dovecot-managesieved", "postfix-mysql"] # Repo ee_repo_file = "ee-repo.list"