📄 server_privileges.php
字号:
$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 (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 .= ';'; } $real_sql_query .= ';'; $sql_query .= ';'; if (empty($_REQUEST['change_copy'])) { $_error = false; if (isset($create_user_real)) { if (! PMA_DBI_try_query($create_user_real)) { $_error = true; } $sql_query = $create_user_show . $sql_query; } if ($_error || ! PMA_DBI_try_query($real_sql_query)) { $_REQUEST['createdb'] = false; $message = PMA_Message::rawError(PMA_DBI_getError()); } else { $message = PMA_Message::success('strAddUserMessage'); } switch (PMA_ifSetOr($_REQUEST['createdb'], '0')) { case '1' : $q = 'CREATE DATABASE IF NOT EXISTS ' . PMA_backquote(PMA_sqlAddslashes($username)) . ';'; $sql_query .= $q; if (! PMA_DBI_try_query($q)) { $message = PMA_Message::rawError(PMA_DBI_getError()); break; } $GLOBALS['reload'] = TRUE; PMA_reloadNavigation(); $q = 'GRANT ALL PRIVILEGES ON ' . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; $sql_query .= $q; if (! PMA_DBI_try_query($q)) { $message = PMA_Message::rawError(PMA_DBI_getError()); } break; case '2' : $q = 'GRANT ALL PRIVILEGES ON ' . PMA_backquote(PMA_sqlAddslashes($username) . '\_%') . '.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; $sql_query .= $q; if (! PMA_DBI_try_query($q)) { $message = PMA_Message::rawError(PMA_DBI_getError()); } break; case '0' : default : break; } } else { if (isset($create_user_real)) { $queries[] = $create_user_real; } $queries[] = $real_sql_query; // we put the query containing the hidden password in // $queries_for_display, at the same position occupied // by the real query in $queries $tmp_count = count($queries); if (isset($create_user_real)) { $queries_for_display[$tmp_count - 2] = $create_user_show; } $queries_for_display[$tmp_count - 1] = $sql_query; } unset($res, $real_sql_query); }}/** * Changes / copies a user, part III */if (isset($_REQUEST['change_copy'])) { $user_host_condition = ' WHERE `User`' .' = \'' . PMA_sqlAddslashes($old_username) . "'" .' AND `Host`' .' = \'' . $old_hostname . '\';'; $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($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); while ($row = PMA_DBI_fetch_assoc($res)) { $res2 = PMA_DBI_QUERY( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE `User`' .' = \'' . PMA_sqlAddslashes($old_username) . "'" .' AND `Host`' .' = \'' . $old_hostname . '\'' .' AND `Db`' .' = \'' . $row['Db'] . "'" .' AND `Table_name`' .' = \'' . $row['Table_name'] . "'" .';', null, PMA_DBI_QUERY_STORE); $tmp_privs1 = PMA_extractPrivInfo($row); $tmp_privs2 = array( 'Select' => array(), 'Insert' => array(), 'Update' => array(), 'References' => array() ); while ($row2 = PMA_DBI_fetch_assoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { $tmp_privs2['Select'][] = $row2['Column_name']; } if (in_array('Insert', $tmp_array)) { $tmp_privs2['Insert'][] = $row2['Column_name']; } if (in_array('Update', $tmp_array)) { $tmp_privs2['Update'][] = $row2['Column_name']; } if (in_array('References', $tmp_array)) { $tmp_privs2['References'][] = $row2['Column_name']; } unset($tmp_array); } if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) { $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)'; } if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) { $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)'; } if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) { $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)'; } 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($username) . '\'@\'' . $hostname . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';'); }}/** * Updates privileges */if (!empty($update_privs)) { $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, (isset($tablename) ? $tablename : '')); $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; if (!isset($Grant_priv) || $Grant_priv != 'Y') { $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; } else { $sql_query1 = ''; } // Should not do a GRANT USAGE for a table-specific privilege, it // causes problems later (cannot revoke it) if (! (isset($tablename) && 'USAGE' == implode('', PMA_extractPrivInfo()))) { $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; /** * @todo similar code appears twice in this script */ if ((isset($Grant_priv) && $Grant_priv == 'Y') || (! isset($dbname) && (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 (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 (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) $sql_query0 = ''; } if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too... $sql_query1 = ''; } if (isset($sql_query2)) { PMA_DBI_query($sql_query2); } else { $sql_query2 = ''; } $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2; $message = PMA_Message::success('strUpdatePrivMessage'); $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');}/** * Revokes Privileges */if (isset($_REQUEST['revokeall'])) { $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, isset($tablename) ? $tablename : ''); $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; PMA_DBI_query($sql_query0); if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too... $sql_query1 = ''; } $sql_query = $sql_query0 . ' ' . $sql_query1; $message = PMA_Message::success('strRevokeMessage'); $message->addParam('\'' . $username . '\'@\'' . $hostname . '\''); if (! isset($tablename)) { unset($dbname); } else { unset($tablename); }}/** * Updates the password */if (isset($_REQUEST['change_pw'])) { // similar logic in user_password.php $message = ''; if ($nopass == 0 && isset($pma_pw) && isset($pma_pw2)) { if ($pma_pw != $pma_pw2) { $message = PMA_Message::error('strPasswordNotSame'); } elseif (empty($pma_pw) || empty($pma_pw2)) { $message = PMA_Message::error('strPasswordEmpty'); } } // end if // here $nopass could be == 1 if (empty($message)) { $hashing_function = (!empty($pw_hash) && $pw_hash == 'old' ? 'OLD_' : '') . 'PASSWORD'; // in $sql_query which will be displayed, hide the password $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')'); $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($pma_pw) . '\')');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -