3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
10 $js_to_run = 'server_privileges.js';
11 require('./libraries/server_common.inc.php');
15 * Checks if a dropdown box has been used for selecting a database / table
17 if (isset($pred_dbname) && strlen($pred_dbname)) {
18 $dbname = $pred_dbname;
21 if (isset($pred_tablename) && strlen($pred_tablename)) {
22 $tablename = $pred_tablename;
23 unset($pred_tablename);
26 // check if given $dbanem is a wildcard or not
27 if ( isset( $dbname ) ) {
28 //if ( preg_match( '/\\\\(?:_|%)/i', $dbname ) ) {
29 if ( preg_match( '/(?<!\\\\)(?:_|%)/i', $dbname ) ) {
30 $dbname_is_wildcard = true;
32 $dbname_is_wildcard = false;
37 * Checks if the user is allowed to do what he tries to...
40 require('./libraries/server_links.inc.php');
42 . ($GLOBALS['cfg']['MainPageIconic'] ?
'<img class="icon" src="'. $GLOBALS['pmaThemeImage'] . 'b_usrlist.png" alt="" />' : '')
43 . $GLOBALS['strPrivileges'] . "\n"
45 . $GLOBALS['strNoPrivileges'] . "\n";
46 require_once('./libraries/footer.inc.php');
50 * Generates a condition on the user name
52 * @param string the user's initial
53 * @return string the generated condition
55 function PMA_RangeOfUsers($initial = '') {
56 // strtolower() is used because the User field
57 // might be BINARY, so LIKE would be case sensitive
58 if (!empty($initial)) {
59 $ret = " WHERE " . PMA_convert_using('User')
60 . " LIKE " . PMA_convert_using($initial . '%', 'quoted')
61 . " OR ". PMA_convert_using('User')
62 . " LIKE " . PMA_convert_using(strtolower($initial) . '%', 'quoted');
70 * Extracts the privilege information of a priv table row
72 * @param array $row the row
73 * @param boolean $enableHTML add <dfn> tag with tooltips
75 * @global ressource $user_link the database connection
79 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
82 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
83 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
84 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
85 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
86 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
87 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
88 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
89 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
90 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess' . ((!empty($row) && isset($row['Super_priv'])) ||
(empty($row) && isset($GLOBALS['Super_priv'])) ?
'4' : '3')]),
91 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
92 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
93 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
94 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
95 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
96 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
97 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
98 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
99 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
100 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),
101 array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
103 array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
104 array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
106 array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
107 array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
108 array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
109 array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser'])
111 if (PMA_MYSQL_INT_VERSION
>= 40002 && PMA_MYSQL_INT_VERSION
<50003) {
112 $grants[] = array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
114 $grants[] = array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']);
117 if (!empty($row) && isset($row['Table_priv'])) {
118 $res = PMA_DBI_query(
119 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
120 $GLOBALS['userlink'] );
121 $row1 = PMA_DBI_fetch_assoc($res);
122 PMA_DBI_free_result($res);
123 $av_grants = explode ('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7));
125 $users_grants = explode(',', $row['Table_priv']);
126 foreach ($av_grants as $current_grant) {
127 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ?
'Y' : 'N';
129 unset($current_grant);
131 unset($users_grants);
134 $allPrivileges = TRUE;
135 foreach ($grants as $current_grant) {
136 if ((!empty($row) && isset($row[$current_grant[0]])) ||
(empty($row) && isset($GLOBALS[$current_grant[0]]))) {
137 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']))))) {
139 $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
141 $privs[] = $current_grant[1];
143 } elseif (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) {
145 $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
147 $priv_string = $current_grant[1];
149 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
151 $allPrivileges = FALSE;
157 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
161 } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) ||
count($privs) == $GLOBALS['grant_count'])) {
163 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
165 $privs = array('ALL PRIVILEGES');
169 } // end of the 'PMA_extractPrivInfo()' function
173 * Displays on which column(s) a table-specific privilege is granted
175 function PMA_display_column_privs($spaces, $columns, $row, $name_for_select, $priv_for_header, $name, $name_for_dfn, $name_for_current) {
177 echo $spaces . ' <div class="item" id="div_item_' . $name . '">' . "\n"
178 . $spaces . ' <label for="select_' . $name . '_priv">' . "\n"
179 . $spaces . ' <tt><dfn title="' . $name_for_dfn . '">' . $priv_for_header . '</dfn></tt>' . "\n"
180 . $spaces . ' </label>' . "\n"
181 . $spaces . ' <select id="select_' . $name . '_priv" name="' . $name_for_select . '[]" multiple="multiple">' . "\n";
183 foreach ($columns as $current_column => $current_column_privileges) {
184 echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
185 if ($row[$name_for_select] == 'Y' ||
$current_column_privileges[$name_for_current]) {
186 echo ' selected="selected"';
188 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
191 echo $spaces . ' </select>' . "\n"
192 . $spaces . ' <i>' . $GLOBALS['strOr'] . '</i>' . "\n"
193 . $spaces . ' <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'] . '" />'
194 . $GLOBALS['strNone'] . '</label>' . "\n"
195 . $spaces . ' </div>' . "\n";
199 * Displays the privileges form table
201 * @param string $db the database
202 * @param string $table the table
203 * @param boolean $submit wheather to display the submit button or not
204 * @param int $indent the indenting level of the code
206 * @global array $cfg the phpMyAdmin configuration
207 * @global ressource $user_link the database connection
211 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
216 $spaces = str_repeat( ' ', $indent );
218 if (isset($GLOBALS['username'])) {
219 $username = $GLOBALS['username'];
220 $hostname = $GLOBALS['hostname'];
223 'SELECT * FROM `mysql`.`user`'
224 .' WHERE ' . PMA_convert_using('User')
225 .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
226 .' AND ' . PMA_convert_using('Host')
227 .' = ' . PMA_convert_using($hostname, 'quoted') . ';';
228 } elseif ($table == '*') {
230 'SELECT * FROM `mysql`.`db`'
231 .' WHERE ' . PMA_convert_using('`User`')
232 .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
233 .' AND ' . PMA_convert_using('`Host`')
234 .' = ' . PMA_convert_using($hostname, 'quoted')
235 .' AND ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' )
236 .' LIKE ' . PMA_convert_using( '`Db`' ) . ';';
239 'SELECT `Table_priv`'
240 .' FROM `mysql`.`tables_priv`'
241 .' WHERE ' . PMA_convert_using('`User`')
242 .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
243 .' AND ' .PMA_convert_using('`Host`')
244 .' = ' . PMA_convert_using( $hostname, 'quoted' )
245 .' AND ' .PMA_convert_using('`Db`')
246 .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' )
247 .' AND ' . PMA_convert_using('`Table_name`')
248 .' = ' . PMA_convert_using($table, 'quoted') . ';';
250 $res = PMA_DBI_query($sql_query);
251 $row = PMA_DBI_fetch_assoc($res);
252 PMA_DBI_free_result($res);
257 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
258 } elseif ($table == '*') {
259 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
261 $res = PMA_DBI_query($sql_query);
262 while ($row1 = PMA_DBI_fetch_row($res)) {
263 if (substr($row1[0], 0, 4) == 'max_') {
266 $row[$row1[0]] = 'N';
269 PMA_DBI_free_result($res);
271 $row = array('Table_priv' => '');
274 if (isset($row['Table_priv'])) {
275 $res = PMA_DBI_query(
276 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
277 $GLOBALS['userlink'] );
278 // note: in MySQL 5.0.3 we get "Create View', 'Show view';
279 // the View for Create is spelled with uppercase V
280 // the view for Show is spelled with lowercase v
281 // and there is a space between the words
283 $row1 = PMA_DBI_fetch_assoc($res);
284 PMA_DBI_free_result($res);
285 $av_grants = explode ('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') +
2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
287 $users_grants = explode(',', $row['Table_priv']);
289 foreach ($av_grants as $current_grant) {
290 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ?
'Y' : 'N';
292 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
295 $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards( $db ) . '`.`' . $table . '`;');
298 while ($row1 = PMA_DBI_fetch_row($res)) {
299 $columns[$row1[0]] = array(
303 'References' => FALSE
306 PMA_DBI_free_result($res);
310 // t a b l e - s p e c i f i c p r i v i l e g e s
311 if ( ! empty( $columns ) ) {
312 $res = PMA_DBI_query(
313 'SELECT `Column_name`, `Column_priv`'
314 .' FROM `mysql`.`columns_priv`'
315 .' WHERE ' . PMA_convert_using('`User`')
316 .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
317 .' AND ' . PMA_convert_using('`Host`')
318 .' = ' . PMA_convert_using($hostname, 'quoted')
319 .' AND ' . PMA_convert_using('`Db`')
320 .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted')
321 .' AND ' . PMA_convert_using('`Table_name`')
322 .' = ' . PMA_convert_using($table, 'quoted') . ';');
324 while ($row1 = PMA_DBI_fetch_row($res)) {
325 $row1[1] = explode(',', $row1[1]);
326 foreach ($row1[1] as $current) {
327 $columns[$row1[0]][$current] = TRUE;
330 PMA_DBI_free_result($res);
331 unset( $res, $row1, $current );
333 echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
334 . $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
335 . $spaces . '<fieldset id="fieldset_user_priv">' . "\n"
336 . $spaces . ' <legend>' . $GLOBALS['strTblPrivileges'] . '</legend>' . "\n"
337 . $spaces . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n";
340 // privs that are attached to a specific column
341 PMA_display_column_privs($spaces, $columns, $row, 'Select_priv', 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select');
343 PMA_display_column_privs($spaces, $columns, $row, 'Insert_priv', 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert');
345 PMA_display_column_privs($spaces, $columns, $row, 'Update_priv', 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update');
347 PMA_display_column_privs($spaces, $columns, $row, 'References_priv', 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References');
349 // privs that are not attached to a specific column
351 echo $spaces . ' <div class="item">' . "\n";
352 foreach ($row as $current_grant => $current_grant_value) {
353 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
356 // make a substitution to match the messages variables;
357 // also we must substitute the grant we get, because we can't generate
358 // a form variable containing blanks (those would get changed to
359 // an underscore when receiving the POST)
360 if ($current_grant == 'Create View_priv') {
361 $tmp_current_grant = 'CreateView_priv';
362 $current_grant = 'Create_view_priv';
363 } elseif ($current_grant == 'Show view_priv') {
364 $tmp_current_grant = 'ShowView_priv';
365 $current_grant = 'Show_view_priv';
367 $tmp_current_grant = $current_grant;
370 echo $spaces . ' <div class="item">' . "\n"
371 . $spaces . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ?
'checked="checked" ' : '') . 'title="';
373 echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ?
$GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";
375 echo $spaces . ' <label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ?
$GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n"
376 . $spaces . ' </div>' . "\n";
379 echo $spaces . ' </div>' . "\n";
381 echo $spaces . ' <div class="clearfloat"></div>' . "\n";
385 // g l o b a l o r d b - s p e c i f i c
388 $privTable[0] = array(
389 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
390 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
391 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
392 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
395 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
399 $privTable[1] = array(
400 array('Create', 'CREATE', ($table == '*' ?
$GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
401 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
402 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
403 array('Drop', 'DROP', ($table == '*' ?
$GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl']))
405 if (isset($row['Create_tmp_table_priv'])) {
406 $privTable[1][] = array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']);
408 // this one is for a db-specific priv: Create_view_priv
409 if (isset($row['Create_view_priv'])) {
410 $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
412 // this one is for a table-specific priv: Create View_priv
413 if (isset($row['Create View_priv'])) {
414 $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
416 if (isset($row['Show_view_priv'])) {
417 $privTable[1][] = array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']);
419 if (isset($row['Create_routine_priv'])) {
420 $privTable[1][] = array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']);
422 if (isset($row['Alter_routine_priv'])) {
423 $privTable[1][] = array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']);
425 if (isset($row['Execute_priv'])) {
426 if (PMA_MYSQL_INT_VERSION
>= 40002 && PMA_MYSQL_INT_VERSION
<50003) {
427 $privTable[1][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
429 $privTable[1][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']);
433 // a d m i n i s t r a t i o n
434 $privTable[2] = array();
435 if (isset($row['Grant_priv'])) {
436 $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']);
439 if (isset($row['Super_priv'])) {
440 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
441 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']);
443 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']);
445 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
446 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
447 if (isset($row['Show_db_priv'])) {
448 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
451 if (isset($row['Lock_tables_priv'])) {
452 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
454 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
456 //if (isset($row['Execute_priv'])) {
457 // $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
459 if (isset($row['Repl_client_priv'])) {
460 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
462 if (isset($row['Repl_slave_priv'])) {
463 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
465 if (isset($row['Create_user_priv'])) {
466 $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']);
469 echo $spaces . '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) +
count($privTable[1]) +
count($privTable[2]) - (isset($row['Grant_priv']) ?
1 : 0)) . '" />' . "\n"
470 . $spaces . '<fieldset id="fieldset_user_global_rights">' . "\n"
471 . $spaces . ' <legend>' . "\n"
472 . $spaces . ' ' . ($db == '*' ?
$GLOBALS['strGlobalPrivileges'] : ($table == '*' ?
$GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . "\n"
473 . $spaces . ' ( <a href="./server_privileges.php?' . $GLOBALS['url_query'] . '&checkall=1" onclick="setCheckboxes(\'usersForm\', true); return false;">' . $GLOBALS['strCheckAll'] . '</a> /' . "\n"
474 . $spaces . ' <a href="./server_privileges.php?' . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'usersForm\', false); return false;">' . $GLOBALS['strUncheckAll'] . '</a> )' . "\n"
475 . $spaces . ' </legend>' . "\n"
476 . $spaces . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n"
477 . $spaces . ' <fieldset>' . "\n"
478 . $spaces . ' <legend>' . $GLOBALS['strData'] . '</legend>' . "\n";
479 foreach ( $privTable[0] as $priv )
481 echo $spaces . ' <div class="item">' . "\n"
482 . $spaces . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"') . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv" value="Y" ' . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '') . 'title="' . $priv[2] . '"/>' . "\n"
483 . $spaces . ' <label for="checkbox_' . $priv[0] . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1] . '</dfn></tt></label>' . "\n"
484 . $spaces . ' </div>' . "\n";
486 echo $spaces . ' </fieldset>' . "\n"
487 . $spaces . ' <fieldset>' . "\n"
488 . $spaces . ' <legend>' . $GLOBALS['strStructure'] . '</legend>' . "\n";
489 foreach ( $privTable[1] as $priv )
491 echo $spaces . ' <div class="item">' . "\n"
492 . $spaces . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"') . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv" value="Y" ' . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '') . 'title="' . $priv[2] . '"/>' . "\n"
493 . $spaces . ' <label for="checkbox_' . $priv[0] . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1] . '</dfn></tt></label>' . "\n"
494 . $spaces . ' </div>' . "\n";
496 echo $spaces . ' </fieldset>' . "\n"
497 . $spaces . ' <fieldset>' . "\n"
498 . $spaces . ' <legend>' . $GLOBALS['strAdministration'] . '</legend>' . "\n";
499 foreach ( $privTable[2] as $priv )
501 echo $spaces . ' <div class="item">' . "\n"
502 . $spaces . ' <input type="checkbox"' . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"') . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv" value="Y" ' . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '') . 'title="' . $priv[2] . '"/>' . "\n"
503 . $spaces . ' <label for="checkbox_' . $priv[0] . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1] . '</dfn></tt></label>' . "\n"
504 . $spaces . ' </div>' . "\n";
507 echo $spaces . ' </fieldset>' . "\n";
508 // The "Resource limits" box is not displayed for db-specific privs
509 if ($db == '*' && PMA_MYSQL_INT_VERSION
>= 40002) {
510 echo $spaces . ' <fieldset>' . "\n"
511 . $spaces . ' <legend>' . $GLOBALS['strResourceLimits'] . '</legend>' . "\n"
512 . $spaces . ' <p><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></p>' . "\n"
513 . $spaces . ' <div class="item">' . "\n"
514 . $spaces . ' <label for="text_max_questions"><tt><dfn title="' . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label>' . "\n"
515 . $spaces . ' <input type="text" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" />' . "\n"
516 . $spaces . ' </div>' . "\n"
517 . $spaces . ' <div class="item">' . "\n"
518 . $spaces . ' <label for="text_max_updates"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label>' . "\n"
519 . $spaces . ' <input type="text" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" />' . "\n"
520 . $spaces . ' </div>' . "\n"
521 . $spaces . ' <div class="item">' . "\n"
522 . $spaces . ' <label for="text_max_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label>' . "\n"
523 . $spaces . ' <input type="text" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" />' . "\n"
524 . $spaces . ' </div>' . "\n";
526 if (PMA_MYSQL_INT_VERSION
>= 50003) {
527 echo $spaces . ' <div class="item">' . "\n"
528 . $spaces . ' <label for="text_max_user_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '">MAX USER_CONNECTIONS</dfn></tt></label>' . "\n"
529 . $spaces . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="' . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '" />' . "\n"
530 . $spaces . ' </div>' . "\n";
532 echo $spaces . ' </fieldset>' . "\n";
535 echo $spaces . ' <div class="clearfloat"></div>' . "\n";
537 echo $spaces . '</fieldset>' . "\n";
539 echo $spaces . '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
540 . $spaces . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
541 . $spaces . '</fieldset>' . "\n";
543 } // end of the 'PMA_displayPrivTable()' function
547 * Displays the fields used by the "new user" form as well as the
548 * "change login information / copy user" form.
550 * @param string $mode are we creating a new user or are we just
551 * changing one? (allowed values: 'new', 'change')
552 * @param int $indent the indenting level of the code
554 * @global array $cfg the phpMyAdmin configuration
555 * @global ressource $user_link the database connection
559 function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) {
560 $spaces = str_repeat( ' ', $indent);
562 // Get user/host name lengths
563 $fields_info = PMA_DBI_get_fields('mysql', 'user');
564 $username_length = 16;
565 $hostname_length = 41;
566 foreach ($fields_info as $key => $val) {
567 if ($val['Field'] == 'User') {
568 strtok($val['Type'], '()');
571 $username_length = $v;
573 } elseif ($val['Field'] == 'Host') {
574 strtok($val['Type'], '()');
577 $hostname_length = $v;
583 if ( isset( $GLOBALS['username'] ) && strlen( $GLOBALS['username'] ) === 0 ) {
584 $GLOBALS['pred_username'] = 'any';
586 echo $spaces . '<fieldset id="fieldset_add_user_login">' . "\n"
587 . $spaces . '<legend>' . $GLOBALS['strLoginInformation'] . '</legend>' . "\n"
588 . $spaces . '<div class="item">' . "\n"
589 . $spaces . '<label for="select_pred_username">' . "\n"
590 . $spaces . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
591 . $spaces . '</label>' . "\n"
592 . $spaces . '<span class="options">' . "\n"
593 . $spaces . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
594 . $spaces . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
595 . $spaces . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
596 . $spaces . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) ||
$GLOBALS['pred_username'] == 'userdefined') ?
' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
597 . $spaces . ' </select>' . "\n"
598 . $spaces . '</span>' . "\n"
599 . $spaces . '<input type="text" name="username" maxlength="' . $username_length . '" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ?
'' : ' value="' . (isset($GLOBALS['new_username']) ?
$GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
600 . $spaces . '</div>' . "\n"
601 . $spaces . '<div class="item">' . "\n"
602 . $spaces . '<label for="select_pred_hostname">' . "\n"
603 . $spaces . ' ' . $GLOBALS['strHost'] . ':' . "\n"
604 . $spaces . '</label>' . "\n"
605 . $spaces . '<span class="options">' . "\n"
606 . $spaces . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
607 $res = PMA_DBI_query('SELECT USER();');
608 $row = PMA_DBI_fetch_row($res);
609 PMA_DBI_free_result($res);
611 if (!empty($row[0])) {
612 $thishost = str_replace("'", '', substr($row[0], (strrpos($row[0], '@') +
1)));
613 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
617 echo $spaces . ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
618 . (empty($thishost) ?
'' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
619 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
622 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
623 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
624 switch (strtolower($GLOBALS['hostname'])) {
627 $GLOBALS['pred_hostname'] = 'localhost';
630 $GLOBALS['pred_hostname'] = 'any';
633 $GLOBALS['pred_hostname'] = 'userdefined';
637 echo $spaces . ' <option value="any"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any') ?
' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n"
638 . $spaces . ' <option value="localhost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost') ?
' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n";
639 if (!empty($thishost)) {
640 echo $spaces . ' <option value="thishost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost') ?
' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n";
643 echo $spaces . ' <option value="hosttable"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable') ?
' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n"
644 . $spaces . ' <option value="userdefined"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined') ?
' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
645 . $spaces . ' </select>' . "\n"
646 . $spaces . '</span>' . "\n"
647 . $spaces . '<input type="text" name="hostname" maxlength="' . $hostname_length . '" value="' . ( isset($GLOBALS['hostname']) ?
$GLOBALS['hostname'] : '' ) . '" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
648 . $spaces . '</div>' . "\n"
649 . $spaces . '<div class="item">' . "\n"
650 . $spaces . '<label for="select_pred_password">' . "\n"
651 . $spaces . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
652 . $spaces . '</label>' . "\n"
653 . $spaces . '<span class="options">' . "\n"
654 . $spaces . ' <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n"
655 . $spaces . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
656 . ($mode == 'change' ?
$spaces . ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
657 . $spaces . ' <option value="none"';
658 if ( isset( $GLOBALS['username'] ) && $mode != 'change' ) {
659 echo ' selected="selected"';
661 echo $spaces . '>' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
662 . $spaces . ' <option value="userdefined"' . ( isset( $GLOBALS['username'] ) ?
'' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
663 . $spaces . ' </select>' . "\n"
664 . $spaces . '</span>' . "\n"
665 . $spaces . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
666 . $spaces . '</div>' . "\n"
667 . $spaces . '<div class="item">' . "\n"
668 . $spaces . '<label for="text_pma_pw2">' . "\n"
669 . $spaces . ' ' . $GLOBALS['strReType'] . ':' . "\n"
670 . $spaces . '</label>' . "\n"
671 . $spaces . '<span class="options"> </span>' . "\n"
672 . $spaces . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
673 . $spaces . '</div>' . "\n"
674 . $spaces . '<div class="item">' . "\n"
675 . $spaces . '<label for="button_generate_password">' . "\n"
676 . $spaces . ' ' . $GLOBALS['strGeneratePassword'] . ':' . "\n"
677 . $spaces . '</label>' . "\n"
678 . $spaces . '<span class="options">' . "\n"
679 . $spaces . ' <input type="button" id="button_generate_password" value="' . $GLOBALS['strGenerate'] . '" onclick="suggestPassword()" />' . "\n"
680 . $spaces . ' <input type="button" id="button_copy_password" value="' . $GLOBALS['strCopy'] . '" onclick="suggestPasswordCopy(this.form)" />' . "\n"
681 . $spaces . '</span>' . "\n"
682 . $spaces . '<input type="text" name="generated_pw" id="generated_pw" />' . "\n"
683 . $spaces . '</div>' . "\n"
684 . $spaces . '</fieldset>' . "\n";
685 } // end of the 'PMA_displayUserAndHostFields()' function
689 * Changes / copies a user, part I
691 if (!empty($change_copy)) {
692 $user_host_condition =
693 ' WHERE ' . PMA_convert_using('User')
694 .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted')
695 .' AND ' . PMA_convert_using('Host')
696 .' = ' . PMA_convert_using($old_hostname, 'quoted') . ';';
697 $res = PMA_DBI_query('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
699 $message = $GLOBALS['strNoUsersFound'];
702 $row = PMA_DBI_fetch_assoc($res);
703 extract($row, EXTR_OVERWRITE
);
704 // Recent MySQL versions have the field "Password" in mysql.user,
705 // so the previous extract creates $Password but this script
707 if (!isset($password) && isset($Password)) {
710 PMA_DBI_free_result($res);
718 * (Changes / copies a user, part II)
720 if (!empty($adduser_submit) ||
!empty($change_copy)) {
722 if ($pred_username == 'any') {
725 switch ($pred_hostname) {
730 $hostname = 'localhost';
736 $res = PMA_DBI_query('SELECT USER();');
737 $row = PMA_DBI_fetch_row($res);
738 PMA_DBI_free_result($res);
740 $hostname = substr($row[0], (strrpos($row[0], '@') +
1));
744 $res = PMA_DBI_query(
745 'SELECT \'foo\' FROM `mysql`.`user`'
746 .' WHERE ' . PMA_convert_using('User')
747 .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
748 .' AND ' . PMA_convert_using('Host')
749 .' = ' . PMA_convert_using($hostname, 'quoted') . ';',
750 null, PMA_DBI_QUERY_STORE
);
751 if (PMA_DBI_num_rows($res) == 1) {
752 PMA_DBI_free_result($res);
753 $message = sprintf($GLOBALS['strUserAlreadyExists'], '[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
756 PMA_DBI_free_result($res);
758 if (50002 <= PMA_MYSQL_INT_VERSION
) {
759 // MySQL 5 requires CREATE USER before any GRANT on this user can done
760 $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
764 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \''
765 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
766 if ($pred_password != 'none' && $pred_password != 'keep') {
767 $pma_pw_hidden = str_repeat('*', strlen($pma_pw));
768 $sql_query = $real_sql_query . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\'';
769 $real_sql_query .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
770 if ( isset( $create_user_real ) ) {
771 $create_user_show = $create_user_real . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\'';
772 $create_user_real .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
775 if ($pred_password == 'keep' && !empty($password)) {
776 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
777 if ( isset( $create_user_real ) ) {
778 $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
781 $sql_query = $real_sql_query;
782 if ( isset( $create_user_real ) ) {
783 $create_user_show = $create_user_real;
787 * @todo similar code appears twice in this script
789 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)))) {
790 $real_sql_query .= 'WITH';
791 $sql_query .= 'WITH';
792 if (isset($Grant_priv) && $Grant_priv == 'Y') {
793 $real_sql_query .= ' GRANT OPTION';
794 $sql_query .= ' GRANT OPTION';
796 if (PMA_MYSQL_INT_VERSION
>= 40002) {
797 if (isset($max_questions)) {
798 // avoid negative values
799 $max_questions = max(0, (int)$max_questions);
800 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
801 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
803 if (isset($max_connections)) {
804 $max_connections = max(0, (int)$max_connections);
805 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
806 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
808 if (isset($max_updates)) {
809 $max_updates = max(0, (int)$max_updates);
810 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
811 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
814 if (PMA_MYSQL_INT_VERSION
>= 50003) {
815 if (isset($max_user_connections)) {
816 $max_user_connections = max(0, (int)$max_user_connections);
817 $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
818 $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
822 if ( isset( $create_user_real ) ) {
823 $create_user_real .= ';';
824 $create_user_show .= ';';
826 $real_sql_query .= ';';
828 if (empty($change_copy)) {
829 if ( isset( $create_user_real ) ) {
830 PMA_DBI_try_query($create_user_real) or PMA_mysqlDie(PMA_DBI_getError(), $create_user_show);
831 $sql_query = $create_user_show . $sql_query;
833 PMA_DBI_try_query($real_sql_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
834 $message = $GLOBALS['strAddUserMessage'];
836 /* Create database for new user */
837 if (isset($createdb) && $createdb > 0) {
838 if ($createdb == 1) {
839 $q = 'CREATE DATABASE ' . PMA_backquote(PMA_sqlAddslashes($username)) . ';';
841 PMA_DBI_try_query($q) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
843 $q = 'GRANT ALL PRIVILEGES ON ' . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
845 PMA_DBI_try_query($q) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
846 } elseif ($createdb == 2) {
847 $q = 'GRANT ALL PRIVILEGES ON ' . PMA_backquote(PMA_sqlAddslashes($username) . '_%') . '.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
849 PMA_DBI_try_query($q) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
853 if ( isset( $create_user_real ) ) {
854 $queries[] = $create_user_real;
856 $queries[] = $real_sql_query;
857 // we put the query containing the hidden password in
858 // $queries_for_display, at the same position occupied
859 // by the real query in $queries
860 $tmp_count = count($queries);
861 if ( isset( $create_user_real ) ) {
862 $queries_for_display[$tmp_count - 2] = $create_user_show;
864 $queries_for_display[$tmp_count - 1] = $sql_query;
866 unset($res, $real_sql_query);
872 * Changes / copies a user, part III
874 if (!empty($change_copy)) {
875 $user_host_condition =
876 ' WHERE ' . PMA_convert_using('User')
877 .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted')
878 .' AND ' . PMA_convert_using('Host')
879 .' = ' . PMA_convert_using($old_hostname, 'quoted') . ';';
880 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition );
881 while ($row = PMA_DBI_fetch_assoc($res)) {
883 'GRANT ' . join(', ', PMA_extractPrivInfo($row))
884 .' ON `' . $row['Db'] . '`.*'
885 .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
886 . ( $row['Grant_priv'] == 'Y' ?
' WITH GRANT OPTION;' : ';' );
888 PMA_DBI_free_result($res);
889 $res = PMA_DBI_query(
890 'SELECT `Db`, `Table_name`, `Table_priv`'
891 .' FROM `mysql`.`tables_priv`' . $user_host_condition,
892 $GLOBALS['userlink'], PMA_DBI_QUERY_STORE
);
893 while ($row = PMA_DBI_fetch_assoc($res)) {
895 $res2 = PMA_DBI_QUERY(
896 'SELECT `Column_name`, `Column_priv`'
897 .' FROM `mysql`.`columns_priv`'
898 .' WHERE ' . PMA_convert_using('User')
899 .' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted')
900 .' AND ' . PMA_convert_using('`Host`')
901 .' = ' . PMA_convert_using($old_hostname, 'quoted')
902 .' AND ' . PMA_convert_using('`Db`')
903 .' = ' . PMA_convert_using($row['Db'], 'quoted')
904 .' AND ' . PMA_convert_using('`Table_name`')
905 .' = ' . PMA_convert_using($row['Table_name'], 'quoted')
907 null, PMA_DBI_QUERY_STORE
);
909 $tmp_privs1 = PMA_extractPrivInfo($row);
914 'References' => array()
917 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
918 $tmp_array = explode(',', $row2['Column_priv']);
919 if (in_array('Select', $tmp_array)) {
920 $tmp_privs2['Select'][] = $row2['Column_name'];
922 if (in_array('Insert', $tmp_array)) {
923 $tmp_privs2['Insert'][] = $row2['Column_name'];
925 if (in_array('Update', $tmp_array)) {
926 $tmp_privs2['Update'][] = $row2['Column_name'];
928 if (in_array('References', $tmp_array)) {
929 $tmp_privs2['References'][] = $row2['Column_name'];
933 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
934 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
936 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
937 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
939 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
940 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
942 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
943 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
947 'GRANT ' . join(', ', $tmp_privs1)
948 . ' ON `' . $row['Db'] . '`.`' . $row['Table_name']
949 . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
950 . (in_array('Grant', explode(',', $row['Table_priv'])) ?
' WITH GRANT OPTION;' : ';');
958 if (!empty($update_privs)) {
959 // escaping a wildcard character in a GRANT is only accepted at the global
960 // or database level, not at table level; this is why I remove
961 // the escaping character
962 // Note: in the phpMyAdmin list of Database-specific privileges,
963 // we will have for example
964 // test\_db SELECT (this one is for privileges on a db level)
965 // test_db USAGE (this one is for table-specific privileges)
967 // It looks curious but reflects the way MySQL works
969 if (! isset($dbname) ||
! strlen($dbname)) {
970 $db_and_table = '*.*';
972 if ( isset( $tablename ) && strlen($tablename) ) {
973 $db_and_table = PMA_backquote( PMA_unescape_mysql_wildcards( $dbname ) ) . '.';
974 $db_and_table .= PMA_backquote( $tablename );
976 $db_and_table = PMA_backquote( $dbname ) . '.';
977 $db_and_table .= '*';
982 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
983 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
984 if (!isset($Grant_priv) ||
$Grant_priv != 'Y') {
986 'REVOKE GRANT OPTION ON ' . $db_and_table
987 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
990 'GRANT ' . join(', ', PMA_extractPrivInfo())
991 . ' ON ' . $db_and_table
992 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
995 * @todo similar code appears twice in this script
997 if ( ( isset($Grant_priv) && $Grant_priv == 'Y')
998 ||
( ( ! isset($dbname) ||
! strlen($dbname) ) && PMA_MYSQL_INT_VERSION
>= 40002
999 && ( isset($max_questions) ||
isset($max_connections)
1000 ||
isset($max_updates) ||
isset($max_user_connections))))
1002 $sql_query2 .= 'WITH';
1003 if (isset($Grant_priv) && $Grant_priv == 'Y') {
1004 $sql_query2 .= ' GRANT OPTION';
1006 if (PMA_MYSQL_INT_VERSION
>= 40002) {
1007 if (isset($max_questions)) {
1008 $max_questions = max(0, (int)$max_questions);
1009 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
1011 if (isset($max_connections)) {
1012 $max_connections = max(0, (int)$max_connections);
1013 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
1015 if (isset($max_updates)) {
1016 $max_updates = max(0, (int)$max_updates);
1017 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
1020 if (PMA_MYSQL_INT_VERSION
>= 50003) {
1021 if (isset($max_user_connections)) {
1022 $max_user_connections = max(0, (int)$max_user_connections);
1023 $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
1028 if (!PMA_DBI_try_query($sql_query0)) { // this query may fail, but this does not matter :o)
1029 // a case when it can fail is when the admin does not have all
1030 // privileges: he can't do a REVOKE ALL PRIVILEGES !
1031 // so at least we display the error
1032 echo PMA_DBI_getError();
1035 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too...
1038 PMA_DBI_query($sql_query2);
1039 $sql_query = (isset($sql_query0) ?
$sql_query0 . ' ' : '')
1040 . (isset($sql_query1) ?
$sql_query1 . ' ' : '')
1042 $message = sprintf($GLOBALS['strUpdatePrivMessage'], '\'' . $username . '\'@\'' . $hostname . '\'');
1047 * Revokes Privileges
1049 if (!empty($revokeall)) {
1051 if ( ! isset($dbname) ||
! strlen($dbname) ) {
1052 $db_and_table = '*.*';
1054 if ( ! isset( $tablename ) ||
! strlen($tablename) ) {
1055 $db_and_table = PMA_backquote( $dbname ) . '.';
1056 $db_and_table .= '*';
1058 $db_and_table = PMA_backquote( PMA_unescape_mysql_wildcards( $dbname ) ) . '.';
1059 $db_and_table .= PMA_backquote( $tablename );
1064 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1065 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1067 'REVOKE GRANT OPTION ON ' . $db_and_table
1068 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1069 PMA_DBI_query($sql_query0);
1070 if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too...
1073 $sql_query = $sql_query0 . (isset($sql_query1) ?
' ' . $sql_query1 : '');
1074 $message = sprintf($GLOBALS['strRevokeMessage'], '\'' . $username . '\'@\'' . $hostname . '\'');
1075 if ( ! isset($tablename) ||
! strlen($tablename) ) {
1084 * Updates the password
1086 if (!empty($change_pw)) {
1088 $sql_query = 'SET PASSWORD FOR \'' . $username . '\'@\'' . $hostname . '\' = \'\';';
1089 PMA_DBI_query($sql_query);
1090 $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\'');
1091 } elseif (empty($pma_pw) ||
empty($pma_pw2)) {
1092 $message = $GLOBALS['strPasswordEmpty'];
1093 } elseif ($pma_pw != $pma_pw2) {
1094 $message = $GLOBALS['strPasswordNotSame'];
1097 for ($i = 0; $i < strlen($pma_pw); $i++
) {
1100 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')';
1101 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . $hidden_pw . '\')';
1102 PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
1103 $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\'');
1110 * (Changes / copies a user, part IV)
1112 $user_host_separator = chr(27);
1114 if (!empty($delete) ||
(!empty($change_copy) && $mode < 4)) {
1115 if (!empty($change_copy)) {
1116 $selected_usr = array($old_username . $user_host_separator . $old_hostname);
1120 for ($i = 0; isset($selected_usr[$i]); $i++
) {
1121 list($this_user, $this_host) = explode($user_host_separator, $selected_usr[$i]);
1122 $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
1123 if ( PMA_MYSQL_INT_VERSION
>= 50002 ) {
1124 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1127 // The SHOW GRANTS query may fail if the user has not been loaded
1129 $res = PMA_DBI_try_query('SHOW GRANTS FOR \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';');
1131 $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1132 while ($row = PMA_DBI_fetch_row($res)) {
1133 $this_table = substr($row[0], (strpos($row[0], 'ON') +
3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3));
1134 if ($this_table != '*.*') {
1135 $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1137 if (strpos($row[0], 'WITH GRANT OPTION')) {
1138 $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1143 PMA_DBI_free_result($res);
1147 if ( PMA_MYSQL_INT_VERSION
>= 40101 ) {
1148 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1150 $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') . ';';
1153 // If we REVOKE the table grants, we should not need to modify the
1154 // `mysql`.`db`, `mysql`.`tables_priv` and `mysql`.`columns_priv` tables manually...
1155 $user_host_condition =
1156 ' WHERE ' . PMA_convert_using('User')
1157 . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted')
1158 . ' AND ' . PMA_convert_using('Host')
1159 . ' = ' . PMA_convert_using($this_host, 'quoted') . ';';
1160 $queries[] = 'DELETE FROM `mysql`.`db`' . $user_host_condition;
1161 $queries[] = 'DELETE FROM `mysql`.`tables_priv`' . $user_host_condition;
1162 $queries[] = 'DELETE FROM `mysql`.`columns_priv`' . $user_host_condition;
1165 if (!empty($drop_users_db)) {
1166 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
1167 $GLOBALS['reload'] = TRUE;
1168 PMA_reloadNavigation();
1171 if (empty($change_copy)) {
1172 if (empty($queries)) {
1173 $show_error_header = TRUE;
1174 $message = $GLOBALS['strDeleteNoUsersSelected'];
1177 $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
1178 $queries[] = 'FLUSH PRIVILEGES;';
1180 foreach ($queries as $sql_query) {
1181 if ($sql_query{0} != '#') {
1182 PMA_DBI_query($sql_query, $GLOBALS['userlink']);
1185 $sql_query = join("\n", $queries);
1186 $message = $GLOBALS['strUsersDeleted'];
1194 * Changes / copies a user, part V
1196 if (!empty($change_copy)) {
1198 foreach ($queries as $sql_query) {
1199 if ($sql_query{0} != '#') {
1200 PMA_DBI_query($sql_query);
1202 // when there is a query containing a hidden password, take it
1203 // instead of the real query sent
1204 if (isset($queries_for_display[$tmp_count])) {
1205 $queries[$tmp_count] = $queries_for_display[$tmp_count];
1209 $message = $GLOBALS['strSuccess'];
1210 $sql_query = join("\n", $queries);
1215 * Reloads the privilege tables into memory
1217 if (!empty($flush_privileges)) {
1218 $sql_query = 'FLUSH PRIVILEGES;';
1219 PMA_DBI_query($sql_query);
1220 $message = $GLOBALS['strPrivilegesReloaded'];
1225 * Displays the links
1227 if (isset($viewing_mode) && $viewing_mode == 'db') {
1229 $url_query .= '&goto=db_operations.php';
1231 // Gets the database structure
1232 $sub_part = '_structure';
1233 require('./libraries/db_details_db_info.inc.php');
1236 require('./libraries/server_links.inc.php');
1241 * defines some standard links
1243 $link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1247 .'&tablename=%s">';
1248 if ( $GLOBALS['cfg']['PropertiesIconic'] ) {
1249 $link_edit .= '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_usredit.png" width="16" height="16" alt="' . $GLOBALS['strEditPrivileges'] . '" title="' . $GLOBALS['strEditPrivileges'] . '" />';
1251 $link_edit .= $GLOBALS['strEditPrivileges'];
1253 $link_edit .= '</a>';
1255 $link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1259 .'&tablename=%s'
1260 .'&revokeall=1">';
1261 if ( $GLOBALS['cfg']['PropertiesIconic'] ) {
1262 $link_revoke .= '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_usrdrop.png" width="16" height="16" alt="' . $GLOBALS['strRevoke'] . '" title="' . $GLOBALS['strRevoke'] . '" />';
1264 $link_revoke .= $GLOBALS['strRevoke'];
1266 $link_revoke .= '</a>';
1271 if ( empty( $adduser ) && ( ! isset( $checkprivs ) ||
! strlen($checkprivs) ) ) {
1272 if ( ! isset( $username ) ) {
1273 // No username is given --> display the overview
1275 . ($GLOBALS['cfg']['MainPageIconic'] ?
'<img class="icon" src="'. $GLOBALS['pmaThemeImage'] . 'b_usrlist.png" alt="" />' : '')
1276 . $GLOBALS['strUserOverview'] . "\n"
1282 ' IF(`Password` = ' . (PMA_MYSQL_INT_VERSION
>= 40100 ?
'_latin1 ' : '') . '\'\', \'N\', \'Y\') AS \'Password\',' .
1292 ' `References_priv`,' .
1294 ' `Shutdown_priv`,' .
1295 ' `Process_priv`,' .
1298 if (PMA_MYSQL_INT_VERSION
>= 40002) {
1299 $sql_query .= ', `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`';
1302 if (PMA_MYSQL_INT_VERSION
>= 50001) {
1303 $sql_query .= ', `Create_view_priv`, `Show_view_priv`';
1306 if (PMA_MYSQL_INT_VERSION
>= 50003) {
1307 $sql_query .= ', `Create_user_priv`, `Create_routine_priv`, `Alter_routine_priv`';
1310 $sql_query .= ' FROM `mysql`.`user`';
1312 $sql_query .= (isset($initial) ?
PMA_RangeOfUsers($initial) : '');
1314 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
1315 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE
);
1318 // the query failed! This may have two reasons:
1319 // - the user does not have enough privileges
1320 // - the privilege tables use a structure of an earlier version.
1321 // so let's try a more simple query
1323 $sql_query = 'SELECT * FROM `mysql`.`user`';
1324 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE
);
1327 echo '<i>' . $GLOBALS['strNoPrivileges'] . '</i>' . "\n";
1328 PMA_DBI_free_result($res);
1331 // rabus: This message is hardcoded because I will replace it by
1332 // a automatic repair feature soon.
1333 echo '<div class="warning">' . "\n"
1334 . ' Warning: Your privilege table structure seems to be older than this MySQL version!<br />' . "\n"
1335 . ' Please run the script <tt>mysql_fix_privilege_tables</tt> that should be included in your MySQL server distribution to solve this problem!' . "\n"
1336 . '</div><br />' . "\n";
1340 // we also want users not in table `user` but in other table
1341 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1343 $tables_to_search_for_users = array(
1344 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',
1347 $db_rights_sqls = array();
1348 foreach ( $tables_to_search_for_users as $table_search_in ) {
1349 if ( in_array( $table_search_in, $tables ) ) {
1350 $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ?
PMA_RangeOfUsers($initial) : '');
1354 $user_defaults = array(
1358 'Grant_priv' => 'N',
1359 'privs' => array( 'USAGE' ),
1362 // for all initials, even non A-Z
1363 $array_initials = array();
1365 $db_rights = array();
1367 // do not use UNION DISTINCT, as it's not allowed before
1368 // MySQL 4.0.17, and because "it does nothing" (cf manual)
1369 if ( PMA_MYSQL_INT_VERSION
>= 40000 ) {
1370 $db_rights_sql = '(' . implode( ') UNION (', $db_rights_sqls ) . ')'
1371 .' ORDER BY `User` ASC, `Host` ASC';
1373 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1375 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1376 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1377 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1381 foreach ( $db_rights_sqls as $db_rights_sql ) {
1382 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1384 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1385 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1386 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1391 PMA_DBI_free_result( $db_rights_result );
1392 unset( $db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row );
1393 ksort( $db_rights );
1396 * Displays the initials
1399 // initialize to FALSE the letters A-Z
1400 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++
) {
1401 if ( ! isset( $array_initials[chr($letter_counter +
64)] ) ) {
1402 $array_initials[chr($letter_counter +
64)] = FALSE;
1406 $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
);
1407 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1408 $array_initials[$tmp_initial] = TRUE;
1411 // Display the initials, which can be any characters, not
1412 // just letters. For letters A-Z, we add the non-used letters
1415 uksort( $array_initials, "strnatcasecmp" );
1417 echo '<table cellspacing="5"><tr>';
1418 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1419 if ($initial_was_found) {
1420 echo '<td><a href="' . $PHP_SELF . '?' . $GLOBALS['url_query'] . '&initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a></td>' . "\n";
1422 echo '<td>' . $tmp_initial . '</td>';
1425 echo '<td><a href="' . $PHP_SELF . '?' . $GLOBALS['url_query'] . '&showall=1">[' . $GLOBALS['strShowAll'] . ']</a></td>' . "\n";
1426 echo '</tr></table>';
1429 * Display the user overview
1430 * (if less than 50 users, display them immediately)
1433 if (isset($initial) ||
isset($showall) ||
PMA_DBI_num_rows($res) < 50) {
1435 while ( $row = PMA_DBI_fetch_assoc( $res ) ) {
1436 $row['privs'] = PMA_extractPrivInfo( $row, true );
1437 $db_rights[$row['User']][$row['Host']] = $row;
1439 @PMA_DBI_free_result
( $res );
1442 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1443 . PMA_generate_common_hidden_inputs('', '', 1)
1444 . ' <table id="tableuserrights" class="data">' . "\n"
1446 . ' <tr><td></td>' . "\n"
1447 . ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1448 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1449 . ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n"
1450 . ' <th>' . $GLOBALS['strGlobalPrivileges'] . ' '
1451 . PMA_showHint( $GLOBALS['strEnglishPrivileges'] ) . '</th>' . "\n"
1452 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1453 . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ?
'<td></td>' : '<th>' . $GLOBALS['strAction'] . '</th>') . "\n";
1454 echo ' </tr>' . "\n";
1455 echo ' </thead>' . "\n";
1456 echo ' <tbody>' . "\n";
1458 $index_checkbox = -1;
1459 foreach ( $db_rights as $user ) {
1462 foreach ( $user as $host ) {
1464 echo ' <tr class="' . ( $odd_row ?
'odd' : 'even' ) . '">' . "\n"
1465 . ' <td><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_' . $index_checkbox . '" value="' . str_replace( chr(27), '', htmlentities($host['User'] . $user_host_separator . $host['Host'] ) ) . '"' . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"') . ' /></td>' . "\n"
1466 . ' <td><label for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ?
'<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n"
1467 . ' <td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
1469 switch ($host['Password']) {
1471 echo $GLOBALS['strYes'];
1474 echo '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>';
1476 // this happens if this is a definition not coming from mysql.user
1478 echo '--'; // in future version, replace by "not present"
1482 . ' <td><tt>' . "\n"
1483 . ' ' . implode( ',' . "\n" . ' ', $host['privs'] ) . "\n"
1484 . ' </tt></td>' . "\n"
1485 . ' <td>' . ($host['Grant_priv'] == 'Y' ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1486 . ' <td align="center">';
1487 printf( $link_edit, urlencode( $host['User'] ),
1488 urlencode( $host['Host'] ), '', '' );
1491 $odd_row = ! $odd_row;
1495 unset( $user, $host, $odd_row );
1496 echo ' </tbody></table>' . "\n"
1497 .'<img class="selectallarrow"'
1498 .' src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
1499 .' width="38" height="22"'
1500 .' alt="' . $GLOBALS['strWithChecked'] . '" />' . "\n"
1501 .'<a href="./server_privileges.php?' . $GLOBALS['url_query'] . '&checkall=1"'
1502 .' onclick="if ( markAllRows(\'usersForm\') ) return false;">'
1503 . $GLOBALS['strCheckAll'] . '</a>' . "\n"
1505 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '"'
1506 .' onclick="if ( unMarkAllRows(\'usersForm\') ) return false;">'
1507 . $GLOBALS['strUncheckAll'] . '</a>' . "\n";
1509 // add/delete user fieldset
1510 echo ' <fieldset id="fieldset_add_user">' . "\n"
1511 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&adduser=1">' . "\n"
1512 . ($GLOBALS['cfg']['PropertiesIconic'] ?
' <img class="icon" src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" alt="" />' . "\n" : '' )
1513 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1514 . ' </fieldset>' . "\n"
1515 . ' <fieldset id="fieldset_delete_user">'
1516 . ' <legend>' . "\n"
1517 . ($GLOBALS['cfg']['PropertiesIconic'] ?
' <img class="icon" src="' . $pmaThemeImage . 'b_usrdrop.png" width="16" height="16" alt="" />' . "\n" : '' )
1518 . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n"
1519 . ' </legend>' . "\n";
1521 // before MySQL 4.1.1, we offer some choices for the delete
1522 // mode, but for 4.1.1+, it will be done with REVOKEing the
1523 // privileges then a DROP USER (even no REVOKE at all
1524 // for MySQL 5), so no need to offer so many options
1525 if (PMA_MYSQL_INT_VERSION
< 40101) {
1526 echo ' <input type="radio" title="' . $GLOBALS['strJustDelete'] . ' ' . $GLOBALS['strJustDeleteDescr'] . '" name="mode" id="radio_mode_1" value="1" checked="checked" />' . "\n"
1527 . ' <label for="radio_mode_1" title="' . $GLOBALS['strJustDelete'] . ' ' . $GLOBALS['strJustDeleteDescr'] . '">' . "\n"
1528 . ' ' . $GLOBALS['strJustDelete'] . "\n"
1529 . ' </label><br />' . "\n"
1530 . ' <input type="radio" title="' . $GLOBALS['strRevokeAndDelete'] . ' ' . $GLOBALS['strRevokeAndDeleteDescr'] . '" name="mode" id="radio_mode_2" value="2" />' . "\n"
1531 . ' <label for="radio_mode_2" title="' . $GLOBALS['strRevokeAndDelete'] . ' ' . $GLOBALS['strRevokeAndDeleteDescr'] . '">' . "\n"
1532 . ' ' . $GLOBALS['strRevokeAndDelete'] . "\n"
1533 . ' </label><br />' . "\n"
1534 . ' <input type="radio" title="' . $GLOBALS['strDeleteAndFlush'] . ' ' . $GLOBALS['strDeleteAndFlushDescr'] . '" name="mode" id="radio_mode_3" value="3" />' . "\n"
1535 . ' <label for="radio_mode_3" title="' . $GLOBALS['strDeleteAndFlush'] . ' ' . $GLOBALS['strDeleteAndFlushDescr'] . '">' . "\n"
1536 . ' ' . $GLOBALS['strDeleteAndFlush'] . "\n"
1537 . ' </label><br />' . "\n";
1539 echo ' <input type="hidden" name="mode" value="2" />' . "\n"
1540 . '( ' . $GLOBALS['strRevokeAndDelete'] . ' )<br />' . "\n";
1543 echo ' <input type="checkbox" title="' . $GLOBALS['strDropUsersDb'] . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
1544 . ' <label for="checkbox_drop_users_db" title="' . $GLOBALS['strDropUsersDb'] . '">' . "\n"
1545 . ' ' . $GLOBALS['strDropUsersDb'] . "\n"
1546 . ' </label>' . "\n"
1547 . ' </fieldset>' . "\n"
1548 . ' <fieldset id="fieldset_delete_user_footer" class="tblFooters">' . "\n"
1549 . ' <input type="submit" name="delete" value="' . $GLOBALS['strGo'] . '" id="buttonGo" />' . "\n"
1550 . ' </fieldset>' . "\n";
1554 echo ' <fieldset id="fieldset_add_user">' . "\n"
1555 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&adduser=1">' . "\n"
1556 . ($GLOBALS['cfg']['PropertiesIconic'] ?
' <img class="icon" src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" alt="" />' . "\n" : '' )
1557 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1558 . ' </fieldset>' . "\n";
1559 } // end if (display overview)
1560 echo '</form>' . "\n"
1561 . '<div class="warning">' . "\n"
1562 . ' ' . sprintf($GLOBALS['strFlushPrivilegesNote'], '<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&flush_privileges=1">', '</a>') . "\n"
1569 // A user was selected -> display the user's properties
1572 . ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $pmaThemeImage . 'b_usredit.png" width="16" height="16" alt="" />' : '' )
1573 . $GLOBALS['strUser'] . ' <i><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '">\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</a></i>' . "\n";
1574 if ( isset( $dbname ) && strlen($dbname) ) {
1575 if ( $dbname_is_wildcard ) {
1576 echo ' - ' . $GLOBALS['strDatabases'];
1578 echo ' - ' . $GLOBALS['strDatabase'];
1580 echo ' <i><a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $GLOBALS['url_query'] . '&db=' . urlencode($dbname) . '&reload=1">' . htmlspecialchars($dbname) . '</a></i>' . "\n";
1581 if ( isset( $tablename ) && strlen($tablename) ) {
1582 echo ' - ' . $GLOBALS['strTable'] . ' <i><a href="' . $GLOBALS['cfg']['DefaultTabTable'] . '?' . $GLOBALS['url_query'] . '&db=' . urlencode($dbname) . '&table=' . urlencode($tablename) . '&reload=1">' . htmlspecialchars($tablename) . '</a></i>' . "\n";
1585 echo ' : ' . $GLOBALS['strEditPrivileges'] . '</h2>' . "\n";
1586 $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
);
1587 $user_does_not_exists = (PMA_DBI_num_rows( $res ) < 1);
1588 PMA_DBI_free_result($res);
1590 if ( $user_does_not_exists ) {
1591 echo $GLOBALS['strUserNotFound'];
1592 PMA_displayLoginInformationFields();
1593 //require_once('./libraries/footer.inc.php');
1595 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1596 . PMA_generate_common_hidden_inputs('', '', 3)
1597 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1598 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
1599 if ( isset( $dbname ) && strlen($dbname) ) {
1600 echo '<input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '" />' . "\n";
1601 if ( isset( $tablename ) && strlen($tablename) ) {
1602 echo ' <input type="hidden" name="tablename" value="' . htmlspecialchars($tablename) . '" />' . "\n";
1605 PMA_displayPrivTable((( ! isset( $dbname ) ||
! strlen($dbname) ) ?
'*' : $dbname),
1606 ((( ! isset( $dbname ) ||
! strlen($dbname) ) ||
( ! isset( $tablename ) ||
! strlen($tablename) )) ?
'*' : $tablename),
1608 echo '</form>' . "\n";
1610 if ( ( ! isset( $tablename ) ||
! strlen($tablename) ) && empty( $dbname_is_wildcard ) ) {
1612 // no table name was given, display all table specific rights
1613 // but only if $dbname contains no wildcards
1616 echo '<form action="server_privileges.php" method="post">' . "\n"
1617 . PMA_generate_common_hidden_inputs('', '', 6)
1618 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1619 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1620 . '<fieldset>' . "\n"
1621 . '<legend>' . (( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '</legend>' . "\n"
1622 . '<table class="data">' . "\n"
1624 . '<tr><th>' . (( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '</th>' . "\n"
1625 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1626 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1627 . ' <th>' . (( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '</th>' . "\n"
1628 . ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>' . "\n"
1633 $user_host_condition =
1634 ' WHERE ' . PMA_convert_using('`User`')
1635 . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
1636 . ' AND ' . PMA_convert_using('`Host`')
1637 . ' = ' . PMA_convert_using($hostname, 'quoted');
1642 // we also want privielgs for this user not in table `db` but in other table
1643 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1644 if ( ( ! isset( $dbname ) ||
! strlen($dbname) ) ) {
1646 // no db name given, so we want all privs for the given user
1648 $tables_to_search_for_users = array(
1649 'tables_priv', 'columns_priv',
1652 $db_rights_sqls = array();
1653 foreach ( $tables_to_search_for_users as $table_search_in ) {
1654 if ( in_array( $table_search_in, $tables ) ) {
1655 $db_rights_sqls[] = '
1656 SELECT DISTINCT `Db`
1657 FROM `mysql`.`' . $table_search_in . '`
1658 ' . $user_host_condition;
1662 $user_defaults = array(
1664 'Grant_priv' => 'N',
1665 'privs' => array( 'USAGE' ),
1666 'Table_privs' => true,
1670 $db_rights = array();
1672 if ( PMA_MYSQL_INT_VERSION
>= 40000 ) {
1673 $db_rights_sql = '(' . implode( ') UNION (', $db_rights_sqls ) . ')'
1674 .' ORDER BY `Db` ASC';
1676 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1678 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1679 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1680 // only Db names in the table `mysql`.`db` uses wildcards
1681 // as we are in the db specific rights display we want
1682 // all db names escaped, also from other sources
1683 $db_rights_row['Db'] = PMA_escape_mysql_wildcards(
1684 $db_rights_row['Db'] );
1685 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1688 foreach ( $db_rights_sqls as $db_rights_sql ) {
1689 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1691 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1692 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1693 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1697 PMA_DBI_free_result( $db_rights_result );
1698 unset( $db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row );
1700 $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC';
1701 $res = PMA_DBI_query( $sql_query );
1702 unset( $sql_query );
1704 while ( $row = PMA_DBI_fetch_assoc( $res ) ) {
1705 if ( isset( $db_rights[$row['Db']] ) ) {
1706 $db_rights[$row['Db']] = array_merge( $db_rights[$row['Db']], $row );
1708 $db_rights[$row['Db']] = $row;
1710 // there are db specific rights for this user
1711 // so we can drop this db rights
1712 $db_rights[$row['Db']]['can_delete'] = true;
1714 PMA_DBI_free_result( $res );
1715 unset( $row, $res );
1719 // db name was given,
1720 // so we want all user specific rights for this db
1722 $user_host_condition .=
1723 ' AND ' . PMA_convert_using('`Db`')
1724 .' LIKE ' . PMA_convert_using( $dbname, 'quoted' );
1726 $tables_to_search_for_users = array(
1730 $db_rights_sqls = array();
1731 foreach ( $tables_to_search_for_users as $table_search_in ) {
1732 if ( in_array( $table_search_in, $tables ) ) {
1733 $db_rights_sqls[] = '
1734 SELECT DISTINCT `Table_name`
1735 FROM `mysql`.`' . $table_search_in . '`
1736 ' . $user_host_condition;
1740 $user_defaults = array(
1742 'Grant_priv' => 'N',
1743 'privs' => array( 'USAGE' ),
1744 'Column_priv' => true,
1748 $db_rights = array();
1750 if ( PMA_MYSQL_INT_VERSION
>= 40000 ) {
1751 $db_rights_sql = '(' . implode( ') UNION (', $db_rights_sqls ) . ')'
1752 .' ORDER BY `Table_name` ASC';
1754 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1756 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1757 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1758 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1761 foreach ( $db_rights_sqls as $db_rights_sql ) {
1762 $db_rights_result = PMA_DBI_query( $db_rights_sql );
1764 while ( $db_rights_row = PMA_DBI_fetch_assoc( $db_rights_result ) ) {
1765 $db_rights_row = array_merge( $user_defaults, $db_rights_row );
1766 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1770 PMA_DBI_free_result( $db_rights_result );
1771 unset( $db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row );
1774 'SELECT `Table_name`,'
1776 .' IF(`Column_priv` = ' . (PMA_MYSQL_INT_VERSION
>= 40100 ?
'_latin1 ' : '') . ' \'\', 0, 1)'
1777 .' AS \'Column_priv\''
1778 .' FROM `mysql`.`tables_priv`'
1779 . $user_host_condition
1780 .' ORDER BY `Table_name` ASC;';
1781 $res = PMA_DBI_query( $sql_query );
1782 unset( $sql_query );
1784 while ( $row = PMA_DBI_fetch_assoc( $res ) ) {
1785 if ( isset( $db_rights[$row['Table_name']] ) ) {
1786 $db_rights[$row['Table_name']] = array_merge( $db_rights[$row['Table_name']], $row );
1788 $db_rights[$row['Table_name']] = $row;
1791 PMA_DBI_free_result( $res );
1792 unset( $row, $res );
1794 ksort( $db_rights );
1797 if ( count( $db_rights ) < 1 ) {
1798 echo '<tr class="odd">' . "\n"
1799 . ' <td colspan="6"><center><i>' . $GLOBALS['strNone'] . '</i></center></td>' . "\n"
1803 $found_rows = array();
1804 //while ( $row = PMA_DBI_fetch_assoc( $res ) ) {
1805 foreach ( $db_rights as $row ) {
1806 $found_rows[] = ( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$row['Db'] : $row['Table_name'];
1808 echo '<tr class="' . ( $odd_row ?
'odd' : 'even' ) . '">' . "\n"
1809 . ' <td>' . htmlspecialchars(( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$row['Db'] : $row['Table_name']) . '</td>' . "\n"
1810 . ' <td><tt>' . "\n"
1811 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1812 . ' </tt></td>' . "\n"
1813 . ' <td>' . (((( ! isset( $dbname ) ||
! strlen($dbname) ) && $row['Grant_priv'] == 'Y') ||
(isset($dbname) && strlen($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1815 if ( ! empty( $row['Table_privs'] ) ||
! empty ( $row['Column_priv'] ) ) {
1816 echo $GLOBALS['strYes'];
1818 echo $GLOBALS['strNo'];
1822 printf( $link_edit, urlencode( $username ),
1823 urlencode( $hostname ),
1824 urlencode( ( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$row['Db'] : $dbname ),
1825 urlencode( ( ! isset( $dbname ) ||
! strlen($dbname) ) ?
'' : $row['Table_name'] ) );
1828 if ( ! empty( $row['can_delete'] ) ||
isset( $row['Table_name'] ) && strlen($row['Table_name']) ) {
1829 printf( $link_revoke, urlencode( $username ),
1830 urlencode( $hostname ),
1831 urlencode( ( ! isset( $dbname ) ||
! strlen($dbname) ) ?
$row['Db'] : $dbname ),
1832 urlencode( ( ! isset( $dbname ) ||
! strlen($dbname) ) ?
'' : $row['Table_name'] ) );
1836 $odd_row = ! $odd_row;
1840 echo '</tbody>' . "\n"
1841 . '</table>' . "\n";
1843 if ( ! isset( $dbname ) ||
! strlen($dbname) ) {
1845 // no database name was give, display select db
1847 if ( ! empty( $found_rows ) ) {
1848 $pred_db_array = array_diff(
1849 PMA_DBI_fetch_result( 'SHOW DATABASES;' ),
1852 $pred_db_array =PMA_DBI_fetch_result( 'SHOW DATABASES;' );
1855 echo ' <label for="text_dbname">' . $GLOBALS['strAddPrivilegesOnDb'] . ':</label>' . "\n";
1856 if (!empty($pred_db_array)) {
1857 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1858 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1859 foreach ($pred_db_array as $current_db) {
1860 $current_db = PMA_escape_mysql_wildcards( $current_db );
1861 echo ' <option value="' . htmlspecialchars( $current_db ) . '">'
1862 . htmlspecialchars( $current_db ) . '</option>' . "\n";
1864 echo ' </select>' . "\n";
1866 echo ' <input type="text" id="text_dbname" name="dbname" />' . "\n"
1867 .PMA_showHint( $GLOBALS['strEscapeWildcards'] );
1869 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1870 . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n";
1871 if ($res = @PMA_DBI_try_query
('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE
)) {
1872 $pred_tbl_array = array();
1873 while ($row = PMA_DBI_fetch_row($res)) {
1874 if (!isset($found_rows) ||
!in_array($row[0], $found_rows)) {
1875 $pred_tbl_array[] = $row[0];
1878 PMA_DBI_free_result($res);
1879 unset( $res, $row );
1880 if (!empty($pred_tbl_array)) {
1881 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1882 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1883 foreach ($pred_tbl_array as $current_table) {
1884 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1886 echo ' </select>' . "\n";
1891 echo ' <input type="text" id="text_tablename" name="tablename" />' . "\n";
1893 echo '</fieldset>' . "\n";
1894 echo '<fieldset class="tblFooters">' . "\n"
1895 . ' <input type="submit" value="' . $GLOBALS['strGo'] . '" />'
1896 . '</fieldset>' . "\n"
1900 if ( ( ! isset( $dbname ) ||
! strlen($dbname) ) && ! $user_does_not_exists ) {
1901 echo '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1902 . PMA_generate_common_hidden_inputs('', '', 3)
1903 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1904 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1905 . '<fieldset id="fieldset_change_password">' . "\n"
1906 . ' <legend>' . $GLOBALS['strChangePassword'] . '</legend>' . "\n"
1907 . ' <table class="data">' . "\n"
1908 . ' <tr class="odd noclick">' . "\n"
1909 . ' <td><input type="radio" name="nopass" value="1" id="radio_nopass_1" onclick="pw_pma_pw.value=\'\'; pw_pma_pw2.value=\'\';" /></td>' . "\n"
1910 . ' <td colspan="2"><label for="radio_nopass_1">' . $GLOBALS['strNoPassword'] . '</label></td>' . "\n"
1912 . ' <tr class="even noclick">' . "\n"
1913 . ' <td><input type="radio" name="nopass" value="0" id="radio_nopass_0" onclick="document.getElementById(\'pw_pma_pw\').focus();" /></td>' . "\n"
1914 . ' <td><label for="radio_nopass_0">' . $GLOBALS['strPassword'] . ':</label></td>' . "\n"
1915 . ' <td><input type="password" name="pma_pw" id="pw_pma_pw" onchange="nopass[1].checked = true;" /></td>' . "\n"
1917 . ' <tr class="odd noclick">' . "\n"
1918 . ' <td></td>' . "\n"
1919 . ' <td><label for="pw_pma_pw2">' . $GLOBALS['strReType'] . ':</label></td>' . "\n"
1920 . ' <td><input type="password" name="pma_pw2" id="pw_pma_pw2" onchange="nopass[1].checked = true;" /></td>' . "\n"
1922 . ' </table>' . "\n"
1923 . '</fieldset>' . "\n"
1924 . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . "\n"
1925 . ' <input type="submit" name="change_pw" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1926 . '</fieldset>' . "\n"
1928 . '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1929 . PMA_generate_common_hidden_inputs('', '', 3)
1930 . '<input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1931 . '<input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1932 . '<fieldset id="fieldset_change_copy_user">' . "\n"
1933 . ' <legend>' . $GLOBALS['strChangeCopyUser'] . '</legend>' . "\n";
1934 PMA_displayLoginInformationFields('change', 3 );
1935 echo ' <fieldset>' . "\n"
1936 . ' <legend>' . $GLOBALS['strChangeCopyMode'] . '</legend>' . "\n"
1937 . ' <input type="radio" name="mode" value="4" id="radio_mode_4" checked="checked" /><label for="radio_mode_4">' . "\n"
1938 . ' ' . $GLOBALS['strChangeCopyModeCopy'] . "\n"
1939 . ' </label><br />' . "\n"
1940 . ' <input type="radio" name="mode" value="1" id="radio_mode_1" /><label for="radio_mode_1">' . "\n"
1941 . ' ' . $GLOBALS['strChangeCopyModeJustDelete'] . "\n"
1942 . ' </label><br />' . "\n"
1943 . ' <input type="radio" name="mode" value="2" id="radio_mode_2" /><label for="radio_mode_2">' . "\n"
1944 . ' ' . $GLOBALS['strChangeCopyModeRevoke'] . "\n"
1945 . ' </label><br />' . "\n"
1946 . ' <input type="radio" name="mode" value="3" id="radio_mode_3" /><label for="radio_mode_3">' . "\n"
1947 . ' ' . $GLOBALS['strChangeCopyModeDeleteAndReload'] . "\n"
1948 . ' </label>' . "\n"
1949 . ' </fieldset>' . "\n"
1950 . '</fieldset>' . "\n"
1951 . '<fieldset id="fieldset_change_copy_user_footer" class="tblFooters">' . "\n"
1952 . ' <input type="submit" name="change_copy" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1953 . '</fieldset>' . "\n"
1957 } elseif (!empty($adduser)) {
1959 $GLOBALS['url_query'] .= '&adduser=1';
1961 . ($GLOBALS['cfg']['PropertiesIconic'] ?
'<img class="icon" src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" alt="" />' : '' )
1962 . ' ' . $GLOBALS['strAddUser'] . "\n"
1964 . '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1965 . PMA_generate_common_hidden_inputs('', '', 1);
1966 PMA_displayLoginInformationFields('new', 2);
1967 echo '<fieldset id="fieldset_add_user_database">' . "\n"
1968 . '<legend>' . $GLOBALS['strCreateUserDatabase'] . '</legend>' . "\n"
1969 . ' <div class="item">' . "\n"
1970 . ' <input type="radio" name="createdb" value="0" id="radio_createdb_0" checked="checked" />' . "\n"
1971 . ' <label for="radio_createdb_0">' . $GLOBALS['strCreateUserDatabaseNone'] . '</label>' . "\n"
1973 . ' <div class="item">' . "\n"
1974 . ' <input type="radio" name="createdb" value="1" id="radio_createdb_1" />' . "\n"
1975 . ' <label for="radio_createdb_1">' . $GLOBALS['strCreateUserDatabaseName'] . '</label>' . "\n"
1977 . ' <div class="item">' . "\n"
1978 . ' <input type="radio" name="createdb" value="2" id="radio_createdb_2" />' . "\n"
1979 . ' <label for="radio_createdb_2">' . $GLOBALS['strCreateUserDatabaseWildcard'] . '</label>' . "\n"
1981 . '</fieldset>' . "\n";
1982 PMA_displayPrivTable('*', '*', FALSE, 1);
1983 echo ' <fieldset id="fieldset_add_user_footer" class="tblFooters">' . "\n"
1984 . ' <input type="submit" name="adduser_submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1985 . ' </fieldset>' . "\n"
1988 // check the privileges for a particular database.
1989 echo '<table id="tablespecificuserrights" class="data">' . "\n"
1990 . '<caption class="tblHeaders">' . "\n"
1991 . ($GLOBALS['cfg']['PropertiesIconic'] ?
' <img class="icon" src="' . $pmaThemeImage . 'b_usrcheck.png" width="16" height="16" alt="" />' . "\n" : '' )
1992 . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
1993 . '</caption>' . "\n"
1995 . ' <tr><th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1996 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1997 . ' <th>' . $GLOBALS['strType'] . '</th>' . "\n"
1998 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1999 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
2000 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n"
2008 // now, we build the table...
2009 if (PMA_MYSQL_INT_VERSION
>= 40000) {
2010 // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes
2011 // the job much easier here!
2013 $no = PMA_convert_using('N', 'quoted');
2015 $list_of_privileges =
2016 PMA_convert_using('Select_priv') . ' AS Select_priv, '
2017 . PMA_convert_using('Insert_priv') . ' AS Insert_priv, '
2018 . PMA_convert_using('Update_priv') . ' AS Update_priv, '
2019 . PMA_convert_using('Delete_priv') . ' AS Delete_priv, '
2020 . PMA_convert_using('Create_priv') . ' AS Create_priv, '
2021 . PMA_convert_using('Drop_priv') . ' AS Drop_priv, '
2022 . PMA_convert_using('Grant_priv') . ' AS Grant_priv, '
2023 . PMA_convert_using('References_priv') . ' AS References_priv';
2025 $list_of_compared_privileges =
2026 PMA_convert_using('Select_priv') . ' = ' . $no
2027 . ' AND ' . PMA_convert_using('Insert_priv') . ' = ' . $no
2028 . ' AND ' . PMA_convert_using('Update_priv') . ' = ' . $no
2029 . ' AND ' . PMA_convert_using('Delete_priv') . ' = ' . $no
2030 . ' AND ' . PMA_convert_using('Create_priv') . ' = ' . $no
2031 . ' AND ' . PMA_convert_using('Drop_priv') . ' = ' . $no
2032 . ' AND ' . PMA_convert_using('Grant_priv') . ' = ' . $no
2033 . ' AND ' . PMA_convert_using('References_priv') . ' = ' . $no;
2036 '(SELECT ' . PMA_convert_using('`User`') . ' AS `User`, '
2037 . PMA_convert_using('`Host`') . ' AS `Host`, '
2038 . PMA_convert_using('`Db`') . ' AS `Db`, '
2039 . $list_of_privileges
2040 .' FROM `mysql`.`db`'
2041 .' WHERE ' . PMA_convert_using( $checkprivs, 'quoted' )
2042 .' LIKE ' . PMA_convert_using('`Db`')
2043 .' AND NOT (' . $list_of_compared_privileges. ')) '
2045 .'(SELECT ' . PMA_convert_using('`User`') . ' AS `User`, '
2046 . PMA_convert_using('`Host`') . ' AS `Host`, '
2047 . PMA_convert_using('*', 'quoted') .' AS `Db`, '
2048 . $list_of_privileges
2049 .' FROM `mysql`.`user` '
2050 .' WHERE NOT (' . $list_of_compared_privileges . ')) '
2051 .' ORDER BY `User` ASC,'
2054 $res = PMA_DBI_query($sql_query);
2055 $row = PMA_DBI_fetch_assoc($res);
2060 // With MySQL 3, we need 2 seperate queries here.
2061 $sql_query = 'SELECT * FROM `mysql`.`user` WHERE NOT (`Select_priv` = \'N\' AND `Insert_priv` = \'N\' AND `Update_priv` = \'N\' AND `Delete_priv` = \'N\' AND `Create_priv` = \'N\' AND `Drop_priv` = \'N\' AND `Grant_priv` = \'N\' AND `References_priv` = \'N\') ORDER BY `User` ASC, `Host` ASC;';
2062 $res1 = PMA_DBI_query($sql_query);
2063 $row1 = PMA_DBI_fetch_assoc($res1);
2065 'SELECT * FROM `mysql`.`db`'
2066 .' WHERE \'' . $checkprivs . '\''
2068 .' AND NOT (`Select_priv` = \'N\''
2069 .' AND `Insert_priv` = \'N\''
2070 .' AND `Update_priv` = \'N\''
2071 .' AND `Delete_priv` = \'N\''
2072 .' AND `Create_priv` = \'N\''
2073 .' AND `Drop_priv` = \'N\''
2074 .' AND `Grant_priv` = \'N\''
2075 .' AND `References_priv` = \'N\')'
2076 .' ORDER BY `User` ASC, `Host` ASC;';
2077 $res2 = PMA_DBI_query($sql_query);
2078 $row2 = PMA_DBI_fetch_assoc($res2);
2079 if ($row1 ||
$row2) {
2082 } // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ...
2085 // prepare the current user
2086 if (PMA_MYSQL_INT_VERSION
>= 40000) {
2087 $current_privileges = array();
2088 $current_user = $row['User'];
2089 $current_host = $row['Host'];
2090 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
2091 $current_privileges[] = $row;
2092 $row = PMA_DBI_fetch_assoc($res);
2095 $current_privileges = array();
2096 if ($row1 && (!$row2 ||
($row1['User'] < $row2['User'] ||
($row1['User'] == $row2['User'] && $row1['Host'] <= $row2['Host'])))) {
2097 $current_user = $row1['User'];
2098 $current_host = $row1['Host'];
2099 $current_privileges = array($row1);
2100 $row1 = PMA_DBI_fetch_assoc($res1);
2102 $current_user = $row2['User'];
2103 $current_host = $row2['Host'];
2104 $current_privileges = array();
2106 while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) {
2107 $current_privileges[] = $row2;
2108 $row2 = PMA_DBI_fetch_assoc($res2);
2111 echo ' <tr class="' . ( $odd_row ?
'odd' : 'even' ) . '">' . "\n"
2113 if (count($current_privileges) > 1) {
2114 echo ' rowspan="' . count($current_privileges) . '"';
2116 echo '>' . (empty($current_user) ?
'<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($current_user)) . "\n"
2119 if (count($current_privileges) > 1) {
2120 echo ' rowspan="' . count($current_privileges) . '"';
2122 echo '>' . htmlspecialchars($current_host) . '</td>' . "\n";
2123 foreach ($current_privileges as $current) {
2126 if (!isset($current['Db']) ||
$current['Db'] == '*') {
2127 echo $GLOBALS['strGlobal'];
2128 } elseif ( $current['Db'] == PMA_escape_mysql_wildcards( $checkprivs ) ) {
2129 echo $GLOBALS['strDbSpecific'];
2131 echo $GLOBALS['strWildcard'], ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
2137 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
2141 . ' ' . ($current['Grant_priv'] == 'Y' ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n"
2144 printf( $link_edit, urlencode( $current_user ),
2145 urlencode( $current_host ),
2146 urlencode( ! isset( $current['Db'] ) ||
$current['Db'] == '*' ?
'' : $current['Db'] ),
2151 if (empty($row) && empty($row1) && empty($row2)) {
2154 $odd_row = ! $odd_row;
2157 echo ' <tr class="odd">' . "\n"
2158 . ' <td colspan="6">' . "\n"
2159 . ' ' . $GLOBALS['strNoUsersFound'] . "\n"
2163 echo '</tbody>' . "\n"
2164 . '</table>' . "\n";
2165 } // end if (empty($adduser) && empty($checkprivs)) ... elseif ... else ...
2169 * Displays the footer
2172 require_once('./libraries/footer.inc.php');