PageRenderTime 67ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/pma/libraries/Config.class.php

https://bitbucket.org/StasPiv/playzone
PHP | 1069 lines | 613 code | 107 blank | 349 comment | 158 complexity | 198d2f432dd337987ffe4a98f4c5a76c MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. *
  6. * @version $Id: Config.class.php 12609 2009-06-30 10:52:07Z lem9 $
  7. * @package phpMyAdmin
  8. */
  9. /**
  10. * Load vendor configuration.
  11. */
  12. require_once('./libraries/vendor_config.php');
  13. /**
  14. * Configuration class
  15. *
  16. * @package phpMyAdmin
  17. */
  18. class PMA_Config
  19. {
  20. /**
  21. * @var string default config source
  22. */
  23. var $default_source = './libraries/config.default.php';
  24. /**
  25. * @var array configuration settings
  26. */
  27. var $settings = array();
  28. /**
  29. * @var string config source
  30. */
  31. var $source = '';
  32. /**
  33. * @var int source modification time
  34. */
  35. var $source_mtime = 0;
  36. var $default_source_mtime = 0;
  37. var $set_mtime = 0;
  38. /**
  39. * @var boolean
  40. */
  41. var $error_config_file = false;
  42. /**
  43. * @var boolean
  44. */
  45. var $error_config_default_file = false;
  46. /**
  47. * @var boolean
  48. */
  49. var $error_pma_uri = false;
  50. /**
  51. * @var array
  52. */
  53. var $default_server = array();
  54. /**
  55. * @var boolean whether init is done or not
  56. * set this to false to force some initial checks
  57. * like checking for required functions
  58. */
  59. var $done = false;
  60. /**
  61. * constructor
  62. *
  63. * @param string source to read config from
  64. */
  65. function __construct($source = null)
  66. {
  67. $this->settings = array();
  68. // functions need to refresh in case of config file changed goes in
  69. // PMA_Config::load()
  70. $this->load($source);
  71. // other settings, independent from config file, comes in
  72. $this->checkSystem();
  73. $this->checkIsHttps();
  74. }
  75. /**
  76. * sets system and application settings
  77. */
  78. function checkSystem()
  79. {
  80. $this->set('PMA_VERSION', '3.2.0.1');
  81. /**
  82. * @deprecated
  83. */
  84. $this->set('PMA_THEME_VERSION', 2);
  85. /**
  86. * @deprecated
  87. */
  88. $this->set('PMA_THEME_GENERATION', 2);
  89. $this->checkPhpVersion();
  90. $this->checkWebServerOs();
  91. $this->checkWebServer();
  92. $this->checkGd2();
  93. $this->checkClient();
  94. $this->checkUpload();
  95. $this->checkUploadSize();
  96. $this->checkOutputCompression();
  97. }
  98. /**
  99. * whether to use gzip output compression or not
  100. */
  101. function checkOutputCompression()
  102. {
  103. // If zlib output compression is set in the php configuration file, no
  104. // output buffering should be run
  105. if (@ini_get('zlib.output_compression')) {
  106. $this->set('OBGzip', false);
  107. }
  108. // disable output-buffering (if set to 'auto') for IE6, else enable it.
  109. if (strtolower($this->get('OBGzip')) == 'auto') {
  110. if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
  111. && $this->get('PMA_USR_BROWSER_VER') >= 6
  112. && $this->get('PMA_USR_BROWSER_VER') < 7) {
  113. $this->set('OBGzip', false);
  114. } else {
  115. $this->set('OBGzip', true);
  116. }
  117. }
  118. }
  119. /**
  120. * Determines platform (OS), browser and version of the user
  121. * Based on a phpBuilder article:
  122. * @see http://www.phpbuilder.net/columns/tim20000821.php
  123. */
  124. function checkClient()
  125. {
  126. if (PMA_getenv('HTTP_USER_AGENT')) {
  127. $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
  128. } elseif (!isset($HTTP_USER_AGENT)) {
  129. $HTTP_USER_AGENT = '';
  130. }
  131. // 1. Platform
  132. if (strstr($HTTP_USER_AGENT, 'Win')) {
  133. $this->set('PMA_USR_OS', 'Win');
  134. } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
  135. $this->set('PMA_USR_OS', 'Mac');
  136. } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
  137. $this->set('PMA_USR_OS', 'Linux');
  138. } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
  139. $this->set('PMA_USR_OS', 'Unix');
  140. } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
  141. $this->set('PMA_USR_OS', 'OS/2');
  142. } else {
  143. $this->set('PMA_USR_OS', 'Other');
  144. }
  145. // 2. browser and version
  146. // (must check everything else before Mozilla)
  147. if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  148. $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
  149. $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
  150. } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  151. $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  152. $this->set('PMA_USR_BROWSER_AGENT', 'IE');
  153. } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  154. $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  155. $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
  156. // Konqueror 2.2.2 says Konqueror/2.2.2
  157. // Konqueror 3.0.3 says Konqueror/3
  158. } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
  159. $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
  160. $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
  161. } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
  162. && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
  163. $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
  164. $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
  165. } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
  166. $this->set('PMA_USR_BROWSER_VER', '1.9');
  167. $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
  168. } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
  169. $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
  170. $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
  171. } else {
  172. $this->set('PMA_USR_BROWSER_VER', 0);
  173. $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
  174. }
  175. }
  176. /**
  177. * Whether GD2 is present
  178. */
  179. function checkGd2()
  180. {
  181. if ($this->get('GD2Available') == 'yes') {
  182. $this->set('PMA_IS_GD2', 1);
  183. } elseif ($this->get('GD2Available') == 'no') {
  184. $this->set('PMA_IS_GD2', 0);
  185. } else {
  186. if (!@function_exists('imagecreatetruecolor')) {
  187. $this->set('PMA_IS_GD2', 0);
  188. } else {
  189. if (@function_exists('gd_info')) {
  190. $gd_nfo = gd_info();
  191. if (strstr($gd_nfo["GD Version"], '2.')) {
  192. $this->set('PMA_IS_GD2', 1);
  193. } else {
  194. $this->set('PMA_IS_GD2', 0);
  195. }
  196. } else {
  197. /* We must do hard way... but almost no chance to execute this */
  198. ob_start();
  199. phpinfo(INFO_MODULES); /* Only modules */
  200. $a = strip_tags(ob_get_contents());
  201. ob_end_clean();
  202. /* Get GD version string from phpinfo output */
  203. if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
  204. if (strstr($v, '2.')) {
  205. $this->set('PMA_IS_GD2', 1);
  206. } else {
  207. $this->set('PMA_IS_GD2', 0);
  208. }
  209. } else {
  210. $this->set('PMA_IS_GD2', 0);
  211. }
  212. }
  213. }
  214. }
  215. }
  216. /**
  217. * Whether the Web server php is running on is IIS
  218. */
  219. function checkWebServer()
  220. {
  221. if (PMA_getenv('SERVER_SOFTWARE')
  222. // some versions return Microsoft-IIS, some Microsoft/IIS
  223. // we could use a preg_match() but it's slower
  224. && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
  225. && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
  226. $this->set('PMA_IS_IIS', 1);
  227. } else {
  228. $this->set('PMA_IS_IIS', 0);
  229. }
  230. }
  231. /**
  232. * Whether the os php is running on is windows or not
  233. */
  234. function checkWebServerOs()
  235. {
  236. // Default to Unix or Equiv
  237. $this->set('PMA_IS_WINDOWS', 0);
  238. // If PHP_OS is defined then continue
  239. if (defined('PHP_OS')) {
  240. if (stristr(PHP_OS, 'win')) {
  241. // Is it some version of Windows
  242. $this->set('PMA_IS_WINDOWS', 1);
  243. } elseif (stristr(PHP_OS, 'OS/2')) {
  244. // Is it OS/2 (No file permissions like Windows)
  245. $this->set('PMA_IS_WINDOWS', 1);
  246. }
  247. }
  248. }
  249. /**
  250. * detects PHP version
  251. */
  252. function checkPhpVersion()
  253. {
  254. $match = array();
  255. if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
  256. phpversion(), $match)) {
  257. $result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
  258. phpversion(), $match);
  259. }
  260. if (isset($match) && ! empty($match[1])) {
  261. if (! isset($match[2])) {
  262. $match[2] = 0;
  263. }
  264. if (! isset($match[3])) {
  265. $match[3] = 0;
  266. }
  267. $this->set('PMA_PHP_INT_VERSION',
  268. (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
  269. } else {
  270. $this->set('PMA_PHP_INT_VERSION', 0);
  271. }
  272. $this->set('PMA_PHP_STR_VERSION', phpversion());
  273. }
  274. /**
  275. * re-init object after loading from session file
  276. * checks config file for changes and relaods if neccessary
  277. */
  278. function __wakeup()
  279. {
  280. if (SKIP_MTIME_CONFIG_CHECK
  281. || ! $this->checkConfigSource()
  282. || $this->source_mtime !== filemtime($this->getSource())
  283. || $this->default_source_mtime !== filemtime($this->default_source)
  284. || $this->error_config_file
  285. || $this->error_config_default_file) {
  286. $this->settings = array();
  287. $this->load();
  288. $this->checkSystem();
  289. }
  290. // check for https needs to be done everytime,
  291. // as https and http uses same session so this info can not be stored
  292. // in session
  293. $this->checkIsHttps();
  294. $this->checkCollationConnection();
  295. $this->checkFontsize();
  296. }
  297. /**
  298. * loads default values from default source
  299. *
  300. * @uses file_exists()
  301. * @uses $this->default_source
  302. * @uses $this->error_config_default_file
  303. * @uses $this->settings
  304. * @return boolean success
  305. */
  306. function loadDefaults()
  307. {
  308. $cfg = array();
  309. if (! file_exists($this->default_source)) {
  310. $this->error_config_default_file = true;
  311. return false;
  312. }
  313. include $this->default_source;
  314. $this->default_source_mtime = filemtime($this->default_source);
  315. $this->default_server = $cfg['Servers'][1];
  316. unset($cfg['Servers']);
  317. $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
  318. $this->error_config_default_file = false;
  319. return true;
  320. }
  321. /**
  322. * loads configuration from $source, usally the config file
  323. * should be called on object creation and from __wakeup if config file
  324. * has changed
  325. *
  326. * @param string $source config file
  327. */
  328. function load($source = null)
  329. {
  330. $this->loadDefaults();
  331. if (null !== $source) {
  332. $this->setSource($source);
  333. }
  334. if (! $this->checkConfigSource()) {
  335. return false;
  336. }
  337. $cfg = array();
  338. /**
  339. * Parses the configuration file
  340. */
  341. $old_error_reporting = error_reporting(0);
  342. if (function_exists('file_get_contents')) {
  343. $eval_result =
  344. eval('?>' . trim(file_get_contents($this->getSource())));
  345. } else {
  346. $eval_result =
  347. eval('?>' . trim(implode("\n", file($this->getSource()))));
  348. }
  349. error_reporting($old_error_reporting);
  350. if ($eval_result === false) {
  351. $this->error_config_file = true;
  352. } else {
  353. $this->error_config_file = false;
  354. $this->source_mtime = filemtime($this->getSource());
  355. }
  356. /**
  357. * Backward compatibility code
  358. */
  359. if (!empty($cfg['DefaultTabTable'])) {
  360. $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
  361. }
  362. if (!empty($cfg['DefaultTabDatabase'])) {
  363. $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
  364. }
  365. $this->checkFontsize();
  366. //$this->checkPmaAbsoluteUri();
  367. $this->settings = PMA_array_merge_recursive($this->settings, $cfg);
  368. $this->checkPermissions();
  369. // Handling of the collation must be done after merging of $cfg
  370. // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
  371. // can have an effect. Note that the presence of collation
  372. // information in a cookie has priority over what is defined
  373. // in the default or user's config files.
  374. /**
  375. * @todo check validity of $_COOKIE['pma_collation_connection']
  376. */
  377. if (! empty($_COOKIE['pma_collation_connection'])) {
  378. $this->set('collation_connection',
  379. strip_tags($_COOKIE['pma_collation_connection']));
  380. } else {
  381. $this->set('collation_connection',
  382. $this->get('DefaultConnectionCollation'));
  383. }
  384. // Now, a collation information could come from REQUEST
  385. // (an example of this: the collation selector in main.php)
  386. // so the following handles the setting of collation_connection
  387. // and later, in common.inc.php, the cookie will be set
  388. // according to this.
  389. $this->checkCollationConnection();
  390. return true;
  391. }
  392. /**
  393. * set source
  394. * @param string $source
  395. */
  396. function setSource($source)
  397. {
  398. $this->source = trim($source);
  399. }
  400. /**
  401. * checks if the config folder still exists and terminates app if true
  402. */
  403. function checkConfigFolder()
  404. {
  405. // Refuse to work while there still might be some world writable dir:
  406. if (is_dir('./config')) {
  407. die('Remove "./config" directory before using phpMyAdmin!');
  408. }
  409. }
  410. /**
  411. * check config source
  412. *
  413. * @return boolean whether source is valid or not
  414. */
  415. function checkConfigSource()
  416. {
  417. if (! $this->getSource()) {
  418. // no configuration file set at all
  419. return false;
  420. }
  421. if (! file_exists($this->getSource())) {
  422. // do not trigger error here
  423. // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
  424. /*
  425. trigger_error(
  426. 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
  427. E_USER_WARNING);
  428. */
  429. $this->source_mtime = 0;
  430. return false;
  431. }
  432. if (! is_readable($this->getSource())) {
  433. $this->source_mtime = 0;
  434. die('Existing configuration file (' . $this->getSource() . ') is not readable.');
  435. }
  436. return true;
  437. }
  438. /**
  439. * verifies the permissions on config file (if asked by configuration)
  440. * (must be called after config.inc.php has been merged)
  441. */
  442. function checkPermissions()
  443. {
  444. // Check for permissions (on platforms that support it):
  445. if ($this->get('CheckConfigurationPermissions')) {
  446. $perms = @fileperms($this->getSource());
  447. if (!($perms === false) && ($perms & 2)) {
  448. // This check is normally done after loading configuration
  449. $this->checkWebServerOs();
  450. if ($this->get('PMA_IS_WINDOWS') == 0) {
  451. $this->source_mtime = 0;
  452. die('Wrong permissions on configuration file, should not be world writable!');
  453. }
  454. }
  455. }
  456. }
  457. /**
  458. * returns specific config setting
  459. * @param string $setting
  460. * @return mixed value
  461. */
  462. function get($setting)
  463. {
  464. if (isset($this->settings[$setting])) {
  465. return $this->settings[$setting];
  466. }
  467. return null;
  468. }
  469. /**
  470. * sets configuration variable
  471. *
  472. * @uses $this->settings
  473. * @param string $setting configuration option
  474. * @param string $value new value for configuration option
  475. */
  476. function set($setting, $value)
  477. {
  478. if (!isset($this->settings[$setting]) || $this->settings[$setting] != $value) {
  479. $this->settings[$setting] = $value;
  480. $this->set_mtime = time();
  481. }
  482. }
  483. /**
  484. * returns source for current config
  485. * @return string config source
  486. */
  487. function getSource()
  488. {
  489. return $this->source;
  490. }
  491. /**
  492. * returns a unique value to force a CSS reload if either the config
  493. * or the theme changes
  494. * must also check the pma_fontsize cookie in case there is no
  495. * config file
  496. * @return int Unix timestamp
  497. */
  498. function getThemeUniqueValue()
  499. {
  500. return intval((null !== $_SESSION['PMA_Config']->get('fontsize') ? $_SESSION['PMA_Config']->get('fontsize') : (isset($_COOKIE['pma_fontsize']) ? $_COOKIE['pma_fontsize'] : 0))) + ($this->source_mtime + $this->default_source_mtime + $_SESSION['PMA_Theme']->mtime_info + $_SESSION['PMA_Theme']->filesize_info) . (isset($_SESSION['userconf']['custom_color']) ? substr($_SESSION['userconf']['custom_color'],1,6) : '');
  501. }
  502. /**
  503. * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
  504. * set properly and, depending on browsers, inserting or updating a
  505. * record might fail
  506. */
  507. function checkPmaAbsoluteUri()
  508. {
  509. // Setup a default value to let the people and lazy sysadmins work anyway,
  510. // they'll get an error if the autodetect code doesn't work
  511. $pma_absolute_uri = $this->get('PmaAbsoluteUri');
  512. $is_https = $this->get('is_https');
  513. if (strlen($pma_absolute_uri) < 5
  514. // needed to catch http/https switch
  515. || ($is_https && substr($pma_absolute_uri, 0, 6) != 'https:')
  516. || (!$is_https && substr($pma_absolute_uri, 0, 5) != 'http:')
  517. ) {
  518. $url = array();
  519. // At first we try to parse REQUEST_URI, it might contain full URL
  520. /**
  521. * REQUEST_URI contains PATH_INFO too, this is not what we want
  522. * script-php/pathinfo/
  523. if (PMA_getenv('REQUEST_URI')) {
  524. $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  525. if ($url === false) {
  526. $url = array('path' => $_SERVER['REQUEST_URI']);
  527. }
  528. }
  529. */
  530. // If we don't have scheme, we didn't have full URL so we need to
  531. // dig deeper
  532. if (empty($url['scheme'])) {
  533. // Scheme
  534. if (PMA_getenv('HTTP_SCHEME')) {
  535. $url['scheme'] = PMA_getenv('HTTP_SCHEME');
  536. } else {
  537. $url['scheme'] =
  538. PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  539. ? 'https'
  540. : 'http';
  541. }
  542. // Host and port
  543. if (PMA_getenv('HTTP_HOST')) {
  544. if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) {
  545. list($url['host'], $url['port']) =
  546. explode(':', PMA_getenv('HTTP_HOST'));
  547. } else {
  548. $url['host'] = PMA_getenv('HTTP_HOST');
  549. }
  550. } elseif (PMA_getenv('SERVER_NAME')) {
  551. $url['host'] = PMA_getenv('SERVER_NAME');
  552. } else {
  553. $this->error_pma_uri = true;
  554. return false;
  555. }
  556. // If we didn't set port yet...
  557. if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
  558. $url['port'] = PMA_getenv('SERVER_PORT');
  559. }
  560. // And finally the path could be already set from REQUEST_URI
  561. if (empty($url['path'])) {
  562. /**
  563. * REQUEST_URI contains PATH_INFO too, this is not what we want
  564. * script-php/pathinfo/
  565. if (PMA_getenv('PATH_INFO')) {
  566. $path = parse_url(PMA_getenv('PATH_INFO'));
  567. } else {
  568. // PHP_SELF in CGI often points to cgi executable, so use it
  569. // as last choice
  570. */
  571. $path = parse_url($GLOBALS['PMA_PHP_SELF']);
  572. //}
  573. $url['path'] = $path['path'];
  574. }
  575. }
  576. // Make url from parts we have
  577. $pma_absolute_uri = $url['scheme'] . '://';
  578. // Was there user information?
  579. if (!empty($url['user'])) {
  580. $pma_absolute_uri .= $url['user'];
  581. if (!empty($url['pass'])) {
  582. $pma_absolute_uri .= ':' . $url['pass'];
  583. }
  584. $pma_absolute_uri .= '@';
  585. }
  586. // Add hostname
  587. $pma_absolute_uri .= $url['host'];
  588. // Add port, if it not the default one
  589. if (! empty($url['port'])
  590. && (($url['scheme'] == 'http' && $url['port'] != 80)
  591. || ($url['scheme'] == 'https' && $url['port'] != 443))) {
  592. $pma_absolute_uri .= ':' . $url['port'];
  593. }
  594. // And finally path, without script name, the 'a' is there not to
  595. // strip our directory, when path is only /pmadir/ without filename.
  596. // Backslashes returned by Windows have to be changed.
  597. // Only replace backslashes by forward slashes if on Windows,
  598. // as the backslash could be valid on a non-Windows system.
  599. if ($this->get('PMA_IS_WINDOWS') == 1) {
  600. $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
  601. } else {
  602. $path = dirname($url['path'] . 'a');
  603. }
  604. // To work correctly within transformations overview:
  605. if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') {
  606. if ($this->get('PMA_IS_WINDOWS') == 1) {
  607. $path = str_replace("\\", "/", dirname(dirname($path)));
  608. } else {
  609. $path = dirname(dirname($path));
  610. }
  611. }
  612. // in vhost situations, there could be already an ending slash
  613. if (substr($path, -1) != '/') {
  614. $path .= '/';
  615. }
  616. $pma_absolute_uri .= $path;
  617. // We used to display a warning if PmaAbsoluteUri wasn't set, but now
  618. // the autodetect code works well enough that we don't display the
  619. // warning at all. The user can still set PmaAbsoluteUri manually.
  620. // See
  621. // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
  622. } else {
  623. // The URI is specified, however users do often specify this
  624. // wrongly, so we try to fix this.
  625. // Adds a trailing slash et the end of the phpMyAdmin uri if it
  626. // does not exist.
  627. if (substr($pma_absolute_uri, -1) != '/') {
  628. $pma_absolute_uri .= '/';
  629. }
  630. // If URI doesn't start with http:// or https://, we will add
  631. // this.
  632. if (substr($pma_absolute_uri, 0, 7) != 'http://'
  633. && substr($pma_absolute_uri, 0, 8) != 'https://') {
  634. $pma_absolute_uri =
  635. (PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  636. ? 'https'
  637. : 'http')
  638. . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//')
  639. . $pma_absolute_uri;
  640. }
  641. }
  642. $this->set('PmaAbsoluteUri', $pma_absolute_uri);
  643. }
  644. /**
  645. * check selected collation_connection
  646. * @todo check validity of $_REQUEST['collation_connection']
  647. */
  648. function checkCollationConnection()
  649. {
  650. if (! empty($_REQUEST['collation_connection'])) {
  651. $this->set('collation_connection',
  652. strip_tags($_REQUEST['collation_connection']));
  653. }
  654. }
  655. /**
  656. * checks for font size configuration, and sets font size as requested by user
  657. *
  658. * @uses $_GET
  659. * @uses $_POST
  660. * @uses $_COOKIE
  661. * @uses preg_match()
  662. * @uses function_exists()
  663. * @uses PMA_Config::set()
  664. * @uses PMA_Config::get()
  665. * @uses PMA_setCookie()
  666. */
  667. function checkFontsize()
  668. {
  669. $new_fontsize = '';
  670. if (isset($_GET['fontsize'])) {
  671. $new_fontsize = $_GET['fontsize'];
  672. } elseif (isset($_POST['fontsize'])) {
  673. $new_fontsize = $_POST['fontsize'];
  674. } elseif (isset($_COOKIE['pma_fontsize'])) {
  675. $new_fontsize = $_COOKIE['pma_fontsize'];
  676. }
  677. if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
  678. $this->set('fontsize', $new_fontsize);
  679. } elseif (! $this->get('fontsize')) {
  680. // 80% would correspond to the default browser font size
  681. // of 16, but use 82% to help read the monoface font
  682. $this->set('fontsize', '82%');
  683. }
  684. if (function_exists('PMA_setCookie')) {
  685. PMA_setCookie('pma_fontsize', $this->get('fontsize'), '82%');
  686. }
  687. }
  688. /**
  689. * checks if upload is enabled
  690. *
  691. */
  692. function checkUpload()
  693. {
  694. if (ini_get('file_uploads')) {
  695. $this->set('enable_upload', true);
  696. // if set "php_admin_value file_uploads Off" in httpd.conf
  697. // ini_get() also returns the string "Off" in this case:
  698. if ('off' == strtolower(ini_get('file_uploads'))) {
  699. $this->set('enable_upload', false);
  700. }
  701. } else {
  702. $this->set('enable_upload', false);
  703. }
  704. }
  705. /**
  706. * Maximum upload size as limited by PHP
  707. * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
  708. *
  709. * this section generates $max_upload_size in bytes
  710. */
  711. function checkUploadSize()
  712. {
  713. if (! $filesize = ini_get('upload_max_filesize')) {
  714. $filesize = "5M";
  715. }
  716. if ($postsize = ini_get('post_max_size')) {
  717. $this->set('max_upload_size',
  718. min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
  719. } else {
  720. $this->set('max_upload_size', PMA_get_real_size($filesize));
  721. }
  722. }
  723. /**
  724. * check for https
  725. */
  726. function checkIsHttps()
  727. {
  728. $this->set('is_https', PMA_Config::isHttps());
  729. }
  730. /**
  731. * @static
  732. */
  733. static public function isHttps()
  734. {
  735. $is_https = false;
  736. $url = array();
  737. // At first we try to parse REQUEST_URI, it might contain full URL,
  738. if (PMA_getenv('REQUEST_URI')) {
  739. $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  740. if($url === false) {
  741. $url = array();
  742. }
  743. }
  744. // If we don't have scheme, we didn't have full URL so we need to
  745. // dig deeper
  746. if (empty($url['scheme'])) {
  747. // Scheme
  748. if (PMA_getenv('HTTP_SCHEME')) {
  749. $url['scheme'] = PMA_getenv('HTTP_SCHEME');
  750. } else {
  751. $url['scheme'] =
  752. PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
  753. ? 'https'
  754. : 'http';
  755. }
  756. }
  757. if (isset($url['scheme'])
  758. && $url['scheme'] == 'https') {
  759. $is_https = true;
  760. } else {
  761. $is_https = false;
  762. }
  763. return $is_https;
  764. }
  765. /**
  766. * detect correct cookie path
  767. */
  768. function checkCookiePath()
  769. {
  770. $this->set('cookie_path', PMA_Config::getCookiePath());
  771. }
  772. /**
  773. * @static
  774. */
  775. static public function getCookiePath()
  776. {
  777. static $cookie_path = null;
  778. if (null !== $cookie_path) {
  779. return $cookie_path;
  780. }
  781. $url = '';
  782. /**
  783. * REQUEST_URI contains PATH_INFO too, this is not what we want
  784. * script-php/pathinfo/
  785. if (PMA_getenv('REQUEST_URI')) {
  786. $url = PMA_getenv('REQUEST_URI');
  787. }
  788. */
  789. // If we don't have path
  790. if (empty($url)) {
  791. if ($GLOBALS['PMA_PHP_SELF']) {
  792. // PHP_SELF in CGI often points to cgi executable, so use it
  793. // as last choice
  794. $url = $GLOBALS['PMA_PHP_SELF'];
  795. // on IIS with PHP-CGI:
  796. } elseif (PMA_getenv('SCRIPT_NAME')) {
  797. $url = PMA_getenv('SCRIPT_NAME');
  798. }
  799. }
  800. /**
  801. * REQUEST_URI contains PATH_INFO too, this is not what we want
  802. * script-php/pathinfo/
  803. $parsed_url = @parse_url($_SERVER['REQUEST_URI']); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
  804. if ($parsed_url === false) {
  805. */
  806. $parsed_url = array('path' => $url);
  807. //}
  808. $cookie_path = substr($parsed_url['path'], 0, strrpos($parsed_url['path'], '/')) . '/';
  809. return $cookie_path;
  810. }
  811. /**
  812. * enables backward compatibility
  813. */
  814. function enableBc()
  815. {
  816. $GLOBALS['cfg'] = $this->settings;
  817. $GLOBALS['default_server'] = $this->default_server;
  818. unset($this->default_server);
  819. $GLOBALS['collation_connection'] = $this->get('collation_connection');
  820. $GLOBALS['is_upload'] = $this->get('enable_upload');
  821. $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
  822. $GLOBALS['cookie_path'] = $this->get('cookie_path');
  823. $GLOBALS['is_https'] = $this->get('is_https');
  824. $defines = array(
  825. 'PMA_VERSION',
  826. 'PMA_THEME_VERSION',
  827. 'PMA_THEME_GENERATION',
  828. 'PMA_PHP_STR_VERSION',
  829. 'PMA_PHP_INT_VERSION',
  830. 'PMA_IS_WINDOWS',
  831. 'PMA_IS_IIS',
  832. 'PMA_IS_GD2',
  833. 'PMA_USR_OS',
  834. 'PMA_USR_BROWSER_VER',
  835. 'PMA_USR_BROWSER_AGENT'
  836. );
  837. foreach ($defines as $define) {
  838. if (! defined($define)) {
  839. define($define, $this->get($define));
  840. }
  841. }
  842. }
  843. /**
  844. * @todo finish
  845. */
  846. function save() {}
  847. /**
  848. * returns options for font size selection
  849. *
  850. * @uses preg_replace()
  851. * @uses ksort()
  852. * @static
  853. * @param string $current_size current selected font size with unit
  854. * @return array selectable font sizes
  855. */
  856. static protected function _getFontsizeOptions($current_size = '82%')
  857. {
  858. $unit = preg_replace('/[0-9.]*/', '', $current_size);
  859. $value = preg_replace('/[^0-9.]*/', '', $current_size);
  860. $factors = array();
  861. $options = array();
  862. $options["$value"] = $value . $unit;
  863. if ($unit === '%') {
  864. $factors[] = 1;
  865. $factors[] = 5;
  866. $factors[] = 10;
  867. } elseif ($unit === 'em') {
  868. $factors[] = 0.05;
  869. $factors[] = 0.2;
  870. $factors[] = 1;
  871. } elseif ($unit === 'pt') {
  872. $factors[] = 0.5;
  873. $factors[] = 2;
  874. } elseif ($unit === 'px') {
  875. $factors[] = 1;
  876. $factors[] = 5;
  877. $factors[] = 10;
  878. } else {
  879. //unknown font size unit
  880. $factors[] = 0.05;
  881. $factors[] = 0.2;
  882. $factors[] = 1;
  883. $factors[] = 5;
  884. $factors[] = 10;
  885. }
  886. foreach ($factors as $key => $factor) {
  887. $option_inc = $value + $factor;
  888. $option_dec = $value - $factor;
  889. while (count($options) < 21) {
  890. $options["$option_inc"] = $option_inc . $unit;
  891. if ($option_dec > $factors[0]) {
  892. $options["$option_dec"] = $option_dec . $unit;
  893. }
  894. $option_inc += $factor;
  895. $option_dec -= $factor;
  896. if (isset($factors[$key + 1])
  897. && $option_inc >= $value + $factors[$key + 1]) {
  898. break;
  899. }
  900. }
  901. }
  902. ksort($options);
  903. return $options;
  904. }
  905. /**
  906. * returns html selectbox for font sizes
  907. *
  908. * @uses $_SESSION['PMA_Config']
  909. * @uses PMA_Config::get()
  910. * @uses PMA_Config::_getFontsizeOptions()
  911. * @uses $GLOBALS['strFontSize']
  912. * @static
  913. * @param string $current_size currently slected font size with unit
  914. * @return string html selectbox
  915. */
  916. static protected function _getFontsizeSelection()
  917. {
  918. $current_size = $_SESSION['PMA_Config']->get('fontsize');
  919. // for the case when there is no config file (this is supported)
  920. if (empty($current_size)) {
  921. if (isset($_COOKIE['pma_fontsize'])) {
  922. $current_size = $_COOKIE['pma_fontsize'];
  923. } else {
  924. $current_size = '82%';
  925. }
  926. }
  927. $options = PMA_Config::_getFontsizeOptions($current_size);
  928. $return = '<label for="select_fontsize">' . $GLOBALS['strFontSize'] . ':</label>' . "\n";
  929. $return .= '<select name="fontsize" id="select_fontsize" onchange="this.form.submit();">' . "\n";
  930. foreach ($options as $option) {
  931. $return .= '<option value="' . $option . '"';
  932. if ($option == $current_size) {
  933. $return .= ' selected="selected"';
  934. }
  935. $return .= '>' . $option . '</option>' . "\n";
  936. }
  937. $return .= '</select>';
  938. return $return;
  939. }
  940. /**
  941. * return complete font size selection form
  942. *
  943. * @uses PMA_generate_common_hidden_inputs()
  944. * @uses PMA_Config::_getFontsizeSelection()
  945. * @uses $GLOBALS['strGo']
  946. * @static
  947. * @param string $current_size currently slected font size with unit
  948. * @return string html selectbox
  949. */
  950. static public function getFontsizeForm()
  951. {
  952. return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
  953. . ' method="post" action="index.php" target="_parent">' . "\n"
  954. . PMA_generate_common_hidden_inputs() . "\n"
  955. . PMA_Config::_getFontsizeSelection() . "\n"
  956. . '<noscript>' . "\n"
  957. . '<input type="submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
  958. . '</noscript>' . "\n"
  959. . '</form>';
  960. }
  961. }
  962. ?>