From bbadf0a1f801ad7d6c83521639ecea4ef8b0f232 Mon Sep 17 00:00:00 2001 From: Achilles-96 Date: Sun, 17 Jul 2016 17:44:17 +0530 Subject: [PATCH 01/34] Fixes #12378 - Support for IPv6 proxies Signed-off-by: Raghuram Vadapalli --- libraries/ip_allow_deny.lib.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php index 47ff7572c9..1dae2d4b7f 100644 --- a/libraries/ip_allow_deny.lib.php +++ b/libraries/ip_allow_deny.lib.php @@ -35,14 +35,11 @@ function PMA_getIp() $matches = array(); // the $ checks that the header contains only one IP address, // ?: makes sure the () don't capture - $is_ip = preg_match( - '|^(?:[0-9]{1,3}\.){3,3}[0-9]{1,3}$|', - $trusted_header_value, $matches - ); + $is_ip = (filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)); - if ($is_ip && (count($matches) == 1)) { + if ($is_ip) { // True IP behind a proxy - return $matches[0]; + return $trusted_header_value; } /* Return true IP */ From c310304712e010100265efcd54352aafd8623eba Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Wed, 27 Jul 2016 17:57:44 +0100 Subject: [PATCH 02/34] Restore Overhead column in Server > Databases > Enable Statistics. (Was removed in 582b02262bcda6edb10ffc6df1b67c47468bbe59) Signed-off-by: Pavel Rochnyack --- libraries/DatabaseInterface.php | 3 ++- .../controllers/server/ServerDatabasesController.php | 8 +++++--- .../classes/controllers/ServerDatabasesControllerTest.php | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 114132ee9c..b394b01b43 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -871,7 +871,8 @@ class DatabaseInterface SUM(t.INDEX_LENGTH) AS SCHEMA_INDEX_LENGTH, SUM(t.DATA_LENGTH + t.INDEX_LENGTH) AS SCHEMA_LENGTH, - SUM(t.DATA_FREE) AS SCHEMA_DATA_FREE'; + SUM(IF(t.ENGINE <> \'InnoDB\', t.DATA_FREE, 0)) + AS SCHEMA_DATA_FREE'; } $sql .= ' FROM `information_schema`.SCHEMATA s'; diff --git a/libraries/controllers/server/ServerDatabasesController.php b/libraries/controllers/server/ServerDatabasesController.php index a8e2a46f2c..29db80d5c8 100644 --- a/libraries/controllers/server/ServerDatabasesController.php +++ b/libraries/controllers/server/ServerDatabasesController.php @@ -357,9 +357,11 @@ class ServerDatabasesController extends Controller 'format' => 'byte', 'footer' => 0, ); - // At this point we were preparing the display of Overhead using DATA_FREE - // but its content does not represent the real overhead in the case - // of InnoDB + $column_order['SCHEMA_DATA_FREE'] = array( + 'disp_name' => __('Overhead'), + 'format' => 'byte', + 'footer' => 0, + ); return $column_order; } diff --git a/test/classes/controllers/ServerDatabasesControllerTest.php b/test/classes/controllers/ServerDatabasesControllerTest.php index 11b583067f..3c7984a3d0 100644 --- a/test/classes/controllers/ServerDatabasesControllerTest.php +++ b/test/classes/controllers/ServerDatabasesControllerTest.php @@ -311,6 +311,11 @@ class ServerDatabasesControllerTest extends PMATestCase 'disp_name' => __('Total'), 'format' => 'byte', 'footer' => 0 + ), + 'SCHEMA_DATA_FREE' => array( + 'disp_name' => __('Overhead'), + 'format' => 'byte', + 'footer' => 0 ) ), $method->invoke($ctrl) From 76f94e4228b8df44401607ae70366b6c541e5546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 28 Jul 2016 11:06:26 +0200 Subject: [PATCH 03/34] Add changelog entry for issue #12409 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-enable overhead on server databases view Signed-off-by: Michal Čihař --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 0e7592a305..55a40115a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ phpMyAdmin - ChangeLog - issue #12394 Create view should require a view name - issue #12391 Message with 'Change password successfully' displayed, but does not take effect - issue Tighten control on PHP sessions and session cookies +- issue #12409 Re-enable overhead on server databases view 4.6.3 (2016-06-23) - issue #12249 Fixed cookie path on Windows From b705dc5f6784dfec60fd788e9bdaa969668fb150 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Wed, 27 Jul 2016 19:54:49 +0100 Subject: [PATCH 04/34] Fix replication status output in Server > Databases Broken by 829a84b46e101cc5caa3a4252ea6f4453c49528d refactoring. Incorrectly fixed in c4710c3e1d20c95b6cf5081d02ac50eda86d2538 Signed-off-by: Pavel Rochnyack --- libraries/controllers/server/ServerDatabasesController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/controllers/server/ServerDatabasesController.php b/libraries/controllers/server/ServerDatabasesController.php index a8e2a46f2c..140c14fe17 100644 --- a/libraries/controllers/server/ServerDatabasesController.php +++ b/libraries/controllers/server/ServerDatabasesController.php @@ -482,9 +482,7 @@ class ServerDatabasesController extends Controller ); if (mb_strlen($key) > 0 - || (isset($replication_info[$type]['Do_DB'][0]) - && $replication_info[$type]['Do_DB'][0] == "" - && count($replication_info[$type]['Do_DB']) == 1) + || count($replication_info[$type]['Do_DB']) == 0 ) { // if ($key != null) did not work for index "0" $out = Util::getIcon( From c63b11d2bb0ec56671c3c12601f635ff8cb59871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 10:42:06 +0200 Subject: [PATCH 05/34] Fixed rendering of Original theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12414 Signed-off-by: Michal Čihař --- ChangeLog | 1 + themes/original/css/common.css.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 55a40115a3..77610c8c5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ phpMyAdmin - ChangeLog - issue #12391 Message with 'Change password successfully' displayed, but does not take effect - issue Tighten control on PHP sessions and session cookies - issue #12409 Re-enable overhead on server databases view +- issue #12414 Fixed rendering of Original theme 4.6.3 (2016-06-23) - issue #12249 Fixed cookie path on Windows diff --git a/themes/original/css/common.css.php b/themes/original/css/common.css.php index 42e7b48c1c..de8b70f647 100644 --- a/themes/original/css/common.css.php +++ b/themes/original/css/common.css.php @@ -418,6 +418,7 @@ div.error { margin: 0.3em 0 0 0; border: 2px solid; background-repeat: no-repeat; + clear: both; background-position: 10px 50%; @@ -878,7 +879,7 @@ div#tablestatistics table { #fieldset_add_user_login label { float: ; display: block; - width: 10em; + width: 15em; max-width: 100%; text-align: ; padding-: 0.5em; From 489970f218cdaf6ed81ad3843f5228f5dcf5ed97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 10:44:58 +0200 Subject: [PATCH 06/34] Fixed deleting users in non English locales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12413 Signed-off-by: Michal Čihař --- ChangeLog | 1 + server_privileges.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 77610c8c5b..e73754b13a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ phpMyAdmin - ChangeLog - issue Tighten control on PHP sessions and session cookies - issue #12409 Re-enable overhead on server databases view - issue #12414 Fixed rendering of Original theme +- issue #12413 Fixed deleting users in non English locales 4.6.3 (2016-06-23) - issue #12249 Fixed cookie path on Windows diff --git a/server_privileges.php b/server_privileges.php index c095f42a91..34dd8933b8 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -301,7 +301,7 @@ if ($GLOBALS['is_ajax_request'] && (! isset($_REQUEST['submit_mult']) || $_REQUEST['submit_mult'] != 'export') && ((! isset($_REQUEST['initial']) || $_REQUEST['initial'] === null || $_REQUEST['initial'] === '') - || (isset($_REQUEST['delete']) && $_REQUEST['delete'] === 'Go')) + || (isset($_REQUEST['delete']) && $_REQUEST['delete'] === __('Go'))) && ! isset($_REQUEST['showall']) && ! isset($_REQUEST['edit_user_group_dialog']) && ! isset($_REQUEST['db_specific']) From de1e473a9dfc50d2a7e71b618706c9e13a87f13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 10:47:15 +0200 Subject: [PATCH 07/34] Changelog entry for issue #12416 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index e73754b13a..7bd07d6347 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ phpMyAdmin - ChangeLog - issue #12409 Re-enable overhead on server databases view - issue #12414 Fixed rendering of Original theme - issue #12413 Fixed deleting users in non English locales +- issue #12416 Fixed replication status output in Databases listing 4.6.3 (2016-06-23) - issue #12249 Fixed cookie path on Windows From 314ec0a1f9eaf1a4dedc6c9801dc0479eecbd7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 10:49:19 +0200 Subject: [PATCH 08/34] Simplify IP address validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check IPv4 and IPv6 in one call - type strict checking of return value See issue #12389 Signed-off-by: Michal Čihař --- libraries/ip_allow_deny.lib.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php index 8d2fc11de4..120463307a 100644 --- a/libraries/ip_allow_deny.lib.php +++ b/libraries/ip_allow_deny.lib.php @@ -33,11 +33,10 @@ function PMA_getIp() $trusted_header_value = PMA_getenv($GLOBALS['cfg']['TrustedProxies'][$direct_ip]); $matches = array(); - // the $ checks that the header contains only one IP address, - // ?: makes sure the () don't capture - $is_ip = (filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || filter_var($trusted_header_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)); + // checks that the header contains only one IP address, + $is_ip = filter_var($trusted_header_value, FILTER_VALIDATE_IP); - if ($is_ip) { + if ($is_ip !== false) { // True IP behind a proxy return $trusted_header_value; } From 9588dbd4aaf7eb8c9558444ba52610a5a12e1aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 10:50:20 +0200 Subject: [PATCH 09/34] Add changelog entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12378 Fixes #12389 Signed-off-by: Michal Čihař --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 707506bc1f..d73a870d39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ phpMyAdmin - ChangeLog - issue #5555 Better report query errors while generating SQL exports - issue #12307 Produce valid JSON on export - issue #12325 Setup script icons broken +- issue #12378 Support IPv6 proxies 4.6.4 (not yet released) - issue Include X-Robots-Tag header in responses From bee2805b34f5d61a3e535478a62001db2524733e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:19:22 +0200 Subject: [PATCH 10/34] Remove auxiliary_connection flag from DBI backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They do not use it anyway. Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 2 +- libraries/dbi/DBIDummy.php | 5 +---- libraries/dbi/DBIExtension.php | 5 +---- libraries/dbi/DBIMysql.php | 5 +---- libraries/dbi/DBIMysqli.php | 5 +---- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index a740b338e7..d82f652094 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2222,7 +2222,7 @@ class DatabaseInterface ) { $error_count = $GLOBALS['error_handler']->countErrors(); $result = $this->_extension->connect( - $user, $password, $is_controluser, $server, $auxiliary_connection + $user, $password, $is_controluser, $server ); /* Any errors from connection? */ diff --git a/libraries/dbi/DBIDummy.php b/libraries/dbi/DBIDummy.php index e5f0db96f5..6641149cff 100644 --- a/libraries/dbi/DBIDummy.php +++ b/libraries/dbi/DBIDummy.php @@ -899,8 +899,6 @@ class DBIDummy implements DBIExtension * @param string $password mysql user password * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) * * @return mixed false on error or a mysqli object on success */ @@ -908,8 +906,7 @@ class DBIDummy implements DBIExtension $user, $password, $is_controluser = false, - $server = null, - $auxiliary_connection = false + $server = null ) { return true; } diff --git a/libraries/dbi/DBIExtension.php b/libraries/dbi/DBIExtension.php index eaa93caa64..e2b9761a2b 100644 --- a/libraries/dbi/DBIExtension.php +++ b/libraries/dbi/DBIExtension.php @@ -22,14 +22,11 @@ interface DBIExtension * @param string $password user password * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) * * @return mixed false on error or a connection object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null, - $auxiliary_connection = false + $user, $password, $is_controluser = false, $server = null ); /** diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index f44b9bfa27..1abac01553 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -96,14 +96,11 @@ class DBIMysql implements DBIExtension * @param string $password mysql user password * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) * * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null, - $auxiliary_connection = false + $user, $password, $is_controluser = false, $server = null ) { global $cfg; diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 0870726920..84f3c6c103 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -114,14 +114,11 @@ class DBIMysqli implements DBIExtension * @param string $password mysql user password * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) * * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null, - $auxiliary_connection = false + $user, $password, $is_controluser = false, $server = null ) { global $cfg; From 53f541af86dc0f020e36c43b4446943efc0cc675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:29:30 +0200 Subject: [PATCH 11/34] Removed MySQL connection retry without password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This really does not make sense for any decent setup. It is useful only with http authentication, but still no password is not something we would want to automatically fall back to. Signed-off-by: Michal Čihař --- ChangeLog | 1 + libraries/dbi/DBIMysql.php | 8 -------- libraries/dbi/DBIMysqli.php | 17 ----------------- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index d73a870d39..daeb1a1b2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ phpMyAdmin - ChangeLog - issue #12307 Produce valid JSON on export - issue #12325 Setup script icons broken - issue #12378 Support IPv6 proxies +- issue Removed MySQL connection retry without password 4.6.4 (not yet released) - issue Include X-Robots-Tag header in responses diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index 1abac01553..2f00b32d25 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -141,14 +141,6 @@ class DBIMysql implements DBIExtension $cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? null : $client_flags ); - - // Retry with empty password if we're allowed to - if (empty($link) && $cfg['Server']['nopassword'] && ! $is_controluser) { - $link = $this->_realConnect( - $cfg['Server']['host'] . $server_port . $server_socket, - $user, '', empty($client_flags) ? null : $client_flags - ); - } } else { if (!isset($server['host'])) { $link = $this->_realConnect($server_socket, $user, $password, null); diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 84f3c6c103..1e183afed8 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -183,23 +183,6 @@ class DBIMysqli implements DBIExtension $server_socket, $client_flags ); - // Retry with empty password if we're allowed to - if ($return_value == false - && isset($cfg['Server']['nopassword']) - && $cfg['Server']['nopassword'] - && ! $is_controluser - ) { - $return_value = $this->_realConnect( - $link, - $cfg['Server']['host'], - $user, - '', - false, - $server_port, - $server_socket, - $client_flags - ); - } } else { $return_value = $this->_realConnect( $link, From f46fd340812fc05e1c9358ca8e8d42932ab7c8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:34:55 +0200 Subject: [PATCH 12/34] Remove is_controluser flag from DBI backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They no longer need it (it was used only for empty password fallback). Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 2 +- libraries/dbi/DBIDummy.php | 2 -- libraries/dbi/DBIExtension.php | 3 +-- libraries/dbi/DBIMysql.php | 3 +-- libraries/dbi/DBIMysqli.php | 3 +-- test/classes/dbi/DBIMysqlTest.php | 8 ++------ test/classes/dbi/DBIMysqliTest.php | 5 +---- 7 files changed, 7 insertions(+), 19 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index d82f652094..43b9e63c01 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2222,7 +2222,7 @@ class DatabaseInterface ) { $error_count = $GLOBALS['error_handler']->countErrors(); $result = $this->_extension->connect( - $user, $password, $is_controluser, $server + $user, $password, $server ); /* Any errors from connection? */ diff --git a/libraries/dbi/DBIDummy.php b/libraries/dbi/DBIDummy.php index 6641149cff..1f1a60b6a2 100644 --- a/libraries/dbi/DBIDummy.php +++ b/libraries/dbi/DBIDummy.php @@ -897,7 +897,6 @@ class DBIDummy implements DBIExtension * * @param string $user mysql user name * @param string $password mysql user password - * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent * * @return mixed false on error or a mysqli object on success @@ -905,7 +904,6 @@ class DBIDummy implements DBIExtension public function connect( $user, $password, - $is_controluser = false, $server = null ) { return true; diff --git a/libraries/dbi/DBIExtension.php b/libraries/dbi/DBIExtension.php index e2b9761a2b..6d90479c97 100644 --- a/libraries/dbi/DBIExtension.php +++ b/libraries/dbi/DBIExtension.php @@ -20,13 +20,12 @@ interface DBIExtension * * @param string $user user name * @param string $password user password - * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent * * @return mixed false on error or a connection object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null + $user, $password, $server = null ); /** diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index 2f00b32d25..a725d59a5a 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -94,13 +94,12 @@ class DBIMysql implements DBIExtension * * @param string $user mysql user name * @param string $password mysql user password - * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent * * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null + $user, $password, $server = null ) { global $cfg; diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 1e183afed8..b17d4f5498 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -112,13 +112,12 @@ class DBIMysqli implements DBIExtension * * @param string $user mysql user name * @param string $password mysql user password - * @param bool $is_controluser whether this is a control user connection * @param array $server host/port/socket/persistent * * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $is_controluser = false, $server = null + $user, $password, $server = null ) { global $cfg; diff --git a/test/classes/dbi/DBIMysqlTest.php b/test/classes/dbi/DBIMysqlTest.php index 2a296e5b70..7ce3d16874 100644 --- a/test/classes/dbi/DBIMysqlTest.php +++ b/test/classes/dbi/DBIMysqlTest.php @@ -153,18 +153,15 @@ class DBIMysqlTest extends PMATestCase //test for connect $user = 'PMA_user'; $password = 'PMA_password'; - $is_controluser = false; $server = array( 'port' => 8080, 'socket' => 123, 'host' => 'locahost', ); - $auxiliary_connection = true; //test for connect $ret = $this->object->connect( - $user, $password, $is_controluser, - $server, $auxiliary_connection + $user, $password, $server ); $this->assertEquals( 'mysql_connect', @@ -173,8 +170,7 @@ class DBIMysqlTest extends PMATestCase $GLOBALS['cfg']['PersistentConnections'] = true; $ret = $this->object->connect( - $user, $password, $is_controluser, - $server, $auxiliary_connection + $user, $password, $server ); $this->assertEquals( 'mysql_pconnect', diff --git a/test/classes/dbi/DBIMysqliTest.php b/test/classes/dbi/DBIMysqliTest.php index 45f0152515..18fe4a4550 100644 --- a/test/classes/dbi/DBIMysqliTest.php +++ b/test/classes/dbi/DBIMysqliTest.php @@ -102,18 +102,15 @@ class DBIMysqliTest extends PMATestCase $user = 'PMA_user'; $password = 'PMA_password'; - $is_controluser = false; $server = array( 'port' => 8080, 'socket' => 123, 'host' => 'locahost', ); - $auxiliary_connection = true; //test for connect $ret = $this->object->connect( - $user, $password, $is_controluser, - $server, $auxiliary_connection + $user, $password, $server ); $this->assertEquals( 'mysqli_init', From f30f65c67a1f0a61da39f14c8d465bef7ea7d0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:36:07 +0200 Subject: [PATCH 13/34] Indentify connection type by one flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use integer values rather than set of boolean flags. This makes it easier to make decision and makes the code more readable. Also removes confusion what should happen in case both boolean flags are set. Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 45 ++++++++++++++++++++------------- libraries/common.inc.php | 8 +++--- libraries/replication.inc.php | 2 +- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 43b9e63c01..dbd7247d73 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -38,6 +38,21 @@ class DatabaseInterface */ const GETVAR_GLOBAL = 2; + /** + * User connection. + */ + const CONNECT_USER = 0x100; + /** + * Control user connection. + */ + const CONNECT_CONTROL = 0x101; + /** + * Auxiliary connection. + * + * Used for example for replication setup. + */ + const CONNECT_AUXILIARY = 0x102; + /** * @var DBIExtension */ @@ -2207,19 +2222,16 @@ class DatabaseInterface /** * connects to the database server * - * @param string $user user name - * @param string $password user password - * @param bool $is_controluser whether this is a control user connection - * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) + * @param string $user user name + * @param string $password user password + * @param integer $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL + * or CONNECT_AUXILIARY. + * @param array $server Server information like host/port/socket/persistent * * @return mixed false on error or a connection object on success */ - public function connect( - $user, $password, $is_controluser = false, $server = null, - $auxiliary_connection = false - ) { + public function connect($user, $password, $mode, $server = null) { + $error_count = $GLOBALS['error_handler']->countErrors(); $result = $this->_extension->connect( $user, $password, $server @@ -2237,13 +2249,14 @@ class DatabaseInterface } if ($result) { - if (! $auxiliary_connection && ! $is_controluser) { + /* Run post connect for user connections */ + if ($mode == DatabaseInterface::CONNECT_USER) { $this->postConnect($result); } return $result; } - if ($is_controluser) { + if ($mode == DatabaseInterface::CONNECT_CONTROL) { trigger_error( __( 'Connection for controluser as defined in your ' @@ -2252,11 +2265,9 @@ class DatabaseInterface E_USER_WARNING ); return false; - } - - // Do not go back to main login if connection failed - // (currently used only in unit testing) - if ($auxiliary_connection) { + } else if ($mode == DatabaseInterface::CONNECT_AUXILIARY) { + // Do not go back to main login if connection failed + // (currently used only in unit testing) return false; } diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 451128df21..b4537bea9a 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -777,14 +777,14 @@ if (! defined('PMA_MINIMUM_COMMON')) { $controllink = $GLOBALS['dbi']->connect( $cfg['Server']['controluser'], $cfg['Server']['controlpass'], - true, + DatabaseInterface::CONNECT_CONTROL, $server_details ); } else { $controllink = $GLOBALS['dbi']->connect( $cfg['Server']['controluser'], $cfg['Server']['controlpass'], - true + DatabaseInterface::CONNECT_CONTROL ); } } @@ -792,7 +792,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { // Connects to the server (validates user's login) /** @var DatabaseInterface $userlink */ $userlink = $GLOBALS['dbi']->connect( - $cfg['Server']['user'], $cfg['Server']['password'], false + $cfg['Server']['user'], $cfg['Server']['password'], DatabaseInterface::CONNECT_USER ); // Set timestamp for the session, if required. @@ -834,7 +834,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { * is not locked by that time. */ $controllink = $GLOBALS['dbi']->connect( - $cfg['Server']['user'], $cfg['Server']['password'], false + $cfg['Server']['user'], $cfg['Server']['password'], DatabaseInterface::CONNECT_USER ); } diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index f4a4cd4aa4..c92c42f3dd 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -299,7 +299,7 @@ function PMA_Replication_connectToMaster( // 5th parameter set to true means that it's an auxiliary connection // and we must not go back to login page if it fails - return $GLOBALS['dbi']->connect($user, $password, false, $server, true); + return $GLOBALS['dbi']->connect($user, $password, DatabaseInterface::CONNECT_AUXILIARY, $server); } /** * Fetches position and file of current binary log on master From 25a38b206760276c9c0e185692f124a51dceec8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:51:09 +0200 Subject: [PATCH 14/34] Determine correct user/password for connect in DatabaseInterface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API only specifies what kind of link we want and we will get it. Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 30 +++++++++++++++++++++++++++--- libraries/common.inc.php | 12 ++---------- libraries/replication.inc.php | 4 +++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index dbd7247d73..ab942a783d 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2222,15 +2222,39 @@ class DatabaseInterface /** * connects to the database server * - * @param string $user user name - * @param string $password user password * @param integer $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL * or CONNECT_AUXILIARY. * @param array $server Server information like host/port/socket/persistent * * @return mixed false on error or a connection object on success */ - public function connect($user, $password, $mode, $server = null) { + public function connect($mode, $server = null) { + global $cfg; + + $user = null; + $password = null; + + if ($mode == DatabaseInterface::CONNECT_USER) { + $user = $cfg['Server']['user']; + $password = $cfg['Server']['password']; + } elseif ($mode == DatabaseInterface::CONNECT_CONTROL) { + $user = $cfg['Server']['controluser']; + $user = $cfg['Server']['controlpass']; + } else { + if (isset($server['user'])) { + $user = $server['user']; + } + if (isset($server['password'])) { + $password = $server['password']; + } + } + if (is_null($user) || is_null($password)) { + trigger_error( + __('Missing connection parameters!'), + E_USER_WARNING + ); + return false; + } $error_count = $GLOBALS['error_handler']->countErrors(); $result = $this->_extension->connect( diff --git a/libraries/common.inc.php b/libraries/common.inc.php index b4537bea9a..c9aa3f5c84 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -775,15 +775,11 @@ if (! defined('PMA_MINIMUM_COMMON')) { // allowing it to take default mysql port $controllink = $GLOBALS['dbi']->connect( - $cfg['Server']['controluser'], - $cfg['Server']['controlpass'], DatabaseInterface::CONNECT_CONTROL, $server_details ); } else { $controllink = $GLOBALS['dbi']->connect( - $cfg['Server']['controluser'], - $cfg['Server']['controlpass'], DatabaseInterface::CONNECT_CONTROL ); } @@ -791,9 +787,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { // Connects to the server (validates user's login) /** @var DatabaseInterface $userlink */ - $userlink = $GLOBALS['dbi']->connect( - $cfg['Server']['user'], $cfg['Server']['password'], DatabaseInterface::CONNECT_USER - ); + $userlink = $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_USER); // Set timestamp for the session, if required. if ($cfg['Server']['SessionTimeZone'] != '') { @@ -833,9 +827,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { * and phpMyAdmin issuing queries to configuration storage, which * is not locked by that time. */ - $controllink = $GLOBALS['dbi']->connect( - $cfg['Server']['user'], $cfg['Server']['password'], DatabaseInterface::CONNECT_USER - ); + $controllink = $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_USER); } $auth_plugin->storeUserCredentials(); diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index c92c42f3dd..b34f520122 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -293,13 +293,15 @@ function PMA_Replication_connectToMaster( $user, $password, $host = null, $port = null, $socket = null ) { $server = array(); + $server['user'] = $user; + $server['password'] = $password; $server["host"] = $host; $server["port"] = $port; $server["socket"] = $socket; // 5th parameter set to true means that it's an auxiliary connection // and we must not go back to login page if it fails - return $GLOBALS['dbi']->connect($user, $password, DatabaseInterface::CONNECT_AUXILIARY, $server); + return $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_AUXILIARY, $server); } /** * Fetches position and file of current binary log on master From 2dce03394338bc85654d97611c02c79a5f9dc8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:53:49 +0200 Subject: [PATCH 15/34] Move configuration management in DBI to separate method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index ab942a783d..c8bdb0f14c 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2219,16 +2219,8 @@ class DatabaseInterface || $schema_name == 'sys'; } - /** - * connects to the database server - * - * @param integer $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL - * or CONNECT_AUXILIARY. - * @param array $server Server information like host/port/socket/persistent - * - * @return mixed false on error or a connection object on success - */ - public function connect($mode, $server = null) { + public function getConnectionParams($mode, $server = null) + { global $cfg; $user = null; @@ -2239,7 +2231,7 @@ class DatabaseInterface $password = $cfg['Server']['password']; } elseif ($mode == DatabaseInterface::CONNECT_CONTROL) { $user = $cfg['Server']['controluser']; - $user = $cfg['Server']['controlpass']; + $password = $cfg['Server']['controlpass']; } else { if (isset($server['user'])) { $user = $server['user']; @@ -2248,6 +2240,23 @@ class DatabaseInterface $password = $server['password']; } } + + return array($user, $password, $server); + } + + /** + * connects to the database server + * + * @param integer $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL + * or CONNECT_AUXILIARY. + * @param array $server Server information like host/port/socket/persistent + * + * @return mixed false on error or a connection object on success + */ + public function connect($mode, $server = null) + { + list($user, $password, $server) = $this->getConnectionParams($mode, $server); + if (is_null($user) || is_null($password)) { trigger_error( __('Missing connection parameters!'), From 95064ed9fbf77e4f43ac438591d03998c6bb38c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 11:58:02 +0200 Subject: [PATCH 16/34] Move control user connection calculation to DatabaseInterface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 21 +++++++++++++++++++++ libraries/common.inc.php | 32 +++----------------------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index c8bdb0f14c..ebd068859d 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2232,6 +2232,27 @@ class DatabaseInterface } elseif ($mode == DatabaseInterface::CONNECT_CONTROL) { $user = $cfg['Server']['controluser']; $password = $cfg['Server']['controlpass']; + + $server = array(); + if (! empty($cfg['Server']['controlhost']) + || ! empty($cfg['Server']['controlport']) + ) { + if (! empty($cfg['Server']['controlhost'])) { + $server['host'] = $cfg['Server']['controlhost']; + } else { + $server['host'] = $cfg['Server']['host']; + } + if (! empty($cfg['Server']['controlport'])) { + $server['port'] = $cfg['Server']['controlport']; + } elseif ($server['host'] == $cfg['Server']['host']) { + // Evaluates to true when controlhost == host + // or controlhost is not defined (hence it defaults to host) + // In such case we can use the value of port. + $server['port'] = $cfg['Server']['port']; + } + // otherwise we leave the $server['port'] unset, + // allowing it to take default mysql port + } } else { if (isset($server['user'])) { $user = $server['user']; diff --git a/libraries/common.inc.php b/libraries/common.inc.php index c9aa3f5c84..51dc538316 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -754,35 +754,9 @@ if (! defined('PMA_MINIMUM_COMMON')) { // scripts) $controllink = false; if ($cfg['Server']['controluser'] != '') { - if (! empty($cfg['Server']['controlhost']) - || ! empty($cfg['Server']['controlport']) - ) { - $server_details = array(); - if (! empty($cfg['Server']['controlhost'])) { - $server_details['host'] = $cfg['Server']['controlhost']; - } else { - $server_details['host'] = $cfg['Server']['host']; - } - if (! empty($cfg['Server']['controlport'])) { - $server_details['port'] = $cfg['Server']['controlport']; - } elseif ($server_details['host'] == $cfg['Server']['host']) { - // Evaluates to true when controlhost == host - // or controlhost is not defined (hence it defaults to host) - // In such case we can use the value of port. - $server_details['port'] = $cfg['Server']['port']; - } - // otherwise we leave the $server_details['port'] unset, - // allowing it to take default mysql port - - $controllink = $GLOBALS['dbi']->connect( - DatabaseInterface::CONNECT_CONTROL, - $server_details - ); - } else { - $controllink = $GLOBALS['dbi']->connect( - DatabaseInterface::CONNECT_CONTROL - ); - } + $controllink = $GLOBALS['dbi']->connect( + DatabaseInterface::CONNECT_CONTROL + ); } // Connects to the server (validates user's login) From 6fd55f968aee6543b41a9889eb8eef68eb3e3043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:04:25 +0200 Subject: [PATCH 17/34] Pass user link parameter in server array as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index ebd068859d..10eaf0bb30 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2229,6 +2229,7 @@ class DatabaseInterface if ($mode == DatabaseInterface::CONNECT_USER) { $user = $cfg['Server']['user']; $password = $cfg['Server']['password']; + $server = $cfg['Server']; } elseif ($mode == DatabaseInterface::CONNECT_CONTROL) { $user = $cfg['Server']['controluser']; $password = $cfg['Server']['controlpass']; From 9592f66bd539437a89f0ab512eb2b33cfcf501b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:09:26 +0200 Subject: [PATCH 18/34] Share socket/port/host sanitization in DatabaseInterface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 49 +++++++++------------------------ libraries/dbi/DBIMysql.php | 11 +++----- libraries/dbi/DBIMysqli.php | 11 +++----- 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 10eaf0bb30..4aef3772b5 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2263,6 +2263,19 @@ class DatabaseInterface } } + // Perform sanity checks on host, socket and port + if (empty($server['port'])) { + $server['port'] = intval($server['port']); + } else { + $server['port'] = ''; + } + if (empty($server['socket'])) { + $server['socket'] = null; + } + if (empty($server['host'])) { + $server['host'] = 'localhost'; + } + return array($user, $password, $server); } @@ -2635,42 +2648,6 @@ class DatabaseInterface return $this->_extension->fieldFlags($result, $i); } - /** - * Gets server connection port - * - * @param array|null $server host/port/socket/persistent - * - * @return int - */ - public function getServerPort($server = null) - { - if (is_null($server)) { - $server = &$GLOBALS['cfg']['Server']; - } - - return intval($server['port']); - } - - /** - * Gets server connection socket - * - * @param array|null $server host/port/socket/persistent - * - * @return null|string - */ - public function getServerSocket($server = null) - { - if (is_null($server)) { - $server = &$GLOBALS['cfg']['Server']; - } - - if (empty($server['socket'])) { - return null; - } else { - return $server['socket']; - } - } - /** * Gets correct link object. * diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index a725d59a5a..bff3123610 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -103,19 +103,16 @@ class DBIMysql implements DBIExtension ) { global $cfg; - $server_port = $GLOBALS['dbi']->getServerPort($server); - $server_socket = $GLOBALS['dbi']->getServerSocket($server); - - if ($server_port === 0) { + if ($server['port'] === 0) { $server_port = ''; } else { - $server_port = ':' . $server_port; + $server_port = ':' . $server['port']; } - if (is_null($server_socket)) { + if (is_null($server['socket'])) { $server_socket = ''; } else { - $server_socket = ':' . $server_socket; + $server_socket = ':' . $server['socket']; } $client_flags = 0; diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index b17d4f5498..0e6d2da7b3 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -121,9 +121,6 @@ class DBIMysqli implements DBIExtension ) { global $cfg; - $server_port = $GLOBALS['dbi']->getServerPort($server); - $server_socket = $GLOBALS['dbi']->getServerSocket($server); - if ($server) { $server['host'] = (empty($server['host'])) ? 'localhost' @@ -178,8 +175,8 @@ class DBIMysqli implements DBIExtension $user, $password, false, - $server_port, - $server_socket, + $server['port'], + $server['socket'], $client_flags ); } else { @@ -189,8 +186,8 @@ class DBIMysqli implements DBIExtension $user, $password, false, - $server_port, - $server_socket + $server['port'], + $server['socket'] ); } From 061c62072394ce5d81c83af947c3c9ecdafa5f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:19:40 +0200 Subject: [PATCH 19/34] Generate connection settings at one place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 21 ++++++++++++++------- libraries/dbi/DBIMysql.php | 8 +++----- libraries/dbi/DBIMysqli.php | 24 +++++++++++------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 4aef3772b5..fe21a05714 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2243,16 +2243,23 @@ class DatabaseInterface } else { $server['host'] = $cfg['Server']['host']; } + // Share the settings if the host is same + if ($server['host'] == $cfg['Server']['host']) { + $shared = array( + 'port', 'socket', 'connect_type', 'compress', + 'ssl', 'ssl_key', 'ssl_cert', 'ssl_ca', + 'ssl_ca_path', 'ssl_ciphers', 'ssl_verify', + ); + foreach ($shared as $item) { + if (! empty($cfg['Server'][$item])) { + $server[$item] = $cfg['Server'][$item]; + } + } + } + // Set configured port if (! empty($cfg['Server']['controlport'])) { $server['port'] = $cfg['Server']['controlport']; - } elseif ($server['host'] == $cfg['Server']['host']) { - // Evaluates to true when controlhost == host - // or controlhost is not defined (hence it defaults to host) - // In such case we can use the value of port. - $server['port'] = $cfg['Server']['port']; } - // otherwise we leave the $server['port'] unset, - // allowing it to take default mysql port } } else { if (isset($server['user'])) { diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index bff3123610..511fd3b38d 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -101,8 +101,6 @@ class DBIMysql implements DBIExtension public function connect( $user, $password, $server = null ) { - global $cfg; - if ($server['port'] === 0) { $server_port = ''; } else { @@ -123,18 +121,18 @@ class DBIMysql implements DBIExtension $client_flags |= 128; /* Optionally compress connection */ - if (defined('MYSQL_CLIENT_COMPRESS') && $cfg['Server']['compress']) { + if (defined('MYSQL_CLIENT_COMPRESS') && $server['compress']) { $client_flags |= MYSQL_CLIENT_COMPRESS; } /* Optionally enable SSL */ - if (defined('MYSQL_CLIENT_SSL') && $cfg['Server']['ssl']) { + if (defined('MYSQL_CLIENT_SSL') && $server['ssl']) { $client_flags |= MYSQL_CLIENT_SSL; } if (! $server) { $link = $this->_realConnect( - $cfg['Server']['host'] . $server_port . $server_socket, + $server['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? null : $client_flags ); } else { diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 0e6d2da7b3..6eb934c0b5 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -119,8 +119,6 @@ class DBIMysqli implements DBIExtension public function connect( $user, $password, $server = null ) { - global $cfg; - if ($server) { $server['host'] = (empty($server['host'])) ? 'localhost' @@ -136,21 +134,21 @@ class DBIMysqli implements DBIExtension $client_flags = 0; /* Optionally compress connection */ - if ($cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { + if ($server['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { $client_flags |= MYSQLI_CLIENT_COMPRESS; } /* Optionally enable SSL */ - if ($cfg['Server']['ssl']) { + if ($server['ssl']) { $client_flags |= MYSQLI_CLIENT_SSL; - if (!empty($cfg['Server']['ssl_key'])) { + if (!empty($server['ssl_key'])) { mysqli_ssl_set( $link, - $cfg['Server']['ssl_key'], - $cfg['Server']['ssl_cert'], - $cfg['Server']['ssl_ca'], - $cfg['Server']['ssl_ca_path'], - $cfg['Server']['ssl_ciphers'] + $server['ssl_key'], + $server['ssl_cert'], + $server['ssl_ca'], + $server['ssl_ca_path'], + $server['ssl_ciphers'] ); } /* @@ -158,11 +156,11 @@ class DBIMysqli implements DBIExtension * @link https://bugs.php.net/bug.php?id=68344 * @link https://github.com/phpmyadmin/phpmyadmin/pull/11838 */ - if (! $cfg['Server']['ssl_verify']) { + if (! $server['ssl_verify']) { mysqli_options( $link, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, - $cfg['Server']['ssl_verify'] + $server['ssl_verify'] ); $client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; } @@ -171,7 +169,7 @@ class DBIMysqli implements DBIExtension if (! $server) { $return_value = $this->_realConnect( $link, - $cfg['Server']['host'], + $server['host'], $user, $password, false, From f2e179b750d09dc0ace990d8da79b79380881392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:21:06 +0200 Subject: [PATCH 20/34] Simplify DBI code as $server no longer can be null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/dbi/DBIExtension.php | 2 +- libraries/dbi/DBIMysql.php | 17 +++++------------ libraries/dbi/DBIMysqli.php | 33 ++++++++++----------------------- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/libraries/dbi/DBIExtension.php b/libraries/dbi/DBIExtension.php index 6d90479c97..f871c65b67 100644 --- a/libraries/dbi/DBIExtension.php +++ b/libraries/dbi/DBIExtension.php @@ -25,7 +25,7 @@ interface DBIExtension * @return mixed false on error or a connection object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ); /** diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index 511fd3b38d..0546ab9d49 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -99,7 +99,7 @@ class DBIMysql implements DBIExtension * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ) { if ($server['port'] === 0) { $server_port = ''; @@ -130,20 +130,13 @@ class DBIMysql implements DBIExtension $client_flags |= MYSQL_CLIENT_SSL; } - if (! $server) { + if (!isset($server['host'])) { + $link = $this->_realConnect($server_socket, $user, $password, null); + } else { $link = $this->_realConnect( $server['host'] . $server_port . $server_socket, - $user, $password, empty($client_flags) ? null : $client_flags + $user, $password, null ); - } else { - if (!isset($server['host'])) { - $link = $this->_realConnect($server_socket, $user, $password, null); - } else { - $link = $this->_realConnect( - $server['host'] . $server_port . $server_socket, - $user, $password, null - ); - } } return $link; } diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 6eb934c0b5..485b649a76 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -117,7 +117,7 @@ class DBIMysqli implements DBIExtension * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ) { if ($server) { $server['host'] = (empty($server['host'])) @@ -166,28 +166,15 @@ class DBIMysqli implements DBIExtension } } - if (! $server) { - $return_value = $this->_realConnect( - $link, - $server['host'], - $user, - $password, - false, - $server['port'], - $server['socket'], - $client_flags - ); - } else { - $return_value = $this->_realConnect( - $link, - $server['host'], - $user, - $password, - false, - $server['port'], - $server['socket'] - ); - } + $return_value = $this->_realConnect( + $link, + $server['host'], + $user, + $password, + false, + $server['port'], + $server['socket'] + ); if ($return_value === false || is_null($return_value)) { return false; From 94ff41a97fe2f8ef5a679b4fcc7c74ec672a1195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:22:01 +0200 Subject: [PATCH 21/34] Add safety check for invalid method call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index fe21a05714..8eb6c8a2fb 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2262,6 +2262,9 @@ class DatabaseInterface } } } else { + if (is_null($server)) { + return array(null, null, null); + } if (isset($server['user'])) { $user = $server['user']; } From 8a41fd3f63f04752f522430b7a1aafa40cf00042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:24:28 +0200 Subject: [PATCH 22/34] Fix fallback value for MySQL port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 8eb6c8a2fb..7297db25bb 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2275,9 +2275,9 @@ class DatabaseInterface // Perform sanity checks on host, socket and port if (empty($server['port'])) { - $server['port'] = intval($server['port']); + $server['port'] = 0; } else { - $server['port'] = ''; + $server['port'] = intval($server['port']); } if (empty($server['socket'])) { $server['socket'] = null; From 0fdc46eb5559d442eb933a045bb92fe730218c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:24:39 +0200 Subject: [PATCH 23/34] Always set default connection params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 7297db25bb..90f9af6780 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2251,7 +2251,7 @@ class DatabaseInterface 'ssl_ca_path', 'ssl_ciphers', 'ssl_verify', ); foreach ($shared as $item) { - if (! empty($cfg['Server'][$item])) { + if (isset($cfg['Server'][$item])) { $server[$item] = $cfg['Server'][$item]; } } From a36367bafb7b1d09c62f9a584feedc448a0b83f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:27:06 +0200 Subject: [PATCH 24/34] Always provide default for ssl and compress settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 90f9af6780..e11fbb8f41 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2273,7 +2273,7 @@ class DatabaseInterface } } - // Perform sanity checks on host, socket and port + // Perform sanity checks on some variables if (empty($server['port'])) { $server['port'] = 0; } else { @@ -2285,6 +2285,12 @@ class DatabaseInterface if (empty($server['host'])) { $server['host'] = 'localhost'; } + if (!isset($server['ssl'])) { + $server['ssl'] = false; + } + if (!isset($server['compress'])) { + $server['compress'] = false; + } return array($user, $password, $server); } From d6e85cc48d7c6ec6666782bfd3efe100645a45d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:29:47 +0200 Subject: [PATCH 25/34] Remove wrong parts of the docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- doc/config.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 150a5a1817..3cc5b2fb67 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -462,15 +462,11 @@ Server connection settings :type: string :default: ``''`` - This special account is used to access :ref:`linked-tables`. - You don't need it in single user case, but if phpMyAdmin is shared it - is recommended to give access to :ref:`linked-tables` only to this user - and configure phpMyAdmin to use it. All users will then be able to use - the features without need to have direct access to :ref:`linked-tables`. - - (see - - You can use + This special account is used to access :ref:`linked-tables`. + You don't need it in single user case, but if phpMyAdmin is shared it + is recommended to give access to :ref:`linked-tables` only to this user + and configure phpMyAdmin to use it. All users will then be able to use + the features without need to have direct access to :ref:`linked-tables`. .. versionchanged:: 2.2.5 those were called ``stduser`` and ``stdpass`` From 90498afe7671a088c64d304ed7cc59f95c2e060a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:38:03 +0200 Subject: [PATCH 26/34] Allow to specify further parameters for control connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12218 Signed-off-by: Michal Čihař --- ChangeLog | 1 + doc/config.rst | 48 ++++++++++++++++++++++++++++++++- libraries/DatabaseInterface.php | 6 +++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index daeb1a1b2b..da29baacb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ phpMyAdmin - ChangeLog - issue #12325 Setup script icons broken - issue #12378 Support IPv6 proxies - issue Removed MySQL connection retry without password +- issue #12218 Allow to specify further parameters for control connection 4.6.4 (not yet released) - issue Include X-Robots-Tag header in responses diff --git a/doc/config.rst b/doc/config.rst index 3cc5b2fb67..6707144308 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -442,6 +442,10 @@ Server connection settings Permits to use an alternate host to hold the configuration storage data. + .. seealso:: + + :config:option:`$cfg['Servers'][$i]['control_*']` + .. _controlport: .. config:option:: $cfg['Servers'][$i]['controlport'] @@ -451,6 +455,10 @@ Server connection settings Permits to use an alternate port to connect to the host that holds the configuration storage. + .. seealso:: + + :config:option:`$cfg['Servers'][$i]['control_*']` + .. _controluser: .. config:option:: $cfg['Servers'][$i]['controluser'] @@ -476,7 +484,45 @@ Server connection settings :ref:`setup`, :ref:`authentication_modes`, :ref:`linked-tables`, - :config:option:`$cfg['Servers'][$i]['pmadb']` + :config:option:`$cfg['Servers'][$i]['pmadb']`, + :config:option:`$cfg['Servers'][$i]['controlhost']`, + :config:option:`$cfg['Servers'][$i]['controlport']`, + :config:option:`$cfg['Servers'][$i]['control_*']` + +.. config:option:: $cfg['Servers'][$i]['control_*'] + + :type: mixed + + .. versionadded:: 4.7.0 + + You can change any MySQL connection setting for control link (used to + access :ref:`linked-tables`) using configuration prefixed with ``control_``. + + This can be used to change any aspect of the control connection, which by + default uses same parameters as the user one. + + For example you can configure SSL for the control connection: + + .. code-block:: php + + // Enable SSL + $cfg['Servers'][$i]['control_ssl'] = true; + // Client secret key + $cfg['Servers'][$i]['control_ssl_key'] = '../client-key.pem'; + // Client certificate + $cfg['Servers'][$i]['control_ssl_cert'] = '../client-cert.pem'; + // Server certification authority + $cfg['Servers'][$i]['control_ssl_ca'] = '../server-ca.pem'; + + .. seealso:: + + :config:option:`$cfg['Servers'][$i]['ssl']`, + :config:option:`$cfg['Servers'][$i]['ssl_key']`, + :config:option:`$cfg['Servers'][$i]['ssl_cert']`, + :config:option:`$cfg['Servers'][$i]['ssl_ca']`, + :config:option:`$cfg['Servers'][$i]['ssl_ca_path']`, + :config:option:`$cfg['Servers'][$i]['ssl_ciphers']`, + :config:option:`$cfg['Servers'][$i]['ssl_verify']` .. config:option:: $cfg['Servers'][$i]['auth_type'] diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index e11fbb8f41..3bf03bb09d 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2260,6 +2260,12 @@ class DatabaseInterface if (! empty($cfg['Server']['controlport'])) { $server['port'] = $cfg['Server']['controlport']; } + // Set any configuration with control_ prefix + foreach ($cfg['Server'] as $key => $val) { + if (substr($key, 0, 8) === 'control_') { + $server[substr($key, 8)] = $val; + } + } } } else { if (is_null($server)) { From 6b6040acbf982f91d3af90b5c6133090729e1829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:40:45 +0200 Subject: [PATCH 27/34] Adjust tests to new parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/dbi/DBIMysqlTest.php | 2 ++ test/classes/dbi/DBIMysqliTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/classes/dbi/DBIMysqlTest.php b/test/classes/dbi/DBIMysqlTest.php index 7ce3d16874..595b99842a 100644 --- a/test/classes/dbi/DBIMysqlTest.php +++ b/test/classes/dbi/DBIMysqlTest.php @@ -157,6 +157,8 @@ class DBIMysqlTest extends PMATestCase 'port' => 8080, 'socket' => 123, 'host' => 'locahost', + 'compress' => false, + 'ssl' => false, ); //test for connect diff --git a/test/classes/dbi/DBIMysqliTest.php b/test/classes/dbi/DBIMysqliTest.php index 18fe4a4550..b23db1e980 100644 --- a/test/classes/dbi/DBIMysqliTest.php +++ b/test/classes/dbi/DBIMysqliTest.php @@ -106,6 +106,8 @@ class DBIMysqliTest extends PMATestCase 'port' => 8080, 'socket' => 123, 'host' => 'locahost', + 'compress' => false, + 'ssl' => false, ); //test for connect From 9d0c745aa528923b59a50a58f9b453728de2845c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:48:57 +0200 Subject: [PATCH 28/34] Add missing documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 3bf03bb09d..900b863a95 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2219,6 +2219,15 @@ class DatabaseInterface || $schema_name == 'sys'; } + /** + * Return connection parameters for the database server + * + * @param integer $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL + * or CONNECT_AUXILIARY. + * @param array $server Server information like host/port/socket/persistent + * + * @return array user, host and server settings array + */ public function getConnectionParams($mode, $server = null) { global $cfg; From 4054228e1b97da9e802b3381c2911089e764e7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 13:25:29 +0200 Subject: [PATCH 29/34] Always merge control user configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #12218 Signed-off-by: Michal Čihař --- libraries/DatabaseInterface.php | 53 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 900b863a95..7e5302976d 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -2244,36 +2244,33 @@ class DatabaseInterface $password = $cfg['Server']['controlpass']; $server = array(); - if (! empty($cfg['Server']['controlhost']) - || ! empty($cfg['Server']['controlport']) - ) { - if (! empty($cfg['Server']['controlhost'])) { - $server['host'] = $cfg['Server']['controlhost']; - } else { - $server['host'] = $cfg['Server']['host']; - } - // Share the settings if the host is same - if ($server['host'] == $cfg['Server']['host']) { - $shared = array( - 'port', 'socket', 'connect_type', 'compress', - 'ssl', 'ssl_key', 'ssl_cert', 'ssl_ca', - 'ssl_ca_path', 'ssl_ciphers', 'ssl_verify', - ); - foreach ($shared as $item) { - if (isset($cfg['Server'][$item])) { - $server[$item] = $cfg['Server'][$item]; - } + + if (! empty($cfg['Server']['controlhost'])) { + $server['host'] = $cfg['Server']['controlhost']; + } else { + $server['host'] = $cfg['Server']['host']; + } + // Share the settings if the host is same + if ($server['host'] == $cfg['Server']['host']) { + $shared = array( + 'port', 'socket', 'connect_type', 'compress', + 'ssl', 'ssl_key', 'ssl_cert', 'ssl_ca', + 'ssl_ca_path', 'ssl_ciphers', 'ssl_verify', + ); + foreach ($shared as $item) { + if (isset($cfg['Server'][$item])) { + $server[$item] = $cfg['Server'][$item]; } } - // Set configured port - if (! empty($cfg['Server']['controlport'])) { - $server['port'] = $cfg['Server']['controlport']; - } - // Set any configuration with control_ prefix - foreach ($cfg['Server'] as $key => $val) { - if (substr($key, 0, 8) === 'control_') { - $server[substr($key, 8)] = $val; - } + } + // Set configured port + if (! empty($cfg['Server']['controlport'])) { + $server['port'] = $cfg['Server']['controlport']; + } + // Set any configuration with control_ prefix + foreach ($cfg['Server'] as $key => $val) { + if (substr($key, 0, 8) === 'control_') { + $server[substr($key, 8)] = $val; } } } else { From 43cfaeeade02308994a4bfcb0a09edb7acb5ac17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 13:25:58 +0200 Subject: [PATCH 30/34] Add tests for control user connection fallbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #12218 Signed-off-by: Michal Čihař --- test/classes/DatabaseInterfaceTest.php | 166 +++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/test/classes/DatabaseInterfaceTest.php b/test/classes/DatabaseInterfaceTest.php index c7d701fe76..3339ad15ce 100644 --- a/test/classes/DatabaseInterfaceTest.php +++ b/test/classes/DatabaseInterfaceTest.php @@ -6,6 +6,8 @@ * @package PhpMyAdmin-test */ +use PMA\libraries\DatabaseInterface; + require_once 'test/PMATestCase.php'; /** @@ -140,6 +142,170 @@ class DatabaseInterfaceTest extends PMATestCase $GLOBALS['cfg']['DBG']['sql'] = true; $this->assertEquals('utf8_general_ci', $this->_dbi->getServerCollation()); } + + /** + * Test for getConnectionParams + * + * @param array $server_cfg Server configuration + * @param integer $mode Mode to test + * @param array|null $server Server array to test + * @param array $expected Expected result + * + * @return void + * + * @dataProvider connectionParams + */ + public function testGetConnectionParams($server_cfg, $mode, $server, $expected) + { + $GLOBALS['cfg']['Server'] = $server_cfg; + $result = $this->_dbi->getConnectionParams($mode, $server); + $this->assertEquals($expected, $result); + } + + /** + * Data provider for getConnectionParams test + * + * @return array + */ + public function connectionParams() + { + $cfg_basic = array( + 'user' => 'u', + 'password' => 'pass', + 'host' => '', + 'controluser' => 'u2', + 'controlpass' => 'p2', + ); + $cfg_ssl = array( + 'user' => 'u', + 'password' => 'pass', + 'host' => '', + 'ssl' => true, + 'controluser' => 'u2', + 'controlpass' => 'p2', + ); + $cfg_control_ssl = array( + 'user' => 'u', + 'password' => 'pass', + 'host' => '', + 'control_ssl' => true, + 'controluser' => 'u2', + 'controlpass' => 'p2', + ); + return array( + array( + $cfg_basic, + DatabaseInterface::CONNECT_USER, + null, + array( + 'u', + 'pass', + array( + 'user' => 'u', + 'password' => 'pass', + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => false, + 'compress' => false, + 'controluser' => 'u2', + 'controlpass' => 'p2', + ) + ), + ), + array( + $cfg_basic, + DatabaseInterface::CONNECT_CONTROL, + null, + array( + 'u2', + 'p2', + array( + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => false, + 'compress' => false, + ) + ), + ), + array( + $cfg_ssl, + DatabaseInterface::CONNECT_USER, + null, + array( + 'u', + 'pass', + array( + 'user' => 'u', + 'password' => 'pass', + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => true, + 'compress' => false, + 'controluser' => 'u2', + 'controlpass' => 'p2', + ) + ), + ), + array( + $cfg_ssl, + DatabaseInterface::CONNECT_CONTROL, + null, + array( + 'u2', + 'p2', + array( + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => true, + 'compress' => false, + ) + ), + ), + array( + $cfg_control_ssl, + DatabaseInterface::CONNECT_USER, + null, + array( + 'u', + 'pass', + array( + 'user' => 'u', + 'password' => 'pass', + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => false, + 'compress' => false, + 'controluser' => 'u2', + 'controlpass' => 'p2', + 'control_ssl' => true, + ) + ), + ), + array( + $cfg_control_ssl, + DatabaseInterface::CONNECT_CONTROL, + null, + array( + 'u2', + 'p2', + array( + 'host' => 'localhost', + 'socket' => null, + 'port' => 0, + 'ssl' => true, + 'compress' => false, + ) + ), + ), + ); + } + + } /** From c328697e39e56957d66e75de62ce610a90259e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 13:53:08 +0200 Subject: [PATCH 31/34] Do not use mb_strlen result for string indexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The string indexes are in bytes, while mb_strlen counts chars. Issue #12397 Signed-off-by: Michal Čihař --- examples/openid.php | 2 +- libraries/server_status_monitor.lib.php | 2 +- libraries/transformations.lib.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/openid.php b/examples/openid.php index 8ef34e9ee3..9fe7b90491 100644 --- a/examples/openid.php +++ b/examples/openid.php @@ -89,7 +89,7 @@ $base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; $realm = $base . '/'; $returnTo = $base . dirname($_SERVER['PHP_SELF']); -if ($returnTo[mb_strlen($returnTo) - 1] != '/') { +if ($returnTo[strlen($returnTo) - 1] != '/') { $returnTo .= '/'; } $returnTo .= 'openid.php'; diff --git a/libraries/server_status_monitor.lib.php b/libraries/server_status_monitor.lib.php index f0b6d90df9..ea79aee3b0 100644 --- a/libraries/server_status_monitor.lib.php +++ b/libraries/server_status_monitor.lib.php @@ -675,7 +675,7 @@ function PMA_getJsonForLogDataTypeGeneral($start, $end) $temp = $return['rows'][$insertTablesFirst]['argument']; $return['rows'][$insertTablesFirst]['argument'] .= PMA_getSuspensionPoints( - $temp[mb_strlen($temp) - 1] + $temp[strlen($temp) - 1] ); // Group this value, thus do not add to the result list diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index 2526024bce..812bd13279 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -51,7 +51,7 @@ function PMA_Transformation_getOptions($option_string) $trimmed = trim($option); if (mb_strlen($trimmed) > 1 && $trimmed[0] == "'" - && $trimmed[mb_strlen($trimmed) - 1] == "'" + && $trimmed[strlen($trimmed) - 1] == "'" ) { // '...' $option = mb_substr($trimmed, 1, -1); @@ -62,7 +62,7 @@ function PMA_Transformation_getOptions($option_string) // ..., $trimmed .= ',' . $option; $rtrimmed = rtrim($trimmed); - if ($rtrimmed[mb_strlen($rtrimmed) - 1] == "'") { + if ($rtrimmed[strlen($rtrimmed) - 1] == "'") { // ,...' break; } From 7e6e4fdeff2067b1f7173d8d875043178a81975d Mon Sep 17 00:00:00 2001 From: Juha Date: Fri, 29 Jul 2016 11:47:36 +0000 Subject: [PATCH 32/34] Translated using Weblate (Finnish) Currently translated at 67.5% (2166 of 3208 strings) [CI skip] --- po/fi.po | 56 +++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/po/fi.po b/po/fi.po index df01e295ce..29899adcf8 100644 --- a/po/fi.po +++ b/po/fi.po @@ -4,16 +4,16 @@ msgstr "" "Project-Id-Version: phpMyAdmin 4.7.0-dev\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2016-05-23 14:29+0200\n" -"PO-Revision-Date: 2016-05-19 19:28+0000\n" -"Last-Translator: Daniel Linjama \n" -"Language-Team: Finnish \n" +"PO-Revision-Date: 2016-07-29 11:47+0000\n" +"Last-Translator: Juha \n" +"Language-Team: Finnish " +"\n" "Language: fi\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 2.7-dev\n" +"X-Generator: Weblate 2.8-dev\n" #: changelog.php:37 license.php:33 #, php-format @@ -3043,7 +3043,7 @@ msgstr "Korealainen" #: libraries/Charsets.php:313 msgid "Burmese" -msgstr "" +msgstr "Burma" #: libraries/Charsets.php:316 msgid "Persian" @@ -3063,7 +3063,7 @@ msgstr "Romanialainen" #: libraries/Charsets.php:328 msgid "Sinhalese" -msgstr "" +msgstr "Sinhali" #: libraries/Charsets.php:331 msgid "Slovak" @@ -3108,10 +3108,9 @@ msgid "multilingual" msgstr "monikielinen" #: libraries/Charsets.php:358 -#, fuzzy #| msgid "Table name" msgid "Vietnamese" -msgstr "Taulun nimi" +msgstr "Vietnam" #: libraries/Charsets.php:390 msgid "Central European" @@ -3159,22 +3158,19 @@ msgid "unknown" msgstr "tuntematon" #: libraries/Charsets.php:460 -#, fuzzy #| msgid "Collation" msgid "binary collation" -msgstr "Aakkosjärjestys" +msgstr "Binaarinen kollaatio" #: libraries/Charsets.php:467 -#, fuzzy #| msgid "case-insensitive" msgid "case-insensitive collation" -msgstr "kirjainkoolla ei väliä" +msgstr "kirjainkoosta riippumaton kollaatio" #: libraries/Charsets.php:469 -#, fuzzy #| msgid "case-sensitive" msgid "case-sensitive collation" -msgstr "tarkka kirjainkoko" +msgstr "täsmällinen kirjainkoko" #: libraries/Config.php:1155 #, php-format @@ -3212,8 +3208,8 @@ msgstr "Fonttikoko" #, php-format msgid "Showing %1$d bookmark (both private and shared)" msgid_plural "Showing %1$d bookmarks (both private and shared)" -msgstr[0] "" -msgstr[1] "" +msgstr[0] "Näytetään %1$d kirjanmerkki (sekä yksityinen että jaettu)" +msgstr[1] "Näytetään %1$d kirjanmerkkiä (sekä yksityiset että jaetut)" #: libraries/Console.php:95 msgid "No bookmarks" @@ -3664,7 +3660,6 @@ msgstr "Linkkiä ei löydy!" #. l10n: This is currently used only in Japanese locales #: libraries/Encoding.php:312 -#, fuzzy #| msgid "None" msgctxt "None encoding conversion" msgid "None" @@ -3673,7 +3668,7 @@ msgstr "Ei mitään" #. l10n: This is currently used only in Japanese locales #: libraries/Encoding.php:323 msgid "Convert to Kana" -msgstr "" +msgstr "Käännä Kana-merkeiksi" #: libraries/ErrorHandler.php:65 msgid "Too many error messages, some are not displayed." @@ -5482,14 +5477,11 @@ msgid "Highlight pointer" msgstr "Korosta osoitin" #: libraries/config/messages.inc.php:47 -#, fuzzy #| msgid "" #| "Enable [a@http://en.wikipedia.org/wiki/Bzip2]bzip2[/a] compression for " #| "import operations." msgid "Enable bzip2 compression for import operations." -msgstr "" -"Käytä tuontitoiminnoissa [a@http://en.wikipedia.org/wiki/Bzip2]bzip2[/a]-" -"pakkausta." +msgstr "Käytä tuontitoiminnoissa bzip2-pakkausta." #: libraries/config/messages.inc.php:50 msgid "Bzip2" @@ -5510,7 +5502,6 @@ msgid "CHAR columns editing" msgstr "CHAR-sarakkeiden muokkaus" #: libraries/config/messages.inc.php:58 -#, fuzzy #| msgid "" #| "Use user-friendly editor for editing SQL queries ([a@http://codemirror." #| "net/]CodeMirror[/a]) with syntax highlighting and line numbers." @@ -5518,8 +5509,8 @@ msgid "" "Use user-friendly editor for editing SQL queries (CodeMirror) with syntax " "highlighting and line numbers." msgstr "" -"Käytä käyttäjäystävällistä editoria SQL-kyselyiden muokkaamiseen ([a@http://" -"codemirror.net/]CodeMirror[/a]) syntaksin korostuksella ja rivinumeroilla." +"Käytä käyttäjäystävällistä editoria SQL-kyselyiden (CodeMirror) " +"muokkaamiseen syntaksin korostuksella ja rivinumeroilla." #: libraries/config/messages.inc.php:62 msgid "Enable CodeMirror" @@ -6274,14 +6265,11 @@ msgid "Disable some of the warnings shown by phpMyAdmin." msgstr "Kytke osa phpMyAdminin näyttämistä varoituksista pois päältä." #: libraries/config/messages.inc.php:353 -#, fuzzy #| msgid "" #| "Enable [a@http://en.wikipedia.org/wiki/Gzip]gzip[/a] compression for " #| "import and export operations." msgid "Enable gzip compression for import and export operations." -msgstr "" -"Käytä tuonti- ja vientitoiminnoissa [a@http://en.wikipedia.org/wiki/" -"Gzip]gzip[/a]-pakkausta." +msgstr "Käytä tuonti- ja vientitoiminnoissa gzip-pakkausta." #: libraries/config/messages.inc.php:356 msgid "GZip" @@ -6733,10 +6721,9 @@ msgid "Show row links anyway" msgstr "Näytä rivilinkit jopa tapauksessa" #: libraries/config/messages.inc.php:552 libraries/config/messages.inc.php:553 -#, fuzzy #| msgid "Disable foreign key checks" msgid "Disable shortcut keys" -msgstr "Älä tarkista viiteavaimia" +msgstr "Poista oikotieavaimet käytöstä" #: libraries/config/messages.inc.php:555 msgid "Use natural order for sorting table and database names." @@ -6970,7 +6957,6 @@ msgid "Authentication type" msgstr "Todennustyyppi" #: libraries/config/messages.inc.php:640 -#, fuzzy #| msgid "" #| "Leave blank for no [a@https://wiki.phpmyadmin.net/pma/bookmark]bookmark[/" #| "a] support, suggested: [kbd]pma__bookmark[/kbd]" @@ -6978,8 +6964,8 @@ msgid "" "Leave blank for no [doc@bookmarks@]bookmark[/doc] support, suggested: " "[kbd]pma__bookmark[/kbd]" msgstr "" -"Jätä tyhjäksi, jos et halua [a@https://wiki.phpmyadmin.net/pma/" -"bookmark]kirjanmerkki[/a]tukea, oletusarvo: [kbd]pma__bookmark[/kbd]" +"Jätä tyhjäksi, jos et halua [doc@bookmarks@]kirjanmerkki[/doc]tukea, " +"oletusarvo: [kbd]pma__bookmark[/kbd]" #: libraries/config/messages.inc.php:643 msgid "Bookmark table" From b27020f10882cf74317b26c93034a7312e4656a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 14:03:13 +0200 Subject: [PATCH 33/34] Avoid typecasting to float when not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12303 Signed-off-by: Michal Čihař --- ChangeLog | 1 + libraries/Util.php | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bd07d6347..41c6e80e71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ phpMyAdmin - ChangeLog - issue #12414 Fixed rendering of Original theme - issue #12413 Fixed deleting users in non English locales - issue #12416 Fixed replication status output in Databases listing +- issue #12303 Avoid typecasting to float when not needed 4.6.3 (2016-06-23) - issue #12249 Fixed cookie path on Windows diff --git a/libraries/Util.php b/libraries/Util.php index 8606f4de91..9007e9531f 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -85,7 +85,7 @@ class Util $pow = gmp_strval(gmp_pow($base, $exp)); break; case 'pow' : - $base = (float) $base; + $base = $base; $exp = (int) $exp; $pow = pow($base, $exp); break; @@ -1461,8 +1461,7 @@ class Util $unit = $byteUnits[0]; for ($d = 6, $ex = 15; $d >= 1; $d--, $ex-=3) { - // cast to float to avoid overflow - $unitSize = (float) $li * self::pow(10, $ex); + $unitSize = $li * self::pow(10, $ex); if (isset($byteUnits[$d]) && $value >= $unitSize) { // use 1024.0 to avoid integer overflow on 64-bit machines $value = round($value / (self::pow(1024, $d) / $dh)) /$dh; From 62ad40ef049f63e49df6885b179357326d474049 Mon Sep 17 00:00:00 2001 From: Juha Date: Fri, 29 Jul 2016 11:47:38 +0000 Subject: [PATCH 34/34] Translated using Weblate (Finnish) Currently translated at 67.7% (2173 of 3209 strings) [CI skip] --- po/fi.po | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/po/fi.po b/po/fi.po index 2aa421661e..3c1460fe21 100644 --- a/po/fi.po +++ b/po/fi.po @@ -4,16 +4,16 @@ msgstr "" "Project-Id-Version: phpMyAdmin 4.6.2-dev\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2016-05-23 14:29+0200\n" -"PO-Revision-Date: 2016-05-19 19:28+0000\n" -"Last-Translator: Daniel Linjama \n" -"Language-Team: Finnish \n" +"PO-Revision-Date: 2016-07-29 11:47+0000\n" +"Last-Translator: Juha \n" +"Language-Team: Finnish " +"\n" "Language: fi\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 2.7-dev\n" +"X-Generator: Weblate 2.8-dev\n" #: changelog.php:37 license.php:33 #, php-format @@ -3008,8 +3008,8 @@ msgstr "Tietokanta" #, php-format msgid "Showing %1$d bookmark (both private and shared)" msgid_plural "Showing %1$d bookmarks (both private and shared)" -msgstr[0] "" -msgstr[1] "" +msgstr[0] "Näytetään %1$d kirjanmerkki (sekä yksityinen että jaettu)" +msgstr[1] "Näytetään %1$d kirjanmerkkiä (sekä yksityiset että jaetut)" #: libraries/Console.php:107 msgid "No bookmarks" @@ -5413,14 +5413,11 @@ msgid "Highlight pointer" msgstr "Korosta osoitin" #: libraries/config/messages.inc.php:47 -#, fuzzy #| msgid "" #| "Enable [a@http://en.wikipedia.org/wiki/Bzip2]bzip2[/a] compression for " #| "import operations." msgid "Enable bzip2 compression for import operations." -msgstr "" -"Käytä tuontitoiminnoissa [a@http://en.wikipedia.org/wiki/Bzip2]bzip2[/a]-" -"pakkausta." +msgstr "Käytä tuontitoiminnoissa bzip2-pakkausta." #: libraries/config/messages.inc.php:50 msgid "Bzip2" @@ -5441,7 +5438,6 @@ msgid "CHAR columns editing" msgstr "CHAR-sarakkeiden muokkaus" #: libraries/config/messages.inc.php:58 -#, fuzzy #| msgid "" #| "Use user-friendly editor for editing SQL queries ([a@http://codemirror." #| "net/]CodeMirror[/a]) with syntax highlighting and line numbers." @@ -5449,8 +5445,8 @@ msgid "" "Use user-friendly editor for editing SQL queries (CodeMirror) with syntax " "highlighting and line numbers." msgstr "" -"Käytä käyttäjäystävällistä editoria SQL-kyselyiden muokkaamiseen ([a@http://" -"codemirror.net/]CodeMirror[/a]) syntaksin korostuksella ja rivinumeroilla." +"Käytä käyttäjäystävällistä editoria SQL-kyselyiden (CodeMirror) " +"muokkaamiseen syntaksin korostuksella ja rivinumeroilla." #: libraries/config/messages.inc.php:62 msgid "Enable CodeMirror" @@ -6200,14 +6196,11 @@ msgid "Disable some of the warnings shown by phpMyAdmin." msgstr "Kytke osa phpMyAdminin näyttämistä varoituksista pois päältä." #: libraries/config/messages.inc.php:353 -#, fuzzy #| msgid "" #| "Enable [a@http://en.wikipedia.org/wiki/Gzip]gzip[/a] compression for " #| "import and export operations." msgid "Enable gzip compression for import and export operations." -msgstr "" -"Käytä tuonti- ja vientitoiminnoissa [a@http://en.wikipedia.org/wiki/" -"Gzip]gzip[/a]-pakkausta." +msgstr "Käytä tuonti- ja vientitoiminnoissa gzip-pakkausta." #: libraries/config/messages.inc.php:356 msgid "GZip" @@ -6907,7 +6900,6 @@ msgid "Authentication type" msgstr "Todennustyyppi" #: libraries/config/messages.inc.php:644 -#, fuzzy #| msgid "" #| "Leave blank for no [a@https://wiki.phpmyadmin.net/pma/bookmark]bookmark[/" #| "a] support, suggested: [kbd]pma__bookmark[/kbd]" @@ -6915,8 +6907,8 @@ msgid "" "Leave blank for no [doc@bookmarks@]bookmark[/doc] support, suggested: " "[kbd]pma__bookmark[/kbd]" msgstr "" -"Jätä tyhjäksi, jos et halua [a@https://wiki.phpmyadmin.net/pma/" -"bookmark]kirjanmerkki[/a]tukea, oletusarvo: [kbd]pma__bookmark[/kbd]" +"Jätä tyhjäksi, jos et halua [doc@bookmarks@]kirjanmerkki[/doc]tukea, " +"oletusarvo: [kbd]pma__bookmark[/kbd]" #: libraries/config/messages.inc.php:647 msgid "Bookmark table" @@ -9097,7 +9089,6 @@ msgstr "Lisätyn rivin tunnus: %1$d" #. l10n: This is currently used only in Japanese locales #: libraries/kanji-encoding.lib.php:150 -#, fuzzy #| msgid "None" msgctxt "None encoding conversion" msgid "None" @@ -9106,7 +9097,7 @@ msgstr "Ei mitään" #. l10n: This is currently used only in Japanese locales #: libraries/kanji-encoding.lib.php:161 msgid "Convert to Kana" -msgstr "" +msgstr "Käännä Kana-merkeiksi" #: libraries/mult_submits.inc.php:329 msgid "Success!" @@ -9272,7 +9263,7 @@ msgstr "Romanialainen" #: libraries/mysql_charsets.lib.php:235 msgid "Sinhalese" -msgstr "" +msgstr "Sinhali" #: libraries/mysql_charsets.lib.php:238 msgid "Slovak" @@ -9317,10 +9308,9 @@ msgid "multilingual" msgstr "monikielinen" #: libraries/mysql_charsets.lib.php:265 -#, fuzzy #| msgid "Table name" msgid "Vietnamese" -msgstr "Taulun nimi" +msgstr "Vietnam" #: libraries/mysql_charsets.lib.php:293 msgid "Central European"