patch #1198492, current version check
[phpmyadmin/crack.git] / server_privileges.php
blobe0cd9b819e0daecd1331558760a4f7e06d3ead0b
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Does the common work
7 */
8 $js_to_run = 'server_privileges.js';
9 require('./server_common.inc.php');
12 /**
13 * Checks if a dropdown box has been used for selecting a database / table
15 if (!empty($pred_dbname)) {
16 $dbname = $pred_dbname;
17 unset($pred_dbname);
19 if (!empty($pred_tablename)) {
20 $tablename = $pred_tablename;
21 unset($pred_tablename);
25 /**
26 * Checks if the user is allowed to do what he tries to...
28 if (!$is_superuser) {
29 require('./server_links.inc.php');
30 echo '<h2>' . "\n"
31 . ' ' . ($GLOBALS['cfg']['MainPageIconic'] ? '<img src="'. $GLOBALS['pmaThemeImage'] . 'b_usrlist.png" border="0" hspace="2" align="middle" />' : '')
32 . ' ' . $strPrivileges . "\n"
33 . '</h2>' . "\n"
34 . $strNoPrivileges . "\n";
35 require_once('./footer.inc.php');
39 /**
40 * Extracts the privilege information of a priv table row
42 * @param array the row
43 * @param boolean add <dfn> tag with tooltips
45 * @global ressource the database connection
47 * @return array
49 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
51 global $userlink;
53 $grants = array(
54 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
55 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
56 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
57 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
58 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
59 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
60 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
61 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
62 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess' . ((!empty($row) && isset($row['Super_priv'])) || (empty($row) && isset($GLOBALS['Super_priv'])) ? '4' : '3')]),
63 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
64 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
65 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
66 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
67 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
68 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
69 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
70 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
71 array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute']),
72 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
73 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient'])
75 if (!empty($row) && isset($row['Table_priv'])) {
76 $res = PMA_DBI_query('SHOW COLUMNS FROM `tables_priv` LIKE \'Table_priv\';', $userlink);
77 $row1 = PMA_DBI_fetch_assoc($res);
78 PMA_DBI_free_result($res);
79 $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7));
80 unset($row1);
81 $users_grants = explode(',', $row['Table_priv']);
82 foreach ($av_grants as $current_grant) {
83 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
85 unset($current_grant);
86 unset($av_grants);
87 unset($users_grants);
89 $privs = array();
90 $allPrivileges = TRUE;
91 foreach ($grants as $current_grant) {
92 if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
93 if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'] && empty($GLOBALS[$current_grant[0] . '_none']))))) {
94 if ($enableHTML) {
95 $privs[] = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', '&nbsp;', $current_grant[1]) . '</dfn>';
96 } else {
97 $privs[] = $current_grant[1];
99 } else if (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) {
100 if ($enableHTML) {
101 $priv_string = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', '&nbsp;', $current_grant[1]) . '</dfn>';
102 } else {
103 $priv_string = $current_grant[1];
105 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
106 } else {
107 $allPrivileges = FALSE;
111 if (empty($privs)) {
112 if ($enableHTML) {
113 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
114 } else {
115 $privs[] = 'USAGE';
117 } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
118 if ($enableHTML) {
119 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL&nbsp;PRIVILEGES</dfn>');
120 } else {
121 $privs = array('ALL PRIVILEGES');
124 return $privs;
125 } // end of the 'PMA_extractPrivInfo()' function
128 * Displays the privileges form table
130 * @param string the database
131 * @param string the table
132 * @param boolean wheather to display the submit button or not
133 * @param int the indenting level of the code
135 * @global array the phpMyAdmin configuration
136 * @global ressource the database connection
138 * @return void
140 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
142 global $cfg, $userlink, $url_query, $checkall;
144 if ($db == '*') {
145 $table = '*';
147 $spaces = '';
148 for ($i = 0; $i < $indent; $i++) {
149 $spaces .= ' ';
151 if (isset($GLOBALS['username'])) {
152 $username = $GLOBALS['username'];
153 $hostname = $GLOBALS['hostname'];
154 if ($db == '*') {
155 $sql_query = 'SELECT * FROM `user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';';
156 } else if ($table == '*') {
157 $sql_query = 'SELECT * FROM `db` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ';';
158 } else {
159 $sql_query = 'SELECT `Table_priv` FROM `tables_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' .PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($table, 'quoted') . ';';
161 $res = PMA_DBI_query($sql_query);
162 $row = PMA_DBI_fetch_assoc($res);
163 PMA_DBI_free_result($res);
165 if (empty($row)) {
166 if ($table == '*') {
167 if ($db == '*') {
168 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
169 } else if ($table == '*') {
170 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
172 $res = PMA_DBI_query($sql_query);
173 while ($row1 = PMA_DBI_fetch_row($res)) {
174 if (substr($row1[0], 0, 4) == 'max_') {
175 $row[$row1[0]] = 0;
176 } else {
177 $row[$row1[0]] = 'N';
180 PMA_DBI_free_result($res);
181 } else {
182 $row = array('Table_priv' => '');
185 if (isset($row['Table_priv'])) {
186 $res = PMA_DBI_query('SHOW COLUMNS FROM `tables_priv` LIKE \'Table_priv\';', $userlink);
187 $row1 = PMA_DBI_fetch_assoc($res);
188 PMA_DBI_free_result($res);
189 $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
190 unset($res, $row1);
191 $users_grants = explode(',', $row['Table_priv']);
192 foreach ($av_grants as $current_grant) {
193 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
195 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
196 $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;');
197 $columns = array();
198 if ($res) {
199 while ($row1 = PMA_DBI_fetch_row($res)) {
200 $columns[$row1[0]] = array(
201 'Select' => FALSE,
202 'Insert' => FALSE,
203 'Update' => FALSE,
204 'References' => FALSE
207 PMA_DBI_free_result($res);
209 unset($res, $row1);
211 if (!empty($columns)) {
212 $res = PMA_DBI_QUERY('SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($table, 'quoted') . ';');
214 while ($row1 = PMA_DBI_fetch_row($res)) {
215 $row1[1] = explode(',', $row1[1]);
216 foreach ($row1[1] as $current) {
217 $columns[$row1[0]][$current] = TRUE;
220 PMA_DBI_free_result($res);
221 unset($res);
222 unset($row1);
223 unset($current);
224 echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
225 . $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
226 . $spaces . '<table border="0" cellpadding="2" cellspacing="1">' . "\n"
227 . $spaces . ' <tr>' . "\n"
228 . $spaces . ' <th colspan="6">&nbsp;' . $GLOBALS['strTblPrivileges'] . '&nbsp;</th>' . "\n"
229 . $spaces . ' </tr>' . "\n"
230 . $spaces . ' <tr>' . "\n"
231 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
232 . $spaces . ' </tr>' . "\n"
233 . $spaces . ' <tr>' . "\n"
234 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescSelect'] . '">SELECT</dfn></tt>&nbsp;</td>' . "\n"
235 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescInsert'] . '">INSERT</dfn></tt>&nbsp;</td>' . "\n"
236 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescUpdate'] . '">UPDATE</dfn></tt>&nbsp;</td>' . "\n"
237 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescReferences'] . '">REFERENCES</dfn></tt>&nbsp;</td>' . "\n";
238 list($current_grant, $current_grant_value) = each($row);
239 while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
240 list($current_grant, $current_grant_value) = each($row);
242 echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
243 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
244 . $spaces . ' </tr>' . "\n"
245 . $spaces . ' <tr>' . "\n";
246 $rowspan = count($row) - 5;
247 echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
248 . $spaces . ' <select name="Select_priv[]" multiple="multiple">' . "\n";
249 foreach ($columns as $current_column => $current_column_privileges) {
250 echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
251 if ($row['Select_priv'] == 'Y' || $current_column_privileges['Select']) {
252 echo ' selected="selected"';
254 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
256 echo $spaces . ' </select><br />' . "\n"
257 . $spaces . ' <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
258 . $spaces . ' <input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="Select_priv_none" id="checkbox_Select_priv_none" title="' . $GLOBALS['strNone'] . '" /><label for="checkbox_Select_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
259 . $spaces . ' </td>' . "\n"
260 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
261 . $spaces . ' <select name="Insert_priv[]" multiple="multiple">' . "\n";
262 foreach ($columns as $current_column => $current_column_privileges) {
263 echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
264 if ($row['Insert_priv'] == 'Y' || $current_column_privileges['Insert']) {
265 echo ' selected="selected"';
267 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
269 echo $spaces . ' </select><br />' . "\n"
270 . $spaces . ' <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
271 . $spaces . ' <input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="Insert_priv_none" id="checkbox_Insert_priv_none" title="' . $GLOBALS['strNone'] . '" /><label for="checkbox_Insert_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
272 . $spaces . ' </td>' . "\n"
273 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
274 . $spaces . ' <select name="Update_priv[]" multiple="multiple">' . "\n";
275 foreach ($columns as $current_column => $current_column_privileges) {
276 echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
277 if ($row['Update_priv'] == 'Y' || $current_column_privileges['Update']) {
278 echo ' selected="selected"';
280 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
282 echo $spaces . ' </select><br />' . "\n"
283 . $spaces . ' <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
284 . $spaces . ' <input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="Update_priv_none" id="checkbox_Update_priv_none" title="' . $GLOBALS['strNone'] . '" /><label for="checkbox_Update_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
285 . $spaces . ' </td>' . "\n"
286 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
287 . $spaces . ' <select name="References_priv[]" multiple="multiple">' . "\n";
288 foreach ($columns as $current_column => $current_column_privileges) {
289 echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
290 if ($row['References_priv'] == 'Y' || $current_column_privileges['References']) {
291 echo ' selected="selected"';
293 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
295 echo $spaces . ' </select><br />' . "\n"
296 . $spaces . ' <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
297 . $spaces . ' <input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="References_priv_none" id="checkbox_References_priv_none" title="' . $GLOBALS['strNone'] . '" /><label for="checkbox_References_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
298 . $spaces . ' </td>' . "\n";
299 unset($rowspan);
300 list($current_grant, $current_grant_value) = each($row);
301 while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
302 list($current_grant, $current_grant_value) = each($row);
304 echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
305 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
306 . $spaces . ' </tr>' . "\n";
307 while (list($current_grant, $current_grant_value) = each($row)) {
308 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
309 continue;
311 echo $spaces . ' <tr>' . "\n"
312 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
313 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
314 . $spaces . ' </tr>' . "\n";
316 } else {
317 $privTable[0] = array(
318 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
319 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
320 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
321 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
323 if ($db == '*') {
324 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
326 $privTable[1] = array(
327 array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
328 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
329 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
330 array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl']))
332 if (isset($row['Create_tmp_table_priv'])) {
333 $privTable[1][] = array('Create_tmp_table', 'CREATE&nbsp;TEMPORARY&nbsp;TABLES', $GLOBALS['strPrivDescCreateTmpTable']);
335 $privTable[2] = array();
336 if (isset($row['Grant_priv'])) {
337 $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']);
339 if ($db == '*') {
340 if (isset($row['Super_priv'])) {
341 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
342 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']);
343 } else {
344 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']);
346 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
347 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
348 if (isset($row['Show_db_priv'])) {
349 $privTable[2][] = array('Show_db', 'SHOW&nbsp;DATABASES', $GLOBALS['strPrivDescShowDb']);
352 if (isset($row['Lock_tables_priv'])) {
353 $privTable[2][] = array('Lock_tables', 'LOCK&nbsp;TABLES', $GLOBALS['strPrivDescLockTables']);
355 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
356 if ($db == '*') {
357 if (isset($row['Execute_priv'])) {
358 $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
360 if (isset($row['Repl_client_priv'])) {
361 $privTable[2][] = array('Repl_client', 'REPLICATION&nbsp;CLIENT', $GLOBALS['strPrivDescReplClient']);
363 if (isset($row['Repl_slave_priv'])) {
364 $privTable[2][] = array('Repl_slave', 'REPLICATION&nbsp;SLAVE', $GLOBALS['strPrivDescReplSlave']);
367 echo $spaces . '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n"
368 . $spaces . '<table border="0" cellpadding="2" cellspacing="1">' . "\n"
369 . $spaces . ' <tr>' . "\n"
370 . $spaces . ' <th colspan="6">&nbsp;' . ($db == '*' ? $GLOBALS['strGlobalPrivileges'] : ($table == '*' ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . '&nbsp;</th>' . "\n"
371 . $spaces . ' </tr>' . "\n"
372 . $spaces . ' <tr>' . "\n"
373 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" align="center" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small><br />' . "\n"
374 . $spaces . ' <a href="./server_privileges.php?' . $url_query . '&amp;checkall=1" onclick="setCheckboxes(\'usersForm\', \'\', true); return false;">' . $GLOBALS['strCheckAll'] . '</a>' . "\n"
375 . $spaces . ' &nbsp;&nbsp;&nbsp' . "\n"
376 . $spaces . ' <a href="./server_privileges.php?' . $url_query . '" onclick="setCheckboxes(\'usersForm\', \'\', false); return false;">' . $GLOBALS['strUncheckAll'] . '</a></td>' . "\n"
377 . $spaces . ' </tr>' . "\n"
378 . $spaces . ' <tr>' . "\n"
379 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strData'] . '</i></b>&nbsp;</td>' . "\n"
380 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strStructure'] . '</i></b>&nbsp;</td>' . "\n"
381 . $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strAdministration'] . '</i></b>&nbsp;</td>' . "\n"
382 . $spaces . ' </tr>' . "\n";
383 $limitTable = FALSE;
384 for ($i = 0; isset($privTable[0][$i]) || isset($privTable[1][$i]) || isset($privTable[2][$i]); $i++) {
385 echo $spaces . ' <tr>' . "\n";
386 for ($j = 0; $j < 3; $j++) {
387 if (isset($privTable[$j][$i])) {
388 echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox"' . (empty($checkall) ? '' : ' checked="checked"') . ' name="' . $privTable[$j][$i][0] . '_priv" id="checkbox_' . $privTable[$j][$i][0] . '_priv" value="Y" ' . ($row[$privTable[$j][$i][0] . '_priv'] == 'Y' ? 'checked="checked" ' : '') . 'title="' . $privTable[$j][$i][2] . '"/></td>' . "\n"
389 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $privTable[$j][$i][0] . '_priv"><tt><dfn title="' . $privTable[$j][$i][2] . '">' . $privTable[$j][$i][1] . '</dfn></tt></label></td>' . "\n";
390 } else if ($db == '*' && !isset($privTable[0][$i]) && !isset($privTable[1][$i])
391 && isset($row['max_questions']) && isset($row['max_updates']) && isset($row['max_connections'])
392 && !$limitTable) {
393 echo $spaces . ' <td colspan="4" rowspan="' . (count($privTable[2]) - $i) . '">' . "\n"
394 . $spaces . ' <table border="0" cellpadding="0" cellspacing="0">' . "\n"
395 . $spaces . ' <tr>' . "\n"
396 . $spaces . ' <th colspan="2">&nbsp;' . $GLOBALS['strResourceLimits'] . '&nbsp;</th>' . "\n"
397 . $spaces . ' </tr>' . "\n"
398 . $spaces . ' <tr>' . "\n"
399 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></td>' . "\n"
400 . $spaces . ' </tr>' . "\n"
401 . $spaces . ' <tr>' . "\n"
402 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_questions"><tt><dfn title="' . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX&nbsp;QUERIES&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n"
403 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" /></td>' . "\n"
404 . $spaces . ' </tr>' . "\n"
405 . $spaces . ' <tr>' . "\n"
406 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_updates"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX&nbsp;UPDATES&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n"
407 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" /></td>' . "\n"
408 . $spaces . ' </tr>' . "\n"
409 . $spaces . ' <tr>' . "\n"
410 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxConnections'] . '">MAX&nbsp;CONNECTIONS&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n"
411 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" /></td>' . "\n"
412 . $spaces . ' </tr>' . "\n"
413 . $spaces . ' </table>' . "\n"
414 . $spaces . ' </td>' . "\n";
415 $limitTable = TRUE;
416 } else if (!$limitTable) {
417 echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2">&nbsp;</td>' . "\n";
421 echo $spaces . ' </tr>' . "\n";
423 if ($submit) {
424 echo $spaces . ' <tr>' . "\n"
425 . $spaces . ' <td colspan="6" align="right">' . "\n"
426 . $spaces . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
427 . $spaces . ' </td>' . "\n"
428 . $spaces . ' </tr>' . "\n";
430 echo $spaces . '</table>' . "\n";
431 } // end of the 'PMA_displayPrivTable()' function
435 * Displays the fields used by the "new user" form as well as the
436 * "change login information / copy user" form.
438 * @param string are we creating a new user or are we just changing one?
439 * (allowed values: 'new', 'change')
440 * @param int the indenting level of the code
442 * @global array the phpMyAdmin configuration
443 * @global ressource the database connection
445 * @return void
447 function PMA_displayLoginInformationFields($mode = 'new', $indent = 0)
449 global $cfg, $userlink;
450 $spaces = '';
451 for ($i = 0; $i < $indent; $i++) {
452 $spaces .= ' ';
454 echo $spaces . '<tr>' . "\n"
455 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
456 . $spaces . ' <label for="select_pred_username">' . "\n"
457 . $spaces . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
458 . $spaces . ' </label>' . "\n"
459 . $spaces . ' </td>' . "\n"
460 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
461 . $spaces . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
462 . $spaces . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
463 . $spaces . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
464 . $spaces . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
465 . $spaces . ' </select>' . "\n"
466 . $spaces . ' </td>' . "\n"
467 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
468 . $spaces . ' <input type="text" class="textfield" name="username" class="textfield" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ? '' : ' value="' . (isset($GLOBALS['new_username']) ? $GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
469 . $spaces . ' </td>' . "\n"
470 . $spaces . '</tr>' . "\n"
471 . $spaces . '<tr>' . "\n"
472 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
473 . $spaces . ' <label for="select_pred_hostname">' . "\n"
474 . $spaces . ' ' . $GLOBALS['strHost'] . ':' . "\n"
475 . $spaces . ' </label>' . "\n"
476 . $spaces . ' </td>' . "\n"
477 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
478 . $spaces . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
479 $res = PMA_DBI_query('SELECT USER();');
480 $row = PMA_DBI_fetch_row($res);
481 PMA_DBI_free_result($res);
482 unset($res);
483 if (!empty($row[0])) {
484 $thishost = str_replace("'", '', substr($row[0], (strrpos($row[0], '@') + 1)));
485 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
486 unset($thishost);
489 echo $spaces . ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
490 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
491 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
492 unset($row);
494 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
495 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
496 switch (strtolower($GLOBALS['hostname'])) {
497 case 'localhost':
498 case '127.0.0.1':
499 $GLOBALS['pred_hostname'] = 'localhost';
500 break;
501 case '%':
502 $GLOBALS['pred_hostname'] = 'any';
503 break;
504 default:
505 $GLOBALS['pred_hostname'] = 'userdefined';
506 break;
509 echo $spaces . ' <option value="any"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n"
510 . $spaces . ' <option value="localhost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n";
511 if (!empty($thishost)) {
512 echo $spaces . ' <option value="thishost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n";
514 unset($thishost);
515 echo $spaces . ' <option value="hosttable"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n"
516 . $spaces . ' <option value="userdefined"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
517 . $spaces . ' </select>' . "\n"
518 . $spaces . ' </td>' . "\n"
519 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
520 . $spaces . ' <input type="text" class="textfield" name="hostname" value="' . ( isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '' ) . '" class="textfield" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
521 . $spaces . ' </td>' . "\n"
522 . $spaces . '</tr>' . "\n"
523 . $spaces . '<tr>' . "\n"
524 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
525 . $spaces . ' <label for="select_pred_password">' . "\n"
526 . $spaces . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
527 . $spaces . ' </label>' . "\n"
528 . $spaces . ' </td>' . "\n"
529 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
530 . $spaces . ' <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n"
531 . $spaces . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
532 . ($mode == 'change' ? $spaces . ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
533 . $spaces . ' <option value="none">' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
534 . $spaces . ' <option value="userdefined"' . ($mode == 'change' ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
535 . $spaces . ' </select>' . "\n"
536 . $spaces . ' </td>' . "\n"
537 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
538 . $spaces . ' <input type="password" name="pma_pw" class="textfield" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
539 . $spaces . ' </td>' . "\n"
540 . $spaces . '</tr>' . "\n"
541 . $spaces . '<tr>' . "\n"
542 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
543 . $spaces . ' <label for="text_pma_pw2">' . "\n"
544 . $spaces . ' ' . $GLOBALS['strReType'] . ':' . "\n"
545 . $spaces . ' </label>' . "\n"
546 . $spaces . ' </td>' . "\n"
547 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">&nbsp;</td>' . "\n"
548 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
549 . $spaces . ' <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
550 . $spaces . ' </td>' . "\n"
551 . $spaces . '</tr>' . "\n"
552 . $spaces . '<tr>' . "\n"
553 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
554 . $spaces . ' <label for="text_pma_pw2">' . "\n"
555 . $spaces . ' ' . $GLOBALS[''] . $GLOBALS['strGeneratePassword'] . ':' . "\n"
556 . $spaces . ' </label>' . "\n"
557 . $spaces . ' </td>' . "\n"
558 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
559 . $spaces . ' <input type="button" value="' . $GLOBALS['strGenerate'] . '" onClick="suggestPassword(this.form, \'generated_pw\')">' . "\n"
560 . $spaces . ' <input type="button" value="' . $GLOBALS['strCopy'] . '" onClick="suggestPasswordCopy(this.form)">' . "\n"
561 . $spaces . ' &nbsp;</td>' . "\n"
562 . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
563 . $spaces . ' <input type="text" name="generated_pw" id="generated_pw" class="textfield"/>' . "\n"
564 . $spaces . ' </td>' . "\n"
565 . $spaces . '</tr>' . "\n";
566 } // end of the 'PMA_displayUserAndHostFields()' function
570 * Changes / copies a user, part I
572 if (!empty($change_copy)) {
573 $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ';';
574 $res = PMA_DBI_query('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
575 if (!$res) {
576 $message = $strNoUsersFound;
577 unset($change_copy);
578 } else {
579 $row = PMA_DBI_fetch_assoc($res);
580 extract($row, EXTR_OVERWRITE);
581 // Recent MySQL versions have the field "Password" in mysql.user,
582 // so the previous extract creates $Password but this script
583 // uses $password
584 if (!isset($password) && isset($Password)) {
585 $password=$Password;
587 PMA_DBI_free_result($res);
588 $queries = array();
594 * Adds a user
595 * (Changes / copies a user, part II)
597 if (!empty($adduser_submit) || !empty($change_copy)) {
598 unset($sql_query);
599 if ($pred_username == 'any') {
600 $username = '';
602 switch ($pred_hostname) {
603 case 'any':
604 $hostname = '%';
605 break;
606 case 'localhost':
607 $hostname = 'localhost';
608 break;
609 case 'hosttable':
610 $hostname = '';
611 break;
612 case 'thishost':
613 $res = PMA_DBI_query('SELECT USER();');
614 $row = PMA_DBI_fetch_row($res);
615 PMA_DBI_free_result($res);
616 unset($res);
617 $hostname = substr($row[0], (strrpos($row[0], '@') + 1));
618 unset($row);
619 break;
621 $res = PMA_DBI_query('SELECT \'foo\' FROM `user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE);
622 if (PMA_DBI_num_rows($res) == 1) {
623 PMA_DBI_free_result($res);
624 $message = sprintf($strUserAlreadyExists, '[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
625 $adduser = 1;
626 } else {
627 PMA_DBI_free_result($res);
628 $real_sql_query = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
629 if ($pred_password != 'none' && $pred_password != 'keep') {
630 $pma_pw_hidden = '';
631 for ($i = 0; $i < strlen($pma_pw); $i++) {
632 $pma_pw_hidden .= '*';
634 $sql_query = $real_sql_query . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\'';
635 $real_sql_query .= ' IDENTIFIED BY \'' . $pma_pw . '\'';
636 } else {
637 if ($pred_password == 'keep' && !empty($password)) {
638 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
640 $sql_query = $real_sql_query;
642 if ((isset($Grant_priv) && $Grant_priv == 'Y') || (PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
643 $real_sql_query .= 'WITH';
644 $sql_query .= 'WITH';
645 if (isset($Grant_priv) && $Grant_priv == 'Y') {
646 $real_sql_query .= ' GRANT OPTION';
647 $sql_query .= ' GRANT OPTION';
649 if (PMA_MYSQL_INT_VERSION >= 40002) {
650 if (isset($max_questions)) {
651 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
652 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
654 if (isset($max_connections)) {
655 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
656 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
658 if (isset($max_updates)) {
659 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
660 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
664 $real_sql_query .= ';';
665 $sql_query .= ';';
666 if (empty($change_copy)) {
667 PMA_DBI_try_query($real_sql_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
668 $message = $strAddUserMessage;
669 } else {
670 $queries[] = $real_sql_query;
671 // we put the query containing the hidden password in
672 // $queries_for_display, at the same position occupied
673 // by the real query in $queries
674 $tmp_count = count($queries);
675 $queries_for_display[$tmp_count - 1] = $sql_query;
677 unset($res, $real_sql_query);
683 * Changes / copies a user, part III
685 if (!empty($change_copy)) {
686 $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ';';
687 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition );
688 while ($row = PMA_DBI_fetch_assoc($res)) {
689 $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) . ' ON `' . $row['Db'] . '`.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION' : '') . ';';
691 PMA_DBI_free_result($res);
692 $res = PMA_DBI_query('SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv`' . $user_host_condition, $userlink, PMA_DBI_QUERY_STORE);
693 while ($row = PMA_DBI_fetch_assoc($res)) {
695 $res2 = PMA_DBI_QUERY('SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($row['Db'], 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($row['Table_name'], 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE);
697 $tmp_privs1 = PMA_extractPrivInfo($row);
698 $tmp_privs2 = array(
699 'Select' => array(),
700 'Insert' => array(),
701 'Update' => array(),
702 'References' => array()
705 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
706 $tmp_array = explode(',', $row2['Column_priv']);
707 if (in_array('Select', $tmp_array)) {
708 $tmp_privs2['Select'][] = $row2['Column_name'];
710 if (in_array('Insert', $tmp_array)) {
711 $tmp_privs2['Insert'][] = $row2['Column_name'];
713 if (in_array('Update', $tmp_array)) {
714 $tmp_privs2['Update'][] = $row2['Column_name'];
716 if (in_array('References', $tmp_array)) {
717 $tmp_privs2['References'][] = $row2['Column_name'];
719 unset($tmp_array);
721 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
722 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
724 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
725 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
727 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
728 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
730 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
731 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
733 unset($tmp_privs2);
734 $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION' : '') . ';';
740 * Updates privileges
742 if (!empty($update_privs)) {
743 // escaping a wildcard character in a GRANT is only accepted at the global
744 // or database level, not at table level; this is why I remove
745 // the escaping character
746 // Note: in the phpMyAdmin list of Database-specific privileges,
747 // we will have for example
748 // test\_db SELECT (this one is for privileges on a db level)
749 // test_db USAGE (this one is for table-specific privileges)
751 // It looks curious but reflects the way MySQL works
753 if (empty($dbname)) {
754 $db_and_table = '*.*';
755 } else {
756 if (!empty($tablename)) {
757 $db_and_table = str_replace('\\','',PMA_backquote($dbname))
758 . '.' . PMA_backquote($tablename);
759 } else {
760 // do not remove the escaping character when working at db level
761 $db_and_table = PMA_backquote($dbname)
762 . '.*';
767 $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
768 if (!isset($Grant_priv) || $Grant_priv != 'Y') {
769 $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
771 $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
773 if ((isset($Grant_priv) && $Grant_priv == 'Y') || (empty($dbname) && PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
774 $sql_query2 .= 'WITH';
775 if (isset($Grant_priv) && $Grant_priv == 'Y') {
776 $sql_query2 .= ' GRANT OPTION';
778 if (PMA_MYSQL_INT_VERSION >= 40002) {
779 if (isset($max_questions)) {
780 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
782 if (isset($max_connections)) {
783 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
785 if (isset($max_updates)) {
786 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
790 $sql_query2 .= ';';
791 if (!PMA_DBI_try_query($sql_query0)) { // this query may fail, but this does not matter :o)
792 unset($sql_query0);
794 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too...
795 unset($sql_query1);
797 PMA_DBI_query($sql_query2);
798 $sql_query = (isset($sql_query0) ? $sql_query0 . ' ' : '')
799 . (isset($sql_query1) ? $sql_query1 . ' ' : '')
800 . $sql_query2;
801 $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
806 * Revokes Privileges
808 if (!empty($revokeall)) {
809 $db_and_table = PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename));
810 $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
811 $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
812 PMA_DBI_query($sql_query0);
813 if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too...
814 unset($sql_query1);
816 $sql_query = $sql_query0 . (isset($sql_query1) ? ' ' . $sql_query1 : '');
817 $message = sprintf($strRevokeMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
818 if (empty($tablename)) {
819 unset($dbname);
820 } else {
821 unset($tablename);
827 * Updates the password
829 if (!empty($change_pw)) {
830 if ($nopass == 1) {
831 $sql_query = 'SET PASSWORD FOR \'' . $username . '\'@\'' . $hostname . '\' = \'\';';
832 PMA_DBI_query($sql_query);
833 $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
834 } else if (empty($pma_pw) || empty($pma_pw2)) {
835 $message = $strPasswordEmpty;
836 } else if ($pma_pw != $pma_pw2) {
837 $message = $strPasswordNotSame;
838 } else {
839 $hidden_pw = '';
840 for ($i = 0; $i < strlen($pma_pw); $i++) {
841 $hidden_pw .= '*';
843 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')';
844 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . $hidden_pw . '\')';
845 PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query);
846 $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
852 * Deletes users
853 * (Changes / copies a user, part IV)
855 $user_host_separator = chr(27);
857 if (!empty($delete) || (!empty($change_copy) && $mode < 4)) {
858 if (!empty($change_copy)) {
859 $selected_usr = array($old_username . $user_host_separator . $old_hostname);
860 } else {
861 $queries = array();
863 for ($i = 0; isset($selected_usr[$i]); $i++) {
864 list($this_user, $this_host) = explode($user_host_separator, $selected_usr[$i]);
865 $queries[] = '# ' . sprintf($strDeleting, '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
866 if ($mode == 2) {
867 // The SHOW GRANTS query may fail if the user has not been loaded
868 // into memory
869 $res = PMA_DBI_try_query('SHOW GRANTS FOR \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';');
870 if ($res) {
871 $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
872 while ($row = PMA_DBI_fetch_row($res)) {
873 $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3));
874 if ($this_table != '*.*') {
875 $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
877 if (strpos($row[0], 'WITH GRANT OPTION')) {
878 $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
881 unset($this_table);
883 PMA_DBI_free_result($res);
885 unset($res);
887 $queries[] = 'DELETE FROM `user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($this_host, 'quoted') . ';';
888 if ($mode != 2) {
889 // If we REVOKE the table grants, we should not need to modify the
890 // `db`, `tables_priv` and `columns_priv` tables manually...
891 $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($this_host, 'quoted') . ';';
892 $queries[] = 'DELETE FROM `db`' . $user_host_condition;
893 $queries[] = 'DELETE FROM `tables_priv`' . $user_host_condition;
894 $queries[] = 'DELETE FROM `columns_priv`' . $user_host_condition;
896 if (!empty($drop_users_db)) {
897 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
900 if (empty($change_copy)) {
901 if (empty($queries)) {
902 $message = $strError . ': ' . $strDeleteNoUsersSelected;
903 } else {
904 if ($mode == 3) {
905 $queries[] = '# ' . $strReloadingThePrivileges . ' ...';
906 $queries[] = 'FLUSH PRIVILEGES;';
908 foreach ($queries as $sql_query) {
909 if ($sql_query{0} != '#') {
910 PMA_DBI_query($sql_query, $userlink);
913 $sql_query = join("\n", $queries);
914 $message = $strUsersDeleted;
916 unset($queries);
922 * Changes / copies a user, part V
924 if (!empty($change_copy)) {
925 $tmp_count = -1;
926 foreach ($queries as $sql_query) {
927 $tmp_count++;
928 if ($sql_query{0} != '#') {
929 PMA_DBI_query($sql_query);
931 // when there is a query containing a hidden password, take it
932 // instead of the real query sent
933 if (isset($queries_for_display[$tmp_count])) {
934 $queries[$tmp_count] = $queries_for_display[$tmp_count];
937 $message = $strSuccess;
938 $sql_query = join("\n", $queries);
943 * Reloads the privilege tables into memory
945 if (!empty($flush_privileges)) {
946 $sql_query = 'FLUSH PRIVILEGES;';
947 PMA_DBI_query($sql_query);
948 $message = $strPrivilegesReloaded;
953 * Displays the links
955 require('./server_links.inc.php');
959 * Displays the page
961 if (empty($adduser) && empty($checkprivs)) {
962 if (!isset($username)) {
963 // No username is given --> display the overview
964 echo '<h2>' . "\n"
965 . ' ' . ($GLOBALS['cfg']['MainPageIconic'] ? '<img src="'. $GLOBALS['pmaThemeImage'] . 'b_usrlist.png" border="0" hspace="2" align="middle" />' : '')
966 . $strUserOverview . "\n"
967 . '</h2>' . "\n";
968 $oldPrivTables = FALSE;
969 if (PMA_MYSQL_INT_VERSION >= 40002) {
970 $sql_query = 'SELECT `User`, `Host`, IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '\'\', \'N\', \'Y\') AS \'Password\', `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv` FROM `user` ';
972 // the strtolower() is because sometimes the User field
973 // might be BINARY, so LIKE would be case sensitive
974 if (isset($initial)) {
975 $sql_query .= " WHERE " . PMA_convert_using('User')
976 . " LIKE " . PMA_convert_using($initial . '%', 'quoted')
977 . " OR ". PMA_convert_using('User')
978 . " LIKE " . PMA_convert_using(strtolower($initial) . '%', 'quoted');
981 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
982 $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_STORE);
984 if (!$res) {
985 // the query failed! This may have two reasons:
986 // - the user has not enough privileges
987 // - the privilege tables use a structure of an earlier version.
988 $oldPrivTables = TRUE;
991 if (empty($res) || PMA_MYSQL_INT_VERSION < 40002) {
992 $sql_query = 'SELECT `User`, `Host`, IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '\'\', \'N\', \'Y\') AS \'Password\', `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv` FROM `user`';
994 if (isset($initial)) {
995 $sql_query .= " WHERE " . PMA_convert_using('User')
996 . " LIKE " . PMA_convert_using($initial . '%', 'quoted')
997 . " OR ". PMA_convert_using('User')
998 . " LIKE " . PMA_convert_using(strtolower($initial) . '%', 'quoted');
1001 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
1002 $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_STORE);
1004 if (!$res) {
1005 // the query failed! This may have two reasons:
1006 // - the user has not enough privileges
1007 // - the privilege tables use a structure of an earlier version.
1008 $oldPrivTables = TRUE;
1011 if (!$res) {
1012 echo '<i>' . $strNoPrivileges . '</i>' . "\n";
1013 PMA_DBI_free_result($res);
1014 unset($res);
1015 } else {
1016 if ($oldPrivTables) {
1017 // rabus: This message is hardcoded because I will replace it by
1018 // a automatic repair feature soon.
1019 echo '<div class="warning">' . "\n"
1020 . ' Warning: Your privilege table structure seem to be older than this MySQL version!<br />' . "\n"
1021 . ' Please run the script <tt>mysql_fix_privilege_tables</tt> that should be included in your MySQL server distribution to solve this problem!' . "\n"
1022 . '</div><br />' . "\n";
1026 * Displays the initials
1029 // for all initials, even non A-Z
1030 $array_initials = array();
1032 // initialize to FALSE the letters A-Z
1033 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) {
1034 $array_initials[chr($letter_counter + 64)] = FALSE;
1037 $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1)) FROM `user` ORDER BY `User` ASC', NULL, PMA_DBI_QUERY_STORE);
1038 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1039 $array_initials[$tmp_initial] = TRUE;
1042 // Display the initials, which can be any characters, not
1043 // just letters. For letters A-Z, we add the non-used letters
1044 // as greyed out.
1046 uksort($array_initials, "strnatcasecmp");
1047 reset($array_initials);
1049 echo '<table cellspacing="5" ><tr>';
1050 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1052 if ($initial_was_found) {
1053 echo '<td><a href="' . $PHP_SELF . '?' . $url_query . '&amp;initial=' . urlencode($tmp_initial) . '" style="font-size:' . $font_bigger . '">' . $tmp_initial . '</a></td>' . "\n";
1054 } else {
1055 echo '<td style="font-size:' . $font_bigger . '">' . $tmp_initial . '</td>';
1058 echo '<td><a href="' . $PHP_SELF . '?' . $url_query . '&amp;showall=1" style="font-size:' . $font_bigger . '">[' . $strShowAll . ']</a></td>' . "\n";
1059 echo '</tr></table>';
1062 * Displays the user overview
1065 if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) {
1067 echo '<form name="usersForm" action="server_privileges.php" method="post">' . "\n"
1068 . PMA_generate_common_hidden_inputs('', '', 1)
1069 . ' <table border="0" cellpadding="2" cellspacing="1">' . "\n"
1070 . ' <tr>' . "\n"
1071 . ' <td></td>' . "\n"
1072 . ' <th>&nbsp;' . $strUser . '&nbsp;</th>' . "\n"
1073 . ' <th>&nbsp;' . $strHost . '&nbsp;</th>' . "\n"
1074 . ' <th>&nbsp;' . $strPassword . '&nbsp;</th>' . "\n"
1075 . ' <th>&nbsp;' . $strGlobalPrivileges . '&nbsp;</th>' . "\n"
1076 . ' <th>&nbsp;' . $strGrantOption . '&nbsp;</th>' . "\n"
1077 . ' ' . ($cfg['PropertiesIconic'] ? '<td>&nbsp;</td>' : '<th>' . $strAction . '</th>') . "\n";
1078 echo ' </tr>' . "\n";
1079 $useBgcolorOne = TRUE;
1080 for ($i = 0; $row = PMA_DBI_fetch_assoc($res); $i++) {
1081 echo ' <tr>' . "\n"
1082 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_' . $i . '" value="' . htmlspecialchars($row['User'] . $user_host_separator . $row['Host']) . '"' . (empty($checkall) ? '' : ' checked="checked"') . ' /></td>' . "\n"
1083 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><label for="checkbox_sel_users_' . $i . '">' . (empty($row['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row['User'])) . '</label></td>' . "\n"
1084 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row['Host']) . '</td>' . "\n";
1085 $privs = PMA_extractPrivInfo($row, TRUE);
1086 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Password'] == 'Y' ? $strYes : '<span style="color: #FF0000">' . $strNo . '</span>') . '</td>' . "\n"
1087 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
1088 . ' ' . join(',' . "\n" . ' ', $privs) . "\n"
1089 . ' </tt></td>' . "\n"
1090 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Grant_priv'] == 'Y' ? $strYes : $strNo) . '</td>' . "\n"
1091 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="center"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($row['User']) . '&amp;hostname=' . urlencode($row['Host']) . '">';
1092 if ($GLOBALS['cfg']['PropertiesIconic']) {
1093 echo '<img src="' . $GLOBALS['pmaThemeImage'] . 'b_usredit.png" width="16" height="16" border="0" hspace="2" align="middle" alt="' . $strEditPrivileges . '" title="' . $strEditPrivileges . '" />';
1094 } else {
1095 echo $strEditPrivileges;
1097 echo '</a></td>' . "\n"
1098 . ' </tr>' . "\n";
1099 $useBgcolorOne = !$useBgcolorOne;
1101 @PMA_DBI_free_result($res);
1102 unset($res);
1103 unset ($row);
1104 echo ' <tr>' . "\n"
1105 . ' <td></td>' . "\n"
1106 . ' <td colspan="5">' . "\n"
1107 . ' &nbsp;<i>' . $strEnglishPrivileges . '</i>&nbsp;' . "\n"
1108 . ' </td>' . "\n"
1109 . ' </tr>' . "\n"
1110 . ' <tr>' . "\n"
1111 . ' <td colspan="6" valign="bottom">' . "\n"
1112 . ' <img src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
1113 . ' <a href="./server_privileges.php?' . $url_query . '&amp;checkall=1" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', true); return false;">' . $strCheckAll . '</a>' . "\n"
1114 . ' &nbsp;/&nbsp;' . "\n"
1115 . ' <a href="server_privileges.php?' . $url_query . '" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', false); return false;">' . $strUncheckAll . '</a>' . "\n"
1116 . ' </td>' . "\n"
1117 . ' </tr>' . "\n"
1118 . ' </table>' . "\n"
1119 . ' <br /><table border="0" cellpading="3" cellspacing="0">' . "\n"
1120 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td '
1121 . ($cfg['PropertiesIconic'] ? 'colspan="3"><b><a href="server_privileges.php?' . $url_query . '&amp;adduser=1"><img src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" hspace="2" border="0" align="middle" />' : 'width="20" nowrap="nowrap" align="center" valign="top"><b>&#8226;</b></td><td><b><a href="server_privileges.php?' . $url_query . '&amp;adduser=1">' ). "\n"
1122 . ' ' . $strAddUser . '</a></b>' . "\n"
1123 . ' ' . "\n"
1124 . ' </td></tr>' . "\n" . ' <tr><td colspan="2"></td></tr>'
1125 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td '
1126 . ($cfg['PropertiesIconic'] ? 'colspan="3"><b><img src="' . $pmaThemeImage . 'b_usrdrop.png" width="16" height="16" hspace="2" border="0" align="middle" />' : 'width="20" nowrap="nowrap" align="center" valign="top"><b>&#8226;</b></td><td><b>' ). "\n"
1127 . ' <b>' . $strRemoveSelectedUsers . '</b>' . "\n"
1128 . ' </td></tr>' . "\n"
1129 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td width="16" class="nowrap">&nbsp;</td><td valign="top"><input type="radio" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '" name="mode" id="radio_mode_1" value="1" checked="checked" /></td>' . "\n"
1130 . ' <td><label for="radio_mode_1" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '">' . "\n"
1131 . ' ' . $strJustDelete . "\n"
1132 . ' </label></td></tr>' . "\n"
1133 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td width="16" class="nowrap">&nbsp;</td><td valign="top"><input type="radio" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '" name="mode" id="radio_mode_2" value="2" /></td>' . "\n"
1134 . ' <td><label for="radio_mode_2" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '">' . "\n"
1135 . ' ' . wordwrap($strRevokeAndDelete,75,'<br />') . "\n"
1136 . ' </label></td></tr>' . "\n"
1137 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td width="16" class="nowrap">&nbsp;</td><td valign="top"><input type="radio" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '" name="mode" id="radio_mode_3" value="3" /></td>' . "\n"
1138 . ' <td><label for="radio_mode_3" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '">' . "\n"
1139 . ' ' . $strDeleteAndFlush . "\n"
1140 . ' </label></td></tr>' . "\n"
1141 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td width="16" class="nowrap">&nbsp;</td><td valign="top"><input type="checkbox" title="' . $strDropUsersDb . '" name="drop_users_db" id="checkbox_drop_users_db" /></td>' . "\n"
1142 . ' <td><label for="checkbox_drop_users_db" title="' . $strDropUsersDb . '">' . "\n"
1143 . ' ' . $strDropUsersDb . "\n"
1144 . ' </label>' . "\n"
1145 . ' </td></tr>' . "\n" . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td colspan="3" align="right">'
1146 . ' <input type="submit" name="delete" value="' . $strGo . '" id="buttonGo" />' . "\n"
1147 . ' </td></tr>' . "\n"
1148 . ' </table>' . "\n"
1149 . '</form>' . "\n"
1150 . '<div class="tblWarn">' . "\n"
1151 . ' ' . sprintf($strFlushPrivilegesNote, '<a href="server_privileges.php?' . $url_query . '&amp;flush_privileges=1">', '</a>') . "\n"
1152 . '</div>' . "\n";
1153 } else {
1155 unset ($row);
1156 echo ' <br /><table border="0" cellpading="3" cellspacing="0">' . "\n"
1157 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td '
1158 . ($cfg['PropertiesIconic'] ? 'colspan="3"><b><a href="server_privileges.php?' . $url_query . '&amp;adduser=1"><img src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" hspace="2" border="0" align="middle" />' : 'width="20" nowrap="nowrap" align="center" valign="top"><b>&#8226;</b></td><td><b><a href="server_privileges.php?' . $url_query . '&amp;adduser=1">' ). "\n"
1159 . ' ' . $strAddUser . '</a></b>' . "\n"
1160 . ' ' . "\n"
1161 . ' </td></tr>' . "\n" . ' <tr><td colspan="2"></td></tr>'
1162 . ' </table>' . "\n"
1163 . '</form>' . "\n"
1164 . '<div class="tblWarn">' . "\n"
1165 . ' ' . sprintf($strFlushPrivilegesNote, '<a href="server_privileges.php?' . $url_query . '&amp;flush_privileges=1">', '</a>') . "\n"
1166 . '</div>' . "\n";
1167 } // end if (display overview)
1172 } else {
1174 // A user was selected -> display the user's properties
1176 echo '<h2>' . "\n"
1177 . ($cfg['PropertiesIconic'] ? '<img src="' . $pmaThemeImage . 'b_usredit.png" width="16" height="16" border="0" hspace="2" align="middle" />' : '' )
1178 . ' ' . $strUser . ' <i><a class="h2" href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '">\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</a></i>' . "\n";
1179 if (!empty($dbname)) {
1180 echo ' - ' . $strDatabase . ' <i><a class="h2" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&amp;db=' . urlencode($dbname) . '&amp;reload=1">' . htmlspecialchars($dbname) . '</a></i>' . "\n";
1181 if (!empty($tablename)) {
1182 echo ' - ' . $strTable . ' <i><a class="h2" href="' . $cfg['DefaultTabTable'] . '?' . $url_query . '&amp;db=' . urlencode($dbname) . '&amp;table=' . urlencode($tablename) . '&amp;reload=1">' . htmlspecialchars($tablename) . '</a></i>' . "\n";
1185 echo '</h2>' . "\n";
1186 $res = PMA_DBI_query('SELECT \'foo\' FROM `user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE);
1187 if (PMA_DBI_num_rows($res) < 1) {
1188 echo $strUserNotFound;
1189 require_once('./footer.inc.php');
1191 PMA_DBI_free_result($res);
1192 unset($res);
1193 echo '<ul>' . "\n"
1194 . ' <li>' . "\n"
1195 . ' <form name="usersForm" action="server_privileges.php" method="post">' . "\n"
1196 . PMA_generate_common_hidden_inputs('', '', 3)
1197 . ' <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1198 . ' <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
1199 if (!empty($dbname)) {
1200 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '" />' . "\n";
1201 if (!empty($tablename)) {
1202 echo ' <input type="hidden" name="tablename" value="' . htmlspecialchars($tablename) . '" />' . "\n";
1205 echo ' <b>' . $strEditPrivileges . '</b><br />' . "\n";
1206 PMA_displayPrivTable((empty($dbname) ? '*' : $dbname), ((empty($dbname) || empty($tablename)) ? '*' : $tablename), TRUE, 3);
1207 echo ' </form>' . "\n"
1208 . ' </li>' . "\n";
1209 if (empty($tablename)) {
1210 echo ' <li>' . "\n"
1211 . ' <b>' . (empty($dbname) ? $strDbPrivileges : $strTblPrivileges) . '</b><br />' . "\n"
1212 . ' <table border="0" cellpadding="2" cellspacing="1">' . "\n"
1213 . ' <tr>' . "\n"
1214 . ' <th>&nbsp;' . (empty($dbname) ? $strDatabase : $strTable) . '&nbsp;</th>' . "\n"
1215 . ' <th>&nbsp;' . $strPrivileges . '&nbsp;</th>' . "\n"
1216 . ' <th>&nbsp;' . $strGrantOption . '&nbsp;</th>' . "\n"
1217 . ' <th>&nbsp;' . (empty($dbname) ? $strTblPrivileges : $strColumnPrivileges) . '&nbsp;</th>' . "\n"
1218 . ' <th colspan="2">&nbsp;' . $strAction . '&nbsp;</th>' . "\n"
1219 . ' </tr>' . "\n";
1220 $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted');
1221 if (empty($dbname)) {
1222 $sql_query = 'SELECT * FROM `db`' . $user_host_condition . ' ORDER BY `Db` ASC;';
1223 } else {
1224 $sql_query = 'SELECT `Table_name`, `Table_priv`, IF(`Column_priv` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . ' \'\', 0, 1) AS \'Column_priv\' FROM `tables_priv`' . $user_host_condition . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($dbname, 'quoted') . ' ORDER BY `Table_name` ASC;';
1226 $res = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_STORE);
1227 if (PMA_DBI_affected_rows() == 0) {
1228 echo ' <tr>' . "\n"
1229 . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="6"><center><i>' . $strNone . '</i></center></td>' . "\n"
1230 . ' </tr>' . "\n";
1231 } else {
1232 $useBgcolorOne = TRUE;
1233 if (empty($dbname)) {
1234 $res2 = PMA_DBI_query('SELECT `Db` FROM `tables_priv`' . $user_host_condition . ' GROUP BY `Db` ORDER BY `Db` ASC;');
1235 $row2 = PMA_DBI_fetch_assoc($res2);
1237 $found_rows = array();
1238 while ($row = PMA_DBI_fetch_assoc($res)) {
1240 while (empty($dbname) && $row2 && $row['Db'] > $row2['Db']) {
1241 $found_rows[] = $row2['Db'];
1243 echo ' <tr>' . "\n"
1244 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
1245 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
1246 . ' <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
1247 . ' </tt></td>' . "\n"
1248 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n"
1249 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
1250 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
1251 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . urlencode($row2['Db']) . '&amp;revokeall=1">' . $strRevoke . '</a></td>' . "\n"
1252 . ' </tr>' . "\n";
1253 $row2 = PMA_DBI_fetch_assoc($res2);
1254 $useBgcolorOne = !$useBgcolorOne;
1255 } // end while
1256 $found_rows[] = empty($dbname) ? $row['Db'] : $row['Table_name'];
1258 echo ' <tr>' . "\n"
1259 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars(empty($dbname) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
1260 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
1261 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1262 . ' </tt></td>' . "\n"
1263 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . (((empty($dbname) && $row['Grant_priv'] == 'Y') || (!empty($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $strYes : $strNo) . '</td>' . "\n"
1264 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">';
1265 if ((empty($dbname) && $row2 && $row['Db'] == $row2['Db'])
1266 || (!empty($dbname) && $row['Column_priv'])) {
1267 echo $strYes;
1268 if (empty($dbname)) {
1269 $row2 = PMA_DBI_fetch_assoc($res2);
1271 } else {
1272 echo $strNo;
1274 echo '</td>' . "\n"
1275 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&amp;tablename=' . urlencode($row['Table_name'])) . '">' . $strEdit . '</a></td>' . "\n"
1276 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&amp;tablename=' . urlencode($row['Table_name'])) . '&amp;revokeall=1">' . $strRevoke . '</a></td>' . "\n"
1277 . ' </tr>' . "\n";
1278 $useBgcolorOne = !$useBgcolorOne;
1279 } // end while
1282 while (empty($dbname) && $row2) {
1284 $found_rows[] = $row2['Db'];
1285 echo ' <tr>' . "\n"
1286 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
1287 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
1288 . ' <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
1289 . ' </tt></td>' . "\n"
1290 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n"
1291 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
1292 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
1293 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname) . '&amp;dbname=' . urlencode($row2['Db']) . '&amp;revokeall=1">' . $strRevoke . '</a></td>' . "\n"
1294 . ' </tr>' . "\n";
1295 $row2 = PMA_DBI_fetch_assoc($res2);
1297 $useBgcolorOne = !$useBgcolorOne;
1298 } // end while
1299 if (empty($dbname)) {
1300 PMA_DBI_free_result($res2);
1301 unset($res2);
1302 unset($row2);
1305 PMA_DBI_free_result($res);
1306 unset($res);
1307 unset($row);
1308 echo ' <tr>' . "\n"
1309 . ' <td colspan="5">' . "\n"
1310 . ' <form action="server_privileges.php" method="post">' . "\n"
1311 . PMA_generate_common_hidden_inputs('', '', 6)
1312 . ' <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1313 . ' <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
1314 if (empty($dbname)) {
1315 echo ' <label for="text_dbname">' . $strAddPrivilegesOnDb . ':</label>' . "\n";
1316 $res = PMA_DBI_query('SHOW DATABASES;');
1317 $pred_db_array = array();
1318 while ($row = PMA_DBI_fetch_row($res)) {
1319 if (!isset($found_rows) || !in_array(str_replace('_', '\\_', $row[0]), $found_rows)) {
1320 $pred_db_array[] = $row[0];
1323 PMA_DBI_free_result($res);
1324 unset($res);
1325 unset($row);
1326 if (!empty($pred_db_array)) {
1327 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1328 . ' <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
1329 foreach ($pred_db_array as $current_db) {
1330 echo ' <option value="' . htmlspecialchars(str_replace('_', '\\_', $current_db)) . '">' . htmlspecialchars($current_db) . '</option>' . "\n";
1332 echo ' </select>' . "\n";
1334 echo ' <input type="text" id="text_dbname" name="dbname" class="textfield" />' . "\n";
1335 } else {
1336 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1337 . ' <label for="text_tablename">' . $strAddPrivilegesOnTbl . ':</label>' . "\n";
1338 if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', NULL, PMA_DBI_QUERY_STORE)) {
1339 $pred_tbl_array = array();
1340 while ($row = PMA_DBI_fetch_row($res)) {
1341 if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
1342 $pred_tbl_array[] = $row[0];
1345 PMA_DBI_free_result($res);
1346 unset($res);
1347 unset($row);
1348 if (!empty($pred_tbl_array)) {
1349 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1350 . ' <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
1351 foreach ($pred_tbl_array as $current_table) {
1352 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1354 echo ' </select>' . "\n";
1356 } else {
1357 unset($res);
1359 echo ' <input type="text" id="text_tablename" name="tablename" class="textfield" />' . "\n";
1361 echo ' <input type="submit" value="' . $strGo . '" />' . PMA_showHint($strEscapeWildcards) . "\n"
1362 . ' </form>' . "\n"
1363 . ' </td>' . "\n"
1364 . ' </tr>' . "\n"
1365 . ' </table><br />' . "\n"
1366 . ' </li>' . "\n";
1368 if (empty($dbname)) {
1369 echo ' <li>' . "\n"
1370 . ' <form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1371 . PMA_generate_common_hidden_inputs('', '', 3)
1372 . ' <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1373 . ' <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
1374 echo ' <b>' . $strChangePassword . '</b><br />' . "\n"
1375 . ' <table border="0" cellpadding="2" cellspacing="1">' . "\n"
1376 . ' <tr>' . "\n"
1377 . ' <td bgcolor="' . $cfg['BgcolorOne'] . '"><input type="radio" name="nopass" value="1" id="radio_nopass_1" onclick="pma_pw.value=\'\'; pma_pw2.value=\'\';" /></td>' . "\n"
1378 . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"><label for="radio_nopass_1">' . $strNoPassword . '</label></td>' . "\n"
1379 . ' </tr>' . "\n"
1380 . ' <tr>' . "\n"
1381 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="radio" name="nopass" value="0" id="radio_nopass_0" onclick="document.getElementById(\'pw_pma_pw\').focus();" /></td>' . "\n"
1382 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="radio_nopass_0">' . $strPassword . ':</label></td>' . "\n"
1383 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw" id="pw_pma_pw" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
1384 . ' </tr>' . "\n"
1385 . ' <tr>' . "\n"
1386 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">&nbsp;</td>' . "\n"
1387 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="pw_pma_pw2">' . $strReType . ':</label></td>' . "\n"
1388 . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw2" id="pw_pma_pw2" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
1389 . ' </tr>' . "\n"
1390 . ' <tr>' . "\n"
1391 . ' <td colspan="3" align="right">' . "\n"
1392 . ' <input type="submit" name="change_pw" value="' . $strGo . '" />' . "\n"
1393 . ' </td>' . "\n"
1394 . ' </tr>' . "\n"
1395 . ' </table>' . "\n"
1396 . ' </form>' . "\n"
1397 . ' </li>' . "\n"
1398 . ' <li>' . "\n"
1399 . ' <form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1400 . PMA_generate_common_hidden_inputs('', '', 3)
1401 . ' <input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1402 . ' <input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1403 . ' <b>' . $strChangeCopyUser . '</b><br />' . "\n"
1404 . ' <table border="0" cellpadding="2" cellspacing="1">' . "\n";
1405 PMA_displayLoginInformationFields('change', 3);
1406 echo ' </table>' . "\n"
1407 . ' ' . $strChangeCopyMode . '<br />' . "\n"
1408 . ' <input type="radio" name="mode" value="4" id="radio_mode_4" checked="checked" /><label for="radio_mode_4">' . "\n"
1409 . ' ' . $strChangeCopyModeCopy . "\n"
1410 . ' </label>' . "\n"
1411 . ' <br />' . "\n"
1412 . ' <input type="radio" name="mode" value="1" id="radio_mode_1" /><label for="radio_mode_1">' . "\n"
1413 . ' ' . $strChangeCopyModeJustDelete . "\n"
1414 . ' </label>' . "\n"
1415 . ' <br />' . "\n"
1416 . ' <input type="radio" name="mode" value="2" id="radio_mode_2" /><label for="radio_mode_2">' . "\n"
1417 . ' ' . $strChangeCopyModeRevoke . "\n"
1418 . ' </label>' . "\n"
1419 . ' <br />' . "\n"
1420 . ' <input type="radio" name="mode" value="3" id="radio_mode_3" /><label for="radio_mode_3">' . "\n"
1421 . ' ' . $strChangeCopyModeDeleteAndReload . "\n"
1422 . ' </label>' . "\n"
1423 . ' <br />' . "\n"
1424 . ' <input type="submit" name="change_copy" value="' . $strGo . '" />' . "\n"
1425 . ' </form>' . "\n"
1426 . ' </li>' . "\n";
1428 echo '</ul>' . "\n";
1430 } else if (!empty($adduser)) {
1431 // Add a new user
1432 $url_query .= '&amp;adduser=1';
1433 echo '<h2>' . "\n"
1434 . ($cfg['PropertiesIconic'] ? '<img src="' . $pmaThemeImage . 'b_usradd.png" width="16" height="16" border="0" hspace="2" align="middle" />' : '' )
1435 . ' ' . $strAddUser . "\n"
1436 . '</h2>' . "\n"
1437 . '<form name="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1438 . PMA_generate_common_hidden_inputs('', '', 1)
1439 . ' <table border="0" cellpadding="2" cellspacing="1">' . "\n"
1440 . ' <tr>' . "\n"
1441 . ' <th colspan="3">' . "\n"
1442 . ' ' . $strLoginInformation . "\n"
1443 . ' </th>' . "\n"
1444 . ' </tr>' . "\n";
1445 PMA_displayLoginInformationFields('new', 2);
1446 echo ' </table><br />' . "\n";
1447 PMA_displayPrivTable('*', '*', FALSE, 1);
1448 echo ' <br />' . "\n"
1449 . ' <input type="submit" name="adduser_submit" value="' . $strGo . '" />' . "\n"
1450 . '</form>' . "\n";
1451 } else {
1452 // check the privileges for a particular database.
1453 echo '<h2>' . "\n"
1454 . ($cfg['PropertiesIconic'] ? '<img src="' . $pmaThemeImage . 'b_usrcheck.png" width="16" height="16" border="0" hspace="2" align="middle" />' : '' )
1455 . ' ' . sprintf($strUsersHavingAccessToDb, '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
1456 . '</h2>' . "\n"
1457 . '<table border="0" cellpadding="2" cellspacing="1">' . "\n"
1458 . ' <tr>' . "\n"
1459 . ' <th>' . "\n"
1460 . ' &nbsp;' . $strUser . '&nbsp;' . "\n"
1461 . ' </th>' . "\n"
1462 . ' <th>' . "\n"
1463 . ' &nbsp;' . $strHost . '&nbsp;' . "\n"
1464 . ' </th>' . "\n"
1465 . ' <th>' . "\n"
1466 . ' &nbsp;' . $strType . '&nbsp;' . "\n"
1467 . ' </th>' . "\n"
1468 . ' <th>' . "\n"
1469 . ' &nbsp;' . $strPrivileges . '&nbsp;' . "\n"
1470 . ' </th>' . "\n"
1471 . ' <th>' . "\n"
1472 . ' &nbsp;' . $strGrantOption . '&nbsp;' . "\n"
1473 . ' </th>' . "\n"
1474 . ' <th>' . "\n"
1475 . ' &nbsp;' . $strAction . '&nbsp;' . "\n"
1476 . ' </th>' . "\n"
1477 . ' </tr>' . "\n";
1478 $useBgcolorOne = TRUE;
1479 unset($row);
1480 unset($row1);
1481 unset($row2);
1482 // now, we build the table...
1483 if (PMA_MYSQL_INT_VERSION >= 40000) {
1484 // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes
1485 // the job much easier here!
1487 $no = PMA_convert_using('N', 'quoted');
1489 $list_of_privileges = PMA_convert_using('Select_priv') . ' AS Select_priv, ' . PMA_convert_using('Insert_priv') . ' AS Insert_priv, ' . PMA_convert_using('Update_priv') . ' AS Update_priv, ' . PMA_convert_using('Delete_priv') . ' AS Delete_priv, ' . PMA_convert_using('Create_priv') . ' AS Create_priv, ' . PMA_convert_using('Drop_priv') . ' AS Drop_priv, ' . PMA_convert_using('Grant_priv') . ' AS Grant_priv, '. PMA_convert_using('References_priv') . ' AS References_priv';
1491 $list_of_compared_privileges = PMA_convert_using('Select_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Insert_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Update_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Delete_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Create_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Drop_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Grant_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('References_priv') . ' = ' . $no;
1493 $sql_query = '(SELECT ' . PMA_convert_using('User') . ' AS User,' . PMA_convert_using('Host') . ' AS Host,' . PMA_convert_using('Db') . ' AS Db,' . $list_of_privileges . ' FROM `db` WHERE ' . PMA_convert_using($checkprivs, 'quoted') . ' LIKE ' . PMA_convert_using('Db') . ' AND NOT (' . $list_of_compared_privileges. ')) UNION (SELECT ' . PMA_convert_using('User') . ' AS User, ' . PMA_convert_using('Host') . ' AS Host, ' . PMA_convert_using('*', 'quoted') . ' AS Db, ' . $list_of_privileges . ' FROM `user` WHERE NOT (' . $list_of_compared_privileges . ')) ORDER BY User ASC, Host ASC, Db ASC;';
1494 $res = PMA_DBI_query($sql_query);
1496 $row = PMA_DBI_fetch_assoc($res);
1497 if ($row) {
1498 $found = TRUE;
1500 } else {
1501 // With MySQL 3, we need 2 seperate queries here.
1502 $sql_query = 'SELECT * FROM `user` WHERE NOT (`Select_priv` = \'N\' AND `Insert_priv` = \'N\' AND `Update_priv` = \'N\' AND `Delete_priv` = \'N\' AND `Create_priv` = \'N\' AND `Drop_priv` = \'N\' AND `Grant_priv` = \'N\' AND `References_priv` = \'N\') ORDER BY `User` ASC, `Host` ASC;';
1503 $res1 = PMA_DBI_query($sql_query);
1504 $row1 = PMA_DBI_fetch_assoc($res1);
1505 $sql_query = 'SELECT * FROM `db` WHERE \'' . $checkprivs . '\' LIKE `Db` AND NOT (`Select_priv` = \'N\' AND `Insert_priv` = \'N\' AND `Update_priv` = \'N\' AND `Delete_priv` = \'N\' AND `Create_priv` = \'N\' AND `Drop_priv` = \'N\' AND `Grant_priv` = \'N\' AND `References_priv` = \'N\') ORDER BY `User` ASC, `Host` ASC;';
1506 $res2 = PMA_DBI_query($sql_query);
1507 $row2 = PMA_DBI_fetch_assoc($res2);
1508 if ($row1 || $row2) {
1509 $found = TRUE;
1511 } // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ...
1512 if ($found) {
1513 while (TRUE) {
1514 // prepare the current user
1515 if (PMA_MYSQL_INT_VERSION >= 40000) {
1516 $current_privileges = array();
1517 $current_user = $row['User'];
1518 $current_host = $row['Host'];
1519 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
1520 $current_privileges[] = $row;
1521 $row = PMA_DBI_fetch_assoc($res);
1523 } else {
1524 $current_privileges = array();
1525 if ($row1 && (!$row2 || ($row1['User'] < $row2['User'] || ($row1['User'] == $row2['User'] && $row1['Host'] <= $row2['Host'])))) {
1526 $current_user = $row1['User'];
1527 $current_host = $row1['Host'];
1528 $current_privileges = array($row1);
1529 $row1 = PMA_DBI_fetch_assoc($res1);
1530 } else {
1531 $current_user = $row2['User'];
1532 $current_host = $row2['Host'];
1533 $current_privileges = array();
1535 while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) {
1536 $current_privileges[] = $row2;
1537 $row2 = PMA_DBI_fetch_assoc($res2);
1540 echo ' <tr>' . "\n"
1541 . ' <td';
1542 if (count($current_privileges) > 1) {
1543 echo ' rowspan="' . count($current_privileges) . '"';
1545 echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1546 . ' ' . (empty($current_user) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($current_user)) . "\n"
1547 . ' </td>' . "\n"
1548 . ' <td';
1549 if (count($current_privileges) > 1) {
1550 echo ' rowspan="' . count($current_privileges) . '"';
1552 echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1553 . ' ' . htmlspecialchars($current_host) . "\n"
1554 . ' </td>' . "\n";
1555 foreach ($current_privileges as $current) {
1556 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1557 . ' ';
1558 if (!isset($current['Db']) || $current['Db'] == '*') {
1559 echo $strGlobal;
1560 } else if ($current['Db'] == $checkprivs) {
1561 echo $strDbSpecific;
1562 } else {
1563 echo $strWildcard, ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
1565 echo "\n"
1566 . ' </td>' . "\n"
1567 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1568 . ' <tt>' . "\n"
1569 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
1570 . ' <tt>' . "\n"
1571 . ' </td>' . "\n"
1572 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1573 . ' ' . ($current['Grant_priv'] == 'Y' ? $strYes : $strNo) . "\n"
1574 . ' </td>' . "\n"
1575 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
1576 . ' <a href="./server_privileges.php?' . $url_query . '&amp;username=' . urlencode($current_user) . '&amp;hostname=' . urlencode($current_host) . (!isset($current['Db']) || $current['Db'] == '*' ? '' : '&amp;dbname=' . urlencode($current['Db'])) . '">' . "\n"
1577 . ' ' . $strEdit . "\n"
1578 . ' </a>' . "\n"
1579 . ' </td>' . "\n"
1580 . ' </tr>' . "\n";
1582 if (empty($row) && empty($row1) && empty($row2)) {
1583 break;
1585 $useBgcolorOne = !$useBgcolorOne;
1587 } else {
1588 echo ' <tr>' . "\n"
1589 . ' <td colspan="6" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
1590 . ' ' . $strNoUsersFound . "\n"
1591 . ' </td>' . "\n"
1592 . ' </tr>' . "\n";
1594 echo '</table>' . "\n";
1595 } // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ...
1599 * Displays the footer
1601 echo "\n\n";
1602 require_once('./footer.inc.php');