$params['myparam'] = 'myvalue';
$params['db'] = 'mysql';
$params['table'] = 'rights';
note the missing ?
echo 'script.php' . URL::getCommon($params);
produces with cookies enabled:
script.php?myparam=myvalue&db=mysql&table=rights
with cookies disabled:
script.php?server=1&lang=en&myparam=myvalue&db=mysql
&table=rights
note the missing ?
echo 'script.php' . URL::getCommon();
produces with cookies enabled:
script.php
with cookies disabled:
script.php?server=1&lang=en
/** * Test for URL::getCommon with alternate divider * * @return void */ public function testWithAlternateDivider() { $GLOBALS['server'] = 'x'; $GLOBALS['collation_connection'] = 'x'; $GLOBALS['cfg']['ServerDefault'] = 'y'; $separator = URL::getArgSeparator(); $expected = 'server=x' . $separator . 'lang=en' . $separator . 'collation_connection=x'; $expected = '#ABC#db=db' . $separator . 'table=table' . $separator . $expected; $this->assertEquals($expected, URL::getCommonRaw(array('db' => 'db', 'table' => 'table'), '#ABC#')); }
*/ if (!isset($is_db) || !$is_db) { if (strlen($db) > 0) { $is_db = $GLOBALS['dbi']->selectDb($db); // This "Command out of sync" 2014 error may happen, for example // after calling a MySQL procedure; at this point we can't select // the db but it's not necessarily wrong if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) { $is_db = true; unset($GLOBALS['errno']); } } else { $is_db = false; } // Not a valid db name -> back to the welcome page $uri = './index.php' . URL::getCommonRaw(array()) . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'; if (strlen($db) === 0 || !$is_db) { $response = PMA\libraries\Response::getInstance(); if ($response->isAjax()) { $response->setRequestStatus(false); $response->addJSON('message', Message::error(__('No databases selected.'))); } else { PMA_sendHeaderLocation($uri); } exit; } } // end if (ensures db exists) /** * Changes database charset if requested by the user */
/** * Returns, as an array, a list of parameters * used on the client side * * @return array */ public function getJsParams() { $db = !empty($GLOBALS['db']) ? $GLOBALS['db'] : ''; $table = !empty($GLOBALS['table']) ? $GLOBALS['table'] : ''; $pftext = !empty($_SESSION['tmpval']['pftext']) ? $_SESSION['tmpval']['pftext'] : ''; // not sure when this happens, but it happens if (!isset($GLOBALS['collation_connection'])) { $GLOBALS['collation_connection'] = 'utf8_general_ci'; } $params = array('common_query' => URL::getCommonRaw(), 'opendb_url' => Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database'), 'safari_browser' => PMA_USR_BROWSER_AGENT == 'SAFARI' ? 1 : 0, 'collation_connection' => $GLOBALS['collation_connection'], 'lang' => $GLOBALS['lang'], 'server' => $GLOBALS['server'], 'table' => $table, 'db' => $db, 'token' => $_SESSION[' PMA_token '], 'text_dir' => $GLOBALS['text_dir'], 'show_databases_navigation_as_tree' => $GLOBALS['cfg']['ShowDatabasesNavigationAsTree'], 'pma_text_default_tab' => Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']), 'pma_text_left_default_tab' => Util::getTitleForTarget($GLOBALS['cfg']['NavigationTreeDefaultTabTable']), 'pma_text_left_default_tab2' => Util::getTitleForTarget($GLOBALS['cfg']['NavigationTreeDefaultTabTable2']), 'LimitChars' => $GLOBALS['cfg']['LimitChars'], 'pftext' => $pftext, 'confirm' => $GLOBALS['cfg']['Confirm'], 'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'], 'logged_in' => isset($GLOBALS['userlink']) ? true : false, 'PMA_VERSION' => PMA_VERSION); if (isset($GLOBALS['cfg']['Server']) && isset($GLOBALS['cfg']['Server']['auth_type'])) { $params['auth_type'] = $GLOBALS['cfg']['Server']['auth_type']; if (isset($GLOBALS['cfg']['Server']['user'])) { $params['user'] = $GLOBALS['cfg']['Server']['user']; } } return $params; }
/** * Redirects after saving new user preferences * * @param string $file_name Filename * @param array $params URL parameters * @param string $hash Hash value * * @return void */ function PMA_userprefsRedirect($file_name, $params = null, $hash = null) { // redirect $url_params = array('saved' => 1); if (is_array($params)) { $url_params = array_merge($params, $url_params); } if ($hash) { $hash = '#' . urlencode($hash); } PMA_sendHeaderLocation('./' . $file_name . URL::getCommonRaw($url_params) . $hash); }
$form_param = array_shift($forms_keys); } $form_display = new FormDisplay($cf); foreach ($forms[$form_param] as $form_name => $form) { // skip Developer form if no setting is available if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) { continue; } $form_display->registerForm($form_name, $form, 1); } if (isset($_POST['revert'])) { // revert erroneous fields to their default values $form_display->fixErrors(); // redirect $url_params = array('form' => $form_param); PMA_sendHeaderLocation('./prefs_forms.php' . URL::getCommonRaw($url_params)); exit; } $error = null; if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $result = PMA_saveUserprefs($cf->getConfigArray()); if ($result === true) { // reload config $GLOBALS['PMA_Config']->loadUserPreferences(); $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null; $hash = ltrim($tabHash, '#'); PMA_userprefsRedirect('prefs_forms.php', array('form' => $form_param), $hash); exit; } else { $error = $result;
/** * Prints javascript for upload with plugin, upload process bar * * @param int $upload_id The selected upload id * * @return string */ function PMA_getHtmlForImportWithPlugin($upload_id) { //some variable for javascript $ajax_url = "import_status.php?id=" . $upload_id . "&" . URL::getCommonRaw(array('import_status' => 1)); $promot_str = Sanitize::jsFormat(__('The file being uploaded is probably larger than ' . 'the maximum allowed size or this is a known bug in webkit ' . 'based (Safari, Google Chrome, Arora etc.) browsers.'), false); $statustext_str = Sanitize::escapeJsString(__('%s of %s')); $upload_str = Sanitize::jsFormat(__('Uploading your import file…'), false); $second_str = Sanitize::jsFormat(__('%s/sec.'), false); $remaining_min = Sanitize::jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); $remaining_second = Sanitize::jsFormat(__('About %SEC sec. remaining.'), false); $processed_str = Sanitize::jsFormat(__('The file is being processed, please be patient.'), false); $import_url = URL::getCommonRaw(array('import_status' => 1)); //start output $html = 'var finished = false; '; $html .= 'var percent = 0.0; '; $html .= 'var total = 0; '; $html .= 'var complete = 0; '; $html .= 'var original_title = ' . 'parent && parent.document ? parent.document.title : false; '; $html .= 'var import_start; '; $html .= 'var perform_upload = function () { '; $html .= 'new $.getJSON( '; $html .= ' "' . $ajax_url . '", '; $html .= ' {}, '; $html .= ' function(response) { '; $html .= ' finished = response.finished; '; $html .= ' percent = response.percent; '; $html .= ' total = response.total; '; $html .= ' complete = response.complete; '; $html .= ' if (total==0 && complete==0 && percent==0) { '; $img_tag = '<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif"'; $html .= ' $("#upload_form_status_info").html(\'' . $img_tag . ' width="16" height="16" alt="ajax clock" /> ' . $promot_str . '\'); '; $html .= ' $("#upload_form_status").css("display", "none"); '; $html .= ' } else { '; $html .= ' var now = new Date(); '; $html .= ' now = Date.UTC( '; $html .= ' now.getFullYear(), '; $html .= ' now.getMonth(), '; $html .= ' now.getDate(), '; $html .= ' now.getHours(), '; $html .= ' now.getMinutes(), '; $html .= ' now.getSeconds()) '; $html .= ' + now.getMilliseconds() - 1000; '; $html .= ' var statustext = PMA_sprintf('; $html .= ' "' . $statustext_str . '", '; $html .= ' formatBytes( '; $html .= ' complete, 1, PMA_messages.strDecimalSeparator'; $html .= ' ), '; $html .= ' formatBytes('; $html .= ' total, 1, PMA_messages.strDecimalSeparator'; $html .= ' ) '; $html .= ' ); '; $html .= ' if ($("#importmain").is(":visible")) { '; // show progress UI $html .= ' $("#importmain").hide(); '; $html .= ' $("#import_form_status") '; $html .= ' .html(\'<div class="upload_progress">' . '<div class="upload_progress_bar_outer"><div class="percentage">' . '</div><div id="status" class="upload_progress_bar_inner">' . '<div class="percentage"></div></div></div><div>' . '<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> ' . $upload_str . '</div><div id="statustext"></div></div>\') '; $html .= ' .show(); '; $html .= ' import_start = now; '; $html .= ' } '; $html .= ' else if (percent > 9 || complete > 2000000) { '; // calculate estimated time $html .= ' var used_time = now - import_start; '; $html .= ' var seconds = ' . 'parseInt(((total - complete) / complete) * used_time / 1000); '; $html .= ' var speed = PMA_sprintf("' . $second_str . '"'; $html .= ' , formatBytes(complete / used_time * 1000, 1,' . ' PMA_messages.strDecimalSeparator)); '; $html .= ' var minutes = parseInt(seconds / 60); '; $html .= ' seconds %= 60; '; $html .= ' var estimated_time; '; $html .= ' if (minutes > 0) { '; $html .= ' estimated_time = "' . $remaining_min . '"'; $html .= ' .replace("%MIN", minutes)'; $html .= ' .replace("%SEC", seconds); '; $html .= ' } '; $html .= ' else { '; $html .= ' estimated_time = "' . $remaining_second . '"'; $html .= ' .replace("%SEC", seconds); '; $html .= ' } '; $html .= ' statustext += "<br />" + speed + "<br /><br />" ' . '+ estimated_time; '; $html .= ' } '; $html .= ' var percent_str = Math.round(percent) + "%"; '; $html .= ' $("#status").animate({width: percent_str}, 150); '; $html .= ' $(".percentage").text(percent_str); '; // show percent in window title $html .= ' if (original_title !== false) { '; $html .= ' parent.document.title '; $html .= ' = percent_str + " - " + original_title; '; $html .= ' } '; $html .= ' else { '; $html .= ' document.title '; $html .= ' = percent_str + " - " + original_title; '; $html .= ' } '; $html .= ' $("#statustext").html(statustext); '; $html .= ' } '; $html .= ' if (finished == true) { '; $html .= ' if (original_title !== false) { '; $html .= ' parent.document.title = original_title; '; $html .= ' } '; $html .= ' else { '; $html .= ' document.title = original_title; '; $html .= ' } '; $html .= ' $("#importmain").hide(); '; // loads the message, either success or mysql error $html .= ' $("#import_form_status") '; $html .= ' .html(\'<img src="' . $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif" width="16" height="16" alt="ajax clock" /> ' . $processed_str . '\')'; $html .= ' .show(); '; $html .= ' $("#import_form_status").load("import_status.php?' . 'message=true&' . $import_url . '"); '; $html .= ' PMA_reloadNavigation(); '; // if finished $html .= ' } '; $html .= ' else { '; $html .= ' setTimeout(perform_upload, 1000); '; $html .= ' } '; $html .= '}); '; $html .= '}; '; $html .= 'setTimeout(perform_upload, 1000); '; return $html; }
$response = PMA\libraries\Response::getInstance(); if ($response->isAjax()) { $response->setRequestStatus(false); $response->addJSON('message', Message::error(__('No databases selected.'))); } else { $url_params = array('reload' => 1); if (isset($message)) { $url_params['message'] = $message; } if (!empty($sql_query)) { $url_params['sql_query'] = $sql_query; } if (isset($show_as_php)) { $url_params['show_as_php'] = $show_as_php; } PMA_sendHeaderLocation('./index.php' . URL::getCommonRaw($url_params)); } exit; } } } // end if (ensures db exists) if (empty($is_table) && !defined('PMA_SUBMIT_MULT') && !defined('TABLE_MAY_BE_ABSENT')) { // Not a valid table name -> back to the db_sql.php if (strlen($table) > 0) { $is_table = $GLOBALS['dbi']->getCachedTableContent(array($db, $table), false); if (!$is_table) { $_result = $GLOBALS['dbi']->tryQuery('SHOW TABLES LIKE \'' . $GLOBALS['dbi']->escapeString($table) . '\';', null, PMA\libraries\DatabaseInterface::QUERY_STORE); $is_table = @$GLOBALS['dbi']->numRows($_result); $GLOBALS['dbi']->freeResult($_result); }
/** * Returns the url of the current page * * @return string */ public function getSelfUrl() { $db = !empty($GLOBALS['db']) ? $GLOBALS['db'] : ''; $table = !empty($GLOBALS['table']) ? $GLOBALS['table'] : ''; $target = !empty($_REQUEST['target']) ? $_REQUEST['target'] : ''; $params = array('db' => $db, 'table' => $table, 'server' => $GLOBALS['server'], 'target' => $target); // needed for server privileges tabs if (isset($_REQUEST['viewing_mode']) && in_array($_REQUEST['viewing_mode'], array('server', 'db', 'table'))) { $params['viewing_mode'] = $_REQUEST['viewing_mode']; } /* * @todo coming from server_privileges.php, here $db is not set, * add the following condition below when that is fixed * && $_REQUEST['checkprivsdb'] == $db */ if (isset($_REQUEST['checkprivsdb'])) { $params['checkprivsdb'] = $_REQUEST['checkprivsdb']; } /* * @todo coming from server_privileges.php, here $table is not set, * add the following condition below when that is fixed * && $_REQUEST['checkprivstable'] == $table */ if (isset($_REQUEST['checkprivstable'])) { $params['checkprivstable'] = $_REQUEST['checkprivstable']; } if (isset($_REQUEST['single_table']) && in_array($_REQUEST['single_table'], array(true, false))) { $params['single_table'] = $_REQUEST['single_table']; } return basename(PMA_getenv('SCRIPT_NAME')) . URL::getCommonRaw($params); }
/** * Stores user credentials after successful login. * * @return void|bool */ public function storeUserCredentials() { global $cfg; // Name and password cookies need to be refreshed each time // Duration = one month for username $this->storeUsernameCookie($cfg['Server']['user']); // Duration = as configured // Do not store password cookie on password change as we will // set the cookie again after password has been changed if (!isset($_POST['change_pw'])) { $this->storePasswordCookie($cfg['Server']['password']); } // Set server cookies if required (once per session) and, in this case, // force reload to ensure the client accepts cookies if (!$GLOBALS['from_cookie']) { // URL where to go: $redirect_url = './index.php'; // any parameters to pass? $url_params = array(); if (strlen($GLOBALS['db']) > 0) { $url_params['db'] = $GLOBALS['db']; } if (strlen($GLOBALS['table']) > 0) { $url_params['table'] = $GLOBALS['table']; } // any target to pass? if (!empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') { $url_params['target'] = $GLOBALS['target']; } /** * Clear user cache. */ Util::clearUserCache(); Response::getInstance()->disable(); PMA_sendHeaderLocation($redirect_url . URL::getCommonRaw($url_params), true); if (!defined('TESTSUITE')) { exit; } else { return false; } } // end if return true; }
/** * 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('./server_replication.php' . URL::getCommonRaw($GLOBALS['url_params'])); } } unset($refresh); } }
$state = 'config_not_saved'; } else { $state = 'config_saved'; } header('HTTP/1.1 303 See Other'); header('Location: index.php' . URL::getCommonRaw() . '&action_done=' . $state); exit; } elseif (PMA_ifSetOr($_POST['submit_load'], '')) { // // Load config file from the server // $GLOBALS['ConfigFile']->setConfigData(loadConfig($config_file_path)); header('HTTP/1.1 303 See Other'); header('Location: index.php' . URL::getCommonRaw()); exit; } elseif (PMA_ifSetOr($_POST['submit_delete'], '')) { // // Delete config file on the server // @unlink($config_file_path); header('HTTP/1.1 303 See Other'); header('Location: index.php' . URL::getCommonRaw()); exit; } else { // // Show generated config file in a <textarea> // header('HTTP/1.1 303 See Other'); header('Location: index.php' . URL::getCommonRaw() . '&page=config'); exit; }
/** * Generate header for 303 * * @return void */ function PMA_generateHeader303() { // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php' . URL::getCommonRaw()); if (!defined('TESTSUITE')) { exit; } }
} /** * Core libraries. */ require_once './setup/lib/form_processing.lib.php'; require './libraries/config/setup.forms.php'; $mode = isset($_GET['mode']) ? $_GET['mode'] : null; $id = PMA_isValid($_GET['id'], 'numeric') ? intval($_GET['id']) : null; /** @var ConfigFile $cf */ $cf = $GLOBALS['ConfigFile']; $server_exists = !empty($id) && $cf->get("Servers/{$id}") !== null; if ($mode == 'edit' && $server_exists) { $page_title = __('Edit server') . ' ' . $id . ' <small>(' . htmlspecialchars($cf->getServerDSN($id)) . ')</small>'; } elseif ($mode == 'remove' && $server_exists) { $cf->removeServer($id); header('Location: index.php' . URL::getCommonRaw()); exit; } elseif ($mode == 'revert' && $server_exists) { // handled by process_formset() } else { $page_title = __('Add a new server'); $id = 0; } if (isset($page_title)) { echo '<h2>', $page_title . '</h2>'; } $form_display = new FormDisplay($cf); foreach ($forms['Servers'] as $form_name => $form) { $form_display->registerForm($form_name, $form, $id); } PMA_Process_formset($form_display);
/** * Get delete and kill links * * @param string $where_clause the where clause of the sql * @param boolean $clause_is_unique the unique condition of clause * @param string $url_sql_query the analyzed sql query * @param string $del_lnk the delete link of current row * @param array $row the current row * * @return array 3 element array * $del_url, $del_str, $js_conf * * @access private * * @see _getTableBody() */ private function _getDeleteAndKillLinks($where_clause, $clause_is_unique, $url_sql_query, $del_lnk, $row) { $goto = $this->__get('goto'); if ($del_lnk == self::DELETE_ROW) { // delete row case $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $url_sql_query, 'message_to_show' => __('The row has been deleted.'), 'goto' => empty($goto) ? 'tbl_sql.php' : $goto); $lnk_goto = 'sql.php' . URL::getCommonRaw($_url_params); $del_query = 'DELETE FROM ' . Util::backquote($this->__get('table')) . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1'); $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $del_query, 'message_to_show' => __('The row has been deleted.'), 'goto' => $lnk_goto); $del_url = 'sql.php' . URL::getCommon($_url_params); $js_conf = 'DELETE FROM ' . Sanitize::jsFormat($this->__get('table')) . ' WHERE ' . Sanitize::jsFormat($where_clause, false) . ($clause_is_unique ? '' : ' LIMIT 1'); $del_str = $this->_getActionLinkContent('b_drop.png', __('Delete')); } elseif ($del_lnk == self::KILL_PROCESS) { // kill process case $_url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $url_sql_query, 'goto' => 'index.php'); $lnk_goto = 'sql.php' . URL::getCommonRaw($_url_params); $kill = $GLOBALS['dbi']->getKillQuery($row[0]); $_url_params = array('db' => 'mysql', 'sql_query' => $kill, 'goto' => $lnk_goto); $del_url = 'sql.php' . URL::getCommon($_url_params); $js_conf = $kill; $del_str = Util::getIcon('b_drop.png', __('Kill')); } else { $del_url = $del_str = $js_conf = null; } return array($del_url, $del_str, $js_conf); }