Remove broken link
[phpmyadmin.git] / libraries / common.inc.php
blobd039faa9345bc01d0d6cc2cefb1899f4a99c530a
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
33 use PMA\libraries\Config;
34 use PMA\libraries\DatabaseInterface;
35 use PMA\libraries\ErrorHandler;
36 use PMA\libraries\Message;
37 use PMA\libraries\plugins\AuthenticationPlugin;
38 use PMA\libraries\DbList;
39 use PMA\libraries\ThemeManager;
40 use PMA\libraries\Tracker;
41 use PMA\libraries\Response;
42 use PMA\libraries\TypesMySQL;
43 use PMA\libraries\Util;
44 use PMA\libraries\LanguageManager;
45 use PMA\libraries\Logging;
47 /**
48 * block attempts to directly run this script
50 if (getcwd() == dirname(__FILE__)) {
51 die('Attack stopped');
54 /**
55 * Minimum PHP version; can't call PMA_fatalError() which uses a
56 * PHP 5 function, so cannot easily localize this message.
58 if (version_compare(PHP_VERSION, '5.5.0', 'lt')) {
59 die(
60 'PHP 5.5+ is required. <br /> Currently installed version is: '
61 . phpversion()
65 /**
66 * for verification in all procedural scripts under libraries
68 define('PHPMYADMIN', true);
70 /**
71 * Load vendor configuration.
73 require_once './libraries/vendor_config.php';
75 /**
76 * Activate autoloader
78 if (! @is_readable('./vendor/autoload.php')) {
79 die(
80 'File <tt>./vendor/autoload.php</tt> missing or not readable. <br />'
81 . 'Most likely you did not run Composer to '
82 . '<a href="https://docs.phpmyadmin.net/en/latest/setup.html#installing-from-git">install library files</a>.'
85 require_once './vendor/autoload.php';
87 /**
88 * Load gettext functions.
90 PhpMyAdmin\MoTranslator\Loader::loadFunctions();
92 /**
93 * initialize the error handler
95 $GLOBALS['error_handler'] = new ErrorHandler();
97 /**
98 * core functions
100 require './libraries/core.lib.php';
103 * Warning about missing PHP extensions.
105 PMA_checkExtensions();
108 * Set utf-8 encoding for PHP
110 ini_set('default_charset', 'utf-8');
111 mb_internal_encoding('utf-8');
114 * Set precision to sane value, with higher values
115 * things behave slightly unexpectedly, for example
116 * round(1.2, 2) returns 1.199999999999999956.
118 ini_set('precision', 14);
121 * the relation lib, tracker needs it
123 require './libraries/relation.lib.php';
126 /******************************************************************************/
127 /* start procedural code label_start_procedural */
129 PMA_cleanupPathInfo();
132 * just to be sure there was no import (registering) before here
133 * we empty the global space (but avoid unsetting $variables_list
134 * and $key in the foreach (), we still need them!)
136 $variables_whitelist = array (
137 'GLOBALS',
138 '_SERVER',
139 '_GET',
140 '_POST',
141 '_REQUEST',
142 '_FILES',
143 '_ENV',
144 '_COOKIE',
145 '_SESSION',
146 'error_handler',
147 'PMA_PHP_SELF',
148 'variables_whitelist',
149 'key',
152 foreach (get_defined_vars() as $key => $value) {
153 if (! in_array($key, $variables_whitelist)) {
154 unset($$key);
157 unset($key, $value, $variables_whitelist);
160 * Subforms - some functions need to be called by form, cause of the limited URL
161 * length, but if this functions inside another form you cannot just open a new
162 * form - so phpMyAdmin uses 'arrays' inside this form
164 * <code>
165 * <form ...>
166 * ... main form elements ...
167 * <input type="hidden" name="subform[action1][id]" value="1" />
168 * ... other subform data ...
169 * <input type="submit" name="usesubform[action1]" value="do action1" />
170 * ... other subforms ...
171 * <input type="hidden" name="subform[actionX][id]" value="X" />
172 * ... other subform data ...
173 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
174 * ... main form elements ...
175 * <input type="submit" name="main_action" value="submit form" />
176 * </form>
177 * </code>
179 * so we now check if a subform is submitted
181 $__redirect = null;
182 if (isset($_POST['usesubform']) && ! defined('PMA_MINIMUM_COMMON')) {
183 // if a subform is present and should be used
184 // the rest of the form is deprecated
185 $subform_id = key($_POST['usesubform']);
186 $subform = $_POST['subform'][$subform_id];
187 $_POST = $subform;
188 $_REQUEST = $subform;
190 * some subforms need another page than the main form, so we will just
191 * include this page at the end of this script - we use $__redirect to
192 * track this
194 if (isset($_POST['redirect'])
195 && $_POST['redirect'] != basename($PMA_PHP_SELF)
197 $__redirect = $_POST['redirect'];
198 unset($_POST['redirect']);
200 unset($subform_id, $subform);
201 } else {
202 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
203 // because another application for the same domain could have set
204 // a cookie (with a compatible path) that overrides a variable
205 // we expect from GET or POST.
206 // We'll refer to cookies explicitly with the $_COOKIE syntax.
207 $_REQUEST = array_merge($_GET, $_POST);
209 // end check if a subform is submitted
212 * check timezone setting
213 * this could produce an E_WARNING - but only once,
214 * if not done here it will produce E_WARNING on every date/time function
216 date_default_timezone_set(@date_default_timezone_get());
218 /******************************************************************************/
219 /* parsing configuration file LABEL_parsing_config_file */
222 * @global Config $GLOBALS['PMA_Config']
223 * force reading of config file, because we removed sensitive values
224 * in the previous iteration
226 $GLOBALS['PMA_Config'] = new Config(CONFIG_FILE);
229 * BC - enable backward compatibility
230 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
232 $GLOBALS['PMA_Config']->enableBc();
235 * clean cookies on upgrade
236 * when changing something related to PMA cookies, increment the cookie version
238 $pma_cookie_version = 5;
239 if (isset($_COOKIE)) {
240 if (! isset($_COOKIE['pmaCookieVer'])
241 || $_COOKIE['pmaCookieVer'] != $pma_cookie_version
243 // delete all cookies
244 foreach ($_COOKIE as $cookie_name => $tmp) {
245 // We ignore cookies not with pma prefix
246 if (strncmp('pma', $cookie_name, 3) != 0) {
247 continue;
249 $GLOBALS['PMA_Config']->removeCookie($cookie_name);
251 $_COOKIE = array();
252 $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
257 * include session handling after the globals, to prevent overwriting
259 require './libraries/session.inc.php';
262 * init some variables LABEL_variables_init
266 * holds parameters to be passed to next page
267 * @global array $GLOBALS['url_params']
269 $GLOBALS['url_params'] = array();
272 * the whitelist for $GLOBALS['goto']
273 * @global array $goto_whitelist
275 $goto_whitelist = array(
276 'db_datadict.php',
277 'db_sql.php',
278 'db_events.php',
279 'db_export.php',
280 'db_importdocsql.php',
281 'db_qbe.php',
282 'db_structure.php',
283 'db_import.php',
284 'db_operations.php',
285 'db_search.php',
286 'db_routines.php',
287 'export.php',
288 'import.php',
289 'index.php',
290 'pdf_pages.php',
291 'pdf_schema.php',
292 'server_binlog.php',
293 'server_collations.php',
294 'server_databases.php',
295 'server_engines.php',
296 'server_export.php',
297 'server_import.php',
298 'server_privileges.php',
299 'server_sql.php',
300 'server_status.php',
301 'server_status_advisor.php',
302 'server_status_monitor.php',
303 'server_status_queries.php',
304 'server_status_variables.php',
305 'server_variables.php',
306 'sql.php',
307 'tbl_addfield.php',
308 'tbl_change.php',
309 'tbl_create.php',
310 'tbl_import.php',
311 'tbl_indexes.php',
312 'tbl_sql.php',
313 'tbl_export.php',
314 'tbl_operations.php',
315 'tbl_structure.php',
316 'tbl_relation.php',
317 'tbl_replace.php',
318 'tbl_row_action.php',
319 'tbl_select.php',
320 'tbl_zoom_select.php',
321 'transformation_overview.php',
322 'transformation_wrapper.php',
323 'user_password.php',
327 * check $__redirect against whitelist
329 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
330 $__redirect = null;
334 * holds page that should be displayed
335 * @global string $GLOBALS['goto']
337 $GLOBALS['goto'] = '';
338 // Security fix: disallow accessing serious server files via "?goto="
339 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
340 $GLOBALS['goto'] = $_REQUEST['goto'];
341 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
342 } else {
343 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
347 * returning page
348 * @global string $GLOBALS['back']
350 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
351 $GLOBALS['back'] = $_REQUEST['back'];
352 } else {
353 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
357 * Check whether user supplied token is valid, if not remove any possibly
358 * dangerous stuff from request.
360 * remember that some objects in the session with session_start and __wakeup()
361 * could access this variables before we reach this point
362 * f.e. PMA\libraries\Config: fontsize
364 * Check for token mismatch only if the Request method is POST
365 * GET Requests would never have token and therefore checking
366 * mis-match does not make sense
368 * @todo variables should be handled by their respective owners (objects)
369 * f.e. lang, server, collation_connection in PMA\libraries\Config
372 $token_mismatch = true;
373 $token_provided = false;
375 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
376 if (PMA_isValid($_POST['token'])) {
377 $token_provided = true;
378 $token_mismatch = ! @hash_equals($_SESSION[' PMA_token '], $_POST['token']);
381 if ($token_mismatch) {
383 * We don't allow any POST operation parameters if the token is mismatched
384 * or is not provided
386 $whitelist = array('ajax_request');
387 PMA\libraries\Sanitize::removeRequestVars($whitelist);
393 * current selected database
394 * @global string $GLOBALS['db']
396 PMA_setGlobalDbOrTable('db');
399 * current selected table
400 * @global string $GLOBALS['table']
402 PMA_setGlobalDbOrTable('table');
405 * Store currently selected recent table.
406 * Affect $GLOBALS['db'] and $GLOBALS['table']
408 if (PMA_isValid($_REQUEST['selected_recent_table'])) {
409 $recent_table = json_decode($_REQUEST['selected_recent_table'], true);
411 $GLOBALS['db']
412 = (array_key_exists('db', $recent_table) && is_string($recent_table['db'])) ?
413 $recent_table['db'] : '';
414 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
416 $GLOBALS['table']
417 = (array_key_exists('table', $recent_table) && is_string($recent_table['table'])) ?
418 $recent_table['table'] : '';
419 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
423 * SQL query to be executed
424 * @global string $GLOBALS['sql_query']
426 $GLOBALS['sql_query'] = '';
427 if (PMA_isValid($_REQUEST['sql_query'])) {
428 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
431 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
432 //$_REQUEST['server']; // checked later in this file
433 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
435 /******************************************************************************/
436 /* loading language file LABEL_loading_language_file */
439 * lang detection is done here
441 $language = LanguageManager::getInstance()->selectLanguage();
442 $language->activate();
444 // Defines the cell alignment values depending on text direction
445 if ($GLOBALS['text_dir'] == 'ltr') {
446 $GLOBALS['cell_align_left'] = 'left';
447 $GLOBALS['cell_align_right'] = 'right';
448 } else {
449 $GLOBALS['cell_align_left'] = 'right';
450 $GLOBALS['cell_align_right'] = 'left';
454 * check for errors occurred while loading configuration
455 * this check is done here after loading language files to present errors in locale
457 $GLOBALS['PMA_Config']->checkPermissions();
458 $GLOBALS['PMA_Config']->checkErrors();
461 * As we try to handle charsets by ourself, mbstring overloads just
462 * break it, see bug 1063821.
464 * We specifically use empty here as we are looking for anything else than
465 * empty value or 0.
467 if (@extension_loaded('mbstring') && !empty(@ini_get('mbstring.func_overload'))) {
468 PMA_fatalError(
470 'You have enabled mbstring.func_overload in your PHP '
471 . 'configuration. This option is incompatible with phpMyAdmin '
472 . 'and might cause some data to be corrupted!'
478 * The ini_set and ini_get functions can be disabled using
479 * disable_functions but we're relying quite a lot of them.
481 if (! function_exists('ini_get') || ! function_exists('ini_set')) {
482 PMA_fatalError(
484 'You have disabled ini_get and/or ini_set in php.ini. '
485 . 'This option is incompatible with phpMyAdmin!'
490 /******************************************************************************/
491 /* setup servers LABEL_setup_servers */
494 * current server
495 * @global integer $GLOBALS['server']
497 $GLOBALS['server'] = 0;
500 * Servers array fixups.
501 * $default_server comes from PMA\libraries\Config::enableBc()
502 * @todo merge into PMA\libraries\Config
504 // Do we have some server?
505 if (! isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
506 // No server => create one with defaults
507 $cfg['Servers'] = array(1 => $default_server);
508 } else {
509 // We have server(s) => apply default configuration
510 $new_servers = array();
512 foreach ($cfg['Servers'] as $server_index => $each_server) {
514 // Detect wrong configuration
515 if (!is_int($server_index) || $server_index < 1) {
516 trigger_error(
517 sprintf(__('Invalid server index: %s'), $server_index),
518 E_USER_ERROR
522 $each_server = array_merge($default_server, $each_server);
524 // Final solution to bug #582890
525 // If we are using a socket connection
526 // and there is nothing in the verbose server name
527 // or the host field, then generate a name for the server
528 // in the form of "Server 2", localized of course!
529 if (empty($each_server['host']) && empty($each_server['verbose'])) {
530 $each_server['verbose'] = sprintf(__('Server %d'), $server_index);
533 $new_servers[$server_index] = $each_server;
535 $cfg['Servers'] = $new_servers;
536 unset($new_servers, $server_index, $each_server);
539 // Cleanup
540 unset($default_server);
543 if (! defined('PMA_MINIMUM_COMMON')) {
545 * Lookup server by name
546 * (see FAQ 4.8)
548 if (! empty($_REQUEST['server'])
549 && is_string($_REQUEST['server'])
550 && ! is_numeric($_REQUEST['server'])
552 foreach ($cfg['Servers'] as $i => $server) {
553 $verboseToLower = mb_strtolower($server['verbose']);
554 $serverToLower = mb_strtolower($_REQUEST['server']);
555 if ($server['host'] == $_REQUEST['server']
556 || $server['verbose'] == $_REQUEST['server']
557 || $verboseToLower == $serverToLower
558 || md5($verboseToLower) === $serverToLower
560 $_REQUEST['server'] = $i;
561 break;
564 if (is_string($_REQUEST['server'])) {
565 unset($_REQUEST['server']);
567 unset($i);
572 * If no server is selected, make sure that $cfg['Server'] is empty (so
573 * that nothing will work), and skip server authentication.
574 * We do NOT exit here, but continue on without logging into any server.
575 * This way, the welcome page will still come up (with no server info) and
576 * present a choice of servers in the case that there are multiple servers
577 * and '$cfg['ServerDefault'] = 0' is set.
580 if (isset($_REQUEST['server'])
581 && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server']))
582 && ! empty($_REQUEST['server'])
583 && ! empty($cfg['Servers'][$_REQUEST['server']])
585 $GLOBALS['server'] = $_REQUEST['server'];
586 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
587 } else {
588 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
589 $GLOBALS['server'] = $cfg['ServerDefault'];
590 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
591 } else {
592 $GLOBALS['server'] = 0;
593 $cfg['Server'] = array();
596 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
598 /******************************************************************************/
599 /* setup themes LABEL_theme_setup */
601 ThemeManager::initializeTheme();
603 if (! defined('PMA_MINIMUM_COMMON')) {
605 * save some settings in cookies
606 * @todo should be done in PMA\libraries\Config
608 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
609 if (isset($GLOBALS['collation_connection'])) {
610 $GLOBALS['PMA_Config']->setCookie(
611 'pma_collation_connection',
612 $GLOBALS['collation_connection']
616 ThemeManager::getInstance()->setThemeCookie();
618 if (! empty($cfg['Server'])) {
621 * Loads the proper database interface for this server
623 include_once './libraries/database_interface.inc.php';
625 // get LoginCookieValidity from preferences cache
626 // no generic solution for loading preferences from cache as some settings
627 // need to be kept for processing in
628 // PMA\libraries\Config::loadUserPreferences()
629 $cache_key = 'server_' . $GLOBALS['server'];
630 if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])
632 $value
633 = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
634 $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
635 $GLOBALS['cfg']['LoginCookieValidity'] = $value;
636 unset($value);
638 unset($cache_key);
640 // Gets the authentication library that fits the $cfg['Server'] settings
641 // and run authentication
643 // to allow HTTP or http
644 $cfg['Server']['auth_type']
645 = mb_strtolower($cfg['Server']['auth_type']);
648 * the required auth type plugin
650 $auth_class = "Authentication" . ucfirst($cfg['Server']['auth_type']);
651 if (! @file_exists(
652 './libraries/plugins/auth/'
653 . $auth_class . '.php'
654 )) {
655 PMA_fatalError(
656 __('Invalid authentication method set in configuration:')
657 . ' ' . $cfg['Server']['auth_type']
660 if (isset($_REQUEST['pma_password']) && strlen($_REQUEST['pma_password']) > 256) {
661 $_REQUEST['pma_password'] = substr($_REQUEST['pma_password'], 0, 256);
663 $fqnAuthClass = 'PMA\libraries\plugins\auth\\' . $auth_class;
664 // todo: add plugin manager
665 $plugin_manager = null;
666 /** @var AuthenticationPlugin $auth_plugin */
667 $auth_plugin = new $fqnAuthClass($plugin_manager);
669 if (! $auth_plugin->authCheck()) {
670 /* Force generating of new session on login */
671 PMA_secureSession();
672 $auth_plugin->auth();
673 } else {
674 $auth_plugin->authSetUser();
677 // Check IP-based Allow/Deny rules as soon as possible to reject the
678 // user based on mod_access in Apache
679 if (isset($cfg['Server']['AllowDeny'])
680 && isset($cfg['Server']['AllowDeny']['order'])
684 * ip based access library
686 include_once './libraries/ip_allow_deny.lib.php';
688 $allowDeny_forbidden = false; // default
689 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
690 $allowDeny_forbidden = true;
691 if (PMA_allowDeny('allow')) {
692 $allowDeny_forbidden = false;
694 if (PMA_allowDeny('deny')) {
695 $allowDeny_forbidden = true;
697 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
698 if (PMA_allowDeny('deny')) {
699 $allowDeny_forbidden = true;
701 if (PMA_allowDeny('allow')) {
702 $allowDeny_forbidden = false;
704 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
705 if (PMA_allowDeny('allow') && ! PMA_allowDeny('deny')) {
706 $allowDeny_forbidden = false;
707 } else {
708 $allowDeny_forbidden = true;
710 } // end if ... elseif ... elseif
712 // Ejects the user if banished
713 if ($allowDeny_forbidden) {
714 Logging::logUser($cfg['Server']['user'], 'allow-denied');
715 $auth_plugin->authFails();
717 } // end if
719 // is root allowed?
720 if (! $cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
721 $allowDeny_forbidden = true;
722 Logging::logUser($cfg['Server']['user'], 'root-denied');
723 $auth_plugin->authFails();
726 // is a login without password allowed?
727 if (! $cfg['Server']['AllowNoPassword']
728 && $cfg['Server']['password'] === ''
730 $login_without_password_is_forbidden = true;
731 Logging::logUser($cfg['Server']['user'], 'empty-denied');
732 $auth_plugin->authFails();
735 // Try to connect MySQL with the control user profile (will be used to
736 // get the privileges list for the current user but the true user link
737 // must be open after this one so it would be default one for all the
738 // scripts)
739 $controllink = false;
740 if ($cfg['Server']['controluser'] != '') {
741 $controllink = $GLOBALS['dbi']->connect(
742 DatabaseInterface::CONNECT_CONTROL
746 // Connects to the server (validates user's login)
747 /** @var DatabaseInterface $userlink */
748 $userlink = $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_USER);
750 // Set timestamp for the session, if required.
751 if ($cfg['Server']['SessionTimeZone'] != '') {
752 $sql_query_tz = 'SET ' . Util::backquote('time_zone') . ' = '
753 . '\''
754 . $GLOBALS['dbi']->escapeString($cfg['Server']['SessionTimeZone'])
755 . '\'';
757 if (! $userlink->query($sql_query_tz)) {
758 $error_message_tz = sprintf(
760 'Unable to use timezone %1$s for server %2$d. '
761 . 'Please check your configuration setting for '
762 . '[em]$cfg[\'Servers\'][%3$d][\'SessionTimeZone\'][/em]. '
763 . 'phpMyAdmin is currently using the default time zone '
764 . 'of the database server.'
766 $cfg['Servers'][$GLOBALS['server']]['SessionTimeZone'],
767 $GLOBALS['server'],
768 $GLOBALS['server']
771 $GLOBALS['error_handler']->addError(
772 $error_message_tz,
773 E_USER_WARNING,
776 false
781 if (! $controllink) {
783 * Open separate connection for control queries, this is needed
784 * to avoid problems with table locking used in main connection
785 * and phpMyAdmin issuing queries to configuration storage, which
786 * is not locked by that time.
788 $controllink = $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_USER);
791 $auth_plugin->storeUserCredentials();
793 /* Log success */
794 Logging::logUser($cfg['Server']['user']);
796 if (PMA_MYSQL_INT_VERSION < $cfg['MysqlMinVersion']['internal']) {
797 PMA_fatalError(
798 __('You should upgrade to %s %s or later.'),
799 array('MySQL', $cfg['MysqlMinVersion']['human'])
804 * Type handling object.
806 $GLOBALS['PMA_Types'] = new TypesMySQL();
808 // Loads closest context to this version.
809 PhpMyAdmin\SqlParser\Context::loadClosest('MySql' . PMA_MYSQL_INT_VERSION);
811 // Sets the default delimiter (if specified).
812 if (!empty($_REQUEST['sql_delimiter'])) {
813 PhpMyAdmin\SqlParser\Lexer::$DEFAULT_DELIMITER = $_REQUEST['sql_delimiter'];
816 // TODO: Set SQL modes too.
819 * the DbList class as a stub for the ListDatabase class
821 $dblist = new DbList;
822 $dblist->userlink = $userlink;
823 $dblist->controllink = $controllink;
826 * some resetting has to be done when switching servers
828 if (isset($_SESSION['tmpval']['previous_server'])
829 && $_SESSION['tmpval']['previous_server'] != $GLOBALS['server']
831 unset($_SESSION['tmpval']['navi_limit_offset']);
833 $_SESSION['tmpval']['previous_server'] = $GLOBALS['server'];
835 } else { // end server connecting
836 // No need to check for 'PMA_BYPASS_GET_INSTANCE' since this execution path
837 // applies only to initial login
838 $response = Response::getInstance();
839 $response->getHeader()->disableMenuAndConsole();
840 $response->getFooter()->setMinimal();
844 * check if profiling was requested and remember it
845 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
847 if (isset($_REQUEST['profiling'])
848 && Util::profilingSupported()
850 $_SESSION['profiling'] = true;
851 } elseif (isset($_REQUEST['profiling_form'])) {
852 // the checkbox was unchecked
853 unset($_SESSION['profiling']);
856 // load user preferences
857 $GLOBALS['PMA_Config']->loadUserPreferences();
860 * Inclusion of profiling scripts is needed on various
861 * pages like sql, tbl_sql, db_sql, tbl_select
863 if (! defined('PMA_BYPASS_GET_INSTANCE')) {
864 $response = Response::getInstance();
866 if (isset($response) && isset($_SESSION['profiling'])) {
867 $header = $response->getHeader();
868 $scripts = $header->getScripts();
869 $scripts->addFile('chart.js');
870 $scripts->addFile('jqplot/jquery.jqplot.js');
871 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
872 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
873 $scripts->addFile('jquery/jquery.tablesorter.js');
877 * There is no point in even attempting to process
878 * an ajax request if there is a token mismatch
880 if (isset($response) && $response->isAjax() && $_SERVER['REQUEST_METHOD'] == 'POST' && $token_mismatch) {
881 $response->setRequestStatus(false);
882 $response->addJSON(
883 'message',
884 Message::error(__('Error: Token mismatch'))
886 exit;
888 } else { // end if !defined('PMA_MINIMUM_COMMON')
889 // load user preferences
890 $GLOBALS['PMA_Config']->loadUserPreferences();
893 // remove sensitive values from session
894 $GLOBALS['PMA_Config']->set('blowfish_secret', '');
895 $GLOBALS['PMA_Config']->set('Servers', '');
896 $GLOBALS['PMA_Config']->set('default_server', '');
898 /* Tell tracker that it can actually work */
899 Tracker::enable();
901 if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
902 PMA_fatalError(__("GLOBALS overwrite attempt"));
906 * protect against possible exploits - there is no need to have so much variables
908 if (count($_REQUEST) > 1000) {
909 PMA_fatalError(__('possible exploit'));
912 // here, the function does not exist with this configuration:
913 // $cfg['ServerDefault'] = 0;
914 $GLOBALS['is_superuser']
915 = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser();
917 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
919 * include subform target page
921 include $__redirect;
922 exit();
925 // If Zero configuration mode enabled, check PMA tables in current db.
926 if (! defined('PMA_MINIMUM_COMMON')
927 && ! empty($GLOBALS['server'])
928 && isset($GLOBALS['cfg']['ZeroConf'])
929 && $GLOBALS['cfg']['ZeroConf'] == true
931 if (! empty($GLOBALS['db'])) {
932 $cfgRelation = PMA_getRelationsParam();
933 if (empty($cfgRelation['db'])) {
934 PMA_fixPMATables($GLOBALS['db'], false);
937 $cfgRelation = PMA_getRelationsParam();
938 if (empty($cfgRelation['db'])) {
939 if ($GLOBALS['dblist']->databases->exists('phpmyadmin')) {
940 PMA_fixPMATables('phpmyadmin', false);
945 if (! defined('PMA_MINIMUM_COMMON')) {
946 include_once 'libraries/config/messages.inc.php';
947 include 'libraries/config/user_preferences.forms.php';
948 include_once 'libraries/config/page_settings.forms.php';