prefix for variable holding jQuery object; remove extra wrapping for the object
[phpmyadmin/gandalfml.git] / libraries / common.inc.php
blobe4ce8c8ced886684771a0bb42b0cb006c274faaa
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Misc stuff and REQUIRED by ALL the scripts.
5 * MUST be included by every script
7 * Among other things, it contains the advanced authentication work.
9 * Order of sections for common.inc.php:
11 * the authentication libraries must be before the connection to db
13 * ... so the required order is:
15 * LABEL_variables_init
16 * - initialize some variables always needed
17 * LABEL_parsing_config_file
18 * - parsing of the configuration file
19 * LABEL_loading_language_file
20 * - loading language file
21 * LABEL_setup_servers
22 * - check and setup configured servers
23 * LABEL_theme_setup
24 * - setting up themes
26 * - load of MySQL extension (if necessary)
27 * - loading of an authentication library
28 * - db connection
29 * - authentication work
31 * @package phpMyAdmin
34 /**
35 * Minimum PHP version; can't call PMA_fatalError() which uses a
36 * PHP 5 function, so cannot easily localize this message.
38 if (version_compare(PHP_VERSION, '5.2.0', 'lt')) {
39 die('PHP 5.2+ is required');
42 /**
43 * Backward compatibility for PHP 5.2
45 if (!defined('E_DEPRECATED')) {
46 define('E_DEPRECATED', 8192);
49 /**
50 * the error handler
52 require './libraries/Error_Handler.class.php';
54 /**
55 * initialize the error handler
57 $GLOBALS['error_handler'] = new PMA_Error_Handler();
58 $cfg['Error_Handler']['display'] = TRUE;
60 // at this point PMA_PHP_INT_VERSION is not yet defined
61 if (version_compare(phpversion(), '6', 'lt')) {
62 /**
63 * Avoid object cloning errors
65 @ini_set('zend.ze1_compatibility_mode', false);
67 /**
68 * Avoid problems with magic_quotes_runtime
70 @ini_set('magic_quotes_runtime', false);
73 /**
74 * for verification in all procedural scripts under libraries
76 define('PHPMYADMIN', true);
78 /**
79 * core functions
81 require './libraries/core.lib.php';
83 /**
84 * Input sanitizing
86 require './libraries/sanitizing.lib.php';
88 /**
89 * the PMA_Theme class
91 require './libraries/Theme.class.php';
93 /**
94 * the PMA_Theme_Manager class
96 require './libraries/Theme_Manager.class.php';
98 /**
99 * the PMA_Config class
101 require './libraries/Config.class.php';
104 * the relation lib, tracker needs it
106 require './libraries/relation.lib.php';
109 * the PMA_Tracker class
111 require './libraries/Tracker.class.php';
114 * the PMA_Table class
116 require './libraries/Table.class.php';
118 if (!defined('PMA_MINIMUM_COMMON')) {
120 * common functions
122 require_once './libraries/common.lib.php';
125 * Java script escaping.
127 require_once './libraries/js_escape.lib.php';
130 * Include URL/hidden inputs generating.
132 require_once './libraries/url_generating.lib.php';
135 /******************************************************************************/
136 /* start procedural code label_start_procedural */
139 * protect against possible exploits - there is no need to have so much variables
141 if (count($_REQUEST) > 1000) {
142 die('possible exploit');
146 * Check for numeric keys
147 * (if register_globals is on, numeric key can be found in $GLOBALS)
149 foreach ($GLOBALS as $key => $dummy) {
150 if (is_numeric($key)) {
151 die('numeric key detected');
154 unset($dummy);
157 * PATH_INFO could be compromised if set, so remove it from PHP_SELF
158 * and provide a clean PHP_SELF here
160 $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
161 $_PATH_INFO = PMA_getenv('PATH_INFO');
162 if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
163 $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
164 if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
165 $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
168 $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
172 * just to be sure there was no import (registering) before here
173 * we empty the global space (but avoid unsetting $variables_list
174 * and $key in the foreach(), we still need them!)
176 $variables_whitelist = array (
177 'GLOBALS',
178 '_SERVER',
179 '_GET',
180 '_POST',
181 '_REQUEST',
182 '_FILES',
183 '_ENV',
184 '_COOKIE',
185 '_SESSION',
186 'error_handler',
187 'PMA_PHP_SELF',
188 'variables_whitelist',
189 'key'
192 foreach (get_defined_vars() as $key => $value) {
193 if (! in_array($key, $variables_whitelist)) {
194 unset($$key);
197 unset($key, $value, $variables_whitelist);
201 * Subforms - some functions need to be called by form, cause of the limited URL
202 * length, but if this functions inside another form you cannot just open a new
203 * form - so phpMyAdmin uses 'arrays' inside this form
205 * <code>
206 * <form ...>
207 * ... main form elments ...
208 * <input type="hidden" name="subform[action1][id]" value="1" />
209 * ... other subform data ...
210 * <input type="submit" name="usesubform[action1]" value="do action1" />
211 * ... other subforms ...
212 * <input type="hidden" name="subform[actionX][id]" value="X" />
213 * ... other subform data ...
214 * <input type="submit" name="usesubform[actionX]" value="do actionX" />
215 * ... main form elments ...
216 * <input type="submit" name="main_action" value="submit form" />
217 * </form>
218 * </code>
220 * so we now check if a subform is submitted
222 $__redirect = null;
223 if (isset($_POST['usesubform'])) {
224 // if a subform is present and should be used
225 // the rest of the form is deprecated
226 $subform_id = key($_POST['usesubform']);
227 $subform = $_POST['subform'][$subform_id];
228 $_POST = $subform;
229 $_REQUEST = $subform;
231 * some subforms need another page than the main form, so we will just
232 * include this page at the end of this script - we use $__redirect to
233 * track this
235 if (isset($_POST['redirect'])
236 && $_POST['redirect'] != basename($PMA_PHP_SELF)) {
237 $__redirect = $_POST['redirect'];
238 unset($_POST['redirect']);
240 unset($subform_id, $subform);
241 } else {
242 // Note: here we overwrite $_REQUEST so that it does not contain cookies,
243 // because another application for the same domain could have set
244 // a cookie (with a compatible path) that overrides a variable
245 // we expect from GET or POST.
246 // We'll refer to cookies explicitly with the $_COOKIE syntax.
247 $_REQUEST = array_merge($_GET, $_POST);
249 // end check if a subform is submitted
251 // remove quotes added by php
252 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
253 PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
254 PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
255 PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
256 PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
260 * include deprecated grab_globals only if required
262 if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
263 require './libraries/grab_globals.lib.php';
267 * check timezone setting
268 * this could produce an E_STRICT - but only once,
269 * if not done here it will produce E_STRICT on every date/time function
271 * @todo need to decide how we should handle this (without @)
273 date_default_timezone_set(@date_default_timezone_get());
275 /******************************************************************************/
276 /* parsing configuration file LABEL_parsing_config_file */
279 * We really need this one!
281 if (! function_exists('preg_replace')) {
282 PMA_warnMissingExtension('pcre', true);
286 * @global PMA_Config $GLOBALS['PMA_Config']
287 * force reading of config file, because we removed sensitive values
288 * in the previous iteration
290 $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
292 if (!defined('PMA_MINIMUM_COMMON')) {
293 $GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
297 * BC - enable backward compatibility
298 * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
300 $GLOBALS['PMA_Config']->enableBc();
303 * clean cookies on upgrade
304 * when changing something related to PMA cookies, increment the cookie version
306 $pma_cookie_version = 4;
307 if (isset($_COOKIE)
308 && (isset($_COOKIE['pmaCookieVer'])
309 && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
310 // delete all cookies
311 foreach($_COOKIE as $cookie_name => $tmp) {
312 $GLOBALS['PMA_Config']->removeCookie($cookie_name);
314 $_COOKIE = array();
315 $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
320 * check HTTPS connection
322 if ($GLOBALS['PMA_Config']->get('ForceSSL')
323 && !$GLOBALS['PMA_Config']->get('is_https')) {
324 PMA_sendHeaderLocation(
325 preg_replace('/^http/', 'https',
326 $GLOBALS['PMA_Config']->get('PmaAbsoluteUri'))
327 . PMA_generate_common_url($_GET, 'text'));
328 // delete the current session, otherwise we get problems (see bug #2397877)
329 $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
330 exit;
335 * include session handling after the globals, to prevent overwriting
337 require './libraries/session.inc.php';
340 * init some variables LABEL_variables_init
344 * holds parameters to be passed to next page
345 * @global array $GLOBALS['url_params']
347 $GLOBALS['url_params'] = array();
350 * the whitelist for $GLOBALS['goto']
351 * @global array $goto_whitelist
353 $goto_whitelist = array(
354 //'browse_foreigners.php',
355 //'calendar.php',
356 //'changelog.php',
357 //'chk_rel.php',
358 'db_create.php',
359 'db_datadict.php',
360 'db_sql.php',
361 'db_export.php',
362 'db_importdocsql.php',
363 'db_qbe.php',
364 'db_structure.php',
365 'db_import.php',
366 'db_operations.php',
367 'db_printview.php',
368 'db_search.php',
369 //'Documentation.html',
370 //'error.php',
371 'export.php',
372 'import.php',
373 //'index.php',
374 //'navigation.php',
375 //'license.php',
376 'main.php',
377 'pdf_pages.php',
378 'pdf_schema.php',
379 //'phpinfo.php',
380 'querywindow.php',
381 //'readme.php',
382 'server_binlog.php',
383 'server_collations.php',
384 'server_databases.php',
385 'server_engines.php',
386 'server_export.php',
387 'server_import.php',
388 'server_privileges.php',
389 'server_processlist.php',
390 'server_sql.php',
391 'server_status.php',
392 'server_variables.php',
393 'sql.php',
394 'tbl_addfield.php',
395 'tbl_alter.php',
396 'tbl_change.php',
397 'tbl_create.php',
398 'tbl_import.php',
399 'tbl_indexes.php',
400 'tbl_move_copy.php',
401 'tbl_printview.php',
402 'tbl_sql.php',
403 'tbl_export.php',
404 'tbl_operations.php',
405 'tbl_structure.php',
406 'tbl_relation.php',
407 'tbl_replace.php',
408 'tbl_row_action.php',
409 'tbl_select.php',
410 //'themes.php',
411 'transformation_overview.php',
412 'transformation_wrapper.php',
413 'translators.html',
414 'user_password.php',
418 * check $__redirect against whitelist
420 if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
421 $__redirect = null;
425 * holds page that should be displayed
426 * @global string $GLOBALS['goto']
428 $GLOBALS['goto'] = '';
429 // Security fix: disallow accessing serious server files via "?goto="
430 if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
431 $GLOBALS['goto'] = $_REQUEST['goto'];
432 $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
433 } else {
434 unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
438 * returning page
439 * @global string $GLOBALS['back']
441 if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
442 $GLOBALS['back'] = $_REQUEST['back'];
443 } else {
444 unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
448 * Check whether user supplied token is valid, if not remove any possibly
449 * dangerous stuff from request.
451 * remember that some objects in the session with session_start and __wakeup()
452 * could access this variables before we reach this point
453 * f.e. PMA_Config: fontsize
455 * @todo variables should be handled by their respective owners (objects)
456 * f.e. lang, server, collation_connection in PMA_Config
458 if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
460 * List of parameters which are allowed from unsafe source
462 $allow_list = array(
463 /* needed for direct access, see FAQ 1.34
464 * also, server needed for cookie login screen (multi-server)
466 'server', 'db', 'table', 'target',
467 /* Session ID */
468 'phpMyAdmin',
469 /* Cookie preferences */
470 'pma_lang', 'pma_collation_connection',
471 /* Possible login form */
472 'pma_servername', 'pma_username', 'pma_password',
473 /* for playing blobstreamable media */
474 'media_type', 'custom_type', 'bs_reference',
475 /* for changing BLOB repository file MIME type */
476 'bs_db', 'bs_table', 'bs_ref', 'bs_new_mime_type'
479 * Require cleanup functions
481 require './libraries/cleanup.lib.php';
483 * Do actual cleanup
485 PMA_remove_request_vars($allow_list);
491 * current selected database
492 * @global string $GLOBALS['db']
494 $GLOBALS['db'] = '';
495 if (PMA_isValid($_REQUEST['db'])) {
496 // can we strip tags from this?
497 // only \ and / is not allowed in db names for MySQL
498 $GLOBALS['db'] = $_REQUEST['db'];
499 $GLOBALS['url_params']['db'] = $GLOBALS['db'];
503 * current selected table
504 * @global string $GLOBALS['table']
506 $GLOBALS['table'] = '';
507 if (PMA_isValid($_REQUEST['table'])) {
508 // can we strip tags from this?
509 // only \ and / is not allowed in table names for MySQL
510 $GLOBALS['table'] = $_REQUEST['table'];
511 $GLOBALS['url_params']['table'] = $GLOBALS['table'];
515 * SQL query to be executed
516 * @global string $GLOBALS['sql_query']
518 $GLOBALS['sql_query'] = '';
519 if (PMA_isValid($_REQUEST['sql_query'])) {
520 $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
524 * avoid problems in phpmyadmin.css.php in some cases
525 * @global string $js_frame
527 $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
529 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
530 //$_REQUEST['server']; // checked later in this file
531 //$_REQUEST['lang']; // checked by LABEL_loading_language_file
535 * holds name of JavaScript files to be included in HTML header
536 * @global array $js_include
538 $GLOBALS['js_include'] = array();
539 $GLOBALS['js_include'][] = 'jquery/jquery-1.4.2.js';
540 $GLOBALS['js_include'][] = 'update-location.js';
543 * Add common jQuery functions script here if necessary.
547 * JavaScript events that will be registered
548 * @global array $js_events
550 $GLOBALS['js_events'] = array();
553 * footnotes to be displayed ot the page bottom
554 * @global array $footnotes
556 $GLOBALS['footnotes'] = array();
558 /******************************************************************************/
559 /* loading language file LABEL_loading_language_file */
562 * lang detection is done here
564 require './libraries/select_lang.lib.php';
567 * check for errors occurred while loading configuration
568 * this check is done here after loading language files to present errors in locale
570 if ($GLOBALS['PMA_Config']->error_config_file) {
571 $error = __('phpMyAdmin was unable to read your configuration file!<br />This might happen if PHP finds a parse error in it or PHP cannot find the file.<br />Please call the configuration file directly using the link below and read the PHP error message(s) that you receive. In most cases a quote or a semicolon is missing somewhere.<br />If you receive a blank page, everything is fine.')
572 . '<br /><br />'
573 . ($GLOBALS['PMA_Config']->getSource() == CONFIG_FILE ?
574 '<a href="show_config_errors.php"'
575 .' target="_blank">' . $GLOBALS['PMA_Config']->getSource() . '</a>'
577 '<a href="' . $GLOBALS['PMA_Config']->getSource() . '"'
578 .' target="_blank">' . $GLOBALS['PMA_Config']->getSource() . '</a>');
579 trigger_error($error, E_USER_ERROR);
581 if ($GLOBALS['PMA_Config']->error_config_default_file) {
582 $error = sprintf(__('Could not load default configuration from: %1$s'),
583 $GLOBALS['PMA_Config']->default_source);
584 trigger_error($error, E_USER_ERROR);
586 if ($GLOBALS['PMA_Config']->error_pma_uri) {
587 trigger_error(__('The <tt>$cfg[\'PmaAbsoluteUri\']</tt> directive MUST be set in your configuration file!'), E_USER_ERROR);
591 /******************************************************************************/
592 /* setup servers LABEL_setup_servers */
595 * current server
596 * @global integer $GLOBALS['server']
598 $GLOBALS['server'] = 0;
601 * Servers array fixups.
602 * $default_server comes from PMA_Config::enableBc()
603 * @todo merge into PMA_Config
605 // Do we have some server?
606 if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
607 // No server => create one with defaults
608 $cfg['Servers'] = array(1 => $default_server);
609 } else {
610 // We have server(s) => apply default configuration
611 $new_servers = array();
613 foreach ($cfg['Servers'] as $server_index => $each_server) {
615 // Detect wrong configuration
616 if (!is_int($server_index) || $server_index < 1) {
617 trigger_error(sprintf(__('Invalid server index: %s'), $server_index), E_USER_ERROR);
620 $each_server = array_merge($default_server, $each_server);
622 // Don't use servers with no hostname
623 if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
624 trigger_error(sprintf(__('Invalid hostname for server %1$s. Please review your configuration.'), $server_index), E_USER_ERROR);
627 // Final solution to bug #582890
628 // If we are using a socket connection
629 // and there is nothing in the verbose server name
630 // or the host field, then generate a name for the server
631 // in the form of "Server 2", localized of course!
632 if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
633 $each_server['verbose'] = __('Server') . $server_index;
636 $new_servers[$server_index] = $each_server;
638 $cfg['Servers'] = $new_servers;
639 unset($new_servers, $server_index, $each_server);
642 // Cleanup
643 unset($default_server);
646 /******************************************************************************/
647 /* setup themes LABEL_theme_setup */
649 if (isset($_REQUEST['custom_color_reset'])) {
650 unset($_SESSION['tmp_user_values']['custom_color']);
651 } elseif (isset($_REQUEST['custom_color'])) {
652 $_SESSION['tmp_user_values']['custom_color'] = $_REQUEST['custom_color'];
655 * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
657 if (! isset($_SESSION['PMA_Theme_Manager'])) {
658 $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
659 } else {
661 * @todo move all __wakeup() functionality into session.inc.php
663 $_SESSION['PMA_Theme_Manager']->checkConfig();
666 // for the theme per server feature
667 if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
668 $GLOBALS['server'] = $_REQUEST['server'];
669 $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
670 if (empty($tmp)) {
671 $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
673 $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
674 unset($tmp);
677 * @todo move into PMA_Theme_Manager::__wakeup()
679 if (isset($_REQUEST['set_theme'])) {
680 // if user selected a theme
681 $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
685 * the theme object
686 * @global PMA_Theme $_SESSION['PMA_Theme']
688 $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
690 // BC
692 * the active theme
693 * @global string $GLOBALS['theme']
695 $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
697 * the theme path
698 * @global string $GLOBALS['pmaThemePath']
700 $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
702 * the theme image path
703 * @global string $GLOBALS['pmaThemeImage']
705 $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
708 * load layout file if exists
710 if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
711 include $_SESSION['PMA_Theme']->getLayoutFile();
713 * @todo remove if all themes are update use Navi instead of Left as frame name
715 if (! isset($GLOBALS['cfg']['NaviWidth'])
716 && isset($GLOBALS['cfg']['LeftWidth'])) {
717 $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
721 if (! defined('PMA_MINIMUM_COMMON')) {
723 * Character set conversion.
725 require_once './libraries/charset_conversion.lib.php';
728 * String handling
730 require_once './libraries/string.lib.php';
733 * Lookup server by name
734 * by Arnold - Helder Hosting
735 * (see FAQ 4.8)
737 if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
738 && ! is_numeric($_REQUEST['server'])) {
739 foreach ($cfg['Servers'] as $i => $server) {
740 if ($server['host'] == $_REQUEST['server']) {
741 $_REQUEST['server'] = $i;
742 break;
745 if (is_string($_REQUEST['server'])) {
746 unset($_REQUEST['server']);
748 unset($i);
752 * If no server is selected, make sure that $cfg['Server'] is empty (so
753 * that nothing will work), and skip server authentication.
754 * We do NOT exit here, but continue on without logging into any server.
755 * This way, the welcome page will still come up (with no server info) and
756 * present a choice of servers in the case that there are multiple servers
757 * and '$cfg['ServerDefault'] = 0' is set.
760 if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
761 $GLOBALS['server'] = $_REQUEST['server'];
762 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
763 } else {
764 if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
765 $GLOBALS['server'] = $cfg['ServerDefault'];
766 $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
767 } else {
768 $GLOBALS['server'] = 0;
769 $cfg['Server'] = array();
772 $GLOBALS['url_params']['server'] = $GLOBALS['server'];
775 * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
777 if (function_exists('mb_convert_encoding')
778 && $lang == 'ja') {
779 require_once './libraries/kanji-encoding.lib.php';
781 * enable multibyte string support
783 define('PMA_MULTIBYTE_ENCODING', 1);
784 } // end if
787 * save some settings in cookies
788 * @todo should be done in PMA_Config
790 $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
791 $GLOBALS['PMA_Config']->setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
793 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
795 if (! empty($cfg['Server'])) {
798 * Loads the proper database interface for this server
800 require_once './libraries/database_interface.lib.php';
802 require_once './libraries/logging.lib.php';
804 // get LoginCookieValidity from preferences cache
805 // no generic solution for loading preferences from cache as some settings need to be kept
806 // for processing in PMA_Config::loadUserPreferences()
807 $cache_key = 'server_' . $GLOBALS['server'];
808 if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])) {
809 $value = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
810 $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
811 $GLOBALS['cfg']['LoginCookieValidity'] = $value;
812 unset($value);
814 unset($cache_key);
816 // Gets the authentication library that fits the $cfg['Server'] settings
817 // and run authentication
819 // to allow HTTP or http
820 $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
821 if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
822 PMA_fatalError(__('Invalid authentication method set in configuration:') . ' ' . $cfg['Server']['auth_type']);
825 * the required auth type plugin
827 require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
828 if (!PMA_auth_check()) {
829 /* Force generating of new session on login */
830 PMA_secureSession();
831 PMA_auth();
832 } else {
833 PMA_auth_set_user();
836 // Check IP-based Allow/Deny rules as soon as possible to reject the
837 // user
838 // Based on mod_access in Apache:
839 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
840 // Look at: "static int check_dir_access(request_rec *r)"
841 // Robbat2 - May 10, 2002
842 if (isset($cfg['Server']['AllowDeny'])
843 && isset($cfg['Server']['AllowDeny']['order'])) {
846 * ip based access library
848 require_once './libraries/ip_allow_deny.lib.php';
850 $allowDeny_forbidden = false; // default
851 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
852 $allowDeny_forbidden = true;
853 if (PMA_allowDeny('allow')) {
854 $allowDeny_forbidden = false;
856 if (PMA_allowDeny('deny')) {
857 $allowDeny_forbidden = true;
859 } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
860 if (PMA_allowDeny('deny')) {
861 $allowDeny_forbidden = true;
863 if (PMA_allowDeny('allow')) {
864 $allowDeny_forbidden = false;
866 } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
867 if (PMA_allowDeny('allow')
868 && !PMA_allowDeny('deny')) {
869 $allowDeny_forbidden = false;
870 } else {
871 $allowDeny_forbidden = true;
873 } // end if ... elseif ... elseif
875 // Ejects the user if banished
876 if ($allowDeny_forbidden) {
877 PMA_log_user($cfg['Server']['user'], 'allow-denied');
878 PMA_auth_fails();
880 unset($allowDeny_forbidden); //Clean up after you!
881 } // end if
883 // is root allowed?
884 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
885 $allowDeny_forbidden = true;
886 PMA_log_user($cfg['Server']['user'], 'root-denied');
887 PMA_auth_fails();
888 unset($allowDeny_forbidden); //Clean up after you!
891 // is a login without password allowed?
892 if (!$cfg['Server']['AllowNoPassword'] && $cfg['Server']['password'] == '') {
893 $login_without_password_is_forbidden = true;
894 PMA_log_user($cfg['Server']['user'], 'empty-denied');
895 PMA_auth_fails();
896 unset($login_without_password_is_forbidden); //Clean up after you!
899 // Try to connect MySQL with the control user profile (will be used to
900 // get the privileges list for the current user but the true user link
901 // must be open after this one so it would be default one for all the
902 // scripts)
903 $controllink = false;
904 if ($cfg['Server']['controluser'] != '') {
905 $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
906 $cfg['Server']['controlpass'], true);
909 // Connects to the server (validates user's login)
910 $userlink = PMA_DBI_connect($cfg['Server']['user'],
911 $cfg['Server']['password'], false);
913 if (! $controllink) {
914 $controllink = $userlink;
917 /* Log success */
918 PMA_log_user($cfg['Server']['user']);
921 * with phpMyAdmin 3 we support MySQL >=5
922 * but only production releases:
923 * - > 5.0.15
925 if (PMA_MYSQL_INT_VERSION < 50015) {
926 PMA_fatalError(__('You should upgrade to %s %s or later.'), array('MySQL', '5.0.15'));
930 * SQL Parser code
932 require_once './libraries/sqlparser.lib.php';
935 * SQL Validator interface code
937 require_once './libraries/sqlvalidator.lib.php';
940 * the PMA_List_Database class
942 require_once './libraries/PMA.php';
943 $pma = new PMA;
944 $pma->userlink = $userlink;
945 $pma->controllink = $controllink;
948 * some resetting has to be done when switching servers
950 if (isset($_SESSION['tmp_user_values']['previous_server']) && $_SESSION['tmp_user_values']['previous_server'] != $GLOBALS['server']) {
951 unset($_SESSION['tmp_user_values']['navi_limit_offset']);
953 $_SESSION['tmp_user_values']['previous_server'] = $GLOBALS['server'];
955 } // end server connecting
958 * check if profiling was requested and remember it
959 * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
961 if (isset($_REQUEST['profiling']) && PMA_profilingSupported()) {
962 $_SESSION['profiling'] = true;
963 } elseif (isset($_REQUEST['profiling_form'])) {
964 // the checkbox was unchecked
965 unset($_SESSION['profiling']);
968 // library file for blobstreaming
969 require_once './libraries/blobstreaming.lib.php';
971 // checks for blobstreaming plugins and databases that support
972 // blobstreaming (by having the necessary tables for blobstreaming)
973 checkBLOBStreamingPlugins();
975 } // end if !defined('PMA_MINIMUM_COMMON')
977 // load user preferences
978 $GLOBALS['PMA_Config']->loadUserPreferences();
980 // remove sensitive values from session
981 $GLOBALS['PMA_Config']->set('blowfish_secret', '');
982 $GLOBALS['PMA_Config']->set('Servers', '');
983 $GLOBALS['PMA_Config']->set('default_server', '');
985 /* Tell tracker that it can actually work */
986 PMA_Tracker::enable();
989 * @global boolean $GLOBALS['is_ajax_request']
990 * @todo should this be moved to the variables init section above?
992 * Check if the current request is an AJAX request, and set is_ajax_request
993 * accordingly. Suppress headers, footers and unnecessary output if set to
994 * true
996 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
997 $GLOBALS['is_ajax_request'] = true;
998 } else {
999 $GLOBALS['is_ajax_request'] = false;
1003 * @global boolean $GLOBALS['inline_edit']
1005 * Set to true if this is a request made during an inline edit process. This
1006 * request is made to retrieve the non-truncated/transformed values.
1008 if(isset($_REQUEST['inline_edit']) && $_REQUEST['inline_edit'] == true) {
1009 $GLOBALS['inline_edit'] = true;
1011 else {
1012 $GLOBALS['inline_edit'] = false;
1015 if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
1017 * include subform target page
1019 require $__redirect;
1020 exit();