2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Configuration handling.
8 if (! defined('PHPMYADMIN')) {
13 * Load vendor configuration.
15 require_once './libraries/vendor_config.php';
25 * @var string default config source
27 var $default_source = './libraries/config.default.php';
30 * @var array default configuration settings
32 var $default = array();
35 * @var array configuration settings
37 var $settings = array();
40 * @var string config source
45 * @var int source modification time
47 var $source_mtime = 0;
48 var $default_source_mtime = 0;
54 var $error_config_file = false;
59 var $error_config_default_file = false;
64 var $error_pma_uri = false;
69 var $default_server = array();
72 * @var boolean whether init is done or not
73 * set this to false to force some initial checks
74 * like checking for required functions
81 * @param string $source source to read config from
83 function __construct($source = null)
85 $this->settings
= array();
87 // functions need to refresh in case of config file changed goes in
91 // other settings, independent from config file, comes in
94 $this->checkIsHttps();
98 * sets system and application settings
102 function checkSystem()
104 $this->set('PMA_VERSION', '4.0.4.1');
108 $this->set('PMA_THEME_VERSION', 2);
112 $this->set('PMA_THEME_GENERATION', 2);
114 $this->checkPhpVersion();
115 $this->checkWebServerOs();
116 $this->checkWebServer();
118 $this->checkClient();
119 $this->checkUpload();
120 $this->checkUploadSize();
121 $this->checkOutputCompression();
125 * whether to use gzip output compression or not
129 function checkOutputCompression()
131 // If zlib output compression is set in the php configuration file, no
132 // output buffering should be run
133 if (@ini_get
('zlib.output_compression')) {
134 $this->set('OBGzip', false);
137 // disable output-buffering (if set to 'auto') for IE6, else enable it.
138 if (strtolower($this->get('OBGzip')) == 'auto') {
139 if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE'
140 && $this->get('PMA_USR_BROWSER_VER') >= 6
141 && $this->get('PMA_USR_BROWSER_VER') < 7
143 $this->set('OBGzip', false);
145 $this->set('OBGzip', true);
151 * Determines platform (OS), browser and version of the user
152 * Based on a phpBuilder article:
154 * @see http://www.phpbuilder.net/columns/tim20000821.php
158 function checkClient()
160 if (PMA_getenv('HTTP_USER_AGENT')) {
161 $HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT');
163 $HTTP_USER_AGENT = '';
167 if (strstr($HTTP_USER_AGENT, 'Win')) {
168 $this->set('PMA_USR_OS', 'Win');
169 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
170 $this->set('PMA_USR_OS', 'Mac');
171 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
172 $this->set('PMA_USR_OS', 'Linux');
173 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
174 $this->set('PMA_USR_OS', 'Unix');
175 } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) {
176 $this->set('PMA_USR_OS', 'OS/2');
178 $this->set('PMA_USR_OS', 'Other');
181 // 2. browser and version
182 // (must check everything else before Mozilla)
185 '@Opera(/| )([0-9].[0-9]{1,2})@',
189 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
190 $this->set('PMA_USR_BROWSER_AGENT', 'OPERA');
191 } elseif (preg_match(
192 '@MSIE ([0-9].[0-9]{1,2})@',
196 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
197 $this->set('PMA_USR_BROWSER_AGENT', 'IE');
198 } elseif (preg_match(
199 '@OmniWeb/([0-9].[0-9]{1,2})@',
203 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
204 $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB');
205 // Konqueror 2.2.2 says Konqueror/2.2.2
206 // Konqueror 3.0.3 says Konqueror/3
207 } elseif (preg_match(
208 '@(Konqueror/)(.*)(;)@',
212 $this->set('PMA_USR_BROWSER_VER', $log_version[2]);
213 $this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR');
214 // must check Chrome before Safari
215 } elseif (preg_match(
216 '@Mozilla/([0-9].[0-9]{1,2})@',
219 && preg_match('@Chrome/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)
221 $this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]);
222 $this->set('PMA_USR_BROWSER_AGENT', 'CHROME');
224 } elseif (preg_match(
225 '@Mozilla/([0-9].[0-9]{1,2})@',
228 && preg_match('@Version/(.*) Safari@', $HTTP_USER_AGENT, $log_version2)
231 'PMA_USR_BROWSER_VER', $log_version2[1]
233 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
235 } elseif (preg_match(
236 '@Mozilla/([0-9].[0-9]{1,2})@',
239 && preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)
242 'PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]
244 $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI');
245 } elseif (preg_match('@rv:1.9(.*)Gecko@', $HTTP_USER_AGENT)) {
246 $this->set('PMA_USR_BROWSER_VER', '1.9');
247 $this->set('PMA_USR_BROWSER_AGENT', 'GECKO');
248 } elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) {
249 $this->set('PMA_USR_BROWSER_VER', $log_version[1]);
250 $this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
252 $this->set('PMA_USR_BROWSER_VER', 0);
253 $this->set('PMA_USR_BROWSER_AGENT', 'OTHER');
258 * Whether GD2 is present
264 if ($this->get('GD2Available') == 'yes') {
265 $this->set('PMA_IS_GD2', 1);
266 } elseif ($this->get('GD2Available') == 'no') {
267 $this->set('PMA_IS_GD2', 0);
269 if (!@function_exists
('imagecreatetruecolor')) {
270 $this->set('PMA_IS_GD2', 0);
272 if (@function_exists
('gd_info')) {
274 if (strstr($gd_nfo["GD Version"], '2.')) {
275 $this->set('PMA_IS_GD2', 1);
277 $this->set('PMA_IS_GD2', 0);
280 $this->set('PMA_IS_GD2', 0);
287 * Whether the Web server php is running on is IIS
291 function checkWebServer()
293 // some versions return Microsoft-IIS, some Microsoft/IIS
294 // we could use a preg_match() but it's slower
295 if (PMA_getenv('SERVER_SOFTWARE')
296 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft')
297 && stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')
299 $this->set('PMA_IS_IIS', 1);
301 $this->set('PMA_IS_IIS', 0);
306 * Whether the os php is running on is windows or not
310 function checkWebServerOs()
312 // Default to Unix or Equiv
313 $this->set('PMA_IS_WINDOWS', 0);
314 // If PHP_OS is defined then continue
315 if (defined('PHP_OS')) {
316 if (stristr(PHP_OS
, 'win')) {
317 // Is it some version of Windows
318 $this->set('PMA_IS_WINDOWS', 1);
319 } elseif (stristr(PHP_OS
, 'OS/2')) {
320 // Is it OS/2 (No file permissions like Windows)
321 $this->set('PMA_IS_WINDOWS', 1);
327 * detects PHP version
331 function checkPhpVersion()
335 '@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
340 '@([0-9]{1,2}).([0-9]{1,2})@',
345 if (isset($match) && ! empty($match[1])) {
346 if (! isset($match[2])) {
349 if (! isset($match[3])) {
353 'PMA_PHP_INT_VERSION',
354 (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3])
357 $this->set('PMA_PHP_INT_VERSION', 0);
359 $this->set('PMA_PHP_STR_VERSION', phpversion());
363 * detects if Git revision
367 function isGitRevision()
370 if (isset($_SESSION['is_git_revision'])) {
371 if ($_SESSION['is_git_revision']) {
372 $this->set('PMA_VERSION_GIT', 1);
374 return $_SESSION['is_git_revision'];
376 // find out if there is a .git folder
377 $git_folder = '.git';
378 if (! @file_exists
($git_folder)
379 ||
! @file_exists
($git_folder . '/config')
381 $_SESSION['is_git_revision'] = false;
384 $_SESSION['is_git_revision'] = true;
389 * detects Git revision, if running inside repo
393 function checkGitRevision()
395 // find out if there is a .git folder
396 $git_folder = '.git';
397 if (! $this->isGitRevision()) {
401 if (! $ref_head = @file_get_contents
($git_folder . '/HEAD')) {
405 // are we on any branch?
406 if (strstr($ref_head, '/')) {
407 $ref_head = substr(trim($ref_head), 5);
408 if (substr($ref_head, 0, 11) === 'refs/heads/') {
409 $branch = substr($ref_head, 11);
411 $branch = basename($ref_head);
414 $ref_file = $git_folder . '/' . $ref_head;
415 if (@file_exists
($ref_file)) {
416 if (! $hash = @file_get_contents
($ref_file)) {
421 // deal with packed refs
422 if (! $packed_refs = @file_get_contents
($git_folder . '/packed-refs')) {
425 // split file to lines
426 $ref_lines = explode("\n", $packed_refs);
427 foreach ($ref_lines as $line) {
429 if ($line[0] == '#') {
433 $parts = explode(' ', $line);
434 // care only about named refs
435 if (count($parts) != 2) {
438 // have found our ref?
439 if ($parts[1] == $ref_head) {
444 if (! isset($hash)) {
445 // Could not find ref
450 $hash = trim($ref_head);
454 if ( !isset($_SESSION['PMA_VERSION_COMMITDATA_' . $hash])) {
455 $git_file_name = $git_folder . '/objects/' . substr($hash, 0, 2)
456 . '/' . substr($hash, 2);
457 if (file_exists($git_file_name) ) {
458 if (! $commit = @file_get_contents
($git_file_name)) {
461 $commit = explode("\0", gzuncompress($commit), 2);
462 $commit = explode("\n", $commit[1]);
463 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
465 $pack_names = array();
466 // work with packed data
467 if ($packs = @file_get_contents
($git_folder . '/objects/info/packs')) {
468 // File exists. Read it, parse the file to get the names of the
469 // packs. (to look for them in .git/object/pack directory later)
470 foreach (explode("\n", $packs) as $line) {
472 if (strlen(trim($line)) == 0) {
475 // skip non pack lines
476 if ($line[0] != 'P') {
480 $pack_names[] = substr($line, 2);
483 // '.git/objects/info/packs' file can be missing
484 // (atlease in mysGit)
485 // File missing. May be we can look in the .git/object/pack
486 // directory for all the .pack files and use that list of
488 $it = new DirectoryIterator($git_folder . '/objects/pack');
489 foreach ($it as $file_info) {
490 $file_name = $file_info->getFilename();
491 // if this is a .pack file
492 if ($file_info->isFile()
493 && substr($file_name, -5) == '.pack'
495 $pack_names[] = $file_name;
499 $hash = strtolower($hash);
500 foreach ($pack_names as $pack_name) {
501 $index_name = str_replace('.pack', '.idx', $pack_name);
504 if (! $index_data = @file_get_contents
($git_folder . '/objects/pack/' . $index_name)) {
508 if (substr($index_data, 0, 4) != "\377tOc") {
512 $version = unpack('N', substr($index_data, 4, 4));
513 if ($version[1] != 2) {
516 // parse fanout table
517 $fanout = unpack("N*", substr($index_data, 8, 256 * 4));
519 // find where we should search
520 $firstbyte = intval(substr($hash, 0, 2), 16);
521 // array is indexed from 1 and we need to get
522 // previous entry for start
523 if ($firstbyte == 0) {
526 $start = $fanout[$firstbyte];
528 $end = $fanout[$firstbyte +
1];
530 // stupid linear search for our sha
533 $offset = 8 +
(256 * 4);
534 for ($position = $start; $position < $end; $position++
) {
538 $index_data, $offset +
($position * 20), 20
551 $offset = 8 +
(256 * 4) +
(24 * $fanout[256]);
552 $pack_offset = unpack(
553 'N', substr($index_data, $offset +
($position * 4), 4)
555 $pack_offset = $pack_offset[1];
559 $git_folder . '/objects/pack/' . $pack_name, 'rb'
561 if ($pack_file === false) {
565 fseek($pack_file, $pack_offset);
568 $header = ord(fread($pack_file, 1));
569 $type = ($header >> 4) & 7;
570 $hasnext = ($header & 128) >> 7;
571 $size = $header & 0xf;
575 $byte = ord(fread($pack_file, 1));
576 $size |
= ($byte & 0x7f) << $offset;
577 $hasnext = ($byte & 128) >> 7;
581 // we care only about commit objects
587 $commit = fread($pack_file, $size);
588 $commit = gzuncompress($commit);
589 $commit = explode("\n", $commit);
590 $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] = $commit;
595 $commit = $_SESSION['PMA_VERSION_COMMITDATA_' . $hash];
598 // check if commit exists in Github
599 $is_remote_commit = false;
600 if ($commit !== false
601 && isset($_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash])
603 $is_remote_commit = $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash];
605 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin/git/commits/'
607 $is_found = $this->checkHTTP($link, !$commit);
610 $is_remote_commit = false;
611 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = false;
614 // no remote link for now, but don't cache this as Github is down
615 $is_remote_commit = false;
618 $is_remote_commit = true;
619 $_SESSION['PMA_VERSION_REMOTECOMMIT_' . $hash] = true;
620 if ($commit === false) {
621 // if no local commit data, try loading from Github
622 $commit_json = json_decode($is_found);
628 $is_remote_branch = false;
629 if ($is_remote_commit && $branch !== false) {
630 // check if branch exists in Github
631 if (isset($_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash])) {
632 $is_remote_branch = $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash];
634 $link = 'https://api.github.com/repos/phpmyadmin/phpmyadmin'
635 . '/git/trees/' . $branch;
636 $is_found = $this->checkHTTP($link);
639 $is_remote_branch = true;
640 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = true;
643 $is_remote_branch = false;
644 $_SESSION['PMA_VERSION_REMOTEBRANCH_' . $hash] = false;
647 // no remote link for now, but don't cache this as Github is down
648 $is_remote_branch = false;
654 if ($commit !== false) {
655 $author = array('name' => '', 'email' => '', 'date' => '');
656 $committer = array('name' => '', 'email' => '', 'date' => '');
659 $dataline = array_shift($commit);
660 $datalinearr = explode(' ', $dataline, 2);
661 $linetype = $datalinearr[0];
662 if (in_array($linetype, array('author', 'committer'))) {
663 $user = $datalinearr[1];
664 preg_match('/([^<]+)<([^>]+)> ([0-9]+)( [^ ]+)?/', $user, $user);
666 'name' => trim($user[1]),
667 'email' => trim($user[2]),
668 'date' => date('Y-m-d H:i:s', $user[3]));
669 if (isset($user[4])) {
670 $user2['date'] .= $user[4];
674 } while ($dataline != '');
675 $message = trim(implode(' ', $commit));
677 } elseif (isset($commit_json)) {
679 'name' => $commit_json->author
->name
,
680 'email' => $commit_json->author
->email
,
681 'date' => $commit_json->author
->date
);
683 'name' => $commit_json->committer
->name
,
684 'email' => $commit_json->committer
->email
,
685 'date' => $commit_json->committer
->date
);
686 $message = trim($commit_json->message
);
691 $this->set('PMA_VERSION_GIT', 1);
692 $this->set('PMA_VERSION_GIT_COMMITHASH', $hash);
693 $this->set('PMA_VERSION_GIT_BRANCH', $branch);
694 $this->set('PMA_VERSION_GIT_MESSAGE', $message);
695 $this->set('PMA_VERSION_GIT_AUTHOR', $author);
696 $this->set('PMA_VERSION_GIT_COMMITTER', $committer);
697 $this->set('PMA_VERSION_GIT_ISREMOTECOMMIT', $is_remote_commit);
698 $this->set('PMA_VERSION_GIT_ISREMOTEBRANCH', $is_remote_branch);
702 * Checks if given URL is 200 or 404, optionally returns data
704 * @param mixed $link curl link
705 * @param boolean $get_body whether to retrieve body of document
707 * @return test result or data
709 function checkHTTP($link, $get_body = false)
711 if (! function_exists('curl_init')) {
714 $ch = curl_init($link);
715 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 0);
716 curl_setopt($ch, CURLOPT_HEADER
, 1);
717 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
718 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST
, 0);
719 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
720 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 5);
721 curl_setopt($ch, CURLOPT_USERAGENT
, 'phpMyAdmin/' . PMA_VERSION
);
722 curl_setopt($ch, CURLOPT_TIMEOUT
, 5);
723 $data = @curl_exec
($ch);
724 if ($data === false) {
727 $ok = 'HTTP/1.1 200 OK';
728 $notfound = 'HTTP/1.1 404 Not Found';
729 if (substr($data, 0, strlen($ok)) === $ok) {
730 return $get_body ?
substr($data, strpos($data, "\r\n\r\n") +
4) : true;
731 } elseif (substr($data, 0, strlen($notfound)) === $notfound) {
738 * loads default values from default source
740 * @return boolean success
742 function loadDefaults()
745 if (! file_exists($this->default_source
)) {
746 $this->error_config_default_file
= true;
749 include $this->default_source
;
751 $this->default_source_mtime
= filemtime($this->default_source
);
753 $this->default_server
= $cfg['Servers'][1];
754 unset($cfg['Servers']);
756 $this->default = $cfg;
757 $this->settings
= PMA_arrayMergeRecursive($this->settings
, $cfg);
759 $this->error_config_default_file
= false;
765 * loads configuration from $source, usally the config file
766 * should be called on object creation
768 * @param string $source config file
772 function load($source = null)
774 $this->loadDefaults();
776 if (null !== $source) {
777 $this->setSource($source);
780 if (! $this->checkConfigSource()) {
787 * Parses the configuration file, the eval is used here to avoid
788 * problems with trailing whitespace, what is often a problem.
790 $old_error_reporting = error_reporting(0);
791 $eval_result = eval('?' . '>' . trim(file_get_contents($this->getSource())));
792 error_reporting($old_error_reporting);
794 if ($eval_result === false) {
795 $this->error_config_file
= true;
797 $this->error_config_file
= false;
798 $this->source_mtime
= filemtime($this->getSource());
802 * Backward compatibility code
804 if (!empty($cfg['DefaultTabTable'])) {
805 $cfg['DefaultTabTable'] = str_replace(
809 'tbl_properties.php',
811 $cfg['DefaultTabTable']
815 if (!empty($cfg['DefaultTabDatabase'])) {
816 $cfg['DefaultTabDatabase'] = str_replace(
822 $cfg['DefaultTabDatabase']
827 $this->settings
= PMA_arrayMergeRecursive($this->settings
, $cfg);
828 $this->checkPmaAbsoluteUri();
829 $this->checkFontsize();
831 // Handling of the collation must be done after merging of $cfg
832 // (from config.inc.php) so that $cfg['DefaultConnectionCollation']
833 // can have an effect. Note that the presence of collation
834 // information in a cookie has priority over what is defined
835 // in the default or user's config files.
837 * @todo check validity of $_COOKIE['pma_collation_connection']
839 if (! empty($_COOKIE['pma_collation_connection'])) {
841 'collation_connection',
842 strip_tags($_COOKIE['pma_collation_connection'])
846 'collation_connection',
847 $this->get('DefaultConnectionCollation')
850 // Now, a collation information could come from REQUEST
851 // (an example of this: the collation selector in index.php)
852 // so the following handles the setting of collation_connection
853 // and later, in common.inc.php, the cookie will be set
854 // according to this.
855 $this->checkCollationConnection();
861 * Loads user preferences and merges them with current config
862 * must be called after control connection has been estabilished
866 function loadUserPreferences()
868 // index.php should load these settings, so that phpmyadmin.css.php
869 // will have everything avaiable in session cache
870 $server = isset($GLOBALS['server'])
872 : (!empty($GLOBALS['cfg']['ServerDefault'])
873 ?
$GLOBALS['cfg']['ServerDefault']
875 $cache_key = 'server_' . $server;
876 if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) {
877 $config_mtime = max($this->default_source_mtime
, $this->source_mtime
);
878 // cache user preferences, use database only when needed
879 if (! isset($_SESSION['cache'][$cache_key]['userprefs'])
880 ||
$_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime
882 // load required libraries
883 include_once './libraries/user_preferences.lib.php';
884 $prefs = PMA_loadUserprefs();
885 $_SESSION['cache'][$cache_key]['userprefs']
886 = PMA_applyUserprefs($prefs['config_data']);
887 $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime'];
888 $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type'];
889 $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime;
891 } elseif ($server == 0
892 ||
! isset($_SESSION['cache'][$cache_key]['userprefs'])
894 $this->set('user_preferences', false);
897 $config_data = $_SESSION['cache'][$cache_key]['userprefs'];
898 // type is 'db' or 'session'
901 $_SESSION['cache'][$cache_key]['userprefs_type']
904 'user_preferences_mtime',
905 $_SESSION['cache'][$cache_key]['userprefs_mtime']
908 // backup some settings
910 if (isset($this->settings
['fontsize'])) {
911 $org_fontsize = $this->settings
['fontsize'];
914 $this->settings
= PMA_arrayMergeRecursive($this->settings
, $config_data);
915 $GLOBALS['cfg'] = PMA_arrayMergeRecursive($GLOBALS['cfg'], $config_data);
916 if (defined('PMA_MINIMUM_COMMON')) {
920 // settings below start really working on next page load, but
921 // changes are made only in index.php so everything is set when
925 $tmanager = $_SESSION['PMA_Theme_Manager'];
926 if ($tmanager->getThemeCookie() ||
isset($_REQUEST['set_theme'])) {
927 if ((! isset($config_data['ThemeDefault'])
928 && $tmanager->theme
->getId() != 'original')
929 ||
isset($config_data['ThemeDefault'])
930 && $config_data['ThemeDefault'] != $tmanager->theme
->getId()
932 // new theme was set in common.inc.php
936 $tmanager->theme
->getId(),
941 // no cookie - read default from settings
942 if ($this->settings
['ThemeDefault'] != $tmanager->theme
->getId()
943 && $tmanager->checkTheme($this->settings
['ThemeDefault'])
945 $tmanager->setActiveTheme($this->settings
['ThemeDefault']);
946 $tmanager->setThemeCookie();
951 if ((! isset($config_data['fontsize'])
952 && $org_fontsize != '82%')
953 ||
isset($config_data['fontsize'])
954 && $org_fontsize != $config_data['fontsize']
956 $this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
960 if (isset($_COOKIE['pma_lang']) ||
isset($_POST['lang'])) {
961 if ((! isset($config_data['lang'])
962 && $GLOBALS['lang'] != 'en')
963 ||
isset($config_data['lang'])
964 && $GLOBALS['lang'] != $config_data['lang']
966 $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
969 // read language from settings
970 if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
971 $this->setCookie('pma_lang', $GLOBALS['lang']);
975 // save connection collation
976 if (isset($_COOKIE['pma_collation_connection'])
977 ||
isset($_POST['collation_connection'])
979 if ((! isset($config_data['collation_connection'])
980 && $GLOBALS['collation_connection'] != 'utf8_general_ci')
981 ||
isset($config_data['collation_connection'])
982 && $GLOBALS['collation_connection'] != $config_data['collation_connection']
986 'collation_connection',
987 $GLOBALS['collation_connection'],
992 // read collation from settings
993 if (isset($config_data['collation_connection'])) {
994 $GLOBALS['collation_connection']
995 = $config_data['collation_connection'];
997 'pma_collation_connection',
998 $GLOBALS['collation_connection']
1005 * Sets config value which is stored in user preferences (if available)
1008 * If user preferences are not yet initialized, option is applied to
1009 * global config and added to a update queue, which is processed
1010 * by {@link loadUserPreferences()}
1012 * @param string $cookie_name can be null
1013 * @param string $cfg_path configuration path
1014 * @param mixed $new_cfg_value new value
1015 * @param mixed $default_value default value
1019 function setUserValue($cookie_name, $cfg_path, $new_cfg_value,
1020 $default_value = null
1022 // use permanent user preferences if possible
1023 $prefs_type = $this->get('user_preferences');
1025 include_once './libraries/user_preferences.lib.php';
1026 if ($default_value === null) {
1027 $default_value = PMA_arrayRead($cfg_path, $this->default);
1029 PMA_persistOption($cfg_path, $new_cfg_value, $default_value);
1031 if ($prefs_type != 'db' && $cookie_name) {
1032 // fall back to cookies
1033 if ($default_value === null) {
1034 $default_value = PMA_arrayRead($cfg_path, $this->settings
);
1036 $this->setCookie($cookie_name, $new_cfg_value, $default_value);
1038 PMA_arrayWrite($cfg_path, $GLOBALS['cfg'], $new_cfg_value);
1039 PMA_arrayWrite($cfg_path, $this->settings
, $new_cfg_value);
1043 * Reads value stored by {@link setUserValue()}
1045 * @param string $cookie_name cookie name
1046 * @param mixed $cfg_value config value
1050 function getUserValue($cookie_name, $cfg_value)
1052 $cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]);
1053 $prefs_type = $this->get('user_preferences');
1054 if ($prefs_type == 'db') {
1055 // permanent user preferences value exists, remove cookie
1056 if ($cookie_exists) {
1057 $this->removeCookie($cookie_name);
1059 } else if ($cookie_exists) {
1060 return $_COOKIE[$cookie_name];
1062 // return value from $cfg array
1069 * @param string $source source
1073 function setSource($source)
1075 $this->source
= trim($source);
1079 * check config source
1081 * @return boolean whether source is valid or not
1083 function checkConfigSource()
1085 if (! $this->getSource()) {
1086 // no configuration file set at all
1090 if (! file_exists($this->getSource())) {
1091 $this->source_mtime
= 0;
1095 if (! is_readable($this->getSource())) {
1096 // manually check if file is readable
1097 // might be bug #3059806 Supporting running from CIFS/Samba shares
1100 $handle = @fopen
($this->getSource(), 'r');
1101 if ($handle !== false) {
1102 $contents = @fread
($handle, 1); // reading 1 byte is enough to test
1105 if ($contents === false) {
1106 $this->source_mtime
= 0;
1109 function_exists('__')
1110 ?
__('Existing configuration file (%s) is not readable.')
1111 : 'Existing configuration file (%s) is not readable.',
1123 * verifies the permissions on config file (if asked by configuration)
1124 * (must be called after config.inc.php has been merged)
1128 function checkPermissions()
1130 // Check for permissions (on platforms that support it):
1131 if ($this->get('CheckConfigurationPermissions')) {
1132 $perms = @fileperms
($this->getSource());
1133 if (!($perms === false) && ($perms & 2)) {
1134 // This check is normally done after loading configuration
1135 $this->checkWebServerOs();
1136 if ($this->get('PMA_IS_WINDOWS') == 0) {
1137 $this->source_mtime
= 0;
1138 /* Gettext is possibly still not loaded */
1139 if (function_exists('__')) {
1140 $msg = __('Wrong permissions on configuration file, should not be world writable!');
1142 $msg = 'Wrong permissions on configuration file, should not be world writable!';
1144 PMA_fatalError($msg);
1151 * returns specific config setting
1153 * @param string $setting config setting
1155 * @return mixed value
1157 function get($setting)
1159 if (isset($this->settings
[$setting])) {
1160 return $this->settings
[$setting];
1166 * sets configuration variable
1168 * @param string $setting configuration option
1169 * @param string $value new value for configuration option
1173 function set($setting, $value)
1175 if (! isset($this->settings
[$setting])
1176 ||
$this->settings
[$setting] != $value
1178 $this->settings
[$setting] = $value;
1179 $this->set_mtime
= time();
1184 * returns source for current config
1186 * @return string config source
1188 function getSource()
1190 return $this->source
;
1194 * returns a unique value to force a CSS reload if either the config
1195 * or the theme changes
1196 * must also check the pma_fontsize cookie in case there is no
1199 * @return int Summary of unix timestamps and fontsize,
1200 * to be unique on theme parameters change
1202 function getThemeUniqueValue()
1204 if (null !== $this->get('fontsize')) {
1205 $fontsize = intval($this->get('fontsize'));
1206 } elseif (isset($_COOKIE['pma_fontsize'])) {
1207 $fontsize = intval($_COOKIE['pma_fontsize']);
1213 $this->source_mtime +
1214 $this->default_source_mtime +
1215 $this->get('user_preferences_mtime') +
1216 $_SESSION['PMA_Theme']->mtime_info +
1217 $_SESSION['PMA_Theme']->filesize_info
);
1221 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
1222 * set properly and, depending on browsers, inserting or updating a
1227 function checkPmaAbsoluteUri()
1229 // Setup a default value to let the people and lazy sysadmins work anyway,
1230 // they'll get an error if the autodetect code doesn't work
1231 $pma_absolute_uri = $this->get('PmaAbsoluteUri');
1232 $is_https = $this->detectHttps();
1234 if (strlen($pma_absolute_uri) < 5) {
1237 // If we don't have scheme, we didn't have full URL so we need to
1239 if (empty($url['scheme'])) {
1242 $url['scheme'] = 'https';
1244 $url['scheme'] = 'http';
1248 if (PMA_getenv('HTTP_HOST')) {
1249 // Prepend the scheme before using parse_url() since this
1250 // is not part of the RFC2616 Host request-header
1251 $parsed_url = parse_url(
1252 $url['scheme'] . '://' . PMA_getenv('HTTP_HOST')
1254 if (!empty($parsed_url['host'])) {
1257 $url['host'] = PMA_getenv('HTTP_HOST');
1259 } elseif (PMA_getenv('SERVER_NAME')) {
1260 $url['host'] = PMA_getenv('SERVER_NAME');
1262 $this->error_pma_uri
= true;
1266 // If we didn't set port yet...
1267 if (empty($url['port']) && PMA_getenv('SERVER_PORT')) {
1268 $url['port'] = PMA_getenv('SERVER_PORT');
1271 // And finally the path could be already set from REQUEST_URI
1272 if (empty($url['path'])) {
1273 $path = parse_url($GLOBALS['PMA_PHP_SELF']);
1274 $url['path'] = $path['path'];
1278 // Make url from parts we have
1279 $pma_absolute_uri = $url['scheme'] . '://';
1280 // Was there user information?
1281 if (!empty($url['user'])) {
1282 $pma_absolute_uri .= $url['user'];
1283 if (!empty($url['pass'])) {
1284 $pma_absolute_uri .= ':' . $url['pass'];
1286 $pma_absolute_uri .= '@';
1289 $pma_absolute_uri .= $url['host'];
1290 // Add port, if it not the default one
1291 if (! empty($url['port'])
1292 && (($url['scheme'] == 'http' && $url['port'] != 80)
1293 ||
($url['scheme'] == 'https' && $url['port'] != 443))
1295 $pma_absolute_uri .= ':' . $url['port'];
1297 // And finally path, without script name, the 'a' is there not to
1298 // strip our directory, when path is only /pmadir/ without filename.
1299 // Backslashes returned by Windows have to be changed.
1300 // Only replace backslashes by forward slashes if on Windows,
1301 // as the backslash could be valid on a non-Windows system.
1302 $this->checkWebServerOs();
1303 if ($this->get('PMA_IS_WINDOWS') == 1) {
1304 $path = str_replace("\\", "/", dirname($url['path'] . 'a'));
1306 $path = dirname($url['path'] . 'a');
1309 // To work correctly within transformations overview:
1310 if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR
== '../../') {
1311 if ($this->get('PMA_IS_WINDOWS') == 1) {
1312 $path = str_replace("\\", "/", dirname(dirname($path)));
1314 $path = dirname(dirname($path));
1318 // PHP's dirname function would have returned a dot
1319 // when $path contains no slash
1323 // in vhost situations, there could be already an ending slash
1324 if (substr($path, -1) != '/') {
1327 $pma_absolute_uri .= $path;
1329 // We used to display a warning if PmaAbsoluteUri wasn't set, but now
1330 // the autodetect code works well enough that we don't display the
1331 // warning at all. The user can still set PmaAbsoluteUri manually.
1334 // The URI is specified, however users do often specify this
1335 // wrongly, so we try to fix this.
1337 // Adds a trailing slash et the end of the phpMyAdmin uri if it
1339 if (substr($pma_absolute_uri, -1) != '/') {
1340 $pma_absolute_uri .= '/';
1343 // If URI doesn't start with http:// or https://, we will add
1345 if (substr($pma_absolute_uri, 0, 7) != 'http://'
1346 && substr($pma_absolute_uri, 0, 8) != 'https://'
1349 = ($is_https ?
'https' : 'http')
1350 . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ?
'' : '//')
1351 . $pma_absolute_uri;
1354 $this->set('PmaAbsoluteUri', $pma_absolute_uri);
1358 * Converts currently used PmaAbsoluteUri to SSL based variant.
1360 * @return String witch adjusted URI
1362 function getSSLUri()
1365 $url = $this->get('PmaAbsoluteUri');
1366 // Parse current URL
1367 $parsed = parse_url($url);
1368 // In case parsing has failed do stupid string replacement
1369 if ($parsed === false) {
1370 // Replace http protocol
1371 return preg_replace('@^http:@', 'https:', $url);
1374 // Reconstruct URL using parsed parts
1375 if ($this->get('SSLPort')) {
1376 $port_number = $this->get('SSLPort');
1380 return 'https://' . $parsed['host'] . ':' . $port_number . $parsed['path'];
1384 * check selected collation_connection
1386 * @todo check validity of $_REQUEST['collation_connection']
1390 function checkCollationConnection()
1392 if (! empty($_REQUEST['collation_connection'])) {
1394 'collation_connection',
1395 strip_tags($_REQUEST['collation_connection'])
1401 * checks for font size configuration, and sets font size as requested by user
1405 function checkFontsize()
1409 if (isset($_GET['set_fontsize'])) {
1410 $new_fontsize = $_GET['set_fontsize'];
1411 } elseif (isset($_POST['set_fontsize'])) {
1412 $new_fontsize = $_POST['set_fontsize'];
1413 } elseif (isset($_COOKIE['pma_fontsize'])) {
1414 $new_fontsize = $_COOKIE['pma_fontsize'];
1417 if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) {
1418 $this->set('fontsize', $new_fontsize);
1419 } elseif (! $this->get('fontsize')) {
1420 // 80% would correspond to the default browser font size
1421 // of 16, but use 82% to help read the monoface font
1422 $this->set('fontsize', '82%');
1425 $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%');
1429 * checks if upload is enabled
1433 function checkUpload()
1435 if (ini_get('file_uploads')) {
1436 $this->set('enable_upload', true);
1437 // if set "php_admin_value file_uploads Off" in httpd.conf
1438 // ini_get() also returns the string "Off" in this case:
1439 if ('off' == strtolower(ini_get('file_uploads'))) {
1440 $this->set('enable_upload', false);
1443 $this->set('enable_upload', false);
1448 * Maximum upload size as limited by PHP
1449 * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
1451 * this section generates $max_upload_size in bytes
1455 function checkUploadSize()
1457 if (! $filesize = ini_get('upload_max_filesize')) {
1461 if ($postsize = ini_get('post_max_size')) {
1464 min(PMA_getRealSize($filesize), PMA_getRealSize($postsize))
1467 $this->set('max_upload_size', PMA_getRealSize($filesize));
1476 function checkIsHttps()
1478 $this->set('is_https', $this->isHttps());
1482 * Checks if protocol is https
1484 * This function checks if the https protocol is used in the PmaAbsoluteUri
1485 * configuration setting, as opposed to detectHttps() which checks if the
1486 * https protocol is used on the active connection.
1490 public function isHttps()
1492 static $is_https = null;
1494 if (null !== $is_https) {
1498 $url = parse_url($this->get('PmaAbsoluteUri'));
1500 if (isset($url['scheme']) && $url['scheme'] == 'https') {
1510 * Detects whether https appears to be used.
1512 * This function checks if the https protocol is used in the current connection
1513 * with the webserver, based on environment variables.
1514 * Please note that this just detects what we see, so
1515 * it completely ignores things like reverse proxies.
1519 function detectHttps()
1525 // At first we try to parse REQUEST_URI, it might contain full URL,
1526 if (PMA_getenv('REQUEST_URI')) {
1527 // produces E_WARNING if it cannot get parsed, e.g. '/foobar:/'
1528 $url = @parse_url
(PMA_getenv('REQUEST_URI'));
1529 if ($url === false) {
1534 // If we don't have scheme, we didn't have full URL so we need to
1536 if (empty($url['scheme'])) {
1538 if (PMA_getenv('HTTP_SCHEME')) {
1539 $url['scheme'] = PMA_getenv('HTTP_SCHEME');
1540 } elseif (PMA_getenv('HTTPS')
1541 && strtolower(PMA_getenv('HTTPS')) == 'on'
1543 $url['scheme'] = 'https';
1544 } elseif (PMA_getenv('HTTP_X_FORWARDED_PROTO')) {
1545 $url['scheme'] = strtolower(PMA_getenv('HTTP_X_FORWARDED_PROTO'));
1546 } elseif (PMA_getenv('HTTP_FRONT_END_HTTPS')
1547 && strtolower(PMA_getenv('HTTP_FRONT_END_HTTPS')) == 'on'
1549 $url['scheme'] = 'https';
1551 $url['scheme'] = 'http';
1555 if (isset($url['scheme']) && $url['scheme'] == 'https') {
1565 * detect correct cookie path
1569 function checkCookiePath()
1571 $this->set('cookie_path', $this->getCookiePath());
1579 public function getCookiePath()
1581 static $cookie_path = null;
1583 if (null !== $cookie_path && !defined('TESTSUITE')) {
1584 return $cookie_path;
1587 $parsed_url = parse_url($this->get('PmaAbsoluteUri'));
1589 $cookie_path = $parsed_url['path'];
1591 return $cookie_path;
1595 * enables backward compatibility
1601 $GLOBALS['cfg'] = $this->settings
;
1602 $GLOBALS['default_server'] = $this->default_server
;
1603 unset($this->default_server
);
1604 $GLOBALS['collation_connection'] = $this->get('collation_connection');
1605 $GLOBALS['is_upload'] = $this->get('enable_upload');
1606 $GLOBALS['max_upload_size'] = $this->get('max_upload_size');
1607 $GLOBALS['cookie_path'] = $this->get('cookie_path');
1608 $GLOBALS['is_https'] = $this->get('is_https');
1612 'PMA_THEME_VERSION',
1613 'PMA_THEME_GENERATION',
1614 'PMA_PHP_STR_VERSION',
1615 'PMA_PHP_INT_VERSION',
1620 'PMA_USR_BROWSER_VER',
1621 'PMA_USR_BROWSER_AGENT'
1624 foreach ($defines as $define) {
1625 if (! defined($define)) {
1626 define($define, $this->get($define));
1632 * returns options for font size selection
1634 * @param string $current_size current selected font size with unit
1636 * @return array selectable font sizes
1640 static protected function getFontsizeOptions($current_size = '82%')
1642 $unit = preg_replace('/[0-9.]*/', '', $current_size);
1643 $value = preg_replace('/[^0-9.]*/', '', $current_size);
1647 $options["$value"] = $value . $unit;
1649 if ($unit === '%') {
1653 } elseif ($unit === 'em') {
1657 } elseif ($unit === 'pt') {
1660 } elseif ($unit === 'px') {
1665 //unknown font size unit
1673 foreach ($factors as $key => $factor) {
1674 $option_inc = $value +
$factor;
1675 $option_dec = $value - $factor;
1676 while (count($options) < 21) {
1677 $options["$option_inc"] = $option_inc . $unit;
1678 if ($option_dec > $factors[0]) {
1679 $options["$option_dec"] = $option_dec . $unit;
1681 $option_inc +
= $factor;
1682 $option_dec -= $factor;
1683 if (isset($factors[$key +
1])
1684 && $option_inc >= $value +
$factors[$key +
1]
1695 * returns html selectbox for font sizes
1699 * @return string html selectbox
1701 static protected function getFontsizeSelection()
1703 $current_size = $GLOBALS['PMA_Config']->get('fontsize');
1704 // for the case when there is no config file (this is supported)
1705 if (empty($current_size)) {
1706 if (isset($_COOKIE['pma_fontsize'])) {
1707 $current_size = $_COOKIE['pma_fontsize'];
1709 $current_size = '82%';
1712 $options = PMA_Config
::getFontsizeOptions($current_size);
1714 $return = '<label for="select_fontsize">' . __('Font size')
1715 . ':</label>' . "\n"
1716 . '<select name="set_fontsize" id="select_fontsize"'
1717 . ' class="autosubmit">' . "\n";
1718 foreach ($options as $option) {
1719 $return .= '<option value="' . $option . '"';
1720 if ($option == $current_size) {
1721 $return .= ' selected="selected"';
1723 $return .= '>' . $option . '</option>' . "\n";
1725 $return .= '</select>';
1731 * return complete font size selection form
1735 * @return string html selectbox
1737 static public function getFontsizeForm()
1739 return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
1740 . ' method="get" action="index.php" class="disableAjax">' . "\n"
1741 . PMA_generate_common_hidden_inputs() . "\n"
1742 . PMA_Config
::getFontsizeSelection() . "\n"
1749 * @param string $cookie name of cookie to remove
1751 * @return boolean result of setcookie()
1753 function removeCookie($cookie)
1755 if (defined('TESTSUITE')) {
1756 if (isset($_COOKIE[$cookie])) {
1757 unset($_COOKIE[$cookie]);
1765 $this->getCookiePath(),
1772 * sets cookie if value is different from current cookie value,
1773 * or removes if value is equal to default
1775 * @param string $cookie name of cookie to remove
1776 * @param mixed $value new cookie value
1777 * @param string $default default value
1778 * @param int $validity validity of cookie in seconds (default is one month)
1779 * @param bool $httponly whether cookie is only for HTTP (and not for scripts)
1781 * @return boolean result of setcookie()
1783 function setCookie($cookie, $value, $default = null, $validity = null,
1786 if (strlen($value) && null !== $default && $value === $default) {
1787 // default value is used
1788 if (isset($_COOKIE[$cookie])) {
1790 return $this->removeCookie($cookie);
1795 if (! strlen($value) && isset($_COOKIE[$cookie])) {
1796 // remove cookie, value is empty
1797 return $this->removeCookie($cookie);
1800 if (! isset($_COOKIE[$cookie]) ||
$_COOKIE[$cookie] !== $value) {
1801 // set cookie with new value
1802 /* Calculate cookie validity */
1803 if ($validity === null) {
1804 $validity = time() +
2592000;
1805 } elseif ($validity == 0) {
1808 $validity = time() +
$validity;
1810 if (defined('TESTSUITE')) {
1811 $_COOKIE[$cookie] = $value;
1818 $this->getCookiePath(),
1825 // cookie has already $value as value