PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/phpMyAdmin/libraries/common.inc.php

https://bitbucket.org/tonnyz/scan_ccv
PHP | 1067 lines | 475 code | 124 blank | 468 comment | 133 complexity | fc704b632bf2ce5fe6dee2e3f211f499 MD5 | raw file
Possible License(s): GPL-2.0
  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. * the authentication libraries must be before the connection to db
  12. *
  13. * ... so the required order is:
  14. *
  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
  25. *
  26. * - load of MySQL extension (if necessary)
  27. * - loading of an authentication library
  28. * - db connection
  29. * - authentication work
  30. *
  31. * @package PhpMyAdmin
  32. */
  33. /**
  34. * Minimum PHP version; can't call PMA_fatalError() which uses a
  35. * PHP 5 function, so cannot easily localize this message.
  36. */
  37. if (version_compare(PHP_VERSION, '5.2.0', 'lt')) {
  38. die('PHP 5.2+ is required');
  39. }
  40. /**
  41. * Backward compatibility for PHP 5.2
  42. */
  43. if (!defined('E_DEPRECATED')) {
  44. define('E_DEPRECATED', 8192);
  45. }
  46. /**
  47. * the error handler
  48. */
  49. require './libraries/Error_Handler.class.php';
  50. /**
  51. * initialize the error handler
  52. */
  53. $GLOBALS['error_handler'] = new PMA_Error_Handler();
  54. $cfg['Error_Handler']['display'] = true;
  55. /*
  56. * This setting was removed in PHP 5.3. But at this point PMA_PHP_INT_VERSION
  57. * is not yet defined so we use another way to find out the PHP version.
  58. */
  59. if (version_compare(phpversion(), '5.3', 'lt')) {
  60. /**
  61. * Avoid object cloning errors
  62. */
  63. @ini_set('zend.ze1_compatibility_mode', false);
  64. }
  65. /**
  66. * This setting was removed in PHP 5.4. But at this point PMA_PHP_INT_VERSION
  67. * is not yet defined so we use another way to find out the PHP version.
  68. */
  69. if (version_compare(phpversion(), '5.4', 'lt')) {
  70. /**
  71. * Avoid problems with magic_quotes_runtime
  72. */
  73. @ini_set('magic_quotes_runtime', false);
  74. }
  75. /**
  76. * for verification in all procedural scripts under libraries
  77. */
  78. define('PHPMYADMIN', true);
  79. /**
  80. * core functions
  81. */
  82. require './libraries/core.lib.php';
  83. /**
  84. * Input sanitizing
  85. */
  86. require './libraries/sanitizing.lib.php';
  87. /**
  88. * the PMA_Theme class
  89. */
  90. require './libraries/Theme.class.php';
  91. /**
  92. * the PMA_Theme_Manager class
  93. */
  94. require './libraries/Theme_Manager.class.php';
  95. /**
  96. * the PMA_Config class
  97. */
  98. require './libraries/Config.class.php';
  99. /**
  100. * the relation lib, tracker needs it
  101. */
  102. require './libraries/relation.lib.php';
  103. /**
  104. * the PMA_Tracker class
  105. */
  106. require './libraries/Tracker.class.php';
  107. /**
  108. * the PMA_Table class
  109. */
  110. require './libraries/Table.class.php';
  111. if (!defined('PMA_MINIMUM_COMMON')) {
  112. /**
  113. * common functions
  114. */
  115. include_once './libraries/common.lib.php';
  116. /**
  117. * Java script escaping.
  118. */
  119. include_once './libraries/js_escape.lib.php';
  120. /**
  121. * Include URL/hidden inputs generating.
  122. */
  123. include_once './libraries/url_generating.lib.php';
  124. }
  125. /******************************************************************************/
  126. /* start procedural code label_start_procedural */
  127. /**
  128. * protect against possible exploits - there is no need to have so much variables
  129. */
  130. if (count($_REQUEST) > 1000) {
  131. die(__('possible exploit'));
  132. }
  133. /**
  134. * Check for numeric keys
  135. * (if register_globals is on, numeric key can be found in $GLOBALS)
  136. */
  137. foreach ($GLOBALS as $key => $dummy) {
  138. if (is_numeric($key)) {
  139. die(__('numeric key detected'));
  140. }
  141. }
  142. unset($dummy);
  143. /**
  144. * PATH_INFO could be compromised if set, so remove it from PHP_SELF
  145. * and provide a clean PHP_SELF here
  146. */
  147. $PMA_PHP_SELF = PMA_getenv('PHP_SELF');
  148. $_PATH_INFO = PMA_getenv('PATH_INFO');
  149. if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
  150. $path_info_pos = strrpos($PMA_PHP_SELF, $_PATH_INFO);
  151. if ($path_info_pos + strlen($_PATH_INFO) === strlen($PMA_PHP_SELF)) {
  152. $PMA_PHP_SELF = substr($PMA_PHP_SELF, 0, $path_info_pos);
  153. }
  154. }
  155. $PMA_PHP_SELF = htmlspecialchars($PMA_PHP_SELF);
  156. /**
  157. * just to be sure there was no import (registering) before here
  158. * we empty the global space (but avoid unsetting $variables_list
  159. * and $key in the foreach (), we still need them!)
  160. */
  161. $variables_whitelist = array (
  162. 'GLOBALS',
  163. '_SERVER',
  164. '_GET',
  165. '_POST',
  166. '_REQUEST',
  167. '_FILES',
  168. '_ENV',
  169. '_COOKIE',
  170. '_SESSION',
  171. 'error_handler',
  172. 'PMA_PHP_SELF',
  173. 'variables_whitelist',
  174. 'key'
  175. );
  176. foreach (get_defined_vars() as $key => $value) {
  177. if (! in_array($key, $variables_whitelist)) {
  178. unset($$key);
  179. }
  180. }
  181. unset($key, $value, $variables_whitelist);
  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. * This setting was removed in PHP 5.4. But at this point PMA_PHP_INT_VERSION
  234. * is not yet defined so we use another way to find out the PHP version.
  235. */
  236. if (version_compare(phpversion(), '5.4', 'lt')) {
  237. // remove quotes added by PHP
  238. if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
  239. PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
  240. PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
  241. PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
  242. PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
  243. }
  244. }
  245. /**
  246. * include deprecated grab_globals only if required
  247. */
  248. if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
  249. include './libraries/grab_globals.lib.php';
  250. }
  251. /**
  252. * check timezone setting
  253. * this could produce an E_STRICT - but only once,
  254. * if not done here it will produce E_STRICT on every date/time function
  255. *
  256. * @todo need to decide how we should handle this (without @)
  257. */
  258. date_default_timezone_set(@date_default_timezone_get());
  259. /******************************************************************************/
  260. /* parsing configuration file LABEL_parsing_config_file */
  261. /**
  262. * We really need this one!
  263. */
  264. if (! function_exists('preg_replace')) {
  265. PMA_warnMissingExtension('pcre', true);
  266. }
  267. /**
  268. * @global PMA_Config $GLOBALS['PMA_Config']
  269. * force reading of config file, because we removed sensitive values
  270. * in the previous iteration
  271. */
  272. $GLOBALS['PMA_Config'] = new PMA_Config(CONFIG_FILE);
  273. if (!defined('PMA_MINIMUM_COMMON')) {
  274. $GLOBALS['PMA_Config']->checkPmaAbsoluteUri();
  275. }
  276. /**
  277. * BC - enable backward compatibility
  278. * exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
  279. */
  280. $GLOBALS['PMA_Config']->enableBc();
  281. /**
  282. * clean cookies on upgrade
  283. * when changing something related to PMA cookies, increment the cookie version
  284. */
  285. $pma_cookie_version = 4;
  286. if (isset($_COOKIE)
  287. && (isset($_COOKIE['pmaCookieVer'])
  288. && $_COOKIE['pmaCookieVer'] < $pma_cookie_version)) {
  289. // delete all cookies
  290. foreach ($_COOKIE as $cookie_name => $tmp) {
  291. $GLOBALS['PMA_Config']->removeCookie($cookie_name);
  292. }
  293. $_COOKIE = array();
  294. $GLOBALS['PMA_Config']->setCookie('pmaCookieVer', $pma_cookie_version);
  295. }
  296. /**
  297. * check HTTPS connection
  298. */
  299. if ($GLOBALS['PMA_Config']->get('ForceSSL')
  300. && !$GLOBALS['PMA_Config']->get('is_https')) {
  301. PMA_sendHeaderLocation(
  302. preg_replace('/^http/', 'https',
  303. $GLOBALS['PMA_Config']->get('PmaAbsoluteUri'))
  304. . PMA_generate_common_url($_GET, 'text'));
  305. // delete the current session, otherwise we get problems (see bug #2397877)
  306. $GLOBALS['PMA_Config']->removeCookie($GLOBALS['session_name']);
  307. exit;
  308. }
  309. /**
  310. * include session handling after the globals, to prevent overwriting
  311. */
  312. require './libraries/session.inc.php';
  313. /**
  314. * init some variables LABEL_variables_init
  315. */
  316. /**
  317. * holds parameters to be passed to next page
  318. * @global array $GLOBALS['url_params']
  319. */
  320. $GLOBALS['url_params'] = array();
  321. /**
  322. * the whitelist for $GLOBALS['goto']
  323. * @global array $goto_whitelist
  324. */
  325. $goto_whitelist = array(
  326. //'browse_foreigners.php',
  327. //'calendar.php',
  328. //'changelog.php',
  329. //'chk_rel.php',
  330. 'db_create.php',
  331. 'db_datadict.php',
  332. 'db_sql.php',
  333. 'db_events.php',
  334. 'db_export.php',
  335. 'db_importdocsql.php',
  336. 'db_qbe.php',
  337. 'db_structure.php',
  338. 'db_import.php',
  339. 'db_operations.php',
  340. 'db_printview.php',
  341. 'db_search.php',
  342. 'db_routines.php',
  343. //'Documentation.html',
  344. 'export.php',
  345. 'import.php',
  346. //'index.php',
  347. //'navigation.php',
  348. //'license.php',
  349. 'main.php',
  350. 'pdf_pages.php',
  351. 'pdf_schema.php',
  352. //'phpinfo.php',
  353. 'querywindow.php',
  354. //'readme.php',
  355. 'server_binlog.php',
  356. 'server_collations.php',
  357. 'server_databases.php',
  358. 'server_engines.php',
  359. 'server_export.php',
  360. 'server_import.php',
  361. 'server_privileges.php',
  362. 'server_processlist.php',
  363. 'server_sql.php',
  364. 'server_status.php',
  365. 'server_variables.php',
  366. 'sql.php',
  367. 'tbl_addfield.php',
  368. 'tbl_alter.php',
  369. 'tbl_change.php',
  370. 'tbl_create.php',
  371. 'tbl_import.php',
  372. 'tbl_indexes.php',
  373. 'tbl_move_copy.php',
  374. 'tbl_printview.php',
  375. 'tbl_sql.php',
  376. 'tbl_export.php',
  377. 'tbl_operations.php',
  378. 'tbl_structure.php',
  379. 'tbl_relation.php',
  380. 'tbl_replace.php',
  381. 'tbl_row_action.php',
  382. 'tbl_select.php',
  383. 'tbl_zoom_select.php',
  384. //'themes.php',
  385. 'transformation_overview.php',
  386. 'transformation_wrapper.php',
  387. 'user_password.php',
  388. );
  389. /**
  390. * check $__redirect against whitelist
  391. */
  392. if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
  393. $__redirect = null;
  394. }
  395. /**
  396. * holds page that should be displayed
  397. * @global string $GLOBALS['goto']
  398. */
  399. $GLOBALS['goto'] = '';
  400. // Security fix: disallow accessing serious server files via "?goto="
  401. if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
  402. $GLOBALS['goto'] = $_REQUEST['goto'];
  403. $GLOBALS['url_params']['goto'] = $_REQUEST['goto'];
  404. } else {
  405. unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto'], $_COOKIE['goto']);
  406. }
  407. /**
  408. * returning page
  409. * @global string $GLOBALS['back']
  410. */
  411. if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
  412. $GLOBALS['back'] = $_REQUEST['back'];
  413. } else {
  414. unset($_REQUEST['back'], $_GET['back'], $_POST['back'], $_COOKIE['back']);
  415. }
  416. /**
  417. * Check whether user supplied token is valid, if not remove any possibly
  418. * dangerous stuff from request.
  419. *
  420. * remember that some objects in the session with session_start and __wakeup()
  421. * could access this variables before we reach this point
  422. * f.e. PMA_Config: fontsize
  423. *
  424. * @todo variables should be handled by their respective owners (objects)
  425. * f.e. lang, server, collation_connection in PMA_Config
  426. */
  427. if (! PMA_isValid($_REQUEST['token']) || $_SESSION[' PMA_token '] != $_REQUEST['token']) {
  428. /**
  429. * List of parameters which are allowed from unsafe source
  430. */
  431. $allow_list = array(
  432. /* needed for direct access, see FAQ 1.34
  433. * also, server needed for cookie login screen (multi-server)
  434. */
  435. 'server', 'db', 'table', 'target', 'lang',
  436. /* Session ID */
  437. 'phpMyAdmin',
  438. /* Cookie preferences */
  439. 'pma_lang', 'pma_collation_connection',
  440. /* Possible login form */
  441. 'pma_servername', 'pma_username', 'pma_password',
  442. /* for playing blobstreamable media */
  443. 'media_type', 'custom_type', 'bs_reference',
  444. /* for changing BLOB repository file MIME type */
  445. 'bs_db', 'bs_table', 'bs_ref', 'bs_new_mime_type',
  446. );
  447. /**
  448. * Require cleanup functions
  449. */
  450. include './libraries/cleanup.lib.php';
  451. /**
  452. * Do actual cleanup
  453. */
  454. PMA_remove_request_vars($allow_list);
  455. }
  456. /**
  457. * current selected database
  458. * @global string $GLOBALS['db']
  459. */
  460. $GLOBALS['db'] = '';
  461. if (PMA_isValid($_REQUEST['db'])) {
  462. // can we strip tags from this?
  463. // only \ and / is not allowed in db names for MySQL
  464. $GLOBALS['db'] = $_REQUEST['db'];
  465. $GLOBALS['url_params']['db'] = $GLOBALS['db'];
  466. }
  467. /**
  468. * current selected table
  469. * @global string $GLOBALS['table']
  470. */
  471. $GLOBALS['table'] = '';
  472. if (PMA_isValid($_REQUEST['table'])) {
  473. // can we strip tags from this?
  474. // only \ and / is not allowed in table names for MySQL
  475. $GLOBALS['table'] = $_REQUEST['table'];
  476. $GLOBALS['url_params']['table'] = $GLOBALS['table'];
  477. }
  478. /**
  479. * Store currently selected recent table.
  480. * Affect $GLOBALS['db'] and $GLOBALS['table']
  481. */
  482. if (PMA_isValid($_REQUEST['selected_recent_table'])) {
  483. $recent_table = json_decode($_REQUEST['selected_recent_table'], true);
  484. $GLOBALS['db'] = $recent_table['db'];
  485. $GLOBALS['url_params']['db'] = $GLOBALS['db'];
  486. $GLOBALS['table'] = $recent_table['table'];
  487. $GLOBALS['url_params']['table'] = $GLOBALS['table'];
  488. }
  489. /**
  490. * SQL query to be executed
  491. * @global string $GLOBALS['sql_query']
  492. */
  493. $GLOBALS['sql_query'] = '';
  494. if (PMA_isValid($_REQUEST['sql_query'])) {
  495. $GLOBALS['sql_query'] = $_REQUEST['sql_query'];
  496. }
  497. /**
  498. * avoid problems in phpmyadmin.css.php in some cases
  499. * @global string $js_frame
  500. */
  501. $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], '');
  502. //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
  503. //$_REQUEST['server']; // checked later in this file
  504. //$_REQUEST['lang']; // checked by LABEL_loading_language_file
  505. /**
  506. * holds name of JavaScript files to be included in HTML header
  507. * @global array $js_include
  508. */
  509. $GLOBALS['js_include'] = array();
  510. $GLOBALS['js_include'][] = 'jquery/jquery-1.6.2.js';
  511. $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
  512. $GLOBALS['js_include'][] = 'update-location.js';
  513. /**
  514. * holds an array of javascript code snippets to be included in the HTML header
  515. * Can be used with PMA_AddJSCode() to pass on js variables to the browser.
  516. * @global array $js_script
  517. */
  518. $GLOBALS['js_script'] = array();
  519. /**
  520. * Add common jQuery functions script here if necessary.
  521. */
  522. /**
  523. * JavaScript events that will be registered
  524. * @global array $js_events
  525. */
  526. $GLOBALS['js_events'] = array();
  527. /**
  528. * footnotes to be displayed ot the page bottom
  529. * @global array $footnotes
  530. */
  531. $GLOBALS['footnotes'] = array();
  532. /******************************************************************************/
  533. /* loading language file LABEL_loading_language_file */
  534. /**
  535. * lang detection is done here
  536. */
  537. require './libraries/select_lang.lib.php';
  538. /**
  539. * check for errors occurred while loading configuration
  540. * this check is done here after loading language files to present errors in locale
  541. */
  542. if ($GLOBALS['PMA_Config']->error_config_file) {
  543. $error = '<h1>' . __('Failed to read configuration file') . '</h1>'
  544. . _('This usually means there is a syntax error in it, please check any errors shown below.')
  545. . '<br />'
  546. . '<br />'
  547. . '<iframe src="show_config_errors.php" />';
  548. trigger_error($error, E_USER_ERROR);
  549. }
  550. if ($GLOBALS['PMA_Config']->error_config_default_file) {
  551. $error = sprintf(__('Could not load default configuration from: %1$s'),
  552. $GLOBALS['PMA_Config']->default_source);
  553. trigger_error($error, E_USER_ERROR);
  554. }
  555. if ($GLOBALS['PMA_Config']->error_pma_uri) {
  556. trigger_error(__('The <tt>$cfg[\'PmaAbsoluteUri\']</tt> directive MUST be set in your configuration file!'), E_USER_ERROR);
  557. }
  558. /******************************************************************************/
  559. /* setup servers LABEL_setup_servers */
  560. /**
  561. * current server
  562. * @global integer $GLOBALS['server']
  563. */
  564. $GLOBALS['server'] = 0;
  565. /**
  566. * Servers array fixups.
  567. * $default_server comes from PMA_Config::enableBc()
  568. * @todo merge into PMA_Config
  569. */
  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();
  577. foreach ($cfg['Servers'] as $server_index => $each_server) {
  578. // Detect wrong configuration
  579. if (!is_int($server_index) || $server_index < 1) {
  580. trigger_error(sprintf(__('Invalid server index: %s'), $server_index), E_USER_ERROR);
  581. }
  582. $each_server = array_merge($default_server, $each_server);
  583. // Don't use servers with no hostname
  584. if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
  585. trigger_error(sprintf(__('Invalid hostname for server %1$s. Please review your configuration.'), $server_index), E_USER_ERROR);
  586. }
  587. // Final solution to bug #582890
  588. // If we are using a socket connection
  589. // and there is nothing in the verbose server name
  590. // or the host field, then generate a name for the server
  591. // in the form of "Server 2", localized of course!
  592. if ($each_server['connect_type'] == 'socket' && empty($each_server['host']) && empty($each_server['verbose'])) {
  593. $each_server['verbose'] = __('Server') . $server_index;
  594. }
  595. $new_servers[$server_index] = $each_server;
  596. }
  597. $cfg['Servers'] = $new_servers;
  598. unset($new_servers, $server_index, $each_server);
  599. }
  600. // Cleanup
  601. unset($default_server);
  602. /******************************************************************************/
  603. /* setup themes LABEL_theme_setup */
  604. /**
  605. * @global PMA_Theme_Manager $_SESSION['PMA_Theme_Manager']
  606. */
  607. if (! isset($_SESSION['PMA_Theme_Manager'])) {
  608. $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
  609. } else {
  610. /**
  611. * @todo move all __wakeup() functionality into session.inc.php
  612. */
  613. $_SESSION['PMA_Theme_Manager']->checkConfig();
  614. }
  615. // for the theme per server feature
  616. if (isset($_REQUEST['server']) && ! isset($_REQUEST['set_theme'])) {
  617. $GLOBALS['server'] = $_REQUEST['server'];
  618. $tmp = $_SESSION['PMA_Theme_Manager']->getThemeCookie();
  619. if (empty($tmp)) {
  620. $tmp = $_SESSION['PMA_Theme_Manager']->theme_default;
  621. }
  622. $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
  623. unset($tmp);
  624. }
  625. /**
  626. * @todo move into PMA_Theme_Manager::__wakeup()
  627. */
  628. if (isset($_REQUEST['set_theme'])) {
  629. // if user selected a theme
  630. $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
  631. }
  632. /**
  633. * the theme object
  634. * @global PMA_Theme $_SESSION['PMA_Theme']
  635. */
  636. $_SESSION['PMA_Theme'] = $_SESSION['PMA_Theme_Manager']->theme;
  637. // BC
  638. /**
  639. * the active theme
  640. * @global string $GLOBALS['theme']
  641. */
  642. $GLOBALS['theme'] = $_SESSION['PMA_Theme']->getName();
  643. /**
  644. * the theme path
  645. * @global string $GLOBALS['pmaThemePath']
  646. */
  647. $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
  648. /**
  649. * the theme image path
  650. * @global string $GLOBALS['pmaThemeImage']
  651. */
  652. $GLOBALS['pmaThemeImage'] = $_SESSION['PMA_Theme']->getImgPath();
  653. /**
  654. * load layout file if exists
  655. */
  656. if (@file_exists($_SESSION['PMA_Theme']->getLayoutFile())) {
  657. include $_SESSION['PMA_Theme']->getLayoutFile();
  658. /**
  659. * @todo remove if all themes are update use Navi instead of Left as frame name
  660. */
  661. if (! isset($GLOBALS['cfg']['NaviWidth'])
  662. && isset($GLOBALS['cfg']['LeftWidth'])) {
  663. $GLOBALS['cfg']['NaviWidth'] = $GLOBALS['cfg']['LeftWidth'];
  664. }
  665. }
  666. if (! defined('PMA_MINIMUM_COMMON')) {
  667. /**
  668. * Character set conversion.
  669. */
  670. include_once './libraries/charset_conversion.lib.php';
  671. /**
  672. * String handling
  673. */
  674. include_once './libraries/string.lib.php';
  675. /**
  676. * Lookup server by name
  677. * (see FAQ 4.8)
  678. */
  679. if (! empty($_REQUEST['server']) && is_string($_REQUEST['server'])
  680. && ! is_numeric($_REQUEST['server'])) {
  681. foreach ($cfg['Servers'] as $i => $server) {
  682. if ($server['host'] == $_REQUEST['server']) {
  683. $_REQUEST['server'] = $i;
  684. break;
  685. }
  686. }
  687. if (is_string($_REQUEST['server'])) {
  688. unset($_REQUEST['server']);
  689. }
  690. unset($i);
  691. }
  692. /**
  693. * If no server is selected, make sure that $cfg['Server'] is empty (so
  694. * that nothing will work), and skip server authentication.
  695. * We do NOT exit here, but continue on without logging into any server.
  696. * This way, the welcome page will still come up (with no server info) and
  697. * present a choice of servers in the case that there are multiple servers
  698. * and '$cfg['ServerDefault'] = 0' is set.
  699. */
  700. if (isset($_REQUEST['server']) && (is_string($_REQUEST['server']) || is_numeric($_REQUEST['server'])) && ! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) {
  701. $GLOBALS['server'] = $_REQUEST['server'];
  702. $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
  703. } else {
  704. if (!empty($cfg['Servers'][$cfg['ServerDefault']])) {
  705. $GLOBALS['server'] = $cfg['ServerDefault'];
  706. $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
  707. } else {
  708. $GLOBALS['server'] = 0;
  709. $cfg['Server'] = array();
  710. }
  711. }
  712. $GLOBALS['url_params']['server'] = $GLOBALS['server'];
  713. /**
  714. * Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
  715. */
  716. if (function_exists('mb_convert_encoding')
  717. && $lang == 'ja') {
  718. include_once './libraries/kanji-encoding.lib.php';
  719. } // end if
  720. /**
  721. * save some settings in cookies
  722. * @todo should be done in PMA_Config
  723. */
  724. $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
  725. if (isset($GLOBALS['collation_connection'])) {
  726. $GLOBALS['PMA_Config']->setCookie(
  727. 'pma_collation_connection',
  728. $GLOBALS['collation_connection']);
  729. }
  730. $_SESSION['PMA_Theme_Manager']->setThemeCookie();
  731. if (! empty($cfg['Server'])) {
  732. /**
  733. * Loads the proper database interface for this server
  734. */
  735. include_once './libraries/database_interface.lib.php';
  736. include_once './libraries/logging.lib.php';
  737. // get LoginCookieValidity from preferences cache
  738. // no generic solution for loading preferences from cache as some settings need to be kept
  739. // for processing in PMA_Config::loadUserPreferences()
  740. $cache_key = 'server_' . $GLOBALS['server'];
  741. if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])) {
  742. $value = $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
  743. $GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
  744. $GLOBALS['cfg']['LoginCookieValidity'] = $value;
  745. unset($value);
  746. }
  747. unset($cache_key);
  748. // Gets the authentication library that fits the $cfg['Server'] settings
  749. // and run authentication
  750. // to allow HTTP or http
  751. $cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
  752. if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
  753. PMA_fatalError(__('Invalid authentication method set in configuration:') . ' ' . $cfg['Server']['auth_type']);
  754. }
  755. /**
  756. * the required auth type plugin
  757. */
  758. include_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
  759. if (!PMA_auth_check()) {
  760. /* Force generating of new session on login */
  761. PMA_secureSession();
  762. PMA_auth();
  763. } else {
  764. PMA_auth_set_user();
  765. }
  766. // Check IP-based Allow/Deny rules as soon as possible to reject the
  767. // user
  768. // Based on mod_access in Apache:
  769. // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
  770. // Look at: "static int check_dir_access(request_rec *r)"
  771. if (isset($cfg['Server']['AllowDeny'])
  772. && isset($cfg['Server']['AllowDeny']['order'])) {
  773. /**
  774. * ip based access library
  775. */
  776. include_once './libraries/ip_allow_deny.lib.php';
  777. $allowDeny_forbidden = false; // default
  778. if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
  779. $allowDeny_forbidden = true;
  780. if (PMA_allowDeny('allow')) {
  781. $allowDeny_forbidden = false;
  782. }
  783. if (PMA_allowDeny('deny')) {
  784. $allowDeny_forbidden = true;
  785. }
  786. } elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
  787. if (PMA_allowDeny('deny')) {
  788. $allowDeny_forbidden = true;
  789. }
  790. if (PMA_allowDeny('allow')) {
  791. $allowDeny_forbidden = false;
  792. }
  793. } elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
  794. if (PMA_allowDeny('allow')
  795. && !PMA_allowDeny('deny')) {
  796. $allowDeny_forbidden = false;
  797. } else {
  798. $allowDeny_forbidden = true;
  799. }
  800. } // end if ... elseif ... elseif
  801. // Ejects the user if banished
  802. if ($allowDeny_forbidden) {
  803. PMA_log_user($cfg['Server']['user'], 'allow-denied');
  804. PMA_auth_fails();
  805. }
  806. unset($allowDeny_forbidden); //Clean up after you!
  807. } // end if
  808. // is root allowed?
  809. if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
  810. $allowDeny_forbidden = true;
  811. PMA_log_user($cfg['Server']['user'], 'root-denied');
  812. PMA_auth_fails();
  813. unset($allowDeny_forbidden); //Clean up after you!
  814. }
  815. // is a login without password allowed?
  816. if (!$cfg['Server']['AllowNoPassword'] && $cfg['Server']['password'] == '') {
  817. $login_without_password_is_forbidden = true;
  818. PMA_log_user($cfg['Server']['user'], 'empty-denied');
  819. PMA_auth_fails();
  820. unset($login_without_password_is_forbidden); //Clean up after you!
  821. }
  822. // if using TCP socket is not needed
  823. if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
  824. $cfg['Server']['socket'] = '';
  825. }
  826. // Try to connect MySQL with the control user profile (will be used to
  827. // get the privileges list for the current user but the true user link
  828. // must be open after this one so it would be default one for all the
  829. // scripts)
  830. $controllink = false;
  831. if ($cfg['Server']['controluser'] != '') {
  832. if (! empty($cfg['Server']['controlhost'])) {
  833. $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
  834. $cfg['Server']['controlpass'], true,
  835. array('host' => $cfg['Server']['controlhost'])
  836. );
  837. } else {
  838. $controllink = PMA_DBI_connect($cfg['Server']['controluser'],
  839. $cfg['Server']['controlpass'], true);
  840. }
  841. }
  842. // Connects to the server (validates user's login)
  843. $userlink = PMA_DBI_connect($cfg['Server']['user'],
  844. $cfg['Server']['password'], false);
  845. if (! $controllink) {
  846. $controllink = $userlink;
  847. }
  848. /* Log success */
  849. PMA_log_user($cfg['Server']['user']);
  850. /**
  851. * with phpMyAdmin 3 we support MySQL >=5
  852. * but only production releases:
  853. * - > 5.0.15
  854. */
  855. if (PMA_MYSQL_INT_VERSION < 50015) {
  856. PMA_fatalError(__('You should upgrade to %s %s or later.'), array('MySQL', '5.0.15'));
  857. }
  858. if (PMA_DRIZZLE) {
  859. // DisableIS must be set to false for Drizzle, it maps SHOW commands
  860. // to INFORMATION_SCHEMA queries anyway so it's fast on large servers
  861. $cfg['Server']['DisableIS'] = false;
  862. // SHOW OPEN TABLES is not supported by Drizzle
  863. $cfg['SkipLockedTables'] = false;
  864. }
  865. /**
  866. * SQL Parser code
  867. */
  868. include_once './libraries/sqlparser.lib.php';
  869. /**
  870. * SQL Validator interface code
  871. */
  872. include_once './libraries/sqlvalidator.lib.php';
  873. /**
  874. * the PMA_List_Database class
  875. */
  876. include_once './libraries/PMA.php';
  877. $pma = new PMA;
  878. $pma->userlink = $userlink;
  879. $pma->controllink = $controllink;
  880. /**
  881. * some resetting has to be done when switching servers
  882. */
  883. if (isset($_SESSION['tmp_user_values']['previous_server']) && $_SESSION['tmp_user_values']['previous_server'] != $GLOBALS['server']) {
  884. unset($_SESSION['tmp_user_values']['navi_limit_offset']);
  885. }
  886. $_SESSION['tmp_user_values']['previous_server'] = $GLOBALS['server'];
  887. } // end server connecting
  888. /**
  889. * check if profiling was requested and remember it
  890. * (note: when $cfg['ServerDefault'] = 0, constant is not defined)
  891. */
  892. if (isset($_REQUEST['profiling']) && PMA_profilingSupported()) {
  893. $_SESSION['profiling'] = true;
  894. } elseif (isset($_REQUEST['profiling_form'])) {
  895. // the checkbox was unchecked
  896. unset($_SESSION['profiling']);
  897. }
  898. // library file for blobstreaming
  899. include_once './libraries/blobstreaming.lib.php';
  900. // checks for blobstreaming plugins and databases that support
  901. // blobstreaming (by having the necessary tables for blobstreaming)
  902. checkBLOBStreamingPlugins();
  903. } // end if !defined('PMA_MINIMUM_COMMON')
  904. // load user preferences
  905. $GLOBALS['PMA_Config']->loadUserPreferences();
  906. // remove sensitive values from session
  907. $GLOBALS['PMA_Config']->set('blowfish_secret', '');
  908. $GLOBALS['PMA_Config']->set('Servers', '');
  909. $GLOBALS['PMA_Config']->set('default_server', '');
  910. /* Tell tracker that it can actually work */
  911. PMA_Tracker::enable();
  912. /**
  913. * @global boolean $GLOBALS['is_ajax_request']
  914. * @todo should this be moved to the variables init section above?
  915. *
  916. * Check if the current request is an AJAX request, and set is_ajax_request
  917. * accordingly. Suppress headers, footers and unnecessary output if set to
  918. * true
  919. */
  920. if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
  921. $GLOBALS['is_ajax_request'] = true;
  922. } else {
  923. $GLOBALS['is_ajax_request'] = false;
  924. }
  925. /**
  926. * @global boolean $GLOBALS['grid_edit']
  927. *
  928. * Set to true if this is a request made during an grid edit process. This
  929. * request is made to retrieve the non-truncated/transformed values.
  930. */
  931. if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) {
  932. $GLOBALS['grid_edit'] = true;
  933. } else {
  934. $GLOBALS['grid_edit'] = false;
  935. }
  936. if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
  937. /**
  938. * include subform target page
  939. */
  940. include $__redirect;
  941. exit();
  942. }
  943. ?>