@@ -282,9 +282,11 @@ public function grant_master_database_rights() {
282282
283283 $ hosts [$ from_host ]['user ' ] = $ conf ['mysql ' ]['master_ispconfig_user ' ];
284284 $ hosts [$ from_host ]['db ' ] = $ conf ['mysql ' ]['master_database ' ];
285+ $ hosts [$ from_host ]['pwd ' ] = $ conf ['mysql ' ]['master_ispconfig_password ' ];
285286
286287 $ hosts [$ from_ip ]['user ' ] = $ conf ['mysql ' ]['master_ispconfig_user ' ];
287288 $ hosts [$ from_ip ]['db ' ] = $ conf ['mysql ' ]['master_database ' ];
289+ $ hosts [$ from_ip ]['pwd ' ] = $ conf ['mysql ' ]['master_ispconfig_password ' ];
288290 } else {
289291 /*
290292 * it is NOT a master-slave - Setup so we have to find out all clients and their
@@ -298,19 +300,28 @@ public function grant_master_database_rights() {
298300 foreach ($ data as $ item ){
299301 $ hosts [$ item ['Host ' ]]['user ' ] = $ item ['User ' ];
300302 $ hosts [$ item ['Host ' ]]['db ' ] = $ conf ['mysql ' ]['master_database ' ];
303+ $ hosts [$ item ['Host ' ]]['pwd ' ] = '' ; // the user already exists, so we need no pwd!
301304 }
302305 }
303306
304307 if (is_array ($ hosts )) {
305308 foreach ($ hosts as $ host => $ value ) {
306309 /*
307- * Delete ISPConfig user in the master database, in case that it exists
310+ * If a pwd exists, this means, we have to add the new user (and his pwd).
311+ * if not, the user already exists and we do not need the pwd
308312 */
309- $ query = " REVOKE ALL PRIVILEGES, GRANT OPTION FROM ' " . $ value ['user ' ]. " '@' " . $ host . " ' " ;
310- if (! $ this -> dbmaster -> query ( $ query )) {
311- $ this ->error ( ' Unable to remove rights of user in master database: ' . $ value [ ' db ' ]. ' Error: ' . $ this -> dbmaster ->errorMessage );
313+ if ( $ value ['pwd ' ] != '' ){
314+ $ query = " CREATE USER ' " . $ value [ ' user ' ]. " '@' " . $ host . " ' IDENTIFIED BY ' " . $ value [ ' pwd ' ] . " ' " ;
315+ $ this ->dbmaster ->query ( $ query ); // ignore the error
312316 }
313317
318+ /*
319+ * Try to delete all rights of the user in case that it exists.
320+ * In Case that it will not exist, do nothing (ignore the error!)
321+ */
322+ $ query = "REVOKE ALL PRIVILEGES, GRANT OPTION FROM ' " .$ value ['user ' ]."'@' " .$ host ."' " ;
323+ $ this ->dbmaster ->query ($ query ); // ignore the error
324+
314325 //* Create the ISPConfig database user in the remote database
315326 $ query = "GRANT SELECT ON " .$ value ['db ' ].".`server` TO ' " .$ value ['user ' ]."'@' " .$ host ."' " ;
316327 if (!$ this ->dbmaster ->query ($ query )) {
0 commit comments