Ejemplo n.º 1
0
 /**
  * Test clearing user cache
  *
  * @return void
  */
 public function testClearUserCache()
 {
     $GLOBALS['server'] = 'server';
     PMA_Util::cacheSet('is_superuser', 'yes', true);
     $this->assertEquals('yes', $_SESSION['cache']['server_server']['is_superuser']);
     PMA_Util::clearUserCache();
     $this->assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_server']);
 }
Ejemplo n.º 2
0
 /**
  * Test for rename
  *
  * @return void
  */
 public function testRename()
 {
     $table = 'PMA_BookMark';
     $db = 'PMA';
     PMA_Util::cacheSet('lower_case_table_names', false);
     $table = new PMA_Table($table, $db);
     //rename to same name
     $table_new = 'PMA_BookMark';
     $result = $table->rename($table_new);
     $this->assertEquals(true, $result);
     //isValidName
     //space in table name
     $table_new = 'PMA_BookMark ';
     $result = $table->rename($table_new);
     $this->assertEquals(false, $result);
     //empty name
     $table_new = '';
     $result = $table->rename($table_new);
     $this->assertEquals(false, $result);
     //dot in table name
     $table_new = 'PMA_.BookMark';
     $result = $table->rename($table_new);
     $this->assertEquals(false, $result);
     $table_new = 'PMA_BookMark_new';
     $db_new = 'PMA_new';
     $result = $table->rename($table_new, $db_new);
     $this->assertEquals(true, $result);
     //message
     $this->assertEquals("Table PMA_BookMark has been renamed to PMA_BookMark_new.", $table->getLastMessage());
 }
Ejemplo n.º 3
0
 /**
  * Returns the server tabs as an array
  *
  * @return array Data for generating server tabs
  */
 private function _getServerTabs()
 {
     $is_superuser = $GLOBALS['dbi']->isSuperuser();
     $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant') || $GLOBALS['dbi']->isUserType('create');
     $binary_logs = null;
     $notDrizzle = !defined('PMA_DRIZZLE') || defined('PMA_DRIZZLE') && !PMA_DRIZZLE;
     if ($notDrizzle) {
         if (PMA_Util::cacheExists('binary_logs')) {
             $binary_logs = PMA_Util::cacheGet('binary_logs');
         } else {
             $binary_logs = $GLOBALS['dbi']->fetchResult('SHOW MASTER LOGS', 'Log_name', null, null, PMA_DatabaseInterface::QUERY_STORE);
             PMA_Util::cacheSet('binary_logs', $binary_logs);
         }
     }
     $tabs = array();
     $tabs['databases']['icon'] = 's_db.png';
     $tabs['databases']['link'] = 'server_databases.php';
     $tabs['databases']['text'] = __('Databases');
     $tabs['sql']['icon'] = 'b_sql.png';
     $tabs['sql']['link'] = 'server_sql.php';
     $tabs['sql']['text'] = __('SQL');
     $tabs['status']['icon'] = 's_status.png';
     $tabs['status']['link'] = 'server_status.php';
     $tabs['status']['text'] = __('Status');
     $tabs['status']['active'] = in_array(basename($GLOBALS['PMA_PHP_SELF']), array('server_status.php', 'server_status_advisor.php', 'server_status_monitor.php', 'server_status_queries.php', 'server_status_variables.php', 'server_status_processes.php'));
     if (($is_superuser || $isCreateOrGrantUser) && !PMA_DRIZZLE) {
         $tabs['rights']['icon'] = 's_rights.png';
         $tabs['rights']['link'] = 'server_privileges.php';
         $tabs['rights']['text'] = __('Users');
         $tabs['rights']['active'] = in_array(basename($GLOBALS['PMA_PHP_SELF']), array('server_privileges.php', 'server_user_groups.php'));
         $tabs['rights']['args']['viewing_mode'] = 'server';
     }
     $tabs['export']['icon'] = 'b_export.png';
     $tabs['export']['link'] = 'server_export.php';
     $tabs['export']['text'] = __('Export');
     $tabs['import']['icon'] = 'b_import.png';
     $tabs['import']['link'] = 'server_import.php';
     $tabs['import']['text'] = __('Import');
     $tabs['settings']['icon'] = 'b_tblops.png';
     $tabs['settings']['link'] = 'prefs_manage.php';
     $tabs['settings']['text'] = __('Settings');
     $tabs['settings']['active'] = in_array(basename($GLOBALS['PMA_PHP_SELF']), array('prefs_forms.php', 'prefs_manage.php'));
     if (!empty($binary_logs)) {
         $tabs['binlog']['icon'] = 's_tbl.png';
         $tabs['binlog']['link'] = 'server_binlog.php';
         $tabs['binlog']['text'] = __('Binary log');
     }
     if ($is_superuser && !PMA_DRIZZLE) {
         $tabs['replication']['icon'] = 's_replication.png';
         $tabs['replication']['link'] = 'server_replication.php';
         $tabs['replication']['text'] = __('Replication');
     }
     $tabs['vars']['icon'] = 's_vars.png';
     $tabs['vars']['link'] = 'server_variables.php';
     $tabs['vars']['text'] = __('Variables');
     $tabs['charset']['icon'] = 's_asci.png';
     $tabs['charset']['link'] = 'server_collations.php';
     $tabs['charset']['text'] = __('Charsets');
     if (defined('PMA_DRIZZLE') && PMA_DRIZZLE) {
         $tabs['plugins']['icon'] = 'b_engine.png';
         $tabs['plugins']['link'] = 'server_plugins.php';
         $tabs['plugins']['text'] = __('Plugins');
     } else {
         $tabs['engine']['icon'] = 'b_engine.png';
         $tabs['engine']['link'] = 'server_engines.php';
         $tabs['engine']['text'] = __('Engines');
     }
     return $tabs;
 }
Ejemplo n.º 4
0
        $mysql_charsets_available['utf8'] = $mysql_charsets_available['utf8_general_ci'];
        unset($mysql_collations['utf8_general_ci'], $mysql_default_collations['utf8_general_ci'], $mysql_charsets_available['utf8_general_ci']);
    }
    sort($mysql_collations_flat, SORT_STRING);
    foreach ($mysql_collations as $key => $value) {
        sort($mysql_collations[$key], SORT_STRING);
        reset($mysql_collations[$key]);
    }
    unset($key, $value);
    PMA_Util::cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
    PMA_Util::cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
    PMA_Util::cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
    PMA_Util::cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
    PMA_Util::cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
    PMA_Util::cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
    PMA_Util::cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
} else {
    $GLOBALS['mysql_charsets'] = PMA_Util::cacheGet('mysql_charsets', true);
    $GLOBALS['mysql_charsets_descriptions'] = PMA_Util::cacheGet('mysql_charsets_descriptions', true);
    $GLOBALS['mysql_charsets_available'] = PMA_Util::cacheGet('mysql_charsets_available', true);
    $GLOBALS['mysql_collations'] = PMA_Util::cacheGet('mysql_collations', true);
    $GLOBALS['mysql_default_collations'] = PMA_Util::cacheGet('mysql_default_collations', true);
    $GLOBALS['mysql_collations_flat'] = PMA_Util::cacheGet('mysql_collations_flat', true);
    $GLOBALS['mysql_collations_available'] = PMA_Util::cacheGet('mysql_collations_available', true);
}
define('PMA_CSDROPDOWN_COLLATION', 0);
define('PMA_CSDROPDOWN_CHARSET', 1);
/**
 * shared functions for mysql charsets
 */
require_once './libraries/mysql_charsets.lib.php';
Ejemplo n.º 5
0
 /**
  * returns true (int > 0) if current user is superuser
  * otherwise 0
  *
  * @return bool Whether use is a superuser
  */
 public function isSuperuser()
 {
     if (PMA_Util::cacheExists('is_superuser', true)) {
         return PMA_Util::cacheGet('is_superuser', true);
     }
     // when connection failed we don't have a $userlink
     if (isset($GLOBALS['userlink'])) {
         if (PMA_DRIZZLE) {
             // Drizzle has no authorization by default, so when no plugin is
             // enabled everyone is a superuser
             // Known authorization libraries: regex_policy, simple_user_policy
             // Plugins limit object visibility (dbs, tables, processes), we can
             // safely assume we always deal with superuser
             $result = true;
         } else {
             // check access to mysql.user table
             $result = (bool) $GLOBALS['dbi']->tryQuery('SELECT COUNT(*) FROM mysql.user', $GLOBALS['userlink'], self::QUERY_STORE);
         }
         PMA_Util::cacheSet('is_superuser', $result, true);
     } else {
         PMA_Util::cacheSet('is_superuser', false, true);
     }
     return PMA_Util::cacheGet('is_superuser', true);
 }
Ejemplo n.º 6
0
/**
 * sets privilege information extracted from SHOW GRANTS result
 *
 * Detection for some CREATE privilege.
 *
 * Since MySQL 4.1.2, we can easily detect current user's grants using $userlink
 * (no control user needed) and we don't have to try any other method for
 * detection
 *
 * @todo fix to get really all privileges, not only explicitly defined for this user
 * from MySQL manual: (http://dev.mysql.com/doc/refman/5.0/en/show-grants.html)
 * SHOW GRANTS displays only the privileges granted explicitly to the named
 * account. Other privileges might be available to the account, but they are not
 * displayed. For example, if an anonymous account exists, the named account
 * might be able to use its privileges, but SHOW GRANTS will not display them.
 *
 * @return void
 */
function PMA_analyseShowGrant()
{
    if (PMA_Util::cacheExists('is_create_db_priv')) {
        $GLOBALS['is_create_db_priv'] = PMA_Util::cacheGet('is_create_db_priv');
        $GLOBALS['is_reload_priv'] = PMA_Util::cacheGet('is_reload_priv');
        $GLOBALS['db_to_create'] = PMA_Util::cacheGet('db_to_create');
        $GLOBALS['dbs_where_create_table_allowed'] = PMA_Util::cacheGet('dbs_where_create_table_allowed');
        $GLOBALS['dbs_to_test'] = PMA_Util::cacheGet('dbs_to_test');
        return;
    }
    // defaults
    $GLOBALS['is_create_db_priv'] = false;
    $GLOBALS['is_reload_priv'] = false;
    $GLOBALS['db_to_create'] = '';
    $GLOBALS['dbs_where_create_table_allowed'] = array();
    $GLOBALS['dbs_to_test'] = $GLOBALS['dbi']->getSystemSchemas();
    $rs_usr = $GLOBALS['dbi']->tryQuery('SHOW GRANTS');
    if (!$rs_usr) {
        return;
    }
    $re0 = '(^|(\\\\\\\\)+|[^\\\\])';
    // non-escaped wildcards
    $re1 = '(^|[^\\\\])(\\\\)+';
    // escaped wildcards
    while ($row = $GLOBALS['dbi']->fetchRow($rs_usr)) {
        // extract db from GRANT ... ON *.* or GRANT ... ON db.*
        $db_name_offset = mb_strpos($row[0], ' ON ') + 4;
        $show_grants_dbname = mb_substr($row[0], $db_name_offset, mb_strpos($row[0], '.', $db_name_offset) - $db_name_offset);
        $show_grants_dbname = PMA_Util::unQuote($show_grants_dbname, '`');
        $show_grants_str = mb_substr($row[0], 6, mb_strpos($row[0], ' ON ') - 6);
        if ($show_grants_dbname == '*') {
            if ($show_grants_str != 'USAGE') {
                $GLOBALS['dbs_to_test'] = false;
            }
        } elseif ($GLOBALS['dbs_to_test'] !== false) {
            $GLOBALS['dbs_to_test'][] = $show_grants_dbname;
        }
        if ($show_grants_str == 'RELOAD') {
            $GLOBALS['is_reload_priv'] = true;
        }
        /**
         * @todo if we find CREATE VIEW but not CREATE, do not offer
         * the create database dialog box
         */
        if ($show_grants_str == 'ALL' || $show_grants_str == 'ALL PRIVILEGES' || $show_grants_str == 'CREATE' || strpos($show_grants_str, 'CREATE,') !== false) {
            if ($show_grants_dbname == '*') {
                // a global CREATE privilege
                $GLOBALS['is_create_db_priv'] = true;
                $GLOBALS['is_reload_priv'] = true;
                $GLOBALS['db_to_create'] = '';
                $GLOBALS['dbs_where_create_table_allowed'][] = '*';
                // @todo we should not break here, cause GRANT ALL *.*
                // could be revoked by a later rule like GRANT SELECT ON db.*
                break;
            } else {
                // this array may contain wildcards
                $GLOBALS['dbs_where_create_table_allowed'][] = $show_grants_dbname;
                $dbname_to_test = PMA_Util::backquote($show_grants_dbname);
                if ($GLOBALS['is_create_db_priv']) {
                    // no need for any more tests if we already know this
                    continue;
                }
                // does this db exist?
                if (preg_match('/' . $re0 . '%|_/', $show_grants_dbname) && !preg_match('/\\\\%|\\\\_/', $show_grants_dbname) || !$GLOBALS['dbi']->tryQuery('USE ' . preg_replace('/' . $re1 . '(%|_)/', '\\1\\3', $dbname_to_test)) && mb_substr($GLOBALS['dbi']->getError(), 1, 4) != 1044) {
                    /**
                     * Do not handle the underscore wildcard
                     * (this case must be rare anyway)
                     */
                    $GLOBALS['db_to_create'] = preg_replace('/' . $re0 . '%/', '\\1', $show_grants_dbname);
                    $GLOBALS['db_to_create'] = preg_replace('/' . $re1 . '(%|_)/', '\\1\\3', $GLOBALS['db_to_create']);
                    $GLOBALS['is_create_db_priv'] = true;
                    /**
                     * @todo collect $GLOBALS['db_to_create'] into an array,
                     * to display a drop-down in the "Create database" dialog
                     */
                    // we don't break, we want all possible databases
                    //break;
                }
                // end if
            }
            // end elseif
        }
        // end if
    }
    // end while
    $GLOBALS['dbi']->freeResult($rs_usr);
    // must also cacheUnset() them in
    // libraries/plugins/auth/AuthenticationCookie.class.php
    PMA_Util::cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv']);
    PMA_Util::cacheSet('is_reload_priv', $GLOBALS['is_reload_priv']);
    PMA_Util::cacheSet('db_to_create', $GLOBALS['db_to_create']);
    PMA_Util::cacheSet('dbs_where_create_table_allowed', $GLOBALS['dbs_where_create_table_allowed']);
    PMA_Util::cacheSet('dbs_to_test', $GLOBALS['dbs_to_test']);
}
 /**
  * Checks if this database server is running on Amazon RDS.
  *
  * @return boolean
  */
 public function isAmazonRds()
 {
     if (PMA_Util::cacheExists('is_amazon_rds')) {
         return PMA_Util::cacheGet('is_amazon_rds');
     }
     $sql = 'SELECT @@basedir';
     $result = $this->fetchResult($sql);
     $rds = $result[0] == '/rdsdbbin/mysql/';
     PMA_Util::cacheSet('is_amazon_rds', $rds);
     return $rds;
 }