2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once './libraries/common.inc.php';
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';
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'];
34 if (PMA_isValid($_REQUEST['pred_dbname'])) {
35 $dbname = $_REQUEST['pred_dbname'];
37 } elseif (PMA_isValid($_REQUEST['dbname'])) {
38 $dbname = $_REQUEST['dbname'];
45 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
46 if (isset($tablename)) {
47 $db_and_table .= PMA_backquote($tablename);
52 $db_and_table = '*.*';
55 // check if given $dbanem is a wildcard or not
57 //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
58 if (preg_match('/(?<!\\\\)(?:_|%)/i', $dbname)) {
59 $dbname_is_wildcard = true;
61 $dbname_is_wildcard = false;
66 * Checks if the user is allowed to do what he tries to...
69 require './libraries/server_links.inc.php';
71 . PMA_getIcon('b_usrlist.png')
72 . $GLOBALS['strPrivileges'] . "\n"
74 PMA_Message
::error('strNoPrivileges')->display();
75 require_once './libraries/footer.inc.php';
79 * Generates a condition on the user name
81 * @param string the user's initial
82 * @return string the generated condition
84 function PMA_RangeOfUsers($initial = '')
86 // strtolower() is used because the User field
87 // might be BINARY, so LIKE would be case sensitive
88 if (!empty($initial)) {
89 $ret = " WHERE `User` LIKE '" . $initial . "%'"
90 . " OR `User` LIKE '" . strtolower($initial) . "%'";
98 * Extracts the privilege information of a priv table row
100 * @param array $row the row
101 * @param boolean $enableHTML add <dfn> tag with tooltips
103 * @global ressource $user_link the database connection
107 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
110 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
111 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
112 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
113 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
114 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
115 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
116 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
117 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
118 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess']),
119 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
120 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
121 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
122 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
123 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
124 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
125 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
126 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
127 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
128 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),
129 array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
130 array('Event_priv', 'EVENT', $GLOBALS['strPrivDescEvent']),
131 array('Trigger_priv', 'TRIGGER', $GLOBALS['strPrivDescTrigger']),
133 array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
134 array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
136 array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
137 array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
138 array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
139 array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']),
140 array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
143 if (!empty($row) && isset($row['Table_priv'])) {
144 $row1 = PMA_DBI_fetch_single_row(
145 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
146 'ASSOC', $GLOBALS['userlink']);
147 $av_grants = explode('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7));
149 $users_grants = explode(',', $row['Table_priv']);
150 foreach ($av_grants as $current_grant) {
151 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ?
'Y' : 'N';
153 unset($current_grant);
155 unset($users_grants);
158 $allPrivileges = TRUE;
159 foreach ($grants as $current_grant) {
160 if ((!empty($row) && isset($row[$current_grant[0]]))
161 ||
(empty($row) && isset($GLOBALS[$current_grant[0]]))) {
162 if ((!empty($row) && $row[$current_grant[0]] == 'Y')
164 && ($GLOBALS[$current_grant[0]] == 'Y'
165 ||
(is_array($GLOBALS[$current_grant[0]])
166 && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count']
167 && empty($GLOBALS[$current_grant[0] . '_none'])))))
170 $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
172 $privs[] = $current_grant[1];
174 } elseif (!empty($GLOBALS[$current_grant[0]])
175 && is_array($GLOBALS[$current_grant[0]])
176 && empty($GLOBALS[$current_grant[0] . '_none'])) {
178 $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
180 $priv_string = $current_grant[1];
182 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
184 $allPrivileges = FALSE;
190 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
194 } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) ||
count($privs) == $GLOBALS['grant_count'])) {
196 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
198 $privs = array('ALL PRIVILEGES');
202 } // end of the 'PMA_extractPrivInfo()' function
205 * Displays on which column(s) a table-specific privilege is granted
207 function PMA_display_column_privs($columns, $row, $name_for_select,
208 $priv_for_header, $name, $name_for_dfn, $name_for_current)
210 echo ' <div class="item" id="div_item_' . $name . '">' . "\n"
211 . ' <label for="select_' . $name . '_priv">' . "\n"
212 . ' <tt><dfn title="' . $name_for_dfn . '">'
213 . $priv_for_header . '</dfn></tt>' . "\n"
214 . ' </label><br />' . "\n"
215 . ' <select id="select_' . $name . '_priv" name="'
216 . $name_for_select . '[]" multiple="multiple" size="8">' . "\n";
218 foreach ($columns as $current_column => $current_column_privileges) {
219 echo ' <option value="' . htmlspecialchars($current_column) . '"';
220 if ($row[$name_for_select] == 'Y' ||
$current_column_privileges[$name_for_current]) {
221 echo ' selected="selected"';
223 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
226 echo ' </select>' . "\n"
227 . ' <i>' . $GLOBALS['strOr'] . '</i>' . "\n"
228 . ' <label for="checkbox_' . $name_for_select
229 . '_none"><input type="checkbox"'
230 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
231 . ' name="' . $name_for_select . '_none" id="checkbox_'
232 . $name_for_select . '_none" title="' . $GLOBALS['strNone'] . '" />'
233 . $GLOBALS['strNone'] . '</label>' . "\n"
239 * Displays the privileges form table
241 * @param string $db the database
242 * @param string $table the table
243 * @param boolean $submit wheather to display the submit button or not
244 * @global array $cfg the phpMyAdmin configuration
245 * @global ressource $user_link the database connection
249 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE)
255 if (isset($GLOBALS['username'])) {
256 $username = $GLOBALS['username'];
257 $hostname = $GLOBALS['hostname'];
260 "SELECT * FROM `mysql`.`user`"
261 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
262 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
263 } elseif ($table == '*') {
265 "SELECT * FROM `mysql`.`db`"
266 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
267 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
268 ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"
272 "SELECT `Table_priv`"
273 ." FROM `mysql`.`tables_priv`"
274 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
275 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
276 ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'"
277 ." AND `Table_name` = '" . PMA_sqlAddslashes($table) . "';";
279 $row = PMA_DBI_fetch_single_row($sql_query);
284 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
285 } elseif ($table == '*') {
286 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
288 $res = PMA_DBI_query($sql_query);
289 while ($row1 = PMA_DBI_fetch_row($res)) {
290 if (substr($row1[0], 0, 4) == 'max_') {
293 $row[$row1[0]] = 'N';
296 PMA_DBI_free_result($res);
298 $row = array('Table_priv' => '');
301 if (isset($row['Table_priv'])) {
302 $row1 = PMA_DBI_fetch_single_row(
303 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
304 'ASSOC', $GLOBALS['userlink']);
305 // note: in MySQL 5.0.3 we get "Create View', 'Show view';
306 // the View for Create is spelled with uppercase V
307 // the view for Show is spelled with lowercase v
308 // and there is a space between the words
310 $av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') +
2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
312 $users_grants = explode(',', $row['Table_priv']);
314 foreach ($av_grants as $current_grant) {
315 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ?
'Y' : 'N';
317 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
320 $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards($db) . '`.`' . $table . '`;');
323 while ($row1 = PMA_DBI_fetch_row($res)) {
324 $columns[$row1[0]] = array(
328 'References' => FALSE
331 PMA_DBI_free_result($res);
335 // t a b l e - s p e c i f i c p r i v i l e g e s
336 if (! empty($columns)) {
337 $res = PMA_DBI_query(
338 'SELECT `Column_name`, `Column_priv`'
339 .' FROM `mysql`.`columns_priv`'
341 .' = \'' . PMA_sqlAddslashes($username) . "'"
343 .' = \'' . PMA_sqlAddslashes($hostname) . "'"
345 .' = \'' . PMA_unescape_mysql_wildcards($db) . "'"
347 .' = \'' . PMA_sqlAddslashes($table) . '\';');
349 while ($row1 = PMA_DBI_fetch_row($res)) {
350 $row1[1] = explode(',', $row1[1]);
351 foreach ($row1[1] as $current) {
352 $columns[$row1[0]][$current] = TRUE;
355 PMA_DBI_free_result($res);
356 unset($res, $row1, $current);
358 echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
359 . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
360 . '<fieldset id="fieldset_user_priv">' . "\n"
361 . ' <legend>' . $GLOBALS['strTblPrivileges']
362 . PMA_showHint($GLOBALS['strEnglishPrivileges'])
363 . '</legend>' . "\n";
367 // privs that are attached to a specific column
368 PMA_display_column_privs($columns, $row, 'Select_priv',
369 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select');
371 PMA_display_column_privs($columns, $row, 'Insert_priv',
372 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert');
374 PMA_display_column_privs($columns, $row, 'Update_priv',
375 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update');
377 PMA_display_column_privs($columns, $row, 'References_priv',
378 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References');
380 // privs that are not attached to a specific column
382 echo ' <div class="item">' . "\n";
383 foreach ($row as $current_grant => $current_grant_value) {
384 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)),
385 array('Select', 'Insert', 'Update', 'References'))) {
388 // make a substitution to match the messages variables;
389 // also we must substitute the grant we get, because we can't generate
390 // a form variable containing blanks (those would get changed to
391 // an underscore when receiving the POST)
392 if ($current_grant == 'Create View_priv') {
393 $tmp_current_grant = 'CreateView_priv';
394 $current_grant = 'Create_view_priv';
395 } elseif ($current_grant == 'Show view_priv') {
396 $tmp_current_grant = 'ShowView_priv';
397 $current_grant = 'Show_view_priv';
399 $tmp_current_grant = $current_grant;
402 echo ' <div class="item">' . "\n"
403 . ' <input type="checkbox"'
404 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
405 . ' name="' . $current_grant . '" id="checkbox_' . $current_grant
407 . ($current_grant_value == 'Y' ?
'checked="checked" ' : '')
410 echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
411 ?
$GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
412 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";
414 echo ' <label for="checkbox_' . $current_grant
415 . '"><tt><dfn title="'
416 . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
417 ?
$GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
418 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl'])
419 . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n"
423 echo ' </div>' . "\n";
425 echo ' <div class="clearfloat"></div>' . "\n";
429 // g l o b a l o r d b - s p e c i f i c
432 $privTable[0] = array(
433 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
434 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
435 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
436 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
439 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
443 $privTable[1] = array(
444 array('Create', 'CREATE', ($table == '*' ?
$GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
445 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
446 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
447 array('Drop', 'DROP', ($table == '*' ?
$GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl'])),
448 array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
449 array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
450 array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
451 array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
452 array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
454 // this one is for a db-specific priv: Create_view_priv
455 if (isset($row['Create_view_priv'])) {
456 $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
458 // this one is for a table-specific priv: Create View_priv
459 if (isset($row['Create View_priv'])) {
460 $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
462 if (isset($row['Event_priv'])) {
464 $privTable[1][] = array('Event', 'EVENT', $GLOBALS['strPrivDescEvent']);
465 $privTable[1][] = array('Trigger', 'TRIGGER', $GLOBALS['strPrivDescTrigger']);
468 // a d m i n i s t r a t i o n
469 $privTable[2] = array(
470 array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']),
473 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
474 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess']);
475 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
476 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
477 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
479 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
480 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
482 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
483 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
484 $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']);
486 echo '<input type="hidden" name="grant_count" value="'
487 . (count($privTable[0]) +
count($privTable[1]) +
count($privTable[2]) - (isset($row['Grant_priv']) ?
1 : 0))
489 . '<fieldset id="fieldset_user_global_rights">' . "\n"
493 ?
$GLOBALS['strGlobalPrivileges']
495 ?
$GLOBALS['strDbPrivileges']
496 : $GLOBALS['strTblPrivileges'])) . "\n"
497 . ' (<a href="server_privileges.php?'
498 . $GLOBALS['url_query'] . '&checkall=1" onclick="setCheckboxes(\'usersForm\', true); return false;">'
499 . $GLOBALS['strCheckAll'] . '</a> /' . "\n"
500 . ' <a href="server_privileges.php?'
501 . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'usersForm\', false); return false;">'
502 . $GLOBALS['strUncheckAll'] . '</a>)' . "\n"
503 . ' </legend>' . "\n"
504 . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n"
505 . ' <fieldset>' . "\n"
506 . ' <legend>' . $GLOBALS['strData'] . '</legend>' . "\n";
507 foreach ($privTable[0] as $priv)
509 echo ' <div class="item">' . "\n"
510 . ' <input type="checkbox"'
511 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
512 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
513 . '_priv" value="Y" '
514 . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '')
515 . 'title="' . $priv[2] . '"/>' . "\n"
516 . ' <label for="checkbox_' . $priv[0]
517 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
518 . '</dfn></tt></label>' . "\n"
521 echo ' </fieldset>' . "\n"
522 . ' <fieldset>' . "\n"
523 . ' <legend>' . $GLOBALS['strStructure'] . '</legend>' . "\n";
524 foreach ($privTable[1] as $priv)
526 echo ' <div class="item">' . "\n"
527 . ' <input type="checkbox"'
528 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
529 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
530 . '_priv" value="Y" '
531 . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '')
532 . 'title="' . $priv[2] . '"/>' . "\n"
533 . ' <label for="checkbox_' . $priv[0]
534 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
535 . '</dfn></tt></label>' . "\n"
538 echo ' </fieldset>' . "\n"
539 . ' <fieldset>' . "\n"
540 . ' <legend>' . $GLOBALS['strAdministration'] . '</legend>' . "\n";
541 foreach ($privTable[2] as $priv)
543 echo ' <div class="item">' . "\n"
544 . ' <input type="checkbox"'
545 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
546 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
547 . '_priv" value="Y" '
548 . ($row[$priv[0] . '_priv'] == 'Y' ?
'checked="checked" ' : '')
549 . 'title="' . $priv[2] . '"/>' . "\n"
550 . ' <label for="checkbox_' . $priv[0]
551 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
552 . '</dfn></tt></label>' . "\n"
556 echo ' </fieldset>' . "\n";
557 // The "Resource limits" box is not displayed for db-specific privs
559 echo ' <fieldset>' . "\n"
560 . ' <legend>' . $GLOBALS['strResourceLimits'] . '</legend>' . "\n"
561 . ' <p><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></p>' . "\n"
562 . ' <div class="item">' . "\n"
563 . ' <label for="text_max_questions"><tt><dfn title="'
564 . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label>' . "\n"
565 . ' <input type="text" name="max_questions" id="text_max_questions" value="'
566 . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" />' . "\n"
568 . ' <div class="item">' . "\n"
569 . ' <label for="text_max_updates"><tt><dfn title="'
570 . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label>' . "\n"
571 . ' <input type="text" name="max_updates" id="text_max_updates" value="'
572 . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" />' . "\n"
574 . ' <div class="item">' . "\n"
575 . ' <label for="text_max_connections"><tt><dfn title="'
576 . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label>' . "\n"
577 . ' <input type="text" name="max_connections" id="text_max_connections" value="'
578 . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" />' . "\n"
580 . ' <div class="item">' . "\n"
581 . ' <label for="text_max_user_connections"><tt><dfn title="'
582 . $GLOBALS['strPrivDescMaxUserConnections'] . '">MAX USER_CONNECTIONS</dfn></tt></label>' . "\n"
583 . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="'
584 . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '" />' . "\n"
586 . ' </fieldset>' . "\n";
589 echo ' <div class="clearfloat"></div>' . "\n";
591 echo '</fieldset>' . "\n";
593 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
594 . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
595 . '</fieldset>' . "\n";
597 } // end of the 'PMA_displayPrivTable()' function
601 * Displays the fields used by the "new user" form as well as the
602 * "change login information / copy user" form.
604 * @param string $mode are we creating a new user or are we just
605 * changing one? (allowed values: 'new', 'change')
606 * @global array $cfg the phpMyAdmin configuration
607 * @global ressource $user_link the database connection
611 function PMA_displayLoginInformationFields($mode = 'new')
613 // Get user/host name lengths
614 $fields_info = PMA_DBI_get_fields('mysql', 'user');
615 $username_length = 16;
616 $hostname_length = 41;
617 foreach ($fields_info as $key => $val) {
618 if ($val['Field'] == 'User') {
619 strtok($val['Type'], '()');
622 $username_length = $v;
624 } elseif ($val['Field'] == 'Host') {
625 strtok($val['Type'], '()');
628 $hostname_length = $v;
634 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
635 $GLOBALS['pred_username'] = 'any';
637 echo '<fieldset id="fieldset_add_user_login">' . "\n"
638 . '<legend>' . $GLOBALS['strLoginInformation'] . '</legend>' . "\n"
639 . '<div class="item">' . "\n"
640 . '<label for="select_pred_username">' . "\n"
641 . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
643 . '<span class="options">' . "\n"
644 . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
645 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
646 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
647 . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) ||
$GLOBALS['pred_username'] == 'userdefined') ?
' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
648 . ' </select>' . "\n"
650 . '<input type="text" name="username" maxlength="'
651 . $username_length . '" title="' . $GLOBALS['strUserName'] . '"'
652 . (empty($GLOBALS['username'])
654 : ' value="' . (isset($GLOBALS['new_username'])
655 ?
$GLOBALS['new_username']
656 : $GLOBALS['username']) . '"')
657 . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
659 . '<div class="item">' . "\n"
660 . '<label for="select_pred_hostname">' . "\n"
661 . ' ' . $GLOBALS['strHost'] . ':' . "\n"
663 . '<span class="options">' . "\n"
664 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
665 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
666 if (! empty($_current_user)) {
667 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') +
1)));
668 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
672 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
673 . (empty($thishost) ?
'' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
674 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
675 unset($_current_user);
677 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
678 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
679 switch (strtolower($GLOBALS['hostname'])) {
682 $GLOBALS['pred_hostname'] = 'localhost';
685 $GLOBALS['pred_hostname'] = 'any';
688 $GLOBALS['pred_hostname'] = 'userdefined';
692 echo ' <option value="any"'
693 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
694 ?
' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost']
696 . ' <option value="localhost"'
697 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
698 ?
' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost']
699 . '</option>' . "\n";
700 if (!empty($thishost)) {
701 echo ' <option value="thishost"'
702 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
703 ?
' selected="selected"' : '') . '>' . $GLOBALS['strThisHost']
704 . '</option>' . "\n";
707 echo ' <option value="hosttable"'
708 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
709 ?
' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable']
711 . ' <option value="userdefined"'
712 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
713 ?
' selected="selected"' : '')
714 . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
715 . ' </select>' . "\n"
717 . '<input type="text" name="hostname" maxlength="'
718 . $hostname_length . '" value="'
719 . (isset($GLOBALS['hostname']) ?
$GLOBALS['hostname'] : '')
720 . '" title="' . $GLOBALS['strHost']
721 . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
723 . '<div class="item">' . "\n"
724 . '<label for="select_pred_password">' . "\n"
725 . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
727 . '<span class="options">' . "\n"
728 . ' <select name="pred_password" id="select_pred_password" title="'
729 . $GLOBALS['strPassword'] . '"' . "\n"
730 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
731 . ($mode == 'change' ?
' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
732 . ' <option value="none"';
733 if (isset($GLOBALS['username']) && $mode != 'change') {
734 echo ' selected="selected"';
736 echo '>' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
737 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ?
'' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
738 . ' </select>' . "\n"
740 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
742 . '<div class="item">' . "\n"
743 . '<label for="text_pma_pw2">' . "\n"
744 . ' ' . $GLOBALS['strReType'] . ':' . "\n"
746 . '<span class="options"> </span>' . "\n"
747 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
749 . '<div class="item">' . "\n"
750 . '<label for="button_generate_password">' . "\n"
751 . ' ' . $GLOBALS['strGeneratePassword'] . ':' . "\n"
753 . '<span class="options">' . "\n"
754 . ' <input type="button" id="button_generate_password" value="' . $GLOBALS['strGenerate'] . '" onclick="suggestPassword()" />' . "\n"
755 . ' <input type="button" id="button_copy_password" value="' . $GLOBALS['strCopy'] . '" onclick="suggestPasswordCopy(this.form)" />' . "\n"
757 . '<input type="text" name="generated_pw" id="generated_pw" />' . "\n"
759 . '</fieldset>' . "\n";
760 } // end of the 'PMA_displayUserAndHostFields()' function
764 * Changes / copies a user, part I
766 if (isset($_REQUEST['change_copy'])) {
767 $user_host_condition =
769 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
771 .' = \'' . $old_hostname . '\';';
772 $row = PMA_DBI_fetch_single_row('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
774 PMA_Message
::notice('strNoUsersFound')->display();
775 unset($_REQUEST['change_copy']);
777 extract($row, EXTR_OVERWRITE
);
778 // Recent MySQL versions have the field "Password" in mysql.user,
779 // so the previous extract creates $Password but this script
781 if (!isset($password) && isset($Password)) {
782 $password = $Password;
791 * (Changes / copies a user, part II)
793 if (isset($_REQUEST['adduser_submit']) ||
isset($_REQUEST['change_copy'])) {
795 if ($pred_username == 'any') {
798 switch ($pred_hostname) {
803 $hostname = 'localhost';
809 $_user_name = PMA_DBI_fetch_value('SELECT USER()');
810 $hostname = substr($_user_name, (strrpos($_user_name, '@') +
1));
814 $sql = "SELECT '1' FROM `mysql`.`user`"
815 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
816 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
817 if (PMA_DBI_fetch_value($sql) == 1) {
818 $message = PMA_Message
::error('strUserAlreadyExists');
819 $message->addParam('[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
820 $_REQUEST['adduser'] = true;
823 $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
826 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \''
827 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
828 if ($pred_password != 'none' && $pred_password != 'keep') {
829 $sql_query = $real_sql_query . ' IDENTIFIED BY \'***\'';
830 $real_sql_query .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
831 if (isset($create_user_real)) {
832 $create_user_show = $create_user_real . ' IDENTIFIED BY \'***\'';
833 $create_user_real .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
836 if ($pred_password == 'keep' && !empty($password)) {
837 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
838 if (isset($create_user_real)) {
839 $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
842 $sql_query = $real_sql_query;
843 if (isset($create_user_real)) {
844 $create_user_show = $create_user_real;
848 * @todo similar code appears twice in this script
850 if ((isset($Grant_priv) && $Grant_priv == 'Y')
851 ||
(isset($max_questions) ||
isset($max_connections)
852 ||
isset($max_updates) ||
isset($max_user_connections))) {
853 $real_sql_query .= ' WITH';
854 $sql_query .= ' WITH';
855 if (isset($Grant_priv) && $Grant_priv == 'Y') {
856 $real_sql_query .= ' GRANT OPTION';
857 $sql_query .= ' GRANT OPTION';
859 if (isset($max_questions)) {
860 // avoid negative values
861 $max_questions = max(0, (int)$max_questions);
862 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
863 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
865 if (isset($max_connections)) {
866 $max_connections = max(0, (int)$max_connections);
867 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
868 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
870 if (isset($max_updates)) {
871 $max_updates = max(0, (int)$max_updates);
872 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
873 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
875 if (isset($max_user_connections)) {
876 $max_user_connections = max(0, (int)$max_user_connections);
877 $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
878 $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
881 if (isset($create_user_real)) {
882 $create_user_real .= ';';
883 $create_user_show .= ';';
885 $real_sql_query .= ';';
887 if (empty($_REQUEST['change_copy'])) {
890 if (isset($create_user_real)) {
891 if (! PMA_DBI_try_query($create_user_real)) {
894 $sql_query = $create_user_show . $sql_query;
897 if ($_error ||
! PMA_DBI_try_query($real_sql_query)) {
898 $_REQUEST['createdb'] = false;
899 $message = PMA_Message
::rawError(PMA_DBI_getError());
901 $message = PMA_Message
::success('strAddUserMessage');
904 switch (PMA_ifSetOr($_REQUEST['createdb'], '0')) {
906 $q = 'CREATE DATABASE IF NOT EXISTS '
907 . PMA_backquote(PMA_sqlAddslashes($username)) . ';';
909 if (! PMA_DBI_try_query($q)) {
910 $message = PMA_Message
::rawError(PMA_DBI_getError());
913 $GLOBALS['reload'] = TRUE;
914 PMA_reloadNavigation();
916 $q = 'GRANT ALL PRIVILEGES ON '
917 . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \''
918 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
920 if (! PMA_DBI_try_query($q)) {
921 $message = PMA_Message
::rawError(PMA_DBI_getError());
925 $q = 'GRANT ALL PRIVILEGES ON '
926 . PMA_backquote(PMA_sqlAddslashes($username) . '\_%') . '.* TO \''
927 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
929 if (! PMA_DBI_try_query($q)) {
930 $message = PMA_Message
::rawError(PMA_DBI_getError());
938 if (isset($create_user_real)) {
939 $queries[] = $create_user_real;
941 $queries[] = $real_sql_query;
942 // we put the query containing the hidden password in
943 // $queries_for_display, at the same position occupied
944 // by the real query in $queries
945 $tmp_count = count($queries);
946 if (isset($create_user_real)) {
947 $queries_for_display[$tmp_count - 2] = $create_user_show;
949 $queries_for_display[$tmp_count - 1] = $sql_query;
951 unset($res, $real_sql_query);
957 * Changes / copies a user, part III
959 if (isset($_REQUEST['change_copy'])) {
960 $user_host_condition =
962 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
964 .' = \'' . $old_hostname . '\';';
965 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition);
966 while ($row = PMA_DBI_fetch_assoc($res)) {
968 'GRANT ' . join(', ', PMA_extractPrivInfo($row))
969 .' ON `' . $row['Db'] . '`.*'
970 .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
971 . ($row['Grant_priv'] == 'Y' ?
' WITH GRANT OPTION;' : ';');
973 PMA_DBI_free_result($res);
974 $res = PMA_DBI_query(
975 'SELECT `Db`, `Table_name`, `Table_priv`'
976 .' FROM `mysql`.`tables_priv`' . $user_host_condition,
977 $GLOBALS['userlink'], PMA_DBI_QUERY_STORE
);
978 while ($row = PMA_DBI_fetch_assoc($res)) {
980 $res2 = PMA_DBI_QUERY(
981 'SELECT `Column_name`, `Column_priv`'
982 .' FROM `mysql`.`columns_priv`'
984 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
986 .' = \'' . $old_hostname . '\''
988 .' = \'' . $row['Db'] . "'"
990 .' = \'' . $row['Table_name'] . "'"
992 null, PMA_DBI_QUERY_STORE
);
994 $tmp_privs1 = PMA_extractPrivInfo($row);
999 'References' => array()
1002 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
1003 $tmp_array = explode(',', $row2['Column_priv']);
1004 if (in_array('Select', $tmp_array)) {
1005 $tmp_privs2['Select'][] = $row2['Column_name'];
1007 if (in_array('Insert', $tmp_array)) {
1008 $tmp_privs2['Insert'][] = $row2['Column_name'];
1010 if (in_array('Update', $tmp_array)) {
1011 $tmp_privs2['Update'][] = $row2['Column_name'];
1013 if (in_array('References', $tmp_array)) {
1014 $tmp_privs2['References'][] = $row2['Column_name'];
1018 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
1019 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
1021 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
1022 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
1024 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
1025 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
1027 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
1028 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
1032 'GRANT ' . join(', ', $tmp_privs1)
1033 . ' ON `' . $row['Db'] . '`.`' . $row['Table_name']
1034 . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
1035 . (in_array('Grant', explode(',', $row['Table_priv'])) ?
' WITH GRANT OPTION;' : ';');
1041 * Updates privileges
1043 if (!empty($update_privs)) {
1044 // escaping a wildcard character in a GRANT is only accepted at the global
1045 // or database level, not at table level; this is why I remove
1046 // the escaping character
1047 // Note: in the phpMyAdmin list of Database-specific privileges,
1048 // we will have for example
1049 // test\_db SELECT (this one is for privileges on a db level)
1050 // test_db USAGE (this one is for table-specific privileges)
1052 // It looks curious but reflects the way MySQL works
1055 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1056 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1057 if (!isset($Grant_priv) ||
$Grant_priv != 'Y') {
1059 'REVOKE GRANT OPTION ON ' . $db_and_table
1060 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1065 'GRANT ' . join(', ', PMA_extractPrivInfo())
1066 . ' ON ' . $db_and_table
1067 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
1070 * @todo similar code appears twice in this script
1072 if ((isset($Grant_priv) && $Grant_priv == 'Y')
1073 ||
(! isset($dbname)
1074 && (isset($max_questions) ||
isset($max_connections)
1075 ||
isset($max_updates) ||
isset($max_user_connections))))
1077 $sql_query2 .= 'WITH';
1078 if (isset($Grant_priv) && $Grant_priv == 'Y') {
1079 $sql_query2 .= ' GRANT OPTION';
1081 if (isset($max_questions)) {
1082 $max_questions = max(0, (int)$max_questions);
1083 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
1085 if (isset($max_connections)) {
1086 $max_connections = max(0, (int)$max_connections);
1087 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
1089 if (isset($max_updates)) {
1090 $max_updates = max(0, (int)$max_updates);
1091 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
1093 if (isset($max_user_connections)) {
1094 $max_user_connections = max(0, (int)$max_user_connections);
1095 $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
1099 if (!PMA_DBI_try_query($sql_query0)) {
1100 // this query may fail, but this does not matter :o)
1101 // a case when it can fail is when the admin does not have all
1102 // privileges: he can't do a REVOKE ALL PRIVILEGES !
1103 // so at least we display the error
1104 echo PMA_DBI_getError();
1107 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) {
1108 // this one may fail, too...
1111 PMA_DBI_query($sql_query2);
1112 $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2;
1113 $message = PMA_Message
::success('strUpdatePrivMessage');
1114 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1119 * Revokes Privileges
1121 if (isset($_REQUEST['revokeall'])) {
1124 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1125 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1127 'REVOKE GRANT OPTION ON ' . $db_and_table
1128 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1129 PMA_DBI_query($sql_query0);
1130 if (!PMA_DBI_try_query($sql_query1)) {
1131 // this one may fail, too...
1134 $sql_query = $sql_query0 . ' ' . $sql_query1;
1135 $message = PMA_Message
::success('strRevokeMessage');
1136 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1137 if (! isset($tablename)) {
1146 * Updates the password
1148 if (isset($_REQUEST['change_pw'])) {
1149 // similar logic in user_password.php
1152 if ($nopass == 0 && isset($pma_pw) && isset($pma_pw2)) {
1153 if ($pma_pw != $pma_pw2) {
1154 $message = PMA_Message
::error('strPasswordNotSame');
1155 } elseif (empty($pma_pw) ||
empty($pma_pw2)) {
1156 $message = PMA_Message
::error('strPasswordEmpty');
1160 // here $nopass could be == 1
1161 if (empty($message)) {
1163 $hashing_function = (!empty($pw_hash) && $pw_hash == 'old' ?
'OLD_' : '')
1166 // in $sql_query which will be displayed, hide the password
1167 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ?
'\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')');
1168 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ?
'\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($pma_pw) . '\')');
1169 PMA_DBI_try_query($local_query)
1170 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, FALSE, $err_url);
1171 $message = PMA_Message
::success('strPasswordChanged');
1172 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1179 * (Changes / copies a user, part IV)
1181 $user_host_separator = chr(27);
1183 if (isset($_REQUEST['delete']) ||
(isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4)) {
1184 if (isset($_REQUEST['change_copy'])) {
1185 $selected_usr = array($old_username . $user_host_separator . $old_hostname);
1187 $selected_usr = $_REQUEST['selected_usr'];
1190 foreach ($selected_usr as $each_user) {
1191 list($this_user, $this_host) = explode($user_host_separator, $each_user);
1192 $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
1193 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1195 if (isset($_REQUEST['drop_users_db'])) {
1196 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
1197 $GLOBALS['reload'] = TRUE;
1198 PMA_reloadNavigation();
1201 if (empty($_REQUEST['change_copy'])) {
1202 if (empty($queries)) {
1203 $message = PMA_Message
::error('strDeleteNoUsersSelected');
1205 if ($_REQUEST['mode'] == 3) {
1206 $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
1207 $queries[] = 'FLUSH PRIVILEGES;';
1209 $drop_user_error = '';
1210 foreach ($queries as $sql_query) {
1211 if ($sql_query{0} != '#') {
1212 if (! PMA_DBI_try_query($sql_query, $GLOBALS['userlink'])) {
1213 $drop_user_error .= PMA_DBI_getError() . "\n";
1217 $sql_query = join("\n", $queries);
1218 if (! empty($drop_user_error)) {
1219 $message = PMA_Message
::rawError($drop_user_error);
1221 $message = PMA_Message
::success('strUsersDeleted');
1230 * Changes / copies a user, part V
1232 if (isset($_REQUEST['change_copy'])) {
1234 foreach ($queries as $sql_query) {
1235 if ($sql_query{0} != '#') {
1236 PMA_DBI_query($sql_query);
1238 // when there is a query containing a hidden password, take it
1239 // instead of the real query sent
1240 if (isset($queries_for_display[$tmp_count])) {
1241 $queries[$tmp_count] = $queries_for_display[$tmp_count];
1245 $message = PMA_Message
::success();
1246 $sql_query = join("\n", $queries);
1251 * Reloads the privilege tables into memory
1253 if (isset($_REQUEST['flush_privileges'])) {
1254 $sql_query = 'FLUSH PRIVILEGES;';
1255 PMA_DBI_query($sql_query);
1256 $message = PMA_Message
::success('strPrivilegesReloaded');
1261 * Displays the links
1263 if (isset($viewing_mode) && $viewing_mode == 'db') {
1265 $url_query .= '&goto=db_operations.php';
1267 // Gets the database structure
1268 $sub_part = '_structure';
1269 require './libraries/db_info.inc.php';
1272 require './libraries/server_links.inc.php';
1277 * defines some standard links
1279 $link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1280 . '&username=%s'
1281 . '&hostname=%s'
1283 . '&tablename=%s">'
1284 . PMA_getIcon('b_usredit.png', $GLOBALS['strEditPrivileges'])
1287 $link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1288 . '&username=%s'
1289 . '&hostname=%s'
1291 . '&tablename=%s'
1292 . '&revokeall=1">'
1293 . PMA_getIcon('b_usrdrop.png', $GLOBALS['strRevoke'])
1299 if (empty($_REQUEST['adduser']) && (! isset($checkprivs) ||
! strlen($checkprivs))) {
1300 if (! isset($username)) {
1301 // No username is given --> display the overview
1303 . PMA_getIcon('b_usrlist.png')
1304 . $GLOBALS['strUserOverview'] . "\n"
1309 " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" .
1310 ' 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 PMA_Message
::error('strNoPrivileges')->display();
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 $raw = 'Your privilege table structure seems to be older than'
1334 . ' this MySQL version!<br />'
1335 . 'Please run the script <tt>mysql_fix_privilege_tables</tt>'
1336 . ' that should be included in your MySQL server distribution'
1337 . ' to solve this problem!';
1338 PMA_Message
::rawError($raw)->display();
1342 // we also want users not in table `user` but in other table
1343 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1345 $tables_to_search_for_users = array(
1346 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',
1349 $db_rights_sqls = array();
1350 foreach ($tables_to_search_for_users as $table_search_in) {
1351 if (in_array($table_search_in, $tables)) {
1352 $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ?
PMA_RangeOfUsers($initial) : '');
1356 $user_defaults = array(
1360 'Grant_priv' => 'N',
1361 'privs' => array('USAGE'),
1364 // for all initials, even non A-Z
1365 $array_initials = array();
1367 $db_rights = array();
1369 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1370 .' ORDER BY `User` ASC, `Host` ASC';
1372 $db_rights_result = PMA_DBI_query($db_rights_sql);
1374 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1375 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1376 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1379 PMA_DBI_free_result($db_rights_result);
1380 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1384 * Displays the initials
1387 // initialize to FALSE the letters A-Z
1388 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++
) {
1389 if (! isset($array_initials[chr($letter_counter +
64)])) {
1390 $array_initials[chr($letter_counter +
64)] = FALSE;
1394 $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE
);
1395 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1396 $array_initials[$tmp_initial] = TRUE;
1399 // Display the initials, which can be any characters, not
1400 // just letters. For letters A-Z, we add the non-used letters
1403 uksort($array_initials, "strnatcasecmp");
1405 echo '<table cellspacing="5"><tr>';
1406 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1407 if ($initial_was_found) {
1408 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a></td>' . "\n";
1410 echo '<td>' . $tmp_initial . '</td>';
1413 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&showall=1">[' . $GLOBALS['strShowAll'] . ']</a></td>' . "\n";
1414 echo '</tr></table>';
1417 * Display the user overview
1418 * (if less than 50 users, display them immediately)
1421 if (isset($initial) ||
isset($showall) ||
PMA_DBI_num_rows($res) < 50) {
1423 while ($row = PMA_DBI_fetch_assoc($res)) {
1424 $row['privs'] = PMA_extractPrivInfo($row, true);
1425 $db_rights[$row['User']][$row['Host']] = $row;
1427 @PMA_DBI_free_result
($res);
1430 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1431 . PMA_generate_common_hidden_inputs('', '')
1432 . ' <table id="tableuserrights" class="data">' . "\n"
1434 . ' <tr><td></td>' . "\n"
1435 . ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1436 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1437 . ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n"
1438 . ' <th>' . $GLOBALS['strGlobalPrivileges'] . ' '
1439 . PMA_showHint($GLOBALS['strEnglishPrivileges']) . '</th>' . "\n"
1440 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1441 . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ?
'<td></td>' : '<th>' . $GLOBALS['strAction'] . '</th>') . "\n";
1442 echo ' </tr>' . "\n";
1443 echo ' </thead>' . "\n";
1444 echo ' <tbody>' . "\n";
1446 $index_checkbox = -1;
1447 foreach ($db_rights as $user) {
1450 foreach ($user as $host) {
1452 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
1453 . ' <td><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_'
1454 . $index_checkbox . '" value="'
1455 . str_replace(chr(27), '', htmlspecialchars($host['User'] . $user_host_separator . $host['Host']))
1457 . (empty($GLOBALS['checkall']) ?
'' : ' checked="checked"')
1459 . ' <td><label for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ?
'<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n"
1460 . ' <td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
1462 switch ($host['Password']) {
1464 echo $GLOBALS['strYes'];
1467 echo '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>';
1469 // this happens if this is a definition not coming from mysql.user
1471 echo '--'; // in future version, replace by "not present"
1475 . ' <td><tt>' . "\n"
1476 . ' ' . implode(',' . "\n" . ' ', $host['privs']) . "\n"
1477 . ' </tt></td>' . "\n"
1478 . ' <td>' . ($host['Grant_priv'] == 'Y' ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1479 . ' <td align="center">';
1480 printf($link_edit, urlencode($host['User']),
1481 urlencode($host['Host']), '', '');
1484 $odd_row = ! $odd_row;
1488 unset($user, $host, $odd_row);
1489 echo ' </tbody></table>' . "\n"
1490 .'<img class="selectallarrow"'
1491 .' src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
1492 .' width="38" height="22"'
1493 .' alt="' . $GLOBALS['strWithChecked'] . '" />' . "\n"
1494 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&checkall=1"'
1495 .' onclick="if (markAllRows(\'usersForm\')) return false;">'
1496 . $GLOBALS['strCheckAll'] . '</a>' . "\n"
1498 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '"'
1499 .' onclick="if (unMarkAllRows(\'usersForm\')) return false;">'
1500 . $GLOBALS['strUncheckAll'] . '</a>' . "\n";
1502 // add/delete user fieldset
1503 echo ' <fieldset id="fieldset_add_user">' . "\n"
1504 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&adduser=1">' . "\n"
1505 . PMA_getIcon('b_usradd.png')
1506 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1507 . ' </fieldset>' . "\n"
1508 . ' <fieldset id="fieldset_delete_user">'
1509 . ' <legend>' . "\n"
1510 . PMA_getIcon('b_usrdrop.png')
1511 . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n"
1512 . ' </legend>' . "\n"
1513 . ' <input type="hidden" name="mode" value="2" />' . "\n"
1514 . '(' . $GLOBALS['strRevokeAndDelete'] . ')<br />' . "\n"
1515 . ' <input type="checkbox" title="' . $GLOBALS['strDropUsersDb'] . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
1516 . ' <label for="checkbox_drop_users_db" title="' . $GLOBALS['strDropUsersDb'] . '">' . "\n"
1517 . ' ' . $GLOBALS['strDropUsersDb'] . "\n"
1518 . ' </label>' . "\n"
1519 . ' </fieldset>' . "\n"
1520 . ' <fieldset id="fieldset_delete_user_footer" class="tblFooters">' . "\n"
1521 . ' <input type="submit" name="delete" value="' . $GLOBALS['strGo'] . '" id="buttonGo" />' . "\n"
1522 . ' </fieldset>' . "\n";
1526 echo ' <fieldset id="fieldset_add_user">' . "\n"
1527 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&adduser=1">' . "\n"
1528 . PMA_getIcon('b_usradd.png')
1529 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1530 . ' </fieldset>' . "\n";
1531 } // end if (display overview)
1532 echo '</form>' . "\n";
1533 $flushnote = new PMA_Message('strFlushPrivilegesNote', PMA_Message
::NOTICE
);
1534 $flushnote->addParam('<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&flush_privileges=1">', false);
1535 $flushnote->addParam('</a>', false);
1536 $flushnote->display();
1542 // A user was selected -> display the user's properties
1545 . PMA_getIcon('b_usredit.png')
1546 . $GLOBALS['strUser'] . ' <i><a href="server_privileges.php?'
1547 . $GLOBALS['url_query'] . '&username=' . urlencode($username)
1548 . '&hostname=' . urlencode($hostname) . '">\''
1549 . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1550 . '\'</a></i>' . "\n";
1551 if (isset($dbname)) {
1552 if ($dbname_is_wildcard) {
1553 echo ' - ' . $GLOBALS['strDatabases'];
1555 echo ' - ' . $GLOBALS['strDatabase'];
1557 $url_dbname = urlencode(str_replace('\_', '_', $dbname));
1558 echo ' <i><a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?'
1559 . $GLOBALS['url_query'] . '&db=' . $url_dbname . '&reload=1">'
1560 . htmlspecialchars($dbname) . '</a></i>' . "\n";
1561 if (isset($tablename)) {
1562 echo ' - ' . $GLOBALS['strTable'] . ' <i><a href="'
1563 . $GLOBALS['cfg']['DefaultTabTable'] . '?' . $GLOBALS['url_query']
1564 . '&db=' . $url_dbname . '&table=' . urlencode($tablename)
1565 . '&reload=1">' . htmlspecialchars($tablename) . '</a></i>'
1570 echo ' : ' . $GLOBALS['strEditPrivileges'] . '</h2>' . "\n";
1572 $sql = "SELECT '1' FROM `mysql`.`user`"
1573 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
1574 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
1575 $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql);
1577 if ($user_does_not_exists) {
1578 PMA_Message
::warning('strUserNotFound')->display();
1579 PMA_displayLoginInformationFields();
1580 //require_once './libraries/footer.inc.php';
1583 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n";
1585 'username' => $username,
1586 'hostname' => $hostname,
1588 if (isset($dbname)) {
1589 $_params['dbname'] = $dbname;
1590 if (isset($tablename)) {
1591 $_params['tablename'] = $tablename;
1594 echo PMA_generate_common_hidden_inputs($_params);
1596 PMA_displayPrivTable(PMA_ifSetOr($dbname, '*', 'length'),
1597 PMA_ifSetOr($tablename, '*', 'length'));
1599 echo '</form>' . "\n";
1601 if (! isset($tablename) && empty($dbname_is_wildcard)) {
1603 // no table name was given, display all table specific rights
1604 // but only if $dbname contains no wildcards
1607 echo '<form action="server_privileges.php" method="post">' . "\n"
1608 . PMA_generate_common_hidden_inputs('', '')
1609 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1610 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1611 . '<fieldset>' . "\n"
1612 . '<legend>' . (! isset($dbname) ?
$GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '</legend>' . "\n"
1613 . '<table class="data">' . "\n"
1615 . '<tr><th>' . (! isset($dbname) ?
$GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '</th>' . "\n"
1616 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1617 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1618 . ' <th>' . (! isset($dbname) ?
$GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '</th>' . "\n"
1619 . ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>' . "\n"
1624 $user_host_condition =
1626 . ' = \'' . PMA_sqlAddslashes($username) . "'"
1628 . ' = \'' . PMA_sqlAddslashes($hostname) . "'";
1633 // we also want privielgs for this user not in table `db` but in other table
1634 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1635 if (! isset($dbname)) {
1637 // no db name given, so we want all privs for the given user
1639 $tables_to_search_for_users = array(
1640 'tables_priv', 'columns_priv',
1643 $db_rights_sqls = array();
1644 foreach ($tables_to_search_for_users as $table_search_in) {
1645 if (in_array($table_search_in, $tables)) {
1646 $db_rights_sqls[] = '
1647 SELECT DISTINCT `Db`
1648 FROM `mysql`.`' . $table_search_in . '`
1649 ' . $user_host_condition;
1653 $user_defaults = array(
1655 'Grant_priv' => 'N',
1656 'privs' => array('USAGE'),
1657 'Table_privs' => true,
1661 $db_rights = array();
1663 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1664 .' ORDER BY `Db` ASC';
1666 $db_rights_result = PMA_DBI_query($db_rights_sql);
1668 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1669 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1670 // only Db names in the table `mysql`.`db` uses wildcards
1671 // as we are in the db specific rights display we want
1672 // all db names escaped, also from other sources
1673 $db_rights_row['Db'] = PMA_escape_mysql_wildcards(
1674 $db_rights_row['Db']);
1675 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1678 PMA_DBI_free_result($db_rights_result);
1679 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1681 $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC';
1682 $res = PMA_DBI_query($sql_query);
1685 while ($row = PMA_DBI_fetch_assoc($res)) {
1686 if (isset($db_rights[$row['Db']])) {
1687 $db_rights[$row['Db']] = array_merge($db_rights[$row['Db']], $row);
1689 $db_rights[$row['Db']] = $row;
1691 // there are db specific rights for this user
1692 // so we can drop this db rights
1693 $db_rights[$row['Db']]['can_delete'] = true;
1695 PMA_DBI_free_result($res);
1700 // db name was given,
1701 // so we want all user specific rights for this db
1703 $user_host_condition .=
1705 .' LIKE \'' . $dbname . "'";
1707 $tables_to_search_for_users = array(
1711 $db_rights_sqls = array();
1712 foreach ($tables_to_search_for_users as $table_search_in) {
1713 if (in_array($table_search_in, $tables)) {
1714 $db_rights_sqls[] = '
1715 SELECT DISTINCT `Table_name`
1716 FROM `mysql`.`' . $table_search_in . '`
1717 ' . $user_host_condition;
1721 $user_defaults = array(
1723 'Grant_priv' => 'N',
1724 'privs' => array('USAGE'),
1725 'Column_priv' => true,
1729 $db_rights = array();
1731 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1732 .' ORDER BY `Table_name` ASC';
1734 $db_rights_result = PMA_DBI_query($db_rights_sql);
1736 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1737 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1738 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1740 PMA_DBI_free_result($db_rights_result);
1741 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1744 'SELECT `Table_name`,'
1746 .' IF(`Column_priv` = _latin1 \'\', 0, 1)'
1747 .' AS \'Column_priv\''
1748 .' FROM `mysql`.`tables_priv`'
1749 . $user_host_condition
1750 .' ORDER BY `Table_name` ASC;';
1751 $res = PMA_DBI_query($sql_query);
1754 while ($row = PMA_DBI_fetch_assoc($res)) {
1755 if (isset($db_rights[$row['Table_name']])) {
1756 $db_rights[$row['Table_name']] = array_merge($db_rights[$row['Table_name']], $row);
1758 $db_rights[$row['Table_name']] = $row;
1761 PMA_DBI_free_result($res);
1767 if (count($db_rights) < 1) {
1768 echo '<tr class="odd">' . "\n"
1769 . ' <td colspan="6"><center><i>' . $GLOBALS['strNone'] . '</i></center></td>' . "\n"
1773 $found_rows = array();
1774 //while ($row = PMA_DBI_fetch_assoc($res)) {
1775 foreach ($db_rights as $row) {
1776 $found_rows[] = (! isset($dbname)) ?
$row['Db'] : $row['Table_name'];
1778 echo '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
1779 . ' <td>' . htmlspecialchars((! isset($dbname)) ?
$row['Db'] : $row['Table_name']) . '</td>' . "\n"
1780 . ' <td><tt>' . "\n"
1781 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1782 . ' </tt></td>' . "\n"
1783 . ' <td>' . ((((! isset($dbname)) && $row['Grant_priv'] == 'Y') ||
(isset($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1785 if (! empty($row['Table_privs']) ||
! empty ($row['Column_priv'])) {
1786 echo $GLOBALS['strYes'];
1788 echo $GLOBALS['strNo'];
1792 printf($link_edit, urlencode($username),
1793 urlencode($hostname),
1794 urlencode((! isset($dbname)) ?
$row['Db'] : $dbname),
1795 urlencode((! isset($dbname)) ?
'' : $row['Table_name']));
1798 if (! empty($row['can_delete']) ||
isset($row['Table_name']) && strlen($row['Table_name'])) {
1799 printf($link_revoke, urlencode($username),
1800 urlencode($hostname),
1801 urlencode((! isset($dbname)) ?
$row['Db'] : $dbname),
1802 urlencode((! isset($dbname)) ?
'' : $row['Table_name']));
1806 $odd_row = ! $odd_row;
1810 echo '</tbody>' . "\n"
1811 . '</table>' . "\n";
1813 if (! isset($dbname)) {
1815 // no database name was give, display select db
1817 if (! empty($found_rows)) {
1818 $pred_db_array = array_diff(
1819 PMA_DBI_fetch_result('SHOW DATABASES;'),
1822 $pred_db_array =PMA_DBI_fetch_result('SHOW DATABASES;');
1825 echo ' <label for="text_dbname">' . $GLOBALS['strAddPrivilegesOnDb'] . ':</label>' . "\n";
1826 if (!empty($pred_db_array)) {
1827 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1828 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1829 foreach ($pred_db_array as $current_db) {
1830 $current_db = PMA_escape_mysql_wildcards($current_db);
1831 echo ' <option value="' . htmlspecialchars($current_db) . '">'
1832 . htmlspecialchars($current_db) . '</option>' . "\n";
1834 echo ' </select>' . "\n";
1836 echo ' <input type="text" id="text_dbname" name="dbname" />' . "\n"
1837 . PMA_showHint($GLOBALS['strEscapeWildcards']);
1839 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1840 . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n";
1841 if ($res = @PMA_DBI_try_query
('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE
)) {
1842 $pred_tbl_array = array();
1843 while ($row = PMA_DBI_fetch_row($res)) {
1844 if (!isset($found_rows) ||
!in_array($row[0], $found_rows)) {
1845 $pred_tbl_array[] = $row[0];
1848 PMA_DBI_free_result($res);
1850 if (!empty($pred_tbl_array)) {
1851 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1852 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1853 foreach ($pred_tbl_array as $current_table) {
1854 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1856 echo ' </select>' . "\n";
1861 echo ' <input type="text" id="text_tablename" name="tablename" />' . "\n";
1863 echo '</fieldset>' . "\n";
1864 echo '<fieldset class="tblFooters">' . "\n"
1865 . ' <input type="submit" value="' . $GLOBALS['strGo'] . '" />'
1866 . '</fieldset>' . "\n"
1870 if (! isset($dbname) && ! $user_does_not_exists) {
1871 require_once './libraries/display_change_password.lib.php';
1873 echo '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1874 . PMA_generate_common_hidden_inputs('', '')
1875 . '<input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1876 . '<input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1877 . '<fieldset id="fieldset_change_copy_user">' . "\n"
1878 . ' <legend>' . $GLOBALS['strChangeCopyUser'] . '</legend>' . "\n";
1879 PMA_displayLoginInformationFields('change');
1880 echo ' <fieldset>' . "\n"
1881 . ' <legend>' . $GLOBALS['strChangeCopyMode'] . '</legend>' . "\n";
1883 '4' => $GLOBALS['strChangeCopyModeCopy'],
1884 '1' => $GLOBALS['strChangeCopyModeJustDelete'],
1885 '2' => $GLOBALS['strChangeCopyModeRevoke'],
1886 '3' => $GLOBALS['strChangeCopyModeDeleteAndReload']);
1887 PMA_generate_html_radio('mode', $choices, '4', true);
1890 echo ' </fieldset>' . "\n"
1891 . '</fieldset>' . "\n"
1892 . '<fieldset id="fieldset_change_copy_user_footer" class="tblFooters">' . "\n"
1893 . ' <input type="submit" name="change_copy" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1894 . '</fieldset>' . "\n"
1898 } elseif (isset($_REQUEST['adduser'])) {
1900 $GLOBALS['url_query'] .= '&adduser=1';
1902 . PMA_getIcon('b_usradd.png') . $GLOBALS['strAddUser'] . "\n"
1904 . '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1905 . PMA_generate_common_hidden_inputs('', '');
1906 PMA_displayLoginInformationFields('new');
1907 echo '<fieldset id="fieldset_add_user_database">' . "\n"
1908 . '<legend>' . $GLOBALS['strCreateUserDatabase'] . '</legend>' . "\n";
1911 '0' => $GLOBALS['strCreateUserDatabaseNone'],
1912 '1' => $GLOBALS['strCreateUserDatabaseName'],
1913 '2' => $GLOBALS['strCreateUserDatabaseWildcard']);
1914 PMA_generate_html_radio('createdb', $choices, '0', true);
1917 echo '</fieldset>' . "\n";
1918 PMA_displayPrivTable('*', '*', FALSE);
1919 echo ' <fieldset id="fieldset_add_user_footer" class="tblFooters">' . "\n"
1920 . ' <input type="submit" name="adduser_submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1921 . ' </fieldset>' . "\n"
1924 // check the privileges for a particular database.
1925 echo '<table id="tablespecificuserrights" class="data">' . "\n"
1926 . '<caption class="tblHeaders">' . "\n"
1927 . PMA_getIcon('b_usrcheck.png')
1928 . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
1929 . '</caption>' . "\n"
1931 . ' <tr><th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1932 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1933 . ' <th>' . $GLOBALS['strType'] . '</th>' . "\n"
1934 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1935 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1936 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n"
1941 unset($row, $row1, $row2);
1943 // now, we build the table...
1944 $list_of_privileges =
1956 . '`References_priv`, '
1957 . '`Create_tmp_table_priv`, '
1958 . '`Lock_tables_priv`, '
1959 . '`Create_view_priv`, '
1960 . '`Show_view_priv`, '
1961 . '`Create_routine_priv`, '
1962 . '`Alter_routine_priv`, '
1965 $list_of_compared_privileges =
1966 '`Select_priv` = \'N\''
1967 . ' AND `Insert_priv` = \'N\''
1968 . ' AND `Update_priv` = \'N\''
1969 . ' AND `Delete_priv` = \'N\''
1970 . ' AND `Create_priv` = \'N\''
1971 . ' AND `Drop_priv` = \'N\''
1972 . ' AND `Grant_priv` = \'N\''
1973 . ' AND `References_priv` = \'N\''
1974 . ' AND `Create_tmp_table_priv` = \'N\''
1975 . ' AND `Lock_tables_priv` = \'N\''
1976 . ' AND `Create_view_priv` = \'N\''
1977 . ' AND `Show_view_priv` = \'N\''
1978 . ' AND `Create_routine_priv` = \'N\''
1979 . ' AND `Alter_routine_priv` = \'N\''
1980 . ' AND `Execute_priv` = \'N\'';
1982 if (PMA_MYSQL_INT_VERSION
>= 50106) {
1983 $list_of_privileges .=
1986 $list_of_compared_privileges .=
1987 ' AND `Event_priv` = \'N\''
1988 . ' AND `Trigger_priv` = \'N\'';
1992 '(SELECT ' . $list_of_privileges . ', `Db`'
1993 .' FROM `mysql`.`db`'
1994 .' WHERE \'' . PMA_sqlAddslashes($checkprivs) . "'"
1996 .' AND NOT (' . $list_of_compared_privileges. ')) '
1998 .'(SELECT ' . $list_of_privileges . ', \'*\' AS `Db`'
1999 .' FROM `mysql`.`user` '
2000 .' WHERE NOT (' . $list_of_compared_privileges . ')) '
2001 .' ORDER BY `User` ASC,'
2004 $res = PMA_DBI_query($sql_query);
2005 $row = PMA_DBI_fetch_assoc($res);
2012 // prepare the current user
2013 $current_privileges = array();
2014 $current_user = $row['User'];
2015 $current_host = $row['Host'];
2016 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
2017 $current_privileges[] = $row;
2018 $row = PMA_DBI_fetch_assoc($res);
2020 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
2022 if (count($current_privileges) > 1) {
2023 echo ' rowspan="' . count($current_privileges) . '"';
2025 echo '>' . (empty($current_user) ?
'<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($current_user)) . "\n"
2028 if (count($current_privileges) > 1) {
2029 echo ' rowspan="' . count($current_privileges) . '"';
2031 echo '>' . htmlspecialchars($current_host) . '</td>' . "\n";
2032 foreach ($current_privileges as $current) {
2035 if (!isset($current['Db']) ||
$current['Db'] == '*') {
2036 echo $GLOBALS['strGlobal'];
2037 } elseif ($current['Db'] == PMA_escape_mysql_wildcards($checkprivs)) {
2038 echo $GLOBALS['strDbSpecific'];
2040 echo $GLOBALS['strWildcard'], ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
2046 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
2050 . ' ' . ($current['Grant_priv'] == 'Y' ?
$GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n"
2053 printf($link_edit, urlencode($current_user),
2054 urlencode($current_host),
2055 urlencode(! isset($current['Db']) ||
$current['Db'] == '*' ?
'' : $current['Db']),
2060 if (empty($row) && empty($row1) && empty($row2)) {
2063 $odd_row = ! $odd_row;
2066 echo ' <tr class="odd">' . "\n"
2067 . ' <td colspan="6">' . "\n"
2068 . ' ' . $GLOBALS['strNoUsersFound'] . "\n"
2072 echo '</tbody>' . "\n"
2073 . '</table>' . "\n";
2074 } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ...
2078 * Displays the footer
2081 require_once './libraries/footer.inc.php';