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

📄 server_privileges.php

📁 phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站点下就可以用了
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * * @version $Id: server_privileges.php 12167 2009-01-04 20:26:23Z lem9 $ *//** * */require_once './libraries/common.inc.php';/** * Does the common work */$GLOBALS['js_include'][] = 'server_privileges.js';$GLOBALS['js_include'][] = 'functions.js';require './libraries/server_common.inc.php';/** * Checks if a dropdown box has been used for selecting a database / table */if (PMA_isValid($_REQUEST['pred_tablename'])) {    $tablename = $_REQUEST['pred_tablename'];    unset($pred_tablename);} elseif (PMA_isValid($_REQUEST['tablename'])) {    $tablename = $_REQUEST['tablename'];} else {    unset($tablename);}if (PMA_isValid($_REQUEST['pred_dbname'])) {    $dbname = $_REQUEST['pred_dbname'];    unset($pred_dbname);} elseif (PMA_isValid($_REQUEST['dbname'])) {    $dbname = $_REQUEST['dbname'];} else {    unset($dbname);    unset($tablename);}if (isset($dbname)) {    $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';    if (isset($tablename)) {        $db_and_table .= PMA_backquote($tablename);    } else {        $db_and_table .= '*';    }} else {    $db_and_table = '*.*';}// check if given $dbanem is a wildcard or notif (isset($dbname)) {    //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {    if (preg_match('/(?<!\\\\)(?:_|%)/i', $dbname)) {        $dbname_is_wildcard = true;    } else {        $dbname_is_wildcard = false;    }}/** * Checks if the user is allowed to do what he tries to... */if (!$is_superuser) {    require './libraries/server_links.inc.php';    echo '<h2>' . "\n"       . PMA_getIcon('b_usrlist.png')       . $GLOBALS['strPrivileges'] . "\n"       . '</h2>' . "\n";    PMA_Message::error('strNoPrivileges')->display();    require_once './libraries/footer.inc.php';}/** * Escapes wildcard in a database+table specification * before using it in a GRANT statement. * * 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. Internally, in mysql.tables_priv.Db there are * no escaping (for example test_db) but in mysql.db you'll see test\_db * for a db-specific privilege. * * @param   string   $db_and_table  * @param   string   $dbname * @param   string   $tablename * @return  string   the escaped (if necessary) $db_and_table  */function PMA_WildcardEscapeForGrant($db_and_table, $dbname, $tablename) {    if (! strlen($dbname)) {        $db_and_table = '*.*';    } else {        if (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 .= '*';        }    }    return $db_and_table;}/** * Generates a condition on the user name * * @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    if (!empty($initial)) {        $ret = " WHERE `User` LIKE '" . $initial . "%'"            . " OR `User` LIKE '" . strtolower($initial) . "%'";    } else {        $ret = '';    }    return $ret;} // end function/** * Extracts the privilege information of a priv table row * * @param   array   $row        the row * @param   boolean $enableHTML add <dfn> tag with tooltips * * @global  ressource $user_link the database connection * * @return  array */function PMA_extractPrivInfo($row = '', $enableHTML = FALSE){    $grants = array(        array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),        array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),        array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),        array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),        array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),        array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),        array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),        array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),        array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess']),        array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),        array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),        array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),        array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),        array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),        array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),        array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),        array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),        array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),        array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),        array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),        array('Event_priv', 'EVENT', $GLOBALS['strPrivDescEvent']),        array('Trigger_priv', 'TRIGGER', $GLOBALS['strPrivDescTrigger']),        // for table privs:        array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),        array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),        // for table privs:        array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),        array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),        array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),        array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']),        array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),    );    if (!empty($row) && isset($row['Table_priv'])) {        $row1 = PMA_DBI_fetch_single_row(            'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',            'ASSOC', $GLOBALS['userlink']);        $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;    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'])))))            {                if ($enableHTML) {                    $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';                } else {                    $privs[] = $current_grant[1];                }            } elseif (!empty($GLOBALS[$current_grant[0]])             && is_array($GLOBALS[$current_grant[0]])             && empty($GLOBALS[$current_grant[0] . '_none'])) {                if ($enableHTML) {                    $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';                } else {                    $priv_string = $current_grant[1];                }                $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';            } else {                $allPrivileges = FALSE;            }        }    }    if (empty($privs)) {        if ($enableHTML) {            $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';        } else {            $privs[] = 'USAGE';        }    } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {        if ($enableHTML) {            $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');        } else {            $privs = array('ALL PRIVILEGES');        }    }    return $privs;} // end of the 'PMA_extractPrivInfo()' function/** * Displays on which column(s) a table-specific privilege is granted */function PMA_display_column_privs($columns, $row, $name_for_select,    $priv_for_header, $name, $name_for_dfn, $name_for_current){        echo '    <div class="item" id="div_item_' . $name . '">' . "\n"           . '        <label for="select_' . $name . '_priv">' . "\n"           . '            <tt><dfn title="' . $name_for_dfn . '">'            . $priv_for_header . '</dfn></tt>' . "\n"           . '        </label><br />' . "\n"           . '        <select id="select_' . $name . '_priv" name="'            . $name_for_select . '[]" multiple="multiple" size="8">' . "\n";        foreach ($columns as $current_column => $current_column_privileges) {            echo '            <option value="' . htmlspecialchars($current_column) . '"';            if ($row[$name_for_select] == 'Y' || $current_column_privileges[$name_for_current]) {                echo ' selected="selected"';            }            echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";        }        echo '        </select>' . "\n"           . '        <i>' . $GLOBALS['strOr'] . '</i>' . "\n"           . '        <label for="checkbox_' . $name_for_select            . '_none"><input type="checkbox"'            . (empty($GLOBALS['checkall']) ?  '' : ' checked="checked"')            . ' name="' . $name_for_select . '_none" id="checkbox_'            . $name_for_select . '_none" title="' . $GLOBALS['strNone'] . '" />'            . $GLOBALS['strNone'] . '</label>' . "\n"           . '    </div>' . "\n";} // end function/** * Displays the privileges form table * * @param   string  $db     the database * @param   string  $table  the table * @param   boolean $submit wheather to display the submit button or not * @global  array      $cfg         the phpMyAdmin configuration * @global  ressource  $user_link   the database connection * * @return  void */function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE){    if ($db == '*') {        $table = '*';    }    if (isset($GLOBALS['username'])) {        $username = $GLOBALS['username'];        $hostname = $GLOBALS['hostname'];        if ($db == '*') {            $sql_query =                 "SELECT * FROM `mysql`.`user`"                ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"                ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";        } elseif ($table == '*') {            $sql_query =                "SELECT * FROM `mysql`.`db`"                ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"                ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"                ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"                ." LIKE `Db`;";

⌨️ 快捷键说明

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