Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / libraries / common.inc.php
blob0262d57a3ded8e6aa1b13b525536136d4e93bb34
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 * @package phpMyAdmin
34 /**
35 * Minimum PHP version; can't call PMA_fatalError() which uses a
36 * PHP 5 function, so cannot easily localize this message.
38 if (version_compare(PHP_VERSION, '5.2.0', 'lt')) {
39 die('PHP 5.2+ is required');
42 /**
43 * Backward compatibility for PHP 5.2
45 if (!defined('E_DEPRECATED')) {
46 define('E_DEPRECATED', 8192);
49 /**
50 * the error handler
52 require './libraries/Error_Handler.class.php';
54 /**
55 * initialize the error handler
57 $GLOBALS['error_handler'] = new PMA_Error_Handler();
58 $cfg['Error_Handler']['display'] = true;
61 * This setting was removed in PHP 5.3. But at this point PMA_PHP_INT_VERSION
62 * is not yet defined so we use another way to find out the PHP version.
64 if (version_compare(phpversion(), '5.3', 'lt')) {
65 /**
66 * Avoid object cloning errors
68 @ini_set('zend.ze1_compatibility_mode', false);
71 /**
72 * Avoid problems with magic_quotes_runtime
73 * (in the future, this setting will be removed but it's not yet
74 * known in which PHP version)
76 @ini_set('magic_quotes_runtime', false);
78 /**
79 * for verification in all procedural scripts under libraries
81 define('PHPMYADMIN', true);
83 /**
84 * core functions
86 require './libraries/core.lib.php';
88 /**
89 * Input sanitizing
91 require './libraries/sanitizing.lib.php';
93 /**
94 * the PMA_Theme class
96 require './libraries/Theme.class.php';
98 /**
99 * the PMA_Theme_Manager class
101 require './libraries/Theme_Manager.class.php';
104 * the PMA_Config class
106 require './libraries/Config.class.php';
109 * the relation lib, tracker needs it
111 require './libraries/relation.lib.php';
114 * the PMA_Tracker class
116 require './libraries/Tracker.class.php';
119 * the PMA_Table class
121 require './libraries/Table.class.php';
123 if (!defined('PMA_MINIMUM_COMMON')) {
125 * common functions
127 require_once './libraries/common.lib.php';
130 * Java script escaping.
132 require_once './libraries/js_escape.lib.php';
135 * Include URL/hidden inputs generating.
137 require_once './libraries/url_generating.lib.php';
140 /******************************************************************************/
141 /* start procedural code label_start_procedural */
144 * protect against possible exploits - there is no need to have so much variables
146 if (count($_REQUEST) > 1000) {
147 die('possible exploit');
151 * Check for numeric keys
152 * (if register_globals is on, numeric key can be found in $GLOBALS)
154 foreach ($GLOBALS as $key => $dummy) {
155 if (is_numeric($key)) {
156 die('numeric key detected');
159 unset($dummy);
162 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
163 * and provide a clean PHP_SELF here
165 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
166 $_PATH_INFO = PMA_getenv('PATH_INFO');
167 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
168 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
169 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
170 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
173 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
177 * just to be sure there was no import (registering) before here
178 * we empty the global space (but avoid unsetting $variables_list
179 * and $key in the foreach (), we still need them!)
181 $variables_whitelist = array (
182 'GLOBALS',
183 '_SERVER',
184 '_GET',
185 '_POST',
186 '_REQUEST',
187 '_FILES',
188 '_ENV',
189 '_COOKIE',
190 '_SESSION',
191 'error_handler',
192 'PMA_PHP_SELF',
193 'variables_whitelist',
194 'key'
197 foreach (get_defined_vars() as $key => $value) {
198 if (! in_array($key, $variables_whitelist)) {
199 unset($$key);
202 unset($key, $value, $variables_whitelist);
206 * Subforms - some functions need to be called by form, cause of the limited URL
207 * length, but if this functions inside another form you cannot just open a new
208 * form - so phpMyAdmin uses 'arrays' inside this form
210 * <code>
211 * <form ...>
212 * ... main form elments ...
213 * <input type="hidden" name="subform[action1][id]" value="1" />
214 * ... other subform data ...
215 * <input type="submit" name="usesubform[action1]" value="do action1" />
216 * ... other subforms ...
217 * <input type="hidden" name="subform[actionX][id]" value="X" />
218 * ... other subform data ...
219 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
220 * ... main form elments ...
221 * <input type="submit" name="main_action" value="submit form" />
222 * </form>
223 * </code>
225 * so we now check if a subform is submitted
227 $__redirect = null;
228 if (isset($_POST['usesubform'])) {
229 // if a subform is present and should be used
230 // the rest of the form is deprecated
231 $subform_id = key($_POST['usesubform']);
232 $subform = $_POST['subform'][$subform_id];
233 $_POST = $subform;
234 $_REQUEST = $subform;
236 * some subforms need another page than the main form, so we will just
237 * include this page at the end of this script - we use $__redirect to
238 * track this
240 if (isset($_POST['redirect'])
241 && $_POST['redirect'] != basename($PMA_PHP_SELF)) {
242 $__redirect = $_POST['redirect'];
243 unset($_POST['redirect']);
245 unset($subform_id, $subform);
246 } else {
247 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
248 // because another application for the same domain could have set
249 // a cookie (with a compatible path) that overrides a variable
250 // we expect from GET or POST.
251 // We'll refer to cookies explicitly with the $_COOKIE syntax.
252 $_REQUEST = array_merge($_GET, $_POST);
254 // end check if a subform is submitted
256 // remove quotes added by php
257 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
258 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
259 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
260 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
261 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
265 * include deprecated grab_globals only if required
267 if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
268 require './libraries/grab_globals.lib.php';
272 * check timezone setting
273 * this could produce an E_STRICT - but only once,
274 * if not done here it will produce E_STRICT on every date/time function
276 * @todo need to decide how we should handle this (without @)
278 date_default_timezone_set(@date_default_timezone_get());
280 /******************************************************************************/
281 /* parsing configuration file LABEL_parsing_config_file */
284 * We really need this one!
286 if (! function_exists('preg_replace')) {
287 PMA_warnMissingExtension('pcre', true);
291 * @global PMA_Config $GLOBALS['PMA_Config']
292 * force reading of config file, because we removed sensitive values
293 * in the previous iteration
295 $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
297 if (!defined('PMA_MINIMUM_COMMON')) {
298 $GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
302 * BC - enable backward compatibility
303 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
305 $GLOBALS['PMA_Config']->enableBc();
308 * clean cookies on upgrade
309 * when changing something related to PMA cookies, increment the cookie version
311 $pma_cookie_version = 4;
312 if (isset($_COOKIE)
313 && (isset($_COOKIE['pmaCookieVer'])
314 && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
315 // delete all cookies
316 foreach ($_COOKIE as $cookie_name => $tmp) {
317 $GLOBALS['PMA_Config']->removeCookie($cookie_name);
319 $_COOKIE = array();
320 $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
325 * check HTTPS connection
327 if ($GLOBALS['PMA_Config']->get('ForceSSL')
328 && !$GLOBALS['PMA_Config']->get('is_https')) {
329 PMA_sendHeaderLocation(
330 preg_replace('/^http/', 'https',
331 $GLOBALS['PMA_Config']->get('PmaAbsoluteUri'))
332 . PMA_generate_common_url($_GET, 'text'));
333 // delete the current session, otherwise we get problems (see bug #2397877)
334 $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
335 exit;
340 * include session handling after the globals, to prevent overwriting
342 require './libraries/session.inc.php';
345 * init some variables LABEL_variables_init
349 * holds parameters to be passed to next page
350 * @global array $GLOBALS['url_params']
352 $GLOBALS['url_params'] = array();
355 * the whitelist for $GLOBALS['goto']
356 * @global array $goto_whitelist
358 $goto_whitelist = array(
359 //'browse_foreigners.php',
360 //'calendar.php',
361 //'changelog.php',
362 //'chk_rel.php',
363 'db_create.php',
364 'db_datadict.php',
365 'db_sql.php',
366 'db_events.php',
367 'db_export.php',
368 'db_importdocsql.php',
369 'db_qbe.php',
370 'db_structure.php',
371 'db_import.php',
372 'db_operations.php',
373 'db_printview.php',
374 'db_search.php',
375 'db_routines.php',
376 //'Documentation.html',
377 'export.php',
378 'import.php',
379 //'index.php',
380 //'navigation.php',
381 //'license.php',
382 'main.php',
383 'pdf_pages.php',
384 'pdf_schema.php',
385 //'phpinfo.php',
386 'querywindow.php',
387 //'readme.php',
388 'server_binlog.php',
389 'server_collations.php',
390 'server_databases.php',
391 'server_engines.php',
392 'server_export.php',
393 'server_import.php',
394 'server_privileges.php',
395 'server_processlist.php',
396 'server_sql.php',
397 'server_status.php',
398 'server_variables.php',
399 'sql.php',
400 'tbl_addfield.php',
401 'tbl_alter.php',
402 'tbl_change.php',
403 'tbl_create.php',
404 'tbl_import.php',
405 'tbl_indexes.php',
406 'tbl_move_copy.php',
407 'tbl_printview.php',
408 'tbl_sql.php',
409 'tbl_export.php',
410 'tbl_operations.php',
411 'tbl_structure.php',
412 'tbl_relation.php',
413 'tbl_replace.php',
414 'tbl_row_action.php',
415 'tbl_select.php',
416 //'themes.php',
417 'transformation_overview.php',
418 'transformation_wrapper.php',
419 'user_password.php',
423 * check $__redirect against whitelist
425 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
426 $__redirect = null;
430 * holds page that should be displayed
431 * @global string $GLOBALS['goto']
433 $GLOBALS['goto'] = '';
434 // Security fix: disallow accessing serious server files via "?goto="
435 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
436 $GLOBALS['goto'] = $_REQUEST['goto'];
437 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
438 } else {
439 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
443 * returning page
444 * @global string $GLOBALS['back']
446 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
447 $GLOBALS['back'] = $_REQUEST['back'];
448 } else {
449 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
453 * Check whether user supplied token is valid, if not remove any possibly
454 * dangerous stuff from request.
456 * remember that some objects in the session with session_start and __wakeup()
457 * could access this variables before we reach this point
458 * f.e. PMA_Config: fontsize
460 * @todo variables should be handled by their respective owners (objects)
461 * f.e. lang, server, collation_connection in PMA_Config
463 if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
465 * List of parameters which are allowed from unsafe source
467 $allow_list = array(
468 /* needed for direct access, see FAQ 1.34
469 * also, server needed for cookie login screen (multi-server)
471 'server', 'db', 'table', 'target',
472 /* Session ID */
473 'phpMyAdmin',
474 /* Cookie preferences */
475 'pma_lang', 'pma_collation_connection',
476 /* Possible login form */
477 'pma_servername', 'pma_username', 'pma_password',
478 /* for playing blobstreamable media */
479 'media_type', 'custom_type', 'bs_reference',
480 /* for changing BLOB repository file MIME type */
481 'bs_db', 'bs_table', 'bs_ref', 'bs_new_mime_type',
484 * Require cleanup functions
486 require './libraries/cleanup.lib.php';
488 * Do actual cleanup
490 PMA_remove_request_vars($allow_list);
496 * current selected database
497 * @global string $GLOBALS['db']
499 $GLOBALS['db'] = '';
500 if (PMA_isValid($_REQUEST['db'])) {
501 // can we strip tags from this?
502 // only \ and / is not allowed in db names for MySQL
503 $GLOBALS['db'] = $_REQUEST['db'];
504 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
508 * current selected table
509 * @global string $GLOBALS['table']
511 $GLOBALS['table'] = '';
512 if (PMA_isValid($_REQUEST['table'])) {
513 // check if specified table contain db name
514 if (strpos($_REQUEST['table'], '.')) {
515 $splitted = explode('.', $_REQUEST['table']);
516 if (count($splitted) == 2) { // make sure the format is "db.table"
517 $GLOBALS['db'] = $splitted[0];
518 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
519 $GLOBALS['table'] = $splitted[1];
520 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
522 } else {
523 // can we strip tags from this?
524 // only \ and / is not allowed in table names for MySQL
525 $GLOBALS['table'] = $_REQUEST['table'];
526 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
531 * SQL query to be executed
532 * @global string $GLOBALS['sql_query']
534 $GLOBALS['sql_query'] = '';
535 if (PMA_isValid($_REQUEST['sql_query'])) {
536 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
540 * avoid problems in phpmyadmin.css.php in some cases
541 * @global string $js_frame
543 $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
545 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
546 //$_REQUEST['server']; // checked later in this file
547 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
551 * holds name of JavaScript files to be included in HTML header
552 * @global array $js_include
554 $GLOBALS['js_include'] = array();
555 $GLOBALS['js_include'][] = 'jquery/jquery-1.6.1.js';
556 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
557 $GLOBALS['js_include'][] = 'update-location.js';
560 * Add common jQuery functions script here if necessary.
564 * JavaScript events that will be registered
565 * @global array $js_events
567 $GLOBALS['js_events'] = array();
570 * footnotes to be displayed ot the page bottom
571 * @global array $footnotes
573 $GLOBALS['footnotes'] = array();
575 /******************************************************************************/
576 /* loading language file LABEL_loading_language_file */
579 * lang detection is done here
581 require './libraries/select_lang.lib.php';
584 * check for errors occurred while loading configuration
585 * this check is done here after loading language files to present errors in locale
587 if ($GLOBALS['PMA_Config']->error_config_file) {
588 $error = '<h1>' . __('Failed to read configuration file') . '</h1>'
589 . _('This usually means there is a syntax error in it, please check any errors shown below.')
590 . '<br />'
591 . '<br />'
592 . '<iframe src="show_config_errors.php" />';
593 trigger_error($error, E_USER_ERROR);
595 if ($GLOBALS['PMA_Config']->error_config_default_file) {
596 $error = sprintf(__('Could not load default configuration from: %1$s'),
597 $GLOBALS['PMA_Config']->default_source);
598 trigger_error($error, E_USER_ERROR);
600 if ($GLOBALS['PMA_Config']->error_pma_uri) {
601 trigger_error(__('The <tt>$cfg[\'PmaAbsoluteUri\']</tt> directive MUST be set in your configuration file!'), E_USER_ERROR);
605 /******************************************************************************/
606 /* setup servers LABEL_setup_servers */
609 * current server
610 * @global integer $GLOBALS['server']
612 $GLOBALS['server'] = 0;
615 * Servers array fixups.
616 * $default_server comes from PMA_Config::enableBc()
617 * @todo merge into PMA_Config
619 // Do we have some server?
620 if (! isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
621 // No server => create one with defaults
622 $cfg['Servers'] = array(1 => $default_server);
623 } else {
624 // We have server(s) => apply default configuration
625 $new_servers = array();
627 foreach ($cfg['Servers'] as $server_index => $each_server) {
629 // Detect wrong configuration
630 if (!is_int($server_index) || $server_index < 1) {
631 trigger_error(sprintf(__('Invalid server index: %s'), $server_index), E_USER_ERROR);
634 $each_server = array_merge($default_server, $each_server);
636 // Don't use servers with no hostname
637 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
638 trigger_error(sprintf(__('Invalid hostname for server %1$s. Please review your configuration.'), $server_index), E_USER_ERROR);
641 // Final solution to bug #582890
642 // If we are using a socket connection
643 // and there is nothing in the verbose server name
644 // or the host field, then generate a name for the server
645 // in the form of "Server 2", localized of course!
646 if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
647 $each_server['verbose'] = __('Server') . $server_index;
650 $new_servers[$server_index] = $each_server;
652 $cfg['Servers'] = $new_servers;
653 unset($new_servers, $server_index, $each_server);
656 // Cleanup
657 unset($default_server);
660 /******************************************************************************/
661 /* setup themes LABEL_theme_setup */
664 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
666 if (! isset($_SESSION['PMA_Theme_Manager'])) {
667 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
668 } else {
670 * @todo move all __wakeup() functionality into session.inc.php
672 $_SESSION['PMA_Theme_Manager']->checkConfig();
675 // for the theme per server feature
676 if (isset($_REQUEST['server']) && ! isset($_REQUEST['set_theme'])) {
677 $GLOBALS['server'] = $_REQUEST['server'];
678 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
679 if (empty($tmp)) {
680 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
682 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
683 unset($tmp);
686 * @todo move into PMA_Theme_Manager::__wakeup()
688 if (isset($_REQUEST['set_theme'])) {
689 // if user selected a theme
690 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
694 * the theme object
695 * @global PMA_Theme $_SESSION['PMA_Theme']
697 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
699 // BC
701 * the active theme
702 * @global string $GLOBALS['theme']
704 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
706 * the theme path
707 * @global string $GLOBALS['pmaThemePath']
709 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
711 * the theme image path
712 * @global string $GLOBALS['pmaThemeImage']
714 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
717 * load layout file if exists
719 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
720 include $_SESSION['PMA_Theme']->getLayoutFile();
722 * @todo remove if all themes are update use Navi instead of Left as frame name
724 if (! isset($GLOBALS['cfg']['NaviWidth'])
725 && isset($GLOBALS['cfg']['LeftWidth'])) {
726 $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
730 if (! defined('PMA_MINIMUM_COMMON')) {
732 * Character set conversion.
734 require_once './libraries/charset_conversion.lib.php';
737 * String handling
739 require_once './libraries/string.lib.php';
742 * Lookup server by name
743 * (see FAQ 4.8)
745 if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
746 && ! is_numeric($_REQUEST['server'])) {
747 foreach ($cfg['Servers'] as $i => $server) {
748 if ($server['host'] == $_REQUEST['server']) {
749 $_REQUEST['server'] = $i;
750 break;
753 if (is_string($_REQUEST['server'])) {
754 unset($_REQUEST['server']);
756 unset($i);
760 * If no server is selected, make sure that $cfg['Server'] is empty (so
761 * that nothing will work), and skip server authentication.
762 * We do NOT exit here, but continue on without logging into any server.
763 * This way, the welcome page will still come up (with no server info) and
764 * present a choice of servers in the case that there are multiple servers
765 * and '$cfg['ServerDefault'] = 0' is set.
768 if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
769 $GLOBALS['server'] = $_REQUEST['server'];
770 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
771 } else {
772 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
773 $GLOBALS['server'] = $cfg['ServerDefault'];
774 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
775 } else {
776 $GLOBALS['server'] = 0;
777 $cfg['Server'] = array();
780 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
783 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
785 if (function_exists('mb_convert_encoding')
786 && $lang == 'ja') {
787 require_once './libraries/kanji-encoding.lib.php';
788 } // end if
791 * save some settings in cookies
792 * @todo should be done in PMA_Config
794 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
795 $GLOBALS['PMA_Config']->setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
797 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
799 if (! empty($cfg['Server'])) {
802 * Loads the proper database interface for this server
804 require_once './libraries/database_interface.lib.php';
806 require_once './libraries/logging.lib.php';
808 // get LoginCookieValidity from preferences cache
809 // no generic solution for loading preferences from cache as some settings need to be kept
810 // for processing in PMA_Config::loadUserPreferences()
811 $cache_key = 'server_' . $GLOBALS['server'];
812 if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])) {
813 $value = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
814 $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
815 $GLOBALS['cfg']['LoginCookieValidity'] = $value;
816 unset($value);
818 unset($cache_key);
820 // Gets the authentication library that fits the $cfg['Server'] settings
821 // and run authentication
823 // to allow HTTP or http
824 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
825 if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
826 PMA_fatalError(__('Invalid authentication method set in configuration:') . ' ' . $cfg['Server']['auth_type']);
829 * the required auth type plugin
831 require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
832 if (!PMA_auth_check()) {
833 /* Force generating of new session on login */
834 PMA_secureSession();
835 PMA_auth();
836 } else {
837 PMA_auth_set_user();
840 // Check IP-based Allow/Deny rules as soon as possible to reject the
841 // user
842 // Based on mod_access in Apache:
843 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
844 // Look at: "static int check_dir_access(request_rec *r)"
845 if (isset($cfg['Server']['AllowDeny'])
846 && isset($cfg['Server']['AllowDeny']['order'])) {
849 * ip based access library
851 require_once './libraries/ip_allow_deny.lib.php';
853 $allowDeny_forbidden = false; // default
854 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
855 $allowDeny_forbidden = true;
856 if (PMA_allowDeny('allow')) {
857 $allowDeny_forbidden = false;
859 if (PMA_allowDeny('deny')) {
860 $allowDeny_forbidden = true;
862 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
863 if (PMA_allowDeny('deny')) {
864 $allowDeny_forbidden = true;
866 if (PMA_allowDeny('allow')) {
867 $allowDeny_forbidden = false;
869 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
870 if (PMA_allowDeny('allow')
871 && !PMA_allowDeny('deny')) {
872 $allowDeny_forbidden = false;
873 } else {
874 $allowDeny_forbidden = true;
876 } // end if ... elseif ... elseif
878 // Ejects the user if banished
879 if ($allowDeny_forbidden) {
880 PMA_log_user($cfg['Server']['user'], 'allow-denied');
881 PMA_auth_fails();
883 unset($allowDeny_forbidden); //Clean up after you!
884 } // end if
886 // is root allowed?
887 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
888 $allowDeny_forbidden = true;
889 PMA_log_user($cfg['Server']['user'], 'root-denied');
890 PMA_auth_fails();
891 unset($allowDeny_forbidden); //Clean up after you!
894 // is a login without password allowed?
895 if (!$cfg['Server']['AllowNoPassword'] && $cfg['Server']['password'] == '') {
896 $login_without_password_is_forbidden = true;
897 PMA_log_user($cfg['Server']['user'], 'empty-denied');
898 PMA_auth_fails();
899 unset($login_without_password_is_forbidden); //Clean up after you!
902 // Try to connect MySQL with the control user profile (will be used to
903 // get the privileges list for the current user but the true user link
904 // must be open after this one so it would be default one for all the
905 // scripts)
906 $controllink = false;
907 if ($cfg['Server']['controluser'] != '') {
908 $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
909 $cfg['Server']['controlpass'], true);
912 // Connects to the server (validates user's login)
913 $userlink = PMA_DBI_connect($cfg['Server']['user'],
914 $cfg['Server']['password'], false);
916 if (! $controllink) {
917 $controllink = $userlink;
920 /* Log success */
921 PMA_log_user($cfg['Server']['user']);
924 * with phpMyAdmin 3 we support MySQL >=5
925 * but only production releases:
926 * - > 5.0.15
928 if (PMA_MYSQL_INT_VERSION < 50015) {
929 PMA_fatalError(__('You should upgrade to %s %s or later.'), array('MySQL', '5.0.15'));
932 if (PMA_DRIZZLE) {
933 // DisableIS must be set to false for Drizzle, it maps SHOW commands to IS queries anyway
934 $cfg['Server']['DisableIS'] = false;
935 // SHOW OPEN TABLES is not supported by Drizzle
936 $cfg['SkipLockedTables'] = false;
940 * SQL Parser code
942 require_once './libraries/sqlparser.lib.php';
945 * SQL Validator interface code
947 require_once './libraries/sqlvalidator.lib.php';
950 * the PMA_List_Database class
952 require_once './libraries/PMA.php';
953 $pma = new PMA;
954 $pma->userlink = $userlink;
955 $pma->controllink = $controllink;
958 * some resetting has to be done when switching servers
960 if (isset($_SESSION['tmp_user_values']['previous_server']) && $_SESSION['tmp_user_values']['previous_server'] != $GLOBALS['server']) {
961 unset($_SESSION['tmp_user_values']['navi_limit_offset']);
963 $_SESSION['tmp_user_values']['previous_server'] = $GLOBALS['server'];
965 } // end server connecting
968 * check if profiling was requested and remember it
969 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
971 if (isset($_REQUEST['profiling']) && PMA_profilingSupported()) {
972 $_SESSION['profiling'] = true;
973 } elseif (isset($_REQUEST['profiling_form'])) {
974 // the checkbox was unchecked
975 unset($_SESSION['profiling']);
978 // library file for blobstreaming
979 require_once './libraries/blobstreaming.lib.php';
981 // checks for blobstreaming plugins and databases that support
982 // blobstreaming (by having the necessary tables for blobstreaming)
983 checkBLOBStreamingPlugins();
985 } // end if !defined('PMA_MINIMUM_COMMON')
987 // load user preferences
988 $GLOBALS['PMA_Config']->loadUserPreferences();
990 // remove sensitive values from session
991 $GLOBALS['PMA_Config']->set('blowfish_secret', '');
992 $GLOBALS['PMA_Config']->set('Servers', '');
993 $GLOBALS['PMA_Config']->set('default_server', '');
995 /* Tell tracker that it can actually work */
996 PMA_Tracker::enable();
999 * @global boolean $GLOBALS['is_ajax_request']
1000 * @todo should this be moved to the variables init section above?
1002 * Check if the current request is an AJAX request, and set is_ajax_request
1003 * accordingly. Suppress headers, footers and unnecessary output if set to
1004 * true
1006 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
1007 $GLOBALS['is_ajax_request'] = true;
1008 } else {
1009 $GLOBALS['is_ajax_request'] = false;
1013 * @global boolean $GLOBALS['inline_edit']
1015 * Set to true if this is a request made during an inline edit process. This
1016 * request is made to retrieve the non-truncated/transformed values.
1018 if (isset($_REQUEST['inline_edit']) && $_REQUEST['inline_edit'] == true) {
1019 $GLOBALS['inline_edit'] = true;
1021 else {
1022 $GLOBALS['inline_edit'] = false;
1025 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
1027 * include subform target page
1029 require $__redirect;
1030 exit();