diff --git a/libraries/bookmark.lib.php b/libraries/bookmark.lib.php index d2d5aecf7c..ef126232bc 100644 --- a/libraries/bookmark.lib.php +++ b/libraries/bookmark.lib.php @@ -138,8 +138,8 @@ function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = fal /** * Adds a bookmark * - * @param array $fields the properties of the bookmark to add; here, - * $fields['query'] is urlencoded + * @param array $bkm_fields the properties of the bookmark to add; here, + * $bkm_fields['bkm_sql_query'] is urlencoded * @param boolean $all_users whether to make the bookmark available for all users * * @return boolean whether the INSERT succeeds or not @@ -148,7 +148,7 @@ function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = fal * * @global resource the controluser db connection handle */ -function PMA_Bookmark_save($fields, $all_users = false) +function PMA_Bookmark_save($bkm_fields, $all_users = false) { global $controllink; @@ -161,10 +161,10 @@ function PMA_Bookmark_save($fields, $all_users = false) $query = 'INSERT INTO ' . PMA_Util::backquote($cfgBookmark['db']) . '.' . PMA_Util::backquote($cfgBookmark['table']) . ' (id, dbase, user, query, label)' - . ' VALUES (NULL, \'' . PMA_Util::sqlAddSlashes($fields['dbase']) . '\', ' - . '\'' . ($all_users ? '' : PMA_Util::sqlAddSlashes($fields['user'])) . '\', ' - . '\'' . PMA_Util::sqlAddSlashes(urldecode($fields['query'])) . '\', ' - . '\'' . PMA_Util::sqlAddSlashes($fields['label']) . '\')'; + . ' VALUES (NULL, \'' . PMA_Util::sqlAddSlashes($bkm_fields['bkm_database']) . '\', ' + . '\'' . ($all_users ? '' : PMA_Util::sqlAddSlashes($bkm_fields['bkm_user'])) . '\', ' + . '\'' . PMA_Util::sqlAddSlashes(urldecode($bkm_fields['bkm_sql_query'])) . '\', ' + . '\'' . PMA_Util::sqlAddSlashes($bkm_fields['bkm_label']) . '\')'; return $GLOBALS['dbi']->query($query, $controllink); } // end of the 'PMA_Bookmark_save()' function diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 759367fcd2..14a8b11391 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -2913,4 +2913,18 @@ function PMA_SQP_isKeyWord($column) return in_array(strtoupper($column), $PMA_SQPdata_forbidden_word); } +/** + * Checks whether a given query is to drop a database + * + * @param string $sql_query The SQL query to be checked for drop database + * + * @return boolean whether true or false + */ +function PMA_isDropDatabase($sql_query) +{ + return preg_match( + '/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i', + $sql_query + ); +} ?> diff --git a/sql.php b/sql.php index 5c57a3d8d9..1e99d8b057 100644 --- a/sql.php +++ b/sql.php @@ -17,6 +17,7 @@ require_once 'libraries/Header.class.php'; require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/bookmark.lib.php'; require_once 'libraries/sql.lib.php'; +require_once 'libraries/sqlparser.lib.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); @@ -35,42 +36,6 @@ if (isset($ajax_reload) && $ajax_reload['reload'] === true) { $response->addJSON('ajax_reload', $ajax_reload); } -/** - * Sets globals from $_POST - */ -$post_params = array( - 'bkm_all_users', - 'fields', - 'store_bkm' -); -foreach ($post_params as $one_post_param) { - if (isset($_POST[$one_post_param])) { - $GLOBALS[$one_post_param] = $_POST[$one_post_param]; - } -} - -/** - * Sets globals from $_GET - */ -$get_params = array( - 'id_bookmark', - 'label', - 'sql_query' -); -foreach ($get_params as $one_get_param) { - if (isset($_GET[$one_get_param])) { - $GLOBALS[$one_get_param] = $_GET[$one_get_param]; - } -} - - -if (isset($_REQUEST['printview'])) { - $GLOBALS['printview'] = $_REQUEST['printview']; -} - -if (!isset($_SESSION['is_multi_query'])) { - $_SESSION['is_multi_query'] = false; -} /** * Defines the url to return to in case of error in a sql statement @@ -102,13 +67,15 @@ if (! isset($err_url)) { } // end if // Coming from a bookmark dialog -if (isset($fields['query'])) { - $sql_query = $fields['query']; +if (isset($_POST['bkm_fields']['bkm_sql_query'])) { + $sql_query = $_POST['bkm_fields']['bkm_sql_query']; +} elseif (isset($_GET['sql_query'])) { + $sql_query = $_GET['sql_query']; } // This one is just to fill $db -if (isset($fields['dbase'])) { - $db = $fields['dbase']; +if (isset($_POST['bkm_fields']['bkm_database'])) { + $db = $_POST['bkm_fields']['bkm_database']; } @@ -232,12 +199,6 @@ if (empty($sql_query) && strlen($table) && strlen($db)) { PMA_Util::checkParameters(array('sql_query')); } -// instead of doing the test twice -$is_drop_database = preg_match( - '/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i', - $sql_query -); - /** * Check rights in case of DROP DATABASE * @@ -247,7 +208,7 @@ $is_drop_database = preg_match( */ if (! defined('PMA_CHK_DROP') && ! $cfg['AllowUserDropDatabase'] - && $is_drop_database + && PMA_isDropDatabase($sql_query) && ! $is_superuser ) { PMA_Util::mysqlDie( @@ -283,16 +244,16 @@ if (isset($find_real_end) && $find_real_end) { /** * Bookmark add */ -if (isset($store_bkm)) { +if (isset($_POST['store_bkm'])) { $result = PMA_Bookmark_save( - $fields, - (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false) + $_POST['bkm_fields'], + (isset($_POST['bkm_all_users']) && $_POST['bkm_all_users'] == 'true' ? true : false) ); $response = PMA_Response::getInstance(); if ($response->isAjax()) { if ($result) { $msg = PMA_message::success(__('Bookmark %s created')); - $msg->addParam($fields['label']); + $msg->addParam($_POST['bkm_fields']['bkm_label']); $response->addJSON('message', $msg); } else { $msg = PMA_message::error(__('Bookmark not created')); @@ -303,7 +264,7 @@ if (isset($store_bkm)) { } else { // go back to sql.php to redisplay query; do not use & in this case: PMA_sendHeaderLocation( - $cfg['PmaAbsoluteUri'] . $goto . '&label=' . $fields['label'] + $cfg['PmaAbsoluteUri'] . $goto . '&label=' . $_POST['bkm_fields']['bkm_label'] ); } } // end if @@ -344,98 +305,6 @@ if (isset($_REQUEST['btnDrop']) && $_REQUEST['btnDrop'] == __('No')) { exit(); } // end if - -/** - * Displays the confirm page if required - * - * This part of the script is bypassed if $is_js_confirmed = 1 (already checked - * with js) because possible security issue is not so important here: at most, - * the confirm message isn't displayed. - * - * Also bypassed if only showing php code.or validating a SQL query - */ -// if we are coming from a "Create PHP code" or a "Without PHP Code" -// dialog, we won't execute the query anyway, so don't confirm -if (! $cfg['Confirm'] - || isset($_REQUEST['is_js_confirmed']) - || isset($_REQUEST['btnDrop']) - || isset($GLOBALS['show_as_php']) - || ! empty($GLOBALS['validatequery']) -) { - $do_confirm = false; -} else { - $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']); -} - -if ($do_confirm) { - $stripped_sql_query = $sql_query; - $input = ''; - $output = ''; - if ($is_drop_database) { - $output .= '