2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Configuration handling.
10 * Load vendor configuration.
12 require('./libraries/vendor_config.php');
22 * @var string default config source
24 var $default_source = './libraries/config.default.php';
27 * @var array default configuration settings
29 var $default = array();
32 * @var array configuration settings
34 var $settings = array();
37 * @var string config source
42 * @var int source modification time
44 var $source_mtime = 0;
45 var $default_source_mtime = 0;
51 var $error_config_file = false;
56 var $error_config_default_file = false;
61 var $error_pma_uri = false;
66 var $default_server = array();
69 * @var boolean whether init is done or not
70 * set this to false to force some initial checks
71 * like checking for required functions
78 * @param string source to read config from
80 function __construct($source = null)
82 $this->settings
= array();
84 // functions need to refresh in case of config file changed goes in
88 // other settings, independent from config file, comes in
91 $this->checkIsHttps();
95 * sets system and application settings
97 function checkSystem()
99 $this->set('PMA_VERSION', '3.5.0-dev');
103 $this->set('PMA_THEME_VERSION', 2);
107 $this->set('PMA_THEME_GENERATION', 2);
109 $this->checkPhpVersion();
110 $this->checkWebServerOs();
111 $this->checkWebServer();
113 $this->checkClient();
114 $this->checkUpload();
115 $this->checkUploadSize();
116 $this->checkOutputCompression();
120 * whether to use gzip output compression or not
122 function checkOutputCompression()
124 // If zlib output compression is set in the php configuration file, no
125 // output buffering should be run
126 if (@ini_get
('zlib.output_compression')) {
127 $this->set('OBGzip', false);
130 // disable output-buffering (if set to 'auto') for IE6, else enable it.
131 if (strtolower($this->get('OBGzip')) == 'auto') {
132 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
133 && $this->get('PMA_USR_BROWSER_VER') >= 6
134 && $this->get('PMA_USR_BROWSER_VER') < 7) {
135 $this->set('OBGzip', false);
137 $this->set('OBGzip', true);
143 * Determines platform (OS), browser and version of the user
144 * Based on a phpBuilder article:
145 * @see http://www.phpbuilder.net/columns/tim20000821.php
147 function checkClient()
149 if (PMA_getenv('HTTP_USER_AGENT')) {
150 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
151 } elseif (! isset($HTTP_USER_AGENT)) {
152 $HTTP_USER_AGENT = '';
156 if (strstr($HTTP_USER_AGENT, 'Win')) {
157 $this->set('PMA_USR_OS', 'Win');
158 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
159 $this->set('PMA_USR_OS', 'Mac');
160 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
161 $this->set('PMA_USR_OS', 'Linux');
162 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
163 $this->set('PMA_USR_OS', 'Unix');
164 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
165 $this->set('PMA_USR_OS', 'OS/2');
167 $this->set('PMA_USR_OS', 'Other');
170 // 2. browser and version
171 // (must check everything else before Mozilla)
173 if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
174 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
175 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
176 } elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
177 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
178 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
179 } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
180 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
181 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
182 // Konqueror 2.2.2 says Konqueror/2.2.2
183 // Konqueror 3.0.3 says Konqueror/3
184 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) {
185 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
186 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
187 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)
188 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) {
189 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
190 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
191 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
192 $this->set('PMA_USR_BROWSER_VER', '1.9');
193 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
194 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
195 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
196 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
198 $this->set('PMA_USR_BROWSER_VER', 0);
199 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
204 * Whether GD2 is present
208 if ($this->get('GD2Available') == 'yes') {
209 $this->set('PMA_IS_GD2', 1);
210 } elseif ($this->get('GD2Available') == 'no') {
211 $this->set('PMA_IS_GD2', 0);
213 if (!@function_exists
('imagecreatetruecolor')) {
214 $this->set('PMA_IS_GD2', 0);
216 if (@function_exists
('gd_info')) {
218 if (strstr($gd_nfo["GD Version"], '2.')) {
219 $this->set('PMA_IS_GD2', 1);
221 $this->set('PMA_IS_GD2', 0);
224 /* We must do hard way... but almost no chance to execute this */
226 phpinfo(INFO_MODULES
); /* Only modules */
227 $a = strip_tags(ob_get_contents());
229 /* Get GD version string from phpinfo output */
230 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
231 if (strstr($v, '2.')) {
232 $this->set('PMA_IS_GD2', 1);
234 $this->set('PMA_IS_GD2', 0);
237 $this->set('PMA_IS_GD2', 0);
245 * Whether the Web server php is running on is IIS
247 function checkWebServer()
249 if (PMA_getenv('SERVER_SOFTWARE')
250 // some versions return Microsoft-IIS, some Microsoft/IIS
251 // we could use a preg_match() but it's slower
252 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
253 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) {
254 $this->set('PMA_IS_IIS', 1);
256 $this->set('PMA_IS_IIS', 0);
261 * Whether the os php is running on is windows or not
263 function checkWebServerOs()
265 // Default to Unix or Equiv
266 $this->set('PMA_IS_WINDOWS', 0);
267 // If PHP_OS is defined then continue
268 if (defined('PHP_OS')) {
269 if (stristr(PHP_OS
, 'win')) {
270 // Is it some version of Windows
271 $this->set('PMA_IS_WINDOWS', 1);
272 } elseif (stristr(PHP_OS
, 'OS/2')) {
273 // Is it OS/2 (No file permissions like Windows)
274 $this->set('PMA_IS_WINDOWS', 1);
280 * detects PHP version
282 function checkPhpVersion()
285 if (! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
286 phpversion(), $match)) {
287 preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
288 phpversion(), $match);
290 if (isset($match) && ! empty($match[1])) {
291 if (! isset($match[2])) {
294 if (! isset($match[3])) {
297 $this->set('PMA_PHP_INT_VERSION',
298 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
300 $this->set('PMA_PHP_INT_VERSION', 0);
302 $this->set('PMA_PHP_STR_VERSION', phpversion());
306 * loads default values from default source
308 * @return boolean success
310 function loadDefaults()
313 if (! file_exists($this->default_source
)) {
314 $this->error_config_default_file
= true;
317 include $this->default_source
;
319 $this->default_source_mtime
= filemtime($this->default_source
);
321 $this->default_server
= $cfg['Servers'][1];
322 unset($cfg['Servers']);
324 $this->default = $cfg;
325 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
327 $this->error_config_default_file
= false;
333 * loads configuration from $source, usally the config file
334 * should be called on object creation
336 * @param string $source config file
339 function load($source = null)
341 $this->loadDefaults();
343 if (null !== $source) {
344 $this->setSource($source);
347 if (! $this->checkConfigSource()) {
354 * Parses the configuration file, the eval is used here to avoid
355 * problems with trailing whitespace, what is often a problem.
357 $old_error_reporting = error_reporting(0);
358 $eval_result = eval('?' . '>' . trim(file_get_contents($this->getSource())));
359 error_reporting($old_error_reporting);
361 if ($eval_result === false) {
362 $this->error_config_file
= true;
364 $this->error_config_file
= false;
365 $this->source_mtime
= filemtime($this->getSource());
369 * Backward compatibility code
371 if (!empty($cfg['DefaultTabTable'])) {
372 $cfg['DefaultTabTable'] = str_replace('_properties', '', str_replace('tbl_properties.php', 'tbl_sql.php', $cfg['DefaultTabTable']));
374 if (!empty($cfg['DefaultTabDatabase'])) {
375 $cfg['DefaultTabDatabase'] = str_replace('_details', '', str_replace('db_details.php', 'db_sql.php', $cfg['DefaultTabDatabase']));
378 $this->settings
= PMA_array_merge_recursive($this->settings
, $cfg);
379 $this->checkPmaAbsoluteUri();
380 $this->checkFontsize();
382 $this->checkPermissions();
384 // Handling of the collation must be done after merging of $cfg
385 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
386 // can have an effect. Note that the presence of collation
387 // information in a cookie has priority over what is defined
388 // in the default or user's config files.
390 * @todo check validity of $_COOKIE['pma_collation_connection']
392 if (! empty($_COOKIE['pma_collation_connection'])) {
393 $this->set('collation_connection',
394 strip_tags($_COOKIE['pma_collation_connection']));
396 $this->set('collation_connection',
397 $this->get('DefaultConnectionCollation'));
399 // Now, a collation information could come from REQUEST
400 // (an example of this: the collation selector in main.php)
401 // so the following handles the setting of collation_connection
402 // and later, in common.inc.php, the cookie will be set
403 // according to this.
404 $this->checkCollationConnection();
410 * Loads user preferences and merges them with current config
411 * must be called after control connection has been estabilished
415 function loadUserPreferences()
417 // index.php should load these settings, so that phpmyadmin.css.php
418 // will have everything avaiable in session cache
419 $server = isset($GLOBALS['server'])
421 : (!empty($GLOBALS['cfg']['ServerDefault']) ?
$GLOBALS['cfg']['ServerDefault'] : 0);
422 $cache_key = 'server_' . $server;
423 if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) {
424 $config_mtime = max($this->default_source_mtime
, $this->source_mtime
);
425 // cache user preferences, use database only when needed
426 if (! isset($_SESSION['cache'][$cache_key]['userprefs'])
427 ||
$_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime) {
428 // load required libraries
429 require_once './libraries/user_preferences.lib.php';
430 $prefs = PMA_load_userprefs();
431 $_SESSION['cache'][$cache_key]['userprefs'] = PMA_apply_userprefs($prefs['config_data']);
432 $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
433 $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
434 $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
436 } else if ($server == 0 ||
! isset($_SESSION['cache'][$cache_key]['userprefs'])) {
437 $this->set('user_preferences', false);
440 $config_data = $_SESSION['cache'][$cache_key]['userprefs'];
441 // type is 'db' or 'session'
442 $this->set('user_preferences', $_SESSION['cache'][$cache_key]['userprefs_type']);
443 $this->set('user_preferences_mtime', $_SESSION['cache'][$cache_key]['userprefs_mtime']);
445 // backup some settings
446 $org_fontsize = $this->settings
['fontsize'];
448 $this->settings
= PMA_array_merge_recursive($this->settings
, $config_data);
449 $GLOBALS['cfg'] = PMA_array_merge_recursive($GLOBALS['cfg'], $config_data);
450 if (defined('PMA_MINIMUM_COMMON')) {
454 // settings below start really working on next page load, but
455 // changes are made only in index.php so everything is set when
459 $tmanager = $_SESSION['PMA_Theme_Manager'];
460 if ($tmanager->getThemeCookie() ||
isset($_REQUEST['set_theme'])) {
461 if ((! isset($config_data['ThemeDefault']) && $tmanager->theme
->getId() != 'original')
462 ||
isset($config_data['ThemeDefault']) && $config_data['ThemeDefault'] != $tmanager->theme
->getId()) {
463 // new theme was set in common.inc.php
464 $this->setUserValue(null, 'ThemeDefault', $tmanager->theme
->getId(), 'original');
467 // no cookie - read default from settings
468 if ($this->settings
['ThemeDefault'] != $tmanager->theme
->getId()
469 && $tmanager->checkTheme($this->settings
['ThemeDefault'])) {
470 $tmanager->setActiveTheme($this->settings
['ThemeDefault']);
471 $tmanager->setThemeCookie();
476 if ((! isset($config_data['fontsize']) && $org_fontsize != '82%')
477 ||
isset($config_data['fontsize']) && $org_fontsize != $config_data['fontsize']) {
478 $this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
482 if (isset($_COOKIE['pma_lang']) ||
isset($_POST['lang'])) {
483 if ((! isset($config_data['lang']) && $GLOBALS['lang'] != 'en')
484 ||
isset($config_data['lang']) && $GLOBALS['lang'] != $config_data['lang']) {
485 $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
488 // read language from settings
489 if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
490 $this->setCookie('pma_lang', $GLOBALS['lang']);
494 // save connection collation
495 if (isset($_COOKIE['pma_collation_connection']) ||
isset($_POST['collation_connection'])) {
496 if ((! isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != 'utf8_general_ci')
497 ||
isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != $config_data['collation_connection']) {
498 $this->setUserValue(null, 'collation_connection', $GLOBALS['collation_connection'], 'utf8_general_ci');
501 // read collation from settings
502 if (isset($config_data['collation_connection'])) {
503 $GLOBALS['collation_connection'] = $config_data['collation_connection'];
504 $this->setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
510 * Sets config value which is stored in user preferences (if available) or in a cookie.
512 * If user preferences are not yet initialized, option is applied to global config and
513 * added to a update queue, which is processed by {@link loadUserPreferences()}
515 * @param string $cookie_name can be null
516 * @param string $cfg_path
517 * @param mixed $new_cfg_value
518 * @param mixed $default_value
520 function setUserValue($cookie_name, $cfg_path, $new_cfg_value, $default_value = null)
522 // use permanent user preferences if possible
523 $prefs_type = $this->get('user_preferences');
525 require_once './libraries/user_preferences.lib.php';
526 if ($default_value === null) {
527 $default_value = PMA_array_read($cfg_path, $this->default);
529 PMA_persist_option($cfg_path, $new_cfg_value, $default_value);
531 if ($prefs_type != 'db' && $cookie_name) {
532 // fall back to cookies
533 if ($default_value === null) {
534 $default_value = PMA_array_read($cfg_path, $this->settings
);
536 $this->setCookie($cookie_name, $new_cfg_value, $default_value);
538 PMA_array_write($cfg_path, $GLOBALS['cfg'], $new_cfg_value);
539 PMA_array_write($cfg_path, $this->settings
, $new_cfg_value);
543 * Reads value stored by {@link setUserValue()}
545 * @param string $cookie_name
546 * @param mixed $cfg_value
549 function getUserValue($cookie_name, $cfg_value)
551 $cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]);
552 $prefs_type = $this->get('user_preferences');
553 if ($prefs_type == 'db') {
554 // permanent user preferences value exists, remove cookie
555 if ($cookie_exists) {
556 $this->removeCookie($cookie_name);
558 } else if ($cookie_exists) {
559 return $_COOKIE[$cookie_name];
561 // return value from $cfg array
567 * @param string $source
569 function setSource($source)
571 $this->source
= trim($source);
575 * checks if the config folder still exists and terminates app if true
577 function checkConfigFolder()
579 // Refuse to work while there still might be some world writable dir:
580 if (is_dir('./config')) {
581 die('Remove "./config" directory before using phpMyAdmin!');
586 * check config source
588 * @return boolean whether source is valid or not
590 function checkConfigSource()
592 if (! $this->getSource()) {
593 // no configuration file set at all
597 if (! file_exists($this->getSource())) {
598 // do not trigger error here
599 // https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
602 'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
605 $this->source_mtime
= 0;
609 if (! is_readable($this->getSource())) {
610 $this->source_mtime
= 0;
611 die('Existing configuration file (' . $this->getSource() . ') is not readable.');
618 * verifies the permissions on config file (if asked by configuration)
619 * (must be called after config.inc.php has been merged)
621 function checkPermissions()
623 // Check for permissions (on platforms that support it):
624 if ($this->get('CheckConfigurationPermissions')) {
625 $perms = @fileperms
($this->getSource());
626 if (!($perms === false) && ($perms & 2)) {
627 // This check is normally done after loading configuration
628 $this->checkWebServerOs();
629 if ($this->get('PMA_IS_WINDOWS') == 0) {
630 $this->source_mtime
= 0;
631 die('Wrong permissions on configuration file, should not be world writable!');
638 * returns specific config setting
639 * @param string $setting
640 * @return mixed value
642 function get($setting)
644 if (isset($this->settings
[$setting])) {
645 return $this->settings
[$setting];
651 * sets configuration variable
653 * @param string $setting configuration option
654 * @param string $value new value for configuration option
656 function set($setting, $value)
658 if (! isset($this->settings
[$setting]) ||
$this->settings
[$setting] != $value) {
659 $this->settings
[$setting] = $value;
660 $this->set_mtime
= time();
665 * returns source for current config
666 * @return string config source
670 return $this->source
;
674 * returns a unique value to force a CSS reload if either the config
675 * or the theme changes
676 * must also check the pma_fontsize cookie in case there is no
678 * @return int Summary of unix timestamps and fontsize, to be unique on theme parameters change
680 function getThemeUniqueValue()
682 if (null !== $this->get('fontsize')) {
683 $fontsize = intval($this->get('fontsize'));
684 } elseif (isset($_COOKIE['pma_fontsize'])) {
685 $fontsize = intval($_COOKIE['pma_fontsize']);
691 $this->source_mtime +
692 $this->default_source_mtime +
693 $this->get('user_preferences_mtime') +
694 $_SESSION['PMA_Theme']->mtime_info +
695 $_SESSION['PMA_Theme']->filesize_info
);
699 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
700 * set properly and, depending on browsers, inserting or updating a
705 function checkPmaAbsoluteUri()
707 // Setup a default value to let the people and lazy sysadmins work anyway,
708 // they'll get an error if the autodetect code doesn't work
709 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
710 $is_https = $this->detectHttps();
712 if (strlen($pma_absolute_uri) < 5) {
715 // At first we try to parse REQUEST_URI, it might contain full URL
717 * REQUEST_URI contains PATH_INFO too, this is not what we want
718 * script-php/pathinfo/
719 if (PMA_getenv('REQUEST_URI')) {
720 $url = @parse_url(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
721 if ($url === false) {
722 $url = array('path' => $_SERVER['REQUEST_URI']);
727 // If we don't have scheme, we didn't have full URL so we need to
729 if (empty($url['scheme'])) {
731 if (PMA_getenv('HTTP_SCHEME')) {
732 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
735 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
741 if (PMA_getenv('HTTP_HOST')) {
742 // Prepend the scheme before using parse_url() since this is not part of the RFC2616 Host request-header
743 $parsed_url = parse_url($url['scheme'] . '://' . PMA_getenv('HTTP_HOST'));
744 if (!empty($parsed_url['host'])) {
747 $url['host'] = PMA_getenv('HTTP_HOST');
749 } elseif (PMA_getenv('SERVER_NAME')) {
750 $url['host'] = PMA_getenv('SERVER_NAME');
752 $this->error_pma_uri
= true;
756 // If we didn't set port yet...
757 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
758 $url['port'] = PMA_getenv('SERVER_PORT');
761 // And finally the path could be already set from REQUEST_URI
762 if (empty($url['path'])) {
764 * REQUEST_URI contains PATH_INFO too, this is not what we want
765 * script-php/pathinfo/
766 if (PMA_getenv('PATH_INFO')) {
767 $path = parse_url(PMA_getenv('PATH_INFO'));
769 // PHP_SELF in CGI often points to cgi executable, so use it
772 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
774 $url['path'] = $path['path'];
778 // Make url from parts we have
779 $pma_absolute_uri = $url['scheme'] . '://';
780 // Was there user information?
781 if (!empty($url['user'])) {
782 $pma_absolute_uri .= $url['user'];
783 if (!empty($url['pass'])) {
784 $pma_absolute_uri .= ':' . $url['pass'];
786 $pma_absolute_uri .= '@';
789 $pma_absolute_uri .= $url['host'];
790 // Add port, if it not the default one
791 if (! empty($url['port'])
792 && (($url['scheme'] == 'http' && $url['port'] != 80)
793 ||
($url['scheme'] == 'https' && $url['port'] != 443))) {
794 $pma_absolute_uri .= ':' . $url['port'];
796 // And finally path, without script name, the 'a' is there not to
797 // strip our directory, when path is only /pmadir/ without filename.
798 // Backslashes returned by Windows have to be changed.
799 // Only replace backslashes by forward slashes if on Windows,
800 // as the backslash could be valid on a non-Windows system.
801 $this->checkWebServerOs();
802 if ($this->get('PMA_IS_WINDOWS') == 1) {
803 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
805 $path = dirname($url['path'] . 'a');
808 // To work correctly within transformations overview:
809 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR
== '../../') {
810 if ($this->get('PMA_IS_WINDOWS') == 1) {
811 $path = str_replace("\\", "/", dirname(dirname($path)));
813 $path = dirname(dirname($path));
817 // PHP's dirname function would have returned a dot when $path contains no slash
821 // in vhost situations, there could be already an ending slash
822 if (substr($path, -1) != '/') {
825 $pma_absolute_uri .= $path;
827 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
828 // the autodetect code works well enough that we don't display the
829 // warning at all. The user can still set PmaAbsoluteUri manually.
831 // http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411
834 // The URI is specified, however users do often specify this
835 // wrongly, so we try to fix this.
837 // Adds a trailing slash et the end of the phpMyAdmin uri if it
839 if (substr($pma_absolute_uri, -1) != '/') {
840 $pma_absolute_uri .= '/';
843 // If URI doesn't start with http:// or https://, we will add
845 if (substr($pma_absolute_uri, 0, 7) != 'http://'
846 && substr($pma_absolute_uri, 0, 8) != 'https://') {
848 ($is_https ?
'https' : 'http')
849 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ?
'' : '//')
853 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
857 * check selected collation_connection
858 * @todo check validity of $_REQUEST['collation_connection']
860 function checkCollationConnection()
862 if (! empty($_REQUEST['collation_connection'])) {
863 $this->set('collation_connection',
864 strip_tags($_REQUEST['collation_connection']));
869 * checks for font size configuration, and sets font size as requested by user
872 function checkFontsize()
876 if (isset($_GET['set_fontsize'])) {
877 $new_fontsize = $_GET['set_fontsize'];
878 } elseif (isset($_POST['set_fontsize'])) {
879 $new_fontsize = $_POST['set_fontsize'];
880 } elseif (isset($_COOKIE['pma_fontsize'])) {
881 $new_fontsize = $_COOKIE['pma_fontsize'];
884 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
885 $this->set('fontsize', $new_fontsize);
886 } elseif (! $this->get('fontsize')) {
887 // 80% would correspond to the default browser font size
888 // of 16, but use 82% to help read the monoface font
889 $this->set('fontsize', '82%');
892 $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%');
896 * checks if upload is enabled
900 function checkUpload()
902 if (ini_get('file_uploads')) {
903 $this->set('enable_upload', true);
904 // if set "php_admin_value file_uploads Off" in httpd.conf
905 // ini_get() also returns the string "Off" in this case:
906 if ('off' == strtolower(ini_get('file_uploads'))) {
907 $this->set('enable_upload', false);
910 $this->set('enable_upload', false);
915 * Maximum upload size as limited by PHP
916 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
918 * this section generates $max_upload_size in bytes
920 function checkUploadSize()
922 if (! $filesize = ini_get('upload_max_filesize')) {
926 if ($postsize = ini_get('post_max_size')) {
927 $this->set('max_upload_size',
928 min(PMA_get_real_size($filesize), PMA_get_real_size($postsize)));
930 $this->set('max_upload_size', PMA_get_real_size($filesize));
937 function checkIsHttps()
939 $this->set('is_https', $this->isHttps());
945 public function isHttps()
947 static $is_https = null;
949 if (null !== $is_https) {
953 $url = parse_url($this->get('PmaAbsoluteUri'));
955 if (isset($url['scheme'])
956 && $url['scheme'] == 'https') {
966 * Detects whether https appears to be used.
968 * Please note that this just detects what we see, so
969 * it completely ignores things like reverse proxies.
973 function detectHttps()
979 // At first we try to parse REQUEST_URI, it might contain full URL,
980 if (PMA_getenv('REQUEST_URI')) {
981 $url = @parse_url
(PMA_getenv('REQUEST_URI')); // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
982 if ($url === false) {
987 // If we don't have scheme, we didn't have full URL so we need to
989 if (empty($url['scheme'])) {
991 if (PMA_getenv('HTTP_SCHEME')) {
992 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
995 PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off'
1001 if (isset($url['scheme'])
1002 && $url['scheme'] == 'https') {
1012 * detect correct cookie path
1014 function checkCookiePath()
1016 $this->set('cookie_path', $this->getCookiePath());
1022 public function getCookiePath()
1024 static $cookie_path = null;
1026 if (null !== $cookie_path) {
1027 return $cookie_path;
1030 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
1032 $cookie_path = $parsed_url['path'];
1034 return $cookie_path;
1038 * enables backward compatibility
1042 $GLOBALS['cfg'] = $this->settings
;
1043 $GLOBALS['default_server'] = $this->default_server
;
1044 unset($this->default_server
);
1045 $GLOBALS['collation_connection'] = $this->get('collation_connection');
1046 $GLOBALS['is_upload'] = $this->get('enable_upload');
1047 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
1048 $GLOBALS['cookie_path'] = $this->get('cookie_path');
1049 $GLOBALS['is_https'] = $this->get('is_https');
1053 'PMA_THEME_VERSION',
1054 'PMA_THEME_GENERATION',
1055 'PMA_PHP_STR_VERSION',
1056 'PMA_PHP_INT_VERSION',
1061 'PMA_USR_BROWSER_VER',
1062 'PMA_USR_BROWSER_AGENT'
1065 foreach ($defines as $define) {
1066 if (! defined($define)) {
1067 define($define, $this->get($define));
1080 * returns options for font size selection
1083 * @param string $current_size current selected font size with unit
1084 * @return array selectable font sizes
1086 static protected function _getFontsizeOptions($current_size = '82%')
1088 $unit = preg_replace('/[0-9.]*/', '', $current_size);
1089 $value = preg_replace('/[^0-9.]*/', '', $current_size);
1093 $options["$value"] = $value . $unit;
1095 if ($unit === '%') {
1099 } elseif ($unit === 'em') {
1103 } elseif ($unit === 'pt') {
1106 } elseif ($unit === 'px') {
1111 //unknown font size unit
1119 foreach ($factors as $key => $factor) {
1120 $option_inc = $value +
$factor;
1121 $option_dec = $value - $factor;
1122 while (count($options) < 21) {
1123 $options["$option_inc"] = $option_inc . $unit;
1124 if ($option_dec > $factors[0]) {
1125 $options["$option_dec"] = $option_dec . $unit;
1127 $option_inc +
= $factor;
1128 $option_dec -= $factor;
1129 if (isset($factors[$key +
1])
1130 && $option_inc >= $value +
$factors[$key +
1]) {
1140 * returns html selectbox for font sizes
1143 * @param string $current_size currently slected font size with unit
1144 * @return string html selectbox
1146 static protected function _getFontsizeSelection()
1148 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1149 // for the case when there is no config file (this is supported)
1150 if (empty($current_size)) {
1151 if (isset($_COOKIE['pma_fontsize'])) {
1152 $current_size = $_COOKIE['pma_fontsize'];
1154 $current_size = '82%';
1157 $options = PMA_Config
::_getFontsizeOptions($current_size);
1159 $return = '<label for="select_fontsize">' . __('Font size') . ':</label>' . "\n";
1160 $return .= '<select name="set_fontsize" id="select_fontsize" class="autosubmit">' . "\n";
1161 foreach ($options as $option) {
1162 $return .= '<option value="' . $option . '"';
1163 if ($option == $current_size) {
1164 $return .= ' selected="selected"';
1166 $return .= '>' . $option . '</option>' . "\n";
1168 $return .= '</select>';
1174 * return complete font size selection form
1177 * @param string $current_size currently slected font size with unit
1178 * @return string html selectbox
1180 static public function getFontsizeForm()
1182 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1183 . ' method="post" action="index.php" target="_parent">' . "\n"
1184 . PMA_generate_common_hidden_inputs() . "\n"
1185 . PMA_Config
::_getFontsizeSelection() . "\n"
1186 . '<noscript>' . "\n"
1187 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
1188 . '</noscript>' . "\n"
1195 * @param string $cookie name of cookie to remove
1196 * @return boolean result of setcookie()
1198 function removeCookie($cookie)
1200 return setcookie($cookie, '', time() - 3600,
1201 $this->getCookiePath(), '', $this->isHttps());
1205 * sets cookie if value is different from current cokkie value,
1206 * or removes if value is equal to default
1208 * @param string $cookie name of cookie to remove
1209 * @param mixed $value new cookie value
1210 * @param string $default default value
1211 * @param int $validity validity of cookie in seconds (default is one month)
1212 * @param bool $httponlt whether cookie is only for HTTP (and not for scripts)
1213 * @return boolean result of setcookie()
1215 function setCookie($cookie, $value, $default = null, $validity = null, $httponly = true)
1217 if ($validity == null) {
1218 $validity = 2592000;
1220 if (strlen($value) && null !== $default && $value === $default) {
1221 // default value is used
1222 if (isset($_COOKIE[$cookie])) {
1224 return $this->removeCookie($cookie);
1229 if (! strlen($value) && isset($_COOKIE[$cookie])) {
1230 // remove cookie, value is empty
1231 return $this->removeCookie($cookie);
1234 if (! isset($_COOKIE[$cookie]) ||
$_COOKIE[$cookie] !== $value) {
1235 // set cookie with new value
1236 /* Calculate cookie validity */
1237 if ($validity == 0) {
1240 $v = time() +
$validity;
1242 return setcookie($cookie, $value, $v,
1243 $this->getCookiePath(), '', $this->isHttps(), $httponly);
1246 // cookie has already $value as value