diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 69177dd7..4c54bd8b 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -647,15 +647,18 @@ class EEStackController(CementBaseController): EEShellExec.cmd_exec(self, 'mysql < /var/www/22222/htdocs/db' '/anemometer/install.sql') EEMysql.execute(self, 'grant select on *.* to \'anemometer\'' - '@\'localhost\'') + '@\'{0}\''.format(self.app.config.get('mysql', + 'grant-host'))) EEMysql.execute(self, 'grant all on slow_query_log.* to' - '\'anemometer\'@\'localhost\' IDENTIFIED' - ' BY \''+chars+'\'') + '\'anemometer\'@\'{0}\' IDENTIFIED' + ' BY \'{1}\''.format(self.app.config.get( + 'mysql', 'grant-host'), + chars)) # Custom Anemometer configuration Log.debug(self, "configration Anemometer") - data = dict(host='localhost', port='3306', user='anemometer', - password=chars) + data = dict(host=EEVariables.ee_mysql_host, port='3306', + user='anemometer', password=chars) ee_anemometer = open('/var/www/22222/htdocs/db/anemometer' '/conf/config.inc.php', 'w') self.app.render((data), 'anemometer.mustache', @@ -700,8 +703,9 @@ class EEStackController(CementBaseController): " vimbadmin") Log.debug(self, "Granting all privileges on vimbadmin ") EEMysql.execute(self, "grant all privileges on vimbadmin.* to" - " vimbadmin@localhost IDENTIFIED BY" - " '{password}'".format(password=vm_passwd)) + " vimbadmin@{0} IDENTIFIED BY" + " '{1}'".format(self.app.config.get('mysql', + 'grant-host'), vm_passwd)) # Configure ViMbAdmin settings config = configparser.ConfigParser(strict=False) @@ -719,7 +723,7 @@ class EEStackController(CementBaseController): config['user']['resources.doctrine2.connection.' 'options.password'] = vm_passwd config['user']['resources.doctrine2.connection.' - 'options.host'] = 'localhost' + 'options.host'] = EEVariables.ee_mysql_host config['user']['defaults.mailbox.password_scheme'] = 'md5' config['user']['securitysalt'] = (''.join(random.sample (string.ascii_letters @@ -765,7 +769,7 @@ class EEStackController(CementBaseController): Log.debug(self, "Creating directory " "/etc/postfix/mysql/") os.makedirs('/etc/postfix/mysql/') - data = dict(password=vm_passwd) + data = dict(password=vm_passwd, host=EEVariables.ee_mysql) vm_config = open('/etc/postfix/mysql/virtual_alias_maps.cf', 'w') self.app.render((data), 'virtual_alias_maps.mustache', @@ -832,8 +836,10 @@ class EEStackController(CementBaseController): Log.debug(self, "Grant all privileges on roundcubemail") EEMysql.execute(self, "grant all privileges" " on roundcubemail.* to " - " roundcube@localhost IDENTIFIED BY " - "'{password}'".format(password=rc_passwd)) + " roundcube@{0} IDENTIFIED BY " + "'{1}'".format(self.app.config.get( + 'mysql', 'grant-host'), + rc_passwd)) EEShellExec.cmd_exec(self, "mysql roundcubemail < /var/www/" "roundcubemail/htdocs/SQL/mysql" ".initial.sql") @@ -844,10 +850,12 @@ class EEStackController(CementBaseController): "config.inc.php") EEShellExec.cmd_exec(self, "sed -i \"s\'mysql://roundcube:" "pass@localhost/roundcubemail\'mysql://" - "roundcube:{password}@localhost/" + "roundcube:{0}@{1}/" "roundcubemail\'\" /var/www/roundcubemail" "/htdocs/config/config." - "inc.php".format(password=rc_passwd)) + "inc.php" + .format(rc_passwd, + EEVariables.ee_mysql_host)) # Sieve plugin configuration in roundcube EEShellExec.cmd_exec(self, "bash -c \"sed -i \\\"s:\$config\[" diff --git a/ee/cli/templates/dovecot-sql-conf.mustache b/ee/cli/templates/dovecot-sql-conf.mustache index 8c76123d..0ec50c11 100644 --- a/ee/cli/templates/dovecot-sql-conf.mustache +++ b/ee/cli/templates/dovecot-sql-conf.mustache @@ -1,5 +1,5 @@ driver = mysql -connect = host=localhost user=vimbadmin password={{password}} dbname=vimbadmin +connect = host={{host}} user=vimbadmin password={{password}} dbname=vimbadmin default_pass_scheme = MD5 password_query = SELECT username as user, password as password, \ homedir AS home, maildir AS mail, \ diff --git a/ee/cli/templates/virtual_alias_maps.mustache b/ee/cli/templates/virtual_alias_maps.mustache index f155569d..b7919c74 100644 --- a/ee/cli/templates/virtual_alias_maps.mustache +++ b/ee/cli/templates/virtual_alias_maps.mustache @@ -1,5 +1,5 @@ user = vimbadmin password = {{password}} -hosts = 127.0.0.1 +hosts = {{host}} 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 index 5ca23900..2dce79a0 100644 --- a/ee/cli/templates/virtual_domains_maps.mustache +++ b/ee/cli/templates/virtual_domains_maps.mustache @@ -1,5 +1,5 @@ user = vimbadmin password = {{password}} -hosts = 127.0.0.1 +hosts = {{host}} 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 index bb2e8b1b..f8aafdaf 100644 --- a/ee/cli/templates/virtual_mailbox_maps.mustache +++ b/ee/cli/templates/virtual_mailbox_maps.mustache @@ -1,6 +1,6 @@ user = vimbadmin password = {{password}} -hosts = 127.0.0.1 +hosts = {{host}} dbname = vimbadmin table = mailbox select_field = maildir diff --git a/ee/core/variables.py b/ee/core/variables.py index 0a3f2bc3..3b0c5cd7 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -51,6 +51,18 @@ class EEVariables(): ee_ram = psutil.virtual_memory().total / (1024 * 1024) ee_swap = psutil.swap_memory().total / (1024 * 1024) + # MySQL hostname + ee_mysql_host = "" + config = configparser.RawConfigParser() + cnfpath = os.path.expanduser("~")+"/.my.cnf" + if [cnfpath] == config.read(cnfpath): + try: + ee_mysql_host = config.get('client', 'host') + except configparser.NoOptionError as e: + ee_mysql_host = "localhost" + else: + ee_mysql_host = "localhost" + # EasyEngine stack installation varibales # Nginx repo and packages if ee_platform_distro == 'Ubuntu':