@@ -117,25 +117,24 @@ public function configure_database()
117117 {
118118 global $ conf ;
119119
120- $ cf = $ conf ['mysql ' ]; // make $conf['mysql'] more accessible
121120 //** Create the database
122- if (!$ this ->db ->query ('CREATE DATABASE IF NOT EXISTS ' .$ cf [ ' database ' ].' DEFAULT CHARACTER SET ' .$ cf ['charset ' ])) {
123- $ this ->error ('Unable to create MySQL database: ' .$ cf ['database ' ].'. ' );
121+ if (!$ this ->db ->query ('CREATE DATABASE IF NOT EXISTS ' .$ conf [ ' mysql ' ][ ' database ' ].' DEFAULT CHARACTER SET ' .$ conf [ ' mysql ' ] ['charset ' ])) {
122+ $ this ->error ('Unable to create MySQL database: ' .$ conf [ ' mysql ' ] ['database ' ].'. ' );
124123 }
125124
126125 //* Set the database name in the DB library
127- $ this ->db ->dbName = $ cf ['database ' ];
126+ $ this ->db ->dbName = $ conf [ ' mysql ' ] ['database ' ];
128127
129128 //* Load the database dump into the database, if database contains no tables
130129 $ db_tables = $ this ->db ->getTables ();
131130 if (count ($ db_tables ) > 0 ) {
132131 $ this ->error ('Stopped: Database already contains some tables. ' );
133132 } else {
134- if ($ cf ['admin_password ' ] == '' ) {
135- caselog ("mysql --default-character-set= " .$ cf [ ' charset ' ]." -h ' " .$ cf [ ' host ' ]."' -u ' " .$ cf [ ' admin_user ' ]."' ' " .$ cf ['database ' ]."' < ' " .ISPC_INSTALL_ROOT ."/install/sql/ispconfig3.sql' &> /dev/null " ,
133+ if ($ conf [ ' mysql ' ] ['admin_password ' ] == '' ) {
134+ caselog ("mysql --default-character-set= " .$ conf [ ' mysql ' ][ ' charset ' ]." -h ' " .$ conf [ ' mysql ' ][ ' host ' ]."' -u ' " .$ conf [ ' mysql ' ][ ' admin_user ' ]."' ' " .$ conf [ ' mysql ' ] ['database ' ]."' < ' " .ISPC_INSTALL_ROOT ."/install/sql/ispconfig3.sql' &> /dev/null " ,
136135 __FILE__ , __LINE__ , 'read in ispconfig3.sql ' , 'could not read in ispconfig3.sql ' );
137136 } else {
138- caselog ("mysql --default-character-set= " .$ cf [ ' charset ' ]." -h ' " .$ cf [ ' host ' ]."' -u ' " .$ cf [ ' admin_user ' ]."' -p' " .$ cf [ ' admin_password ' ]."' ' " .$ cf ['database ' ]."' < ' " .ISPC_INSTALL_ROOT ."/install/sql/ispconfig3.sql' &> /dev/null " ,
137+ caselog ("mysql --default-character-set= " .$ conf [ ' mysql ' ][ ' charset ' ]." -h ' " .$ conf [ ' mysql ' ][ ' host ' ]."' -u ' " .$ conf [ ' mysql ' ][ ' admin_user ' ]."' -p' " .$ conf [ ' mysql ' ][ ' admin_password ' ]."' ' " .$ conf [ ' mysql ' ] ['database ' ]."' < ' " .ISPC_INSTALL_ROOT ."/install/sql/ispconfig3.sql' &> /dev/null " ,
139138 __FILE__ , __LINE__ , 'read in ispconfig3.sql ' , 'could not read in ispconfig3.sql ' );
140139 }
141140 $ db_tables = $ this ->db ->getTables ();
@@ -150,40 +149,74 @@ public function add_database_server_record() {
150149
151150 global $ conf ;
152151
153- $ cf = $ conf ['mysql ' ]; // make $conf['mysql'] more accessible
154-
155- if ($ cf ['host ' ] == 'localhost ' ) {
152+ if ($ conf ['mysql ' ]['host ' ] == 'localhost ' ) {
156153 $ from_host = 'localhost ' ;
157154 } else {
158155 $ from_host = $ conf ['hostname ' ];
159156 }
160157
161- // Delete ISPConfig user, in case that it exists
162- $ this ->db ->query ("DELETE FROM mysql.user WHERE User = ' " .$ cf ['ispconfig_user ' ]."' AND Host = ' " .$ from_host ."'; " );
163- $ this ->db ->query ("DELETE FROM mysql.db WHERE Db = ' " .$ cf ['database ' ]."' AND Host = ' " .$ from_host ."'; " );
158+ // Delete ISPConfig user in the local database , in case that it exists
159+ $ this ->db ->query ("DELETE FROM mysql.user WHERE User = ' " .$ conf [ ' mysql ' ] ['ispconfig_user ' ]."' AND Host = ' " .$ from_host ."'; " );
160+ $ this ->db ->query ("DELETE FROM mysql.db WHERE Db = ' " .$ conf [ ' mysql ' ] ['database ' ]."' AND Host = ' " .$ from_host ."'; " );
164161 $ this ->db ->query ('FLUSH PRIVILEGES; ' );
165162
166- //* Create the ISPConfig database user
167- $ query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON ' .$ cf ['database ' ].".* "
168- ."TO ' " .$ cf ['ispconfig_user ' ]."'@' " .$ from_host ."' "
169- ."IDENTIFIED BY ' " .$ cf ['ispconfig_password ' ]."'; " ;
163+ //* Create the ISPConfig database user in the local database
164+ $ query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON ' .$ conf [ ' mysql ' ] ['database ' ].".* "
165+ ."TO ' " .$ conf [ ' mysql ' ] ['ispconfig_user ' ]."'@' " .$ from_host ."' "
166+ ."IDENTIFIED BY ' " .$ conf [ ' mysql ' ] ['ispconfig_password ' ]."'; " ;
170167 if (!$ this ->db ->query ($ query )) {
171- $ this ->error ('Unable to create database user: ' .$ cf ['ispconfig_user ' ].' Error: ' .$ this ->db ->errorMessage );
168+ $ this ->error ('Unable to create database user: ' .$ conf [ ' mysql ' ] ['ispconfig_user ' ].' Error: ' .$ this ->db ->errorMessage );
172169 }
173170
174171 //* Reload database privelages
175172 $ this ->db ->query ('FLUSH PRIVILEGES; ' );
176173
177174 //* Set the database name in the DB library
178- $ this ->db ->dbName = $ cf ['database ' ];
175+ $ this ->db ->dbName = $ conf [ ' mysql ' ] ['database ' ];
179176
180177 $ server_ini_content = rf ("tpl/server.ini.master " );
181178 $ server_ini_content = mysql_real_escape_string ($ server_ini_content );
182179
183- $ sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', ' " .$ conf ['hostname ' ]."', 1, 1, 1, 1, 1, 1, ' $ server_ini_content', 0, 1); " ;
184- $ this ->db ->query ($ sql );
185- $ conf ['server_id ' ] = $ this ->db ->insertID ();
186- $ conf ['server_id ' ] = $ conf ['server_id ' ];
180+ if ($ conf ['mysql ' ]['master_slave_setup ' ] == 'y ' ) {
181+
182+ //* Insert the server record in master DB
183+ $ sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', ' " .$ conf ['hostname ' ]."', 1, 1, 1, 1, 1, 1, ' $ server_ini_content', 0, 1); " ;
184+ $ this ->dbmaster ->query ($ sql );
185+ $ conf ['server_id ' ] = $ this ->dbmaster ->insertID ();
186+ $ conf ['server_id ' ] = $ conf ['server_id ' ];
187+
188+ //* Insert the same record in the local DB
189+ $ sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (' " .$ conf ['server_id ' ]."',1, 1, 'riud', 'riud', 'r', ' " .$ conf ['hostname ' ]."', 1, 1, 1, 1, 1, 1, ' $ server_ini_content', 0, 1); " ;
190+ $ this ->db ->query ($ sql );
191+
192+ //* insert the ispconfig user in the remote server
193+ $ from_host = $ conf ['hostname ' ];
194+
195+ //* username for the ispconfig user
196+ $ conf ['mysql ' ]['master_ispconfig_user ' ] = 'ispconfigserver ' .$ conf ['server_id ' ];
197+
198+ //* Delete ISPConfig user in the local database, in case that it exists
199+ $ this ->dbmaster ->query ("DELETE FROM mysql.user WHERE User = ' " .$ conf ['mysql ' ]['master_ispconfig_user ' ]."' AND Host = ' " .$ from_host ."'; " );
200+ $ this ->dbmaster ->query ("DELETE FROM mysql.db WHERE Db = ' " .$ conf ['mysql ' ]['master_database ' ]."' AND Host = ' " .$ from_host ."'; " );
201+ $ this ->dbmaster ->query ('FLUSH PRIVILEGES; ' );
202+
203+ //* Create the ISPConfig database user in the local database
204+ $ query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON ' .$ conf ['mysql ' ]['master_database ' ].".* "
205+ ."TO ' " .$ conf ['mysql ' ]['master_ispconfig_user ' ]."'@' " .$ from_host ."' "
206+ ."IDENTIFIED BY ' " .$ conf ['mysql ' ]['master_ispconfig_password ' ]."'; " ;
207+ if (!$ this ->dbmaster ->query ($ query )) {
208+ $ this ->error ('Unable to create database user in master database: ' .$ conf ['mysql ' ]['master_ispconfig_user ' ].' Error: ' .$ this ->dbmaster ->errorMessage );
209+ }
210+
211+ } else {
212+ //* Insert the server, if its not a mster / slave setup
213+ $ sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', ' " .$ conf ['hostname ' ]."', 1, 1, 1, 1, 1, 1, ' $ server_ini_content', 0, 1); " ;
214+ $ this ->db ->query ($ sql );
215+ $ conf ['server_id ' ] = $ this ->db ->insertID ();
216+ $ conf ['server_id ' ] = $ conf ['server_id ' ];
217+ }
218+
219+
187220 }
188221
189222
@@ -724,6 +757,12 @@ public function install_ispconfig()
724757 $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ['mysql ' ]['ispconfig_password ' ], $ content );
725758 $ content = str_replace ('{mysql_server_database} ' , $ conf ['mysql ' ]['database ' ], $ content );
726759 $ content = str_replace ('{mysql_server_host} ' , $ conf ['mysql ' ]['host ' ], $ content );
760+
761+ $ content = str_replace ('{mysql_master_server_ispconfig_user} ' , $ conf ['mysql ' ]['master_ispconfig_user ' ], $ content );
762+ $ content = str_replace ('{mysql_master_server_ispconfig_password} ' , $ conf ['mysql ' ]['master_ispconfig_password ' ], $ content );
763+ $ content = str_replace ('{mysql_master_server_database} ' , $ conf ['mysql ' ]['master_database ' ], $ content );
764+ $ content = str_replace ('{mysql_master_server_host} ' , $ conf ['mysql ' ]['master_host ' ], $ content );
765+
727766 $ content = str_replace ('{ispconfig_log_priority} ' , $ conf ['ispconfig_log_priority ' ], $ content );
728767 wf ("$ install_dir/interface/lib/ $ configfile " , $ content );
729768
@@ -737,6 +776,12 @@ public function install_ispconfig()
737776 $ content = str_replace ('{mysql_server_ispconfig_password} ' , $ conf ['mysql ' ]['ispconfig_password ' ], $ content );
738777 $ content = str_replace ('{mysql_server_database} ' , $ conf ['mysql ' ]['database ' ], $ content );
739778 $ content = str_replace ('{mysql_server_host} ' , $ conf ['mysql ' ]['host ' ], $ content );
779+
780+ $ content = str_replace ('{mysql_master_server_ispconfig_user} ' , $ conf ['mysql ' ]['master_ispconfig_user ' ], $ content );
781+ $ content = str_replace ('{mysql_master_server_ispconfig_password} ' , $ conf ['mysql ' ]['master_ispconfig_password ' ], $ content );
782+ $ content = str_replace ('{mysql_master_server_database} ' , $ conf ['mysql ' ]['master_database ' ], $ content );
783+ $ content = str_replace ('{mysql_master_server_host} ' , $ conf ['mysql ' ]['master_host ' ], $ content );
784+
740785 $ content = str_replace ('{server_id} ' , $ conf ['server_id ' ], $ content );
741786 $ content = str_replace ('{ispconfig_log_priority} ' , $ conf ['ispconfig_log_priority ' ], $ content );
742787 wf ("$ install_dir/server/lib/ $ configfile " , $ content );
0 commit comments