home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / common.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  26.8 KB  |  919 lines

  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
  6.  *
  7.  * Among other things, it contains the advanced authentication work.
  8.  *
  9.  * Order of sections for common.inc.php:
  10.  *
  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
  19.  *
  20.  * - load of MySQL extension (if necessary)
  21.  * - loading of an authentication library
  22.  * - db connection
  23.  * - authentication work
  24.  *
  25.  * @version $Id: common.inc.php 11326 2008-06-17 21:32:48Z lem9 $
  26.  */
  27.  
  28. /**
  29.  * For now, avoid warnings of E_STRICT mode
  30.  * (this must be done before function definitions)
  31.  */
  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);
  38.     }
  39.     unset($old_error_reporting);
  40. }
  41.  
  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
  46.      */
  47.     @ini_set('zend.ze1_compatibility_mode', false);
  48.  
  49.     /**
  50.      * Avoid problems with magic_quotes_runtime
  51.      */
  52.     @ini_set('magic_quotes_runtime', false);
  53. }
  54.  
  55. /**
  56.  * for verification in all procedural scripts under libraries
  57.  */
  58. define('PHPMYADMIN', true);
  59.  
  60. /**
  61.  * core functions
  62.  */
  63. require_once './libraries/core.lib.php';
  64.  
  65. /**
  66.  * Input sanitizing
  67.  */
  68. require_once './libraries/sanitizing.lib.php';
  69.  
  70. /**
  71.  * the PMA_Theme class
  72.  */
  73. require_once './libraries/Theme.class.php';
  74.  
  75. /**
  76.  * the PMA_Theme_Manager class
  77.  */
  78. require_once './libraries/Theme_Manager.class.php';
  79.  
  80. /**
  81.  * the PMA_Config class
  82.  */
  83. require_once './libraries/Config.class.php';
  84.  
  85. /**
  86.  * the PMA_Table class
  87.  */
  88. require_once './libraries/Table.class.php';
  89.  
  90. if (!defined('PMA_MINIMUM_COMMON')) {
  91.     /**
  92.      * common functions
  93.      */
  94.     require_once './libraries/common.lib.php';
  95.  
  96.     /**
  97.      * Java script escaping.
  98.      */
  99.     require_once './libraries/js_escape.lib.php';
  100.  
  101.     /**
  102.      * Include URL/hidden inputs generating.
  103.      */
  104.     require_once './libraries/url_generating.lib.php';
  105. }
  106.  
  107. /******************************************************************************/
  108. /* start procedural code                       label_start_procedural         */
  109.  
  110. /**
  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 ???
  114.  */
  115. if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])
  116.   || isset($_SERVER['GLOBALS']) || isset($_COOKIE['GLOBALS'])
  117.   || isset($_ENV['GLOBALS'])) {
  118.     die('GLOBALS overwrite attempt');
  119. }
  120.  
  121. /**
  122.  * protect against possible exploits - there is no need to have so much variables
  123.  */
  124. if (count($_REQUEST) > 1000) {
  125.     die('possible exploit');
  126. }
  127.  
  128. /**
  129.  * Check for numeric keys
  130.  * (if register_globals is on, numeric key can be found in $GLOBALS)
  131.  */
  132. foreach ($GLOBALS as $key => $dummy) {
  133.     if (is_numeric($key)) {
  134.         die('numeric key detected');
  135.     }
  136. }
  137. unset($dummy);
  138.  
  139. /**
  140.  * PATH_INFO could be compromised if set, so remove it from PHP_SELF
  141.  * and provide a clean PHP_SELF here
  142.  */
  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);
  149.     }
  150. }
  151. $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
  152.  
  153.  
  154. /**
  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!)
  158.  */
  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'
  172. );
  173.  
  174. foreach (get_defined_vars() as $key => $value) {
  175.     if (! in_array($key, $variables_whitelist)) {
  176.         unset($$key);
  177.     }
  178. }
  179. unset($key, $value, $variables_whitelist);
  180.  
  181.  
  182. /**
  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
  186.  *
  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
  201.  *
  202.  * so we now check if a subform is submitted
  203.  */
  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;
  212.     /**
  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
  216.      */
  217.     if (isset($_POST['redirect'])
  218.       && $_POST['redirect'] != basename($PMA_PHP_SELF)) {
  219.         $__redirect = $_POST['redirect'];
  220.         unset($_POST['redirect']);
  221.     }
  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);
  230. }
  231. // end check if a subform is submitted
  232.  
  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);
  241. }
  242.  
  243. /**
  244.  * clean cookies on new install or upgrade
  245.  * when changing something with increment the cookie version
  246.  */
  247. $pma_cookie_version = 4;
  248. if (isset($_COOKIE)
  249.  && (! isset($_COOKIE['pmaCookieVer'])
  250.   || $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
  251.     // delete all cookies
  252.     foreach($_COOKIE as $cookie_name => $tmp) {
  253.         PMA_removeCookie($cookie_name);
  254.     }
  255.     $_COOKIE = array();
  256.     PMA_setCookie('pmaCookieVer', $pma_cookie_version);
  257. }
  258.  
  259. /**
  260.  * include deprecated grab_globals only if required
  261.  */
  262. if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
  263.     require './libraries/grab_globals.lib.php';
  264. }
  265.  
  266. /**
  267.  * include session handling after the globals, to prevent overwriting
  268.  */
  269. require_once './libraries/session.inc.php';
  270.  
  271. /**
  272.  * init some variables LABEL_variables_init
  273.  */
  274.  
  275. /**
  276.  * holds errors
  277.  * @global array $GLOBALS['PMA_errors']
  278.  */
  279. $GLOBALS['PMA_errors'] = array();
  280.  
  281. /**
  282.  * holds parameters to be passed to next page
  283.  * @global array $GLOBALS['url_params']
  284.  */
  285. $GLOBALS['url_params'] = array();
  286.  
  287. /**
  288.  * the whitelist for $GLOBALS['goto']
  289.  * @global array $goto_whitelist
  290.  */
  291. $goto_whitelist = array(
  292.     //'browse_foreigners.php',
  293.     //'calendar.php',
  294.     //'changelog.php',
  295.     //'chk_rel.php',
  296.     'db_create.php',
  297.     'db_datadict.php',
  298.     'db_sql.php',
  299.     'db_export.php',
  300.     'db_importdocsql.php',
  301.     'db_qbe.php',
  302.     'db_structure.php',
  303.     'db_import.php',
  304.     'db_operations.php',
  305.     'db_printview.php',
  306.     'db_search.php',
  307.     //'Documentation.html',
  308.     //'error.php',
  309.     'export.php',
  310.     'import.php',
  311.     //'index.php',
  312.     //'navigation.php',
  313.     //'license.php',
  314.     'main.php',
  315.     'pdf_pages.php',
  316.     'pdf_schema.php',
  317.     //'phpinfo.php',
  318.     'querywindow.php',
  319.     //'readme.php',
  320.     'server_binlog.php',
  321.     'server_collations.php',
  322.     'server_databases.php',
  323.     'server_engines.php',
  324.     'server_export.php',
  325.     'server_import.php',
  326.     'server_privileges.php',
  327.     'server_processlist.php',
  328.     'server_sql.php',
  329.     'server_status.php',
  330.     'server_variables.php',
  331.     'sql.php',
  332.     'tbl_addfield.php',
  333.     'tbl_alter.php',
  334.     'tbl_change.php',
  335.     'tbl_create.php',
  336.     'tbl_import.php',
  337.     'tbl_indexes.php',
  338.     'tbl_move_copy.php',
  339.     'tbl_printview.php',
  340.     'tbl_sql.php',
  341.     'tbl_export.php',
  342.     'tbl_operations.php',
  343.     'tbl_structure.php',
  344.     'tbl_relation.php',
  345.     'tbl_replace.php',
  346.     'tbl_row_action.php',
  347.     'tbl_select.php',
  348.     //'themes.php',
  349.     'transformation_overview.php',
  350.     'transformation_wrapper.php',
  351.     'translators.html',
  352.     'user_password.php',
  353. );
  354.  
  355. /**
  356.  * check $__redirect against whitelist
  357.  */
  358. if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
  359.     $__redirect = null;
  360. }
  361.  
  362. /**
  363.  * holds page that should be displayed
  364.  * @global string $GLOBALS['goto']
  365.  */
  366. $GLOBALS['goto'] = '';
  367. // Security fix: disallow accessing serious server files via "?goto="
  368. if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
  369.     $GLOBALS['goto'] = $_REQUEST['goto'];
  370.     $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
  371. } else {
  372.     unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
  373. }
  374.  
  375. /**
  376.  * returning page
  377.  * @global string $GLOBALS['back']
  378.  */
  379. if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
  380.     $GLOBALS['back'] = $_REQUEST['back'];
  381. } else {
  382.     unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
  383. }
  384.  
  385. /**
  386.  * Check whether user supplied token is valid, if not remove any possibly
  387.  * dangerous stuff from request.
  388.  *
  389.  * remember that some objects in the session with session_start and __wakeup()
  390.  * could access this variables before we reach this point
  391.  * f.e. PMA_Config: fontsize
  392.  *
  393.  * @todo variables should be handled by their respective owners (objects)
  394.  * f.e. lang, server, convcharset, collation_connection in PMA_Config
  395.  */
  396. if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
  397.     /**
  398.      *  List of parameters which are allowed from unsafe source
  399.      */
  400.     $allow_list = array(
  401.         'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target',
  402.         /* Session ID */
  403.         'phpMyAdmin',
  404.         /* Cookie preferences */
  405.         'pma_lang', 'pma_charset', 'pma_collation_connection',
  406.         /* Possible login form */
  407.         'pma_servername', 'pma_username', 'pma_password',
  408.     );
  409.     /**
  410.      * Require cleanup functions
  411.      */
  412.     require_once './libraries/cleanup.lib.php';
  413.     /**
  414.      * Do actual cleanup
  415.      */
  416.     PMA_remove_request_vars($allow_list);
  417.  
  418. }
  419.  
  420.  
  421. /**
  422.  * @global string $convcharset
  423.  * @see select_lang.lib.php
  424.  */
  425. if (isset($_REQUEST['convcharset'])) {
  426.     $convcharset = strip_tags($_REQUEST['convcharset']);
  427. }
  428.  
  429. /**
  430.  * current selected database
  431.  * @global string $GLOBALS['db']
  432.  */
  433. $GLOBALS['db'] = '';
  434. if (PMA_isValid($_REQUEST['db'])) {
  435.     // can we strip tags from this?
  436.     // only \ and / is not allowed in db names for MySQL
  437.     $GLOBALS['db'] = $_REQUEST['db'];
  438.     $GLOBALS['url_params']['db'] = $GLOBALS['db'];
  439. }
  440.  
  441. /**
  442.  * current selected table
  443.  * @global string $GLOBALS['table']
  444.  */
  445. $GLOBALS['table'] = '';
  446. if (PMA_isValid($_REQUEST['table'])) {
  447.     // can we strip tags from this?
  448.     // only \ and / is not allowed in table names for MySQL
  449.     $GLOBALS['table'] = $_REQUEST['table'];
  450.     $GLOBALS['url_params']['table'] = $GLOBALS['table'];
  451. }
  452.  
  453. /**
  454.  * SQL query to be executed
  455.  * @global string $GLOBALS['sql_query']
  456.  */
  457. $GLOBALS['sql_query'] = '';
  458. if (PMA_isValid($_REQUEST['sql_query'])) {
  459.     $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
  460. }
  461.  
  462. /**
  463.  * avoid problems in phpmyadmin.css.php in some cases
  464.  * @global string $js_frame
  465.  */
  466. $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
  467.  
  468. //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
  469. //$_REQUEST['server']; // checked later in this file
  470. //$_REQUEST['lang'];   // checked by LABEL_loading_language_file
  471.  
  472.  
  473.  
  474. /******************************************************************************/
  475. /* parsing configuration file                         LABEL_parsing_config_file      */
  476.  
  477. /**
  478.  * We really need this one!
  479.  */
  480. if (! function_exists('preg_replace')) {
  481.     PMA_fatalError('strCantLoad', 'pcre');
  482. }
  483.  
  484. /**
  485.  * @global PMA_Config $_SESSION['PMA_Config']
  486.  * force reading of config file, because we removed sensitive values
  487.  * in the previous iteration
  488.  */
  489. $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php');
  490.  
  491. if (!defined('PMA_MINIMUM_COMMON')) {
  492.     $_SESSION['PMA_Config']->checkPmaAbsoluteUri();
  493. }
  494.  
  495. /**
  496.  * BC - enable backward compatibility
  497.  * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
  498.  */
  499. $_SESSION['PMA_Config']->enableBc();
  500.  
  501.  
  502. /**
  503.  * check HTTPS connection
  504.  */
  505. if ($_SESSION['PMA_Config']->get('ForceSSL')
  506.   && !$_SESSION['PMA_Config']->get('is_https')) {
  507.     PMA_sendHeaderLocation(
  508.         preg_replace('/^http/', 'https',
  509.             $_SESSION['PMA_Config']->get('PmaAbsoluteUri'))
  510.         . PMA_generate_common_url($_GET));
  511.     exit;
  512. }
  513.  
  514.  
  515. /******************************************************************************/
  516. /* loading language file                       LABEL_loading_language_file    */
  517.  
  518. /**
  519.  * Added messages while developing:
  520.  */
  521. if (file_exists('./lang/added_messages.php')) {
  522.     include './lang/added_messages.php';
  523. }
  524.  
  525. /**
  526.  * Includes the language file if it hasn't been included yet
  527.  */
  528. require './libraries/language.lib.php';
  529.  
  530.  
  531. /**
  532.  * check for errors occurred while loading configuration
  533.  * this check is done here after loading language files to present errors in locale
  534.  */
  535. if ($_SESSION['PMA_Config']->error_config_file) {
  536.     $GLOBALS['PMA_errors'][] = $strConfigFileError
  537.         . '<br /><br />'
  538.         . ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
  539.         '<a href="show_config_errors.php"'
  540.         .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>'
  541.         :
  542.         '<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
  543.         .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
  544. }
  545. if ($_SESSION['PMA_Config']->error_config_default_file) {
  546.     $GLOBALS['PMA_errors'][] = sprintf($strConfigDefaultFileError,
  547.         $_SESSION['PMA_Config']->default_source);
  548. }
  549. if ($_SESSION['PMA_Config']->error_pma_uri) {
  550.     $GLOBALS['PMA_errors'][] = sprintf($strPmaUriError);
  551. }
  552.  
  553. /**
  554.  * current server
  555.  * @global integer $GLOBALS['server']
  556.  */
  557. $GLOBALS['server'] = 0;
  558.  
  559. /**
  560.  * Servers array fixups.
  561.  * $default_server comes from PMA_Config::enableBc()
  562.  * @todo merge into PMA_Config
  563.  */
  564. // Do we have some server?
  565. if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
  566.     // No server => create one with defaults
  567.     $cfg['Servers'] = array(1 => $default_server);
  568. } else {
  569.     // We have server(s) => apply default configuration
  570.     $new_servers = array();
  571.  
  572.     foreach ($cfg['Servers'] as $server_index => $each_server) {
  573.  
  574.         // Detect wrong configuration
  575.         if (!is_int($server_index) || $server_index < 1) {
  576.             $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerIndex, $server_index);
  577.         }
  578.  
  579.         $each_server = array_merge($default_server, $each_server);
  580.  
  581.         // Don't use servers with no hostname
  582.         if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
  583.             $GLOBALS['PMA_errors'][] = sprintf($strInvalidServerHostname, $server_index);
  584.         }
  585.  
  586.         // Final solution to bug #582890
  587.         // If we are using a socket connection
  588.         // and there is nothing in the verbose server name
  589.         // or the host field, then generate a name for the server
  590.         // in the form of "Server 2", localized of course!
  591.         if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
  592.             $each_server['verbose'] = $GLOBALS['strServer'] . $server_index;
  593.         }
  594.  
  595.         $new_servers[$server_index] = $each_server;
  596.     }
  597.     $cfg['Servers'] = $new_servers;
  598.     unset($new_servers, $server_index, $each_server);
  599. }
  600.  
  601. // Cleanup
  602. unset($default_server);
  603.  
  604.  
  605. /******************************************************************************/
  606. /* setup themes                                          LABEL_theme_setup    */
  607.  
  608. /**
  609.  * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
  610.  */
  611. if (! isset($_SESSION['PMA_Theme_Manager'])) {
  612.     $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
  613. } else {
  614.     /**
  615.      * @todo move all __wakeup() functionality into session.inc.php
  616.      */
  617.     $_SESSION['PMA_Theme_Manager']->checkConfig();
  618. }
  619.  
  620. // for the theme per server feature
  621. if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
  622.     $GLOBALS['server'] = $_REQUEST['server'];
  623.     $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
  624.     if (empty($tmp)) {
  625.         $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
  626.     }
  627.     $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
  628.     unset($tmp);
  629. }
  630. /**
  631.  * @todo move into PMA_Theme_Manager::__wakeup()
  632.  */
  633. if (isset($_REQUEST['set_theme'])) {
  634.     // if user selected a theme
  635.     $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
  636. }
  637.  
  638. /**
  639.  * the theme object
  640.  * @global PMA_Theme $_SESSION['PMA_Theme']
  641.  */
  642. $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
  643.  
  644. // BC
  645. /**
  646.  * the active theme
  647.  * @global string $GLOBALS['theme']
  648.  */
  649. $GLOBALS['theme']           = $_SESSION['PMA_Theme']->getName();
  650. /**
  651.  * the theme path
  652.  * @global string $GLOBALS['pmaThemePath']
  653.  */
  654. $GLOBALS['pmaThemePath']    = $_SESSION['PMA_Theme']->getPath();
  655. /**
  656.  * the theme image path
  657.  * @global string $GLOBALS['pmaThemeImage']
  658.  */
  659. $GLOBALS['pmaThemeImage']   = $_SESSION['PMA_Theme']->getImgPath();
  660.  
  661. /**
  662.  * load layout file if exists
  663.  */
  664. if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
  665.     include $_SESSION['PMA_Theme']->getLayoutFile();
  666.     /**
  667.      * @todo remove if all themes are update use Navi instead of Left as frame name
  668.      */
  669.     if (! isset($GLOBALS['cfg']['NaviWidth'])
  670.      && isset($GLOBALS['cfg']['LeftWidth'])) {
  671.         $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
  672.     }
  673. }
  674.  
  675. if (! defined('PMA_MINIMUM_COMMON')) {
  676.     /**
  677.      * Character set conversion.
  678.      */
  679.     require_once './libraries/charset_conversion.lib.php';
  680.  
  681.     /**
  682.      * String handling
  683.      */
  684.     require_once './libraries/string.lib.php';
  685.  
  686.     /**
  687.      * Lookup server by name
  688.      * by Arnold - Helder Hosting
  689.      * (see FAQ 4.8)
  690.      */
  691.     if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
  692.      && ! is_numeric($_REQUEST['server'])) {
  693.         foreach ($cfg['Servers'] as $i => $server) {
  694.             if ($server['host'] == $_REQUEST['server']) {
  695.                 $_REQUEST['server'] = $i;
  696.                 break;
  697.             }
  698.         }
  699.         if (is_string($_REQUEST['server'])) {
  700.             unset($_REQUEST['server']);
  701.         }
  702.         unset($i);
  703.     }
  704.  
  705.     /**
  706.      * If no server is selected, make sure that $cfg['Server'] is empty (so
  707.      * that nothing will work), and skip server authentication.
  708.      * We do NOT exit here, but continue on without logging into any server.
  709.      * This way, the welcome page will still come up (with no server info) and
  710.      * present a choice of servers in the case that there are multiple servers
  711.      * and '$cfg['ServerDefault'] = 0' is set.
  712.      */
  713.  
  714.     if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
  715.         $GLOBALS['server'] = $_REQUEST['server'];
  716.         $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
  717.     } else {
  718.         if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
  719.             $GLOBALS['server'] = $cfg['ServerDefault'];
  720.             $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
  721.         } else {
  722.             $GLOBALS['server'] = 0;
  723.             $cfg['Server'] = array();
  724.         }
  725.     }
  726.     $GLOBALS['url_params']['server'] = $GLOBALS['server'];
  727.  
  728.     if (! empty($cfg['Server'])) {
  729.  
  730.         /**
  731.          * Loads the proper database interface for this server
  732.          */
  733.         require_once './libraries/database_interface.lib.php';
  734.  
  735.         // Gets the authentication library that fits the $cfg['Server'] settings
  736.         // and run authentication
  737.  
  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']);
  742.         }
  743.         /**
  744.          * the required auth type plugin
  745.          */
  746.         require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
  747.  
  748.         if (!PMA_auth_check()) {
  749.             PMA_auth();
  750.         } else {
  751.             PMA_auth_set_user();
  752.         }
  753.  
  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'])) {
  762.  
  763.             /**
  764.              * ip based access library
  765.              */
  766.             require_once './libraries/ip_allow_deny.lib.php';
  767.  
  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;
  773.                 }
  774.                 if (PMA_allowDeny('deny')) {
  775.                     $allowDeny_forbidden = true;
  776.                 }
  777.             } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
  778.                 if (PMA_allowDeny('deny')) {
  779.                     $allowDeny_forbidden = true;
  780.                 }
  781.                 if (PMA_allowDeny('allow')) {
  782.                     $allowDeny_forbidden = false;
  783.                 }
  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;
  790.                 }
  791.             } // end if ... elseif ... elseif
  792.  
  793.             // Ejects the user if banished
  794.             if ($allowDeny_forbidden) {
  795.                PMA_auth_fails();
  796.             }
  797.             unset($allowDeny_forbidden); //Clean up after you!
  798.         } // end if
  799.  
  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!
  805.         }
  806.  
  807.         $bkp_track_err = @ini_set('track_errors', 1);
  808.  
  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);
  817.         }
  818.         if (! $controllink) {
  819.             $controllink = PMA_DBI_connect($cfg['Server']['user'],
  820.                 $cfg['Server']['password'], true);
  821.         } // end if ... else
  822.  
  823.         // Pass #1 of DB-Config to read in master level DB-Config will go here
  824.         // Robbat2 - May 11, 2002
  825.  
  826.         // Connects to the server (validates user's login)
  827.         $userlink = PMA_DBI_connect($cfg['Server']['user'],
  828.             $cfg['Server']['password'], false);
  829.  
  830.         // Pass #2 of DB-Config to read in user level DB-Config will go here
  831.         // Robbat2 - May 11, 2002
  832.  
  833.         @ini_set('track_errors', $bkp_track_err);
  834.         unset($bkp_track_err);
  835.  
  836.         /**
  837.          * If we auto switched to utf-8 we need to reread messages here
  838.          */
  839.         if (defined('PMA_LANG_RELOAD')) {
  840.             require './libraries/language.lib.php';
  841.         }
  842.  
  843.         /**
  844.          * SQL Parser code
  845.          */
  846.         require_once './libraries/sqlparser.lib.php';
  847.  
  848.         /**
  849.          * SQL Validator interface code
  850.          */
  851.         require_once './libraries/sqlvalidator.lib.php';
  852.  
  853.         /**
  854.          * the PMA_List_Database class
  855.          */
  856.         require_once './libraries/List_Database.class.php';
  857.         $PMA_List_Database = new PMA_List_Database($userlink, $controllink);
  858.  
  859.         /**
  860.          * some resetting has to be done when switching servers
  861.          */
  862.         if (isset($_SESSION['userconf']['previous_server']) && $_SESSION['userconf']['previous_server'] != $GLOBALS['server']) {
  863.             unset($_SESSION['userconf']['navi_limit_offset']);
  864.         }
  865.         $_SESSION['userconf']['previous_server'] = $GLOBALS['server'];
  866.  
  867.     } // end server connecting
  868.  
  869.     /**
  870.      * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
  871.      */
  872.     if (@function_exists('mb_convert_encoding')
  873.         && strpos(' ' . $lang, 'ja-')
  874.         && file_exists('./libraries/kanji-encoding.lib.php')) {
  875.         require_once './libraries/kanji-encoding.lib.php';
  876.         /**
  877.          * enable multibyte string support
  878.          */
  879.         define('PMA_MULTIBYTE_ENCODING', 1);
  880.     } // end if
  881.  
  882.     /**
  883.      * save some settings in cookies
  884.      * @todo should be done in PMA_Config
  885.      */
  886.     PMA_setCookie('pma_lang', $GLOBALS['lang']);
  887.     PMA_setCookie('pma_charset', $GLOBALS['convcharset']);
  888.     PMA_setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
  889.  
  890.     $_SESSION['PMA_Theme_Manager']->setThemeCookie();
  891.  
  892.     /**
  893.      * check if profiling was requested and remember it
  894.      * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
  895.      */
  896.  
  897.     if (PMA_profilingSupported() && isset($_REQUEST['profiling'])) {
  898.         $_SESSION['profiling'] = true;
  899.     } elseif (isset($_REQUEST['profiling_form'])) {
  900.         // the checkbox was unchecked
  901.         unset($_SESSION['profiling']);
  902.     }
  903.  
  904. } // end if !defined('PMA_MINIMUM_COMMON')
  905.  
  906. // remove sensitive values from session
  907. $_SESSION['PMA_Config']->set('blowfish_secret', '');
  908. $_SESSION['PMA_Config']->set('Servers', '');
  909. $_SESSION['PMA_Config']->set('default_server', '');
  910.  
  911. if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
  912.     /**
  913.      * include subform target page
  914.      */
  915.     require $__redirect;
  916.     exit();
  917. }
  918. ?>
  919.