From 82e9b9e7c7ecf1664a7b0d4e57a5c4893739559d Mon Sep 17 00:00:00 2001
From: Michel Kàˆser <mail@michelkaeser.ch>
Date: Sat, 16 May 2015 17:44:59 -0400
Subject: [PATCH] define MySQL port by its own (rather than in the host with :port); it's simply cleaner

---
 install/tpl/config.inc.php.master            |    3 +
 install/dist/lib/fedora.lib.php              |    7 +++
 server/lib/classes/db_mysql.inc.php          |   10 +++--
 install/dist/lib/gentoo.lib.php              |    1 
 install/dist/lib/opensuse.lib.php            |    7 +++
 install/update.php                           |    4 +
 server/lib/app.inc.php                       |    2 
 install/tpl/pdns.local.master                |    1 
 interface/lib/config.inc.php                 |    3 +
 install/install.php                          |    8 +++-
 install/lib/installer_base.lib.php           |    9 ++++
 install/tpl/authmysqlrc.master               |    1 
 install/tpl/opensuse_dovecot-sql.conf.master |    2 
 install/tpl/debian6_dovecot-sql.conf.master  |    2 
 install/dist/lib/debian60.lib.php            |    1 
 install/tpl/mydns.conf.master                |    1 
 interface/lib/classes/db_mysql.inc.php       |    8 ++-
 install/tpl/debian_dovecot-sql.conf.master   |    2 
 install/tpl/fedora_dovecot-sql.conf.master   |    2 
 19 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/install/dist/lib/debian60.lib.php b/install/dist/lib/debian60.lib.php
index 80ad28f..8c7f1ba 100644
--- a/install/dist/lib/debian60.lib.php
+++ b/install/dist/lib/debian60.lib.php
@@ -127,6 +127,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		wf($config_dir.'/'.$configfile, $content);
 
diff --git a/install/dist/lib/fedora.lib.php b/install/dist/lib/fedora.lib.php
index 836f107..f017ea5 100644
--- a/install/dist/lib/fedora.lib.php
+++ b/install/dist/lib/fedora.lib.php
@@ -378,6 +378,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		wf("$config_dir/$configfile", $content);
 
 		exec("chmod 660 $config_dir/$configfile");
@@ -496,6 +497,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		wf("$config_dir/$configfile", $content);
 
@@ -653,6 +655,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf["mysql"]["host"], $content);
+		$content = str_replace('{mysql_server_port}', $conf["mysql"]["port"], $content);
 		$content = str_replace('{server_id}', $conf["server_id"], $content);
 		wf($conf["mydns"]["config_dir"].'/'.$configfile, $content);
 		exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
@@ -932,11 +935,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
@@ -957,11 +962,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php
index 2e14006..6615dac 100644
--- a/install/dist/lib/gentoo.lib.php
+++ b/install/dist/lib/gentoo.lib.php
@@ -834,6 +834,7 @@
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
diff --git a/install/dist/lib/opensuse.lib.php b/install/dist/lib/opensuse.lib.php
index 59c7b32..b452c2f 100644
--- a/install/dist/lib/opensuse.lib.php
+++ b/install/dist/lib/opensuse.lib.php
@@ -433,6 +433,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		wf("$config_dir/$configfile", $content);
 
 		exec("chmod 660 $config_dir/$configfile");
@@ -545,6 +546,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		wf("$config_dir/$configfile", $content);
 
@@ -700,6 +702,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf["mysql"]["host"], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf["server_id"], $content);
 		wf($conf["mydns"]["config_dir"].'/'.$configfile, $content);
 		exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
@@ -1006,11 +1009,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
@@ -1031,11 +1036,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
diff --git a/install/install.php b/install/install.php
index 12e0178..8b32027 100644
--- a/install/install.php
+++ b/install/install.php
@@ -189,6 +189,7 @@
 $finished = false;
 do {
 	$tmp_mysql_server_host = $inst->free_query('MySQL server hostname', $conf['mysql']['host'],'mysql_hostname');	 
+	$tmp_mysql_server_port = $inst->free_query('MySQL server port', $conf['mysql']['port'],'mysql_port');
 	$tmp_mysql_server_admin_user = $inst->free_query('MySQL root username', $conf['mysql']['admin_user'],'mysql_root_user');	 
 	$tmp_mysql_server_admin_password = $inst->free_query('MySQL root password', $conf['mysql']['admin_password'],'mysql_root_password');	 
 	$tmp_mysql_server_database = $inst->free_query('MySQL database to create', $conf['mysql']['database'],'mysql_database');	 
@@ -202,8 +203,9 @@
 	}
 
 	//* Initialize the MySQL server connection
-	if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+	if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password, (int)$tmp_mysql_server_port)) {
 		$conf['mysql']['host'] = $tmp_mysql_server_host;
+		$conf['mysql']['port'] = $tmp_mysql_server_port;
 		$conf['mysql']['admin_user'] = $tmp_mysql_server_admin_user;
 		$conf['mysql']['admin_password'] = $tmp_mysql_server_admin_password;
 		$conf['mysql']['database'] = $tmp_mysql_server_database;
@@ -535,13 +537,15 @@
 		$finished = false;
 		do {
 			$tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host'],'mysql_master_hostname'); 
+			$tmp_mysql_server_port = $inst->free_query('MySQL master server port', $conf['mysql']['master_port'],'mysql_master_port');
 			$tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user'],'mysql_master_root_user');	 
 			$tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password'],'mysql_master_root_password'); 
 			$tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database'],'mysql_master_database');
 
 			//* Initialize the MySQL server connection
-			if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+			if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password, (int)$tmp_mysql_server_port)) {
 				$conf['mysql']['master_host'] = $tmp_mysql_server_host;
+				$conf['mysql']['master_port'] = $tmp_mysql_server_port;
 				$conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
 				$conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
 				$conf['mysql']['master_database'] = $tmp_mysql_server_database;
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index 9610e19..f867f04 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -968,6 +968,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		wf($config_dir.'/'.$configfile, $content);
 
 		chmod($config_dir.'/'.$configfile, 0660);
@@ -1081,6 +1082,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		wf($config_dir.'/'.$configfile, $content);
 
@@ -1259,6 +1261,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		wf($conf['mydns']['config_dir'].'/'.$configfile, $content);
 		chmod($conf['mydns']['config_dir'].'/'.$configfile, 0600);
@@ -1302,6 +1305,7 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{powerdns_database}', $conf['powerdns']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 		wf($conf['powerdns']['config_dir'].'/'.$configfile, $content);
 		chmod($conf['powerdns']['config_dir'].'/'.$configfile, 0600);
 		chown($conf['powerdns']['config_dir'].'/'.$configfile, 'root');
@@ -1967,11 +1971,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
@@ -1992,11 +1998,13 @@
 		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
 		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
 		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
+		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
 
 		$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
 		$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
 		$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
 		$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
+		$content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
 
 		$content = str_replace('{server_id}', $conf['server_id'], $content);
 		$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
@@ -2650,6 +2658,7 @@
 		$tContents = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $tContents);
 		$tContents = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $tContents);
 		$tContents = str_replace('{mysql_server_host}', $conf['mysql']['host'], $tContents);
+		$tContents = str_replace('{mysql_server_port}', $conf['mysql']['port'], $tContents);
 		$tContents = str_replace('{mysql_server_port}', $conf["mysql"]["port"], $tContents);
 
 		return $tContents;
diff --git a/install/tpl/authmysqlrc.master b/install/tpl/authmysqlrc.master
index d44b4f2..3630600 100644
--- a/install/tpl/authmysqlrc.master
+++ b/install/tpl/authmysqlrc.master
@@ -1,4 +1,5 @@
 MYSQL_SERVER {mysql_server_host}
+MYSQL_PORT {mysql_server_port}
 MYSQL_USERNAME {mysql_server_ispconfig_user}
 MYSQL_PASSWORD {mysql_server_ispconfig_password}
 MYSQL_PORT 0
diff --git a/install/tpl/config.inc.php.master b/install/tpl/config.inc.php.master
index e5fa2c4..0737c13 100644
--- a/install/tpl/config.inc.php.master
+++ b/install/tpl/config.inc.php.master
@@ -63,6 +63,7 @@
 //** Database
 $conf['db_type'] = 'mysql';
 $conf['db_host'] = '{mysql_server_host}';
+$conf['db_port'] = '{mysql_server_port}';
 $conf['db_database'] = '{mysql_server_database}';
 $conf['db_user'] = '{mysql_server_ispconfig_user}';
 $conf['db_password'] = '{mysql_server_ispconfig_password}';
@@ -72,6 +73,7 @@
 
 define('DB_TYPE',$conf['db_type']);
 define('DB_HOST',$conf['db_host']);
+define('DB_PORT',$conf['db_port']);
 define('DB_DATABASE',$conf['db_database']);
 define('DB_USER',$conf['db_user']);
 define('DB_PASSWORD',$conf['db_password']);
@@ -81,6 +83,7 @@
 //** Database settings for the master DB. This setting is only used in multiserver setups
 $conf['dbmaster_type']			= 'mysql';
 $conf['dbmaster_host']			= '{mysql_master_server_host}';
+$conf['dbmaster_host']          = '{mysql_master_server_port}';
 $conf['dbmaster_database']		= '{mysql_master_server_database}';
 $conf['dbmaster_user']			= '{mysql_master_server_ispconfig_user}';
 $conf['dbmaster_password']		= '{mysql_master_server_ispconfig_password}';
diff --git a/install/tpl/debian6_dovecot-sql.conf.master b/install/tpl/debian6_dovecot-sql.conf.master
index 5f02350..30afc18 100644
--- a/install/tpl/debian6_dovecot-sql.conf.master
+++ b/install/tpl/debian6_dovecot-sql.conf.master
@@ -10,7 +10,7 @@
 # );
 
 driver = mysql
-connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password}
+connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password} port={mysql_server_port}
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
diff --git a/install/tpl/debian_dovecot-sql.conf.master b/install/tpl/debian_dovecot-sql.conf.master
index 647655f..b8919ff 100644
--- a/install/tpl/debian_dovecot-sql.conf.master
+++ b/install/tpl/debian_dovecot-sql.conf.master
@@ -117,7 +117,7 @@
 #password_query = SELECT userid as user, password, home as userdb_home, uid as userdb_uid, gid as userdb_gid FROM users WHERE userid = '%u'
 
 driver = mysql
-connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password}
+connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password} port={mysql_server_port}
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
diff --git a/install/tpl/fedora_dovecot-sql.conf.master b/install/tpl/fedora_dovecot-sql.conf.master
index 3815a0e..d242c8c 100644
--- a/install/tpl/fedora_dovecot-sql.conf.master
+++ b/install/tpl/fedora_dovecot-sql.conf.master
@@ -130,7 +130,7 @@
 #  FROM users WHERE userid = '%u'
 
 driver = mysql
-connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password}
+connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password} port={mysql_server_port}
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
diff --git a/install/tpl/mydns.conf.master b/install/tpl/mydns.conf.master
index 4af5a8e..fbfac02 100644
--- a/install/tpl/mydns.conf.master
+++ b/install/tpl/mydns.conf.master
@@ -18,6 +18,7 @@
 db-user = {mysql_server_ispconfig_user}             # SQL server username
 db-password = {mysql_server_ispconfig_password}         # SQL server password
 database = {mysql_server_database}          # MyDNS database name
+db-port = {mysql_server_port}             # SQL server port
 
 
                                 # GENERAL OPTIONS
diff --git a/install/tpl/opensuse_dovecot-sql.conf.master b/install/tpl/opensuse_dovecot-sql.conf.master
index 938975e..f9ffbf7 100644
--- a/install/tpl/opensuse_dovecot-sql.conf.master
+++ b/install/tpl/opensuse_dovecot-sql.conf.master
@@ -130,7 +130,7 @@
 #  FROM users WHERE userid = '%u'
 
 driver = mysql
-connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password}
+connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password} port={mysql_server_port}
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
diff --git a/install/tpl/pdns.local.master b/install/tpl/pdns.local.master
index 3e29ec4..eb4ab71 100644
--- a/install/tpl/pdns.local.master
+++ b/install/tpl/pdns.local.master
@@ -7,6 +7,7 @@
 gmysql-user={mysql_server_ispconfig_user}
 gmysql-password={mysql_server_ispconfig_password}
 gmysql-dbname={powerdns_database}
+gmysql-port={mysql_server_port}
 
 slave=yes
 master=yes
diff --git a/install/update.php b/install/update.php
index 4394294..97b28fd 100644
--- a/install/update.php
+++ b/install/update.php
@@ -247,13 +247,15 @@
 	$finished = false;
 	do {
 		$tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host'],'mysql_master_hostname');
+		$tmp_mysql_server_port = $inst->free_query('MySQL master server port', $conf['mysql']['master_port'],'mysql_master_port');
 		$tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user'],'mysql_master_root_user');	 
 		$tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password'],'mysql_master_root_password');
 		$tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database'],'mysql_master_database');
 
 		//* Initialize the MySQL server connection
-		if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+		if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password, (int)$tmp_mysql_server_port)) {
 			$conf['mysql']['master_host'] = $tmp_mysql_server_host;
+			$conf['mysql']['master_port'] = $tmp_mysql_server_port;
 			$conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
 			$conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
 			$conf['mysql']['master_database'] = $tmp_mysql_server_database;
diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php
index e4c8d31..116af65 100644
--- a/interface/lib/classes/db_mysql.inc.php
+++ b/interface/lib/classes/db_mysql.inc.php
@@ -36,6 +36,7 @@
 	private $_iConnId;
 
 	private $dbHost = '';  // hostname of the MySQL server
+	private $dbPort = '';  // port of the MySQL server
 	private $dbName = '';  // logical database name on that server
 	private $dbUser = '';  // database authorized user
 	private $dbPass = '';  // user's password
@@ -65,6 +66,7 @@
 		global $conf;
 		if($prefix != '') $prefix .= '_';
 		$this->dbHost = $conf[$prefix.'db_host'];
+		$this->dbPort = $conf[$prefix.'db_port'];
 		$this->dbName = $conf[$prefix.'db_database'];
 		$this->dbUser = $conf[$prefix.'db_user'];
 		$this->dbPass = $conf[$prefix.'db_password'];
@@ -72,13 +74,13 @@
 		$this->dbNewLink = $conf[$prefix.'db_new_link'];
 		$this->dbClientFlags = $conf[$prefix.'db_client_flags'];
 
-		$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass);
+		$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, (int)$this->dbPort);
 		$try = 0;
 		while((!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5) {
 			if($try > 0) sleep(1);
 
 			$try++;
-			$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass);
+			$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, (int)$this->dbPort);
 		}
 
 		if(!is_object($this->_iConnId) || mysqli_connect_error()) {
@@ -240,7 +242,7 @@
 			$try++;
 			$ok = mysqli_ping($this->_iConnId);
 			if(!$ok) {
-				if(!mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName)) {
+				if(!mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort)) {
 					if($try > 4) {
 						$this->_sqlerror('DB::query -> reconnect');
 						return false;
diff --git a/interface/lib/config.inc.php b/interface/lib/config.inc.php
index 7b5dace..907f372 100644
--- a/interface/lib/config.inc.php
+++ b/interface/lib/config.inc.php
@@ -51,6 +51,7 @@
 //** Database
 $conf['db_type'] = 'mysql';
 $conf['db_host'] = 'localhost';
+$conf['db_port'] = 3306;
 $conf['db_database'] = 'ispconfig3_305';
 $conf['db_user'] = 'root';
 $conf['db_password'] = '';
@@ -60,6 +61,7 @@
 
 define('DB_TYPE', $conf['db_type']);
 define('DB_HOST', $conf['db_host']);
+define('DB_PORT', $conf['db_port']);
 define('DB_DATABASE', $conf['db_database']);
 define('DB_USER', $conf['db_user']);
 define('DB_PASSWORD', $conf['db_password']);
@@ -69,6 +71,7 @@
 //** Database settings for the master DB. This setting is only used in multiserver setups
 $conf['dbmaster_type']   = 'mysql';
 $conf['dbmaster_host']   = '{mysql_master_server_host}';
+$conf['dbmaster_port']   = '{mysql_master_server_port}';
 $conf['dbmaster_database']  = '{mysql_master_server_database}';
 $conf['dbmaster_user']   = '{mysql_master_server_ispconfig_user}';
 $conf['dbmaster_password']  = '{mysql_master_server_ispconfig_password}';
diff --git a/server/lib/app.inc.php b/server/lib/app.inc.php
index dc2b016..dd8be5a 100755
--- a/server/lib/app.inc.php
+++ b/server/lib/app.inc.php
@@ -51,7 +51,7 @@
 					*/
 
 			if($conf['dbmaster_host'] != '' && ($conf['dbmaster_host'] != $conf['db_host'] || ($conf['dbmaster_host'] == $conf['db_host'] && $conf['dbmaster_database'] != $conf['db_database']))) {
-				$this->dbmaster = new db($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password'], $conf['dbmaster_database']);
+				$this->dbmaster = new db($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password'], $conf['dbmaster_database'], $conf['dbmaster_port']);
 			} else {
 				$this->dbmaster = $this->db;
 			}
diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php
index d2592f5..67bf7c4 100644
--- a/server/lib/classes/db_mysql.inc.php
+++ b/server/lib/classes/db_mysql.inc.php
@@ -36,6 +36,7 @@
 	private $_iConnId;
 
 	private $dbHost = '';  // hostname of the MySQL server
+	private $dbPort = '';  // port of the MySQL server
 	private $dbName = '';  // logical database name on that server
 	private $dbUser = '';  // database authorized user
 	private $dbPass = '';  // user's password
@@ -61,10 +62,11 @@
 	*/
 
 	// constructor
-	public function __construct($host = NULL , $user = NULL, $pass = NULL, $database = NULL) {
+	public function __construct($host = NULL , $user = NULL, $pass = NULL, $database = NULL, $port = NULL) {
 		global $app, $conf;
 
 		$this->dbHost = $host ? $host  : $conf['db_host'];
+		$this->dbPort = $port ? $port : $conf['db_port'];
 		$this->dbName = $database ? $database : $conf['db_database'];
 		$this->dbUser = $user ? $user : $conf['db_user'];
 		$this->dbPass = $pass ? $pass : $conf['db_password'];
@@ -72,13 +74,13 @@
 		$this->dbNewLink = $conf['db_new_link'];
 		$this->dbClientFlags = $conf['db_client_flags'];
 
-		$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass);
+		$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, (int)$this->dbPort);
 		$try = 0;
 		while((!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5) {
 			if($try > 0) sleep(1);
 
 			$try++;
-			$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass);
+			$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, (int)$this->dbPort);
 		}
 
 		if(!is_object($this->_iConnId) || mysqli_connect_error()) {
@@ -193,7 +195,7 @@
 			$try++;
 			$ok = mysqli_ping($this->_iConnId);
 			if(!$ok) {
-				if(!mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName)) {
+				if(!mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort)) {
 					if($this->errorNumber == '111') {
 						// server is not available
 						if($try > 9) {

--
Gitblit v1.9.1