Installer Class missing array variable check
[openemr.git] / phpmyadmin / libraries / common.inc.php
bloba73a2deeebba3c50ceed4e21151d2288ff83ff50
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 * LABEL_variables_init
12 * - initialize some variables always needed
13 * LABEL_parsing_config_file
14 * - parsing of the configuration file
15 * LABEL_loading_language_file
16 * - loading language file
17 * LABEL_theme_setup
18 * - setting up themes
20 * - load of MySQL extension (if necessary)
21 * - loading of an authentication library
22 * - db connection
23 * - authentication work
25 * @version $Id$
28 /**
29 * For now, avoid warnings of E_STRICT mode
30 * (this must be done before function definitions)
32 if (defined('E_STRICT')) {
33 $old_error_reporting = error_reporting(0);
34 if ($old_error_reporting & E_STRICT) {
35 error_reporting($old_error_reporting ^ E_STRICT);
36 } else {
37 error_reporting($old_error_reporting);
39 unset($old_error_reporting);
42 // at this point PMA_PHP_INT_VERSION is not yet defined
43 if (version_compare(phpversion(), '6', 'lt')) {
44 /**
45 * Avoid object cloning errors
47 @ini_set('zend.ze1_compatibility_mode', false);
49 /**
50 * Avoid problems with magic_quotes_runtime
52 @ini_set('magic_quotes_runtime', false);
55 /**
56 * for verification in all procedural scripts under libraries
58 define('PHPMYADMIN', true);
60 /**
61 * core functions
63 require_once './libraries/core.lib.php';
65 /**
66 * Input sanitizing
68 require_once './libraries/sanitizing.lib.php';
70 /**
71 * the PMA_Theme class
73 require_once './libraries/Theme.class.php';
75 /**
76 * the PMA_Theme_Manager class
78 require_once './libraries/Theme_Manager.class.php';
80 /**
81 * the PMA_Config class
83 require_once './libraries/Config.class.php';
85 /**
86 * the PMA_Table class
88 require_once './libraries/Table.class.php';
90 if (!defined('PMA_MINIMUM_COMMON')) {
91 /**
92 * common functions
94 require_once './libraries/common.lib.php';
96 /**
97 * Java script escaping.
99 require_once './libraries/js_escape.lib.php';
102 * Include URL/hidden inputs generating.
104 require_once './libraries/url_generating.lib.php';
107 /******************************************************************************/
108 /* start procedural code label_start_procedural */
111 * protect against older PHP versions' bug about GLOBALS overwrite
112 * (no need to localize this message :))
113 * but what if script.php?GLOBALS[admin]=1&GLOBALS[_REQUEST]=1 ???
115 if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])
116 || isset($_SERVER['GLOBALS']) || isset($_COOKIE['GLOBALS'])
117 || isset($_ENV['GLOBALS'])) {
118 die('GLOBALS overwrite attempt');
122 * protect against possible exploits - there is no need to have so much variables
124 if (count($_REQUEST) > 1000) {
125 die('possible exploit');
129 * Check for numeric keys
130 * (if register_globals is on, numeric key can be found in $GLOBALS)
132 foreach ($GLOBALS as $key => $dummy) {
133 if (is_numeric($key)) {
134 die('numeric key detected');
137 unset($dummy);
140 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
141 * and provide a clean PHP_SELF here
143 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
144 $_PATH_INFO = PMA_getenv('PATH_INFO');
145 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
146 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
147 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
148 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
151 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
155 * just to be sure there was no import (registering) before here
156 * we empty the global space (but avoid unsetting $variables_list
157 * and $key in the foreach(), we still need them!)
159 $variables_whitelist = array (
160 'GLOBALS',
161 '_SERVER',
162 '_GET',
163 '_POST',
164 '_REQUEST',
165 '_FILES',
166 '_ENV',
167 '_COOKIE',
168 '_SESSION',
169 'PMA_PHP_SELF',
170 'variables_whitelist',
171 'key'
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 * <input type="hidden" name="subform[action1][id]" value="1" />
191 * ... other subform data ...
192 * <input type="submit" name="usesubform[action1]" value="do action1" />
193 * ... other subforms ...
194 * <input type="hidden" name="subform[actionX][id]" value="X" />
195 * ... other subform data ...
196 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
197 * ... main form elments ...
198 * <input 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);
223 } else {
224 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
225 // because another application for the same domain could have set
226 // a cookie (with a compatible path) that overrides a variable
227 // we expect from GET or POST.
228 // We'll refer to cookies explicitly with the $_COOKIE syntax.
229 $_REQUEST = array_merge($_GET, $_POST);
231 // end check if a subform is submitted
233 // remove quotes added by php
234 // (get_magic_quotes_gpc() is deprecated in PHP 5.3, but compare with 5.2.99
235 // to be able to test with 5.3.0-dev)
236 if (function_exists('get_magic_quotes_gpc') && -1 == version_compare(PHP_VERSION, '5.2.99') && get_magic_quotes_gpc()) {
237 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
238 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
239 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
240 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
244 * clean cookies on new install or upgrade
245 * when changing something with increment the cookie version
248 $pma_cookie_version = 4;
249 if (isset($_COOKIE)
250 && (! isset($_COOKIE['pmaCookieVer'])
251 || $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
252 // delete all cookies
253 foreach($_COOKIE as $cookie_name => $tmp) {
254 PMA_removeCookie($cookie_name);
256 $_COOKIE = array();
257 PMA_setCookie('pmaCookieVer', $pma_cookie_version);
261 * include deprecated grab_globals only if required
263 if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
264 require './libraries/grab_globals.lib.php';
268 * include session handling after the globals, to prevent overwriting
270 require_once './libraries/session.inc.php';
273 * init some variables LABEL_variables_init
277 * holds errors
278 * @global array $GLOBALS['PMA_errors']
280 $GLOBALS['PMA_errors'] = array();
283 * holds parameters to be passed to next page
284 * @global array $GLOBALS['url_params']
286 $GLOBALS['url_params'] = array();
289 * the whitelist for $GLOBALS['goto']
290 * @global array $goto_whitelist
292 $goto_whitelist = array(
293 //'browse_foreigners.php',
294 //'calendar.php',
295 //'changelog.php',
296 //'chk_rel.php',
297 'db_create.php',
298 'db_datadict.php',
299 'db_sql.php',
300 'db_export.php',
301 'db_importdocsql.php',
302 'db_qbe.php',
303 'db_structure.php',
304 'db_import.php',
305 'db_operations.php',
306 'db_printview.php',
307 'db_search.php',
308 //'Documentation.html',
309 //'error.php',
310 'export.php',
311 'import.php',
312 //'index.php',
313 //'navigation.php',
314 //'license.php',
315 'main.php',
316 'pdf_pages.php',
317 'pdf_schema.php',
318 //'phpinfo.php',
319 'querywindow.php',
320 //'readme.php',
321 'server_binlog.php',
322 'server_collations.php',
323 'server_databases.php',
324 'server_engines.php',
325 'server_export.php',
326 'server_import.php',
327 'server_privileges.php',
328 'server_processlist.php',
329 'server_sql.php',
330 'server_status.php',
331 'server_variables.php',
332 'sql.php',
333 'tbl_addfield.php',
334 'tbl_alter.php',
335 'tbl_change.php',
336 'tbl_create.php',
337 'tbl_import.php',
338 'tbl_indexes.php',
339 'tbl_move_copy.php',
340 'tbl_printview.php',
341 'tbl_sql.php',
342 'tbl_export.php',
343 'tbl_operations.php',
344 'tbl_structure.php',
345 'tbl_relation.php',
346 'tbl_replace.php',
347 'tbl_row_action.php',
348 'tbl_select.php',
349 //'themes.php',
350 'transformation_overview.php',
351 'transformation_wrapper.php',
352 'translators.html',
353 'user_password.php',
357 * check $__redirect against whitelist
359 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
360 $__redirect = null;
364 * holds page that should be displayed
365 * @global string $GLOBALS['goto']
367 $GLOBALS['goto'] = '';
368 // Security fix: disallow accessing serious server files via "?goto="
369 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
370 $GLOBALS['goto'] = $_REQUEST['goto'];
371 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
372 } else {
373 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
377 * returning page
378 * @global string $GLOBALS['back']
380 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
381 $GLOBALS['back'] = $_REQUEST['back'];
382 } else {
383 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
387 * Check whether user supplied token is valid, if not remove any possibly
388 * dangerous stuff from request.
390 * remember that some objects in the session with session_start and __wakeup()
391 * could access this variables before we reach this point
392 * f.e. PMA_Config: fontsize
394 * @todo variables should be handled by their respective owners (objects)
395 * f.e. lang, server, convcharset, collation_connection in PMA_Config
397 if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
399 * List of parameters which are allowed from unsafe source
401 $allow_list = array(
402 /* needed for direct access, see FAQ 1.34
403 * also, server needed for cookie login screen (multi-server)
405 'server', 'db', 'table', 'target',
406 /* to change the language on login screen or main page */
407 'lang',
408 /* Session ID */
409 'phpMyAdmin',
410 /* Cookie preferences */
411 'pma_lang', 'pma_charset', 'pma_collation_connection',
412 /* Possible login form */
413 'pma_servername', 'pma_username', 'pma_password',
416 * Require cleanup functions
418 require_once './libraries/cleanup.lib.php';
420 * Do actual cleanup
422 PMA_remove_request_vars($allow_list);
428 * @global string $convcharset
429 * @see select_lang.lib.php
431 if (isset($_REQUEST['convcharset'])) {
432 $convcharset = strip_tags($_REQUEST['convcharset']);
436 * current selected database
437 * @global string $GLOBALS['db']
439 $GLOBALS['db'] = '';
440 if (PMA_isValid($_REQUEST['db'])) {
441 // can we strip tags from this?
442 // only \ and / is not allowed in db names for MySQL
443 $GLOBALS['db'] = $_REQUEST['db'];
444 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
448 * current selected table
449 * @global string $GLOBALS['table']
451 $GLOBALS['table'] = '';
452 if (PMA_isValid($_REQUEST['table'])) {
453 // can we strip tags from this?
454 // only \ and / is not allowed in table names for MySQL
455 $GLOBALS['table'] = $_REQUEST['table'];
456 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
460 * SQL query to be executed
461 * @global string $GLOBALS['sql_query']
463 $GLOBALS['sql_query'] = '';
464 if (PMA_isValid($_REQUEST['sql_query'])) {
465 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
469 * avoid problems in phpmyadmin.css.php in some cases
470 * @global string $js_frame
472 $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
474 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
475 //$_REQUEST['server']; // checked later in this file
476 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
480 /******************************************************************************/
481 /* parsing configuration file LABEL_parsing_config_file */
484 * We really need this one!
486 if (! function_exists('preg_replace')) {
487 PMA_fatalError('strCantLoad', 'pcre');
491 * @global PMA_Config $_SESSION['PMA_Config']
492 * force reading of config file, because we removed sensitive values
493 * in the previous iteration
495 $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php');
497 if (!defined('PMA_MINIMUM_COMMON')) {
498 $_SESSION['PMA_Config']->checkPmaAbsoluteUri();
502 * BC - enable backward compatibility
503 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
505 $_SESSION['PMA_Config']->enableBc();
509 * check HTTPS connection
511 if ($_SESSION['PMA_Config']->get('ForceSSL')
512 && !$_SESSION['PMA_Config']->get('is_https')) {
513 PMA_sendHeaderLocation(
514 preg_replace('/^http/', 'https',
515 $_SESSION['PMA_Config']->get('PmaAbsoluteUri'))
516 . PMA_generate_common_url($_GET));
517 exit;
521 /******************************************************************************/
522 /* loading language file LABEL_loading_language_file */
525 * Added messages while developing:
527 if (file_exists('./lang/added_messages.php')) {
528 include './lang/added_messages.php';
532 * Includes the language file if it hasn't been included yet
534 require './libraries/language.lib.php';
538 * check for errors occurred while loading configuration
539 * this check is done here after loading language files to present errors in locale
541 if ($_SESSION['PMA_Config']->error_config_file) {
542 $GLOBALS['PMA_errors'][] = $strConfigFileError
543 . '<br /><br />'
544 . ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
545 '<a href="show_config_errors.php"'
546 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>'
548 '<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
549 .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
551 if ($_SESSION['PMA_Config']->error_config_default_file) {
552 $GLOBALS['PMA_errors'][] = sprintf($strConfigDefaultFileError,
553 $_SESSION['PMA_Config']->default_source);
555 if ($_SESSION['PMA_Config']->error_pma_uri) {
556 $GLOBALS['PMA_errors'][] = sprintf($strPmaUriError);
560 * current server
561 * @global integer $GLOBALS['server']
563 $GLOBALS['server'] = 0;
566 * Servers array fixups.
567 * $default_server comes from PMA_Config::enableBc()
568 * @todo merge into PMA_Config
570 // Do we have some server?
571 if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
572 // No server => create one with defaults
573 $cfg['Servers'] = array(1 => $default_server);
574 } else {
575 // We have server(s) => apply default configuration
576 $new_servers = array();
578 foreach ($cfg['Servers'] as $server_index => $each_server) {
580 // Detect wrong configuration
581 if (!is_int($server_index) || $server_index < 1) {
582 $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerIndex, $server_index);
585 $each_server = array_merge($default_server, $each_server);
587 // Don't use servers with no hostname
588 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
589 $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerHostname, $server_index);
592 // Final solution to bug #582890
593 // If we are using a socket connection
594 // and there is nothing in the verbose server name
595 // or the host field, then generate a name for the server
596 // in the form of "Server 2", localized of course!
597 if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
598 $each_server['verbose'] = $GLOBALS['strServer'] . $server_index;
601 $new_servers[$server_index] = $each_server;
603 $cfg['Servers'] = $new_servers;
604 unset($new_servers, $server_index, $each_server);
607 // Cleanup
608 unset($default_server);
611 /******************************************************************************/
612 /* setup themes LABEL_theme_setup */
615 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
617 if (! isset($_SESSION['PMA_Theme_Manager'])) {
618 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
619 } else {
621 * @todo move all __wakeup() functionality into session.inc.php
623 $_SESSION['PMA_Theme_Manager']->checkConfig();
626 // for the theme per server feature
627 if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
628 $GLOBALS['server'] = $_REQUEST['server'];
629 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
630 if (empty($tmp)) {
631 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
633 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
634 unset($tmp);
637 * @todo move into PMA_Theme_Manager::__wakeup()
639 if (isset($_REQUEST['set_theme'])) {
640 // if user selected a theme
641 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
645 * the theme object
646 * @global PMA_Theme $_SESSION['PMA_Theme']
648 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
650 // BC
652 * the active theme
653 * @global string $GLOBALS['theme']
655 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
657 * the theme path
658 * @global string $GLOBALS['pmaThemePath']
660 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
662 * the theme image path
663 * @global string $GLOBALS['pmaThemeImage']
665 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
668 * load layout file if exists
670 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
671 include $_SESSION['PMA_Theme']->getLayoutFile();
673 * @todo remove if all themes are update use Navi instead of Left as frame name
675 if (! isset($GLOBALS['cfg']['NaviWidth'])
676 && isset($GLOBALS['cfg']['LeftWidth'])) {
677 $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
681 if (! defined('PMA_MINIMUM_COMMON')) {
683 * Character set conversion.
685 require_once './libraries/charset_conversion.lib.php';
688 * String handling
690 require_once './libraries/string.lib.php';
693 * Lookup server by name
694 * by Arnold - Helder Hosting
695 * (see FAQ 4.8)
697 if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
698 && ! is_numeric($_REQUEST['server'])) {
699 foreach ($cfg['Servers'] as $i => $server) {
700 if ($server['host'] == $_REQUEST['server']) {
701 $_REQUEST['server'] = $i;
702 break;
705 if (is_string($_REQUEST['server'])) {
706 unset($_REQUEST['server']);
708 unset($i);
712 * If no server is selected, make sure that $cfg['Server'] is empty (so
713 * that nothing will work), and skip server authentication.
714 * We do NOT exit here, but continue on without logging into any server.
715 * This way, the welcome page will still come up (with no server info) and
716 * present a choice of servers in the case that there are multiple servers
717 * and '$cfg['ServerDefault'] = 0' is set.
720 if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
721 $GLOBALS['server'] = $_REQUEST['server'];
722 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
723 } else {
724 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
725 $GLOBALS['server'] = $cfg['ServerDefault'];
726 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
727 } else {
728 $GLOBALS['server'] = 0;
729 $cfg['Server'] = array();
732 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
734 if (! empty($cfg['Server'])) {
737 * Loads the proper database interface for this server
739 require_once './libraries/database_interface.lib.php';
741 // Gets the authentication library that fits the $cfg['Server'] settings
742 // and run authentication
744 // to allow HTTP or http
745 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
746 if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
747 PMA_fatalError($strInvalidAuthMethod . ' ' . $cfg['Server']['auth_type']);
750 * the required auth type plugin
752 require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
754 if (!PMA_auth_check()) {
755 PMA_auth();
756 } else {
757 PMA_auth_set_user();
760 // Check IP-based Allow/Deny rules as soon as possible to reject the
761 // user
762 // Based on mod_access in Apache:
763 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
764 // Look at: "static int check_dir_access(request_rec *r)"
765 // Robbat2 - May 10, 2002
766 if (isset($cfg['Server']['AllowDeny'])
767 && isset($cfg['Server']['AllowDeny']['order'])) {
770 * ip based access library
772 require_once './libraries/ip_allow_deny.lib.php';
774 $allowDeny_forbidden = false; // default
775 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
776 $allowDeny_forbidden = true;
777 if (PMA_allowDeny('allow')) {
778 $allowDeny_forbidden = false;
780 if (PMA_allowDeny('deny')) {
781 $allowDeny_forbidden = true;
783 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
784 if (PMA_allowDeny('deny')) {
785 $allowDeny_forbidden = true;
787 if (PMA_allowDeny('allow')) {
788 $allowDeny_forbidden = false;
790 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
791 if (PMA_allowDeny('allow')
792 && !PMA_allowDeny('deny')) {
793 $allowDeny_forbidden = false;
794 } else {
795 $allowDeny_forbidden = true;
797 } // end if ... elseif ... elseif
799 // Ejects the user if banished
800 if ($allowDeny_forbidden) {
801 PMA_auth_fails();
803 unset($allowDeny_forbidden); //Clean up after you!
804 } // end if
806 // is root allowed?
807 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
808 $allowDeny_forbidden = true;
809 PMA_auth_fails();
810 unset($allowDeny_forbidden); //Clean up after you!
813 $bkp_track_err = @ini_set('track_errors', 1);
815 // Try to connect MySQL with the control user profile (will be used to
816 // get the privileges list for the current user but the true user link
817 // must be open after this one so it would be default one for all the
818 // scripts)
819 $controllink = false;
820 if ($cfg['Server']['controluser'] != '') {
821 $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
822 $cfg['Server']['controlpass'], true);
824 if (! $controllink) {
825 $controllink = PMA_DBI_connect($cfg['Server']['user'],
826 $cfg['Server']['password'], true);
827 } // end if ... else
829 // Pass #1 of DB-Config to read in master level DB-Config will go here
830 // Robbat2 - May 11, 2002
832 // Connects to the server (validates user's login)
833 $userlink = PMA_DBI_connect($cfg['Server']['user'],
834 $cfg['Server']['password'], false);
836 // Pass #2 of DB-Config to read in user level DB-Config will go here
837 // Robbat2 - May 11, 2002
839 @ini_set('track_errors', $bkp_track_err);
840 unset($bkp_track_err);
843 * If we auto switched to utf-8 we need to reread messages here
845 if (defined('PMA_LANG_RELOAD')) {
846 require './libraries/language.lib.php';
850 * SQL Parser code
852 require_once './libraries/sqlparser.lib.php';
855 * SQL Validator interface code
857 require_once './libraries/sqlvalidator.lib.php';
860 * the PMA_List_Database class
862 require_once './libraries/List_Database.class.php';
863 $PMA_List_Database = new PMA_List_Database($userlink, $controllink);
866 * some resetting has to be done when switching servers
868 if (isset($_SESSION['userconf']['previous_server']) && $_SESSION['userconf']['previous_server'] != $GLOBALS['server']) {
869 unset($_SESSION['userconf']['navi_limit_offset']);
871 $_SESSION['userconf']['previous_server'] = $GLOBALS['server'];
873 } // end server connecting
876 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
878 if (@function_exists('mb_convert_encoding')
879 && strpos(' ' . $lang, 'ja-')
880 && file_exists('./libraries/kanji-encoding.lib.php')) {
881 require_once './libraries/kanji-encoding.lib.php';
883 * enable multibyte string support
885 define('PMA_MULTIBYTE_ENCODING', 1);
886 } // end if
889 * save some settings in cookies
890 * @todo should be done in PMA_Config
892 PMA_setCookie('pma_lang', $GLOBALS['lang']);
893 PMA_setCookie('pma_charset', $GLOBALS['convcharset']);
894 PMA_setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
896 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
899 * check if profiling was requested and remember it
900 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
903 if (PMA_profilingSupported() && isset($_REQUEST['profiling'])) {
904 $_SESSION['profiling'] = true;
905 } elseif (isset($_REQUEST['profiling_form'])) {
906 // the checkbox was unchecked
907 unset($_SESSION['profiling']);
910 } // end if !defined('PMA_MINIMUM_COMMON')
912 // remove sensitive values from session
913 $_SESSION['PMA_Config']->set('blowfish_secret', '');
914 $_SESSION['PMA_Config']->set('Servers', '');
915 $_SESSION['PMA_Config']->set('default_server', '');
917 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
919 * include subform target page
921 require $__redirect;
922 exit();