for last XSS fix: forgot to whitelist PMA_PHP_SELF
[phpmyadmin/arisferyanto.git] / libraries / common.inc.php
blob2264abeb0f0900bef8afb4c3ed90ccdbedaa2ac3
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 include of libraries/defines_mysql.lib.php must be after the connection
12 * to db to get the MySql version
14 * the authentication libraries must be before the connection to db
16 * ... so the required order is:
18 * LABEL_variables_init
19 * - initialize some variables always needed
20 * LABEL_parsing_config_file
21 * - parsing of the configuration file
22 * LABEL_loading_language_file
23 * - loading language file
24 * LABEL_theme_setup
25 * - setting up themes
27 * - load of MySQL extension (if necessary)
28 * - loading of an authentication library
29 * - db connection
30 * - authentication work
31 * - load of the libraries/defines_mysql.lib.php library to get the MySQL
32 * release number
34 * @version $Id$
37 /**
38 * For now, avoid warnings of E_STRICT mode
39 * (this must be done before function definitions)
41 if (defined('E_STRICT')) {
42 $old_error_reporting = error_reporting(0);
43 if ($old_error_reporting & E_STRICT) {
44 error_reporting($old_error_reporting ^ E_STRICT);
45 } else {
46 error_reporting($old_error_reporting);
48 unset($old_error_reporting);
51 // at this point PMA_PHP_INT_VERSION is not yet defined
52 if (version_compare(phpversion(), '6', 'lt')) {
53 /**
54 * Avoid object cloning errors
56 @ini_set('zend.ze1_compatibility_mode', false);
58 /**
59 * Avoid problems with magic_quotes_runtime
61 @ini_set('magic_quotes_runtime', false);
64 /**
65 * core functions
67 require_once './libraries/core.lib.php';
69 /**
70 * Input sanitizing
72 require_once './libraries/sanitizing.lib.php';
74 /**
75 * the PMA_Theme class
77 require_once './libraries/Theme.class.php';
79 /**
80 * the PMA_Theme_Manager class
82 require_once './libraries/Theme_Manager.class.php';
84 /**
85 * the PMA_Config class
87 require_once './libraries/Config.class.php';
89 /**
90 * the PMA_Table class
92 require_once './libraries/Table.class.php';
94 if (!defined('PMA_MINIMUM_COMMON')) {
95 /**
96 * common functions
98 require_once './libraries/common.lib.php';
101 * Java script escaping.
103 require_once './libraries/js_escape.lib.php';
106 * Include URL/hidden inputs generating.
108 require_once './libraries/url_generating.lib.php';
111 /******************************************************************************/
112 /* start procedural code label_start_procedural */
115 * protect against older PHP versions' bug about GLOBALS overwrite
116 * (no need to localize this message :))
117 * but what if script.php?GLOBALS[admin]=1&GLOBALS[_REQUEST]=1 ???
119 if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])
120 || isset($_SERVER['GLOBALS']) || isset($_COOKIE['GLOBALS'])
121 || isset($_ENV['GLOBALS'])) {
122 die('GLOBALS overwrite attempt');
126 * protect against possible exploits - there is no need to have so much variables
128 if (count($_REQUEST) > 1000) {
129 die('possible exploit');
133 * Check for numeric keys
134 * (if register_globals is on, numeric key can be found in $GLOBALS)
136 foreach ($GLOBALS as $key => $dummy) {
137 if (is_numeric($key)) {
138 die('numeric key detected');
143 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
144 * and provide a clean PHP_SELF here
146 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
147 $_PATH_INFO = PMA_getenv('PATH_INFO');
148 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
149 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
150 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
151 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
154 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
158 * just to be sure there was no import (registering) before here
159 * we empty the global space
161 $variables_whitelist = array (
162 'GLOBALS',
163 '_SERVER',
164 '_GET',
165 '_POST',
166 '_REQUEST',
167 '_FILES',
168 '_ENV',
169 '_COOKIE',
170 '_SESSION',
171 'PMA_PHP_SELF',
174 foreach (get_defined_vars() as $key => $value) {
175 if (! in_array($key, $variables_whitelist)) {
176 unset($$key);
179 unset($key, $value, $variables_whitelist);
183 * Subforms - some functions need to be called by form, cause of the limited URL
184 * length, but if this functions inside another form you cannot just open a new
185 * form - so phpMyAdmin uses 'arrays' inside this form
187 * <code>
188 * <form ...>
189 * ... main form elments ...
190 * <intput type="hidden" name="subform[action1][id]" value="1" />
191 * ... other subform data ...
192 * <intput type="submit" name="usesubform[action1]" value="do action1" />
193 * ... other subforms ...
194 * <intput type="hidden" name="subform[actionX][id]" value="X" />
195 * ... other subform data ...
196 * <intput type="submit" name="usesubform[actionX]" value="do actionX" />
197 * ... main form elments ...
198 * <intput type="submit" name="main_action" value="submit form" />
199 * </form>
200 * </code
202 * so we now check if a subform is submitted
204 $__redirect = null;
205 if (isset($_POST['usesubform'])) {
206 // if a subform is present and should be used
207 // the rest of the form is deprecated
208 $subform_id = key($_POST['usesubform']);
209 $subform = $_POST['subform'][$subform_id];
210 $_POST = $subform;
211 $_REQUEST = $subform;
213 * some subforms need another page than the main form, so we will just
214 * include this page at the end of this script - we use $__redirect to
215 * track this
217 if (isset($_POST['redirect'])
218 && $_POST['redirect'] != basename($PMA_PHP_SELF)) {
219 $__redirect = $_POST['redirect'];
220 unset($_POST['redirect']);
222 unset($subform_id, $subform);
224 // end check if a subform is submitted
226 // remove quotes added by php
227 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
228 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
229 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
230 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
231 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
235 * clean cookies on new install or upgrade
236 * when changing something with increment the cookie version
238 $pma_cookie_version = 4;
239 if (isset($_COOKIE)
240 && (! isset($_COOKIE['pmaCookieVer'])
241 || $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
242 // delete all cookies
243 foreach($_COOKIE as $cookie_name => $tmp) {
244 PMA_removeCookie($cookie_name);
246 $_COOKIE = array();
247 PMA_setCookie('pmaCookieVer', $pma_cookie_version);
251 * include deprecated grab_globals only if required
253 if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
254 require './libraries/grab_globals.lib.php';
258 * include session handling after the globals, to prevent overwriting
260 require_once './libraries/session.inc.php';
263 * init some variables LABEL_variables_init
267 * holds errors
268 * @global array $GLOBALS['PMA_errors']
270 $GLOBALS['PMA_errors'] = array();
273 * holds parameters to be passed to next page
274 * @global array $GLOBALS['url_params']
276 $GLOBALS['url_params'] = array();
279 * the whitelist for $GLOBALS['goto']
280 * @global array $goto_whitelist
282 $goto_whitelist = array(
283 //'browse_foreigners.php',
284 //'calendar.php',
285 //'changelog.php',
286 //'chk_rel.php',
287 'db_create.php',
288 'db_datadict.php',
289 'db_sql.php',
290 'db_export.php',
291 'db_importdocsql.php',
292 'db_qbe.php',
293 'db_structure.php',
294 'db_import.php',
295 'db_operations.php',
296 'db_printview.php',
297 'db_search.php',
298 //'Documentation.html',
299 //'error.php',
300 'export.php',
301 'import.php',
302 //'index.php',
303 //'navigation.php',
304 //'license.php',
305 'main.php',
306 'pdf_pages.php',
307 'pdf_schema.php',
308 //'phpinfo.php',
309 'querywindow.php',
310 //'readme.php',
311 'server_binlog.php',
312 'server_collations.php',
313 'server_databases.php',
314 'server_engines.php',
315 'server_export.php',
316 'server_import.php',
317 'server_privileges.php',
318 'server_processlist.php',
319 'server_sql.php',
320 'server_status.php',
321 'server_variables.php',
322 'sql.php',
323 'tbl_addfield.php',
324 'tbl_alter.php',
325 'tbl_change.php',
326 'tbl_create.php',
327 'tbl_import.php',
328 'tbl_indexes.php',
329 'tbl_move_copy.php',
330 'tbl_printview.php',
331 'tbl_sql.php',
332 'tbl_export.php',
333 'tbl_operations.php',
334 'tbl_structure.php',
335 'tbl_relation.php',
336 'tbl_replace.php',
337 'tbl_row_action.php',
338 'tbl_select.php',
339 //'themes.php',
340 'transformation_overview.php',
341 'transformation_wrapper.php',
342 'translators.html',
343 'user_password.php',
347 * check $__redirect against whitelist
349 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
350 $__redirect = null;
354 * holds page that should be displayed
355 * @global string $GLOBALS['goto']
357 $GLOBALS['goto'] = '';
358 // Security fix: disallow accessing serious server files via "?goto="
359 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
360 $GLOBALS['goto'] = $_REQUEST['goto'];
361 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
362 } else {
363 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
367 * returning page
368 * @global string $GLOBALS['back']
370 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
371 $GLOBALS['back'] = $_REQUEST['back'];
372 } else {
373 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
377 * Check whether user supplied token is valid, if not remove any possibly
378 * dangerous stuff from request.
380 * remember that some objects in the session with session_start and __wakeup()
381 * could access this variables before we reach this point
382 * f.e. PMA_Config: fontsize
384 * @todo variables should be handled by their respective owners (objects)
385 * f.e. lang, server, convcharset, collation_connection in PMA_Config
387 if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
389 * List of parameters which are allowed from unsafe source
391 $allow_list = array(
392 'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target',
393 /* Session ID */
394 'phpMyAdmin',
395 /* Cookie preferences */
396 'pma_lang', 'pma_charset', 'pma_collation_connection',
397 /* Possible login form */
398 'pma_servername', 'pma_username', 'pma_password',
401 * Require cleanup functions
403 require_once './libraries/cleanup.lib.php';
405 * Do actual cleanup
407 PMA_remove_request_vars($allow_list);
413 * @global string $convcharset
414 * @see select_lang.lib.php
416 if (isset($_REQUEST['convcharset'])) {
417 $convcharset = strip_tags($_REQUEST['convcharset']);
421 * current selected database
422 * @global string $GLOBALS['db']
424 $GLOBALS['db'] = '';
425 if (PMA_isValid($_REQUEST['db'])) {
426 // can we strip tags from this?
427 // only \ and / is not allowed in db names for MySQL
428 $GLOBALS['db'] = $_REQUEST['db'];
429 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
433 * current selected table
434 * @global string $GLOBALS['table']
436 $GLOBALS['table'] = '';
437 if (PMA_isValid($_REQUEST['table'])) {
438 // can we strip tags from this?
439 // only \ and / is not allowed in table names for MySQL
440 $GLOBALS['table'] = $_REQUEST['table'];
441 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
445 * SQL query to be executed
446 * @global string $GLOBALS['sql_query']
448 $GLOBALS['sql_query'] = '';
449 if (PMA_isValid($_REQUEST['sql_query'])) {
450 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
454 * avoid problems in phpmyadmin.css.php in some cases
455 * @global string $js_frame
457 $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
459 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
460 //$_REQUEST['server']; // checked later in this file
461 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
465 /******************************************************************************/
466 /* parsing configuration file LABEL_parsing_config_file */
468 if (empty($_SESSION['PMA_Config'])) {
470 * We really need this one!
472 if (! function_exists('preg_replace')) {
473 PMA_fatalError('strCantLoad', 'pcre');
477 * @global PMA_Config $_SESSION['PMA_Config']
479 $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php');
481 } elseif (version_compare(phpversion(), '5', 'lt')) {
483 * @todo move all __wakeup() functionality into session.inc.php
485 $_SESSION['PMA_Config']->__wakeup();
488 if (!defined('PMA_MINIMUM_COMMON')) {
489 $_SESSION['PMA_Config']->checkPmaAbsoluteUri();
493 * BC - enable backward compatibility
494 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
496 $_SESSION['PMA_Config']->enableBc();
500 * check HTTPS connection
502 if ($_SESSION['PMA_Config']->get('ForceSSL')
503 && !$_SESSION['PMA_Config']->get('is_https')) {
504 PMA_sendHeaderLocation(
505 preg_replace('/^http/', 'https',
506 $_SESSION['PMA_Config']->get('PmaAbsoluteUri'))
507 . PMA_generate_common_url($_GET));
508 exit;
512 /******************************************************************************/
513 /* loading language file LABEL_loading_language_file */
516 * Added messages while developing:
518 if (file_exists('./lang/added_messages.php')) {
519 include './lang/added_messages.php';
523 * Includes the language file if it hasn't been included yet
525 require './libraries/language.lib.php';
529 * check for errors occurred while loading configuration
530 * this check is done here after loading language files to present errors in locale
532 if ($_SESSION['PMA_Config']->error_config_file) {
533 $GLOBALS['PMA_errors'][] = $strConfigFileError
534 . '<br /><br />'
535 . ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
536 '<a href="show_config_errors.php"'
537 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>'
539 '<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
540 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
542 if ($_SESSION['PMA_Config']->error_config_default_file) {
543 $GLOBALS['PMA_errors'][] = sprintf($strConfigDefaultFileError,
544 $_SESSION['PMA_Config']->default_source);
546 if ($_SESSION['PMA_Config']->error_pma_uri) {
547 $GLOBALS['PMA_errors'][] = sprintf($strPmaUriError);
551 * current server
552 * @global integer $GLOBALS['server']
554 $GLOBALS['server'] = 0;
557 * Servers array fixups.
558 * $default_server comes from PMA_Config::enableBc()
559 * @todo merge into PMA_Config
561 // Do we have some server?
562 if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
563 // No server => create one with defaults
564 $cfg['Servers'] = array(1 => $default_server);
565 } else {
566 // We have server(s) => apply default configuration
567 $new_servers = array();
569 foreach ($cfg['Servers'] as $server_index => $each_server) {
571 // Detect wrong configuration
572 if (!is_int($server_index) || $server_index < 1) {
573 $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerIndex, $server_index);
576 $each_server = array_merge($default_server, $each_server);
578 // Don't use servers with no hostname
579 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
580 $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerHostname, $server_index);
583 // Final solution to bug #582890
584 // If we are using a socket connection
585 // and there is nothing in the verbose server name
586 // or the host field, then generate a name for the server
587 // in the form of "Server 2", localized of course!
588 if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
589 $each_server['verbose'] = $GLOBALS['strServer'] . $server_index;
592 $new_servers[$server_index] = $each_server;
594 $cfg['Servers'] = $new_servers;
595 unset($new_servers, $server_index, $each_server);
598 // Cleanup
599 unset($default_server);
602 /******************************************************************************/
603 /* setup themes LABEL_theme_setup */
606 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
608 if (! isset($_SESSION['PMA_Theme_Manager'])) {
609 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
610 } else {
612 * @todo move all __wakeup() functionality into session.inc.php
614 $_SESSION['PMA_Theme_Manager']->checkConfig();
617 // for the theme per server feature
618 if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
619 $GLOBALS['server'] = $_REQUEST['server'];
620 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
621 if (empty($tmp)) {
622 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
624 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
625 unset($tmp);
628 * @todo move into PMA_Theme_Manager::__wakeup()
630 if (isset($_REQUEST['set_theme'])) {
631 // if user selected a theme
632 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
636 * the theme object
637 * @global PMA_Theme $_SESSION['PMA_Theme']
639 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
641 // BC
643 * the active theme
644 * @global string $GLOBALS['theme']
646 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
648 * the theme path
649 * @global string $GLOBALS['pmaThemePath']
651 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
653 * the theme image path
654 * @global string $GLOBALS['pmaThemeImage']
656 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
659 * load layout file if exists
661 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
662 include $_SESSION['PMA_Theme']->getLayoutFile();
664 * @todo remove if all themes are update use Navi instead of Left as frame name
666 if (! isset($GLOBALS['cfg']['NaviWidth'])
667 && isset($GLOBALS['cfg']['LeftWidth'])) {
668 $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
672 if (! defined('PMA_MINIMUM_COMMON')) {
674 * Character set conversion.
676 require_once './libraries/charset_conversion.lib.php';
679 * String handling
681 require_once './libraries/string.lib.php';
684 * Lookup server by name
685 * by Arnold - Helder Hosting
686 * (see FAQ 4.8)
688 if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
689 && ! is_numeric($_REQUEST['server'])) {
690 foreach ($cfg['Servers'] as $i => $server) {
691 if ($server['host'] == $_REQUEST['server']) {
692 $_REQUEST['server'] = $i;
693 break;
696 if (is_string($_REQUEST['server'])) {
697 unset($_REQUEST['server']);
699 unset($i);
703 * If no server is selected, make sure that $cfg['Server'] is empty (so
704 * that nothing will work), and skip server authentication.
705 * We do NOT exit here, but continue on without logging into any server.
706 * This way, the welcome page will still come up (with no server info) and
707 * present a choice of servers in the case that there are multiple servers
708 * and '$cfg['ServerDefault'] = 0' is set.
711 if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
712 $GLOBALS['server'] = $_REQUEST['server'];
713 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
714 } else {
715 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
716 $GLOBALS['server'] = $cfg['ServerDefault'];
717 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
718 } else {
719 $GLOBALS['server'] = 0;
720 $cfg['Server'] = array();
723 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
725 if (! empty($cfg['Server'])) {
728 * Loads the proper database interface for this server
730 require_once './libraries/database_interface.lib.php';
732 // Gets the authentication library that fits the $cfg['Server'] settings
733 // and run authentication
735 // (for a quick check of path disclosure in auth/cookies:)
736 $coming_from_common = true;
738 // to allow HTTP or http
739 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
740 if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
741 PMA_fatalError($strInvalidAuthMethod . ' ' . $cfg['Server']['auth_type']);
744 * the required auth type plugin
746 require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
748 if (!PMA_auth_check()) {
749 PMA_auth();
750 } else {
751 PMA_auth_set_user();
754 // Check IP-based Allow/Deny rules as soon as possible to reject the
755 // user
756 // Based on mod_access in Apache:
757 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
758 // Look at: "static int check_dir_access(request_rec *r)"
759 // Robbat2 - May 10, 2002
760 if (isset($cfg['Server']['AllowDeny'])
761 && isset($cfg['Server']['AllowDeny']['order'])) {
764 * ip based access library
766 require_once './libraries/ip_allow_deny.lib.php';
768 $allowDeny_forbidden = false; // default
769 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
770 $allowDeny_forbidden = true;
771 if (PMA_allowDeny('allow')) {
772 $allowDeny_forbidden = false;
774 if (PMA_allowDeny('deny')) {
775 $allowDeny_forbidden = true;
777 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
778 if (PMA_allowDeny('deny')) {
779 $allowDeny_forbidden = true;
781 if (PMA_allowDeny('allow')) {
782 $allowDeny_forbidden = false;
784 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
785 if (PMA_allowDeny('allow')
786 && !PMA_allowDeny('deny')) {
787 $allowDeny_forbidden = false;
788 } else {
789 $allowDeny_forbidden = true;
791 } // end if ... elseif ... elseif
793 // Ejects the user if banished
794 if ($allowDeny_forbidden) {
795 PMA_auth_fails();
797 unset($allowDeny_forbidden); //Clean up after you!
798 } // end if
800 // is root allowed?
801 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
802 $allowDeny_forbidden = true;
803 PMA_auth_fails();
804 unset($allowDeny_forbidden); //Clean up after you!
807 $bkp_track_err = @ini_set('track_errors', 1);
809 // Try to connect MySQL with the control user profile (will be used to
810 // get the privileges list for the current user but the true user link
811 // must be open after this one so it would be default one for all the
812 // scripts)
813 $controllink = false;
814 if ($cfg['Server']['controluser'] != '') {
815 $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
816 $cfg['Server']['controlpass'], true);
818 if (! $controllink) {
819 $controllink = PMA_DBI_connect($cfg['Server']['user'],
820 $cfg['Server']['password'], true);
821 } // end if ... else
823 // Pass #1 of DB-Config to read in master level DB-Config will go here
824 // Robbat2 - May 11, 2002
826 // Connects to the server (validates user's login)
827 $userlink = PMA_DBI_connect($cfg['Server']['user'],
828 $cfg['Server']['password'], false);
830 // Pass #2 of DB-Config to read in user level DB-Config will go here
831 // Robbat2 - May 11, 2002
833 @ini_set('track_errors', $bkp_track_err);
834 unset($bkp_track_err);
837 * If we auto switched to utf-8 we need to reread messages here
839 if (defined('PMA_LANG_RELOAD')) {
840 require './libraries/language.lib.php';
844 * SQL Parser code
846 require_once './libraries/sqlparser.lib.php';
849 * SQL Validator interface code
851 require_once './libraries/sqlvalidator.lib.php';
854 * the PMA_List_Database class
856 require_once './libraries/List_Database.class.php';
857 $PMA_List_Database = new PMA_List_Database($userlink, $controllink);
859 } // end server connecting
862 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
864 if (@function_exists('mb_convert_encoding')
865 && strpos(' ' . $lang, 'ja-')
866 && file_exists('./libraries/kanji-encoding.lib.php')) {
867 require_once './libraries/kanji-encoding.lib.php';
869 * enable multibyte string support
871 define('PMA_MULTIBYTE_ENCODING', 1);
872 } // end if
875 * save some settings in cookies
876 * @todo should be done in PMA_Config
878 PMA_setCookie('pma_lang', $GLOBALS['lang']);
879 PMA_setCookie('pma_charset', $GLOBALS['convcharset']);
880 PMA_setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
882 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
885 * check if profiling was requested and remember it
886 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
889 if (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 50037 && isset($_REQUEST['profiling'])) {
890 $_SESSION['profiling'] = true;
891 } elseif (isset($_REQUEST['profiling_form'])) {
892 // the checkbox was unchecked
893 unset($_SESSION['profiling']);
896 } // end if !defined('PMA_MINIMUM_COMMON')
898 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
900 * include subform target page
902 require $__redirect;
903 exit();