From 0a9c4fc3eb259a6a85bea16704a32f116a3fde1a Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Tue, 11 Apr 2006 15:13:22 +0000 Subject: [PATCH] never rush a checkin - its allways trouble --- libraries/Table.class.php | 452 +----------- server_privileges.php | 1298 ++++++++++++++++----------------- tbl_properties_operations.php | 45 +- 3 files changed, 675 insertions(+), 1120 deletions(-) diff --git a/libraries/Table.class.php b/libraries/Table.class.php index ee6ad22d5..686db7221 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -1,25 +1,6 @@ getName(); } - function getOptions($engine = null) - { - if (null === $engine) { - $engine = $this->getEnginge(); - } - - $options = array(); - $all_options = PMA_Table::getAlterOptions(); - - if (($engine === 'myisam' || $engine === 'isam')) { - $options['KEYS'] = $all_options['KEYS']; - } - - if (($engine === 'myisam')) { - $options['checksum'] = $all_options['KEYS']; - $options['delay_key_write'] = $all_options['KEYS']; - } - - if (($engine === 'myisam' || $engine === 'innodb')) { - $options['auto_increment'] = $all_options['KEYS']; - } - } - - /** - * returns all available options for any table engine - * - * @todo update with mysql manual, last: ??? - * @static - */ - function getAlterOptions() - { - static $options = null; - - if (null === $options) { - $options = array( - // ENABLE/DISABLE KEY - // skipped, makes no sense here - 'COMMENT' => array( - 'type' => 'string', - 'name' => 'strTableComment', - ), - 'TYPE' => array( - 'type' => 'string', - 'values' => array('PMA_Table', 'getEngines'), - 'name' => 'strTableEngine', - ), - 'DEFAULT_CHARSET_COLLATION' => array( - 'type' => 'string', - 'desc' => 'strTableCharset', - ), - 'pack_keys' => array( - 'type' => 'string', - 'name' => 'pack_keys', - 'desc' => '', - 'engines' => array( - PMA_DBI_ENGINE_MYISAM, - PMA_DBI_ENGINE_ISAM, - ), - ), - 'checksum' => array( - 'type' => 'string', - 'name' => 'checksum', - 'engines' => array( - PMA_DBI_ENGINE_MYISAM, - ), - ), - 'delay_key_write' => array( - 'type' => 'string', - 'name' => 'delay_key_write', - 'engines' => array( - PMA_DBI_ENGINE_MYISAM, - ), - ), - 'auto_increment' => array( - 'type' => 'int', - 'name' => 'auto_increment', - 'engines' => array( - PMA_DBI_ENGINE_MYISAM, - PMA_DBI_ENGINE_INNODB, - ), - ), - ); - } - - return $options; - } - - function setEngine($engine) - { - $this->set('ENGINE', $engine); - } - - function getEngine() - { - return $this->get('ENGINE'); - } - - /** - * @todo update with mysql manual, last: ??? - */ - function getEngineName($engine = null) - { - if (null === $engine) { - $engine = $this->getEngine(); - } - - switch ($engine) { - case PMA_DBI_ENGINE_MYISAM : - return 'MyISAM'; - break; - case PMA_DBI_ENGINE_ISAM : - return 'ISAM'; - break; - case PMA_DBI_ENGINE_INNODB : - return 'InnoDB'; - break; - case PMA_DBI_ENGINE_MERGE : - return 'Merge'; - break; - case PMA_DBI_ENGINE_MEMORY : - return 'MEMORY'; - break; - case PMA_DBI_ENGINE_HEAP : - return 'HEAP'; - break; - case PMA_DBI_ENGINE_BDB : - return 'BerkeleyDB'; - break; - default : - return 'UNKNOWN'; - } - } - function getLastError() { return end($this->errors); @@ -296,203 +144,33 @@ class PMA_Table { } /** - * sets given $value for given $option + * sets given $value for given $param * - * @uses $this->options to add or change value - * @param string $option option name - * @param mixed $value option value + * @uses $this->settings to add or change value + * @param string param name + * @param mixed param value */ - function set($option, $value) + function set($param, $value) { - $this->options[$option]->value = $value; - } - - /** - * @static - * @param string $option - * @param mixed $value - * @return string - */ - function getAlterOption($option, $value) { - switch ($option) { - case 'KEYS' : - return ($value ? 'ENABLE' : 'DISABLE') . ' KEYS'; - break; - case 'TABLESPACE' : - return ($value ? 'IMPORT' : 'DISCARD') . ' TABLESPACE'; - break; - case 'RENAME TO' : - case 'RENAME' : - case 'CHECK' : - case 'ORDER BY' : - return $option . ' ' . $value; - break; - case 'PACK_KEYS' : - //{0 | 1 | DEFAULT} - case 'CHECKSUM' : - case 'DELAY_KEY_WRITE' : - return $option . ' = ' . (int) (bool) $value; - break; - case 'CONVERT CHARACTER SET' : - return 'CONVERT ' . PMA_generateCharsetQueryPart($value); - break; - case 'TABLE_COLLATION' : - case 'DEFAULT CHARACTER SET' : - return 'DEFAULT ' . PMA_generateCharsetQueryPart($value); - break; - case 'CHARACTER SET' : - return PMA_generateCharsetQueryPart($value); - break; - case 'INSERT_METHOD' : - //{ NO | FIRST | LAST } - case 'UNION' : - case 'ROW_FORMAT' : - //{DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} - case 'MIN_ROWS' : - case 'MAX_ROWS' : - case 'AVG_ROW_LENGTH' : - case 'ENGINE' : - case 'TYPE' : - case 'AUTO_INCREMENT' : - return $option . ' = ' . $value; - break; - case 'CONNECTION' : - case 'INDEX DIRECTORY' : - case 'DATA DIRECTORY' : - case 'CONNECTION' : - return $option . ' = \'' . PMA_sqlAddslashes($value) . '\''; - break; - case 'TABLE_COMMENT' : - case 'COMMENT' : - return 'COMMENT = \'' . PMA_sqlAddslashes($value) . '\''; - break; - default : - return '-- UNKNOWN OPTION: ' . $option . ' = \'' . PMA_sqlAddslashes($value) . '\''; - } - } - - /** - * set options from given array of options - * - * @param array $options - * @return boolean success - */ - function setOptions($options, $bc = false) - { - if ($bc) { - // backward compatibility - $new_engine = strtolower($this->get('ENGINE')); - $bc_options = $options; - $options = array(); - if (null !== $this->get('TABLE_COMMENT') - && isset($bc_options['comment'])) { - $options['TABLE_COMMENT'] = $bc_options['comment']; - } - if (isset($bc_options['new_tbl_type']) - && ! $this->isEngineOneOf($bc_options['new_tbl_type'])) { - $options['ENGINE'] = $bc_options['new_tbl_type']; - $new_engine = strtolower($options['ENGINE']); - } elseif (null !== $this->get('TYPE') - && isset($bc_options['new_tbl_type'])) { - $options['TYPE'] = $bc_options['new_tbl_type']; - } - if (null !== $this->get('TABLE_COLLATION') - && isset($bc_options['tbl_collation'])) { - $options['TABLE_COLLATION'] = $bc_options['tbl_collation']; - } - - //if (null !== $this->get('PACK_KEYS')) { - if ($new_engine === 'myisam' || $new_engine === 'isam') { - $options['PACK_KEYS'] = (int) !empty($bc_options['new_pack_keys']); - } - //if (null !== $this->get('CHECKSUM')) { - if ($new_engine === 'myisam') { - $options['CHECKSUM'] = (int) !empty($bc_options['new_checksum']); - } - //if (null !== $this->get('DELAY_KEY_WRITE')) { - if ($new_engine === 'myisam') { - $options['DELAY_KEY_WRITE'] = (int) !empty($bc_options['new_delay_key_write']); - } - //if (null !== $this->get('AUTO_INCREMENT') - // && isset($bc_options['new_auto_increment'])) { - if (isset($bc_options['new_auto_increment']) - && ($new_engine === 'myisam' - // MEMORY in 4.1.0 - || ($new_engine === 'memory' && PMA_MYSQL_INT_VERSION >= 40100) - // InnoDB in 4.1.2 and 5.0.3 - || ($new_engine === 'innodb' && PMA_MYSQL_INT_VERSION >= 40102))) { - $options['AUTO_INCREMENT'] = (int) $bc_options['new_auto_increment']; - } - } - - $table_alters = array(); - - foreach ($options as $option => $value) { - if ($this->get($option) != $value) { - $table_alters[] = PMA_Table::getAlterOption($option, $value); - } - } - - if (count($table_alters)) { - $sql_query = ' - ALTER TABLE ' . $this->getFullName(true) . ' - ' . implode("\r\n", $table_alters); - if (! PMA_DBI_try_query($sql_query)) { - $this->errors[] = $GLOBALS['strError']; - return false; - } - - // display executed query in user interface - if (! isset($GLOBALS['sql_query'])) { - $GLOBALS['sql_query'] = ''; - } - $GLOBALS['sql_query'] .= "\r\n" . $sql_query . ';'; - $this->messages[] = $GLOBALS['strSuccess']; - } - - return true; + $this->settings[$param] = $value; } /** * returns value for given setting/param * - * @uses $this->options to return value - * @param string $option name for value to return - * @return mixed value for $option + * @uses $this->settings to return value + * @param string name for value to return + * @return mixed value for $param */ - function get($option) + function get($param) { - if (isset($this->options[$option])) { - return $this->options[$option]->value; + if (isset($this->settings[$param])) { + return $this->settings[$param]; } return null; } - /** - * cleans 'InnoDB free'-string from table comment - */ - function cleanInnodbComment($comment = null) - { - $return = true; - - if (null === $comment) { - if (! $this->isEngineOneOf('innodb')) { - return; - } - $comment = $this->get('TABLE_COMMENT'); - $return = false; - } - - $comment = preg_replace('/(; InnoDB free: .*$)/i', '', $comment); - - if ($return) { - return $comment; - } else { - $this->set('TABLE_COMMENT', $comment); - } - } - /** * loads structure data */ @@ -504,96 +182,25 @@ class PMA_Table { return false; } - foreach ($table_info[$this->getName()] as $key => $value) { - $this->options[$key]->value = $value; - } + $this->settings = $table_info; - $this->cleanInnodbComment(); - - /** - * init some values, check if they exists, if not create them with - * standard values - */ if ($this->get('TABLE_ROWS') === null) { $this->set('TABLE_ROWS', PMA_Table::countRecords($this->getDbName(), $this->getName(), true, true)); } - /* - if (null === $this->get('AUTO_INCREMENT') - && ($this->isEngineOneOf('myisam') - // MEMORY in 4.1.0 - || ($this->isEngineOneOf('memory') && PMA_MYSQL_INT_VERSION >= 40100) - // InnoDB in 4.1.2 and 5.0.3 - || ($this->isEngineOneOf('innodb') && PMA_MYSQL_INT_VERSION >= 40102))) { - $this->set('AUTO_INCREMENT', 0); - } else { - // do not support this option on others than MyISAM or ISAM - $this->removeOption('AUTO_INCREMENT'); - } - - if (null === $this->get('PACK_KEYS') - && $this->isEngineOneOf('myisam', 'isam')) { - $this->set('PACK_KEYS', 'DEFAULT'); - echo __LINE__; - } elseif (null !== $this->get('PACK_KEYS')) { - // do not support this option on others than MyISAM or ISAM - $this->removeOption('PACK_KEYS'); - echo __LINE__; - } - - if (null === $this->get('CHECKSUM') - && $this->isEngineOneOf('myisam')) { - $this->set('CHECKSUM', 0); - } else { - // do not support this option on others than MyISAM - $this->removeOption('CHECKSUM'); - } - - if (null === $this->get('DELAY_KEY_WRITE') - && $this->isEngineOneOf('myisam')) { - $this->set('DELAY_KEY_WRITE', 0); - } else { - // do not support this option on others than MyISAM - $this->removeOption('DELAY_KEY_WRITE'); - } - */ - - $create_options = explode(' ', $this->get('CREATE_OPTIONS')); + $create_options = explode(' ', $this->get('TABLE_ROWS')); // export create options by its name as variables into gloabel namespace // f.e. pack_keys=1 becomes available as $pack_keys with value of '1' foreach ($create_options as $each_create_option) { $each_create_option = explode('=', $each_create_option); if (isset($each_create_option[1])) { - $this->set(strtoupper($each_create_option[0]), $each_create_option[1]); + $this->set($$each_create_option[0], $each_create_option[1]); } } } - function removeOption($option) - { - if (isset($this->options[$option])) { - unset($this->options[$option]); - } - } - - /** - * - * @param string $engine,... engine - * @return boolean whether one of the given engines is equal with current engine - */ - function isEngineOneOf() - { - foreach (func_get_args() as $engine) { - if (strtolower($this->getEngine()) === strtolower($engine)) { - return true; - } - } - - return false; - } - /** * old PHP 4style constructor * @@ -889,6 +496,7 @@ class PMA_Table { return true; } // end of 'PMA_Table::duplicateInfo()' function + /** * Copies or renames table * FIXME: use RENAME @@ -1260,21 +868,15 @@ class PMA_Table { return false; } - $sql_query = ' + $GLOBALS['sql_query'] = ' RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; - if (! PMA_DBI_query($sql_query)) { + if (! PMA_DBI_query($GLOBALS['sql_query'])) { // TODO add $GLOBALS['strErrorRenamingTable']; $this->errors[] = $GLOBALS['strError'] . ': ' . $new_table->getFullName(); return false; } - // display executed query in user interface - if (! isset( $GLOBALS['sql_query'])) { - $GLOBALS['sql_query'] = ''; - } - $GLOBALS['sql_query'] .= "\n\n" . $sql_query; - $old_name = $this->getName(); $old_db = $this->getDbName(); $this->setName($new_name); diff --git a/server_privileges.php b/server_privileges.php index 8f014b42a..443769860 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -2,107 +2,48 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: -if (! defined('PMA_NO_VARIABLES_IMPORT')) { - define('PMA_NO_VARIABLES_IMPORT', true); -} -require_once './libraries/common.lib.php'; +require_once('./libraries/common.lib.php'); /** * Does the common work */ $js_to_run = 'server_privileges.js'; -require './libraries/server_common.inc.php'; - - -/** - * Checks if the user is allowed to do what he tries to... - */ -if (!$is_superuser) { - require './libraries/server_links.inc.php'; - echo '

' . "\n" - . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') - . $GLOBALS['strPrivileges'] . "\n" - . '

' . "\n" - . $GLOBALS['strNoPrivileges'] . "\n"; - require_once './libraries/footer.inc.php'; -} +require('./libraries/server_common.inc.php'); /** * Checks if a dropdown box has been used for selecting a database / table */ -if (isset($_REQUEST['pred_dbname']) && strlen($_REQUEST['pred_dbname'])) { - $dbname = $_REQUEST['pred_dbname']; - unset($_REQUEST['pred_dbname']); -} elseif (isset($_REQUEST['dbname']) && strlen($_REQUEST['dbname'])) { - $dbname = $_REQUEST['dbname']; - unset($_REQUEST['dbname']); -} else { - $dbname = ''; +if (isset($pred_dbname) && strlen($pred_dbname)) { + $dbname = $pred_dbname; + unset($pred_dbname); +} +if (isset($pred_tablename) && strlen($pred_tablename)) { + $tablename = $pred_tablename; + unset($pred_tablename); } -if (isset($_REQUEST['pred_tablename']) && strlen($_REQUEST['pred_tablename'])) { - $tablename = $_REQUEST['pred_tablename']; - unset($_REQUEST['pred_tablename']); -} else { - $tablename = ''; -} - -/** - * check if given $dbname is a wildcard or not - */ -//if (preg_match('/\\\\(?:_|%)/i', $dbname)) { -//if (preg_match('/(?' . "\n" + . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') + . $GLOBALS['strPrivileges'] . "\n" + . '' . "\n" + . $GLOBALS['strNoPrivileges'] . "\n"; + require_once('./libraries/footer.inc.php'); } /** @@ -111,10 +52,9 @@ function PMA_addUSerTablePrivs(&$user_privs) * @param string the user's initial * @return string the generated condition */ -function PMA_RangeOfUsers($initial = '') -{ - // strtolower() is used because the User field - // might be BINARY, so LIKE would be case sensitive +function PMA_RangeOfUsers($initial = '') { +// strtolower() is used because the User field +// might be BINARY, so LIKE would be case sensitive if (!empty($initial)) { $ret = " WHERE " . PMA_convert_using('User') . " LIKE " . PMA_convert_using($initial . '%', 'quoted') @@ -136,7 +76,7 @@ function PMA_RangeOfUsers($initial = '') * * @return array */ -function PMA_extractPrivInfo($row = '', $enableHTML = false) +function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) { $grants = array( array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']), @@ -174,10 +114,24 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) $grants[] = array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']); } - PMA_addUSerTablePrivs($row); - + if (!empty($row) && isset($row['Table_priv'])) { + $res = PMA_DBI_query( + 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', + $GLOBALS['userlink'] ); + $row1 = PMA_DBI_fetch_assoc($res); + PMA_DBI_free_result($res); + $av_grants = explode ('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7)); + unset($row1); + $users_grants = explode(',', $row['Table_priv']); + foreach ($av_grants as $current_grant) { + $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; + } + unset($current_grant); + unset($av_grants); + unset($users_grants); + } $privs = array(); - $allPrivileges = true; + $allPrivileges = TRUE; foreach ($grants as $current_grant) { if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) { if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'] && empty($GLOBALS[$current_grant[0] . '_none']))))) { @@ -194,7 +148,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) } $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)'; } else { - $allPrivileges = false; + $allPrivileges = FALSE; } } } @@ -218,36 +172,27 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) /** * Displays on which column(s) a table-specific privilege is granted */ -function PMA_display_column_privs($spaces, $columns, $row, $name_for_select, - $priv_for_header, $name, $name_for_dfn, $name_for_current) -{ - $spaces .= ' '; - echo $spaces . '
' . "\n" - . $spaces . ' ' . "\n" - . $spaces . ' ' . "\n"; + + foreach ($columns as $current_column => $current_column_privileges) { + echo $spaces . ' ' . "\n"; } - echo '>' . htmlspecialchars($current_column) . '' . "\n"; - } - echo $spaces . ' ' . "\n" - . $spaces . ' ' . $GLOBALS['strOr'] . '' . "\n" - . $spaces . ' ' . "\n" - . $spaces . '
' . "\n"; + echo $spaces . ' ' . "\n" + . $spaces . ' ' . $GLOBALS['strOr'] . '' . "\n" + . $spaces . ' ' . "\n" + . $spaces . ' ' . "\n"; } // end function /** @@ -263,50 +208,54 @@ function PMA_display_column_privs($spaces, $columns, $row, $name_for_select, * * @return void */ -function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = 0) +function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0) { if ($db == '*') { $table = '*'; } - $spaces = str_repeat(' ', $indent); + $spaces = str_repeat( ' ', $indent ); - if (isset($_REQUEST['username'])) { + if (isset($GLOBALS['username'])) { + $username = $GLOBALS['username']; + $hostname = $GLOBALS['hostname']; if ($db == '*') { $sql_query = 'SELECT * FROM `mysql`.`user`' .' WHERE ' . PMA_convert_using('User') - .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') .' AND ' . PMA_convert_using('Host') - .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted') . ';'; + .' = ' . PMA_convert_using($hostname, 'quoted') . ';'; } elseif ($table == '*') { $sql_query = 'SELECT * FROM `mysql`.`db`' .' WHERE ' . PMA_convert_using('`User`') - .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') .' AND ' . PMA_convert_using('`Host`') - .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted') - .' AND ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted') - .' LIKE ' . PMA_convert_using('`Db`') . ';'; + .' = ' . PMA_convert_using($hostname, 'quoted') + .' AND ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' ) + .' LIKE ' . PMA_convert_using( '`Db`' ) . ';'; } else { $sql_query = 'SELECT `Table_priv`' .' FROM `mysql`.`tables_priv`' .' WHERE ' . PMA_convert_using('`User`') - .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') .' AND ' .PMA_convert_using('`Host`') - .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted') + .' = ' . PMA_convert_using( $hostname, 'quoted' ) .' AND ' .PMA_convert_using('`Db`') - .' = ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted') + .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' ) .' AND ' . PMA_convert_using('`Table_name`') .' = ' . PMA_convert_using($table, 'quoted') . ';'; } - $row = PMA_DBI_fetch_single_row($sql_query); + $res = PMA_DBI_query($sql_query); + $row = PMA_DBI_fetch_assoc($res); + PMA_DBI_free_result($res); } if (empty($row)) { if ($table == '*') { if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; - } else { + } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } $res = PMA_DBI_query($sql_query); @@ -323,18 +272,35 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = } } if (isset($row['Table_priv'])) { - PMA_addUSerTablePrivs($row); + $res = PMA_DBI_query( + 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', + $GLOBALS['userlink'] ); + // note: in MySQL 5.0.3 we get "Create View', 'Show view'; + // the View for Create is spelled with uppercase V + // the view for Show is spelled with lowercase v + // and there is a space between the words + + $row1 = PMA_DBI_fetch_assoc($res); + PMA_DBI_free_result($res); + $av_grants = explode ('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3)); + unset($res, $row1); + $users_grants = explode(',', $row['Table_priv']); + + foreach ($av_grants as $current_grant) { + $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; + } + unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); // get collumns - $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards($db) . '`.`' . $table . '`;'); + $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards( $db ) . '`.`' . $table . '`;'); $columns = array(); - if ($res) { + if ( $res ) { while ($row1 = PMA_DBI_fetch_row($res)) { $columns[$row1[0]] = array( - 'Select' => false, - 'Insert' => false, - 'Update' => false, - 'References' => false + 'Select' => FALSE, + 'Insert' => FALSE, + 'Update' => FALSE, + 'References' => FALSE ); } PMA_DBI_free_result($res); @@ -342,27 +308,27 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = unset($res, $row1); } // t a b l e - s p e c i f i c p r i v i l e g e s - if (! empty($columns)) { + if ( ! empty( $columns ) ) { $res = PMA_DBI_query( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE ' . PMA_convert_using('`User`') - .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') .' AND ' . PMA_convert_using('`Host`') - .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted') + .' = ' . PMA_convert_using($hostname, 'quoted') .' AND ' . PMA_convert_using('`Db`') - .' = ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted') + .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted') .' AND ' . PMA_convert_using('`Table_name`') .' = ' . PMA_convert_using($table, 'quoted') . ';'); while ($row1 = PMA_DBI_fetch_row($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { - $columns[$row1[0]][$current] = true; + $columns[$row1[0]][$current] = TRUE; } } PMA_DBI_free_result($res); - unset($res, $row1, $current); + unset( $res, $row1, $current ); echo $spaces . '' . "\n" . $spaces . '' . "\n" @@ -510,7 +476,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = . $spaces . '

' . $GLOBALS['strEnglishPrivileges'] . '

' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strData'] . '' . "\n"; - foreach ($privTable[0] as $priv) + foreach ( $privTable[0] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" @@ -520,7 +486,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = echo $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strStructure'] . '' . "\n"; - foreach ($privTable[1] as $priv) + foreach ( $privTable[1] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" @@ -530,7 +496,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = echo $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strAdministration'] . '' . "\n"; - foreach ($privTable[2] as $priv) + foreach ( $privTable[2] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" @@ -590,11 +556,10 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = * * @return void */ -function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) -{ - $spaces = str_repeat(' ', $indent); +function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) { + $spaces = str_repeat( ' ', $indent); - // Get maximum user/host name column lengths from mysql table structure + // Get user/host name lengths $fields_info = PMA_DBI_get_fields('mysql', 'user'); $username_length = 16; $hostname_length = 41; @@ -613,10 +578,10 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) } } } - unset($fields_info, $v, $key, $val); + unset($fields_info); - if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) { - $_REQUEST['pred_username'] = 'any'; + if ( isset( $GLOBALS['username'] ) && strlen( $GLOBALS['username'] ) === 0 ) { + $GLOBALS['pred_username'] = 'any'; } echo $spaces . '
' . "\n" . $spaces . '' . $GLOBALS['strLoginInformation'] . '' . "\n" @@ -627,11 +592,11 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" - . $spaces . '' . "\n" + . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" - . $spaces . '' . "\n" + . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n"; } // end of the 'PMA_displayUserAndHostFields()' function -/** - * string PMA_getPrivCondition(string $username, string $hostname[, - * string $db = null[, string $table = null]]) - * - * returns (simplified): - * WEHRE `User` = '$username' - * AND `Host` = '$hostname' - * [ AND `Db` = '$db'] - * [ AND `Table_name` = '$table']; - * - * @param string $username user name - * @param string $hostname host name - * @return string user host WHERE condition - */ -function PMA_getPrivCondition($username, $hostname, $db = null, $table = null) -{ - $return = - ' WHERE ' . PMA_convert_using('`User`') - .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') - .' AND ' . PMA_convert_using('`Host`') - .' = ' . PMA_convert_using($hostname, 'quoted'); - - if ( null !== $db ) { - $return .= - ' AND ' . PMA_convert_using('`Db`') - .' = ' . PMA_convert_using($db, 'quoted'); - } - if ( null !== $table ) { - $return .= - ' AND ' . PMA_convert_using('`Table_name`') - .' = ' . PMA_convert_using($table, 'quoted'); - } - - return $return . ';'; -} - -/** - * string PMA_getDbTable(string $db, string $table) - * - * escaping a wildcard character in a GRANT is only accepted at the global - * or database level, not at table level; this is why I remove - * the escaping character - * Note: in the phpMyAdmin list of Database-specific privileges, - * we will have for example - * test\_db SELECT (this one is for privileges on a db level) - * test_db USAGE (this one is for table-specific privileges) - * - * It looks curious but reflects the way MySQL works - * - * @param string $db database name - * @param string $table table name - */ -function PMA_getDbTable($db, $table) -{ - if (strlen($db)) { - if (strlen($table)) { - $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($db)); - $db_and_table .= '.' . PMA_backquote($table); - } else { - $db_and_table = PMA_backquote($db) . '.*'; - } - } else { - $db_and_table = '*.*'; - } - - return $db_and_table; -} - -/** - * returns WITH privileg options - * - * @param array $privs privilegs to include - * @return string WITH privilegs - */ -function PMA_checkWithPrivs(&$privs) -{ - $with = ''; - - if (isset($privs['Grant_priv']) && $privs['Grant_priv'] == 'Y') { - $with .= ' GRANT OPTION'; - } - - if (PMA_MYSQL_INT_VERSION >= 40002) { - if (isset($privs['max_questions'])) { - // avoid negative values - $privs['max_questions'] = - max(0, (int) $privs['max_questions']); - $with .= ' MAX_QUERIES_PER_HOUR ' . $privs['max_questions']; - } - if (isset($privs['max_connections'])) { - $privs['max_connections'] = - max(0, (int) $privs['max_connections']); - $with .= ' MAX_CONNECTIONS_PER_HOUR ' . $privs['max_connections']; - } - if (isset($privs['max_updates'])) { - $privs['max_updates'] = - max(0, (int) $privs['max_updates']); - $with .= ' MAX_UPDATES_PER_HOUR ' . $privs['max_updates']; - } - } - - if (PMA_MYSQL_INT_VERSION >= 50003) { - if (isset($privs['max_user_connections'])) { - $privs['max_user_connections'] = - max(0, (int) $privs['max_user_connections']); - $with .= ' MAX_USER_CONNECTIONS ' . $privs['max_user_connections']; - } - } - - if (strlen($with)) { - $with = ' WITH' . $with . ' '; - } - - return $with; -} /** * Changes / copies a user, part I - * - * chek if given user exists */ -$mysql_user = array(); -if (!empty($_REQUEST['change_copy'])) { - $user_host_condition = PMA_getPrivCondition($_REQUEST['old_username'], - $_REQUEST['old_hostname']); - $mysql_user = PMA_DBI_fetch_single_row( - 'SELECT * FROM `mysql`.`user` ' . $user_host_condition); - if (!$mysql_user) { - $mysql_user = array(); +if (!empty($change_copy)) { + $user_host_condition = + ' WHERE ' . PMA_convert_using('User') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') + .' AND ' . PMA_convert_using('Host') + .' = ' . PMA_convert_using($old_hostname, 'quoted') . ';'; + $res = PMA_DBI_query('SELECT * FROM `mysql`.`user` ' . $user_host_condition); + if (!$res) { $message = $GLOBALS['strNoUsersFound']; - unset($_REQUEST['change_copy']); + unset($change_copy); } else { + $row = PMA_DBI_fetch_assoc($res); + 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($mysql_user['Password']) && isset($mysql_user['password'])) { - $mysql_user['Password'] =& $mysql_user['password']; + if (!isset($password) && isset($Password)) { + $password=$Password; } + PMA_DBI_free_result($res); $queries = array(); } } @@ -863,91 +717,124 @@ if (!empty($_REQUEST['change_copy'])) { * Adds a user * (Changes / copies a user, part II) */ -if (!empty($_REQUEST['adduser_submit']) || !empty($_REQUEST['change_copy'])) { +if (!empty($adduser_submit) || !empty($change_copy)) { unset($sql_query); - if ($_REQUEST['pred_username'] == 'any') { - $_REQUEST['username'] = ''; + if ($pred_username == 'any') { + $username = ''; } - switch ($_REQUEST['pred_hostname']) { + switch ($pred_hostname) { case 'any': - $_REQUEST['hostname'] = '%'; + $hostname = '%'; break; case 'localhost': - $_REQUEST['hostname'] = 'localhost'; + $hostname = 'localhost'; break; case 'hosttable': - $_REQUEST['hostname'] = ''; + $hostname = ''; break; case 'thishost': - $_REQUEST['hostname'] = PMA_DBI_fetch_value('SELECT USER();'); - $_REQUEST['hostname'] = substr($_REQUEST['hostname'], - (strrpos($_REQUEST['hostname'], '@') + 1)); + $res = PMA_DBI_query('SELECT USER();'); + $row = PMA_DBI_fetch_row($res); + PMA_DBI_free_result($res); + unset($res); + $hostname = substr($row[0], (strrpos($row[0], '@') + 1)); + unset($row); break; } - $user_exists = PMA_DBI_fetch_value( - 'SELECT COUNT(*) FROM `mysql`.`user`' - . PMA_getPrivCondition($_REQUEST['username'], $_REQUEST['hostname'])); - if ($user_exists) { - $message = sprintf($GLOBALS['strUserAlreadyExists'], - "[i]'" . $_REQUEST['username'] . "'@'" . $_REQUEST['hostname'] . "'[/i]"); - // display add user page again - $_REQUEST['adduser'] = true; + $res = PMA_DBI_query( + 'SELECT \'foo\' FROM `mysql`.`user`' + .' WHERE ' . PMA_convert_using('User') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') + .' AND ' . PMA_convert_using('Host') + .' = ' . PMA_convert_using($hostname, 'quoted') . ';', + null, PMA_DBI_QUERY_STORE); + if (PMA_DBI_num_rows($res) == 1) { + PMA_DBI_free_result($res); + $message = sprintf($GLOBALS['strUserAlreadyExists'], '[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]'); + $adduser = 1; } else { + PMA_DBI_free_result($res); + if (50002 <= PMA_MYSQL_INT_VERSION) { // MySQL 5 requires CREATE USER before any GRANT on this user can done - $create_user_real = 'CREATE USER \'' - . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\''; + $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; } $real_sql_query = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \'' - . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\''; - if ($_REQUEST['pred_password'] != 'none' - && $_REQUEST['pred_password'] != 'keep') { - $sql_query = $real_sql_query . ' IDENTIFIED BY \'*****\''; - $real_sql_query .= ' IDENTIFIED BY \'' . $_REQUEST['pma_pw'] . '\''; - if (isset($create_user_real)) { - $create_user_show = $create_user_real . ' IDENTIFIED BY \'*****\''; - $create_user_real .= ' IDENTIFIED BY \'' . $_REQUEST['pma_pw'] . '\''; + . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; + if ($pred_password != 'none' && $pred_password != 'keep') { + $pma_pw_hidden = ''; + for ($i = 0; $i < strlen($pma_pw); $i++) { + $pma_pw_hidden .= '*'; + } + $sql_query = $real_sql_query . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\''; + $real_sql_query .= ' IDENTIFIED BY \'' . $pma_pw . '\''; + if ( isset( $create_user_real ) ) { + $create_user_show = $create_user_real . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\''; + $create_user_real .= ' IDENTIFIED BY \'' . $pma_pw . '\''; } } else { - if ($_REQUEST['pred_password'] == 'keep' - && !empty($mysql_user['Password'])) { - $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' - . $mysql_user['Password'] . '\''; - if (isset($create_user_real)) { - $create_user_real .= ' IDENTIFIED BY PASSWORD \'' - . $mysql_user['Password'] . '\''; + if ($pred_password == 'keep' && !empty($password)) { + $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\''; + if ( isset( $create_user_real ) ) { + $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\''; } } $sql_query = $real_sql_query; - if (isset($create_user_real)) { + if ( isset( $create_user_real ) ) { $create_user_show = $create_user_real; } } - - $with = PMA_checkWithPrivs($mysql_user); - $real_sql_query .= $with . ';'; - $sql_query .= $with . ';'; - if (isset($create_user_real)) { + // FIXME: similar code appears twice in this script + if ((isset($Grant_priv) && $Grant_priv == 'Y') || (PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates) || isset($max_user_connections)))) { + $real_sql_query .= 'WITH'; + $sql_query .= 'WITH'; + if (isset($Grant_priv) && $Grant_priv == 'Y') { + $real_sql_query .= ' GRANT OPTION'; + $sql_query .= ' GRANT OPTION'; + } + if (PMA_MYSQL_INT_VERSION >= 40002) { + if (isset($max_questions)) { + // avoid negative values + $max_questions = max(0, (int)$max_questions); + $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; + $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; + } + if (isset($max_connections)) { + $max_connections = max(0, (int)$max_connections); + $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; + $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; + } + if (isset($max_updates)) { + $max_updates = max(0, (int)$max_updates); + $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; + $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; + } + } + if (PMA_MYSQL_INT_VERSION >= 50003) { + if (isset($max_user_connections)) { + $max_user_connections = max(0, (int)$max_user_connections); + $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; + $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; + } + } + } + if ( isset( $create_user_real ) ) { $create_user_real .= ';'; $create_user_show .= ';'; } - unset($with); - - if (empty($_REQUEST['change_copy'])) { - if (isset($create_user_real)) { - PMA_DBI_try_query($create_user_real) - or PMA_mysqlDie(PMA_DBI_getError(), $create_user_show); + $real_sql_query .= ';'; + $sql_query .= ';'; + if (empty($change_copy)) { + if ( isset( $create_user_real ) ) { + PMA_DBI_try_query($create_user_real) or PMA_mysqlDie(PMA_DBI_getError(), $create_user_show); $sql_query = $create_user_show . $sql_query; } - PMA_DBI_try_query($real_sql_query) - or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); + PMA_DBI_try_query($real_sql_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); $message = $GLOBALS['strAddUserMessage']; } else { - if (isset($create_user_real)) { + if ( isset( $create_user_real ) ) { $queries[] = $create_user_real; } $queries[] = $real_sql_query; @@ -955,15 +842,12 @@ if (!empty($_REQUEST['adduser_submit']) || !empty($_REQUEST['change_copy'])) { // $queries_for_display, at the same position occupied // by the real query in $queries $tmp_count = count($queries); - if (isset($create_user_real)) { + if ( isset( $create_user_real ) ) { $queries_for_display[$tmp_count - 2] = $create_user_show; } $queries_for_display[$tmp_count - 1] = $sql_query; } - unset($real_sql_query); - if (isset($create_user_real)) { - unset($create_user_show, $create_user_real); - } + unset($res, $real_sql_query); } } @@ -971,31 +855,39 @@ if (!empty($_REQUEST['adduser_submit']) || !empty($_REQUEST['change_copy'])) { /** * Changes / copies a user, part III */ -if (!empty($_REQUEST['change_copy'])) { - $user_host_condition = PMA_getPrivCondition($_REQUEST['old_username'], - $_REQUEST['old_hostname']); - $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition); +if (!empty($change_copy)) { + $user_host_condition = + ' WHERE ' . PMA_convert_using('User') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') + .' AND ' . PMA_convert_using('Host') + .' = ' . PMA_convert_using($old_hostname, 'quoted') . ';'; + $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition ); while ($row = PMA_DBI_fetch_assoc($res)) { $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) - . ' ON `' . $row['Db'] . '`.* TO \'' - . PMA_sqlAddslashes($_REQUEST['username']) . "'@'" - . $_REQUEST['hostname'] . "'" - . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';'); + .' ON `' . $row['Db'] . '`.*' + .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' + . ( $row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';' ); } PMA_DBI_free_result($res); - $res = PMA_DBI_query( 'SELECT `Db`, `Table_name`, `Table_priv`' .' FROM `mysql`.`tables_priv`' . $user_host_condition, - $GLOBALS['userlink'], PMA_DBI_QUERY_STORE); + $GLOBALS['userlink'], PMA_DBI_QUERY_STORE ); while ($row = PMA_DBI_fetch_assoc($res)) { $res2 = PMA_DBI_QUERY( 'SELECT `Column_name`, `Column_priv`' - . ' FROM `mysql`.`columns_priv`' - . PMA_getPrivCondition($_REQUEST['old_username'], - $_REQUEST['old_hostname'], $row['Db'], $row['Table_name']), + .' FROM `mysql`.`columns_priv`' + .' WHERE ' . PMA_convert_using('User') + .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') + .' AND ' . PMA_convert_using('`Host`') + .' = ' . PMA_convert_using($old_hostname, 'quoted') + .' AND ' . PMA_convert_using('`Db`') + .' = ' . PMA_convert_using($row['Db'], 'quoted') + .' AND ' . PMA_convert_using('`Table_name`') + .' = ' . PMA_convert_using($row['Table_name'], 'quoted') + .';', null, PMA_DBI_QUERY_STORE); $tmp_privs1 = PMA_extractPrivInfo($row); @@ -1006,7 +898,6 @@ if (!empty($_REQUEST['change_copy'])) { 'References' => array() ); - $tmp_array = array(); while ($row2 = PMA_DBI_fetch_assoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { @@ -1021,121 +912,173 @@ if (!empty($_REQUEST['change_copy'])) { if (in_array('References', $tmp_array)) { $tmp_privs2['References'][] = $row2['Column_name']; } + unset($tmp_array); } - PMA_DBI_free_result($res2); - - if (count($tmp_privs2['Select']) && !in_array('SELECT', $tmp_privs1)) { + if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) { $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)'; } - if (count($tmp_privs2['Insert']) && !in_array('INSERT', $tmp_privs1)) { + if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) { $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)'; } - if (count($tmp_privs2['Update']) && !in_array('UPDATE', $tmp_privs1)) { + if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) { $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)'; } - if (count($tmp_privs2['References']) && !in_array('REFERENCES', $tmp_privs1)) { + if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) { $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)'; } + unset($tmp_privs2); $queries[] = 'GRANT ' . join(', ', $tmp_privs1) - . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] . '` TO \'' - . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\'' + . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] + . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';'); } - PMA_DBI_free_result($res); - unset($res, $res2, $row2, $tmp_array, $tmp_privs2, $tmp_privs1, $row, - $user_host_condition); } /** * Updates privileges */ -if (!empty($_REQUEST['update_privs'])) { - $db_and_table = PMA_getDbTable($dbname, $tablename); +if (!empty($update_privs)) { + // escaping a wildcard character in a GRANT is only accepted at the global + // or database level, not at table level; this is why I remove + // the escaping character + // Note: in the phpMyAdmin list of Database-specific privileges, + // we will have for example + // test\_db SELECT (this one is for privileges on a db level) + // test_db USAGE (this one is for table-specific privileges) + // + // It looks curious but reflects the way MySQL works + + if (! isset($dbname) || ! strlen($dbname)) { + $db_and_table = '*.*'; + } else { + if ( isset( $tablename ) && strlen($tablename) ) { + $db_and_table = PMA_backquote( PMA_unescape_mysql_wildcards( $dbname ) ) . '.'; + $db_and_table .= PMA_backquote( $tablename ); + } else { + $db_and_table = PMA_backquote( $dbname ) . '.'; + $db_and_table .= '*'; + } + } $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table - . ' FROM \'' . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\';'; - if (!isset($mysql_user['Grant_priv']) || $mysql_user['Grant_priv'] != 'Y') { + . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; + if (!isset($Grant_priv) || $Grant_priv != 'Y') { $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table - . ' FROM \'' . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\';'; + . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; } $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table - . ' TO \'' . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' - . $_REQUEST['hostname'] . '\''; + . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; - $sql_query2 .= PMA_checkWithPrivs($mysql_user) . ';'; - - if (!PMA_DBI_try_query($sql_query0)) { - // this query may fail, but this does not matter :o) + // FIXME: similar code appears twice in this script + if ( ( isset($Grant_priv) && $Grant_priv == 'Y') + || ( ( ! isset($dbname) || ! strlen($dbname) ) && PMA_MYSQL_INT_VERSION >= 40002 + && ( isset($max_questions) || isset($max_connections) + || isset($max_updates) || isset($max_user_connections)))) + { + $sql_query2 .= 'WITH'; + if (isset($Grant_priv) && $Grant_priv == 'Y') { + $sql_query2 .= ' GRANT OPTION'; + } + if (PMA_MYSQL_INT_VERSION >= 40002) { + if (isset($max_questions)) { + $max_questions = max(0, (int)$max_questions); + $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; + } + if (isset($max_connections)) { + $max_connections = max(0, (int)$max_connections); + $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; + } + if (isset($max_updates)) { + $max_updates = max(0, (int)$max_updates); + $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; + } + } + if (PMA_MYSQL_INT_VERSION >= 50003) { + if (isset($max_user_connections)) { + $max_user_connections = max(0, (int)$max_user_connections); + $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; + } + } + } + $sql_query2 .= ';'; + if (!PMA_DBI_try_query($sql_query0)) { // this query may fail, but this does not matter :o) unset($sql_query0); } - if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { - // this one may fail, too... + if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too... unset($sql_query1); } PMA_DBI_query($sql_query2); $sql_query = (isset($sql_query0) ? $sql_query0 . ' ' : '') . (isset($sql_query1) ? $sql_query1 . ' ' : '') . $sql_query2; - $message = sprintf($GLOBALS['strUpdatePrivMessage'], '\'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\''); - unset($sql_query2, $db_and_table); + $message = sprintf($GLOBALS['strUpdatePrivMessage'], '\'' . $username . '\'@\'' . $hostname . '\''); } /** * Revokes Privileges */ -if (!empty($_REQUEST['revokeall'])) { +if (!empty($revokeall)) { - $db_and_table = PMA_getDbTable($dbname, $tablename); + if ( ! isset($dbname) || ! strlen($dbname) ) { + $db_and_table = '*.*'; + } else { + if ( ! isset( $tablename ) || ! strlen($tablename) ) { + $db_and_table = PMA_backquote( $dbname ) . '.'; + $db_and_table .= '*'; + } else { + $db_and_table = PMA_backquote( PMA_unescape_mysql_wildcards( $dbname ) ) . '.'; + $db_and_table .= PMA_backquote( $tablename ); + } + } $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table - . ' FROM \'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\';'; + . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table - . ' FROM \'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\';'; + . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; PMA_DBI_query($sql_query0); if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too... unset($sql_query1); } $sql_query = $sql_query0 . (isset($sql_query1) ? ' ' . $sql_query1 : ''); - $message = sprintf($GLOBALS['strRevokeMessage'], '\'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\''); - if (strlen($tablename)) { - unset($tablename); - } else { + $message = sprintf($GLOBALS['strRevokeMessage'], '\'' . $username . '\'@\'' . $hostname . '\''); + if ( ! isset($tablename) || ! strlen($tablename) ) { unset($dbname); + } else { + unset($tablename); } - - unset($sql_query0, $db_and_table); } /** * Updates the password */ -if (!empty($_REQUEST['change_pw'])) { - if ($_REQUEST['$nopass'] == 1) { - $sql_query = 'SET PASSWORD FOR \'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\' = \'\';'; +if (!empty($change_pw)) { + if ($nopass == 1) { + $sql_query = 'SET PASSWORD FOR \'' . $username . '\'@\'' . $hostname . '\' = \'\';'; PMA_DBI_query($sql_query); - $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\''); - } elseif (empty($_REQUEST['pma_pw']) || empty($_REQUEST['pma_pw2'])) { + $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\''); + } elseif (empty($pma_pw) || empty($pma_pw2)) { $message = $GLOBALS['strPasswordEmpty']; - } elseif ($_REQUEST['pma_pw'] != $_REQUEST['pma_pw2']) { + } elseif ($pma_pw != $pma_pw2) { $message = $GLOBALS['strPasswordNotSame']; } else { - $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' . $_REQUEST['hostname'] . '\' = PASSWORD(\'' . PMA_sqlAddslashes($_REQUEST['pma_pw']) . '\')'; - $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($_REQUEST['username']) . '\'@\'' . $_REQUEST['hostname'] . '\' = PASSWORD(\'*****\')'; + $hidden_pw = ''; + for ($i = 0; $i < strlen($pma_pw); $i++) { + $hidden_pw .= '*'; + } + $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')'; + $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . $hidden_pw . '\')'; PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); - $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $_REQUEST['username'] . '\'@\'' . $_REQUEST['hostname'] . '\''); + $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\''); } } @@ -1146,36 +1089,31 @@ if (!empty($_REQUEST['change_pw'])) { */ $user_host_separator = chr(27); -if (!empty($_REQUEST['delete']) || (!empty($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4)) { - if (!empty($_REQUEST['change_copy'])) { - $_REQUEST['selected_usr'] = - array($_REQUEST['old_username'] . $user_host_separator . $_REQUEST['old_hostname']); +if (!empty($delete) || (!empty($change_copy) && $mode < 4)) { + if (!empty($change_copy)) { + $selected_usr = array($old_username . $user_host_separator . $old_hostname); } else { $queries = array(); } - foreach ($_REQUEST['selected_usr'] as $each_selected_user) { - list($this_user, $this_host) = explode($user_host_separator, $each_selected_user); - $this_user_host = "'" . PMA_sqlAddslashes($this_user) . "'@'" . $this_host . "'"; - $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], $this_user_host) . ' ...'; - if (PMA_MYSQL_INT_VERSION >= 50002) { - $queries[] = 'DROP USER ' . $this_user_host . ';'; + for ($i = 0; isset($selected_usr[$i]); $i++) { + list($this_user, $this_host) = explode($user_host_separator, $selected_usr[$i]); + $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...'; + if ( PMA_MYSQL_INT_VERSION >= 50002 ) { + $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; } else { - if ($_REQUEST['mode'] == 2) { + if ($mode == 2) { // The SHOW GRANTS query may fail if the user has not been loaded // into memory - $res = PMA_DBI_try_query('SHOW GRANTS FOR ' . $this_user_host . ';'); + $res = PMA_DBI_try_query('SHOW GRANTS FOR \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'); if ($res) { - $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM ' . $this_user_host . ';'; + $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; while ($row = PMA_DBI_fetch_row($res)) { - $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), - (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3)); + $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3)); if ($this_table != '*.*') { - $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table - . ' FROM ' . $this_user_host . ';'; + $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; if (strpos($row[0], 'WITH GRANT OPTION')) { - $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table - . ' FROM ' . $this_user_host . ';'; + $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; } } unset($this_table); @@ -1184,16 +1122,19 @@ if (!empty($_REQUEST['delete']) || (!empty($_REQUEST['change_copy']) && $_REQUES } unset($res); } - if (PMA_MYSQL_INT_VERSION >= 40101) { - $queries[] = 'DROP USER ' . $this_user_host . ';'; + if ( PMA_MYSQL_INT_VERSION >= 40101 ) { + $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; } else { - $queries[] = 'DELETE FROM `mysql`.`user`' - . PMA_getPrivCondition($this_user, $this_host); + $queries[] = 'DELETE FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($this_host, 'quoted') . ';'; } - if ($_REQUEST['mode'] != 2) { + if ($mode != 2) { // If we REVOKE the table grants, we should not need to modify the // `mysql`.`db`, `mysql`.`tables_priv` and `mysql`.`columns_priv` tables manually... - $user_host_condition = PMA_getPrivCondition($this_user, $this_host); + $user_host_condition = + ' WHERE ' . PMA_convert_using('User') + . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') + . ' AND ' . PMA_convert_using('Host') + . ' = ' . PMA_convert_using($this_host, 'quoted') . ';'; $queries[] = 'DELETE FROM `mysql`.`db`' . $user_host_condition; $queries[] = 'DELETE FROM `mysql`.`tables_priv`' . $user_host_condition; $queries[] = 'DELETE FROM `mysql`.`columns_priv`' . $user_host_condition; @@ -1201,16 +1142,16 @@ if (!empty($_REQUEST['delete']) || (!empty($_REQUEST['change_copy']) && $_REQUES } if (!empty($drop_users_db)) { $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';'; - $GLOBALS['reload'] = true; + $GLOBALS['reload'] = TRUE; PMA_reloadNavigation(); } } - if (empty($_REQUEST['change_copy'])) { + if (empty($change_copy)) { if (empty($queries)) { - $show_error_header = true; + $show_error_header = TRUE; $message = $GLOBALS['strDeleteNoUsersSelected']; } else { - if ($_REQUEST['mode'] == 3) { + if ($mode == 3) { $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...'; $queries[] = 'FLUSH PRIVILEGES;'; } @@ -1221,8 +1162,8 @@ if (!empty($_REQUEST['delete']) || (!empty($_REQUEST['change_copy']) && $_REQUES } $sql_query = join("\n", $queries); $message = $GLOBALS['strUsersDeleted']; - unset($queries); } + unset($queries); } } @@ -1230,7 +1171,7 @@ if (!empty($_REQUEST['delete']) || (!empty($_REQUEST['change_copy']) && $_REQUES /** * Changes / copies a user, part V */ -if (!empty($_REQUEST['change_copy'])) { +if (!empty($change_copy)) { $tmp_count = 0; foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { @@ -1251,7 +1192,7 @@ if (!empty($_REQUEST['change_copy'])) { /** * Reloads the privilege tables into memory */ -if (!empty($_REQUEST['flush_privileges'])) { +if (!empty($flush_privileges)) { $sql_query = 'FLUSH PRIVILEGES;'; PMA_DBI_query($sql_query); $message = $GLOBALS['strPrivilegesReloaded']; @@ -1260,20 +1201,17 @@ if (!empty($_REQUEST['flush_privileges'])) { /** * Displays the links - * - * $_REQUEST['checkprivs'] come from 'Rights'-tab in database pages - * $_REQUEST['viewing_mode'] come from 'Rights'-tab in database pages */ -if (isset($_REQUEST['viewing_mode']) && $_REQUEST['viewing_mode'] == 'db') { - $db = $_REQUEST['checkprivs']; +if (isset($viewing_mode) && $viewing_mode == 'db') { + $db = $checkprivs; $url_query .= '&goto=db_operations.php'; - $url_params['goto'] = 'db_operations.php'; // Gets the database structure $sub_part = '_structure'; - require './libraries/db_details_db_info.inc.php'; + require('./libraries/db_details_db_info.inc.php'); + echo "\n"; } else { - require './libraries/server_links.inc.php'; + require('./libraries/server_links.inc.php'); } @@ -1285,11 +1223,8 @@ $link_edit = ''; -if ($GLOBALS['cfg']['PropertiesIconic']) { - $link_edit .= '' . $GLOBALS['strEditPrivileges'] . ''; +if ( $GLOBALS['cfg']['PropertiesIconic'] ) { + $link_edit .= '' . $GLOBALS['strEditPrivileges'] . ''; } else { $link_edit .= $GLOBALS['strEditPrivileges']; } @@ -1301,11 +1236,8 @@ $link_revoke = ''; -if ($GLOBALS['cfg']['PropertiesIconic']) { - $link_revoke .= '' . $GLOBALS['strRevoke'] . ''; +if ( $GLOBALS['cfg']['PropertiesIconic'] ) { + $link_revoke .= '' . $GLOBALS['strRevoke'] . ''; } else { $link_revoke .= $GLOBALS['strRevoke']; } @@ -1314,19 +1246,14 @@ $link_revoke .= ''; /** * Displays the page */ -if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen($_REQUEST['checkprivs']))) { - if (! isset($_REQUEST['username'])) { +if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) { + if ( ! isset( $username ) ) { // No username is given --> display the overview echo '

' . "\n" - . ($GLOBALS['cfg']['MainPageIconic'] - ? '' - : '') + . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . $GLOBALS['strUserOverview'] . "\n" . '

' . "\n"; - /** - * @todo why not SELECT * ??? - */ $sql_query = 'SELECT `User`,' . ' `Host`,' . @@ -1360,7 +1287,7 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen $sql_query .= ' FROM `mysql`.`user`'; - $sql_query .= (isset($_REQUEST['initial']) ? PMA_RangeOfUsers($_REQUEST['initial']) : ''); + $sql_query .= (isset($initial) ? PMA_RangeOfUsers($initial) : ''); $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); @@ -1396,11 +1323,9 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen ); $db_rights_sqls = array(); - foreach ($tables_to_search_for_users as $table_search_in) { - if (in_array($table_search_in, $tables)) { - $db_rights_sqls[] = - 'SELECT DISTINCT `User`, `Host`' - . ' FROM `mysql`.`' . $table_search_in . '` ' . (isset($_REQUEST['initial']) ? PMA_RangeOfUsers($_REQUEST['initial']) : ''); + foreach ( $tables_to_search_for_users as $table_search_in ) { + if ( in_array( $table_search_in, $tables ) ) { + $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ? PMA_RangeOfUsers($initial) : ''); } } @@ -1409,73 +1334,73 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen 'Host' => '%', 'Password' => '?', 'Grant_priv' => 'N', - 'privs' => array('USAGE'), + 'privs' => array( 'USAGE' ), ); + // for all initials, even non A-Z + $array_initials = array(); // for the rights $db_rights = array(); - // do not use UNION DISTINCT, as it's not allowed before + // do not use UNION DISTINCT, as it's not allowed before // MySQL 4.0.17, and because "it does nothing" (cf manual) - if (PMA_MYSQL_INT_VERSION >= 40000) { - $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')' + if ( PMA_MYSQL_INT_VERSION >= 40000 ) { + $db_rights_sql = '(' . implode( ') UNION (', $db_rights_sqls ) . ')' .' ORDER BY `User` ASC, `Host` ASC'; - $db_rights_result = PMA_DBI_query($db_rights_sql); + $db_rights_result = PMA_DBI_query( $db_rights_sql ); - while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) { - $db_rights_row = array_merge($user_defaults, $db_rights_row); + while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) { + $db_rights_row = array_merge( $user_defaults, $db_rights_row ); $db_rights[$db_rights_row['User']][$db_rights_row['Host']] = $db_rights_row; } } else { - foreach ($db_rights_sqls as $db_rights_sql) { - $db_rights_result = PMA_DBI_query($db_rights_sql); + foreach ( $db_rights_sqls as $db_rights_sql ) { + $db_rights_result = PMA_DBI_query( $db_rights_sql ); - while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) { - $db_rights_row = array_merge($user_defaults, $db_rights_row); + while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) { + $db_rights_row = array_merge( $user_defaults, $db_rights_row ); $db_rights[$db_rights_row['User']][$db_rights_row['Host']] = $db_rights_row; } } } - PMA_DBI_free_result($db_rights_result); - unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row); - ksort($db_rights); + PMA_DBI_free_result( $db_rights_result ); + unset( $db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row ); + ksort( $db_rights ); /** * Displays the initials */ - // for all initials, even non A-Z - $array_initials = PMA_DBI_fetch_result( - 'SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1))' - . ' FROM `user` ORDER BY `User` ASC', - 0, 0); - // initialize to false the letters A-Z + // initialize to FALSE the letters A-Z for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) { - if (isset($array_initials[chr($letter_counter + 64)])) { - $array_initials[chr($letter_counter + 64)] = true; - } else { - $array_initials[chr($letter_counter + 64)] = false; + if ( ! isset( $array_initials[chr($letter_counter + 64)] ) ) { + $array_initials[chr($letter_counter + 64)] = FALSE; } } + $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE); + while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { + $array_initials[$tmp_initial] = TRUE; + } + // Display the initials, which can be any characters, not // just letters. For letters A-Z, we add the non-used letters // as greyed out. - uksort($array_initials, "strnatcasecmp"); + uksort( $array_initials, "strnatcasecmp" ); echo ''; foreach ($array_initials as $tmp_initial => $initial_was_found) { if ($initial_was_found) { - echo '' . "\n"; + echo '' . "\n"; } else { echo ''; } } - echo '' . "\n"; + echo '' . "\n"; echo '
' . $tmp_initial . '' . $tmp_initial . '' . $tmp_initial . '[' . $GLOBALS['strShowAll'] . '][' . $GLOBALS['strShowAll'] . ']
'; /** @@ -1483,18 +1408,17 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen * (if less than 50 users, display them immediately) */ - if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) - || PMA_DBI_num_rows($res) < 50) { + if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) { - while ($row = PMA_DBI_fetch_assoc($res)) { - $row['privs'] = PMA_extractPrivInfo($row, true); + while ( $row = PMA_DBI_fetch_assoc( $res ) ) { + $row['privs'] = PMA_extractPrivInfo( $row, true ); $db_rights[$row['User']][$row['Host']] = $row; } - @PMA_DBI_free_result($res); - unset($res); + @PMA_DBI_free_result( $res ); + unset( $res ); echo '
' . "\n" - . PMA_generate_common_hidden_inputs() + . PMA_generate_common_hidden_inputs('', '', 1) . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" @@ -1502,32 +1426,22 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" + . PMA_showHint( $GLOBALS['strEnglishPrivileges'] ) . '' . "\n" . ' ' . "\n" - . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] - ? '' - : '') - . "\n"; + . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ? '' : '') . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; $odd_row = true; $index_checkbox = -1; - foreach ($db_rights as $user) { + foreach ( $db_rights as $user ) { $index_checkbox++; - ksort($user); - foreach ($user as $host) { + ksort( $user ); + foreach ( $user as $host ) { $index_checkbox++; - echo ' ' . "\n" - . ' ' . "\n" - . ' ' . "\n" + echo ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" . ' ' . "\n"; echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n"; $odd_row = ! $odd_row; } } - unset($user, $host, $odd_row); + unset( $user, $host, $odd_row ); echo '
' . $GLOBALS['strHost'] . '' . $GLOBALS['strPassword'] . '' . $GLOBALS['strGlobalPrivileges'] . ' ' - . PMA_showHint($GLOBALS['strEnglishPrivileges']) . '' . $GLOBALS['strGrantOption'] . '' . $GLOBALS['strAction'] . '' . $GLOBALS['strAction'] . '
' . htmlspecialchars($host['Host']) . ''; switch ($host['Password']) { @@ -1544,46 +1458,46 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen } // end switch echo '' . "\n" - . ' ' . implode(',' . "\n" . ' ', $host['privs']) . "\n" + . ' ' . implode( ',' . "\n" . ' ', $host['privs'] ) . "\n" . ' ' . ($host['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . ''; - printf($link_edit, urlencode($host['User']), - urlencode($host['Host']), '', ''); + printf( $link_edit, urlencode( $host['User'] ), + urlencode( $host['Host'] ), '', '' ); echo '
' . "\n" .'' . $GLOBALS['strWithChecked'] . '' . "\n" .'' + .' onclick="if ( markAllRows(\'usersForm\') ) return false;">' . $GLOBALS['strCheckAll'] . '' . "\n" .'/' . "\n" .'' + .' onclick="if ( unMarkAllRows(\'usersForm\') ) return false;">' . $GLOBALS['strUncheckAll'] . '' . "\n"; // add/delete user fieldset echo '
' . "\n" . ' ' . "\n" - . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '') + . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . $GLOBALS['strAddUser'] . '' . "\n" . '
' . "\n" . '
' . ' ' . "\n" - . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '') + . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n" . ' ' . "\n"; - + // before MySQL 4.1.1, we offer some choices for the delete - // mode, but for 4.1.1+, it will be done with REVOKEing the + // mode, but for 4.1.1+, it will be done with REVOKEing the // privileges then a DROP USER (even no REVOKE at all // for MySQL 5), so no need to offer so many options if (PMA_MYSQL_INT_VERSION < 40101) { @@ -1602,7 +1516,7 @@ if (empty($_REQUEST['adduser']) && (! isset($_REQUEST['checkprivs']) || ! strlen } else { echo ' ' . "\n" . '( ' . $GLOBALS['strRevokeAndDelete'] . ' )
' . "\n"; - } + } echo ' ' . "\n" . '