oops
[phpmyadmin/crack.git] / main.php3
blob26d81d394d13d934a6a6996ca610ecc462a4860a
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Don't display the page heading
7 */
8 define('PMA_DISPLAY_HEADING', 0);
10 /**
11 * Gets some core libraries and displays a top message if required
13 if (!defined('PMA_GRAB_GLOBALS_INCLUDED')) {
14 include('./libraries/grab_globals.lib.php3');
16 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
17 include('./libraries/common.lib.php3');
19 // Puts the language to use in a cookie that will expire in 30 days
20 if (!isset($pma_uri_parts)) {
21 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
22 $cookie_path = substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/'));
23 $is_https = ($pma_uri_parts['scheme'] == 'https') ? 1 : 0;
25 setcookie('lang', $lang, time() + 60*60*24*30, $cookie_path, '', $is_https);
26 // Defines the "item" image depending on text direction
27 $item_img = 'images/item_' . $text_dir . '.gif';
28 // Handles some variables that may have been sent by the calling script
29 if (isset($db)) {
30 unset($db);
32 if (isset($table)) {
33 unset($table);
35 $show_query = '1';
36 require('./header.inc.php3');
37 if (isset($message)) {
38 PMA_showMessage($message);
40 else if (isset($reload) && $reload) {
41 // Reloads the navigation frame via JavaScript if required
42 echo "\n";
44 <script type="text/javascript" language="javascript1.2">
45 <!--
46 window.parent.frames['nav'].location.replace('./left.php3?lang=<?php echo $lang; ?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>');
47 //-->
48 </script>
49 <?php
51 echo "\n";
54 /**
55 * Displays the welcome message and the server informations
58 <h1><?php echo sprintf($strWelcome, ' phpMyAdmin ' . PMA_VERSION); ?></h1>
60 <?php
61 // Don't display server info if $server == 0 (no server selected)
62 // loic1: modified in order to have a valid words order whatever is the
63 // language used
64 if ($server > 0) {
65 // robbat2: Use the verbose name of the server instead of the hostname
66 // if a value is set
67 if(!empty($cfg['Server']['verbose'])) {
68 $server_info = $cfg['Server']['verbose'];
69 } else {
70 $server_info = $cfg['Server']['host'];
72 $server_info .= (empty($cfg['Server']['port']) ? '' : ':' . $cfg['Server']['port']);
73 // loic1: skip this because it's not a so good idea to display sockets
74 // used to everybody
75 // if (!empty($cfg['Server']['socket']) && PMA_PHP_INT_VERSION >= 30010) {
76 // $server_info .= ':' . $cfg['Server']['socket'];
77 // }
78 $local_query = 'SELECT VERSION() as version, USER() as user';
79 $res = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, '');
80 $mysql_cur_user_and_host = PMA_mysql_result($res, 0, 'user');
81 $mysql_cur_user = substr($mysql_cur_user_and_host, 0, strrpos($mysql_cur_user_and_host, '@'));
83 $full_string = str_replace('%pma_s1%', PMA_mysql_result($res, 0, 'version'), $strMySQLServerProcess);
84 $full_string = str_replace('%pma_s2%', $server_info, $full_string);
85 $full_string = str_replace('%pma_s3%', $mysql_cur_user_and_host, $full_string);
87 echo '<p><b>' . $full_string . '</b></p><br />' . "\n";
88 } // end if
91 /**
92 * Reload mysql (flush privileges)
94 if (($server > 0) && isset($mode) && ($mode == 'reload')) {
95 $result = PMA_mysql_query('FLUSH PRIVILEGES'); // Debug: or PMA_mysqlDie('', 'FLUSH PRIVILEGES', FALSE, 'main.php3?lang=' . $lang . '&amp;server=' . $server);
96 echo '<p><b>';
97 if ($result != 0) {
98 echo $strMySQLReloaded;
99 } else {
100 echo $strReloadFailed;
102 echo '</b></p>' . "\n\n";
107 * Displays the MySQL servers choice form
109 if ($server == 0 || count($cfg['Servers']) > 1) {
111 <!-- MySQL servers choice form -->
112 <table>
113 <tr>
114 <th><?php echo $strServerChoice; ?></th>
115 </tr>
116 <tr>
117 <td>
118 <form method="post" action="index.php3" target="_parent">
119 <select name="server">
120 <?php
121 echo "\n";
122 reset($cfg['Servers']);
123 while (list($key, $val) = each($cfg['Servers'])) {
124 if (!empty($val['host'])) {
125 echo ' <option value="' . $key . '"';
126 if (!empty($server) && ($server == $key)) {
127 echo ' selected="selected"';
129 echo '>';
130 if (!empty($val['verbose'])) {
131 echo $val['verbose'];
132 } else {
133 echo $val['host'];
134 if (!empty($val['port'])) {
135 echo ':' . $val['port'];
137 // loic1: skip this because it's not a so good idea to display
138 // sockets used to everybody
139 // if (!empty($val['socket']) && PMA_PHP_INT_VERSION >= 30010) {
140 // echo ':' . $val['socket'];
141 // }
143 // loic1: if 'only_db' is an array and there is more than one
144 // value, displaying such informations may not be a so good
145 // idea
146 if (!empty($val['only_db'])) {
147 echo ' - ' . (is_array($val['only_db']) ? implode(', ', $val['only_db']) : $val['only_db']);
149 if (!empty($val['user']) && ($val['auth_type'] == 'config')) {
150 echo ' (' . $val['user'] . ')';
152 echo '&nbsp;</option>' . "\n";
153 } // end if (!empty($val['host']))
154 } // end while
156 </select>
157 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
158 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
159 <input type="submit" value="<?php echo $strGo; ?>" />
160 </form>
161 </td>
162 </tr>
163 </table>
164 <br />
165 <?php
166 } // end of the servers choice form
169 <!-- MySQL and phpMyAdmin related links -->
170 <table>
171 <tr>
173 <?php
175 * Displays the mysql server related links
177 $is_superuser = FALSE;
178 if ($server > 0) {
179 // Get user's global privileges ($dbh and $userlink are links to MySQL
180 // defined in the "common.lib.php3" library)
181 $is_create_priv = FALSE;
182 // $is_process_priv = FALSE;
183 $is_reload_priv = FALSE;
184 $is_superuser = @PMA_mysql_query('USE mysql', $userlink);
185 if ($dbh) {
186 $local_query = 'SELECT Create_priv, Process_priv, Reload_priv FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\'';
187 $rs_usr = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
188 if ($rs_usr) {
189 while ($result_usr = PMA_mysql_fetch_array($rs_usr)) {
190 if (!$is_create_priv) {
191 $is_create_priv = ($result_usr['Create_priv'] == 'Y');
193 /* 02-12-09 rabus: Every user has access to the process list -
194 at least to its own :-)
195 if (!$is_process_priv) {
196 $is_process_priv = ($result_usr['Process_priv'] == 'Y');
199 if (!$is_reload_priv) {
200 $is_reload_priv = ($result_usr['Reload_priv'] == 'Y');
202 } // end while
203 mysql_free_result($rs_usr);
204 } // end if
205 } // end if
207 // If the user has Create priv on a inexistant db, show him in the dialog
208 // the first inexistant db name that we find, in most cases it's probably
209 // the one he just dropped :)
210 if (!$is_create_priv) {
211 $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\'';
212 $rs_usr = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
213 if ($rs_usr) {
214 $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards
215 $re1 = '(^|[^\])(\\\)+'; // escaped wildcards
216 while ($row = PMA_mysql_fetch_array($rs_usr)) {
217 if (ereg($re0 . '(%|_)', $row['Db'])
218 || (!PMA_mysql_select_db(ereg_replace($re1 . '(%|_)', '\\1\\3', $row['Db']), $userlink) && @mysql_errno() != 1044)) {
219 $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $row['Db']));
220 $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create);
221 $is_create_priv = TRUE;
222 break;
223 } // end if
224 } // end while
225 mysql_free_result($rs_usr);
226 } // end if
227 else if (PMA_MYSQL_INT_VERSION >= 32304) {
228 // Finally, let's try to get the user's privileges by using SHOW
229 // GRANTS...
230 // Maybe we'll find a little CREATE priv there :)
231 $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user_and_host;
232 $rs_usr = PMA_mysql_query($local_query, $dbh);
233 if (!$rs_usr) {
234 // OK, now we'd have to guess the user's hostname, but we
235 // only try out the 'username'@'%' case.
236 $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user;
237 $rs_usr = PMA_mysql_query($local_query, $dbh);
239 if ($rs_usr) {
240 $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards
241 $re1 = '(^|[^\])(\\\)+'; // escaped wildcards
242 while ($row = PMA_mysql_fetch_row($rs_usr)) {
243 $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4,(strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4));
244 $show_grants_str = substr($row[0],6,(strpos($row[0],' ON ')-6));
245 if (($show_grants_str == 'ALL') || ($show_grants_str == 'ALL PRIVILEGES') || ($show_grants_str == 'CREATE') || strpos($show_grants_str, 'CREATE')) {
246 if ($show_grants_dbname == '*') {
247 $is_create_priv = TRUE;
248 $db_to_create = '';
249 break;
250 } // end if
251 else if (ereg($re0 . '%|_', $show_grants_dbname) || !PMA_mysql_select_db($show_grants_dbname, $userlink) && @mysql_errno() != 1044) {
252 $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $show_grants_dbname));
253 $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create);
254 $is_create_priv = TRUE;
255 break;
256 } // end elseif
257 } // end if
258 } // end while
259 unset($show_grants_dbname);
260 unset($show_grants_str);
261 mysql_free_result($rs_usr);
262 } // end if
263 } // end elseif
264 } // end if
265 else {
266 $db_to_create = '';
267 } // end else
269 if (!$cfg['SuggestDBName']) {
270 $db_to_create = '';
273 $common_url_query = 'lang=' . $lang . '&amp;convcharset=' . $convcharset . '&amp;server=' . $server;
275 if ($is_superuser) {
276 $cfg['ShowMysqlInfo'] = TRUE;
277 $cfg['ShowMysqlVars'] = TRUE;
278 $cfg['ShowChgPassword'] = TRUE;
280 if ($cfg['Server']['auth_type'] == 'config') {
281 $cfg['ShowChgPassword'] = FALSE;
284 // loic1: Displays the MySQL column only if at least one feature has to be
285 // displayed
286 if ($is_superuser || $is_create_priv || $is_process_priv || $is_reload_priv
287 || $cfg['ShowMysqlInfo'] || $cfg['ShowMysqlVars'] || $cfg['ShowChgPassword']
288 || $cfg['Server']['auth_type'] != 'config') {
290 <!-- MySQL server related links -->
291 <td valign="top" align="<?php echo $cell_align_left; ?>">
292 <table>
293 <tr>
294 <th colspan="2">&nbsp;&nbsp;MySQL</th>
295 </tr>
296 <?php
297 // The user is allowed to create a db
298 if ($is_create_priv) {
299 echo "\n";
301 <!-- db creation form -->
302 <tr>
303 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
304 <td>
305 <form method="post" action="db_create.php3">
306 <?php echo $strCreateNewDatabase . '&nbsp;' . PMA_showMySQLDocu('Reference', 'CREATE_DATABASE'); ?><br />
307 <input type="hidden" name="server" value="<?php echo $server; ?>" />
308 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
309 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
310 <input type="hidden" name="reload" value="1" />
311 <input type="text" name="db" value="<?php echo $db_to_create; ?>" maxlength="64" class="textfield" />
312 <input type="submit" value="<?php echo $strCreate; ?>" />
313 </form>
314 </td>
315 </tr>
316 <?php
317 } else {
318 echo "\n";
320 <!-- db creation no privileges message -->
321 <tr>
322 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
323 <td>
324 <?php echo $strCreateNewDatabase . ':&nbsp;' . PMA_showMySQLDocu('Reference', 'CREATE_DATABASE'); ?><br />
325 <?php echo '<i>' . $strNoPrivileges .'</i>'; ?><br />
326 </td>
327 </tr>
328 <?php
329 } // end create db form or message
330 echo "\n";
332 // Server related links
334 <!-- server-related links -->
335 <?php
336 if ($cfg['ShowMysqlInfo']) {
337 echo "\n";
339 <tr>
340 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
341 <td>
342 <a href="./server_status.php3?<?php echo $common_url_query; ?>">
343 <?php echo $strMySQLShowStatus . "\n"; ?>
344 </a>
345 </td>
346 </tr>
347 <?php
348 } // end if
349 if ($cfg['ShowMysqlVars']) {
350 echo "\n";
352 <tr>
353 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
354 <td>
355 <a href="./server_variables.php3?<?php echo $common_url_query; ?>">
356 <?php echo $strMySQLShowVars;?></a>&nbsp;
357 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'SHOW_VARIABLES') . "\n"; ?>
358 </td>
359 </tr>
360 <?php
363 // if ($is_process_priv) {
364 echo "\n";
366 <tr>
367 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
368 <td>
369 <a href="./server_processlist.php3?<?php echo $common_url_query; ?>">
370 <?php echo $strMySQLShowProcess; ?></a>&nbsp;
371 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'SHOW_PROCESSLIST') . "\n"; ?>
372 </td>
373 </tr>
374 <?php
375 // } // end if
377 if ($is_reload_priv) {
378 echo "\n";
380 <tr>
381 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
382 <td>
383 <a href="main.php3?<?php echo $common_url_query; ?>&amp;mode=reload">
384 <?php echo $strReloadMySQL; ?></a>&nbsp;
385 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n"; ?>
386 </td>
387 </tr>
388 <?php
391 if ($is_superuser) {
392 echo "\n";
394 <tr>
395 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
396 <td>
397 <a href="user_details.php3?<?php echo $common_url_query; ?>&amp;db=mysql&amp;table=user">
398 <?php echo $strUsers; ?></a>&nbsp;
399 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'Privilege_system') . "\n"; ?>
400 </td>
401 </tr>
402 <?php
403 if (PMA_MYSQL_INT_VERSION >= 32303) {
404 echo "\n";
406 <tr>
407 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
408 <td>
409 <a href="db_stats.php3?<?php echo $common_url_query; ?>">
410 <?php echo $strDatabasesStats; ?></a>
411 </td>
412 </tr>
413 <?php
417 // Change password (needs another message)
418 if ($cfg['ShowChgPassword']) {
419 echo "\n";
421 <tr>
422 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
423 <td>
424 <a href="user_password.php3?<?php echo $common_url_query; ?>">
425 <?php echo ($strChangePassword); ?></a>
426 </td>
427 </tr>
428 <?php
429 } // end if
431 // Logout for advanced authentication
432 if ($cfg['Server']['auth_type'] != 'config') {
433 $http_logout = ($cfg['Server']['auth_type'] == 'http')
434 ? "\n" . ' <a href="./Documentation.html#login_bug" target="documentation">(*)</a>'
435 : '';
436 echo "\n";
438 <tr>
439 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
440 <td>
441 <a href="index.php3?<?php echo $common_url_query; ?>&amp;old_usr=<?php echo urlencode($PHP_AUTH_USER); ?>" target="_parent">
442 <b><?php echo $strLogout; ?></b></a>&nbsp;<?php echo $http_logout . "\n"; ?>
443 </td>
444 </tr>
445 <?php
446 } // end if
447 echo "\n";
449 </table>
450 </td>
452 <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
453 <?php
454 } // end if
455 } // end of if ($server > 0)
456 echo "\n";
460 * Displays the phpMyAdmin related links
464 <!-- phpMyAdmin related links -->
465 <td valign="top" align="<?php echo $cell_align_left; ?>">
466 <table>
467 <tr>
468 <th colspan="2">&nbsp;&nbsp;phpMyAdmin</th>
469 </tr>
471 <?php
472 // Displays language selection combo
473 if (empty($cfg['Lang'])) {
475 <!-- Language Selection -->
476 <tr>
477 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
478 <td nowrap="nowrap">
479 <form method="post" action="index.php3" target="_parent">
480 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
481 <input type="hidden" name="server" value="<?php echo $server; ?>" />
482 Language <a href="./translators.html" target="documentation">(*)</a>:
483 <select name="lang" dir="ltr" onchange="this.form.submit();">
484 <?php
485 echo "\n";
488 * Sorts available languages by their true names
490 * @param array the array to be sorted
491 * @param mixed a required parameter
493 * @return the sorted array
495 * @access private
497 function PMA_cmp(&$a, $b)
499 return (strcmp($a[1], $b[1]));
500 } // end of the 'PMA_cmp()' function
502 uasort($available_languages, 'PMA_cmp');
503 reset($available_languages);
504 while (list($id, $tmplang) = each($available_languages)) {
505 $lang_name = ucfirst(substr(strstr($tmplang[0], '|'), 1));
506 if ($lang == $id) {
507 $selected = ' selected="selected"';
508 } else {
509 $selected = '';
511 echo ' ';
512 echo '<option value="' . $id . '"' . $selected . '>' . $lang_name . ' (' . $id . ')</option>' . "\n";
515 </select>
516 <noscript><input type="submit" value="Go" /></noscript>
517 </form>
518 </td>
519 </tr>
520 <?php
523 if (isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding']
524 && $allow_recoding) {
525 echo "\n";
527 <!-- Charset Selection -->
528 <tr>
529 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
530 <td nowrap="nowrap">
531 <form method="post" action="index.php3" target="_parent">
532 <input type="hidden" name="server" value="<?php echo $server; ?>" />
533 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
534 <?php echo $strMySQLCharset;?>:
535 <select name="convcharset" dir="ltr" onchange="this.form.submit();">
536 <?php
537 echo "\n";
538 reset($cfg['AvailableCharsets']);
539 while (list($id, $tmpcharset) = each($cfg['AvailableCharsets'])) {
540 if ($convcharset == $tmpcharset) {
541 $selected = ' selected="selected"';
542 } else {
543 $selected = '';
545 echo ' ';
546 echo '<option value="' . $tmpcharset . '"' . $selected . '>' . $tmpcharset . '</option>' . "\n";
549 </select>
550 <noscript><input type="submit" value="Go" /></noscript>
551 </form>
552 </td>
553 </tr>
554 <?php
556 echo "\n";
559 <!-- Documentation -->
560 <tr>
561 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
562 <td>
563 <a href="Documentation.html" target="documentation"><b><?php echo $strPmaDocumentation; ?></b></a>
564 </td>
565 </tr>
567 <?php
568 if ($is_superuser || $cfg['ShowPhpInfo']) {
570 <!-- PHP Information -->
571 <tr>
572 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
573 <td>
574 <a href="phpinfo.php3" target="_new"><?php echo $strShowPHPInfo; ?></a>
575 </td>
576 </tr>
577 <?php
579 echo "\n";
582 <!-- phpMyAdmin related urls -->
583 <tr>
584 <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
585 <td>
586 <a href="http://www.phpMyAdmin.net/" target="_new"><?php echo $strHomepageOfficial; ?></a><br />
587 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href="ChangeLog" target="_new">ChangeLog</a>]
588 &nbsp;&nbsp;&nbsp;[<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpmyadmin/phpMyAdmin/" target="_new">CVS</a>]
589 &nbsp;&nbsp;&nbsp;[<a href="http://sourceforge.net/mail/?group_id=23067" target="_new">Lists</a>]
590 </td>
591 </tr>
592 </table>
593 </td>
595 </tr>
596 </table>
599 <?php
601 * Displays the "empty $cfg['PmaAbsoluteUri'] warning"
603 if ($display_pmaAbsoluteUri_warning) {
604 echo '<p class="warning">' . $strPmaUriError . '</p>' . "\n";
608 * Warning if using the default MySQL privileged account
610 if ($server != 0
611 && $cfg['Server']['user'] == 'root'
612 && $cfg['Server']['password'] == '') {
613 echo '<p class="warning">' . $strInsecureMySQL . '</p>' . "\n";
617 * Warning for PHP 4.2.3
620 if (PMA_PHP_INT_VERSION == 40203 && @extension_loaded('mbstring')) {
621 echo '<p class="warning">' . $strPHP40203 . '</p>' . "\n";
625 * Displays the footer
627 echo "\n";
628 require('./footer.inc.php3');