From 3c118b8106ee5e67a34e90686e9ce0167bd69236 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 31 Aug 2015 22:28:03 +1000 Subject: [PATCH 1/2] Fix #11446 MySQL 5.7 and Variables page for an unprivileged user Signed-off-by: Madhura Jayaratne --- libraries/server_variables.lib.php | 25 ++++++------ server_variables.php | 41 +++++++++++++++++--- test/libraries/PMA_server_variables_test.php | 14 ++++++- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/libraries/server_variables.lib.php b/libraries/server_variables.lib.php index cf7d3479c5..ec9164313b 100644 --- a/libraries/server_variables.lib.php +++ b/libraries/server_variables.lib.php @@ -167,11 +167,14 @@ function PMA_getHtmlForLinkTemplates() * Prints Html for Server Variables * * @param Array $variable_doc_links documentation links + * @param Array $serverVars global variables + * @param Array $serverVarsSession session variables * * @return string */ -function PMA_getHtmlForServerVariables($variable_doc_links) -{ +function PMA_getHtmlForServerVariables( + $variable_doc_links, $serverVars, $serverVarsSession +) { $value = ! empty($_REQUEST['filter']) ? htmlspecialchars($_REQUEST['filter']) : ''; @@ -194,7 +197,9 @@ function PMA_getHtmlForServerVariables($variable_doc_links) . '' . ''; - $output .= PMA_getHtmlForServerVariablesItems($variable_doc_links); + $output .= PMA_getHtmlForServerVariablesItems( + $variable_doc_links, $serverVars, $serverVarsSession + ); $output .= ''; @@ -206,18 +211,14 @@ function PMA_getHtmlForServerVariables($variable_doc_links) * Prints Html for Server Variables Items * * @param Array $variable_doc_links documentation links + * @param Array $serverVars global variables + * @param Array $serverVarsSession session variables * * @return string */ -function PMA_getHtmlForServerVariablesItems($variable_doc_links) -{ - /** - * Sends the queries and buffers the results - */ - $serverVarsSession - = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1); - $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); - +function PMA_getHtmlForServerVariablesItems( + $variable_doc_links, $serverVars, $serverVarsSession +) { // list of static system variables $static_variables = PMA_getStaticSystemVariables(); diff --git a/server_variables.php b/server_variables.php index ac2bf5e0a2..b0708662a0 100644 --- a/server_variables.php +++ b/server_variables.php @@ -46,13 +46,42 @@ $doc_link = PMA_Util::showMySQLDocu('server_system_variables'); $response->addHtml(PMA_getHtmlForSubPageHeader('variables', $doc_link)); /** - * Link templates + * Sends the queries and buffers the results */ -$response->addHtml(PMA_getHtmlForLinkTemplates()); +$serverVarsResult = $GLOBALS['dbi']->tryQuery('SHOW SESSION VARIABLES;'); -/** - * Displays the page - */ -$response->addHtml(PMA_getHtmlForServerVariables($variable_doc_links)); +if ($serverVarsResult !== false) { + + $serverVarsSession = array(); + while ($arr = $GLOBALS['dbi']->fetchRow($serverVarsResult)) { + $serverVarsSession[$arr[0]] = $arr[1]; + } + $GLOBALS['dbi']->freeResult($serverVarsResult); + + $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); + + /** + * Link templates + */ + $response->addHtml(PMA_getHtmlForLinkTemplates()); + + /** + * Displays the page + */ + $response->addHtml( + PMA_getHtmlForServerVariables( + $variable_doc_links, $serverVars, $serverVarsSession + ) + ); +} else { + /** + * Display the error message + */ + $response->addHTML( + PMA_Message::error( + __('Not enough privilege to view server variables and settings.') + )->getDisplay() + ); +} exit; diff --git a/test/libraries/PMA_server_variables_test.php b/test/libraries/PMA_server_variables_test.php index bd4aa62fdb..8a1b2aa448 100644 --- a/test/libraries/PMA_server_variables_test.php +++ b/test/libraries/PMA_server_variables_test.php @@ -175,7 +175,12 @@ class PMA_ServerVariables_Test extends PHPUnit_Framework_TestCase $_REQUEST['filter'] = "auto-commit"; $variable_doc_links = PMA_getArrayForDocumentLinks(); - $html = PMA_getHtmlForServerVariables($variable_doc_links); + $serverVarsSession + = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1); + $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); + $html = PMA_getHtmlForServerVariables( + $variable_doc_links, $serverVars, $serverVarsSession + ); //validate 1: Filters $this->assertContains( @@ -216,7 +221,12 @@ class PMA_ServerVariables_Test extends PHPUnit_Framework_TestCase //Call the test function $variable_doc_links = PMA_getArrayForDocumentLinks(); - $html = PMA_getHtmlForServerVariablesItems($variable_doc_links); + $serverVarsSession + = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1); + $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); + $html = PMA_getHtmlForServerVariablesItems( + $variable_doc_links, $serverVars, $serverVarsSession + ); //validate 1: variable: auto_increment_increment $name = "auto_increment_increment"; From a998d7516e5815472864f7050cd99decc2991d3c Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 31 Aug 2015 22:55:04 +1000 Subject: [PATCH 2/2] Fix another test Signed-off-by: Madhura Jayaratne --- test/libraries/PMA_server_status_test.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/libraries/PMA_server_status_test.php b/test/libraries/PMA_server_status_test.php index b4ed4436ed..8b9912279a 100644 --- a/test/libraries/PMA_server_status_test.php +++ b/test/libraries/PMA_server_status_test.php @@ -107,6 +107,32 @@ class PMA_ServerStatus_Test extends PHPUnit_Framework_TestCase ), ); + $dbi->expects($this->at(0)) + ->method('tryQuery') + ->with('SHOW GLOBAL STATUS') + ->will($this->returnValue(true)); + + $dbi->expects($this->at(1)) + ->method('fetchRow') + ->will($this->returnValue(array("Aborted_clients", "0"))); + $dbi->expects($this->at(2)) + ->method('fetchRow') + ->will($this->returnValue(array("Aborted_connects", "0"))); + $dbi->expects($this->at(3)) + ->method('fetchRow') + ->will($this->returnValue(array("Com_delete_multi", "0"))); + $dbi->expects($this->at(4)) + ->method('fetchRow') + ->will($this->returnValue(array("Com_create_function", "0"))); + $dbi->expects($this->at(5)) + ->method('fetchRow') + ->will($this->returnValue(array("Com_empty_query", "0"))); + $dbi->expects($this->at(6)) + ->method('fetchRow') + ->will($this->returnValue(false)); + + $dbi->expects($this->at(7))->method('freeResult'); + $dbi->expects($this->any())->method('fetchResult') ->will($this->returnValueMap($fetchResult));