Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / phpmyadmin / libraries / common.inc.php
blob85cf8f49ec28d54965aeef477a5eee473e94e989
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 * This setting was removed in PHP 5.4. But at this point PMA_PHP_INT_VERSION
73 * is not yet defined so we use another way to find out the PHP version.
75 if (version_compare(phpversion(), '5.4', 'lt')) {
76 /**
77 * Avoid problems with magic_quotes_runtime
79 @ini_set('magic_quotes_runtime', false);
82 /**
83 * for verification in all procedural scripts under libraries
85 define('PHPMYADMIN', true);
87 /**
88 * core functions
90 require './libraries/core.lib.php';
92 /**
93 * Input sanitizing
95 require './libraries/sanitizing.lib.php';
97 /**
98 * the PMA_Theme class
100 require './libraries/Theme.class.php';
103 * the PMA_Theme_Manager class
105 require './libraries/Theme_Manager.class.php';
108 * the PMA_Config class
110 require './libraries/Config.class.php';
113 * the relation lib, tracker needs it
115 require './libraries/relation.lib.php';
118 * the PMA_Tracker class
120 require './libraries/Tracker.class.php';
123 * the PMA_Table class
125 require './libraries/Table.class.php';
128 * the PMA_Types class
130 require './libraries/Types.class.php';
132 if (! defined('PMA_MINIMUM_COMMON')) {
134 * common functions
136 include_once './libraries/Util.class.php';
139 * JavaScript escaping.
141 include_once './libraries/js_escape.lib.php';
144 * Include URL/hidden inputs generating.
146 include_once './libraries/url_generating.lib.php';
149 * Used to generate the page
151 include_once 'libraries/Response.class.php';
154 /******************************************************************************/
155 /* start procedural code label_start_procedural */
158 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
159 * and provide a clean PHP_SELF here
161 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
162 $_PATH_INFO = PMA_getenv('PATH_INFO');
163 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
164 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
165 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
166 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
169 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
173 * just to be sure there was no import (registering) before here
174 * we empty the global space (but avoid unsetting $variables_list
175 * and $key in the foreach (), we still need them!)
177 $variables_whitelist = array (
178 'GLOBALS',
179 '_SERVER',
180 '_GET',
181 '_POST',
182 '_REQUEST',
183 '_FILES',
184 '_ENV',
185 '_COOKIE',
186 '_SESSION',
187 'error_handler',
188 'PMA_PHP_SELF',
189 'variables_whitelist',
190 'key'
193 foreach (get_defined_vars() as $key => $value) {
194 if (! in_array($key, $variables_whitelist)) {
195 unset($$key);
198 unset($key, $value, $variables_whitelist);
202 * Subforms - some functions need to be called by form, cause of the limited URL
203 * length, but if this functions inside another form you cannot just open a new
204 * form - so phpMyAdmin uses 'arrays' inside this form
206 * <code>
207 * <form ...>
208 * ... main form elments ...
209 * <input type="hidden" name="subform[action1][id]" value="1" />
210 * ... other subform data ...
211 * <input type="submit" name="usesubform[action1]" value="do action1" />
212 * ... other subforms ...
213 * <input type="hidden" name="subform[actionX][id]" value="X" />
214 * ... other subform data ...
215 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
216 * ... main form elments ...
217 * <input type="submit" name="main_action" value="submit form" />
218 * </form>
219 * </code>
221 * so we now check if a subform is submitted
223 $__redirect = null;
224 if (isset($_POST['usesubform'])) {
225 // if a subform is present and should be used
226 // the rest of the form is deprecated
227 $subform_id = key($_POST['usesubform']);
228 $subform = $_POST['subform'][$subform_id];
229 $_POST = $subform;
230 $_REQUEST = $subform;
232 * some subforms need another page than the main form, so we will just
233 * include this page at the end of this script - we use $__redirect to
234 * track this
236 if (isset($_POST['redirect'])
237 && $_POST['redirect'] != basename($PMA_PHP_SELF)
239 $__redirect = $_POST['redirect'];
240 unset($_POST['redirect']);
242 unset($subform_id, $subform);
243 } else {
244 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
245 // because another application for the same domain could have set
246 // a cookie (with a compatible path) that overrides a variable
247 // we expect from GET or POST.
248 // We'll refer to cookies explicitly with the $_COOKIE syntax.
249 $_REQUEST = array_merge($_GET, $_POST);
251 // end check if a subform is submitted
254 * This setting was removed in PHP 5.4. But at this point PMA_PHP_INT_VERSION
255 * is not yet defined so we use another way to find out the PHP version.
257 if (version_compare(phpversion(), '5.4', 'lt')) {
258 // remove quotes added by PHP
259 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
260 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
261 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
262 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
263 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
268 * check timezone setting
269 * this could produce an E_STRICT - but only once,
270 * if not done here it will produce E_STRICT on every date/time function
271 * (starting with PHP 5.3, this code can produce E_WARNING rather than
272 * E_STRICT)
275 date_default_timezone_set(@date_default_timezone_get());
277 /******************************************************************************/
278 /* parsing configuration file LABEL_parsing_config_file */
281 * We really need this one!
283 if (! function_exists('preg_replace')) {
284 PMA_warnMissingExtension('pcre', true);
288 * JSON is required in several places.
290 if (! function_exists('json_encode')) {
291 PMA_warnMissingExtension('json', true);
295 * @global PMA_Config $GLOBALS['PMA_Config']
296 * force reading of config file, because we removed sensitive values
297 * in the previous iteration
299 $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
301 if (!defined('PMA_MINIMUM_COMMON')) {
302 $GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
306 * BC - enable backward compatibility
307 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
309 $GLOBALS['PMA_Config']->enableBc();
312 * clean cookies on upgrade
313 * when changing something related to PMA cookies, increment the cookie version
315 $pma_cookie_version = 4;
316 if (isset($_COOKIE)
317 && (isset($_COOKIE['pmaCookieVer'])
318 && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)
320 // delete all cookies
321 foreach ($_COOKIE as $cookie_name => $tmp) {
322 $GLOBALS['PMA_Config']->removeCookie($cookie_name);
324 $_COOKIE = array();
325 $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
330 * check HTTPS connection
332 if ($GLOBALS['PMA_Config']->get('ForceSSL')
333 && ! $GLOBALS['PMA_Config']->get('is_https')
335 // grab SSL URL
336 $url = $GLOBALS['PMA_Config']->getSSLUri();
337 // Actually redirect
338 PMA_sendHeaderLocation($url . PMA_generate_common_url($_GET, 'text'));
339 // delete the current session, otherwise we get problems (see bug #2397877)
340 $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
341 exit;
346 * include session handling after the globals, to prevent overwriting
348 require './libraries/session.inc.php';
351 * init some variables LABEL_variables_init
355 * holds parameters to be passed to next page
356 * @global array $GLOBALS['url_params']
358 $GLOBALS['url_params'] = array();
361 * the whitelist for $GLOBALS['goto']
362 * @global array $goto_whitelist
364 $goto_whitelist = array(
365 //'browse_foreigners.php',
366 //'changelog.php',
367 //'chk_rel.php',
368 'db_create.php',
369 'db_datadict.php',
370 'db_sql.php',
371 'db_events.php',
372 'db_export.php',
373 'db_importdocsql.php',
374 'db_qbe.php',
375 'db_structure.php',
376 'db_import.php',
377 'db_operations.php',
378 'db_printview.php',
379 'db_search.php',
380 'db_routines.php',
381 'export.php',
382 'import.php',
383 //'index.php',
384 //'navigation.php',
385 //'license.php',
386 'index.php',
387 'pdf_pages.php',
388 'pdf_schema.php',
389 //'phpinfo.php',
390 'querywindow.php',
391 'server_binlog.php',
392 'server_collations.php',
393 'server_databases.php',
394 'server_engines.php',
395 'server_export.php',
396 'server_import.php',
397 'server_privileges.php',
398 'server_sql.php',
399 'server_status.php',
400 'server_status_advisor.php',
401 'server_status_monitor.php',
402 'server_status_queries.php',
403 'server_status_variables.php',
404 'server_variables.php',
405 'sql.php',
406 'tbl_addfield.php',
407 'tbl_change.php',
408 'tbl_create.php',
409 'tbl_import.php',
410 'tbl_indexes.php',
411 'tbl_move_copy.php',
412 'tbl_printview.php',
413 'tbl_sql.php',
414 'tbl_export.php',
415 'tbl_operations.php',
416 'tbl_structure.php',
417 'tbl_relation.php',
418 'tbl_replace.php',
419 'tbl_row_action.php',
420 'tbl_select.php',
421 'tbl_zoom_select.php',
422 //'themes.php',
423 'transformation_overview.php',
424 'transformation_wrapper.php',
425 'user_password.php',
429 * check $__redirect against whitelist
431 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
432 $__redirect = null;
436 * holds page that should be displayed
437 * @global string $GLOBALS['goto']
439 $GLOBALS['goto'] = '';
440 // Security fix: disallow accessing serious server files via "?goto="
441 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
442 $GLOBALS['goto'] = $_REQUEST['goto'];
443 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
444 } else {
445 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
449 * returning page
450 * @global string $GLOBALS['back']
452 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
453 $GLOBALS['back'] = $_REQUEST['back'];
454 } else {
455 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
459 * Check whether user supplied token is valid, if not remove any possibly
460 * dangerous stuff from request.
462 * remember that some objects in the session with session_start and __wakeup()
463 * could access this variables before we reach this point
464 * f.e. PMA_Config: fontsize
466 * @todo variables should be handled by their respective owners (objects)
467 * f.e. lang, server, collation_connection in PMA_Config
469 $token_mismatch = true;
470 if (PMA_isValid($_REQUEST['token'])) {
471 $token_mismatch = ($_SESSION[' PMA_token '] != $_REQUEST['token']);
474 if ($token_mismatch) {
476 * List of parameters which are allowed from unsafe source
478 $allow_list = array(
479 /* needed for direct access, see FAQ 1.34
480 * also, server needed for cookie login screen (multi-server)
482 'server', 'db', 'table', 'target', 'lang',
483 /* Session ID */
484 'phpMyAdmin',
485 /* Cookie preferences */
486 'pma_lang', 'pma_collation_connection',
487 /* Possible login form */
488 'pma_servername', 'pma_username', 'pma_password',
489 /* Needed to send the correct reply */
490 'ajax_request',
491 /* Permit to log out even if there is a token mismatch */
492 'old_usr'
495 * Allow changing themes in test/theme.php
497 if (defined('PMA_TEST_THEME')) {
498 $allow_list[] = 'set_theme';
501 * Require cleanup functions
503 include './libraries/cleanup.lib.php';
505 * Do actual cleanup
507 PMA_remove_request_vars($allow_list);
513 * current selected database
514 * @global string $GLOBALS['db']
516 $GLOBALS['db'] = '';
517 if (PMA_isValid($_REQUEST['db'])) {
518 // can we strip tags from this?
519 // only \ and / is not allowed in db names for MySQL
520 $GLOBALS['db'] = $_REQUEST['db'];
521 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
525 * current selected table
526 * @global string $GLOBALS['table']
528 $GLOBALS['table'] = '';
529 if (PMA_isValid($_REQUEST['table'])) {
530 // can we strip tags from this?
531 // only \ and / is not allowed in table names for MySQL
532 $GLOBALS['table'] = $_REQUEST['table'];
533 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
537 * Store currently selected recent table.
538 * Affect $GLOBALS['db'] and $GLOBALS['table']
540 if (PMA_isValid($_REQUEST['selected_recent_table'])) {
541 $recent_table = json_decode($_REQUEST['selected_recent_table'], true);
542 $GLOBALS['db'] = $recent_table['db'];
543 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
544 $GLOBALS['table'] = $recent_table['table'];
545 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
549 * SQL query to be executed
550 * @global string $GLOBALS['sql_query']
552 $GLOBALS['sql_query'] = '';
553 if (PMA_isValid($_REQUEST['sql_query'])) {
554 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
557 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
558 //$_REQUEST['server']; // checked later in this file
559 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
561 /******************************************************************************/
562 /* loading language file LABEL_loading_language_file */
565 * lang detection is done here
567 require './libraries/select_lang.lib.php';
569 // Defines the cell alignment values depending on text direction
570 if ($GLOBALS['text_dir'] == 'ltr') {
571 $GLOBALS['cell_align_left'] = 'left';
572 $GLOBALS['cell_align_right'] = 'right';
573 } else {
574 $GLOBALS['cell_align_left'] = 'right';
575 $GLOBALS['cell_align_right'] = 'left';
579 * check for errors occurred while loading configuration
580 * this check is done here after loading language files to present errors in locale
582 $GLOBALS['PMA_Config']->checkPermissions();
584 if ($GLOBALS['PMA_Config']->error_config_file) {
585 $error = '[strong]' . __('Failed to read configuration file') . '[/strong]'
586 . '[br][br]'
587 . __('This usually means there is a syntax error in it, please check any errors shown below.')
588 . '[br][br]'
589 . '[conferr]';
590 trigger_error($error, E_USER_ERROR);
592 if ($GLOBALS['PMA_Config']->error_config_default_file) {
593 $error = sprintf(
594 __('Could not load default configuration from: %1$s'),
595 $GLOBALS['PMA_Config']->default_source
597 trigger_error($error, E_USER_ERROR);
599 if ($GLOBALS['PMA_Config']->error_pma_uri) {
600 trigger_error(
601 __('The [code]$cfg[\'PmaAbsoluteUri\'][/code] directive MUST be set in your configuration file!'),
602 E_USER_ERROR
607 /******************************************************************************/
608 /* setup servers LABEL_setup_servers */
611 * current server
612 * @global integer $GLOBALS['server']
614 $GLOBALS['server'] = 0;
617 * Servers array fixups.
618 * $default_server comes from PMA_Config::enableBc()
619 * @todo merge into PMA_Config
621 // Do we have some server?
622 if (! isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
623 // No server => create one with defaults
624 $cfg['Servers'] = array(1 => $default_server);
625 } else {
626 // We have server(s) => apply default configuration
627 $new_servers = array();
629 foreach ($cfg['Servers'] as $server_index => $each_server) {
631 // Detect wrong configuration
632 if (!is_int($server_index) || $server_index < 1) {
633 trigger_error(
634 sprintf(__('Invalid server index: %s'), $server_index),
635 E_USER_ERROR
639 $each_server = array_merge($default_server, $each_server);
641 // Don't use servers with no hostname
642 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
643 trigger_error(
644 sprintf(
645 __('Invalid hostname for server %1$s. Please review your configuration.'),
646 $server_index
648 E_USER_ERROR
652 // Final solution to bug #582890
653 // If we are using a socket connection
654 // and there is nothing in the verbose server name
655 // or the host field, then generate a name for the server
656 // in the form of "Server 2", localized of course!
657 if ($each_server['connect_type'] == 'socket'
658 && empty($each_server['host'])
659 && empty($each_server['verbose'])
661 $each_server['verbose'] = __('Server') . $server_index;
664 $new_servers[$server_index] = $each_server;
666 $cfg['Servers'] = $new_servers;
667 unset($new_servers, $server_index, $each_server);
670 // Cleanup
671 unset($default_server);
674 /******************************************************************************/
675 /* setup themes LABEL_theme_setup */
678 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
680 if (! isset($_SESSION['PMA_Theme_Manager'])) {
681 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
682 } else {
684 * @todo move all __wakeup() functionality into session.inc.php
686 $_SESSION['PMA_Theme_Manager']->checkConfig();
689 // for the theme per server feature
690 if (isset($_REQUEST['server']) && ! isset($_REQUEST['set_theme'])) {
691 $GLOBALS['server'] = $_REQUEST['server'];
692 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
693 if (empty($tmp)) {
694 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
696 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
697 unset($tmp);
700 * @todo move into PMA_Theme_Manager::__wakeup()
702 if (isset($_REQUEST['set_theme'])) {
703 // if user selected a theme
704 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
708 * the theme object
709 * @global PMA_Theme $_SESSION['PMA_Theme']
711 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
713 // BC
715 * the active theme
716 * @global string $GLOBALS['theme']
718 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
720 * the theme path
721 * @global string $GLOBALS['pmaThemePath']
723 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
725 * the theme image path
726 * @global string $GLOBALS['pmaThemeImage']
728 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
731 * load layout file if exists
733 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
734 include $_SESSION['PMA_Theme']->getLayoutFile();
737 if (! defined('PMA_MINIMUM_COMMON')) {
738 // get a dummy object to ensure that the class is instanciated
739 PMA_Response::getInstance();
742 * Character set conversion.
744 include_once './libraries/charset_conversion.lib.php';
747 * String handling
749 include_once './libraries/string.lib.php';
752 * Lookup server by name
753 * (see FAQ 4.8)
755 if (! empty($_REQUEST['server'])
756 && is_string($_REQUEST['server'])
757 && ! is_numeric($_REQUEST['server'])
759 foreach ($cfg['Servers'] as $i => $server) {
760 if ($server['host'] == $_REQUEST['server']) {
761 $_REQUEST['server'] = $i;
762 break;
765 if (is_string($_REQUEST['server'])) {
766 unset($_REQUEST['server']);
768 unset($i);
772 * If no server is selected, make sure that $cfg['Server'] is empty (so
773 * that nothing will work), and skip server authentication.
774 * We do NOT exit here, but continue on without logging into any server.
775 * This way, the welcome page will still come up (with no server info) and
776 * present a choice of servers in the case that there are multiple servers
777 * and '$cfg['ServerDefault'] = 0' is set.
780 if (isset($_REQUEST['server'])
781 && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server']))
782 && ! empty($_REQUEST['server'])
783 && ! empty($cfg['Servers'][$_REQUEST['server']])
785 $GLOBALS['server'] = $_REQUEST['server'];
786 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
787 } else {
788 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
789 $GLOBALS['server'] = $cfg['ServerDefault'];
790 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
791 } else {
792 $GLOBALS['server'] = 0;
793 $cfg['Server'] = array();
796 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
799 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
801 if (function_exists('mb_convert_encoding')
802 && $lang == 'ja'
804 include_once './libraries/kanji-encoding.lib.php';
805 } // end if
808 * save some settings in cookies
809 * @todo should be done in PMA_Config
811 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
812 if (isset($GLOBALS['collation_connection'])) {
813 $GLOBALS['PMA_Config']->setCookie(
814 'pma_collation_connection',
815 $GLOBALS['collation_connection']
819 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
821 if (! empty($cfg['Server'])) {
824 * Loads the proper database interface for this server
826 include_once './libraries/database_interface.lib.php';
828 include_once './libraries/logging.lib.php';
830 // get LoginCookieValidity from preferences cache
831 // no generic solution for loading preferences from cache as some settings
832 // need to be kept for processing in PMA_Config::loadUserPreferences()
833 $cache_key = 'server_' . $GLOBALS['server'];
834 if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])) {
835 $value = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
836 $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
837 $GLOBALS['cfg']['LoginCookieValidity'] = $value;
838 unset($value);
840 unset($cache_key);
842 // Gets the authentication library that fits the $cfg['Server'] settings
843 // and run authentication
845 // to allow HTTP or http
846 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
849 * the required auth type plugin
851 $auth_class = "Authentication" . ucfirst($cfg['Server']['auth_type']);
852 if (! file_exists('./libraries/plugins/auth/' . $auth_class . '.class.php')) {
853 PMA_fatalError(
854 __('Invalid authentication method set in configuration:')
855 . ' ' . $cfg['Server']['auth_type']
858 include_once './libraries/plugins/auth/' . $auth_class . '.class.php';
859 // todo: add plugin manager
860 $plugin_manager = null;
861 $auth_plugin = new $auth_class($plugin_manager);
863 if (! $auth_plugin->authCheck()) {
864 /* Force generating of new session on login */
865 PMA_secureSession();
866 $auth_plugin->auth();
867 } else {
868 $auth_plugin->authSetUser();
871 // Check IP-based Allow/Deny rules as soon as possible to reject the
872 // user
873 // Based on mod_access in Apache:
874 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
875 // Look at: "static int check_dir_access(request_rec *r)"
876 if (isset($cfg['Server']['AllowDeny'])
877 && isset($cfg['Server']['AllowDeny']['order'])
881 * ip based access library
883 include_once './libraries/ip_allow_deny.lib.php';
885 $allowDeny_forbidden = false; // default
886 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
887 $allowDeny_forbidden = true;
888 if (PMA_allowDeny('allow')) {
889 $allowDeny_forbidden = false;
891 if (PMA_allowDeny('deny')) {
892 $allowDeny_forbidden = true;
894 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
895 if (PMA_allowDeny('deny')) {
896 $allowDeny_forbidden = true;
898 if (PMA_allowDeny('allow')) {
899 $allowDeny_forbidden = false;
901 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
902 if (PMA_allowDeny('allow') && ! PMA_allowDeny('deny')) {
903 $allowDeny_forbidden = false;
904 } else {
905 $allowDeny_forbidden = true;
907 } // end if ... elseif ... elseif
909 // Ejects the user if banished
910 if ($allowDeny_forbidden) {
911 PMA_log_user($cfg['Server']['user'], 'allow-denied');
912 $auth_plugin->authFails();
914 } // end if
916 // is root allowed?
917 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
918 $allowDeny_forbidden = true;
919 PMA_log_user($cfg['Server']['user'], 'root-denied');
920 $auth_plugin->authFails();
923 // is a login without password allowed?
924 if (!$cfg['Server']['AllowNoPassword'] && $cfg['Server']['password'] == '') {
925 $login_without_password_is_forbidden = true;
926 PMA_log_user($cfg['Server']['user'], 'empty-denied');
927 $auth_plugin->authFails();
930 // if using TCP socket is not needed
931 if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
932 $cfg['Server']['socket'] = '';
935 // Try to connect MySQL with the control user profile (will be used to
936 // get the privileges list for the current user but the true user link
937 // must be open after this one so it would be default one for all the
938 // scripts)
939 $controllink = false;
940 if ($cfg['Server']['controluser'] != '') {
941 if (! empty($cfg['Server']['controlhost'])) {
942 $controllink = PMA_DBI_connect(
943 $cfg['Server']['controluser'],
944 $cfg['Server']['controlpass'],
945 true,
946 array('host' => $cfg['Server']['controlhost'])
948 } else {
949 $controllink = PMA_DBI_connect(
950 $cfg['Server']['controluser'],
951 $cfg['Server']['controlpass'],
952 true
957 // Connects to the server (validates user's login)
958 $userlink = PMA_DBI_connect(
959 $cfg['Server']['user'], $cfg['Server']['password'], false
962 if (! $controllink) {
963 $controllink = $userlink;
966 /* Log success */
967 PMA_log_user($cfg['Server']['user']);
970 * with phpMyAdmin 3 we support MySQL >=5
971 * but only production releases:
972 * - > 5.0.15
974 if (PMA_MYSQL_INT_VERSION < 50015) {
975 PMA_fatalError(
976 __('You should upgrade to %s %s or later.'),
977 array('MySQL', '5.0.15')
982 * Type handling object.
984 if (PMA_DRIZZLE) {
985 $GLOBALS['PMA_Types'] = new PMA_Types_Drizzle();
986 } else {
987 $GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
990 if (PMA_DRIZZLE) {
991 // DisableIS must be set to false for Drizzle, it maps SHOW commands
992 // to INFORMATION_SCHEMA queries anyway so it's fast on large servers
993 $cfg['Server']['DisableIS'] = false;
994 // SHOW OPEN TABLES is not supported by Drizzle
995 $cfg['SkipLockedTables'] = false;
999 * SQL Parser code
1001 include_once './libraries/sqlparser.lib.php';
1004 * SQL Validator interface code
1006 include_once './libraries/sqlvalidator.lib.php';
1009 * the PMA_List_Database class
1011 include_once './libraries/PMA.php';
1012 $pma = new PMA;
1013 $pma->userlink = $userlink;
1014 $pma->controllink = $controllink;
1017 * some resetting has to be done when switching servers
1019 if (isset($_SESSION['tmp_user_values']['previous_server'])
1020 && $_SESSION['tmp_user_values']['previous_server'] != $GLOBALS['server']
1022 unset($_SESSION['tmp_user_values']['navi_limit_offset']);
1024 $_SESSION['tmp_user_values']['previous_server'] = $GLOBALS['server'];
1026 } // end server connecting
1029 * check if profiling was requested and remember it
1030 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
1032 if (isset($_REQUEST['profiling'])
1033 && PMA_Util::profilingSupported()
1035 $_SESSION['profiling'] = true;
1036 } elseif (isset($_REQUEST['profiling_form'])) {
1037 // the checkbox was unchecked
1038 unset($_SESSION['profiling']);
1041 * Inclusion of profiling scripts is needed on various
1042 * pages like sql, tbl_sql, db_sql, tbl_select
1044 $response = PMA_Response::getInstance();
1045 if (isset($_SESSION['profiling'])) {
1046 $header = $response->getHeader();
1047 $scripts = $header->getScripts();
1048 /* < IE 9 doesn't support canvas natively */
1049 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
1050 $scripts->addFile('canvg/flashcanvas.js');
1052 $scripts->addFile('jqplot/jquery.jqplot.js');
1053 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
1054 $scripts->addFile('canvg/canvg.js');
1058 * There is no point in even attempting to process
1059 * an ajax request if there is a token mismatch
1061 if ($response->isAjax() && $token_mismatch) {
1062 $response->isSuccess(false);
1063 $response->addJSON(
1064 'message',
1065 PMA_Message::error(__('Error: Token mismatch'))
1067 exit;
1069 } // end if !defined('PMA_MINIMUM_COMMON')
1071 // load user preferences
1072 $GLOBALS['PMA_Config']->loadUserPreferences();
1074 // remove sensitive values from session
1075 $GLOBALS['PMA_Config']->set('blowfish_secret', '');
1076 $GLOBALS['PMA_Config']->set('Servers', '');
1077 $GLOBALS['PMA_Config']->set('default_server', '');
1079 /* Tell tracker that it can actually work */
1080 PMA_Tracker::enable();
1083 * @global boolean $GLOBALS['is_ajax_request']
1084 * @todo should this be moved to the variables init section above?
1086 * Check if the current request is an AJAX request, and set is_ajax_request
1087 * accordingly. Suppress headers, footers and unnecessary output if set to
1088 * true
1090 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
1091 $GLOBALS['is_ajax_request'] = true;
1092 } else {
1093 $GLOBALS['is_ajax_request'] = false;
1097 * @global boolean $GLOBALS['grid_edit']
1099 * Set to true if this is a request made during an grid edit process. This
1100 * request is made to retrieve the non-truncated/transformed values.
1102 if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) {
1103 $GLOBALS['grid_edit'] = true;
1104 } else {
1105 $GLOBALS['grid_edit'] = false;
1108 if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
1109 PMA_fatalError(__("GLOBALS overwrite attempt"));
1113 * protect against possible exploits - there is no need to have so much variables
1115 if (count($_REQUEST) > 1000) {
1116 PMA_fatalError(__('possible exploit'));
1120 * Check for numeric keys
1121 * (if register_globals is on, numeric key can be found in $GLOBALS)
1123 foreach ($GLOBALS as $key => $dummy) {
1124 if (is_numeric($key)) {
1125 PMA_fatalError(__('numeric key detected'));
1128 unset($dummy);
1130 // here, the function does not exist with this configuration:
1131 // $cfg['ServerDefault'] = 0;
1132 $GLOBALS['is_superuser'] = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
1134 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
1136 * include subform target page
1138 include $__redirect;
1139 exit();