do not allow root user without password unless explicitly enabled by AllowEmptyRoot
[phpmyadmin/crack.git] / libraries / common.inc.php
blob8ae6ed38375c0e7b3afcb104c3199116e4b1802d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Misc stuff and REQUIRED by ALL the scripts.
5 * MUST be included by every script
7 * Among other things, it contains the advanced authentication work.
9 * Order of sections for common.inc.php:
11 * the authentication libraries must be before the connection to db
13 * ... so the required order is:
15 * LABEL_variables_init
16 * - initialize some variables always needed
17 * LABEL_parsing_config_file
18 * - parsing of the configuration file
19 * LABEL_loading_language_file
20 * - loading language file
21 * LABEL_setup_servers
22 * - check and setup configured servers
23 * LABEL_theme_setup
24 * - setting up themes
26 * - load of MySQL extension (if necessary)
27 * - loading of an authentication library
28 * - db connection
29 * - authentication work
31 * @version $Id$
34 /**
35 * the error handler
37 require_once './libraries/Error_Handler.class.php';
39 /**
40 * initialize the error handler
42 $GLOBALS['error_handler'] = new PMA_Error_Handler();
43 $cfg['Error_Handler']['display'] = TRUE;
45 // at this point PMA_PHP_INT_VERSION is not yet defined
46 if (version_compare(phpversion(), '6', 'lt')) {
47 /**
48 * Avoid object cloning errors
50 @ini_set('zend.ze1_compatibility_mode', false);
52 /**
53 * Avoid problems with magic_quotes_runtime
55 @ini_set('magic_quotes_runtime', false);
58 /**
59 * for verification in all procedural scripts under libraries
61 define('PHPMYADMIN', true);
63 /**
64 * core functions
66 require_once './libraries/core.lib.php';
68 /**
69 * Input sanitizing
71 require_once './libraries/sanitizing.lib.php';
73 /**
74 * the PMA_Theme class
75 * (this one is the first to produce a fatal error under PHP < 5)
76 * and let's put here the same minimum requirement as in our doc.
78 if (version_compare(PHP_VERSION, '5.2.0') < 0 ) {
79 PMA_fatalError('strUpgrade', array('PHP', '5.2'));
82 require_once './libraries/Theme.class.php';
84 /**
85 * the PMA_Theme_Manager class
87 require_once './libraries/Theme_Manager.class.php';
89 /**
90 * the PMA_Config class
92 require_once './libraries/Config.class.php';
94 /**
95 * the PMA_Table class
97 require_once './libraries/Table.class.php';
99 if (!defined('PMA_MINIMUM_COMMON')) {
101 * common functions
103 require_once './libraries/common.lib.php';
106 * Java script escaping.
108 require_once './libraries/js_escape.lib.php';
111 * Include URL/hidden inputs generating.
113 require_once './libraries/url_generating.lib.php';
116 /******************************************************************************/
117 /* start procedural code label_start_procedural */
120 * protect against possible exploits - there is no need to have so much variables
122 if (count($_REQUEST) > 1000) {
123 die('possible exploit');
127 * Check for numeric keys
128 * (if register_globals is on, numeric key can be found in $GLOBALS)
130 foreach ($GLOBALS as $key => $dummy) {
131 if (is_numeric($key)) {
132 die('numeric key detected');
135 unset($dummy);
138 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
139 * and provide a clean PHP_SELF here
141 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
142 $_PATH_INFO = PMA_getenv('PATH_INFO');
143 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
144 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
145 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
146 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
149 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
153 * just to be sure there was no import (registering) before here
154 * we empty the global space (but avoid unsetting $variables_list
155 * and $key in the foreach(), we still need them!)
157 $variables_whitelist = array (
158 'GLOBALS',
159 '_SERVER',
160 '_GET',
161 '_POST',
162 '_REQUEST',
163 '_FILES',
164 '_ENV',
165 '_COOKIE',
166 '_SESSION',
167 'error_handler',
168 'PMA_PHP_SELF',
169 'variables_whitelist',
170 'key'
173 foreach (get_defined_vars() as $key => $value) {
174 if (! in_array($key, $variables_whitelist)) {
175 unset($$key);
178 unset($key, $value, $variables_whitelist);
182 * Subforms - some functions need to be called by form, cause of the limited URL
183 * length, but if this functions inside another form you cannot just open a new
184 * form - so phpMyAdmin uses 'arrays' inside this form
186 * <code>
187 * <form ...>
188 * ... main form elments ...
189 * <input type="hidden" name="subform[action1][id]" value="1" />
190 * ... other subform data ...
191 * <input type="submit" name="usesubform[action1]" value="do action1" />
192 * ... other subforms ...
193 * <input type="hidden" name="subform[actionX][id]" value="X" />
194 * ... other subform data ...
195 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
196 * ... main form elments ...
197 * <input type="submit" name="main_action" value="submit form" />
198 * </form>
199 * </code
201 * so we now check if a subform is submitted
203 $__redirect = null;
204 if (isset($_POST['usesubform'])) {
205 // if a subform is present and should be used
206 // the rest of the form is deprecated
207 $subform_id = key($_POST['usesubform']);
208 $subform = $_POST['subform'][$subform_id];
209 $_POST = $subform;
210 $_REQUEST = $subform;
212 * some subforms need another page than the main form, so we will just
213 * include this page at the end of this script - we use $__redirect to
214 * track this
216 if (isset($_POST['redirect'])
217 && $_POST['redirect'] != basename($PMA_PHP_SELF)) {
218 $__redirect = $_POST['redirect'];
219 unset($_POST['redirect']);
221 unset($subform_id, $subform);
222 } else {
223 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
224 // because another application for the same domain could have set
225 // a cookie (with a compatible path) that overrides a variable
226 // we expect from GET or POST.
227 // We'll refer to cookies explicitly with the $_COOKIE syntax.
228 $_REQUEST = array_merge($_GET, $_POST);
230 // end check if a subform is submitted
232 // remove quotes added by php
233 // (get_magic_quotes_gpc() is deprecated in PHP 5.3, but compare with 5.2.99
234 // to be able to test with 5.3.0-dev)
235 if (function_exists('get_magic_quotes_gpc') && -1 == version_compare(PHP_VERSION, '5.2.99') && get_magic_quotes_gpc()) {
236 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
237 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
238 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
239 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
243 * clean cookies on upgrade
244 * when changing something related to PMA cookies, increment the cookie version
246 $pma_cookie_version = 4;
247 if (isset($_COOKIE)
248 && (isset($_COOKIE['pmaCookieVer'])
249 && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
250 // delete all cookies
251 foreach($_COOKIE as $cookie_name => $tmp) {
252 PMA_removeCookie($cookie_name);
254 $_COOKIE = array();
255 PMA_setCookie('pmaCookieVer', $pma_cookie_version);
259 * include deprecated grab_globals only if required
261 if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
262 require './libraries/grab_globals.lib.php';
266 * check timezone setting
267 * this could produce an E_STRICT - but only once,
268 * if not done here it will produce E_STRICT on every date/time function
270 * @todo need to decide how we should handle this (without @)
272 date_default_timezone_set(@date_default_timezone_get());
275 * include session handling after the globals, to prevent overwriting
277 require_once './libraries/session.inc.php';
280 * init some variables LABEL_variables_init
284 * holds parameters to be passed to next page
285 * @global array $GLOBALS['url_params']
287 $GLOBALS['url_params'] = array();
290 * the whitelist for $GLOBALS['goto']
291 * @global array $goto_whitelist
293 $goto_whitelist = array(
294 //'browse_foreigners.php',
295 //'calendar.php',
296 //'changelog.php',
297 //'chk_rel.php',
298 'db_create.php',
299 'db_datadict.php',
300 'db_sql.php',
301 'db_export.php',
302 'db_importdocsql.php',
303 'db_qbe.php',
304 'db_structure.php',
305 'db_import.php',
306 'db_operations.php',
307 'db_printview.php',
308 'db_search.php',
309 //'Documentation.html',
310 //'error.php',
311 'export.php',
312 'import.php',
313 //'index.php',
314 //'navigation.php',
315 //'license.php',
316 'main.php',
317 'pdf_pages.php',
318 'pdf_schema.php',
319 //'phpinfo.php',
320 'querywindow.php',
321 //'readme.php',
322 'server_binlog.php',
323 'server_collations.php',
324 'server_databases.php',
325 'server_engines.php',
326 'server_export.php',
327 'server_import.php',
328 'server_privileges.php',
329 'server_processlist.php',
330 'server_sql.php',
331 'server_status.php',
332 'server_variables.php',
333 'sql.php',
334 'tbl_addfield.php',
335 'tbl_alter.php',
336 'tbl_change.php',
337 'tbl_create.php',
338 'tbl_import.php',
339 'tbl_indexes.php',
340 'tbl_move_copy.php',
341 'tbl_printview.php',
342 'tbl_sql.php',
343 'tbl_export.php',
344 'tbl_operations.php',
345 'tbl_structure.php',
346 'tbl_relation.php',
347 'tbl_replace.php',
348 'tbl_row_action.php',
349 'tbl_select.php',
350 //'themes.php',
351 'transformation_overview.php',
352 'transformation_wrapper.php',
353 'translators.html',
354 'user_password.php',
358 * check $__redirect against whitelist
360 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
361 $__redirect = null;
365 * holds page that should be displayed
366 * @global string $GLOBALS['goto']
368 $GLOBALS['goto'] = '';
369 // Security fix: disallow accessing serious server files via "?goto="
370 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
371 $GLOBALS['goto'] = $_REQUEST['goto'];
372 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
373 } else {
374 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
378 * returning page
379 * @global string $GLOBALS['back']
381 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
382 $GLOBALS['back'] = $_REQUEST['back'];
383 } else {
384 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
388 * Check whether user supplied token is valid, if not remove any possibly
389 * dangerous stuff from request.
391 * remember that some objects in the session with session_start and __wakeup()
392 * could access this variables before we reach this point
393 * f.e. PMA_Config: fontsize
395 * @todo variables should be handled by their respective owners (objects)
396 * f.e. lang, server, convcharset, collation_connection in PMA_Config
398 if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
400 * List of parameters which are allowed from unsafe source
402 $allow_list = array(
403 /* needed for direct access, see FAQ 1.34
404 * also, server needed for cookie login screen (multi-server)
406 'server', 'db', 'table', 'target',
407 /* Session ID */
408 'phpMyAdmin',
409 /* Cookie preferences */
410 'pma_lang', 'pma_charset', 'pma_collation_connection',
411 /* Possible login form */
412 'pma_servername', 'pma_username', 'pma_password',
413 /* rajk - for playing blobstreamable media */
414 'media_type', 'bs_reference',
415 /* rajk - for changing BLOB repository file MIME type */
416 'bs_db', 'bs_table', 'bs_ref', 'bs_new_mime_type'
419 * Require cleanup functions
421 require_once './libraries/cleanup.lib.php';
423 * Do actual cleanup
425 PMA_remove_request_vars($allow_list);
431 * @global string $GLOBALS['convcharset']
432 * @see select_lang.lib.php
434 if (isset($_REQUEST['convcharset'])) {
435 $GLOBALS['convcharset'] = strip_tags($_REQUEST['convcharset']);
439 * current selected database
440 * @global string $GLOBALS['db']
442 $GLOBALS['db'] = '';
443 if (PMA_isValid($_REQUEST['db'])) {
444 // can we strip tags from this?
445 // only \ and / is not allowed in db names for MySQL
446 $GLOBALS['db'] = $_REQUEST['db'];
447 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
451 * current selected table
452 * @global string $GLOBALS['table']
454 $GLOBALS['table'] = '';
455 if (PMA_isValid($_REQUEST['table'])) {
456 // can we strip tags from this?
457 // only \ and / is not allowed in table names for MySQL
458 $GLOBALS['table'] = $_REQUEST['table'];
459 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
463 * SQL query to be executed
464 * @global string $GLOBALS['sql_query']
466 $GLOBALS['sql_query'] = '';
467 if (PMA_isValid($_REQUEST['sql_query'])) {
468 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
472 * avoid problems in phpmyadmin.css.php in some cases
473 * @global string $js_frame
475 $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
477 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
478 //$_REQUEST['server']; // checked later in this file
479 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
483 * holds name of JavaScript files to be included in HTML header
484 * @global array $js_include
486 $GLOBALS['js_include'] = array();
489 * holds locale messages required by JavaScript function
490 * @global array $js_messages
492 $GLOBALS['js_messages'] = array();
495 * JavaScript events that will be registered
496 * @global array $js_events
498 $GLOBALS['js_events'] = array();
501 * footnotes to be displayed ot the page bottom
502 * @global array $footnotes
504 $GLOBALS['footnotes'] = array();
506 /******************************************************************************/
507 /* parsing configuration file LABEL_parsing_config_file */
510 * We really need this one!
512 if (! function_exists('preg_replace')) {
513 PMA_fatalError('strCantLoad', 'pcre');
517 * @global PMA_Config $_SESSION['PMA_Config']
518 * force reading of config file, because we removed sensitive values
519 * in the previous iteration
521 $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php');
523 if (!defined('PMA_MINIMUM_COMMON')) {
524 $_SESSION['PMA_Config']->checkPmaAbsoluteUri();
528 * BC - enable backward compatibility
529 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
531 $_SESSION['PMA_Config']->enableBc();
535 * check HTTPS connection
537 if ($_SESSION['PMA_Config']->get('ForceSSL')
538 && !$_SESSION['PMA_Config']->get('is_https')) {
539 PMA_sendHeaderLocation(
540 preg_replace('/^http/', 'https',
541 $_SESSION['PMA_Config']->get('PmaAbsoluteUri'))
542 . PMA_generate_common_url($_GET));
543 exit;
547 /******************************************************************************/
548 /* loading language file LABEL_loading_language_file */
551 * Added messages while developing:
553 if (file_exists('./lang/added_messages.php')) {
554 include './lang/added_messages.php';
558 * lang detection is done here
560 require_once './libraries/select_lang.lib.php';
563 * check for errors occurred while loading configuration
564 * this check is done here after loading language files to present errors in locale
566 if ($_SESSION['PMA_Config']->error_config_file) {
567 $error = $strConfigFileError
568 . '<br /><br />'
569 . ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
570 '<a href="show_config_errors.php"'
571 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>'
573 '<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
574 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
575 trigger_error($error, E_USER_ERROR);
577 if ($_SESSION['PMA_Config']->error_config_default_file) {
578 $error = sprintf($strConfigDefaultFileError,
579 $_SESSION['PMA_Config']->default_source);
580 trigger_error($error, E_USER_ERROR);
582 if ($_SESSION['PMA_Config']->error_pma_uri) {
583 trigger_error($strPmaUriError, E_USER_ERROR);
587 /******************************************************************************/
588 /* setup servers LABEL_setup_servers */
591 * current server
592 * @global integer $GLOBALS['server']
594 $GLOBALS['server'] = 0;
597 * Servers array fixups.
598 * $default_server comes from PMA_Config::enableBc()
599 * @todo merge into PMA_Config
601 // Do we have some server?
602 if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
603 // No server => create one with defaults
604 $cfg['Servers'] = array(1 => $default_server);
605 } else {
606 // We have server(s) => apply default configuration
607 $new_servers = array();
609 foreach ($cfg['Servers'] as $server_index => $each_server) {
611 // Detect wrong configuration
612 if (!is_int($server_index) || $server_index < 1) {
613 trigger_error(sprintf($strInvalidServerIndex, $server_index), E_USER_ERROR);
616 $each_server = array_merge($default_server, $each_server);
618 // Don't use servers with no hostname
619 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
620 trigger_error(sprintf($strInvalidServerHostname, $server_index), E_USER_ERROR);
623 // Final solution to bug #582890
624 // If we are using a socket connection
625 // and there is nothing in the verbose server name
626 // or the host field, then generate a name for the server
627 // in the form of "Server 2", localized of course!
628 if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
629 $each_server['verbose'] = $GLOBALS['strServer'] . $server_index;
632 $new_servers[$server_index] = $each_server;
634 $cfg['Servers'] = $new_servers;
635 unset($new_servers, $server_index, $each_server);
638 // Cleanup
639 unset($default_server);
642 /******************************************************************************/
643 /* setup themes LABEL_theme_setup */
645 if (isset($_REQUEST['custom_color_reset'])) {
646 unset($_SESSION['userconf']['custom_color']);
647 unset($_SESSION['userconf']['custom_color_rgb']);
648 } elseif (isset($_REQUEST['custom_color'])) {
649 $_SESSION['userconf']['custom_color'] = $_REQUEST['custom_color'];
650 $_SESSION['userconf']['custom_color_rgb'] = $_REQUEST['custom_color_rgb'];
653 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
655 if (! isset($_SESSION['PMA_Theme_Manager'])) {
656 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
657 } else {
659 * @todo move all __wakeup() functionality into session.inc.php
661 $_SESSION['PMA_Theme_Manager']->checkConfig();
664 // for the theme per server feature
665 if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
666 $GLOBALS['server'] = $_REQUEST['server'];
667 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
668 if (empty($tmp)) {
669 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
671 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
672 unset($tmp);
675 * @todo move into PMA_Theme_Manager::__wakeup()
677 if (isset($_REQUEST['set_theme'])) {
678 // if user selected a theme
679 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
683 * the theme object
684 * @global PMA_Theme $_SESSION['PMA_Theme']
686 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
688 // BC
690 * the active theme
691 * @global string $GLOBALS['theme']
693 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
695 * the theme path
696 * @global string $GLOBALS['pmaThemePath']
698 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
700 * the theme image path
701 * @global string $GLOBALS['pmaThemeImage']
703 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
706 * load layout file if exists
708 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
709 include $_SESSION['PMA_Theme']->getLayoutFile();
711 * @todo remove if all themes are update use Navi instead of Left as frame name
713 if (! isset($GLOBALS['cfg']['NaviWidth'])
714 && isset($GLOBALS['cfg']['LeftWidth'])) {
715 $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
719 if (! defined('PMA_MINIMUM_COMMON')) {
721 * Character set conversion.
723 require_once './libraries/charset_conversion.lib.php';
726 * String handling
728 require_once './libraries/string.lib.php';
731 * Lookup server by name
732 * by Arnold - Helder Hosting
733 * (see FAQ 4.8)
735 if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
736 && ! is_numeric($_REQUEST['server'])) {
737 foreach ($cfg['Servers'] as $i => $server) {
738 if ($server['host'] == $_REQUEST['server']) {
739 $_REQUEST['server'] = $i;
740 break;
743 if (is_string($_REQUEST['server'])) {
744 unset($_REQUEST['server']);
746 unset($i);
750 * If no server is selected, make sure that $cfg['Server'] is empty (so
751 * that nothing will work), and skip server authentication.
752 * We do NOT exit here, but continue on without logging into any server.
753 * This way, the welcome page will still come up (with no server info) and
754 * present a choice of servers in the case that there are multiple servers
755 * and '$cfg['ServerDefault'] = 0' is set.
758 if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
759 $GLOBALS['server'] = $_REQUEST['server'];
760 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
761 } else {
762 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
763 $GLOBALS['server'] = $cfg['ServerDefault'];
764 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
765 } else {
766 $GLOBALS['server'] = 0;
767 $cfg['Server'] = array();
770 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
773 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
775 if (function_exists('mb_convert_encoding')
776 && strpos($lang, 'ja-') !== false) {
777 require_once './libraries/kanji-encoding.lib.php';
779 * enable multibyte string support
781 define('PMA_MULTIBYTE_ENCODING', 1);
782 } // end if
785 * save some settings in cookies
786 * @todo should be done in PMA_Config
788 PMA_setCookie('pma_lang', $GLOBALS['lang']);
789 PMA_setCookie('pma_charset', $GLOBALS['convcharset']);
790 PMA_setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
792 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
794 if (! empty($cfg['Server'])) {
797 * Loads the proper database interface for this server
799 require_once './libraries/database_interface.lib.php';
801 // Gets the authentication library that fits the $cfg['Server'] settings
802 // and run authentication
804 // to allow HTTP or http
805 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
806 if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
807 PMA_fatalError($strInvalidAuthMethod . ' ' . $cfg['Server']['auth_type']);
810 * the required auth type plugin
812 require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
814 if (!PMA_auth_check()) {
815 PMA_auth();
816 } else {
817 PMA_auth_set_user();
820 // Check IP-based Allow/Deny rules as soon as possible to reject the
821 // user
822 // Based on mod_access in Apache:
823 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
824 // Look at: "static int check_dir_access(request_rec *r)"
825 // Robbat2 - May 10, 2002
826 if (isset($cfg['Server']['AllowDeny'])
827 && isset($cfg['Server']['AllowDeny']['order'])) {
830 * ip based access library
832 require_once './libraries/ip_allow_deny.lib.php';
834 $allowDeny_forbidden = false; // default
835 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
836 $allowDeny_forbidden = true;
837 if (PMA_allowDeny('allow')) {
838 $allowDeny_forbidden = false;
840 if (PMA_allowDeny('deny')) {
841 $allowDeny_forbidden = true;
843 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
844 if (PMA_allowDeny('deny')) {
845 $allowDeny_forbidden = true;
847 if (PMA_allowDeny('allow')) {
848 $allowDeny_forbidden = false;
850 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
851 if (PMA_allowDeny('allow')
852 && !PMA_allowDeny('deny')) {
853 $allowDeny_forbidden = false;
854 } else {
855 $allowDeny_forbidden = true;
857 } // end if ... elseif ... elseif
859 // Ejects the user if banished
860 if ($allowDeny_forbidden) {
861 PMA_auth_fails();
863 unset($allowDeny_forbidden); //Clean up after you!
864 } // end if
866 // is root allowed?
867 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
868 $allowDeny_forbidden = true;
869 PMA_auth_fails();
870 unset($allowDeny_forbidden); //Clean up after you!
873 // is root without password allowed?
874 if (!$cfg['Server']['AllowNoPasswordRoot'] && $cfg['Server']['user'] == 'root' && $cfg['Server']['password'] == '') {
875 $allowDeny_forbidden = true;
876 PMA_auth_fails();
877 unset($allowDeny_forbidden); //Clean up after you!
880 // Try to connect MySQL with the control user profile (will be used to
881 // get the privileges list for the current user but the true user link
882 // must be open after this one so it would be default one for all the
883 // scripts)
884 $controllink = false;
885 if ($cfg['Server']['controluser'] != '') {
886 $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
887 $cfg['Server']['controlpass'], true);
890 // Connects to the server (validates user's login)
891 $userlink = PMA_DBI_connect($cfg['Server']['user'],
892 $cfg['Server']['password'], false);
894 if (! $controllink) {
895 $controllink = $userlink;
899 * with phpMyAdmin 3 we support MySQL >=5
900 * but only production releases:
901 * - > 5.0.15
903 if (PMA_MYSQL_INT_VERSION < 50015) {
904 PMA_fatalError('strUpgrade', array('MySQL', '5.0.15'));
908 * SQL Parser code
910 require_once './libraries/sqlparser.lib.php';
913 * SQL Validator interface code
915 require_once './libraries/sqlvalidator.lib.php';
918 * the PMA_List_Database class
920 require_once './libraries/PMA.php';
921 $pma = new PMA;
922 $pma->userlink = $userlink;
923 $pma->controllink = $controllink;
926 * some resetting has to be done when switching servers
928 if (isset($_SESSION['userconf']['previous_server']) && $_SESSION['userconf']['previous_server'] != $GLOBALS['server']) {
929 unset($_SESSION['userconf']['navi_limit_offset']);
931 $_SESSION['userconf']['previous_server'] = $GLOBALS['server'];
933 } // end server connecting
936 * check if profiling was requested and remember it
937 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
939 if (isset($_REQUEST['profiling']) && PMA_profilingSupported()) {
940 $_SESSION['profiling'] = true;
941 } elseif (isset($_REQUEST['profiling_form'])) {
942 // the checkbox was unchecked
943 unset($_SESSION['profiling']);
946 // rajk - library file for blobstreaming
947 require_once './libraries/blobstreaming.lib.php';
949 // rajk - checks for blobstreaming plugins and databases that support
950 // blobstreaming (by having the necessary tables for blobstreaming)
951 if (checkBLOBStreamingPlugins())
952 checkBLOBStreamableDatabases();
953 } // end if !defined('PMA_MINIMUM_COMMON')
955 // remove sensitive values from session
956 $_SESSION['PMA_Config']->set('blowfish_secret', '');
957 $_SESSION['PMA_Config']->set('Servers', '');
958 $_SESSION['PMA_Config']->set('default_server', '');
960 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
962 * include subform target page
964 require $__redirect;
965 exit();