there was an extra space in the ChangeLog
[phpmyadmin/crack.git] / server_privileges.php
blob0470ffe1b889578078920ac40fb61f62f56f6a00
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 /**
15 * Does the common work
17 $GLOBALS['js_include'][] = 'server_privileges.js';
18 $GLOBALS['js_include'][] = 'functions.js';
19 require './libraries/server_common.inc.php';
22 /**
23 * Checks if a dropdown box has been used for selecting a database / table
25 if (PMA_isValid($_REQUEST['pred_tablename'])) {
26 $tablename = $_REQUEST['pred_tablename'];
27 unset($pred_tablename);
28 } elseif (PMA_isValid($_REQUEST['tablename'])) {
29 $tablename = $_REQUEST['tablename'];
30 } else {
31 unset($tablename);
34 if (PMA_isValid($_REQUEST['pred_dbname'])) {
35 $dbname = $_REQUEST['pred_dbname'];
36 unset($pred_dbname);
37 } elseif (PMA_isValid($_REQUEST['dbname'])) {
38 $dbname = $_REQUEST['dbname'];
39 } else {
40 unset($dbname);
41 unset($tablename);
44 if (isset($dbname)) {
45 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
46 if (isset($tablename)) {
47 $db_and_table .= PMA_backquote($tablename);
48 } else {
49 $db_and_table .= '*';
51 } else {
52 $db_and_table = '*.*';
55 // check if given $dbname is a wildcard or not
56 if (isset($dbname)) {
57 //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
58 if (preg_match('/(?<!\\\\)(?:_|%)/i', $dbname)) {
59 $dbname_is_wildcard = true;
60 } else {
61 $dbname_is_wildcard = false;
65 /**
66 * Checks if the user is allowed to do what he tries to...
68 if (!$is_superuser) {
69 require './libraries/server_links.inc.php';
70 echo '<h2>' . "\n"
71 . PMA_getIcon('b_usrlist.png')
72 . $GLOBALS['strPrivileges'] . "\n"
73 . '</h2>' . "\n";
74 PMA_Message::error('strNoPrivileges')->display();
75 require_once './libraries/footer.inc.php';
78 /**
79 * Escapes wildcard in a database+table specification
80 * before using it in a GRANT statement.
82 * Escaping a wildcard character in a GRANT is only accepted at the global
83 * or database level, not at table level; this is why I remove
84 * the escaping character. Internally, in mysql.tables_priv.Db there are
85 * no escaping (for example test_db) but in mysql.db you'll see test\_db
86 * for a db-specific privilege.
88 * @param string $db_and_table
89 * @param string $dbname
90 * @param string $tablename
91 * @return string the escaped (if necessary) $db_and_table
93 function PMA_WildcardEscapeForGrant($db_and_table, $dbname, $tablename) {
95 if (! strlen($dbname)) {
96 $db_and_table = '*.*';
97 } else {
98 if (strlen($tablename)) {
99 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
100 $db_and_table .= PMA_backquote($tablename);
101 } else {
102 $db_and_table = PMA_backquote($dbname) . '.';
103 $db_and_table .= '*';
106 return $db_and_table;
110 * Generates a condition on the user name
112 * @param string the user's initial
113 * @return string the generated condition
115 function PMA_RangeOfUsers($initial = '')
117 // strtolower() is used because the User field
118 // might be BINARY, so LIKE would be case sensitive
119 if (!empty($initial)) {
120 $ret = " WHERE `User` LIKE '" . $initial . "%'"
121 . " OR `User` LIKE '" . strtolower($initial) . "%'";
122 } else {
123 $ret = '';
125 return $ret;
126 } // end function
129 * Extracts the privilege information of a priv table row
131 * @param array $row the row
132 * @param boolean $enableHTML add <dfn> tag with tooltips
134 * @global ressource $user_link the database connection
136 * @return array
138 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
140 $grants = array(
141 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
142 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
143 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
144 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
145 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
146 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
147 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
148 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
149 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess']),
150 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
151 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
152 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
153 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
154 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
155 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
156 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
157 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
158 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
159 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),
160 array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
161 array('Event_priv', 'EVENT', $GLOBALS['strPrivDescEvent']),
162 array('Trigger_priv', 'TRIGGER', $GLOBALS['strPrivDescTrigger']),
163 // for table privs:
164 array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
165 array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
166 // for table privs:
167 array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
168 array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
169 array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
170 array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']),
171 array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
174 if (!empty($row) && isset($row['Table_priv'])) {
175 $row1 = PMA_DBI_fetch_single_row(
176 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
177 'ASSOC', $GLOBALS['userlink']);
178 $av_grants = explode('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7));
179 unset($row1);
180 $users_grants = explode(',', $row['Table_priv']);
181 foreach ($av_grants as $current_grant) {
182 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
184 unset($current_grant);
185 unset($av_grants);
186 unset($users_grants);
188 $privs = array();
189 $allPrivileges = TRUE;
190 foreach ($grants as $current_grant) {
191 if ((!empty($row) && isset($row[$current_grant[0]]))
192 || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
193 if ((!empty($row) && $row[$current_grant[0]] == 'Y')
194 || (empty($row)
195 && ($GLOBALS[$current_grant[0]] == 'Y'
196 || (is_array($GLOBALS[$current_grant[0]])
197 && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count']
198 && empty($GLOBALS[$current_grant[0] . '_none'])))))
200 if ($enableHTML) {
201 $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
202 } else {
203 $privs[] = $current_grant[1];
205 } elseif (!empty($GLOBALS[$current_grant[0]])
206 && is_array($GLOBALS[$current_grant[0]])
207 && empty($GLOBALS[$current_grant[0] . '_none'])) {
208 if ($enableHTML) {
209 $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
210 } else {
211 $priv_string = $current_grant[1];
213 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
214 } else {
215 $allPrivileges = FALSE;
219 if (empty($privs)) {
220 if ($enableHTML) {
221 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
222 } else {
223 $privs[] = 'USAGE';
225 } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
226 if ($enableHTML) {
227 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
228 } else {
229 $privs = array('ALL PRIVILEGES');
232 return $privs;
233 } // end of the 'PMA_extractPrivInfo()' function
236 * Displays on which column(s) a table-specific privilege is granted
238 function PMA_display_column_privs($columns, $row, $name_for_select,
239 $priv_for_header, $name, $name_for_dfn, $name_for_current)
241 echo ' <div class="item" id="div_item_' . $name . '">' . "\n"
242 . ' <label for="select_' . $name . '_priv">' . "\n"
243 . ' <tt><dfn title="' . $name_for_dfn . '">'
244 . $priv_for_header . '</dfn></tt>' . "\n"
245 . ' </label><br />' . "\n"
246 . ' <select id="select_' . $name . '_priv" name="'
247 . $name_for_select . '[]" multiple="multiple" size="8">' . "\n";
249 foreach ($columns as $current_column => $current_column_privileges) {
250 echo ' <option value="' . htmlspecialchars($current_column) . '"';
251 if ($row[$name_for_select] == 'Y' || $current_column_privileges[$name_for_current]) {
252 echo ' selected="selected"';
254 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
257 echo ' </select>' . "\n"
258 . ' <i>' . $GLOBALS['strOr'] . '</i>' . "\n"
259 . ' <label for="checkbox_' . $name_for_select
260 . '_none"><input type="checkbox"'
261 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
262 . ' name="' . $name_for_select . '_none" id="checkbox_'
263 . $name_for_select . '_none" title="' . $GLOBALS['strNone'] . '" />'
264 . $GLOBALS['strNone'] . '</label>' . "\n"
265 . ' </div>' . "\n";
266 } // end function
270 * Displays the privileges form table
272 * @param string $db the database
273 * @param string $table the table
274 * @param boolean $submit wheather to display the submit button or not
275 * @global array $cfg the phpMyAdmin configuration
276 * @global ressource $user_link the database connection
278 * @return void
280 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE)
282 if ($db == '*') {
283 $table = '*';
286 if (isset($GLOBALS['username'])) {
287 $username = $GLOBALS['username'];
288 $hostname = $GLOBALS['hostname'];
289 if ($db == '*') {
290 $sql_query =
291 "SELECT * FROM `mysql`.`user`"
292 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
293 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
294 } elseif ($table == '*') {
295 $sql_query =
296 "SELECT * FROM `mysql`.`db`"
297 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
298 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
299 ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"
300 ." LIKE `Db`;";
301 } else {
302 $sql_query =
303 "SELECT `Table_priv`"
304 ." FROM `mysql`.`tables_priv`"
305 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
306 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
307 ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'"
308 ." AND `Table_name` = '" . PMA_sqlAddslashes($table) . "';";
310 $row = PMA_DBI_fetch_single_row($sql_query);
312 if (empty($row)) {
313 if ($table == '*') {
314 if ($db == '*') {
315 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
316 } elseif ($table == '*') {
317 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
319 $res = PMA_DBI_query($sql_query);
320 while ($row1 = PMA_DBI_fetch_row($res)) {
321 if (substr($row1[0], 0, 4) == 'max_') {
322 $row[$row1[0]] = 0;
323 } else {
324 $row[$row1[0]] = 'N';
327 PMA_DBI_free_result($res);
328 } else {
329 $row = array('Table_priv' => '');
332 if (isset($row['Table_priv'])) {
333 $row1 = PMA_DBI_fetch_single_row(
334 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
335 'ASSOC', $GLOBALS['userlink']);
336 // note: in MySQL 5.0.3 we get "Create View', 'Show view';
337 // the View for Create is spelled with uppercase V
338 // the view for Show is spelled with lowercase v
339 // and there is a space between the words
341 $av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
342 unset($row1);
343 $users_grants = explode(',', $row['Table_priv']);
345 foreach ($av_grants as $current_grant) {
346 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
348 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
350 // get collumns
351 $res = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote(PMA_unescape_mysql_wildcards($db)) . '.' . PMA_backquote($table) . ';');
352 $columns = array();
353 if ($res) {
354 while ($row1 = PMA_DBI_fetch_row($res)) {
355 $columns[$row1[0]] = array(
356 'Select' => FALSE,
357 'Insert' => FALSE,
358 'Update' => FALSE,
359 'References' => FALSE
362 PMA_DBI_free_result($res);
364 unset($res, $row1);
366 // t a b l e - s p e c i f i c p r i v i l e g e s
367 if (! empty($columns)) {
368 $res = PMA_DBI_query(
369 'SELECT `Column_name`, `Column_priv`'
370 .' FROM `mysql`.`columns_priv`'
371 .' WHERE `User`'
372 .' = \'' . PMA_sqlAddslashes($username) . "'"
373 .' AND `Host`'
374 .' = \'' . PMA_sqlAddslashes($hostname) . "'"
375 .' AND `Db`'
376 .' = \'' . PMA_sqlAddslashes(PMA_unescape_mysql_wildcards($db)) . "'"
377 .' AND `Table_name`'
378 .' = \'' . PMA_sqlAddslashes($table) . '\';');
380 while ($row1 = PMA_DBI_fetch_row($res)) {
381 $row1[1] = explode(',', $row1[1]);
382 foreach ($row1[1] as $current) {
383 $columns[$row1[0]][$current] = TRUE;
386 PMA_DBI_free_result($res);
387 unset($res, $row1, $current);
389 echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
390 . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
391 . '<fieldset id="fieldset_user_priv">' . "\n"
392 . ' <legend>' . $GLOBALS['strTblPrivileges']
393 . PMA_showHint($GLOBALS['strEnglishPrivileges'])
394 . '</legend>' . "\n";
398 // privs that are attached to a specific column
399 PMA_display_column_privs($columns, $row, 'Select_priv',
400 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select');
402 PMA_display_column_privs($columns, $row, 'Insert_priv',
403 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert');
405 PMA_display_column_privs($columns, $row, 'Update_priv',
406 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update');
408 PMA_display_column_privs($columns, $row, 'References_priv',
409 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References');
411 // privs that are not attached to a specific column
413 echo ' <div class="item">' . "\n";
414 foreach ($row as $current_grant => $current_grant_value) {
415 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)),
416 array('Select', 'Insert', 'Update', 'References'))) {
417 continue;
419 // make a substitution to match the messages variables;
420 // also we must substitute the grant we get, because we can't generate
421 // a form variable containing blanks (those would get changed to
422 // an underscore when receiving the POST)
423 if ($current_grant == 'Create View_priv') {
424 $tmp_current_grant = 'CreateView_priv';
425 $current_grant = 'Create_view_priv';
426 } elseif ($current_grant == 'Show view_priv') {
427 $tmp_current_grant = 'ShowView_priv';
428 $current_grant = 'Show_view_priv';
429 } else {
430 $tmp_current_grant = $current_grant;
433 echo ' <div class="item">' . "\n"
434 . ' <input type="checkbox"'
435 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
436 . ' name="' . $current_grant . '" id="checkbox_' . $current_grant
437 . '" value="Y" '
438 . ($current_grant_value == 'Y' ? 'checked="checked" ' : '')
439 . 'title="';
441 echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
442 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
443 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";
445 echo ' <label for="checkbox_' . $current_grant
446 . '"><tt><dfn title="'
447 . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
448 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
449 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl'])
450 . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n"
451 . ' </div>' . "\n";
452 } // end foreach ()
454 echo ' </div>' . "\n";
455 // for Safari 2.0.2
456 echo ' <div class="clearfloat"></div>' . "\n";
458 } else {
460 // g l o b a l o r d b - s p e c i f i c
462 // d a t a
463 $privTable[0] = array(
464 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
465 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
466 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
467 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
469 if ($db == '*') {
470 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
473 // s t r u c t u r e
474 $privTable[1] = array(
475 array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
476 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
477 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
478 array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl'])),
479 array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
480 array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
481 array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
482 array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
483 array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
485 // this one is for a db-specific priv: Create_view_priv
486 if (isset($row['Create_view_priv'])) {
487 $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
489 // this one is for a table-specific priv: Create View_priv
490 if (isset($row['Create View_priv'])) {
491 $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
493 if (isset($row['Event_priv'])) {
494 // MySQL 5.1.6
495 $privTable[1][] = array('Event', 'EVENT', $GLOBALS['strPrivDescEvent']);
496 $privTable[1][] = array('Trigger', 'TRIGGER', $GLOBALS['strPrivDescTrigger']);
499 // a d m i n i s t r a t i o n
500 $privTable[2] = array(
501 array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']),
503 if ($db == '*') {
504 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
505 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess']);
506 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
507 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
508 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
510 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
511 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
512 if ($db == '*') {
513 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
514 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
515 $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']);
517 echo '<input type="hidden" name="grant_count" value="'
518 . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0))
519 . '" />' . "\n"
520 . '<fieldset id="fieldset_user_global_rights">' . "\n"
521 . ' <legend>' . "\n"
522 . ' '
523 . ($db == '*'
524 ? $GLOBALS['strGlobalPrivileges']
525 : ($table == '*'
526 ? $GLOBALS['strDbPrivileges']
527 : $GLOBALS['strTblPrivileges'])) . "\n"
528 . ' (<a href="server_privileges.php?'
529 . $GLOBALS['url_query'] . '&amp;checkall=1" onclick="setCheckboxes(\'usersForm\', true); return false;">'
530 . $GLOBALS['strCheckAll'] . '</a> /' . "\n"
531 . ' <a href="server_privileges.php?'
532 . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'usersForm\', false); return false;">'
533 . $GLOBALS['strUncheckAll'] . '</a>)' . "\n"
534 . ' </legend>' . "\n"
535 . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n"
536 . ' <fieldset>' . "\n"
537 . ' <legend>' . $GLOBALS['strData'] . '</legend>' . "\n";
538 foreach ($privTable[0] as $priv)
540 echo ' <div class="item">' . "\n"
541 . ' <input type="checkbox"'
542 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
543 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
544 . '_priv" value="Y" '
545 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
546 . 'title="' . $priv[2] . '"/>' . "\n"
547 . ' <label for="checkbox_' . $priv[0]
548 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
549 . '</dfn></tt></label>' . "\n"
550 . ' </div>' . "\n";
552 echo ' </fieldset>' . "\n"
553 . ' <fieldset>' . "\n"
554 . ' <legend>' . $GLOBALS['strStructure'] . '</legend>' . "\n";
555 foreach ($privTable[1] as $priv)
557 echo ' <div class="item">' . "\n"
558 . ' <input type="checkbox"'
559 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
560 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
561 . '_priv" value="Y" '
562 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
563 . 'title="' . $priv[2] . '"/>' . "\n"
564 . ' <label for="checkbox_' . $priv[0]
565 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
566 . '</dfn></tt></label>' . "\n"
567 . ' </div>' . "\n";
569 echo ' </fieldset>' . "\n"
570 . ' <fieldset>' . "\n"
571 . ' <legend>' . $GLOBALS['strAdministration'] . '</legend>' . "\n";
572 foreach ($privTable[2] as $priv)
574 echo ' <div class="item">' . "\n"
575 . ' <input type="checkbox"'
576 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
577 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
578 . '_priv" value="Y" '
579 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
580 . 'title="' . $priv[2] . '"/>' . "\n"
581 . ' <label for="checkbox_' . $priv[0]
582 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
583 . '</dfn></tt></label>' . "\n"
584 . ' </div>' . "\n";
587 echo ' </fieldset>' . "\n";
588 // The "Resource limits" box is not displayed for db-specific privs
589 if ($db == '*') {
590 echo ' <fieldset>' . "\n"
591 . ' <legend>' . $GLOBALS['strResourceLimits'] . '</legend>' . "\n"
592 . ' <p><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></p>' . "\n"
593 . ' <div class="item">' . "\n"
594 . ' <label for="text_max_questions"><tt><dfn title="'
595 . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label>' . "\n"
596 . ' <input type="text" name="max_questions" id="text_max_questions" value="'
597 . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" />' . "\n"
598 . ' </div>' . "\n"
599 . ' <div class="item">' . "\n"
600 . ' <label for="text_max_updates"><tt><dfn title="'
601 . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label>' . "\n"
602 . ' <input type="text" name="max_updates" id="text_max_updates" value="'
603 . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" />' . "\n"
604 . ' </div>' . "\n"
605 . ' <div class="item">' . "\n"
606 . ' <label for="text_max_connections"><tt><dfn title="'
607 . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label>' . "\n"
608 . ' <input type="text" name="max_connections" id="text_max_connections" value="'
609 . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" />' . "\n"
610 . ' </div>' . "\n"
611 . ' <div class="item">' . "\n"
612 . ' <label for="text_max_user_connections"><tt><dfn title="'
613 . $GLOBALS['strPrivDescMaxUserConnections'] . '">MAX USER_CONNECTIONS</dfn></tt></label>' . "\n"
614 . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="'
615 . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '" />' . "\n"
616 . ' </div>' . "\n"
617 . ' </fieldset>' . "\n";
619 // for Safari 2.0.2
620 echo ' <div class="clearfloat"></div>' . "\n";
622 echo '</fieldset>' . "\n";
623 if ($submit) {
624 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
625 . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
626 . '</fieldset>' . "\n";
628 } // end of the 'PMA_displayPrivTable()' function
632 * Displays the fields used by the "new user" form as well as the
633 * "change login information / copy user" form.
635 * @param string $mode are we creating a new user or are we just
636 * changing one? (allowed values: 'new', 'change')
637 * @global array $cfg the phpMyAdmin configuration
638 * @global ressource $user_link the database connection
640 * @return void
642 function PMA_displayLoginInformationFields($mode = 'new')
644 // Get user/host name lengths
645 $fields_info = PMA_DBI_get_fields('mysql', 'user');
646 $username_length = 16;
647 $hostname_length = 41;
648 foreach ($fields_info as $key => $val) {
649 if ($val['Field'] == 'User') {
650 strtok($val['Type'], '()');
651 $v = strtok('()');
652 if (is_int($v)) {
653 $username_length = $v;
655 } elseif ($val['Field'] == 'Host') {
656 strtok($val['Type'], '()');
657 $v = strtok('()');
658 if (is_int($v)) {
659 $hostname_length = $v;
663 unset($fields_info);
665 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
666 $GLOBALS['pred_username'] = 'any';
668 echo '<fieldset id="fieldset_add_user_login">' . "\n"
669 . '<legend>' . $GLOBALS['strLoginInformation'] . '</legend>' . "\n"
670 . '<div class="item">' . "\n"
671 . '<label for="select_pred_username">' . "\n"
672 . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
673 . '</label>' . "\n"
674 . '<span class="options">' . "\n"
675 . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
676 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
677 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
678 . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
679 . ' </select>' . "\n"
680 . '</span>' . "\n"
681 . '<input type="text" name="username" maxlength="'
682 . $username_length . '" title="' . $GLOBALS['strUserName'] . '"'
683 . (empty($GLOBALS['username'])
684 ? ''
685 : ' value="' . htmlspecialchars(isset($GLOBALS['new_username'])
686 ? $GLOBALS['new_username']
687 : $GLOBALS['username']) . '"')
688 . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
689 . '</div>' . "\n"
690 . '<div class="item">' . "\n"
691 . '<label for="select_pred_hostname">' . "\n"
692 . ' ' . $GLOBALS['strHost'] . ':' . "\n"
693 . '</label>' . "\n"
694 . '<span class="options">' . "\n"
695 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
696 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
697 if (! empty($_current_user)) {
698 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
699 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
700 unset($thishost);
703 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
704 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
705 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
706 unset($_current_user);
708 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
709 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
710 switch (strtolower($GLOBALS['hostname'])) {
711 case 'localhost':
712 case '127.0.0.1':
713 $GLOBALS['pred_hostname'] = 'localhost';
714 break;
715 case '%':
716 $GLOBALS['pred_hostname'] = 'any';
717 break;
718 default:
719 $GLOBALS['pred_hostname'] = 'userdefined';
720 break;
723 echo ' <option value="any"'
724 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
725 ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost']
726 . '</option>' . "\n"
727 . ' <option value="localhost"'
728 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
729 ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost']
730 . '</option>' . "\n";
731 if (!empty($thishost)) {
732 echo ' <option value="thishost"'
733 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
734 ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost']
735 . '</option>' . "\n";
737 unset($thishost);
738 echo ' <option value="hosttable"'
739 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
740 ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable']
741 . '</option>' . "\n"
742 . ' <option value="userdefined"'
743 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
744 ? ' selected="selected"' : '')
745 . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
746 . ' </select>' . "\n"
747 . '</span>' . "\n"
748 . '<input type="text" name="hostname" maxlength="'
749 . $hostname_length . '" value="'
750 . htmlspecialchars(isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
751 . '" title="' . $GLOBALS['strHost']
752 . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
753 . PMA_showHint($GLOBALS['strHostTableExplanation'])
754 . '</div>' . "\n"
755 . '<div class="item">' . "\n"
756 . '<label for="select_pred_password">' . "\n"
757 . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
758 . '</label>' . "\n"
759 . '<span class="options">' . "\n"
760 . ' <select name="pred_password" id="select_pred_password" title="'
761 . $GLOBALS['strPassword'] . '"' . "\n"
762 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
763 . ($mode == 'change' ? ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
764 . ' <option value="none"';
765 if (isset($GLOBALS['username']) && $mode != 'change') {
766 echo ' selected="selected"';
768 echo '>' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
769 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
770 . ' </select>' . "\n"
771 . '</span>' . "\n"
772 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
773 . '</div>' . "\n"
774 . '<div class="item">' . "\n"
775 . '<label for="text_pma_pw2">' . "\n"
776 . ' ' . $GLOBALS['strReType'] . ':' . "\n"
777 . '</label>' . "\n"
778 . '<span class="options">&nbsp;</span>' . "\n"
779 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
780 . '</div>' . "\n"
781 . '<div class="item">' . "\n"
782 . '<label for="button_generate_password">' . "\n"
783 . ' ' . $GLOBALS['strGeneratePassword'] . ':' . "\n"
784 . '</label>' . "\n"
785 . '<span class="options">' . "\n"
786 . ' <input type="button" id="button_generate_password" value="' . $GLOBALS['strGenerate'] . '" onclick="suggestPassword(this.form)" />' . "\n"
787 . '</span>' . "\n"
788 . '<input type="text" name="generated_pw" id="generated_pw" />' . "\n"
789 . '</div>' . "\n"
790 . '</fieldset>' . "\n";
791 } // end of the 'PMA_displayUserAndHostFields()' function
795 * Changes / copies a user, part I
797 if (isset($_REQUEST['change_copy'])) {
798 $user_host_condition =
799 ' WHERE `User`'
800 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
801 .' AND `Host`'
802 .' = \'' . PMA_sqlAddslashes($old_hostname) . '\';';
803 $row = PMA_DBI_fetch_single_row('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
804 if (! $row) {
805 PMA_Message::notice('strNoUsersFound')->display();
806 unset($_REQUEST['change_copy']);
807 } else {
808 extract($row, EXTR_OVERWRITE);
809 // Recent MySQL versions have the field "Password" in mysql.user,
810 // so the previous extract creates $Password but this script
811 // uses $password
812 if (!isset($password) && isset($Password)) {
813 $password = $Password;
815 $queries = array();
821 * Adds a user
822 * (Changes / copies a user, part II)
824 if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) {
825 $sql_query = '';
826 if ($pred_username == 'any') {
827 $username = '';
829 switch ($pred_hostname) {
830 case 'any':
831 $hostname = '%';
832 break;
833 case 'localhost':
834 $hostname = 'localhost';
835 break;
836 case 'hosttable':
837 $hostname = '';
838 break;
839 case 'thishost':
840 $_user_name = PMA_DBI_fetch_value('SELECT USER()');
841 $hostname = substr($_user_name, (strrpos($_user_name, '@') + 1));
842 unset($_user_name);
843 break;
845 $sql = "SELECT '1' FROM `mysql`.`user`"
846 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
847 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
848 if (PMA_DBI_fetch_value($sql) == 1) {
849 $message = PMA_Message::error('strUserAlreadyExists');
850 $message->addParam('[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
851 $_REQUEST['adduser'] = true;
852 } else {
854 $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\'';
856 $real_sql_query =
857 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \''
858 . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\'';
859 if ($pred_password != 'none' && $pred_password != 'keep') {
860 $sql_query = $real_sql_query . ' IDENTIFIED BY \'***\'';
861 $real_sql_query .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
862 if (isset($create_user_real)) {
863 $create_user_show = $create_user_real . ' IDENTIFIED BY \'***\'';
864 $create_user_real .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
866 } else {
867 if ($pred_password == 'keep' && !empty($password)) {
868 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
869 if (isset($create_user_real)) {
870 $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
873 $sql_query = $real_sql_query;
874 if (isset($create_user_real)) {
875 $create_user_show = $create_user_real;
879 * @todo similar code appears twice in this script
881 if ((isset($Grant_priv) && $Grant_priv == 'Y')
882 || (isset($max_questions) || isset($max_connections)
883 || isset($max_updates) || isset($max_user_connections))) {
884 $real_sql_query .= ' WITH';
885 $sql_query .= ' WITH';
886 if (isset($Grant_priv) && $Grant_priv == 'Y') {
887 $real_sql_query .= ' GRANT OPTION';
888 $sql_query .= ' GRANT OPTION';
890 if (isset($max_questions)) {
891 // avoid negative values
892 $max_questions = max(0, (int)$max_questions);
893 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
894 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
896 if (isset($max_connections)) {
897 $max_connections = max(0, (int)$max_connections);
898 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
899 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
901 if (isset($max_updates)) {
902 $max_updates = max(0, (int)$max_updates);
903 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
904 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
906 if (isset($max_user_connections)) {
907 $max_user_connections = max(0, (int)$max_user_connections);
908 $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
909 $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
912 if (isset($create_user_real)) {
913 $create_user_real .= ';';
914 $create_user_show .= ';';
916 $real_sql_query .= ';';
917 $sql_query .= ';';
918 if (empty($_REQUEST['change_copy'])) {
919 $_error = false;
921 if (isset($create_user_real)) {
922 if (! PMA_DBI_try_query($create_user_real)) {
923 $_error = true;
925 $sql_query = $create_user_show . $sql_query;
928 if ($_error || ! PMA_DBI_try_query($real_sql_query)) {
929 $_REQUEST['createdb'] = false;
930 $message = PMA_Message::rawError(PMA_DBI_getError());
931 } else {
932 $message = PMA_Message::success('strAddUserMessage');
935 switch (PMA_ifSetOr($_REQUEST['createdb'], '0')) {
936 case '1' :
937 // Create database with same name and grant all privileges
938 $q = 'CREATE DATABASE IF NOT EXISTS '
939 . PMA_backquote(PMA_sqlAddslashes($username)) . ';';
940 $sql_query .= $q;
941 if (! PMA_DBI_try_query($q)) {
942 $message = PMA_Message::rawError(PMA_DBI_getError());
943 break;
945 $GLOBALS['reload'] = TRUE;
946 PMA_reloadNavigation();
948 $q = 'GRANT ALL PRIVILEGES ON '
949 . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \''
950 . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
951 $sql_query .= $q;
952 if (! PMA_DBI_try_query($q)) {
953 $message = PMA_Message::rawError(PMA_DBI_getError());
955 break;
956 case '2' :
957 // Grant all privileges on wildcard name (username\_%)
958 $q = 'GRANT ALL PRIVILEGES ON '
959 . PMA_backquote(PMA_sqlAddslashes($username) . '\_%') . '.* TO \''
960 . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
961 $sql_query .= $q;
962 if (! PMA_DBI_try_query($q)) {
963 $message = PMA_Message::rawError(PMA_DBI_getError());
965 break;
966 case '3' :
967 // Grant all privileges on the specified database to the new user
968 $q = 'GRANT ALL PRIVILEGES ON '
969 . PMA_backquote(PMA_sqlAddslashes($dbname)) . '.* TO \''
970 . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
971 $sql_query .= $q;
972 if (! PMA_DBI_try_query($q)) {
973 $message = PMA_Message::rawError(PMA_DBI_getError());
975 break;
976 case '0' :
977 default :
978 break;
980 } else {
981 if (isset($create_user_real)) {
982 $queries[] = $create_user_real;
984 $queries[] = $real_sql_query;
985 // we put the query containing the hidden password in
986 // $queries_for_display, at the same position occupied
987 // by the real query in $queries
988 $tmp_count = count($queries);
989 if (isset($create_user_real)) {
990 $queries_for_display[$tmp_count - 2] = $create_user_show;
992 $queries_for_display[$tmp_count - 1] = $sql_query;
994 unset($res, $real_sql_query);
1000 * Changes / copies a user, part III
1002 if (isset($_REQUEST['change_copy'])) {
1003 $user_host_condition =
1004 ' WHERE `User`'
1005 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
1006 .' AND `Host`'
1007 .' = \'' . PMA_sqlAddslashes($old_hostname) . '\';';
1008 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition);
1009 while ($row = PMA_DBI_fetch_assoc($res)) {
1010 $queries[] =
1011 'GRANT ' . join(', ', PMA_extractPrivInfo($row))
1012 .' ON ' . PMA_backquote($row['Db']) . '.*'
1013 .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\''
1014 . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';');
1016 PMA_DBI_free_result($res);
1017 $res = PMA_DBI_query(
1018 'SELECT `Db`, `Table_name`, `Table_priv`'
1019 .' FROM `mysql`.`tables_priv`' . $user_host_condition,
1020 $GLOBALS['userlink'], PMA_DBI_QUERY_STORE);
1021 while ($row = PMA_DBI_fetch_assoc($res)) {
1023 $res2 = PMA_DBI_QUERY(
1024 'SELECT `Column_name`, `Column_priv`'
1025 .' FROM `mysql`.`columns_priv`'
1026 .' WHERE `User`'
1027 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
1028 .' AND `Host`'
1029 .' = \'' . PMA_sqlAddslashes($old_hostname) . '\''
1030 .' AND `Db`'
1031 .' = \'' . PMA_sqlAddslashes($row['Db']) . "'"
1032 .' AND `Table_name`'
1033 .' = \'' . PMA_sqlAddslashes($row['Table_name']) . "'"
1034 .';',
1035 null, PMA_DBI_QUERY_STORE);
1037 $tmp_privs1 = PMA_extractPrivInfo($row);
1038 $tmp_privs2 = array(
1039 'Select' => array(),
1040 'Insert' => array(),
1041 'Update' => array(),
1042 'References' => array()
1045 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
1046 $tmp_array = explode(',', $row2['Column_priv']);
1047 if (in_array('Select', $tmp_array)) {
1048 $tmp_privs2['Select'][] = $row2['Column_name'];
1050 if (in_array('Insert', $tmp_array)) {
1051 $tmp_privs2['Insert'][] = $row2['Column_name'];
1053 if (in_array('Update', $tmp_array)) {
1054 $tmp_privs2['Update'][] = $row2['Column_name'];
1056 if (in_array('References', $tmp_array)) {
1057 $tmp_privs2['References'][] = $row2['Column_name'];
1059 unset($tmp_array);
1061 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
1062 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
1064 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
1065 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
1067 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
1068 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
1070 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
1071 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
1073 unset($tmp_privs2);
1074 $queries[] =
1075 'GRANT ' . join(', ', $tmp_privs1)
1076 . ' ON ' . PMA_backquote($row['Db']) . '.' . PMA_backquote($row['Table_name'])
1077 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\''
1078 . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';');
1084 * Updates privileges
1086 if (!empty($update_privs)) {
1087 $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, (isset($tablename) ? $tablename : ''));
1089 $sql_query0 =
1090 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1091 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
1092 if (!isset($Grant_priv) || $Grant_priv != 'Y') {
1093 $sql_query1 =
1094 'REVOKE GRANT OPTION ON ' . $db_and_table
1095 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
1096 } else {
1097 $sql_query1 = '';
1100 // Should not do a GRANT USAGE for a table-specific privilege, it
1101 // causes problems later (cannot revoke it)
1102 if (! (isset($tablename) && 'USAGE' == implode('', PMA_extractPrivInfo()))) {
1103 $sql_query2 =
1104 'GRANT ' . join(', ', PMA_extractPrivInfo())
1105 . ' ON ' . $db_and_table
1106 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\'';
1109 * @todo similar code appears twice in this script
1111 if ((isset($Grant_priv) && $Grant_priv == 'Y')
1112 || (! isset($dbname)
1113 && (isset($max_questions) || isset($max_connections)
1114 || isset($max_updates) || isset($max_user_connections))))
1116 $sql_query2 .= 'WITH';
1117 if (isset($Grant_priv) && $Grant_priv == 'Y') {
1118 $sql_query2 .= ' GRANT OPTION';
1120 if (isset($max_questions)) {
1121 $max_questions = max(0, (int)$max_questions);
1122 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
1124 if (isset($max_connections)) {
1125 $max_connections = max(0, (int)$max_connections);
1126 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
1128 if (isset($max_updates)) {
1129 $max_updates = max(0, (int)$max_updates);
1130 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
1132 if (isset($max_user_connections)) {
1133 $max_user_connections = max(0, (int)$max_user_connections);
1134 $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
1137 $sql_query2 .= ';';
1139 if (! PMA_DBI_try_query($sql_query0)) {
1140 // this query may fail, but this does not matter :o)
1141 $sql_query0 = '';
1143 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) {
1144 // this one may fail, too...
1145 $sql_query1 = '';
1147 if (isset($sql_query2)) {
1148 PMA_DBI_query($sql_query2);
1149 } else {
1150 $sql_query2 = '';
1152 $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2;
1153 $message = PMA_Message::success('strUpdatePrivMessage');
1154 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1159 * Revokes Privileges
1161 if (isset($_REQUEST['revokeall'])) {
1162 $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, isset($tablename) ? $tablename : '');
1164 $sql_query0 =
1165 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1166 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
1167 $sql_query1 =
1168 'REVOKE GRANT OPTION ON ' . $db_and_table
1169 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\';';
1171 PMA_DBI_query($sql_query0);
1172 if (! PMA_DBI_try_query($sql_query1)) {
1173 // this one may fail, too...
1174 $sql_query1 = '';
1176 $sql_query = $sql_query0 . ' ' . $sql_query1;
1177 $message = PMA_Message::success('strRevokeMessage');
1178 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1179 if (! isset($tablename)) {
1180 unset($dbname);
1181 } else {
1182 unset($tablename);
1188 * Updates the password
1190 if (isset($_REQUEST['change_pw'])) {
1191 // similar logic in user_password.php
1192 $message = '';
1194 if ($nopass == 0 && isset($pma_pw) && isset($pma_pw2)) {
1195 if ($pma_pw != $pma_pw2) {
1196 $message = PMA_Message::error('strPasswordNotSame');
1197 } elseif (empty($pma_pw) || empty($pma_pw2)) {
1198 $message = PMA_Message::error('strPasswordEmpty');
1200 } // end if
1202 // here $nopass could be == 1
1203 if (empty($message)) {
1205 $hashing_function = (!empty($pw_hash) && $pw_hash == 'old' ? 'OLD_' : '')
1206 . 'PASSWORD';
1208 // in $sql_query which will be displayed, hide the password
1209 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')');
1210 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . PMA_sqlAddslashes($hostname) . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($pma_pw) . '\')');
1211 PMA_DBI_try_query($local_query)
1212 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, FALSE, $err_url);
1213 $message = PMA_Message::success('strPasswordChanged');
1214 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1220 * Deletes users
1221 * (Changes / copies a user, part IV)
1224 if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4)) {
1225 if (isset($_REQUEST['change_copy'])) {
1226 $selected_usr = array($old_username . '&amp;#27;' . $old_hostname);
1227 } else {
1228 $selected_usr = $_REQUEST['selected_usr'];
1229 $queries = array();
1231 foreach ($selected_usr as $each_user) {
1232 list($this_user, $this_host) = explode('&amp;#27;', $each_user);
1233 $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
1234 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . PMA_sqlAddslashes($this_host) . '\';';
1236 if (isset($_REQUEST['drop_users_db'])) {
1237 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
1238 $GLOBALS['reload'] = TRUE;
1239 PMA_reloadNavigation();
1242 if (empty($_REQUEST['change_copy'])) {
1243 if (empty($queries)) {
1244 $message = PMA_Message::error('strDeleteNoUsersSelected');
1245 } else {
1246 if ($_REQUEST['mode'] == 3) {
1247 $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
1248 $queries[] = 'FLUSH PRIVILEGES;';
1250 $drop_user_error = '';
1251 foreach ($queries as $sql_query) {
1252 if ($sql_query{0} != '#') {
1253 if (! PMA_DBI_try_query($sql_query, $GLOBALS['userlink'])) {
1254 $drop_user_error .= PMA_DBI_getError() . "\n";
1258 $sql_query = join("\n", $queries);
1259 if (! empty($drop_user_error)) {
1260 $message = PMA_Message::rawError($drop_user_error);
1261 } else {
1262 $message = PMA_Message::success('strUsersDeleted');
1265 unset($queries);
1271 * Changes / copies a user, part V
1273 if (isset($_REQUEST['change_copy'])) {
1274 $tmp_count = 0;
1275 foreach ($queries as $sql_query) {
1276 if ($sql_query{0} != '#') {
1277 PMA_DBI_query($sql_query);
1279 // when there is a query containing a hidden password, take it
1280 // instead of the real query sent
1281 if (isset($queries_for_display[$tmp_count])) {
1282 $queries[$tmp_count] = $queries_for_display[$tmp_count];
1284 $tmp_count++;
1286 $message = PMA_Message::success();
1287 $sql_query = join("\n", $queries);
1292 * Reloads the privilege tables into memory
1294 if (isset($_REQUEST['flush_privileges'])) {
1295 $sql_query = 'FLUSH PRIVILEGES;';
1296 PMA_DBI_query($sql_query);
1297 $message = PMA_Message::success('strPrivilegesReloaded');
1302 * Displays the links
1304 if (isset($viewing_mode) && $viewing_mode == 'db') {
1305 $db = $checkprivs;
1306 $url_query .= '&amp;goto=db_operations.php';
1308 // Gets the database structure
1309 $sub_part = '_structure';
1310 require './libraries/db_info.inc.php';
1311 echo "\n";
1312 } else {
1313 require './libraries/server_links.inc.php';
1318 * defines some standard links
1320 $link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1321 . '&amp;username=%s'
1322 . '&amp;hostname=%s'
1323 . '&amp;dbname=%s'
1324 . '&amp;tablename=%s">'
1325 . PMA_getIcon('b_usredit.png', $GLOBALS['strEditPrivileges'])
1326 . '</a>';
1328 $link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1329 . '&amp;username=%s'
1330 . '&amp;hostname=%s'
1331 . '&amp;dbname=%s'
1332 . '&amp;tablename=%s'
1333 . '&amp;revokeall=1">'
1334 . PMA_getIcon('b_usrdrop.png', $GLOBALS['strRevoke'])
1335 . '</a>';
1338 * Displays the page
1340 if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs))) {
1341 if (! isset($username)) {
1342 // No username is given --> display the overview
1343 echo '<h2>' . "\n"
1344 . PMA_getIcon('b_usrlist.png')
1345 . $GLOBALS['strUserOverview'] . "\n"
1346 . '</h2>' . "\n";
1348 $sql_query =
1349 'SELECT *,' .
1350 " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" .
1351 ' FROM `mysql`.`user`';
1353 $sql_query .= (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1355 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
1356 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1358 if (! $res) {
1359 // the query failed! This may have two reasons:
1360 // - the user does not have enough privileges
1361 // - the privilege tables use a structure of an earlier version.
1362 // so let's try a more simple query
1364 $sql_query = 'SELECT * FROM `mysql`.`user`';
1365 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1367 if (!$res) {
1368 PMA_Message::error('strNoPrivileges')->display();
1369 PMA_DBI_free_result($res);
1370 unset($res);
1371 } else {
1372 // rabus: This message is hardcoded because I will replace it by
1373 // a automatic repair feature soon.
1374 $raw = 'Your privilege table structure seems to be older than'
1375 . ' this MySQL version!<br />'
1376 . 'Please run the <tt>mysql_upgrade</tt> command'
1377 . '(<tt>mysql_fix_privilege_tables</tt> on older systems)'
1378 . ' that should be included in your MySQL server distribution'
1379 . ' to solve this problem!';
1380 PMA_Message::rawError($raw)->display();
1382 } else {
1384 // we also want users not in table `user` but in other table
1385 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1387 $tables_to_search_for_users = array(
1388 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',
1391 $db_rights_sqls = array();
1392 foreach ($tables_to_search_for_users as $table_search_in) {
1393 if (in_array($table_search_in, $tables)) {
1394 $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1398 $user_defaults = array(
1399 'User' => '',
1400 'Host' => '%',
1401 'Password' => '?',
1402 'Grant_priv' => 'N',
1403 'privs' => array('USAGE'),
1406 // for all initials, even non A-Z
1407 $array_initials = array();
1408 // for the rights
1409 $db_rights = array();
1411 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1412 .' ORDER BY `User` ASC, `Host` ASC';
1414 $db_rights_result = PMA_DBI_query($db_rights_sql);
1416 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1417 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1418 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1419 $db_rights_row;
1421 PMA_DBI_free_result($db_rights_result);
1422 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1423 ksort($db_rights);
1426 * Displays the initials
1429 // initialize to FALSE the letters A-Z
1430 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) {
1431 if (! isset($array_initials[chr($letter_counter + 64)])) {
1432 $array_initials[chr($letter_counter + 64)] = FALSE;
1436 $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE);
1437 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1438 $array_initials[$tmp_initial] = TRUE;
1441 // Display the initials, which can be any characters, not
1442 // just letters. For letters A-Z, we add the non-used letters
1443 // as greyed out.
1445 uksort($array_initials, "strnatcasecmp");
1447 echo '<table cellspacing="5"><tr>';
1448 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1449 if ($initial_was_found) {
1450 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a></td>' . "\n";
1451 } else {
1452 echo '<td>' . $tmp_initial . '</td>';
1455 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;showall=1">[' . $GLOBALS['strShowAll'] . ']</a></td>' . "\n";
1456 echo '</tr></table>';
1459 * Display the user overview
1460 * (if less than 50 users, display them immediately)
1463 if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) {
1465 while ($row = PMA_DBI_fetch_assoc($res)) {
1466 $row['privs'] = PMA_extractPrivInfo($row, true);
1467 $db_rights[$row['User']][$row['Host']] = $row;
1469 @PMA_DBI_free_result($res);
1470 unset($res);
1472 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1473 . PMA_generate_common_hidden_inputs('', '')
1474 . ' <table id="tableuserrights" class="data">' . "\n"
1475 . ' <thead>' . "\n"
1476 . ' <tr><th></th>' . "\n"
1477 . ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1478 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1479 . ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n"
1480 . ' <th>' . $GLOBALS['strGlobalPrivileges'] . ' '
1481 . PMA_showHint($GLOBALS['strEnglishPrivileges']) . '</th>' . "\n"
1482 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1483 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n";
1484 echo ' </tr>' . "\n";
1485 echo ' </thead>' . "\n";
1486 echo ' <tbody>' . "\n";
1487 $odd_row = true;
1488 $index_checkbox = -1;
1489 foreach ($db_rights as $user) {
1490 $index_checkbox++;
1491 ksort($user);
1492 foreach ($user as $host) {
1493 $index_checkbox++;
1494 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1495 . ' <td><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_'
1496 . $index_checkbox . '" value="'
1497 . htmlspecialchars($host['User'] . '&amp;#27;' . $host['Host'])
1498 . '"'
1499 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
1500 . ' /></td>' . "\n"
1501 . ' <td><label for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n"
1502 . ' <td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
1503 echo ' <td>';
1504 switch ($host['Password']) {
1505 case 'Y':
1506 echo $GLOBALS['strYes'];
1507 break;
1508 case 'N':
1509 echo '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>';
1510 break;
1511 // this happens if this is a definition not coming from mysql.user
1512 default:
1513 echo '--'; // in future version, replace by "not present"
1514 break;
1515 } // end switch
1516 echo '</td>' . "\n"
1517 . ' <td><tt>' . "\n"
1518 . ' ' . implode(',' . "\n" . ' ', $host['privs']) . "\n"
1519 . ' </tt></td>' . "\n"
1520 . ' <td>' . ($host['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1521 . ' <td align="center">';
1522 printf($link_edit, urlencode($host['User']),
1523 urlencode($host['Host']), '', '');
1524 echo '</td>' . "\n"
1525 . ' </tr>' . "\n";
1526 $odd_row = ! $odd_row;
1530 unset($user, $host, $odd_row);
1531 echo ' </tbody></table>' . "\n"
1532 .'<img class="selectallarrow"'
1533 .' src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
1534 .' width="38" height="22"'
1535 .' alt="' . $GLOBALS['strWithChecked'] . '" />' . "\n"
1536 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;checkall=1"'
1537 .' onclick="if (markAllRows(\'usersForm\')) return false;">'
1538 . $GLOBALS['strCheckAll'] . '</a>' . "\n"
1539 .'/' . "\n"
1540 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '"'
1541 .' onclick="if (unMarkAllRows(\'usersForm\')) return false;">'
1542 . $GLOBALS['strUncheckAll'] . '</a>' . "\n";
1544 // add/delete user fieldset
1545 echo ' <fieldset id="fieldset_add_user">' . "\n"
1546 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1547 . PMA_getIcon('b_usradd.png')
1548 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1549 . ' </fieldset>' . "\n"
1550 . ' <fieldset id="fieldset_delete_user">'
1551 . ' <legend>' . "\n"
1552 . PMA_getIcon('b_usrdrop.png')
1553 . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n"
1554 . ' </legend>' . "\n"
1555 . ' <input type="hidden" name="mode" value="2" />' . "\n"
1556 . '(' . $GLOBALS['strRevokeAndDelete'] . ')<br />' . "\n"
1557 . ' <input type="checkbox" title="' . $GLOBALS['strDropUsersDb'] . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
1558 . ' <label for="checkbox_drop_users_db" title="' . $GLOBALS['strDropUsersDb'] . '">' . "\n"
1559 . ' ' . $GLOBALS['strDropUsersDb'] . "\n"
1560 . ' </label>' . "\n"
1561 . ' </fieldset>' . "\n"
1562 . ' <fieldset id="fieldset_delete_user_footer" class="tblFooters">' . "\n"
1563 . ' <input type="submit" name="delete" value="' . $GLOBALS['strGo'] . '" id="buttonGo" />' . "\n"
1564 . ' </fieldset>' . "\n"
1565 . '</form>' . "\n";
1566 } else {
1568 unset ($row);
1569 echo ' <fieldset id="fieldset_add_user">' . "\n"
1570 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1571 . PMA_getIcon('b_usradd.png')
1572 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1573 . ' </fieldset>' . "\n";
1574 } // end if (display overview)
1575 $flushnote = new PMA_Message('strFlushPrivilegesNote', PMA_Message::NOTICE);
1576 $flushnote->addParam('<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;flush_privileges=1">', false);
1577 $flushnote->addParam('</a>', false);
1578 $flushnote->display();
1582 } else {
1584 // A user was selected -> display the user's properties
1586 echo '<h2>' . "\n"
1587 . PMA_getIcon('b_usredit.png')
1588 . $GLOBALS['strEditPrivileges'] . ': '
1589 . $GLOBALS['strUser'] ;
1591 if (isset($dbname)) {
1592 echo ' <i><a href="server_privileges.php?'
1593 . $GLOBALS['url_query'] . '&amp;username=' . urlencode($username)
1594 . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=&amp;tablename=">\''
1595 . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1596 . '\'</a></i>' . "\n";
1597 $url_dbname = urlencode(str_replace(array('\_', '\%'), array('_', '%'), $dbname));
1599 echo ' - ' . ($dbname_is_wildcard ? $GLOBALS['strDatabases'] : $GLOBALS['strDatabase'] );
1600 if (isset($tablename)) {
1601 echo ' <i><a href="server_privileges.php?' . $GLOBALS['url_query']
1602 . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname)
1603 . '&amp;dbname=' . $url_dbname . '&amp;tablename=">' . htmlspecialchars($dbname) . '</a></i>';
1604 echo ' - ' . $GLOBALS['strTable'] . ' <i>' . htmlspecialchars($tablename) . '</i>';
1605 } else {
1606 echo ' <i>' . htmlspecialchars($dbname) . '</i>';
1609 } else {
1610 echo ' <i>\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1611 . '\'</i>' . "\n";
1614 echo '</h2>' . "\n";
1617 $sql = "SELECT '1' FROM `mysql`.`user`"
1618 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
1619 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
1620 $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql);
1621 unset($sql);
1622 if ($user_does_not_exists) {
1623 PMA_Message::warning('strUserNotFound')->display();
1624 PMA_displayLoginInformationFields();
1625 //require_once './libraries/footer.inc.php';
1628 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n";
1629 $_params = array(
1630 'username' => $username,
1631 'hostname' => $hostname,
1633 if (isset($dbname)) {
1634 $_params['dbname'] = $dbname;
1635 if (isset($tablename)) {
1636 $_params['tablename'] = $tablename;
1639 echo PMA_generate_common_hidden_inputs($_params);
1641 PMA_displayPrivTable(PMA_ifSetOr($dbname, '*', 'length'),
1642 PMA_ifSetOr($tablename, '*', 'length'));
1644 echo '</form>' . "\n";
1646 if (! isset($tablename) && empty($dbname_is_wildcard)) {
1648 // no table name was given, display all table specific rights
1649 // but only if $dbname contains no wildcards
1651 // table header
1652 echo '<form action="server_privileges.php" method="post">' . "\n"
1653 . PMA_generate_common_hidden_inputs('', '')
1654 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1655 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1656 . '<fieldset>' . "\n"
1657 . '<legend>' . (! isset($dbname) ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '</legend>' . "\n"
1658 . '<table class="data">' . "\n"
1659 . '<thead>' . "\n"
1660 . '<tr><th>' . (! isset($dbname) ? $GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '</th>' . "\n"
1661 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1662 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1663 . ' <th>' . (! isset($dbname) ? $GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '</th>' . "\n"
1664 . ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>' . "\n"
1665 . '</tr>' . "\n"
1666 . '</thead>' . "\n"
1667 . '<tbody>' . "\n";
1669 $user_host_condition =
1670 ' WHERE `User`'
1671 . ' = \'' . PMA_sqlAddslashes($username) . "'"
1672 . ' AND `Host`'
1673 . ' = \'' . PMA_sqlAddslashes($hostname) . "'";
1675 // table body
1676 // get data
1678 // we also want privielgs for this user not in table `db` but in other table
1679 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1680 if (! isset($dbname)) {
1682 // no db name given, so we want all privs for the given user
1684 $tables_to_search_for_users = array(
1685 'tables_priv', 'columns_priv',
1688 $db_rights_sqls = array();
1689 foreach ($tables_to_search_for_users as $table_search_in) {
1690 if (in_array($table_search_in, $tables)) {
1691 $db_rights_sqls[] = '
1692 SELECT DISTINCT `Db`
1693 FROM `mysql`.' . PMA_backquote($table_search_in)
1694 . $user_host_condition;
1698 $user_defaults = array(
1699 'Db' => '',
1700 'Grant_priv' => 'N',
1701 'privs' => array('USAGE'),
1702 'Table_privs' => true,
1705 // for the rights
1706 $db_rights = array();
1708 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1709 .' ORDER BY `Db` ASC';
1711 $db_rights_result = PMA_DBI_query($db_rights_sql);
1713 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1714 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1715 // only Db names in the table `mysql`.`db` uses wildcards
1716 // as we are in the db specific rights display we want
1717 // all db names escaped, also from other sources
1718 $db_rights_row['Db'] = PMA_escape_mysql_wildcards(
1719 $db_rights_row['Db']);
1720 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1723 PMA_DBI_free_result($db_rights_result);
1724 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1726 $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC';
1727 $res = PMA_DBI_query($sql_query);
1728 $sql_query = '';
1730 while ($row = PMA_DBI_fetch_assoc($res)) {
1731 if (isset($db_rights[$row['Db']])) {
1732 $db_rights[$row['Db']] = array_merge($db_rights[$row['Db']], $row);
1733 } else {
1734 $db_rights[$row['Db']] = $row;
1736 // there are db specific rights for this user
1737 // so we can drop this db rights
1738 $db_rights[$row['Db']]['can_delete'] = true;
1740 PMA_DBI_free_result($res);
1741 unset($row, $res);
1743 } else {
1745 // db name was given,
1746 // so we want all user specific rights for this db
1748 $user_host_condition .=
1749 ' AND `Db`'
1750 .' LIKE \'' . PMA_sqlAddslashes($dbname) . "'";
1752 $tables_to_search_for_users = array(
1753 'columns_priv',
1756 $db_rights_sqls = array();
1757 foreach ($tables_to_search_for_users as $table_search_in) {
1758 if (in_array($table_search_in, $tables)) {
1759 $db_rights_sqls[] = '
1760 SELECT DISTINCT `Table_name`
1761 FROM `mysql`.' . PMA_backquote($table_search_in)
1762 . $user_host_condition;
1766 $user_defaults = array(
1767 'Table_name' => '',
1768 'Grant_priv' => 'N',
1769 'privs' => array('USAGE'),
1770 'Column_priv' => true,
1773 // for the rights
1774 $db_rights = array();
1776 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1777 .' ORDER BY `Table_name` ASC';
1779 $db_rights_result = PMA_DBI_query($db_rights_sql);
1781 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1782 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1783 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1785 PMA_DBI_free_result($db_rights_result);
1786 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1788 $sql_query =
1789 'SELECT `Table_name`,'
1790 .' `Table_priv`,'
1791 .' IF(`Column_priv` = _latin1 \'\', 0, 1)'
1792 .' AS \'Column_priv\''
1793 .' FROM `mysql`.`tables_priv`'
1794 . $user_host_condition
1795 .' ORDER BY `Table_name` ASC;';
1796 $res = PMA_DBI_query($sql_query);
1797 $sql_query = '';
1799 while ($row = PMA_DBI_fetch_assoc($res)) {
1800 if (isset($db_rights[$row['Table_name']])) {
1801 $db_rights[$row['Table_name']] = array_merge($db_rights[$row['Table_name']], $row);
1802 } else {
1803 $db_rights[$row['Table_name']] = $row;
1806 PMA_DBI_free_result($res);
1807 unset($row, $res);
1809 ksort($db_rights);
1811 // display rows
1812 if (count($db_rights) < 1) {
1813 echo '<tr class="odd">' . "\n"
1814 . ' <td colspan="6"><center><i>' . $GLOBALS['strNone'] . '</i></center></td>' . "\n"
1815 . '</tr>' . "\n";
1816 } else {
1817 $odd_row = true;
1818 $found_rows = array();
1819 //while ($row = PMA_DBI_fetch_assoc($res)) {
1820 foreach ($db_rights as $row) {
1821 $found_rows[] = (! isset($dbname)) ? $row['Db'] : $row['Table_name'];
1823 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1824 . ' <td>' . htmlspecialchars((! isset($dbname)) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
1825 . ' <td><tt>' . "\n"
1826 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1827 . ' </tt></td>' . "\n"
1828 . ' <td>' . ((((! isset($dbname)) && $row['Grant_priv'] == 'Y') || (isset($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1829 . ' <td>';
1830 if (! empty($row['Table_privs']) || ! empty ($row['Column_priv'])) {
1831 echo $GLOBALS['strYes'];
1832 } else {
1833 echo $GLOBALS['strNo'];
1835 echo '</td>' . "\n"
1836 . ' <td>';
1837 printf($link_edit, urlencode($username),
1838 urlencode($hostname),
1839 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1840 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1841 echo '</td>' . "\n"
1842 . ' <td>';
1843 if (! empty($row['can_delete']) || isset($row['Table_name']) && strlen($row['Table_name'])) {
1844 printf($link_revoke, urlencode($username),
1845 urlencode($hostname),
1846 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1847 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1849 echo '</td>' . "\n"
1850 . '</tr>' . "\n";
1851 $odd_row = ! $odd_row;
1852 } // end while
1854 unset($row);
1855 echo '</tbody>' . "\n"
1856 . '</table>' . "\n";
1858 if (! isset($dbname)) {
1860 // no database name was given, display select db
1862 $pred_db_array =PMA_DBI_fetch_result('SHOW DATABASES;');
1864 echo ' <label for="text_dbname">' . $GLOBALS['strAddPrivilegesOnDb'] . ':</label>' . "\n";
1865 if (!empty($pred_db_array)) {
1866 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1867 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1868 foreach ($pred_db_array as $current_db) {
1869 $current_db = PMA_escape_mysql_wildcards($current_db);
1870 // cannot use array_diff() once, outside of the loop,
1871 // because the list of databases has special characters
1872 // already escaped in $found_rows,
1873 // contrary to the output of SHOW DATABASES
1874 if (empty($found_rows) || ! in_array($current_db, $found_rows)) {
1875 echo ' <option value="' . htmlspecialchars($current_db) . '">'
1876 . htmlspecialchars($current_db) . '</option>' . "\n";
1879 echo ' </select>' . "\n";
1881 echo ' <input type="text" id="text_dbname" name="dbname" />' . "\n"
1882 . PMA_showHint($GLOBALS['strEscapeWildcards']);
1883 } else {
1884 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1885 . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n";
1886 if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE)) {
1887 $pred_tbl_array = array();
1888 while ($row = PMA_DBI_fetch_row($res)) {
1889 if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
1890 $pred_tbl_array[] = $row[0];
1893 PMA_DBI_free_result($res);
1894 unset($res, $row);
1895 if (!empty($pred_tbl_array)) {
1896 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1897 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1898 foreach ($pred_tbl_array as $current_table) {
1899 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1901 echo ' </select>' . "\n";
1903 } else {
1904 unset($res);
1906 echo ' <input type="text" id="text_tablename" name="tablename" />' . "\n";
1908 echo '</fieldset>' . "\n";
1909 echo '<fieldset class="tblFooters">' . "\n"
1910 . ' <input type="submit" value="' . $GLOBALS['strGo'] . '" />'
1911 . '</fieldset>' . "\n"
1912 . '</form>' . "\n";
1916 // Provide a line with links to the relevant database and table
1917 if (isset($dbname) && empty($dbname_is_wildcard)) {
1918 echo '[ ' . $GLOBALS['strDatabase']
1919 . ' <a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?'
1920 . $GLOBALS['url_query'] . '&amp;db=' . $url_dbname . '&amp;reload=1">'
1921 . htmlspecialchars($dbname) . ': ' . PMA_getTitleForTarget($GLOBALS['cfg']['DefaultTabDatabase']) . "</a> ]\n";
1923 if (isset($tablename)) {
1924 echo ' [ ' . $GLOBALS['strTable'] . ' <a href="'
1925 . $GLOBALS['cfg']['DefaultTabTable'] . '?' . $GLOBALS['url_query']
1926 . '&amp;db=' . $url_dbname . '&amp;table=' . urlencode($tablename)
1927 . '&amp;reload=1">' . htmlspecialchars($tablename) . ': '
1928 . PMA_getTitleForTarget($GLOBALS['cfg']['DefaultTabTable'])
1929 . "</a> ]\n";
1931 unset($url_dbname);
1934 if (! isset($dbname) && ! $user_does_not_exists) {
1935 require_once './libraries/display_change_password.lib.php';
1937 echo '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1938 . PMA_generate_common_hidden_inputs('', '')
1939 . '<input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1940 . '<input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1941 . '<fieldset id="fieldset_change_copy_user">' . "\n"
1942 . ' <legend>' . $GLOBALS['strChangeCopyUser'] . '</legend>' . "\n";
1943 PMA_displayLoginInformationFields('change');
1944 echo ' <fieldset>' . "\n"
1945 . ' <legend>' . $GLOBALS['strChangeCopyMode'] . '</legend>' . "\n";
1946 $choices = array(
1947 '4' => $GLOBALS['strChangeCopyModeCopy'],
1948 '1' => $GLOBALS['strChangeCopyModeJustDelete'],
1949 '2' => $GLOBALS['strChangeCopyModeRevoke'],
1950 '3' => $GLOBALS['strChangeCopyModeDeleteAndReload']);
1951 PMA_display_html_radio('mode', $choices, '4', true);
1952 unset($choices);
1954 echo ' </fieldset>' . "\n"
1955 . '</fieldset>' . "\n"
1956 . '<fieldset id="fieldset_change_copy_user_footer" class="tblFooters">' . "\n"
1957 . ' <input type="submit" name="change_copy" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1958 . '</fieldset>' . "\n"
1959 . '</form>' . "\n";
1962 } elseif (isset($_REQUEST['adduser'])) {
1963 // Add a new user
1964 $GLOBALS['url_query'] .= '&amp;adduser=1';
1965 echo '<h2>' . "\n"
1966 . PMA_getIcon('b_usradd.png') . $GLOBALS['strAddUser'] . "\n"
1967 . '</h2>' . "\n"
1968 . '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1969 . PMA_generate_common_hidden_inputs('', '');
1970 PMA_displayLoginInformationFields('new');
1971 echo '<fieldset id="fieldset_add_user_database">' . "\n"
1972 . '<legend>' . $GLOBALS['strCreateUserDatabase'] . '</legend>' . "\n";
1974 $default_choice = 0;
1975 $choices = array(
1976 '0' => $GLOBALS['strCreateUserDatabaseNone'],
1977 '1' => $GLOBALS['strCreateUserDatabaseName'],
1978 '2' => $GLOBALS['strCreateUserDatabaseWildcard']);
1980 if ( !empty($dbname) ) {
1981 $choices['3'] = sprintf($GLOBALS['strCreateUserDatabasePrivileges'], htmlspecialchars($dbname));
1982 $default_choice = 3;
1983 echo '<input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '" />' . "\n";
1986 // 4th parameter set to true to add line breaks
1987 // 5th parameter set to false to avoid htmlspecialchars() escaping in the label
1988 // since we have some HTML in some labels
1989 PMA_display_html_radio('createdb', $choices, $default_choice, true, false);
1990 unset($choices);
1991 unset($default_choice);
1993 echo '</fieldset>' . "\n";
1994 PMA_displayPrivTable('*', '*', FALSE);
1995 echo ' <fieldset id="fieldset_add_user_footer" class="tblFooters">' . "\n"
1996 . ' <input type="submit" name="adduser_submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1997 . ' </fieldset>' . "\n"
1998 . '</form>' . "\n";
1999 } else {
2000 // check the privileges for a particular database.
2001 echo '<table id="tablespecificuserrights" class="data">' . "\n"
2002 . '<caption class="tblHeaders">' . "\n"
2003 . PMA_getIcon('b_usrcheck.png')
2004 . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
2005 . '</caption>' . "\n"
2006 . '<thead>' . "\n"
2007 . ' <tr><th>' . $GLOBALS['strUser'] . '</th>' . "\n"
2008 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
2009 . ' <th>' . $GLOBALS['strType'] . '</th>' . "\n"
2010 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
2011 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
2012 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n"
2013 . ' </tr>' . "\n"
2014 . '</thead>' . "\n"
2015 . '<tbody>' . "\n";
2016 $odd_row = TRUE;
2017 unset($row, $row1, $row2);
2019 // now, we build the table...
2020 $list_of_privileges =
2021 '`User`, '
2022 . '`Host`, '
2023 . '`Select_priv`, '
2024 . '`Insert_priv`, '
2025 . '`Update_priv`, '
2026 . '`Delete_priv`, '
2027 . '`Create_priv`, '
2028 . '`Drop_priv`, '
2029 . '`Grant_priv`, '
2030 . '`Index_priv`, '
2031 . '`Alter_priv`, '
2032 . '`References_priv`, '
2033 . '`Create_tmp_table_priv`, '
2034 . '`Lock_tables_priv`, '
2035 . '`Create_view_priv`, '
2036 . '`Show_view_priv`, '
2037 . '`Create_routine_priv`, '
2038 . '`Alter_routine_priv`, '
2039 . '`Execute_priv`';
2041 $list_of_compared_privileges =
2042 '`Select_priv` = \'N\''
2043 . ' AND `Insert_priv` = \'N\''
2044 . ' AND `Update_priv` = \'N\''
2045 . ' AND `Delete_priv` = \'N\''
2046 . ' AND `Create_priv` = \'N\''
2047 . ' AND `Drop_priv` = \'N\''
2048 . ' AND `Grant_priv` = \'N\''
2049 . ' AND `References_priv` = \'N\''
2050 . ' AND `Create_tmp_table_priv` = \'N\''
2051 . ' AND `Lock_tables_priv` = \'N\''
2052 . ' AND `Create_view_priv` = \'N\''
2053 . ' AND `Show_view_priv` = \'N\''
2054 . ' AND `Create_routine_priv` = \'N\''
2055 . ' AND `Alter_routine_priv` = \'N\''
2056 . ' AND `Execute_priv` = \'N\'';
2058 if (PMA_MYSQL_INT_VERSION >= 50106) {
2059 $list_of_privileges .=
2060 ', `Event_priv`, '
2061 . '`Trigger_priv`';
2062 $list_of_compared_privileges .=
2063 ' AND `Event_priv` = \'N\''
2064 . ' AND `Trigger_priv` = \'N\'';
2067 $sql_query =
2068 '(SELECT ' . $list_of_privileges . ', `Db`'
2069 .' FROM `mysql`.`db`'
2070 .' WHERE \'' . PMA_sqlAddslashes($checkprivs) . "'"
2071 .' LIKE `Db`'
2072 .' AND NOT (' . $list_of_compared_privileges. ')) '
2073 .'UNION '
2074 .'(SELECT ' . $list_of_privileges . ', \'*\' AS `Db`'
2075 .' FROM `mysql`.`user` '
2076 .' WHERE NOT (' . $list_of_compared_privileges . ')) '
2077 .' ORDER BY `User` ASC,'
2078 .' `Host` ASC,'
2079 .' `Db` ASC;';
2080 $res = PMA_DBI_query($sql_query);
2081 $row = PMA_DBI_fetch_assoc($res);
2082 if ($row) {
2083 $found = TRUE;
2086 if ($found) {
2087 while (TRUE) {
2088 // prepare the current user
2089 $current_privileges = array();
2090 $current_user = $row['User'];
2091 $current_host = $row['Host'];
2092 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
2093 $current_privileges[] = $row;
2094 $row = PMA_DBI_fetch_assoc($res);
2096 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
2097 . ' <td';
2098 if (count($current_privileges) > 1) {
2099 echo ' rowspan="' . count($current_privileges) . '"';
2101 echo '>' . (empty($current_user) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($current_user)) . "\n"
2102 . ' </td>' . "\n"
2103 . ' <td';
2104 if (count($current_privileges) > 1) {
2105 echo ' rowspan="' . count($current_privileges) . '"';
2107 echo '>' . htmlspecialchars($current_host) . '</td>' . "\n";
2108 foreach ($current_privileges as $current) {
2109 echo ' <td>' . "\n"
2110 . ' ';
2111 if (!isset($current['Db']) || $current['Db'] == '*') {
2112 echo $GLOBALS['strGlobal'];
2113 } elseif ($current['Db'] == PMA_escape_mysql_wildcards($checkprivs)) {
2114 echo $GLOBALS['strDbSpecific'];
2115 } else {
2116 echo $GLOBALS['strWildcard'], ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
2118 echo "\n"
2119 . ' </td>' . "\n"
2120 . ' <td>' . "\n"
2121 . ' <tt>' . "\n"
2122 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
2123 . ' </tt>' . "\n"
2124 . ' </td>' . "\n"
2125 . ' <td>' . "\n"
2126 . ' ' . ($current['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n"
2127 . ' </td>' . "\n"
2128 . ' <td>' . "\n";
2129 printf($link_edit, urlencode($current_user),
2130 urlencode($current_host),
2131 urlencode(! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db']),
2132 '');
2133 echo '</td>' . "\n"
2134 . ' </tr>' . "\n";
2136 if (empty($row) && empty($row1) && empty($row2)) {
2137 break;
2139 $odd_row = ! $odd_row;
2141 } else {
2142 echo ' <tr class="odd">' . "\n"
2143 . ' <td colspan="6">' . "\n"
2144 . ' ' . $GLOBALS['strNoUsersFound'] . "\n"
2145 . ' </td>' . "\n"
2146 . ' </tr>' . "\n";
2148 echo '</tbody>' . "\n"
2149 . '</table>' . "\n";
2151 // Offer to create a new user for the current database
2152 echo '<fieldset id="fieldset_add_user">' . "\n"
2153 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1&amp;dbname=' . $checkprivs .'">' . "\n"
2154 . PMA_getIcon('b_usradd.png')
2155 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
2156 . '</fieldset>' . "\n";
2158 } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ...
2162 * Displays the footer
2164 echo "\n\n";
2165 require_once './libraries/footer.inc.php';