PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://github.com/gauravmittal1995/phpmyadmin
PHP | 665 lines | 498 code | 56 blank | 111 comment | 103 complexity | 7a51bc27b35e36df889ac8979c23c070 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Main loader script
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Gets some core libraries and displays a top message if required
  10. */
  11. require_once 'libraries/common.inc.php';
  12. /**
  13. * display Git revision if requested
  14. */
  15. require_once 'libraries/display_git_revision.lib.php';
  16. /**
  17. * pass variables to child pages
  18. */
  19. $drops = array(
  20. 'lang',
  21. 'server',
  22. 'collation_connection',
  23. 'db',
  24. 'table'
  25. );
  26. foreach ($drops as $each_drop) {
  27. if (array_key_exists($each_drop, $_GET)) {
  28. unset($_GET[$each_drop]);
  29. }
  30. }
  31. unset($drops, $each_drop);
  32. /*
  33. * Black list of all scripts to which front-end must submit data.
  34. * Such scripts must not be loaded on home page.
  35. *
  36. */
  37. $target_blacklist = array (
  38. 'import.php', 'export.php'
  39. );
  40. // If we have a valid target, let's load that script instead
  41. if (! empty($_REQUEST['target'])
  42. && is_string($_REQUEST['target'])
  43. && ! preg_match('/^index/', $_REQUEST['target'])
  44. && ! in_array($_REQUEST['target'], $target_blacklist)
  45. && in_array($_REQUEST['target'], $goto_whitelist)
  46. ) {
  47. include $_REQUEST['target'];
  48. exit;
  49. }
  50. /**
  51. * Check if it is an ajax request to reload the recent tables list.
  52. */
  53. require_once 'libraries/RecentFavoriteTable.class.php';
  54. if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['recent_table'])) {
  55. $response = PMA_Response::getInstance();
  56. $response->addJSON(
  57. 'list',
  58. PMA_RecentFavoriteTable::getInstance('recent')->getHtmlList()
  59. );
  60. exit;
  61. }
  62. if ($GLOBALS['PMA_Config']->isGitRevision()) {
  63. if (isset($_REQUEST['git_revision']) && $GLOBALS['is_ajax_request'] == true) {
  64. PMA_printGitRevision();
  65. exit;
  66. }
  67. echo '<div id="is_git_revision"></div>';
  68. }
  69. // Handles some variables that may have been sent by the calling script
  70. $GLOBALS['db'] = '';
  71. $GLOBALS['table'] = '';
  72. $show_query = '1';
  73. // Any message to display?
  74. if (! empty($message)) {
  75. echo PMA_Util::getMessage($message);
  76. unset($message);
  77. }
  78. $common_url_query = PMA_URL_getCommon('', '');
  79. // when $server > 0, a server has been chosen so we can display
  80. // all MySQL-related information
  81. if ($server > 0) {
  82. include 'libraries/server_common.inc.php';
  83. include 'libraries/StorageEngine.class.php';
  84. // Use the verbose name of the server instead of the hostname
  85. // if a value is set
  86. $server_info = '';
  87. if (! empty($cfg['Server']['verbose'])) {
  88. $server_info .= htmlspecialchars($cfg['Server']['verbose']);
  89. if ($GLOBALS['cfg']['ShowServerInfo']) {
  90. $server_info .= ' (';
  91. }
  92. }
  93. if ($GLOBALS['cfg']['ShowServerInfo'] || empty($cfg['Server']['verbose'])) {
  94. $server_info .= $GLOBALS['dbi']->getHostInfo();
  95. }
  96. if (! empty($cfg['Server']['verbose']) && $GLOBALS['cfg']['ShowServerInfo']) {
  97. $server_info .= ')';
  98. }
  99. $mysql_cur_user_and_host = $GLOBALS['dbi']->fetchValue('SELECT USER();');
  100. // should we add the port info here?
  101. $short_server_info = (!empty($GLOBALS['cfg']['Server']['verbose'])
  102. ? $GLOBALS['cfg']['Server']['verbose']
  103. : $GLOBALS['cfg']['Server']['host']);
  104. }
  105. echo '<div id="maincontainer">' . "\n";
  106. // Anchor for favorite tables synchronization.
  107. echo PMA_RecentFavoriteTable::getInstance('favorite')->getHtmlSyncFavoriteTables();
  108. echo '<div id="main_pane_left">';
  109. if ($server > 0 || count($cfg['Servers']) > 1
  110. ) {
  111. if ($cfg['DBG']['demo']) {
  112. echo '<div class="group">';
  113. echo '<h2>' . __('phpMyAdmin Demo Server') . '</h2>';
  114. echo '<p style="margin: 0.5em 1em 0.5em 1em">';
  115. printf(
  116. __(
  117. 'You are using the demo server. You can do anything here, but '
  118. . 'please do not change root, debian-sys-maint and pma users. '
  119. . 'More information is available at %s.'
  120. ),
  121. '<a href="http://demo.phpmyadmin.net/">demo.phpmyadmin.net</a>'
  122. );
  123. echo '</p>';
  124. echo '</div>';
  125. }
  126. echo '<div class="group">';
  127. echo '<h2>' . __('General Settings') . '</h2>';
  128. echo '<ul>';
  129. /**
  130. * Displays the MySQL servers choice form
  131. */
  132. if ($cfg['ServerDefault'] == 0
  133. || (! $cfg['NavigationDisplayServers']
  134. && (count($cfg['Servers']) > 1
  135. || ($server == 0 && count($cfg['Servers']) == 1)))
  136. ) {
  137. echo '<li id="li_select_server" class="no_bullets" >';
  138. include_once 'libraries/select_server.lib.php';
  139. echo PMA_Util::getImage('s_host.png') . " " . PMA_selectServer(true, true);
  140. echo '</li>';
  141. }
  142. /**
  143. * Displays the mysql server related links
  144. */
  145. if ($server > 0 && ! PMA_DRIZZLE) {
  146. include_once 'libraries/check_user_privileges.lib.php';
  147. // Logout for advanced authentication
  148. if ($cfg['Server']['auth_type'] != 'config') {
  149. if ($cfg['ShowChgPassword']) {
  150. $conditional_class = 'ajax';
  151. PMA_printListItem(
  152. PMA_Util::getImage('s_passwd.png') . " " . __('Change password'),
  153. 'li_change_password',
  154. 'user_password.php?' . $common_url_query,
  155. null,
  156. null,
  157. 'change_password_anchor',
  158. "no_bullets",
  159. $conditional_class
  160. );
  161. }
  162. } // end if
  163. echo ' <li id="li_select_mysql_collation" class="no_bullets" >';
  164. echo ' <form method="post" action="index.php">' . "\n"
  165. . PMA_URL_getHiddenInputs(null, null, 4, 'collation_connection')
  166. . ' <label for="select_collation_connection">' . "\n"
  167. . ' ' . PMA_Util::getImage('s_asci.png') . " "
  168. . __('Server connection collation') . "\n"
  169. // put the doc link in the form so that it appears on the same line
  170. . PMA_Util::showMySQLDocu('Charset-connection')
  171. . ': ' . "\n"
  172. . ' </label>' . "\n"
  173. . PMA_generateCharsetDropdownBox(
  174. PMA_CSDROPDOWN_COLLATION,
  175. 'collation_connection',
  176. 'select_collation_connection',
  177. $collation_connection,
  178. true,
  179. 4,
  180. true
  181. )
  182. . ' </form>' . "\n"
  183. . ' </li>' . "\n";
  184. } // end of if ($server > 0 && !PMA_DRIZZLE)
  185. echo '</ul>';
  186. echo '</div>';
  187. }
  188. echo '<div class="group">';
  189. echo '<h2>' . __('Appearance Settings') . '</h2>';
  190. echo ' <ul>';
  191. // Displays language selection combo
  192. if (empty($cfg['Lang']) && count($GLOBALS['available_languages']) > 1) {
  193. echo '<li id="li_select_lang" class="no_bullets">';
  194. include_once 'libraries/display_select_lang.lib.php';
  195. echo PMA_Util::getImage('s_lang.png') . " " . PMA_getLanguageSelectorHtml();
  196. echo '</li>';
  197. }
  198. // ThemeManager if available
  199. if ($GLOBALS['cfg']['ThemeManager']) {
  200. echo '<li id="li_select_theme" class="no_bullets">';
  201. echo PMA_Util::getImage('s_theme.png') . " "
  202. . $_SESSION['PMA_Theme_Manager']->getHtmlSelectBox();
  203. echo '</li>';
  204. }
  205. echo '<li id="li_select_fontsize">';
  206. echo PMA_Config::getFontsizeForm();
  207. echo '</li>';
  208. echo '</ul>';
  209. // User preferences
  210. if ($server > 0) {
  211. echo '<ul>';
  212. PMA_printListItem(
  213. PMA_Util::getImage('b_tblops.png') . " " . __('More settings'),
  214. 'li_user_preferences',
  215. 'prefs_manage.php?' . $common_url_query,
  216. null,
  217. null,
  218. null,
  219. "no_bullets"
  220. );
  221. echo '</ul>';
  222. }
  223. echo '</div>';
  224. echo '</div>';
  225. echo '<div id="main_pane_right">';
  226. if ($server > 0 && $GLOBALS['cfg']['ShowServerInfo']) {
  227. echo '<div class="group">';
  228. echo '<h2>' . __('Database server') . '</h2>';
  229. echo '<ul>' . "\n";
  230. PMA_printListItem(
  231. __('Server:') . ' ' . $server_info,
  232. 'li_server_info'
  233. );
  234. PMA_printListItem(
  235. __('Server type:') . ' ' . PMA_Util::getServerType(),
  236. 'li_server_type'
  237. );
  238. PMA_printListItem(
  239. __('Server version:')
  240. . ' '
  241. . PMA_MYSQL_STR_VERSION . ' - ' . PMA_MYSQL_VERSION_COMMENT,
  242. 'li_server_version'
  243. );
  244. PMA_printListItem(
  245. __('Protocol version:') . ' ' . $GLOBALS['dbi']->getProtoInfo(),
  246. 'li_mysql_proto'
  247. );
  248. PMA_printListItem(
  249. __('User:') . ' ' . htmlspecialchars($mysql_cur_user_and_host),
  250. 'li_user_info'
  251. );
  252. echo ' <li id="li_select_mysql_charset">';
  253. echo ' ' . __('Server charset:') . ' '
  254. . ' <span lang="en" dir="ltr">';
  255. if (! PMA_DRIZZLE) {
  256. echo ' '
  257. . $mysql_charsets_descriptions[$mysql_charset_map['utf-8']];
  258. }
  259. echo ' (' . $mysql_charset_map['utf-8'] . ')'
  260. . ' </span>'
  261. . ' </li>'
  262. . ' </ul>'
  263. . ' </div>';
  264. }
  265. if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) {
  266. echo '<div class="group">';
  267. echo '<h2>' . __('Web server') . '</h2>';
  268. echo '<ul>';
  269. if ($GLOBALS['cfg']['ShowServerInfo']) {
  270. PMA_printListItem($_SERVER['SERVER_SOFTWARE'], 'li_web_server_software');
  271. if ($server > 0) {
  272. $client_version_str = $GLOBALS['dbi']->getClientInfo();
  273. if (preg_match('#\d+\.\d+\.\d+#', $client_version_str)) {
  274. $client_version_str = 'libmysql - ' . $client_version_str;
  275. }
  276. PMA_printListItem(
  277. __('Database client version:') . ' ' . $client_version_str,
  278. 'li_mysql_client_version'
  279. );
  280. $php_ext_string = __('PHP extension:') . ' ';
  281. if (PMA_DatabaseInterface::checkDbExtension('mysqli')) {
  282. $extension = 'mysqli';
  283. } else {
  284. $extension = 'mysql';
  285. }
  286. $php_ext_string .= $extension . ' '
  287. . PMA_Util::showPHPDocu('book.' . $extension . '.php');
  288. PMA_printListItem(
  289. $php_ext_string,
  290. 'li_used_php_extension'
  291. );
  292. }
  293. }
  294. if ($cfg['ShowPhpInfo']) {
  295. PMA_printListItem(
  296. __('Show PHP information'),
  297. 'li_phpinfo',
  298. 'phpinfo.php?' . $common_url_query,
  299. null,
  300. '_blank'
  301. );
  302. }
  303. echo ' </ul>';
  304. echo ' </div>';
  305. }
  306. echo '<div class="group pmagroup">';
  307. echo '<h2>phpMyAdmin</h2>';
  308. echo '<ul>';
  309. $class = null;
  310. // We rely on CSP to allow access to http://www.phpmyadmin.net, but IE lacks
  311. // support here and does not allow request to http once using https.
  312. if ($GLOBALS['cfg']['VersionCheck']
  313. && (! $GLOBALS['PMA_Config']->get('is_https') || PMA_USR_BROWSER_AGENT != 'IE')
  314. ) {
  315. $class = 'jsversioncheck';
  316. }
  317. PMA_printListItem(
  318. __('Version information:') . ' ' . PMA_VERSION,
  319. 'li_pma_version',
  320. null,
  321. null,
  322. null,
  323. null,
  324. $class
  325. );
  326. PMA_printListItem(
  327. __('Documentation'),
  328. 'li_pma_docs',
  329. PMA_Util::getDocuLink('index'),
  330. null,
  331. '_blank'
  332. );
  333. PMA_printListItem(
  334. __('Wiki'),
  335. 'li_pma_wiki',
  336. PMA_linkURL('http://wiki.phpmyadmin.net/'),
  337. null,
  338. '_blank'
  339. );
  340. // does not work if no target specified, don't know why
  341. PMA_printListItem(
  342. __('Official Homepage'),
  343. 'li_pma_homepage',
  344. PMA_linkURL('http://www.phpMyAdmin.net/'),
  345. null,
  346. '_blank'
  347. );
  348. PMA_printListItem(
  349. __('Contribute'),
  350. 'li_pma_contribute',
  351. PMA_linkURL('http://www.phpmyadmin.net/home_page/improve.php'),
  352. null,
  353. '_blank'
  354. );
  355. PMA_printListItem(
  356. __('Get support'),
  357. 'li_pma_support',
  358. PMA_linkURL('http://www.phpmyadmin.net/home_page/support.php'),
  359. null,
  360. '_blank'
  361. );
  362. PMA_printListItem(
  363. __('List of changes'),
  364. 'li_pma_changes',
  365. PMA_linkURL('changelog.php'),
  366. null,
  367. '_blank'
  368. );
  369. echo ' </ul>';
  370. echo ' </div>';
  371. echo '</div>';
  372. echo '</div>';
  373. /**
  374. * Warning if using the default MySQL privileged account
  375. */
  376. if ($server != 0
  377. && $cfg['Server']['user'] == 'root'
  378. && $cfg['Server']['password'] == ''
  379. ) {
  380. trigger_error(
  381. __(
  382. 'Your configuration file contains settings (root with no password)'
  383. . ' that correspond to the default MySQL privileged account.'
  384. . ' Your MySQL server is running with this default, is open to'
  385. . ' intrusion, and you really should fix this security hole by'
  386. . ' setting a password for user \'root\'.'
  387. ),
  388. E_USER_WARNING
  389. );
  390. }
  391. /**
  392. * As we try to handle charsets by ourself, mbstring overloads just
  393. * break it, see bug 1063821.
  394. */
  395. if (@extension_loaded('mbstring') && @ini_get('mbstring.func_overload') > 1) {
  396. trigger_error(
  397. __(
  398. 'You have enabled mbstring.func_overload in your PHP '
  399. . 'configuration. This option is incompatible with phpMyAdmin '
  400. . 'and might cause some data to be corrupted!'
  401. ),
  402. E_USER_WARNING
  403. );
  404. }
  405. /**
  406. * mbstring is used for handling multibyte inside parser, so it is good
  407. * to tell user something might be broken without it, see bug #1063149.
  408. */
  409. if (! @extension_loaded('mbstring')) {
  410. trigger_error(
  411. __(
  412. 'The mbstring PHP extension was not found and you seem to be using'
  413. . ' a multibyte charset. Without the mbstring extension phpMyAdmin'
  414. . ' is unable to split strings correctly and it may result in'
  415. . ' unexpected results.'
  416. ),
  417. E_USER_WARNING
  418. );
  419. }
  420. /**
  421. * Check whether session.gc_maxlifetime limits session validity.
  422. */
  423. $gc_time = (int)@ini_get('session.gc_maxlifetime');
  424. if ($gc_time < $GLOBALS['cfg']['LoginCookieValidity'] ) {
  425. trigger_error(
  426. __('Your PHP parameter [a@http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime@_blank]session.gc_maxlifetime[/a] is lower than cookie validity configured in phpMyAdmin, because of this, your login will expire sooner than configured in phpMyAdmin.'),
  427. E_USER_WARNING
  428. );
  429. }
  430. /**
  431. * Check whether LoginCookieValidity is limited by LoginCookieStore.
  432. */
  433. if ($GLOBALS['cfg']['LoginCookieStore'] != 0
  434. && $GLOBALS['cfg']['LoginCookieStore'] < $GLOBALS['cfg']['LoginCookieValidity']
  435. ) {
  436. trigger_error(
  437. __('Login cookie store is lower than cookie validity configured in phpMyAdmin, because of this, your login will expire sooner than configured in phpMyAdmin.'),
  438. E_USER_WARNING
  439. );
  440. }
  441. /**
  442. * Check if user does not have defined blowfish secret and it is being used.
  443. */
  444. if (! empty($_SESSION['auto_blowfish_secret'])
  445. && empty($GLOBALS['cfg']['blowfish_secret'])
  446. ) {
  447. trigger_error(
  448. __('The configuration file now needs a secret passphrase (blowfish_secret).'),
  449. E_USER_WARNING
  450. );
  451. }
  452. /**
  453. * Check for existence of config directory which should not exist in
  454. * production environment.
  455. */
  456. if (file_exists('config')) {
  457. trigger_error(
  458. __('Directory [code]config[/code], which is used by the setup script, still exists in your phpMyAdmin directory. It is strongly recommended to remove it once phpMyAdmin has been configured. Otherwise the security of your server may be compromised by unauthorized people downloading your configuration.'),
  459. E_USER_WARNING
  460. );
  461. }
  462. if ($server > 0) {
  463. $cfgRelation = PMA_getRelationsParam();
  464. if (! $cfgRelation['allworks']
  465. && $cfg['PmaNoRelation_DisableWarning'] == false
  466. ) {
  467. $msg = PMA_Message::notice(__('The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. To find out why click %shere%s.'));
  468. $msg->addParam(
  469. '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?'
  470. . $common_url_query . '">',
  471. false
  472. );
  473. $msg->addParam('</a>', false);
  474. /* Show error if user has configured something, notice elsewhere */
  475. if (!empty($cfg['Servers'][$server]['pmadb'])) {
  476. $msg->isError(true);
  477. }
  478. $msg->display();
  479. } // end if
  480. }
  481. /**
  482. * Warning about different MySQL library and server version
  483. * (a difference on the third digit does not count).
  484. * If someday there is a constant that we can check about mysqlnd,
  485. * we can use it instead of strpos().
  486. * If no default server is set, $GLOBALS['dbi'] is not defined yet.
  487. * Drizzle can speak MySQL protocol, so don't warn about version mismatch for
  488. * Drizzle servers.
  489. */
  490. if (isset($GLOBALS['dbi'])
  491. && !PMA_DRIZZLE
  492. && $cfg['ServerLibraryDifference_DisableWarning'] == false
  493. ) {
  494. $_client_info = $GLOBALS['dbi']->getClientInfo();
  495. if ($server > 0
  496. && strpos($_client_info, 'mysqlnd') === false
  497. && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3)
  498. ) {
  499. trigger_error(
  500. PMA_sanitize(
  501. sprintf(
  502. __('Your PHP MySQL library version %s differs from your MySQL server version %s. This may cause unpredictable behavior.'),
  503. $_client_info,
  504. substr(
  505. PMA_MYSQL_STR_VERSION,
  506. 0,
  507. strpos(PMA_MYSQL_STR_VERSION . '-', '-')
  508. )
  509. )
  510. ),
  511. E_USER_NOTICE
  512. );
  513. }
  514. unset($_client_info);
  515. }
  516. /**
  517. * Warning about Suhosin only if its simulation mode is not enabled
  518. */
  519. if ($cfg['SuhosinDisableWarning'] == false
  520. && @ini_get('suhosin.request.max_value_length')
  521. && @ini_get('suhosin.simulation') == '0'
  522. ) {
  523. trigger_error(
  524. sprintf(
  525. __('Server running with Suhosin. Please refer to %sdocumentation%s for possible issues.'),
  526. '[doc@faq1-38]',
  527. '[/doc]'
  528. ),
  529. E_USER_WARNING
  530. );
  531. }
  532. /**
  533. * Warning about mcrypt.
  534. */
  535. if (! function_exists('mcrypt_encrypt')
  536. && ! $GLOBALS['cfg']['McryptDisableWarning']
  537. ) {
  538. PMA_warnMissingExtension('mcrypt');
  539. }
  540. /**
  541. * Warning about incomplete translations.
  542. *
  543. * The data file is created while creating release by ./scripts/remove-incomplete-mo
  544. */
  545. if (file_exists('libraries/language_stats.inc.php')) {
  546. include 'libraries/language_stats.inc.php';
  547. /*
  548. * This message is intentionally not translated, because we're
  549. * handling incomplete translations here and focus on english
  550. * speaking users.
  551. */
  552. if (isset($GLOBALS['language_stats'][$lang])
  553. && $GLOBALS['language_stats'][$lang] < $cfg['TranslationWarningThreshold']
  554. ) {
  555. trigger_error(
  556. 'You are using an incomplete translation, please help to make it '
  557. . 'better by [a@http://www.phpmyadmin.net/home_page/improve.php'
  558. . '#translate@_blank]contributing[/a].',
  559. E_USER_NOTICE
  560. );
  561. }
  562. }
  563. /**
  564. * prints list item for main page
  565. *
  566. * @param string $name displayed text
  567. * @param string $listId id, used for css styles
  568. * @param string $url make item as link with $url as target
  569. * @param string $mysql_help_page display a link to MySQL's manual
  570. * @param string $target special target for $url
  571. * @param string $a_id id for the anchor,
  572. * used for jQuery to hook in functions
  573. * @param string $class class for the li element
  574. * @param string $a_class class for the anchor element
  575. *
  576. * @return void
  577. */
  578. function PMA_printListItem($name, $listId = null, $url = null,
  579. $mysql_help_page = null, $target = null, $a_id = null, $class = null,
  580. $a_class = null
  581. ) {
  582. echo '<li id="' . $listId . '"';
  583. if (null !== $class) {
  584. echo ' class="' . $class . '"';
  585. }
  586. echo '>';
  587. if (null !== $url) {
  588. echo '<a href="' . $url . '"';
  589. if (null !== $target) {
  590. echo ' target="' . $target . '"';
  591. }
  592. if (null != $a_id) {
  593. echo ' id="' . $a_id . '"';
  594. }
  595. if (null != $a_class) {
  596. echo ' class="' . $a_class . '"';
  597. }
  598. echo '>';
  599. }
  600. echo $name;
  601. if (null !== $url) {
  602. echo '</a>' . "\n";
  603. }
  604. if (null !== $mysql_help_page) {
  605. echo PMA_Util::showMySQLDocu($mysql_help_page);
  606. }
  607. echo '</li>';
  608. }
  609. ?>