250 |
kaklik |
1 |
<?php |
|
|
2 |
/* $Id: Config.class.php,v 1.21.2.18.2.8 2006/08/22 17:00:00 lem9 Exp $ */ |
|
|
3 |
// vim: expandtab sw=4 ts=4 sts=4: |
|
|
4 |
|
|
|
5 |
class PMA_Config |
|
|
6 |
{ |
|
|
7 |
/** |
|
|
8 |
* @var string default config source |
|
|
9 |
*/ |
|
|
10 |
var $default_source = './libraries/config.default.php'; |
|
|
11 |
|
|
|
12 |
/** |
|
|
13 |
* @var array configuration settings |
|
|
14 |
*/ |
|
|
15 |
var $settings = array(); |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* @var string config source |
|
|
19 |
*/ |
|
|
20 |
var $source = ''; |
|
|
21 |
|
|
|
22 |
/** |
|
|
23 |
* @var int source modification time |
|
|
24 |
*/ |
|
|
25 |
var $source_mtime = 0; |
|
|
26 |
var $default_source_mtime = 0; |
|
|
27 |
|
|
|
28 |
/** |
|
|
29 |
* @var boolean |
|
|
30 |
*/ |
|
|
31 |
var $error_config_file = false; |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* @var boolean |
|
|
35 |
*/ |
|
|
36 |
var $error_config_default_file = false; |
|
|
37 |
|
|
|
38 |
/** |
|
|
39 |
* @var boolean |
|
|
40 |
*/ |
|
|
41 |
var $error_pma_uri = false; |
|
|
42 |
|
|
|
43 |
/** |
|
|
44 |
* @var array |
|
|
45 |
*/ |
|
|
46 |
var $default_server = array(); |
|
|
47 |
|
|
|
48 |
/** |
|
|
49 |
* @var boolean wether init is done or mot |
|
|
50 |
* set this to false to force some initial checks |
|
|
51 |
* like checking for required functions |
|
|
52 |
*/ |
|
|
53 |
var $done = false; |
|
|
54 |
|
|
|
55 |
/** |
|
|
56 |
* constructor |
|
|
57 |
* |
|
|
58 |
* @param string source to read config from |
|
|
59 |
*/ |
|
|
60 |
function __construct($source = null) |
|
|
61 |
{ |
|
|
62 |
$this->settings = array(); |
|
|
63 |
|
|
|
64 |
// functions need to refresh in case of config file changed goes in |
|
|
65 |
// PMA_Config::load() |
|
|
66 |
$this->load($source); |
|
|
67 |
|
|
|
68 |
// other settings, independant from config file, comes in |
|
|
69 |
$this->checkSystem(); |
|
|
70 |
|
|
|
71 |
$this->checkIsHttps(); |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
/** |
|
|
75 |
* sets system and application settings |
|
|
76 |
*/ |
|
|
77 |
function checkSystem() |
|
|
78 |
{ |
|
|
79 |
$this->set('PMA_VERSION', '2.8.2.4'); |
|
|
80 |
/** |
|
|
81 |
* @deprecated |
|
|
82 |
*/ |
|
|
83 |
$this->set('PMA_THEME_VERSION', 2); |
|
|
84 |
/** |
|
|
85 |
* @deprecated |
|
|
86 |
*/ |
|
|
87 |
$this->set('PMA_THEME_GENERATION', 2); |
|
|
88 |
|
|
|
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 |
/** |
|
|
100 |
* wether to use gzip output compression or not |
|
|
101 |
*/ |
|
|
102 |
function checkOutputCompression() |
|
|
103 |
{ |
|
|
104 |
// If zlib output compression is set in the php configuration file, no |
|
|
105 |
// output buffering should be run |
|
|
106 |
if ( @ini_get('zlib.output_compression') ) { |
|
|
107 |
$this->set('OBGzip', false); |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
// disable output-buffering (if set to 'auto') for IE6, else enable it. |
|
|
111 |
if ( strtolower($this->get('OBGzip')) == 'auto' ) { |
|
|
112 |
if ( $this->get('PMA_USR_BROWSER_AGENT') == 'IE' |
|
|
113 |
&& $this->get('PMA_USR_BROWSER_VER') >= 6 |
|
|
114 |
&& $this->get('PMA_USR_BROWSER_VER') < 7 ) { |
|
|
115 |
$this->set('OBGzip', false); |
|
|
116 |
} else { |
|
|
117 |
$this->set('OBGzip', true); |
|
|
118 |
} |
|
|
119 |
} |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
/** |
|
|
123 |
* Determines platform (OS), browser and version of the user |
|
|
124 |
* Based on a phpBuilder article: |
|
|
125 |
* @see http://www.phpbuilder.net/columns/tim20000821.php |
|
|
126 |
*/ |
|
|
127 |
function checkClient() |
|
|
128 |
{ |
|
|
129 |
if (PMA_getenv('HTTP_USER_AGENT')) { |
|
|
130 |
$HTTP_USER_AGENT = PMA_getenv('HTTP_USER_AGENT'); |
|
|
131 |
} elseif (!isset($HTTP_USER_AGENT)) { |
|
|
132 |
$HTTP_USER_AGENT = ''; |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
// 1. Platform |
|
|
136 |
if (strstr($HTTP_USER_AGENT, 'Win')) { |
|
|
137 |
$this->set('PMA_USR_OS', 'Win'); |
|
|
138 |
} elseif (strstr($HTTP_USER_AGENT, 'Mac')) { |
|
|
139 |
$this->set('PMA_USR_OS', 'Mac'); |
|
|
140 |
} elseif (strstr($HTTP_USER_AGENT, 'Linux')) { |
|
|
141 |
$this->set('PMA_USR_OS', 'Linux'); |
|
|
142 |
} elseif (strstr($HTTP_USER_AGENT, 'Unix')) { |
|
|
143 |
$this->set('PMA_USR_OS', 'Unix'); |
|
|
144 |
} elseif (strstr($HTTP_USER_AGENT, 'OS/2')) { |
|
|
145 |
$this->set('PMA_USR_OS', 'OS/2'); |
|
|
146 |
} else { |
|
|
147 |
$this->set('PMA_USR_OS', 'Other'); |
|
|
148 |
} |
|
|
149 |
|
|
|
150 |
// 2. browser and version |
|
|
151 |
// (must check everything else before Mozilla) |
|
|
152 |
|
|
|
153 |
if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) { |
|
|
154 |
$this->set('PMA_USR_BROWSER_VER', $log_version[2]); |
|
|
155 |
$this->set('PMA_USR_BROWSER_AGENT', 'OPERA'); |
|
|
156 |
} elseif (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) { |
|
|
157 |
$this->set('PMA_USR_BROWSER_VER', $log_version[1]); |
|
|
158 |
$this->set('PMA_USR_BROWSER_AGENT', 'IE'); |
|
|
159 |
} elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) { |
|
|
160 |
$this->set('PMA_USR_BROWSER_VER', $log_version[1]); |
|
|
161 |
$this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB'); |
|
|
162 |
//} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { |
|
|
163 |
// Konqueror 2.2.2 says Konqueror/2.2.2 |
|
|
164 |
// Konqueror 3.0.3 says Konqueror/3 |
|
|
165 |
} elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) { |
|
|
166 |
$this->set('PMA_USR_BROWSER_VER', $log_version[2]); |
|
|
167 |
$this->set('PMA_USR_BROWSER_AGENT', 'KONQUEROR'); |
|
|
168 |
} elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version) |
|
|
169 |
&& preg_match('@Safari/([0-9]*)@', $HTTP_USER_AGENT, $log_version2)) { |
|
|
170 |
$this->set('PMA_USR_BROWSER_VER', $log_version[1] . '.' . $log_version2[1]); |
|
|
171 |
$this->set('PMA_USR_BROWSER_AGENT', 'SAFARI'); |
|
|
172 |
} elseif (preg_match('@Mozilla/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) { |
|
|
173 |
$this->set('PMA_USR_BROWSER_VER', $log_version[1]); |
|
|
174 |
$this->set('PMA_USR_BROWSER_AGENT', 'MOZILLA'); |
|
|
175 |
} else { |
|
|
176 |
$this->set('PMA_USR_BROWSER_VER', 0); |
|
|
177 |
$this->set('PMA_USR_BROWSER_AGENT', 'OTHER'); |
|
|
178 |
} |
|
|
179 |
} |
|
|
180 |
|
|
|
181 |
/** |
|
|
182 |
* Whether GD2 is present |
|
|
183 |
*/ |
|
|
184 |
function checkGd2() |
|
|
185 |
{ |
|
|
186 |
if ( $this->get('GD2Available') == 'yes' ) { |
|
|
187 |
$this->set('PMA_IS_GD2', 1); |
|
|
188 |
} elseif ( $this->get('GD2Available') == 'no' ) { |
|
|
189 |
$this->set('PMA_IS_GD2', 0); |
|
|
190 |
} else { |
|
|
191 |
if (!@extension_loaded('gd')) { |
|
|
192 |
PMA_dl('gd'); |
|
|
193 |
} |
|
|
194 |
if (!@function_exists('imagecreatetruecolor')) { |
|
|
195 |
$this->set('PMA_IS_GD2', 0); |
|
|
196 |
} else { |
|
|
197 |
if (@function_exists('gd_info')) { |
|
|
198 |
$gd_nfo = gd_info(); |
|
|
199 |
if (strstr($gd_nfo["GD Version"], '2.')) { |
|
|
200 |
$this->set('PMA_IS_GD2', 1); |
|
|
201 |
} else { |
|
|
202 |
$this->set('PMA_IS_GD2', 0); |
|
|
203 |
} |
|
|
204 |
} else { |
|
|
205 |
/* We must do hard way... */ |
|
|
206 |
ob_start(); |
|
|
207 |
phpinfo(INFO_MODULES); /* Only modules */ |
|
|
208 |
$a = strip_tags(ob_get_contents()); |
|
|
209 |
ob_end_clean(); |
|
|
210 |
/* Get GD version string from phpinfo output */ |
|
|
211 |
if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) { |
|
|
212 |
if (strstr($v, '2.')) { |
|
|
213 |
$this->set('PMA_IS_GD2', 1); |
|
|
214 |
} else { |
|
|
215 |
$this->set('PMA_IS_GD2', 0); |
|
|
216 |
} |
|
|
217 |
} else { |
|
|
218 |
$this->set('PMA_IS_GD2', 0); |
|
|
219 |
} |
|
|
220 |
} |
|
|
221 |
} |
|
|
222 |
} |
|
|
223 |
} |
|
|
224 |
|
|
|
225 |
/** |
|
|
226 |
* Whether the Web server php is running on is IIS |
|
|
227 |
*/ |
|
|
228 |
function checkWebServer() |
|
|
229 |
{ |
|
|
230 |
if (PMA_getenv('SERVER_SOFTWARE') |
|
|
231 |
// some versions return Microsoft-IIS, some Microsoft/IIS |
|
|
232 |
// we could use a preg_match() but it's slower |
|
|
233 |
&& stristr(PMA_getenv('SERVER_SOFTWARE'), 'Microsoft') |
|
|
234 |
&& stristr(PMA_getenv('SERVER_SOFTWARE'), 'IIS')) { |
|
|
235 |
$this->set('PMA_IS_IIS', 1); |
|
|
236 |
} else { |
|
|
237 |
$this->set('PMA_IS_IIS', 0); |
|
|
238 |
} |
|
|
239 |
} |
|
|
240 |
|
|
|
241 |
/** |
|
|
242 |
* Whether the os php is running on is windows or not |
|
|
243 |
*/ |
|
|
244 |
function checkWebServerOs() |
|
|
245 |
{ |
|
|
246 |
// Default to Unix or Equiv |
|
|
247 |
$this->set('PMA_IS_WINDOWS', 0); |
|
|
248 |
// If PHP_OS is defined then continue |
|
|
249 |
if (defined('PHP_OS')) { |
|
|
250 |
if (stristr(PHP_OS, 'win') ) { |
|
|
251 |
// Is it some version of Windows |
|
|
252 |
$this->set('PMA_IS_WINDOWS', 1); |
|
|
253 |
} elseif (stristr(PHP_OS, 'OS/2')) { |
|
|
254 |
// Is it OS/2 (No file permissions like Windows) |
|
|
255 |
$this->set('PMA_IS_WINDOWS', 1); |
|
|
256 |
} |
|
|
257 |
} |
|
|
258 |
} |
|
|
259 |
|
|
|
260 |
/** |
|
|
261 |
* detects PHP version |
|
|
262 |
*/ |
|
|
263 |
function checkPhpVersion() |
|
|
264 |
{ |
|
|
265 |
$match = array(); |
|
|
266 |
if ( ! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', |
|
|
267 |
phpversion(), $match) ) { |
|
|
268 |
$result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@', |
|
|
269 |
phpversion(), $match); |
|
|
270 |
} |
|
|
271 |
if ( isset( $match ) && ! empty( $match[1] ) ) { |
|
|
272 |
if ( ! isset( $match[2] ) ) { |
|
|
273 |
$match[2] = 0; |
|
|
274 |
} |
|
|
275 |
if ( ! isset( $match[3] ) ) { |
|
|
276 |
$match[3] = 0; |
|
|
277 |
} |
|
|
278 |
$this->set('PMA_PHP_INT_VERSION', |
|
|
279 |
(int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3])); |
|
|
280 |
} else { |
|
|
281 |
$this->set('PMA_PHP_INT_VERSION', 0); |
|
|
282 |
} |
|
|
283 |
$this->set('PMA_PHP_STR_VERSION', phpversion()); |
|
|
284 |
} |
|
|
285 |
|
|
|
286 |
/** |
|
|
287 |
* re-init object after loadiong from session file |
|
|
288 |
* checks config file for changes and relaods if neccessary |
|
|
289 |
*/ |
|
|
290 |
function __wakeup() |
|
|
291 |
{ |
|
|
292 |
if (! $this->checkConfigSource() |
|
|
293 |
|| $this->source_mtime !== filemtime($this->getSource()) |
|
|
294 |
|| $this->default_source_mtime !== filemtime($this->default_source) |
|
|
295 |
|| $this->error_config_file |
|
|
296 |
|| $this->error_config_default_file) { |
|
|
297 |
$this->settings = array(); |
|
|
298 |
$this->load(); |
|
|
299 |
$this->checkSystem(); |
|
|
300 |
} |
|
|
301 |
// check for https needs to be done everytime, |
|
|
302 |
// as https and http uses same session so this info can not be stored |
|
|
303 |
// in session |
|
|
304 |
$this->checkIsHttps(); |
|
|
305 |
|
|
|
306 |
$this->checkCollationConnection(); |
|
|
307 |
} |
|
|
308 |
|
|
|
309 |
/** |
|
|
310 |
* loads default values from default source |
|
|
311 |
* |
|
|
312 |
* @uses file_exists() |
|
|
313 |
* @uses $this->default_source |
|
|
314 |
* @uses $this->error_config_default_file |
|
|
315 |
* @uses $this->settings |
|
|
316 |
* @return boolean success |
|
|
317 |
*/ |
|
|
318 |
function loadDefaults() |
|
|
319 |
{ |
|
|
320 |
$cfg = array(); |
|
|
321 |
if ( ! file_exists($this->default_source) ) { |
|
|
322 |
$this->error_config_default_file = true; |
|
|
323 |
return false; |
|
|
324 |
} |
|
|
325 |
include $this->default_source; |
|
|
326 |
|
|
|
327 |
$this->default_source_mtime = filemtime($this->default_source); |
|
|
328 |
|
|
|
329 |
$this->default_server = $cfg['Servers'][1]; |
|
|
330 |
unset( $cfg['Servers'] ); |
|
|
331 |
|
|
|
332 |
$this->settings = PMA_array_merge_recursive($this->settings, $cfg); |
|
|
333 |
|
|
|
334 |
$this->error_config_default_file = false; |
|
|
335 |
|
|
|
336 |
return true; |
|
|
337 |
} |
|
|
338 |
|
|
|
339 |
/** |
|
|
340 |
* loads configuration from $source, usally the config file |
|
|
341 |
* should be called on object creation and from __wakeup if config file |
|
|
342 |
* has changed |
|
|
343 |
* |
|
|
344 |
* @param string $source config file |
|
|
345 |
*/ |
|
|
346 |
function load($source = null) |
|
|
347 |
{ |
|
|
348 |
$this->loadDefaults(); |
|
|
349 |
|
|
|
350 |
if ( null !== $source ) { |
|
|
351 |
$this->setSource($source); |
|
|
352 |
} |
|
|
353 |
|
|
|
354 |
if ( ! $this->checkConfigSource() ) { |
|
|
355 |
return false; |
|
|
356 |
} |
|
|
357 |
|
|
|
358 |
$cfg = array(); |
|
|
359 |
|
|
|
360 |
/** |
|
|
361 |
* Parses the configuration file |
|
|
362 |
*/ |
|
|
363 |
$old_error_reporting = error_reporting(0); |
|
|
364 |
if ( function_exists('file_get_contents') ) { |
|
|
365 |
$eval_result = |
|
|
366 |
eval( '?>' . file_get_contents($this->getSource()) ); |
|
|
367 |
} else { |
|
|
368 |
$eval_result = |
|
|
369 |
eval( '?>' . implode("\n", file($this->getSource())) ); |
|
|
370 |
} |
|
|
371 |
error_reporting($old_error_reporting); |
|
|
372 |
|
|
|
373 |
if ( $eval_result === false ) { |
|
|
374 |
$this->error_config_file = true; |
|
|
375 |
} else { |
|
|
376 |
$this->error_config_file = false; |
|
|
377 |
$this->source_mtime = filemtime($this->getSource()); |
|
|
378 |
} |
|
|
379 |
|
|
|
380 |
/** |
|
|
381 |
* @TODO check validity of $_COOKIE['pma_collation_connection'] |
|
|
382 |
*/ |
|
|
383 |
if ( ! empty( $_COOKIE['pma_collation_connection'] ) ) { |
|
|
384 |
$this->set('collation_connection', |
|
|
385 |
strip_tags($_COOKIE['pma_collation_connection']) ); |
|
|
386 |
} else { |
|
|
387 |
$this->set('collation_connection', |
|
|
388 |
$this->get('DefaultConnectionCollation') ); |
|
|
389 |
} |
|
|
390 |
|
|
|
391 |
$this->checkCollationConnection(); |
|
|
392 |
//$this->checkPmaAbsoluteUri(); |
|
|
393 |
$this->settings = PMA_array_merge_recursive($this->settings, $cfg); |
|
|
394 |
return true; |
|
|
395 |
} |
|
|
396 |
|
|
|
397 |
/** |
|
|
398 |
* set source |
|
|
399 |
* @param string $source |
|
|
400 |
*/ |
|
|
401 |
function setSource($source) |
|
|
402 |
{ |
|
|
403 |
$this->source = trim($source); |
|
|
404 |
} |
|
|
405 |
|
|
|
406 |
/** |
|
|
407 |
* checks if the config folder still exists and terminates app if true |
|
|
408 |
*/ |
|
|
409 |
function checkConfigFolder() |
|
|
410 |
{ |
|
|
411 |
// Refuse to work while there still might be some world writable dir: |
|
|
412 |
if (is_dir('./config')) { |
|
|
413 |
die('Remove "./config" directory before using phpMyAdmin!'); |
|
|
414 |
} |
|
|
415 |
} |
|
|
416 |
|
|
|
417 |
/** |
|
|
418 |
* check config source |
|
|
419 |
* |
|
|
420 |
* @return boolean wether source is valid or not |
|
|
421 |
*/ |
|
|
422 |
function checkConfigSource() |
|
|
423 |
{ |
|
|
424 |
if (! $this->getSource()) { |
|
|
425 |
// no configuration file set at all |
|
|
426 |
return false; |
|
|
427 |
} |
|
|
428 |
|
|
|
429 |
if ( ! file_exists($this->getSource()) ) { |
|
|
430 |
// do not trigger error here |
|
|
431 |
// https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408 |
|
|
432 |
/* |
|
|
433 |
trigger_error( |
|
|
434 |
'phpMyAdmin-ERROR: unkown configuration source: ' . $source, |
|
|
435 |
E_USER_WARNING); |
|
|
436 |
*/ |
|
|
437 |
$this->source_mtime = 0; |
|
|
438 |
return false; |
|
|
439 |
} |
|
|
440 |
|
|
|
441 |
if ( ! is_readable($this->getSource()) ) { |
|
|
442 |
$this->source_mtime = 0; |
|
|
443 |
die('Existing configuration file (' . $this->getSource() . ') is not readable.'); |
|
|
444 |
} |
|
|
445 |
|
|
|
446 |
// Check for permissions (on platforms that support it): |
|
|
447 |
$perms = @fileperms($this->getSource()); |
|
|
448 |
if (!($perms === false) && ($perms & 2)) { |
|
|
449 |
// This check is normally done after loading configuration |
|
|
450 |
$this->checkWebServerOs(); |
|
|
451 |
if ($this->get('PMA_IS_WINDOWS') == 0) { |
|
|
452 |
$this->source_mtime = 0; |
|
|
453 |
die('Wrong permissions on configuration file, should not be world writable!'); |
|
|
454 |
} |
|
|
455 |
} |
|
|
456 |
|
|
|
457 |
return true; |
|
|
458 |
} |
|
|
459 |
|
|
|
460 |
/** |
|
|
461 |
* returns specific config setting |
|
|
462 |
* @param string $setting |
|
|
463 |
* @return mixed value |
|
|
464 |
*/ |
|
|
465 |
function get($setting) |
|
|
466 |
{ |
|
|
467 |
if ( isset( $this->settings[$setting] ) ) { |
|
|
468 |
return $this->settings[$setting]; |
|
|
469 |
} |
|
|
470 |
return null; |
|
|
471 |
} |
|
|
472 |
|
|
|
473 |
/** |
|
|
474 |
* sets configuration variable |
|
|
475 |
* |
|
|
476 |
* @uses $this->settings |
|
|
477 |
* @param string $setting configuration option |
|
|
478 |
* @param string $value new value for configuration option |
|
|
479 |
*/ |
|
|
480 |
function set($setting, $value) |
|
|
481 |
{ |
|
|
482 |
$this->settings[$setting] = $value; |
|
|
483 |
} |
|
|
484 |
|
|
|
485 |
/** |
|
|
486 |
* returns source for current config |
|
|
487 |
* @return string config source |
|
|
488 |
*/ |
|
|
489 |
function getSource() |
|
|
490 |
{ |
|
|
491 |
return $this->source; |
|
|
492 |
} |
|
|
493 |
|
|
|
494 |
/** |
|
|
495 |
* old PHP 4 style constructor |
|
|
496 |
* |
|
|
497 |
* @deprecated |
|
|
498 |
*/ |
|
|
499 |
function PMA_Config($source = null) |
|
|
500 |
{ |
|
|
501 |
$this->__construct($source); |
|
|
502 |
} |
|
|
503 |
|
|
|
504 |
/** |
|
|
505 |
* $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be |
|
|
506 |
* set properly and, depending on browsers, inserting or updating a |
|
|
507 |
* record might fail |
|
|
508 |
*/ |
|
|
509 |
function checkPmaAbsoluteUri() |
|
|
510 |
{ |
|
|
511 |
// Setup a default value to let the people and lazy syadmins work anyway, |
|
|
512 |
// they'll get an error if the autodetect code doesn't work |
|
|
513 |
$pma_absolute_uri = $this->get('PmaAbsoluteUri'); |
|
|
514 |
if ( strlen($pma_absolute_uri) < 1 ) { |
|
|
515 |
$url = array(); |
|
|
516 |
|
|
|
517 |
// At first we try to parse REQUEST_URI, it might contain full URI |
|
|
518 |
if (PMA_getenv('REQUEST_URI')) { |
|
|
519 |
$url = parse_url(PMA_getenv('REQUEST_URI')); |
|
|
520 |
} |
|
|
521 |
|
|
|
522 |
// If we don't have scheme, we didn't have full URL so we need to |
|
|
523 |
// dig deeper |
|
|
524 |
if ( empty( $url['scheme'] ) ) { |
|
|
525 |
// Scheme |
|
|
526 |
if (PMA_getenv('HTTP_SCHEME')) { |
|
|
527 |
$url['scheme'] = PMA_getenv('HTTP_SCHEME'); |
|
|
528 |
} else { |
|
|
529 |
$url['scheme'] = |
|
|
530 |
PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off' |
|
|
531 |
? 'https' |
|
|
532 |
: 'http'; |
|
|
533 |
} |
|
|
534 |
|
|
|
535 |
// Host and port |
|
|
536 |
if (PMA_getenv('HTTP_HOST')) { |
|
|
537 |
if (strpos(PMA_getenv('HTTP_HOST'), ':') !== false) { |
|
|
538 |
list( $url['host'], $url['port'] ) = |
|
|
539 |
explode(':', PMA_getenv('HTTP_HOST')); |
|
|
540 |
} else { |
|
|
541 |
$url['host'] = PMA_getenv('HTTP_HOST'); |
|
|
542 |
} |
|
|
543 |
} elseif (PMA_getenv('SERVER_NAME')) { |
|
|
544 |
$url['host'] = PMA_getenv('SERVER_NAME'); |
|
|
545 |
} else { |
|
|
546 |
$this->error_pma_uri = true; |
|
|
547 |
return false; |
|
|
548 |
} |
|
|
549 |
|
|
|
550 |
// If we didn't set port yet... |
|
|
551 |
if (empty($url['port']) && PMA_getenv('SERVER_PORT')) { |
|
|
552 |
$url['port'] = PMA_getenv('SERVER_PORT'); |
|
|
553 |
} |
|
|
554 |
|
|
|
555 |
// And finally the path could be already set from REQUEST_URI |
|
|
556 |
if ( empty( $url['path'] ) ) { |
|
|
557 |
if (PMA_getenv('PATH_INFO')) { |
|
|
558 |
$path = parse_url(PMA_getenv('PATH_INFO')); |
|
|
559 |
} else { |
|
|
560 |
// PHP_SELF in CGI often points to cgi executable, so use it |
|
|
561 |
// as last choice |
|
|
562 |
$path = parse_url(PMA_getenv('PHP_SELF')); |
|
|
563 |
} |
|
|
564 |
$url['path'] = $path['path']; |
|
|
565 |
} |
|
|
566 |
} |
|
|
567 |
|
|
|
568 |
// Make url from parts we have |
|
|
569 |
$pma_absolute_uri = $url['scheme'] . '://'; |
|
|
570 |
// Was there user information? |
|
|
571 |
if (!empty($url['user'])) { |
|
|
572 |
$pma_absolute_uri .= $url['user']; |
|
|
573 |
if (!empty($url['pass'])) { |
|
|
574 |
$pma_absolute_uri .= ':' . $url['pass']; |
|
|
575 |
} |
|
|
576 |
$pma_absolute_uri .= '@'; |
|
|
577 |
} |
|
|
578 |
// Add hostname |
|
|
579 |
$pma_absolute_uri .= $url['host']; |
|
|
580 |
// Add port, if it not the default one |
|
|
581 |
if ( ! empty( $url['port'] ) |
|
|
582 |
&& ( ( $url['scheme'] == 'http' && $url['port'] != 80 ) |
|
|
583 |
|| ( $url['scheme'] == 'https' && $url['port'] != 443 ) ) ) { |
|
|
584 |
$pma_absolute_uri .= ':' . $url['port']; |
|
|
585 |
} |
|
|
586 |
// And finally path, without script name, the 'a' is there not to |
|
|
587 |
// strip our directory, when path is only /pmadir/ without filename. |
|
|
588 |
// Backslashes returned by Windows have to be changed. |
|
|
589 |
// Only replace backslashes by forward slashes if on Windows, |
|
|
590 |
// as the backslash could be valid on a non-Windows system. |
|
|
591 |
if ($this->get('PMA_IS_WINDOWS') == 1) { |
|
|
592 |
$path = str_replace("\\", "/", dirname($url['path'] . 'a')); |
|
|
593 |
} else { |
|
|
594 |
$path = dirname($url['path'] . 'a'); |
|
|
595 |
} |
|
|
596 |
|
|
|
597 |
// To work correctly within transformations overview: |
|
|
598 |
if (defined('PMA_PATH_TO_BASEDIR') && PMA_PATH_TO_BASEDIR == '../../') { |
|
|
599 |
if ($this->get('PMA_IS_WINDOWS') == 1) { |
|
|
600 |
$path = str_replace("\\", "/", dirname(dirname($path))); |
|
|
601 |
} else { |
|
|
602 |
$path = dirname(dirname($path)); |
|
|
603 |
} |
|
|
604 |
} |
|
|
605 |
// in vhost situations, there could be already an ending slash |
|
|
606 |
if (substr($path, -1) != '/') { |
|
|
607 |
$path .= '/'; |
|
|
608 |
} |
|
|
609 |
$pma_absolute_uri .= $path; |
|
|
610 |
|
|
|
611 |
// We used to display a warning if PmaAbsoluteUri wasn't set, but now |
|
|
612 |
// the autodetect code works well enough that we don't display the |
|
|
613 |
// warning at all. The user can still set PmaAbsoluteUri manually. |
|
|
614 |
// See |
|
|
615 |
// http://sf.net/tracker/?func=detail&aid=1257134&group_id=23067&atid=377411 |
|
|
616 |
|
|
|
617 |
} else { |
|
|
618 |
// The URI is specified, however users do often specify this |
|
|
619 |
// wrongly, so we try to fix this. |
|
|
620 |
|
|
|
621 |
// Adds a trailing slash et the end of the phpMyAdmin uri if it |
|
|
622 |
// does not exist. |
|
|
623 |
if (substr($pma_absolute_uri, -1) != '/') { |
|
|
624 |
$pma_absolute_uri .= '/'; |
|
|
625 |
} |
|
|
626 |
|
|
|
627 |
// If URI doesn't start with http:// or https://, we will add |
|
|
628 |
// this. |
|
|
629 |
if ( substr($pma_absolute_uri, 0, 7) != 'http://' |
|
|
630 |
&& substr($pma_absolute_uri, 0, 8) != 'https://' ) { |
|
|
631 |
$pma_absolute_uri = |
|
|
632 |
(PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off' |
|
|
633 |
? 'https' |
|
|
634 |
: 'http') |
|
|
635 |
. ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//') |
|
|
636 |
. $pma_absolute_uri; |
|
|
637 |
} |
|
|
638 |
} |
|
|
639 |
|
|
|
640 |
$this->set('PmaAbsoluteUri', $pma_absolute_uri); |
|
|
641 |
} |
|
|
642 |
|
|
|
643 |
/** |
|
|
644 |
* check selected collation_connection |
|
|
645 |
* @TODO check validity of $_REQUEST['collation_connection'] |
|
|
646 |
*/ |
|
|
647 |
function checkCollationConnection() |
|
|
648 |
{ |
|
|
649 |
// (could be improved by executing it after the MySQL connection only if |
|
|
650 |
// PMA_MYSQL_INT_VERSION >= 40100 ) |
|
|
651 |
if ( ! empty( $_REQUEST['collation_connection'] ) ) { |
|
|
652 |
$this->set('collation_connection', |
|
|
653 |
strip_tags($_REQUEST['collation_connection']) ); |
|
|
654 |
} |
|
|
655 |
} |
|
|
656 |
|
|
|
657 |
/** |
|
|
658 |
* checks if upload is enabled |
|
|
659 |
* |
|
|
660 |
*/ |
|
|
661 |
function checkUpload() |
|
|
662 |
{ |
|
|
663 |
$this->set('enable_upload', true); |
|
|
664 |
if ( strtolower(@ini_get('file_uploads')) == 'off' |
|
|
665 |
|| @ini_get('file_uploads') == 0 ) { |
|
|
666 |
$this->set('enable_upload', false); |
|
|
667 |
} |
|
|
668 |
} |
|
|
669 |
|
|
|
670 |
/** |
|
|
671 |
* Maximum upload size as limited by PHP |
|
|
672 |
* Used with permission from Moodle (http://moodle.org) by Martin Dougiamas |
|
|
673 |
* |
|
|
674 |
* this section generates $max_upload_size in bytes |
|
|
675 |
*/ |
|
|
676 |
function checkUploadSize() |
|
|
677 |
{ |
|
|
678 |
if ( ! $filesize = ini_get('upload_max_filesize') ) { |
|
|
679 |
$filesize = "5M"; |
|
|
680 |
} |
|
|
681 |
|
|
|
682 |
if ( $postsize = ini_get('post_max_size') ) { |
|
|
683 |
$this->set('max_upload_size', |
|
|
684 |
min(get_real_size($filesize), get_real_size($postsize)) ); |
|
|
685 |
} else { |
|
|
686 |
$this->set('max_upload_size', get_real_size($filesize)); |
|
|
687 |
} |
|
|
688 |
} |
|
|
689 |
|
|
|
690 |
/** |
|
|
691 |
* check for https |
|
|
692 |
*/ |
|
|
693 |
function checkIsHttps() |
|
|
694 |
{ |
|
|
695 |
$this->set('is_https', PMA_Config::isHttps()); |
|
|
696 |
} |
|
|
697 |
|
|
|
698 |
/** |
|
|
699 |
* @static |
|
|
700 |
*/ |
|
|
701 |
function isHttps() |
|
|
702 |
{ |
|
|
703 |
$is_https = false; |
|
|
704 |
|
|
|
705 |
$url = array(); |
|
|
706 |
|
|
|
707 |
// At first we try to parse REQUEST_URI, it might contain full URI |
|
|
708 |
if (PMA_getenv('REQUEST_URI')) { |
|
|
709 |
$url = parse_url(PMA_getenv('REQUEST_URI')); |
|
|
710 |
} |
|
|
711 |
|
|
|
712 |
// If we don't have scheme, we didn't have full URL so we need to |
|
|
713 |
// dig deeper |
|
|
714 |
if ( empty( $url['scheme'] ) ) { |
|
|
715 |
// Scheme |
|
|
716 |
if (PMA_getenv('HTTP_SCHEME')) { |
|
|
717 |
$url['scheme'] = PMA_getenv('HTTP_SCHEME'); |
|
|
718 |
} else { |
|
|
719 |
$url['scheme'] = |
|
|
720 |
PMA_getenv('HTTPS') && strtolower(PMA_getenv('HTTPS')) != 'off' |
|
|
721 |
? 'https' |
|
|
722 |
: 'http'; |
|
|
723 |
} |
|
|
724 |
} |
|
|
725 |
|
|
|
726 |
if ( isset( $url['scheme'] ) |
|
|
727 |
&& $url['scheme'] == 'https' ) { |
|
|
728 |
$is_https = true; |
|
|
729 |
} else { |
|
|
730 |
$is_https = false; |
|
|
731 |
} |
|
|
732 |
|
|
|
733 |
return $is_https; |
|
|
734 |
} |
|
|
735 |
|
|
|
736 |
/** |
|
|
737 |
* detect correct cookie path |
|
|
738 |
*/ |
|
|
739 |
function checkCookiePath() |
|
|
740 |
{ |
|
|
741 |
$this->set('cookie_path', PMA_Config::getCookiePath()); |
|
|
742 |
} |
|
|
743 |
|
|
|
744 |
/** |
|
|
745 |
* @static |
|
|
746 |
*/ |
|
|
747 |
function getCookiePath() |
|
|
748 |
{ |
|
|
749 |
static $cookie_path = null; |
|
|
750 |
|
|
|
751 |
if ( null !== $cookie_path ) { |
|
|
752 |
return $cookie_path; |
|
|
753 |
} |
|
|
754 |
|
|
|
755 |
$url = ''; |
|
|
756 |
|
|
|
757 |
if (PMA_getenv('REQUEST_URI')) { |
|
|
758 |
$url = PMA_getenv('REQUEST_URI'); |
|
|
759 |
} |
|
|
760 |
|
|
|
761 |
// If we don't have path |
|
|
762 |
if (empty($url)) { |
|
|
763 |
if (PMA_getenv('PATH_INFO')) { |
|
|
764 |
$url = PMA_getenv('PATH_INFO'); |
|
|
765 |
} elseif (PMA_getenv('PHP_SELF')) { |
|
|
766 |
// PHP_SELF in CGI often points to cgi executable, so use it |
|
|
767 |
// as last choice |
|
|
768 |
$url = PMA_getenv('PHP_SELF'); |
|
|
769 |
} elseif (PMA_getenv('SCRIPT_NAME')) { |
|
|
770 |
$url = PMA_getenv('PHP_SELF'); |
|
|
771 |
} |
|
|
772 |
} |
|
|
773 |
|
|
|
774 |
$url = parse_url($url); |
|
|
775 |
|
|
|
776 |
$cookie_path = substr($url['path'], 0, strrpos($url['path'], '/')) . '/'; |
|
|
777 |
|
|
|
778 |
return $cookie_path; |
|
|
779 |
} |
|
|
780 |
|
|
|
781 |
/** |
|
|
782 |
* enables backward compatibility |
|
|
783 |
*/ |
|
|
784 |
function enableBc() |
|
|
785 |
{ |
|
|
786 |
$GLOBALS['cfg'] =& $this->settings; |
|
|
787 |
$GLOBALS['default_server'] =& $this->default_server; |
|
|
788 |
$GLOBALS['collation_connection'] = $this->get('collation_connection'); |
|
|
789 |
$GLOBALS['is_upload'] = $this->get('enable_upload'); |
|
|
790 |
$GLOBALS['max_upload_size'] = $this->get('max_upload_size'); |
|
|
791 |
$GLOBALS['cookie_path'] = $this->get('cookie_path'); |
|
|
792 |
$GLOBALS['is_https'] = $this->get('is_https'); |
|
|
793 |
|
|
|
794 |
$defines = array( |
|
|
795 |
'PMA_VERSION', |
|
|
796 |
'PMA_THEME_VERSION', |
|
|
797 |
'PMA_THEME_GENERATION', |
|
|
798 |
'PMA_PHP_STR_VERSION', |
|
|
799 |
'PMA_PHP_INT_VERSION', |
|
|
800 |
'PMA_IS_WINDOWS', |
|
|
801 |
'PMA_IS_IIS', |
|
|
802 |
'PMA_IS_GD2', |
|
|
803 |
'PMA_USR_OS', |
|
|
804 |
'PMA_USR_BROWSER_VER', |
|
|
805 |
'PMA_USR_BROWSER_AGENT', |
|
|
806 |
); |
|
|
807 |
|
|
|
808 |
foreach ( $defines as $define ) { |
|
|
809 |
if ( ! defined($define) ) { |
|
|
810 |
define($define, $this->get($define)); |
|
|
811 |
} |
|
|
812 |
} |
|
|
813 |
} |
|
|
814 |
|
|
|
815 |
/** |
|
|
816 |
* @todo finish |
|
|
817 |
*/ |
|
|
818 |
function save() {} |
|
|
819 |
} |
|
|
820 |
?> |