Temporary fix for gobs of logged deprecation warnings from the calendar module.
[openemr.git] / phpmyadmin / libraries / common.inc.php
blob2227c1e466d83dbfa2d35ecd21144c5ef1d87899
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 * block attempts to directly run this script
37 if (getcwd() == dirname(__FILE__)) {
38 die('Attack stopped');
41 /**
42 * Minimum PHP version; can't call PMA_fatalError() which uses a
43 * PHP 5 function, so cannot easily localize this message.
45 if (version_compare(PHP_VERSION, '5.3.0', 'lt')) {
46 die('PHP 5.3+ is required');
49 /**
50 * for verification in all procedural scripts under libraries
52 define('PHPMYADMIN', true);
54 /**
55 * the error handler
57 require './libraries/Error_Handler.class.php';
59 /**
60 * initialize the error handler
62 $GLOBALS['error_handler'] = new PMA_Error_Handler();
63 $cfg['Error_Handler']['display'] = true;
65 /**
66 * This setting was removed in PHP 5.4. But at this point PMA_PHP_INT_VERSION
67 * is not yet defined so we use another way to find out the PHP version.
69 if (version_compare(phpversion(), '5.4', 'lt')) {
70 /**
71 * Avoid problems with magic_quotes_runtime
73 @ini_set('magic_quotes_runtime', '0');
76 /**
77 * core functions
79 require './libraries/core.lib.php';
81 /**
82 * Input sanitizing
84 require './libraries/sanitizing.lib.php';
86 /**
87 * Warning about mbstring.
89 if (! function_exists('mb_detect_encoding')) {
90 PMA_warnMissingExtension('mbstring', $fatal = true);
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';
124 * the PMA_Types class
126 require './libraries/Types.class.php';
128 if (! defined('PMA_MINIMUM_COMMON')) {
130 * common functions
132 include_once './libraries/Util.class.php';
135 * JavaScript escaping.
137 include_once './libraries/js_escape.lib.php';
140 * Include URL/hidden inputs generating.
142 include_once './libraries/url_generating.lib.php';
145 * Used to generate the page
147 include_once 'libraries/Response.class.php';
150 /******************************************************************************/
151 /* start procedural code label_start_procedural */
154 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
155 * and provide a clean PHP_SELF here
157 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
158 $_PATH_INFO = PMA_getenv('PATH_INFO');
159 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
160 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
161 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
162 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
165 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
169 * just to be sure there was no import (registering) before here
170 * we empty the global space (but avoid unsetting $variables_list
171 * and $key in the foreach (), we still need them!)
173 $variables_whitelist = array (
174 'GLOBALS',
175 '_SERVER',
176 '_GET',
177 '_POST',
178 '_REQUEST',
179 '_FILES',
180 '_ENV',
181 '_COOKIE',
182 '_SESSION',
183 'error_handler',
184 'PMA_PHP_SELF',
185 'variables_whitelist',
186 'key'
189 foreach (get_defined_vars() as $key => $value) {
190 if (! in_array($key, $variables_whitelist)) {
191 unset($$key);
194 unset($key, $value, $variables_whitelist);
198 * Subforms - some functions need to be called by form, cause of the limited URL
199 * length, but if this functions inside another form you cannot just open a new
200 * form - so phpMyAdmin uses 'arrays' inside this form
202 * <code>
203 * <form ...>
204 * ... main form elments ...
205 * <input type="hidden" name="subform[action1][id]" value="1" />
206 * ... other subform data ...
207 * <input type="submit" name="usesubform[action1]" value="do action1" />
208 * ... other subforms ...
209 * <input type="hidden" name="subform[actionX][id]" value="X" />
210 * ... other subform data ...
211 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
212 * ... main form elments ...
213 * <input type="submit" name="main_action" value="submit form" />
214 * </form>
215 * </code>
217 * so we now check if a subform is submitted
219 $__redirect = null;
220 if (isset($_POST['usesubform'])) {
221 // if a subform is present and should be used
222 // the rest of the form is deprecated
223 $subform_id = key($_POST['usesubform']);
224 $subform = $_POST['subform'][$subform_id];
225 $_POST = $subform;
226 $_REQUEST = $subform;
228 * some subforms need another page than the main form, so we will just
229 * include this page at the end of this script - we use $__redirect to
230 * track this
232 if (isset($_POST['redirect'])
233 && $_POST['redirect'] != basename($PMA_PHP_SELF)
235 $__redirect = $_POST['redirect'];
236 unset($_POST['redirect']);
238 unset($subform_id, $subform);
239 } else {
240 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
241 // because another application for the same domain could have set
242 // a cookie (with a compatible path) that overrides a variable
243 // we expect from GET or POST.
244 // We'll refer to cookies explicitly with the $_COOKIE syntax.
245 $_REQUEST = array_merge($_GET, $_POST);
247 // end check if a subform is submitted
250 * This setting was removed in PHP 5.4, but get_magic_quotes_gpc
251 * always returns False since then.
253 if (get_magic_quotes_gpc()) {
254 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
255 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
256 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
257 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
261 * check timezone setting
262 * this could produce an E_STRICT - but only once,
263 * if not done here it will produce E_STRICT on every date/time function
264 * (starting with PHP 5.3, this code can produce E_WARNING rather than
265 * E_STRICT)
268 date_default_timezone_set(@date_default_timezone_get());
270 /******************************************************************************/
271 /* parsing configuration file LABEL_parsing_config_file */
274 * We really need this one!
276 if (! function_exists('preg_replace')) {
277 PMA_warnMissingExtension('pcre', true);
281 * JSON is required in several places.
283 if (! function_exists('json_encode')) {
284 PMA_warnMissingExtension('json', true);
288 * @global PMA_Config $GLOBALS['PMA_Config']
289 * force reading of config file, because we removed sensitive values
290 * in the previous iteration
292 $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
294 if (!defined('PMA_MINIMUM_COMMON')) {
295 $GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
299 * BC - enable backward compatibility
300 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
302 $GLOBALS['PMA_Config']->enableBc();
305 * clean cookies on upgrade
306 * when changing something related to PMA cookies, increment the cookie version
308 $pma_cookie_version = 4;
309 if (isset($_COOKIE)
310 && (isset($_COOKIE['pmaCookieVer'])
311 && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)
313 // delete all cookies
314 foreach ($_COOKIE as $cookie_name => $tmp) {
315 $GLOBALS['PMA_Config']->removeCookie($cookie_name);
317 $_COOKIE = array();
318 $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
323 * check HTTPS connection
325 if ($GLOBALS['PMA_Config']->get('ForceSSL')
326 && ! $GLOBALS['PMA_Config']->get('is_https')
328 // grab SSL URL
329 $url = $GLOBALS['PMA_Config']->getSSLUri();
330 // Actually redirect
331 PMA_sendHeaderLocation($url . PMA_URL_getCommon($_GET, 'text'));
332 // delete the current session, otherwise we get problems (see bug #2397877)
333 $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
334 exit;
339 * include session handling after the globals, to prevent overwriting
341 require './libraries/session.inc.php';
344 * init some variables LABEL_variables_init
348 * holds parameters to be passed to next page
349 * @global array $GLOBALS['url_params']
351 $GLOBALS['url_params'] = array();
354 * the whitelist for $GLOBALS['goto']
355 * @global array $goto_whitelist
357 $goto_whitelist = array(
358 //'browse_foreigners.php',
359 //'changelog.php',
360 //'chk_rel.php',
361 'db_create.php',
362 'db_datadict.php',
363 'db_sql.php',
364 'db_events.php',
365 'db_export.php',
366 'db_importdocsql.php',
367 'db_qbe.php',
368 'db_structure.php',
369 'db_import.php',
370 'db_operations.php',
371 'db_printview.php',
372 'db_search.php',
373 'db_routines.php',
374 'export.php',
375 'import.php',
376 //'index.php',
377 //'navigation.php',
378 //'license.php',
379 'index.php',
380 'pdf_pages.php',
381 'pdf_schema.php',
382 //'phpinfo.php',
383 'querywindow.php',
384 'server_binlog.php',
385 'server_collations.php',
386 'server_databases.php',
387 'server_engines.php',
388 'server_export.php',
389 'server_import.php',
390 'server_privileges.php',
391 'server_sql.php',
392 'server_status.php',
393 'server_status_advisor.php',
394 'server_status_monitor.php',
395 'server_status_queries.php',
396 'server_status_variables.php',
397 'server_variables.php',
398 'sql.php',
399 'tbl_addfield.php',
400 'tbl_change.php',
401 'tbl_create.php',
402 'tbl_import.php',
403 'tbl_indexes.php',
404 'tbl_move_copy.php',
405 'tbl_printview.php',
406 'tbl_sql.php',
407 'tbl_export.php',
408 'tbl_operations.php',
409 'tbl_structure.php',
410 'tbl_relation.php',
411 'tbl_replace.php',
412 'tbl_row_action.php',
413 'tbl_select.php',
414 'tbl_zoom_select.php',
415 //'themes.php',
416 'transformation_overview.php',
417 'transformation_wrapper.php',
418 'user_password.php',
422 * check $__redirect against whitelist
424 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
425 $__redirect = null;
429 * holds page that should be displayed
430 * @global string $GLOBALS['goto']
432 $GLOBALS['goto'] = '';
433 // Security fix: disallow accessing serious server files via "?goto="
434 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
435 $GLOBALS['goto'] = $_REQUEST['goto'];
436 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
437 } else {
438 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
442 * returning page
443 * @global string $GLOBALS['back']
445 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
446 $GLOBALS['back'] = $_REQUEST['back'];
447 } else {
448 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
452 * Check whether user supplied token is valid, if not remove any possibly
453 * dangerous stuff from request.
455 * remember that some objects in the session with session_start and __wakeup()
456 * could access this variables before we reach this point
457 * f.e. PMA_Config: fontsize
459 * @todo variables should be handled by their respective owners (objects)
460 * f.e. lang, server, collation_connection in PMA_Config
462 $token_mismatch = true;
463 if (PMA_isValid($_REQUEST['token'])) {
464 $token_mismatch = ($_SESSION[' PMA_token '] != $_REQUEST['token']);
467 if ($token_mismatch) {
469 * List of parameters which are allowed from unsafe source
471 $allow_list = array(
472 /* needed for direct access, see FAQ 1.34
473 * also, server needed for cookie login screen (multi-server)
475 'server', 'db', 'table', 'target', 'lang',
476 /* Session ID */
477 'phpMyAdmin',
478 /* Cookie preferences */
479 'pma_lang', 'pma_collation_connection',
480 /* Possible login form */
481 'pma_servername', 'pma_username', 'pma_password',
482 'recaptcha_challenge_field', 'recaptcha_response_field',
483 /* Needed to send the correct reply */
484 'ajax_request',
485 /* Permit to log out even if there is a token mismatch */
486 'old_usr',
487 /* Permit redirection with token-mismatch in url.php */
488 'url',
489 /* Permit session expiry flag */
490 'session_expired'
493 * Allow changing themes in test/theme.php
495 if (defined('PMA_TEST_THEME')) {
496 $allow_list[] = 'set_theme';
499 * Require cleanup functions
501 include './libraries/cleanup.lib.php';
503 * Do actual cleanup
505 PMA_removeRequestVars($allow_list);
511 * current selected database
512 * @global string $GLOBALS['db']
514 $GLOBALS['db'] = '';
515 if (PMA_isValid($_REQUEST['db'])) {
516 // can we strip tags from this?
517 // only \ and / is not allowed in db names for MySQL
518 $GLOBALS['db'] = $_REQUEST['db'];
519 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
523 * current selected table
524 * @global string $GLOBALS['table']
526 $GLOBALS['table'] = '';
527 if (PMA_isValid($_REQUEST['table'])) {
528 // can we strip tags from this?
529 // only \ and / is not allowed in table names for MySQL
530 $GLOBALS['table'] = $_REQUEST['table'];
531 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
535 * Store currently selected recent table.
536 * Affect $GLOBALS['db'] and $GLOBALS['table']
538 if (PMA_isValid($_REQUEST['selected_recent_table'])) {
539 $recent_table = json_decode($_REQUEST['selected_recent_table'], true);
540 $GLOBALS['db'] = $recent_table['db'];
541 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
542 $GLOBALS['table'] = $recent_table['table'];
543 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
547 * SQL query to be executed
548 * @global string $GLOBALS['sql_query']
550 $GLOBALS['sql_query'] = '';
551 if (PMA_isValid($_REQUEST['sql_query'])) {
552 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
555 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
556 //$_REQUEST['server']; // checked later in this file
557 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
559 /******************************************************************************/
560 /* loading language file LABEL_loading_language_file */
563 * lang detection is done here
565 require './libraries/select_lang.lib.php';
567 // Defines the cell alignment values depending on text direction
568 if ($GLOBALS['text_dir'] == 'ltr') {
569 $GLOBALS['cell_align_left'] = 'left';
570 $GLOBALS['cell_align_right'] = 'right';
571 } else {
572 $GLOBALS['cell_align_left'] = 'right';
573 $GLOBALS['cell_align_right'] = 'left';
577 * check for errors occurred while loading configuration
578 * this check is done here after loading language files to present errors in locale
580 $GLOBALS['PMA_Config']->checkPermissions();
582 if ($GLOBALS['PMA_Config']->error_config_file) {
583 $error = '[strong]' . __('Failed to read configuration file!') . '[/strong]'
584 . '[br][br]'
585 . __('This usually means there is a syntax error in it, please check any errors shown below.')
586 . '[br][br]'
587 . '[conferr]';
588 trigger_error($error, E_USER_ERROR);
590 if ($GLOBALS['PMA_Config']->error_config_default_file) {
591 $error = sprintf(
592 __('Could not load default configuration from: %1$s'),
593 $GLOBALS['PMA_Config']->default_source
595 trigger_error($error, E_USER_ERROR);
597 if ($GLOBALS['PMA_Config']->error_pma_uri) {
598 trigger_error(
599 __('The [code]$cfg[\'PmaAbsoluteUri\'][/code] directive MUST be set in your configuration file!'),
600 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(
632 sprintf(__('Invalid server index: %s'), $server_index),
633 E_USER_ERROR
637 $each_server = array_merge($default_server, $each_server);
639 // Don't use servers with no hostname
640 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
641 trigger_error(
642 sprintf(
643 __('Invalid hostname for server %1$s. Please review your configuration.'),
644 $server_index
646 E_USER_ERROR
650 // Final solution to bug #582890
651 // If we are using a socket connection
652 // and there is nothing in the verbose server name
653 // or the host field, then generate a name for the server
654 // in the form of "Server 2", localized of course!
655 if ($each_server['connect_type'] == 'socket'
656 && empty($each_server['host'])
657 && empty($each_server['verbose'])
659 $each_server['verbose'] = sprintf(__('Server %d'), $server_index);
662 $new_servers[$server_index] = $each_server;
664 $cfg['Servers'] = $new_servers;
665 unset($new_servers, $server_index, $each_server);
668 // Cleanup
669 unset($default_server);
672 /******************************************************************************/
673 /* setup themes LABEL_theme_setup */
676 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
678 if (! isset($_SESSION['PMA_Theme_Manager'])) {
679 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
680 } else {
682 * @todo move all __wakeup() functionality into session.inc.php
684 $_SESSION['PMA_Theme_Manager']->checkConfig();
687 // for the theme per server feature
688 if (isset($_REQUEST['server']) && ! isset($_REQUEST['set_theme'])) {
689 $GLOBALS['server'] = $_REQUEST['server'];
690 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
691 if (empty($tmp)) {
692 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
694 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
695 unset($tmp);
698 * @todo move into PMA_Theme_Manager::__wakeup()
700 if (isset($_REQUEST['set_theme'])) {
701 // if user selected a theme
702 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
706 * the theme object
707 * @global PMA_Theme $_SESSION['PMA_Theme']
709 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
711 // BC
713 * the active theme
714 * @global string $GLOBALS['theme']
716 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
718 * the theme path
719 * @global string $GLOBALS['pmaThemePath']
721 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
723 * the theme image path
724 * @global string $GLOBALS['pmaThemeImage']
726 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
729 * load layout file if exists
731 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
732 include $_SESSION['PMA_Theme']->getLayoutFile();
735 if (! defined('PMA_MINIMUM_COMMON')) {
737 * Character set conversion.
739 include_once './libraries/charset_conversion.lib.php';
742 * String handling
744 include_once './libraries/string.inc.php';
747 * Lookup server by name
748 * (see FAQ 4.8)
750 if (! empty($_REQUEST['server'])
751 && is_string($_REQUEST['server'])
752 && ! is_numeric($_REQUEST['server'])
754 foreach ($cfg['Servers'] as $i => $server) {
755 if ($server['host'] == $_REQUEST['server']
756 || $server['verbose'] == $_REQUEST['server']
757 || $PMA_String->strtolower($server['verbose']) == $PMA_String->strtolower($_REQUEST['server'])
758 || md5($PMA_String->strtolower($server['verbose'])) == $PMA_String->strtolower($_REQUEST['server'])
760 $_REQUEST['server'] = $i;
761 break;
764 if (is_string($_REQUEST['server'])) {
765 unset($_REQUEST['server']);
767 unset($i);
771 * If no server is selected, make sure that $cfg['Server'] is empty (so
772 * that nothing will work), and skip server authentication.
773 * We do NOT exit here, but continue on without logging into any server.
774 * This way, the welcome page will still come up (with no server info) and
775 * present a choice of servers in the case that there are multiple servers
776 * and '$cfg['ServerDefault'] = 0' is set.
779 if (isset($_REQUEST['server'])
780 && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server']))
781 && ! empty($_REQUEST['server'])
782 && ! empty($cfg['Servers'][$_REQUEST['server']])
784 $GLOBALS['server'] = $_REQUEST['server'];
785 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
786 } else {
787 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
788 $GLOBALS['server'] = $cfg['ServerDefault'];
789 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
790 } else {
791 $GLOBALS['server'] = 0;
792 $cfg['Server'] = array();
795 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
798 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
800 if (function_exists('mb_convert_encoding')
801 && $lang == 'ja'
803 include_once './libraries/kanji-encoding.lib.php';
804 } // end if
807 * save some settings in cookies
808 * @todo should be done in PMA_Config
810 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
811 if (isset($GLOBALS['collation_connection'])) {
812 $GLOBALS['PMA_Config']->setCookie(
813 'pma_collation_connection',
814 $GLOBALS['collation_connection']
818 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
820 if (! empty($cfg['Server'])) {
823 * Loads the proper database interface for this server
825 include_once './libraries/database_interface.inc.php';
827 include_once './libraries/logging.lib.php';
829 // get LoginCookieValidity from preferences cache
830 // no generic solution for loading preferences from cache as some settings
831 // need to be kept for processing in PMA_Config::loadUserPreferences()
832 $cache_key = 'server_' . $GLOBALS['server'];
833 if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])
835 $value
836 = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
837 $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
838 $GLOBALS['cfg']['LoginCookieValidity'] = $value;
839 unset($value);
841 unset($cache_key);
843 // Gets the authentication library that fits the $cfg['Server'] settings
844 // and run authentication
846 // to allow HTTP or http
847 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
850 * the required auth type plugin
852 $auth_class = "Authentication" . ucfirst($cfg['Server']['auth_type']);
853 if (! file_exists(
854 './libraries/plugins/auth/'
855 . $auth_class . '.class.php'
856 )) {
857 PMA_fatalError(
858 __('Invalid authentication method set in configuration:')
859 . ' ' . $cfg['Server']['auth_type']
862 include_once './libraries/plugins/auth/' . $auth_class . '.class.php';
863 // todo: add plugin manager
864 $plugin_manager = null;
865 $auth_plugin = new $auth_class($plugin_manager);
867 if (! $auth_plugin->authCheck()) {
868 /* Force generating of new session on login */
869 PMA_secureSession();
870 $auth_plugin->auth();
871 } else {
872 $auth_plugin->authSetUser();
875 // Check IP-based Allow/Deny rules as soon as possible to reject the
876 // user
877 // Based on mod_access in Apache:
878 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
879 // Look at: "static int check_dir_access(request_rec *r)"
880 if (isset($cfg['Server']['AllowDeny'])
881 && isset($cfg['Server']['AllowDeny']['order'])
885 * ip based access library
887 include_once './libraries/ip_allow_deny.lib.php';
889 $allowDeny_forbidden = false; // default
890 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
891 $allowDeny_forbidden = true;
892 if (PMA_allowDeny('allow')) {
893 $allowDeny_forbidden = false;
895 if (PMA_allowDeny('deny')) {
896 $allowDeny_forbidden = true;
898 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
899 if (PMA_allowDeny('deny')) {
900 $allowDeny_forbidden = true;
902 if (PMA_allowDeny('allow')) {
903 $allowDeny_forbidden = false;
905 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
906 if (PMA_allowDeny('allow') && ! PMA_allowDeny('deny')) {
907 $allowDeny_forbidden = false;
908 } else {
909 $allowDeny_forbidden = true;
911 } // end if ... elseif ... elseif
913 // Ejects the user if banished
914 if ($allowDeny_forbidden) {
915 PMA_logUser($cfg['Server']['user'], 'allow-denied');
916 $auth_plugin->authFails();
918 } // end if
920 // is root allowed?
921 if (! $cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
922 $allowDeny_forbidden = true;
923 PMA_logUser($cfg['Server']['user'], 'root-denied');
924 $auth_plugin->authFails();
927 // is a login without password allowed?
928 if (! $cfg['Server']['AllowNoPassword']
929 && $cfg['Server']['password'] == ''
931 $login_without_password_is_forbidden = true;
932 PMA_logUser($cfg['Server']['user'], 'empty-denied');
933 $auth_plugin->authFails();
936 // if using TCP socket is not needed
937 if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
938 $cfg['Server']['socket'] = '';
941 // Try to connect MySQL with the control user profile (will be used to
942 // get the privileges list for the current user but the true user link
943 // must be open after this one so it would be default one for all the
944 // scripts)
945 $controllink = false;
946 if ($cfg['Server']['controluser'] != '') {
947 if (! empty($cfg['Server']['controlhost'])
948 || ! empty($cfg['Server']['controlport'])
950 $server_details = array();
951 if (! empty($cfg['Server']['controlhost'])) {
952 $server_details['host'] = $cfg['Server']['controlhost'];
953 } else {
954 $server_details['host'] = $cfg['Server']['host'];
956 if (! empty($cfg['Server']['controlport'])) {
957 $server_details['port'] = $cfg['Server']['controlport'];
958 } elseif ($server_details['host'] == $cfg['Server']['host']) {
959 // Evaluates to true when controlhost == host
960 // or controlhost is not defined (hence it defaults to host)
961 // In such case we can use the value of port.
962 $server_details['port'] = $cfg['Server']['port'];
964 // otherwise we leave the $server_details['port'] unset,
965 // allowing it to take default mysql port
967 $controllink = $GLOBALS['dbi']->connect(
968 $cfg['Server']['controluser'],
969 $cfg['Server']['controlpass'],
970 true,
971 $server_details
973 } else {
974 $controllink = $GLOBALS['dbi']->connect(
975 $cfg['Server']['controluser'],
976 $cfg['Server']['controlpass'],
977 true
982 // Connects to the server (validates user's login)
983 $userlink = $GLOBALS['dbi']->connect(
984 $cfg['Server']['user'], $cfg['Server']['password'], false
987 if (! $controllink) {
988 $controllink = $userlink;
991 /* Log success */
992 PMA_logUser($cfg['Server']['user']);
994 if (PMA_MYSQL_INT_VERSION < 50500) {
995 PMA_fatalError(
996 __('You should upgrade to %s %s or later.'),
997 array('MySQL', '5.5.0')
1001 if (PMA_PHP_INT_VERSION < 50300) {
1002 PMA_fatalError(
1003 __('You should upgrade to %s %s or later.'),
1004 array('PHP', '5.3.0')
1009 * Type handling object.
1011 if (PMA_DRIZZLE) {
1012 $GLOBALS['PMA_Types'] = new PMA_Types_Drizzle();
1013 } else {
1014 $GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
1017 if (PMA_DRIZZLE) {
1018 // SHOW OPEN TABLES is not supported by Drizzle
1019 $cfg['SkipLockedTables'] = false;
1023 * SQL Parser code
1025 include_once './libraries/sqlparser.lib.php';
1028 * the PMA_List_Database class
1030 include_once './libraries/PMA.php';
1031 $pma = new PMA;
1032 $pma->userlink = $userlink;
1033 $pma->controllink = $controllink;
1036 * some resetting has to be done when switching servers
1038 if (isset($_SESSION['tmpval']['previous_server'])
1039 && $_SESSION['tmpval']['previous_server'] != $GLOBALS['server']
1041 unset($_SESSION['tmpval']['navi_limit_offset']);
1043 $_SESSION['tmpval']['previous_server'] = $GLOBALS['server'];
1045 } // end server connecting
1048 * check if profiling was requested and remember it
1049 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
1051 if (isset($_REQUEST['profiling'])
1052 && PMA_Util::profilingSupported()
1054 $_SESSION['profiling'] = true;
1055 } elseif (isset($_REQUEST['profiling_form'])) {
1056 // the checkbox was unchecked
1057 unset($_SESSION['profiling']);
1060 * Inclusion of profiling scripts is needed on various
1061 * pages like sql, tbl_sql, db_sql, tbl_select
1063 if (! defined('PMA_BYPASS_GET_INSTANCE')) {
1064 $response = PMA_Response::getInstance();
1066 if (isset($_SESSION['profiling'])) {
1067 $header = $response->getHeader();
1068 $scripts = $header->getScripts();
1069 $scripts->addFile('jqplot/jquery.jqplot.js');
1070 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
1071 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
1072 $scripts->addFile('canvg/canvg.js');
1073 $scripts->addFile('jquery/jquery.tablesorter.js');
1077 * There is no point in even attempting to process
1078 * an ajax request if there is a token mismatch
1080 if (isset($response) && $response->isAjax() && $token_mismatch) {
1081 $response->isSuccess(false);
1082 $response->addJSON(
1083 'message',
1084 PMA_Message::error(__('Error: Token mismatch'))
1086 exit;
1088 } // end if !defined('PMA_MINIMUM_COMMON')
1090 // load user preferences
1091 $GLOBALS['PMA_Config']->loadUserPreferences();
1093 // remove sensitive values from session
1094 $GLOBALS['PMA_Config']->set('blowfish_secret', '');
1095 $GLOBALS['PMA_Config']->set('Servers', '');
1096 $GLOBALS['PMA_Config']->set('default_server', '');
1098 /* Tell tracker that it can actually work */
1099 PMA_Tracker::enable();
1102 * @global boolean $GLOBALS['is_ajax_request']
1103 * @todo should this be moved to the variables init section above?
1105 * Check if the current request is an AJAX request, and set is_ajax_request
1106 * accordingly. Suppress headers, footers and unnecessary output if set to
1107 * true
1109 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
1110 $GLOBALS['is_ajax_request'] = true;
1111 } else {
1112 $GLOBALS['is_ajax_request'] = false;
1115 if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
1116 PMA_fatalError(__("GLOBALS overwrite attempt"));
1120 * protect against possible exploits - there is no need to have so much variables
1122 if (count($_REQUEST) > 1000) {
1123 PMA_fatalError(__('possible exploit'));
1127 * Check for numeric keys
1128 * (if register_globals is on, numeric key can be found in $GLOBALS)
1130 foreach ($GLOBALS as $key => $dummy) {
1131 if (is_numeric($key)) {
1132 PMA_fatalError(__('numeric key detected'));
1135 unset($dummy);
1137 // here, the function does not exist with this configuration:
1138 // $cfg['ServerDefault'] = 0;
1139 $GLOBALS['is_superuser']
1140 = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser();
1142 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
1144 * include subform target page
1146 include $__redirect;
1147 exit();