/** * Prints details about the current Git commit revision * * @return void */ function PMA_printGitRevision() { if (!$GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus(false); return; } // load revision data from repo $GLOBALS['PMA_Config']->checkGitRevision(); // if using a remote commit fast-forwarded, link to GitHub $commit_hash = substr($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), 0, 7); $commit_hash = '<strong title="' . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE')) . '">' . $commit_hash . '</strong>'; if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) { $commit_hash = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/commit/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')) . '" target="_blank">' . $commit_hash . '</a>'; } $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH'); if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) { $branch = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/tree/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')) . '" target="_blank">' . $branch . '</a>'; } if ($branch !== false) { $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch); } else { $branch = $commit_hash . ' (' . __('no branch') . ')'; } $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); PMA_printListItem(__('Git revision:') . ' ' . $branch . ',<br /> ' . sprintf(__('committed on %1$s by %2$s'), PMA\libraries\Util::localisedDate(strtotime($committer['date'])), '<a href="' . PMA_linkURL('mailto:' . htmlspecialchars($committer['email'])) . '">' . htmlspecialchars($committer['name']) . '</a>') . ($author != $committer ? ', <br />' . sprintf(__('authored on %1$s by %2$s'), PMA\libraries\Util::localisedDate(strtotime($author['date'])), '<a href="' . PMA_linkURL('mailto:' . htmlspecialchars($author['email'])) . '">' . htmlspecialchars($author['name']) . '</a>') : ''), 'li_pma_version_git', null, null, null); }
public function doMockResponse($set_minimal, $body_id, $set_title) { $restoreInstance = PMA\libraries\Response::getInstance(); // mock footer $mockFooter = $this->getMockBuilder('PMA\\libraries\\Footer')->disableOriginalConstructor()->setMethods(array('setMinimal'))->getMock(); $mockFooter->expects($this->exactly($set_minimal))->method('setMinimal')->with(); // mock header $mockHeader = $this->getMockBuilder('PMA\\libraries\\Header')->disableOriginalConstructor()->setMethods(array('setBodyId', 'setTitle', 'disableMenuAndConsole', 'addHTML'))->getMock(); $mockHeader->expects($this->exactly($body_id))->method('setBodyId')->with('loginform'); $mockHeader->expects($this->exactly($set_title))->method('setTitle')->with('Access denied!'); $mockHeader->expects($this->exactly($set_title))->method('disableMenuAndConsole')->with(); // set mocked headers and footers $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('getHeader', 'getFooter', 'addHTML', 'header', 'headersSent'))->getMock(); $mockResponse->expects($this->exactly($set_title))->method('getFooter')->with()->will($this->returnValue($mockFooter)); $mockResponse->expects($this->exactly($set_title))->method('getHeader')->with()->will($this->returnValue($mockHeader)); $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false)); $mockResponse->expects($this->exactly($set_title * 6))->method('addHTML')->with(); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $headers = array_slice(func_get_args(), 3); $header_method = $mockResponse->expects($this->exactly(count($headers)))->method('header'); call_user_func_array(array($header_method, 'withConsecutive'), $headers); try { $this->assertFalse($this->object->auth()); } finally { $attrInstance->setValue($restoreInstance); } }
/** * Send the message as an ajax request * * @param array $change_password_message Message to display * @param string $sql_query SQL query executed * * @return void */ function PMA_getChangePassMessage($change_password_message, $sql_query = '') { if ($GLOBALS['is_ajax_request'] == true) { /** * If in an Ajax request, we don't need to show the rest of the page */ $response = PMA\libraries\Response::getInstance(); if ($change_password_message['error']) { $response->addJSON('message', $change_password_message['msg']); $response->setRequestStatus(false); } else { $sql_query = PMA\libraries\Util::getMessage($change_password_message['msg'], $sql_query, 'success'); $response->addJSON('message', $sql_query); } exit; } }
/** * Test for PMA\libraries\plugins\auth\AuthenticationHttp::auth * * @return void */ public function testAuth() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } $_REQUEST['old_usr'] = '******'; $GLOBALS['cfg']['Server']['LogoutURL'] = 'http://phpmyadmin.net/logout'; $this->assertFalse($this->object->auth()); $this->assertContains('Location: http://phpmyadmin.net/logout', $GLOBALS['header'][0]); // case 2 $restoreInstance = PMA\libraries\Response::getInstance(); // mock footer $mockFooter = $this->getMockBuilder('PMA\\libraries\\Footer')->disableOriginalConstructor()->setMethods(array('setMinimal'))->getMock(); $mockFooter->expects($this->once())->method('setMinimal')->with(); // mock header $mockHeader = $this->getMockBuilder('PMA\\libraries\\Header')->disableOriginalConstructor()->setMethods(array('setBodyId', 'setTitle', 'disableMenuAndConsole', 'addHTML'))->getMock(); $mockHeader->expects($this->once())->method('setBodyId')->with('loginform'); $mockHeader->expects($this->once())->method('setTitle')->with('Access denied!'); $mockHeader->expects($this->once())->method('disableMenuAndConsole')->with(); // set mocked headers and footers $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('getHeader', 'getFooter', 'addHTML'))->getMock(); $mockResponse->expects($this->once())->method('getFooter')->with()->will($this->returnValue($mockFooter)); $mockResponse->expects($this->once())->method('getHeader')->with()->will($this->returnValue($mockHeader)); $mockResponse->expects($this->exactly(6))->method('addHTML')->with(); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $GLOBALS['header'] = array(); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['Server']['verbose'] = 'verboseMessagê'; $this->assertFalse($this->object->auth()); $this->assertEquals(array('WWW-Authenticate: Basic realm="phpMyAdmin verboseMessag"', 'HTTP/1.0 401 Unauthorized', 'status: 401 Unauthorized'), $GLOBALS['header']); $attrInstance->setValue($restoreInstance); // case 3 $GLOBALS['header'] = array(); $GLOBALS['cfg']['Server']['verbose'] = ''; $GLOBALS['cfg']['Server']['host'] = 'hòst'; $this->assertFalse($this->object->auth()); $this->assertEquals(array('WWW-Authenticate: Basic realm="phpMyAdmin hst"', 'HTTP/1.0 401 Unauthorized', 'status: 401 Unauthorized'), $GLOBALS['header']); // case 4 $GLOBALS['header'] = array(); $GLOBALS['cfg']['Server']['host'] = ''; $GLOBALS['cfg']['Server']['auth_http_realm'] = 'rêäealmmessage'; $this->assertFalse($this->object->auth()); $this->assertEquals(array('WWW-Authenticate: Basic realm="realmmessage"', 'HTTP/1.0 401 Unauthorized', 'status: 401 Unauthorized'), $GLOBALS['header']); }
/** * Get Ajax return when $_REQUEST['type'] === 'setval' * * @param Array $variable_doc_links documentation links * * @return null */ function PMA_getAjaxReturnForSetVal($variable_doc_links) { $response = PMA\libraries\Response::getInstance(); $value = $_REQUEST['varValue']; $matches = array(); if (isset($variable_doc_links[$_REQUEST['varName']][3]) && $variable_doc_links[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) { $exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3); $value = floatval($matches[1]) * PMA\libraries\Util::pow(1024, $exp[mb_strtolower($matches[3])]); } else { $value = PMA\libraries\Util::sqlAddSlashes($value); } if (!is_numeric($value)) { $value = "'" . $value . "'"; } if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && $GLOBALS['dbi']->query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) { // Some values are rounded down etc. $varValue = $GLOBALS['dbi']->fetchSingleRow('SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA\libraries\Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); $response->addJSON('variable', PMA_formatVariable($_REQUEST['varName'], $varValue[1], $variable_doc_links)); } else { $response->setRequestStatus(false); $response->addJSON('error', __('Setting variable failed')); } }
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Handles table search tab * * display table search form, create SQL query from form data * and call PMA_executeQueryAndSendQueryResponse() to execute it * * @package PhpMyAdmin */ /** * Gets some core libraries */ require_once 'libraries/common.inc.php'; require_once 'libraries/tbl_common.inc.php'; require_once 'libraries/tbl_info.inc.php'; use PMA\libraries\controllers\table\TableSearchController; $container = \PMA\libraries\di\Container::getDefaultContainer(); $container->factory('PMA\\libraries\\controllers\\table\\TableSearchController'); $container->alias('TableSearchController', 'PMA\\libraries\\controllers\\table\\TableSearchController'); $container->set('PMA\\libraries\\Response', PMA\libraries\Response::getInstance()); $container->alias('response', 'PMA\\libraries\\Response'); /* Define dependencies for the concerned controller */ $dependency_definitions = array('searchType' => 'normal', 'url_query' => &$url_query); /** @var TableSearchController $controller */ $controller = $container->get('TableSearchController', $dependency_definitions); $controller->indexAction();
/** * Test for PMA_determineInsertOrEdit * * @return void */ public function testDetermineInsertOrEdit() { $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $GLOBALS['dbi'] = $dbi; $_REQUEST['where_clause'] = '1'; $_SESSION['edit_next'] = '1'; $_REQUEST['ShowFunctionFields'] = true; $_REQUEST['ShowFieldTypesInDataEditView'] = true; $_REQUEST['after_insert'] = 'edit_next'; $GLOBALS['cfg']['InsertRows'] = 2; $GLOBALS['cfg']['ShowSQL'] = false; $_REQUEST['default_action'] = 'insert'; $responseMock = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('addHtml'))->getMock(); $restoreInstance = PMA\libraries\Response::getInstance(); $response = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $response->setAccessible(true); $response->setValue($responseMock); $result = PMA_determineInsertOrEdit('1', 'db', 'table'); $this->assertEquals(array(false, null, array(1), null, array(null), array(null), false, "edit_next"), $result); // case 2 unset($_REQUEST['where_clause']); unset($_SESSION['edit_next']); $_REQUEST['default_action'] = ''; $result = PMA_determineInsertOrEdit(null, 'db', 'table'); $response->setValue($restoreInstance); $this->assertEquals(array(true, null, array(), null, null, array(false, false), false, "edit_next"), $result); }
/** * Handles export template actions * * @param array $cfgRelation Relation configuration * * @return void */ function PMA_handleExportTemplateActions($cfgRelation) { if (isset($_REQUEST['templateId'])) { $id = PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateId']); } else { $id = ''; } $templateTable = PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['export_templates']); $user = PMA\libraries\Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']); switch ($_REQUEST['templateAction']) { case 'create': $query = "INSERT INTO " . $templateTable . "(" . " `username`, `export_type`," . " `template_name`, `template_data`" . ") VALUES (" . "'" . $user . "', " . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['exportType']) . "', '" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateName']) . "', '" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateData']) . "');"; break; case 'load': $query = "SELECT `template_data` FROM " . $templateTable . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; case 'update': $query = "UPDATE " . $templateTable . " SET `template_data` = " . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateData']) . "'" . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; case 'delete': $query = "DELETE FROM " . $templateTable . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; default: $query = ''; break; } $result = PMA_queryAsControlUser($query, false); $response = PMA\libraries\Response::getInstance(); if (!$result) { $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']); $response->setRequestStatus(false); $response->addJSON('message', $error); exit; } $response->setRequestStatus(true); if ('create' == $_REQUEST['templateAction']) { $response->addJSON('data', PMA_getOptionsForExportTemplates($_REQUEST['exportType'])); } elseif ('load' == $_REQUEST['templateAction']) { $data = null; while ($row = $GLOBALS['dbi']->fetchAssoc($result, $GLOBALS['controllink'])) { $data = $row['template_data']; } $response->addJSON('data', $data); } $GLOBALS['dbi']->freeResult($result); }
// See FAQ 1.34 if (!empty($_REQUEST['db'])) { $page = null; if (!empty($_REQUEST['table'])) { $page = PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table'); } else { $page = PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'); } include $page; exit; } /** * Check if it is an ajax request to reload the recent tables list. */ if ($GLOBALS['is_ajax_request'] && !empty($_REQUEST['recent_table'])) { $response = PMA\libraries\Response::getInstance(); $response->addJSON('list', RecentFavoriteTable::getInstance('recent')->getHtmlList()); exit; } if ($GLOBALS['PMA_Config']->isGitRevision()) { if (isset($_REQUEST['git_revision']) && $GLOBALS['is_ajax_request'] == true) { PMA_printGitRevision(); exit; } echo '<div id="is_git_revision"></div>'; } // Handles some variables that may have been sent by the calling script $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; $show_query = '1'; // Any message to display?
/** * Get List of information: Changes / copies a user * * @return array */ function PMA_getDataForChangeOrCopyUser() { $queries = null; $password = null; if (isset($_REQUEST['change_copy'])) { $user_host_condition = ' WHERE `User` = ' . "'" . Util::sqlAddSlashes($_REQUEST['old_username']) . "'" . ' AND `Host` = ' . "'" . Util::sqlAddSlashes($_REQUEST['old_hostname']) . "';"; $row = $GLOBALS['dbi']->fetchSingleRow('SELECT * FROM `mysql`.`user` ' . $user_host_condition); if (!$row) { $response = PMA\libraries\Response::getInstance(); $response->addHTML(Message::notice(__('No user found.'))->getDisplay()); unset($_REQUEST['change_copy']); } else { extract($row, EXTR_OVERWRITE); // Recent MySQL versions have the field "Password" in mysql.user, // so the previous extract creates $Password but this script // uses $password if (!isset($password) && isset($Password)) { $password = $Password; } if (Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50606 && PMA_MYSQL_INT_VERSION < 50706 && (isset($authentication_string) && empty($password) || isset($plugin) && $plugin == 'sha256_password')) { $password = $authentication_string; } if (Util::getServerType() == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50500 && isset($authentication_string) && empty($password)) { $password = $authentication_string; } // Always use 'authentication_string' column // for MySQL 5.7.6+ since it does not have // the 'password' column at all if (Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 && isset($authentication_string)) { $password = $authentication_string; } $queries = array(); } } return array($queries, $password); }
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Represents the interface between the linter and the query editor. * * @package PhpMyAdmin */ use PMA\libraries\Linter; /** * Loading common files. Used to check for authorization, localization and to * load the parsing library. */ require_once 'libraries/common.inc.php'; /** * The SQL query to be analyzed. * * This does not need to be checked again XSS or MySQL injections because it is * never executed, just parsed. * * The client, which will recieve the JSON response will decode the message and * and any HTML fragments that are displayed to the user will be encoded anyway. * * @var string */ $sql_query = !empty($_POST['sql_query']) ? $_POST['sql_query'] : ''; // Disabling standard response. PMA\libraries\Response::getInstance()->disable(); PMA_headerJSON(); echo json_encode(Linter::lint($sql_query));
/** * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authSetUser (check for headers redirect) * * @return void */ public function testAuthSetUserWithHeaders() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } $GLOBALS['PHP_AUTH_USER'] = '******'; $arr = array('host' => 'a', 'port' => 1, 'socket' => true, 'ssl' => true, 'connect_type' => 'port', 'user' => 'pmaUser2'); $GLOBALS['cfg']['Server'] = $arr; $GLOBALS['cfg']['Server']['host'] = 'b'; $GLOBALS['cfg']['Server']['user'] = '******'; $GLOBALS['cfg']['Servers'][1] = $arr; $GLOBALS['cfg']['AllowArbitraryServer'] = true; $GLOBALS['pma_auth_server'] = 'b 2'; $GLOBALS['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'] = 'testPW'; $GLOBALS['server'] = 2; $GLOBALS['cfg']['LoginCookieStore'] = true; $GLOBALS['from_cookie'] = false; $GLOBALS['cfg']['PmaAbsoluteUri'] = 'http://phpmyadmin.net/'; $GLOBALS['collation_connection'] = 'utf-8'; $restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('disable'))->getMock(); $mockResponse->expects($this->at(0))->method('disable'); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $this->object->authSetUser(); $this->object->storeUserCredentials(); $this->assertTrue(isset($_COOKIE['pmaServer-2'])); // target can be "phpunit" or "ide-phpunit.php", // depending on testing environment $this->assertStringStartsWith('Location: http://phpmyadmin.net/index.php?', $GLOBALS['header'][0]); $this->assertContains('&target=', $GLOBALS['header'][0]); $this->assertContains('&server=2&lang=en&collation_connection=utf-8&token=token&PHPSESSID=', $GLOBALS['header'][0]); $attrInstance->setValue($restoreInstance); }
/** * Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck * * @return void */ public function testAuthCheckToken() { $restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'headersSent', 'header'))->getMock(); $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false)); $mockResponse->expects($this->once())->method('header')->with('Location: https://example.com/SignonURL'); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL'; $GLOBALS['cfg']['Server']['SignonSession'] = 'session123'; $GLOBALS['cfg']['Server']['host'] = 'localhost'; $GLOBALS['cfg']['Server']['port'] = '80'; $GLOBALS['cfg']['Server']['user'] = '******'; $GLOBALS['cfg']['Server']['SignonScript'] = ''; $_COOKIE['session123'] = true; $_SESSION['PMA_single_signon_user'] = '******'; $_SESSION['PMA_single_signon_password'] = '******'; $_SESSION['PMA_single_signon_host'] = 'local'; $_SESSION['PMA_single_signon_port'] = '12'; $_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar'); $_SESSION['PMA_single_signon_token'] = 'pmaToken'; $sessionName = session_name(); $sessionID = session_id(); $this->object->logOut(); $this->assertEquals(array('SignonURL' => 'https://example.com/SignonURL', 'SignonScript' => '', 'SignonSession' => 'session123', 'host' => 'localhost', 'port' => '80', 'user' => 'user'), $GLOBALS['cfg']['Server']); $this->assertEquals($sessionName, session_name()); $this->assertEquals($sessionID, session_id()); $this->assertFalse(isset($_SESSION['LAST_SIGNON_URL'])); $attrInstance->setValue($restoreInstance); }
/** * Handles request for ROLLBACK. * * @param string $sql_query SQL query(s) * * @return void */ function PMA_handleRollbackRequest($sql_query) { $sql_delimiter = $_REQUEST['sql_delimiter']; $queries = explode($sql_delimiter, $sql_query); $error = false; $error_msg = __('Only INSERT, UPDATE, DELETE and REPLACE ' . 'SQL queries containing transactional engine tables can be rolled back.'); foreach ($queries as $sql_query) { if (empty($sql_query)) { continue; } // Check each query for ROLLBACK support. if (!PMA_checkIfRollbackPossible($sql_query)) { $global_error = $GLOBALS['dbi']->getError(); if ($global_error) { $error = $global_error; } else { $error = $error_msg; } break; } } if ($error) { unset($_REQUEST['rollback_query']); $response = PMA\libraries\Response::getInstance(); $message = Message::rawError($error); $response->addJSON('message', $message); exit; } else { // If everything fine, START a transaction. $GLOBALS['dbi']->query('START TRANSACTION'); } }
/** * handle control requests * * @return NULL */ function PMA_handleControlRequest() { if (isset($_REQUEST['sr_take_action'])) { $refresh = false; $result = false; $messageSuccess = null; $messageError = null; if (isset($_REQUEST['slave_changemaster'])) { $result = PMA_handleRequestForSlaveChangeMaster(); } elseif (isset($_REQUEST['sr_slave_server_control'])) { $result = PMA_handleRequestForSlaveServerControl(); $refresh = true; switch ($_REQUEST['sr_slave_action']) { case 'start': $messageSuccess = __('Replication started successfully.'); $messageError = __('Error starting replication.'); break; case 'stop': $messageSuccess = __('Replication stopped successfully.'); $messageError = __('Error stopping replication.'); break; case 'reset': $messageSuccess = __('Replication resetting successfully.'); $messageError = __('Error resetting replication.'); break; default: $messageSuccess = __('Success.'); $messageError = __('Error.'); break; } } elseif (isset($_REQUEST['sr_slave_skip_error'])) { $result = PMA_handleRequestForSlaveSkipError(); } if ($refresh) { $response = PMA\libraries\Response::getInstance(); if ($response->isAjax()) { $response->setRequestStatus($result); $response->addJSON('message', $result ? Message::success($messageSuccess) : Message::error($messageError)); } else { PMA_sendHeaderLocation($GLOBALS['cfg']['PmaAbsoluteUri'] . 'server_replication.php' . PMA_URL_getCommon($GLOBALS['url_params'], 'text')); } } unset($refresh); } }
public function doMockResponse() { $restoreInstance = PMA\libraries\Response::getInstance(); // set mocked headers and footers $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('header', 'headersSent'))->getMock(); $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false)); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $headers = func_get_args(); $header_method = $mockResponse->expects($this->exactly(count($headers)))->method('header'); call_user_func_array(array($header_method, 'withConsecutive'), $headers); $this->object->authFails(); $attrInstance->setValue($restoreInstance); }
/** * Check wether insert row mode and if so include tbl_changen script and set * global variables. * * @return void */ function PMA_isInsertRow() { if (isset($_REQUEST['insert_rows']) && is_numeric($_REQUEST['insert_rows']) && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows']) { $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows']; $response = PMA\libraries\Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('tbl_change.js'); if (!defined('TESTSUITE')) { include 'tbl_change.php'; exit; } } }
echo '<input type="submit"' . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][add_point]"' . ' class="add addPoint" value="' . __("Add a point") . '" />'; } echo '<br/>'; echo '<input type="submit"' . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][add_line]"' . ' class="add addLine" value="' . __('Add an inner ring') . '" />'; echo '<br/>'; } echo '<br/>'; echo '<input type="submit"' . ' name="gis_data[' . $a . '][' . $type . '][add_polygon]"' . ' class="add addPolygon" value="' . __('Add a polygon') . '" />'; } } if ($geom_type == 'GEOMETRYCOLLECTION') { echo '<br/><br/>'; echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"', 'class="add addGeom" value="', __("Add geometry"), '" />'; } echo '</div>'; echo '<!-- End of data section -->'; echo '<br/>'; echo '<input type="submit" name="gis_data[save]" value="', __('Go'), '" />'; echo '<div id="gis_data_output">'; echo '<h3>', __('Output'), '</h3>'; echo '<p>'; echo __('Choose "GeomFromText" from the "Function" column and paste the' . ' string below into the "Value" field.'); echo '</p>'; echo '<textarea id="gis_data_textarea" cols="95" rows="5">'; echo $result; echo '</textarea>'; echo '</div>'; echo '</div>'; echo '</form>'; PMA\libraries\Response::getInstance()->addJSON('gis_editor', ob_get_contents()); ob_end_clean();
/** * Displays SQL query before executing. * * @param array|string $query_data Array containing queries or query itself * * @return void */ function PMA_previewSQL($query_data) { $retval = '<div class="preview_sql">'; if (empty($query_data)) { $retval .= __('No change'); } elseif (is_array($query_data)) { foreach ($query_data as $query) { $retval .= PMA\libraries\Util::formatSql($query); } } else { $retval .= PMA\libraries\Util::formatSql($query_data); } $retval .= '</div>'; $response = PMA\libraries\Response::getInstance(); $response->addJSON('sql_data', $retval); exit; }
exit; } if ($_REQUEST['type'] == 'general') { $return = PMA_getJsonForLogDataTypeGeneral($start, $end); PMA\libraries\Response::getInstance()->addJSON('message', $return); exit; } } if (isset($_REQUEST['logging_vars'])) { $loggingVars = PMA_getJsonForLoggingVars(); PMA\libraries\Response::getInstance()->addJSON('message', $loggingVars); exit; } if (isset($_REQUEST['query_analyzer'])) { $return = PMA_getJsonForQueryAnalyzer(); PMA\libraries\Response::getInstance()->addJSON('message', $return); exit; } } /** * JS Includes */ $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('jquery/jquery.tablesorter.js'); $scripts->addFile('jquery/jquery.sortableTable.js'); $scripts->addFile('jquery/jquery-ui-timepicker-addon.js'); // for charting $scripts->addFile('jqplot/jquery.jqplot.js'); $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js'); $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
/** * Test for PMA_sendHeaderLocation * * @return void */ public function testSendHeaderLocationIisLongUri() { $GLOBALS['PMA_Config']->set('PMA_IS_IIS', true); // over 600 chars $testUri = 'http://testurl.com/test.php?testlonguri=over600chars&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test&test=test&test=test&test=test&test=test' . '&test=test&test=test'; $testUri_html = htmlspecialchars($testUri); $testUri_js = PMA_escapeJsString($testUri); $header = "<html><head><title>- - -</title>\n <meta http-equiv=\"expires\" content=\"0\">" . "<meta http-equiv=\"Pragma\" content=\"no-cache\">" . "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">" . "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri_html . "\">" . "<script type=\"text/javascript\">//<![CDATA[\n setTimeout(\"window.location = decodeURI('" . $testUri_js . "')\", 2000);\n //]]></script></head>\n<body><script type=\"text/javascript\">//<![CDATA[\n document.write('<p><a href=\"" . $testUri_html . "\">" . __('Go') . "</a></p>');\n //]]></script></body></html>\n"; $this->expectOutputString($header); $restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('disable', 'header', 'headersSent'))->getMock(); $mockResponse->expects($this->once())->method('disable'); $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false)); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); PMA_sendHeaderLocation($testUri); $attrInstance->setValue($restoreInstance); }
/** * Deal with Drops multiple databases * * @return null */ function PMA_dropMultiDatabases() { if (!isset($_REQUEST['selected_dbs']) && !isset($_REQUEST['query_type'])) { $message = Message::error(__('No databases selected.')); } else { $action = 'server_databases.php'; $submit_mult = 'drop_db'; $err_url = 'server_databases.php' . PMA_URL_getCommon(); if (isset($_REQUEST['selected_dbs']) && !isset($_REQUEST['is_js_confirmed'])) { $selected_db = $_REQUEST['selected_dbs']; } if (isset($_REQUEST['is_js_confirmed'])) { $_REQUEST = array('query_type' => $submit_mult, 'selected' => $_REQUEST['selected_dbs'], 'mult_btn' => __('Yes'), 'db' => $GLOBALS['db'], 'table' => $GLOBALS['table']); } //the following variables will be used on mult_submits.inc.php global $query_type, $selected, $mult_btn; include 'libraries/mult_submits.inc.php'; unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']); if (empty($message)) { if ($mult_btn == __('Yes')) { $number_of_databases = count($selected); } else { $number_of_databases = 0; } $message = Message::success(_ngettext('%1$d database has been dropped successfully.', '%1$d databases have been dropped successfully.', $number_of_databases)); $message->addParam($number_of_databases); } } if ($GLOBALS['is_ajax_request'] && $message instanceof PMA\libraries\Message) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus($message->isSuccess()); $response->addJSON('message', $message); exit; } }