⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_privileges.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
        PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);        $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\'');    }}/** * Deletes users *   (Changes / copies a user, part IV) */$user_host_separator = chr(27);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();    }    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 ($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 \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';');                if ($res) {                    $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));                        if ($this_table != '*.*') {                            $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 \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';                            }                        }                        unset($this_table);                    }                    PMA_DBI_free_result($res);                }                unset($res);            }            if ( PMA_MYSQL_INT_VERSION >= 40101 ) {                $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';            } else {                $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 ($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 =                    ' 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;            }        }        if (!empty($drop_users_db)) {            $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';            $GLOBALS['reload'] = TRUE;            PMA_reloadNavigation();        }    }    if (empty($change_copy)) {        if (empty($queries)) {            $show_error_header = TRUE;            $message = $GLOBALS['strDeleteNoUsersSelected'];        } else {            if ($mode == 3) {                $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';                $queries[] = 'FLUSH PRIVILEGES;';            }            foreach ($queries as $sql_query) {                if ($sql_query{0} != '#') {                    PMA_DBI_query($sql_query, $GLOBALS['userlink']);                }            }            $sql_query = join("\n", $queries);            $message = $GLOBALS['strUsersDeleted'];        }        unset($queries);    }}/** * Changes / copies a user, part V */if (!empty($change_copy)) {    $tmp_count = 0;    foreach ($queries as $sql_query) {        if ($sql_query{0} != '#') {            PMA_DBI_query($sql_query);        }        // when there is a query containing a hidden password, take it        // instead of the real query sent        if (isset($queries_for_display[$tmp_count])) {            $queries[$tmp_count] = $queries_for_display[$tmp_count];        }        $tmp_count++;    }    $message = $GLOBALS['strSuccess'];    $sql_query = join("\n", $queries);}/** * Reloads the privilege tables into memory */if (!empty($flush_privileges)) {    $sql_query = 'FLUSH PRIVILEGES;';    PMA_DBI_query($sql_query);    $message = $GLOBALS['strPrivilegesReloaded'];}/** * Displays the links */if (isset($viewing_mode) && $viewing_mode == 'db') {     $db = $checkprivs;     $url_query .= '&amp;goto=db_operations.php';     // Gets the database structure     $sub_part = '_structure';     require('./libraries/db_details_db_info.inc.php');     echo "\n";} else {    require('./libraries/server_links.inc.php');}/** * defines some standard links */$link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']    .'&amp;username=%s'    .'&amp;hostname=%s'    .'&amp;dbname=%s'    .'&amp;tablename=%s">';if ( $GLOBALS['cfg']['PropertiesIconic'] ) {    $link_edit .= '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_usredit.png" width="16" height="16" alt="' . $GLOBALS['strEditPrivileges'] . '" title="' . $GLOBALS['strEditPrivileges'] . '" />';} else {    $link_edit .= $GLOBALS['strEditPrivileges'];}$link_edit .= '</a>';$link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']    .'&amp;username=%s'    .'&amp;hostname=%s'    .'&amp;dbname=%s'    .'&amp;tablename=%s'    .'&amp;revokeall=1">';if ( $GLOBALS['cfg']['PropertiesIconic'] ) {    $link_revoke .= '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_usrdrop.png" width="16" height="16" alt="' . $GLOBALS['strRevoke'] . '" title="' . $GLOBALS['strRevoke'] . '" />';} else {    $link_revoke .= $GLOBALS['strRevoke'];}$link_revoke .= '</a>';/** * Displays the page */if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) {    if ( ! isset( $username ) ) {        // No username is given --> display the overview        echo '<h2>' . "\n"           . ($GLOBALS['cfg']['MainPageIconic'] ? '<img class="icon" src="'. $GLOBALS['pmaThemeImage'] . 'b_usrlist.png" alt="" />' : '')           . $GLOBALS['strUserOverview'] . "\n"           . '</h2>' . "\n";        $sql_query =            'SELECT `User`,' .            '       `Host`,' .            '       IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '\'\', \'N\', \'Y\') AS \'Password\',' .            '       `Select_priv`,' .            '       `Insert_priv`,' .            '       `Update_priv`,' .            '       `Delete_priv`,' .            '       `Index_priv`,' .            '       `Alter_priv`,' .            '       `Create_priv`,' .            '       `Drop_priv`,' .            '       `Grant_priv`,' .            '       `References_priv`,' .            '       `Reload_priv`,' .            '       `Shutdown_priv`,' .            '       `Process_priv`,' .            '       `File_priv`';        if (PMA_MYSQL_INT_VERSION >= 40002) {            $sql_query .= ', `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`';        }        if (PMA_MYSQL_INT_VERSION >= 50001) {            $sql_query .= ', `Create_view_priv`, `Show_view_priv`';        }        if (PMA_MYSQL_INT_VERSION >= 50003) {            $sql_query .= ', `Create_user_priv`, `Create_routine_priv`, `Alter_routine_priv`';        }        $sql_query .= '  FROM `mysql`.`user`';        $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);        if (! $res) {            // the query failed! This may have two reasons:            // - the user does not have enough privileges            // - the privilege tables use a structure of an earlier version.            // so let's try a more simple query            $sql_query = 'SELECT * FROM `mysql`.`user`';            $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);            if (!$res) {                echo '<i>' . $GLOBALS['strNoPrivileges'] . '</i>' . "\n";                PMA_DBI_free_result($res);                unset($res);            } else {                // rabus: This message is hardcoded because I will replace it by                // a automatic repair feature soon.                echo '<div class="warning">' . "\n"                   . '    Warning: Your privilege table structure seems to be older than this MySQL version!<br />' . "\n"                   . '    Please run the script <tt>mysql_fix_privilege_tables</tt> that should be included in your MySQL server distribution to solve this problem!' . "\n"                   . '</div><br />' . "\n";            }        } else {            // we also want users not in table `user` but in other table            $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');            $tables_to_search_for_users = array(                'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',            );            $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($initial) ? PMA_RangeOfUsers($initial) : '');                }            }            $user_defaults = array(                'User'      => '',                'Host'      => '%',                'Password'  => '?',                'Grant_priv' => 'N',                'privs'     => array( 'USAGE' ),            );            // for all initials, even non A-Z            $array_initials = array();            // for the rights            $db_rights = array();            // do not use UNION DISTINCT,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -