55namespace PhpMyAdmin ;
66
77use PhpMyAdmin \Config \ConfigFile ;
8+ use PhpMyAdmin \Config \Settings \Server ;
89use PhpMyAdmin \ConfigStorage \Relation ;
910use PhpMyAdmin \Dbal \Connection ;
1011use PhpMyAdmin \Dbal \DatabaseName ;
@@ -185,7 +186,7 @@ public static function run(bool $isSetupPage = false): void
185186 return ;
186187 }
187188
188- self ::setCurrentServerGlobal ($ container , $ config );
189+ self ::setCurrentServerGlobal ($ container , $ config, $ request -> getParam ( ' server ' ) );
189190
190191 $ GLOBALS ['cfg ' ] = $ config ->settings ;
191192 $ settings = $ config ->getSettings ();
@@ -228,7 +229,8 @@ public static function run(bool $isSetupPage = false): void
228229 $ container ->set (DatabaseInterface::class, $ GLOBALS ['dbi ' ]);
229230 $ container ->setAlias ('dbi ' , DatabaseInterface::class);
230231
231- if (! empty ($ GLOBALS ['cfg ' ]['Server ' ])) {
232+ $ currentServer = $ config ->getCurrentServer ();
233+ if ($ currentServer !== null ) {
232234 $ config ->getLoginCookieValidityFromCache ($ GLOBALS ['server ' ]);
233235
234236 /** @var AuthenticationPluginFactory $authPluginFactory */
@@ -251,12 +253,12 @@ public static function run(bool $isSetupPage = false): void
251253 // phpcs:enable
252254 }
253255
254- self ::connectToDatabaseServer ($ GLOBALS ['dbi ' ], $ authPlugin );
256+ self ::connectToDatabaseServer ($ GLOBALS ['dbi ' ], $ authPlugin, $ currentServer );
255257 $ authPlugin ->rememberCredentials ();
256258 $ authPlugin ->checkTwoFactor ();
257259
258260 /* Log success */
259- Logging::logUser ($ config , $ GLOBALS [ ' cfg ' ][ ' Server ' ][ ' user ' ] );
261+ Logging::logUser ($ config , $ currentServer -> user );
260262
261263 if ($ GLOBALS ['dbi ' ]->getVersion () < $ settings ->mysqlMinVersion ['internal ' ]) {
262264 echo self ::getGenericError (sprintf (
@@ -549,14 +551,17 @@ private static function checkRequest(): void
549551 throw new RuntimeException (__ ('possible exploit ' ));
550552 }
551553
552- private static function connectToDatabaseServer (DatabaseInterface $ dbi , AuthenticationPlugin $ auth ): void
553- {
554+ private static function connectToDatabaseServer (
555+ DatabaseInterface $ dbi ,
556+ AuthenticationPlugin $ auth ,
557+ Server $ currentServer ,
558+ ): void {
554559 /**
555560 * Try to connect MySQL with the control user profile (will be used to get the privileges list for the current
556- * user but the true user link must be open after this one so it would be default one for all the scripts).
561+ * user but the true user link must be open after this one, so it would be default one for all the scripts).
557562 */
558563 $ controlConnection = null ;
559- if ($ GLOBALS [ ' cfg ' ][ ' Server ' ][ ' controluser ' ] !== '' ) {
564+ if ($ currentServer -> controluser !== '' ) {
560565 $ controlConnection = $ dbi ->connect (Connection::TYPE_CONTROL );
561566 }
562567
@@ -631,9 +636,12 @@ private static function setSQLQueryGlobalFromRequest(ContainerInterface $contain
631636 $ container ->setParameter ('sql_query ' , $ sqlQuery );
632637 }
633638
634- private static function setCurrentServerGlobal (ContainerInterface $ container , Config $ config ): void
635- {
636- $ server = $ config ->selectServer ();
639+ private static function setCurrentServerGlobal (
640+ ContainerInterface $ container ,
641+ Config $ config ,
642+ mixed $ serverParamFromRequest ,
643+ ): void {
644+ $ server = $ config ->selectServer ($ serverParamFromRequest );
637645 $ GLOBALS ['server ' ] = $ server ;
638646 $ GLOBALS ['urlParams ' ]['server ' ] = $ server ;
639647 $ container ->setParameter ('server ' , $ server );
0 commit comments