forked from NewEraCracker/php-work
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_compatibility.php
More file actions
697 lines (597 loc) · 19.6 KB
/
Copy pathcheck_compatibility.php
File metadata and controls
697 lines (597 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<?php
/*
Helps checking compatibility with IP.Board and other scripts
@author NewEraCracker
@version 2.0.1
@date 2013/02/19
@license Public Domain
Inspired by all noobish hosting companies around the world
Greetz to:
- ForumScriptz Team
- Matt Mecham
- Xenforo Developers
*/
/* -------------
Configuration
------------- */
// MySQL settings
$mysql_enable_check = true;
$mysql_host = '127.0.0.1';
$mysql_port = '3306';
$mysql_username = '';
$mysql_password = '';
// Session settings
$session_enable_extended_check = true;
/* ----------------
Global variables
---------------- */
$errors = array();
/* --------------------------
Functions for calculations
-------------------------- */
/**
* Returns the absolute value of integer
*/
function intAbs($number)
{
return (int)str_replace('-','',(string)$number);
}
/**
* Return the value of a PHP configuration option
*/
function improvedIniGet($varname)
{
if( function_exists('ini_get') )
return @ini_get($varname);
if( function_exists('get_cfg_var') )
return @get_cfg_var($varname);
}
/**
* Get the integer value of a variable
*/
function improvedIntVal($value)
{
$value = (string)$value;
$new = '';
$found = false;
// Build
for( $i=0; $i<strlen($value); $i++ )
{
// Found a number ?
if( is_numeric($value[$i]) )
{
$found = true;
$new .= $value[$i];
}
elseif($found)
{
// We already have numbers and we don't like trash.
break;
}
}
$value = $new;
// Return the result
return (int)$value;
}
/**
* Returns the MySQL version integer from a MySQL version string
*/
function mySqlVersionStringToInt($version)
{
$version = explode('.',$version);
$version = array_map('improvedIntVal',$version);
$version = $version[0]*10000 + $version[1]*100 + $version[2];
return $version;
}
/**
* Returns the MySQL version string from a MySQL version integer
*/
function mySqlVersionIntToString($version)
{
$version_string = '';
$version_remain = (int)($version);
foreach( array(10000,100,1) as $value)
{
$version_bit = (int)($version_remain/$value);
$version_remain = (int)($version_remain-($version_bit*$value));
$version_string .= $version_bit.'.';
}
return rtrim($version_string,'.');
}
/* -------------------
Functions for tests
------------------- */
/**
* Detects if ini parser handling is problematic
*/
function is_ini_parser_problem($disabled_functions)
{
// Function available since PHP 4
$ini_parser_functions = array('parse_ini_file');
// Function available since PHP 5.3
if( version_compare(PHP_VERSION, '5.3') >= 0 )
$ini_parser_functions = array_merge($ini_parser_functions, array('parse_ini_string'));
// Problem counter
$problem = 0;
// Default error message
$error_message = 'Problematic ini parser detected, make sure ';
// Test it
foreach( $ini_parser_functions as $function )
{
if( !function_exists($function) || in_array($function, $disabled_functions) )
{
// Add problematic function to message
$error_message .= ($problem == 0 ? '' : 'and ').$function.' ';
// Increment problem counter
++$problem;
}
}
// Generate message if problem is detected
switch($problem)
{
case 0:
return null;
case 1:
$error_message .= 'function exist and is enabled.';
break;
default:
$error_message .= 'functions exist and are enabled.';
break;
}
return $error_message;
}
/**
* Detects if float handling is problematic
*/
function is_float_problem()
{
$num1 = 2009010200.01;
$num2 = 2009010200.02;
if((string)$num1 === (string)$num2 || $num1 === $num2 || $num2 <= (string)$num1)
return 'Detected unexpected problem in handling of PHP float numbers.';
return null;
}
/**
* Detects if input variables handling is problematic
*/
function is_max_input_vars_problem()
{
// max_input_vars was introduced in PHP 5.3.9
if( version_compare(PHP_VERSION, '5.3.9') >= 0 && (improvedIniGet('max_input_vars') < 4096) )
return 'Problematic max_input_vars setting detected, please set it to 4096 or higher.';
// less than PHP 5.3.9, no problem here
return null;
}
/**
* Detects if mbstring extension is problematic
*/
function is_mbstring_problem()
{
if( extension_loaded('mbstring') && improvedIniGet('mbstring.func_overload') )
return 'Extension Multibyte String may break data when mbstring.func_overload setting is enabled. Please disable this setting.';
return null;
}
/**
* Detects if timezone handling is problematic
*/
function is_timezone_problem()
{
// check if date is loaded and DateTimeZone class exists (this should be true since 5.2.0)
if( extension_loaded('date') && class_exists('DateTimeZone') )
{
$error_message = 'Invalid or empty date.timezone setting detected.';
$status = improvedIniGet('date.timezone');
if( !empty($status) )
{
try
{
$tz = new DateTimeZone($status);
}
catch(Exception $e)
{
// timezone is invalid
return $error_message;
}
// timezone is set and working
return null;
}
// timezone is empty
return $error_message;
}
// extension isn't loaded so we don't check
return null;
}
/**
* Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
* Known fixed with PHP 5.2.9 + libxml2-2.7.3
* @see http://bugs.php.net/bug.php?id=45996
*/
function phpXmlBugTester()
{
if( extension_loaded('xml') )
{
$error_message = 'A bug has been detected in PHP+libxml2 which breaks XML input.';
class XmlBugTester
{
private $parsedData = '';
public $bad = true;
public function __construct()
{
$charData = '<b>c</b>';
$xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
$parser = xml_parser_create();
xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
$parsedOk = xml_parse( $parser, $xml, true );
$this->bad = ( !$parsedOk || ($this->parsedData != $charData) );
}
public function chardata( $parser, $data )
{
$this->parsedData .= $data;
}
}
$xmlBugTester = new XmlBugTester();
if($xmlBugTester->bad)
return $error_message;
}
// extension isn't loaded so we don't check
return null;
}
/**
* Test for PHP bug #50394 (PHP 5.3.x conversion to null only, not 5.2.x)
* @see http://bugs.php.net/bug.php?id=50394
*/
function phpRefCallBugTester()
{
$error_message = 'A regression (bug #50394) has been detected in your PHP version. Please upgrade or downgrade your PHP installation.';
class RefCallBugTester
{
public $bad = true;
function __call( $name, $args )
{
$old = error_reporting( E_ALL & ~E_WARNING );
call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
error_reporting( $old );
}
function checkForBrokenRef( &$var )
{
if( $var )
$this->bad = false;
}
function execute()
{
$var = true;
call_user_func_array( array( $this, 'foo' ), array( &$var ) );
}
}
$refCallBugTester = new RefCallBugTester();
$refCallBugTester->execute();
if($refCallBugTester->bad)
return $error_message;
return null;
}
/* ---------
Check PHP
--------- */
// Check for lower than 5.2.9
if(version_compare(PHP_VERSION, '5.2.9') < 0)
$errors[] = 'PHP 5.2.9 or newer is required. '.PHP_VERSION.' does not meet this requirement.';
// If 5.4, check for lower than 5.4.5
elseif(version_compare(PHP_VERSION, '5.4') >= 0 && version_compare(PHP_VERSION, '5.4.5') < 0)
$errors[] = 'PHP 5.4.5 or newer is required. '.PHP_VERSION.' does not meet this requirement.';
// If 5.3, check for lower than 5.3.5
elseif(version_compare(PHP_VERSION, '5.3') >= 0 && version_compare(PHP_VERSION, '5.3.5') < 0)
$errors[] = 'PHP 5.3.5 or newer is required. '.PHP_VERSION.' does not meet this requirement.';
// Functions to be enabled
$disabled_functions = array_map('trim', explode(',',improvedIniGet('disable_functions')) );
$disabled_functions = array_merge($disabled_functions, array_map('trim', explode(',',improvedIniGet('suhosin.executor.func.blacklist'))));
$functions_required = array('php_uname', 'base64_decode', 'fpassthru', 'get_cfg_var', 'ini_set', 'ini_get');
foreach( $functions_required as $test )
{
if( !function_exists($test) || in_array($test, $disabled_functions) )
$errors[] = 'Function '.$test.' is required to be enabled in PHP.';
}
// Settings
$php_checks = array(
is_ini_parser_problem($disabled_functions),
is_float_problem(),
is_max_input_vars_problem(),
is_mbstring_problem(),
is_timezone_problem(),
phpXmlBugTester(),
phpRefCallBugTester(),
array( in_array('eval',$disabled_functions), 'Language construct eval is required to be enabled in PHP.'),
array( improvedIniGet('magic_quotes_gpc') || @get_magic_quotes_gpc(), 'Setting magic_quotes_gpc has been found enabled in your php.ini. Disable it for better functionality.'),
array( improvedIniGet('safe_mode'), 'PHP must not be running in safe_mode. Disable the PHP safe_mode setting.'),
array( improvedIniGet('output_handler') == 'ob_gzhandler', 'PHP must not be running with output_handler set to ob_gzhandler. Disable this setting.'),
array( improvedIniGet('zlib.output_compression' ), 'PHP must not be running with zlib.output_compression enabled. Disable this setting.'),
array( improvedIniGet('zend.ze1_compatibility_mode'), 'zend.ze1_compatibility_mode is set to On. This may cause some strange problems. It is strongly suggested to turn this value to Off.'),
);
foreach( $php_checks as $test )
{
if( is_array($test) )
{
// For tests that return true if error
if($test[0])
$errors[] = $test[1];
}
else
{
// For tests that return error message
if($test != null)
$errors[] = $test;
}
}
// Upload dir
$upload_dir = improvedIniGet('upload_tmp_dir') ? improvedIniGet('upload_tmp_dir') : @sys_get_temp_dir();
if( !empty($upload_dir) && !is_writable($upload_dir) ) // Make sure upload dir is writable
$errors[] = 'Your upload temporary directory '.htmlspecialchars($upload_dir).' is not writable. Please fix this issue.';
// Session path
$sessionpath = @session_save_path();
if( strpos($sessionpath, ';') !== false ) // http://www.php.net/manual/en/function.session-save-path.php#50355
$sessionpath = substr($sessionpath, strpos($sessionpath, ';')+1);
if( !empty($sessionpath) && !is_writable($sessionpath) ) // Make sure session path is writable
$errors[] = 'Your session path '.htmlspecialchars($sessionpath).' is not writable. Please fix this issue.';
// Check PHP extensions
$required_extensions = array(
array( 'ctype', 'Ctype' ),
array( 'curl', 'cURL' ),
array( 'dom', 'Document Object Model' ),
array( 'iconv', 'Iconv' ),
array( 'gd', 'GD Library' ),
array( 'json', 'JSON' ),
array( 'mbstring', 'Multibyte String' ),
array( 'mysql', 'MySQL' ),
array( 'mysqli', 'MySQLi' ),
array( 'openssl', 'OpenSSL' ),
array( 'pcre', 'Perl-Compatible Regular Expressions' ),
array( 'reflection', 'Reflection Class' ),
array( 'session', 'Session' ),
array( 'spl', 'SPL' ),
array( 'xml', 'XML Parser' ),
array( 'zip', 'Zip' ),
array( 'zlib', 'Zlib' ),
);
foreach( $required_extensions as $test )
{
if( !extension_loaded($test[0]) )
$errors[] = 'The required PHP extension "'.$test[1].'" could not be found. You need to install/enable this extension.';
}
// Check cURL
if( extension_loaded('curl') )
{
$curlFound = 'The required PHP extension "cURL" was found';
// Some hosts have cURL but disable its functions. Lets check for that.
$curlFuctions = array(
'curl_close', 'curl_copy_handle', 'curl_errno', 'curl_error', 'curl_exec', 'curl_getinfo',
'curl_init', 'curl_multi_add_handle', 'curl_multi_close', 'curl_multi_exec', 'curl_multi_getcontent',
'curl_multi_info_read', 'curl_multi_init', 'curl_multi_remove_handle', 'curl_multi_select',
'curl_setopt_array', 'curl_setopt', 'curl_version',
);
foreach( $curlFuctions as $test )
if(!function_exists($test) || in_array($test, $disabled_functions))
$errors[] = $curlFound.', but function '.$test.' is disabled. Please enable it.';
// We need SSL and ZLIB support
if( $curlVersion = @curl_version() )
{
$curlBitFields = array( 'CURL_VERSION_SSL', 'CURL_VERSION_LIBZ' );
$curlBitFriendly = array( 'SSL', 'ZLIB' );
foreach($curlBitFields as $arr_key => $feature)
{
$test = $curlBitFriendly[$arr_key];
if( !($curlVersion['features'] && constant($feature)) )
$errors[] = $curlFound.', but '.$test.' support is missing. Please add support for '.$test.' in cURL.';
}
}
}
// Check GD
if( function_exists('gd_info') )
{
$gdFound = 'The required PHP extension "GD Library" was found';
// We need GIF, JPEG and PNG support
$required_gd = array(
array( 'imagecreatefromgif', 'GIF' ),
array( 'imagecreatefromjpeg', 'JPEG' ),
array( 'imagecreatefrompng', 'PNG' ),
);
foreach( $required_gd as $test )
if( !function_exists($test[0]) )
$errors[] = $gdFound.', but '.$test[1].' support is missing. Please add support for '.$test[1].' images in GD Library.';
// We need GD 2 and freetype support
$gdInfo = @gd_info();
if( @$gdInfo["GD Version"] && !strstr($gdInfo["GD Version"],'2.') )
$errors[] = $gdFound.', but GD Version is older than v2. Please fix this issue.';
if( ! @$gdInfo['FreeType Support'] )
$errors[] = $gdFound.', but FreeType support is missing. Please add support for this.';
}
// Check Session
if( extension_loaded('session') )
{
$sessionFound = 'The required PHP extension "Session" was found';
if( improvedIniGet('session.use_trans_sid') )
$errors[] = $sessionFound.', but session.use_trans_sid is enabled. Please disable this setting for security reasons.';
if( ! improvedIniGet('session.use_only_cookies') )
$errors[] = $sessionFound.', but session.use_only_cookies is disabled. Please enable this setting for security reasons.';
if( $session_enable_extended_check )
{
if( improvedIniGet('session.hash_bits_per_character') < 5 )
$errors[] = $sessionFound.', but session.hash_bits_per_character is set to a low value. Please set it to 5 for security reasons.';
if( ! improvedIniGet('session.hash_function') )
$errors[] = $sessionFound.', but session.hash_function is set to a weak value. Please set it to 1 for security reasons.';
}
}
// Check Ioncube
if( function_exists('ioncube_loader_version') )
{
if( !function_exists('ioncube_loader_iversion') )
$errors[] = 'You have a VERY old version of IonCube Loaders which is known to cause problems.';
elseif(ioncube_loader_iversion() < 40202 && version_compare(PHP_VERSION, '5.4') >= 0)
$errors[] = 'You have an old version of IonCube Loaders (4.2.1 or earlier) which is known to cause problems with PHP 5.4.';
elseif(ioncube_loader_iversion() < 40007 && version_compare(PHP_VERSION, '5.3') >= 0)
$errors[] = 'You have an old version of IonCube Loaders (4.0.6 or earlier) which is known to cause problems with PHP 5.3.';
}
else
{
$errors[] = 'You do not seem to have IonCube Loaders installed.';
}
// Check eAccelerator if installed
if( function_exists('eaccelerator_info') )
{
$ea_info = eaccelerator_info();
if(version_compare($ea_info['version'], '0.9.9') <= 0)
{
// Only 1.0-dev are known to work
$errors[] = 'You have an old version of eAccelerator (earlier than 1.0) which is known to cause problems.';
}
}
// Check RAM limits
if( $memLimit = improvedIniGet('memory_limit') )
{
$memLimit = trim($memLimit);
$last = strtolower($memLimit[strlen($memLimit)-1]);
switch($last) {
case 'g':
$memLimit *= 1024;
case 'm':
$memLimit *= 1024;
case 'k':
$memLimit *= 1024;
}
$recLimit = (128*1024*1024);
if($memLimit < $recLimit)
$errors[] = 'Memory Limit: 128M is required. Please increase this setting.';
}
/* ----------------
Suhosin Settings
---------------- */
if( extension_loaded('suhosin') )
{
// Value has to be false or zero to pass tests
$test_false = array(
'suhosin.mail.protect',
'suhosin.sql.bailout_on_error',
'suhosin.cookie.encrypt',
'suhosin.session.encrypt'
);
// Value has to be the same or higher to pass tests
$test_values = array(
array( 'suhosin.cookie.max_name_length', 64),
array( 'suhosin.cookie.max_totalname_length', 256),
array( 'suhosin.cookie.max_value_length', 10000),
array( 'suhosin.get.max_name_length', 512 ),
array( 'suhosin.get.max_totalname_length', 512 ),
array( 'suhosin.get.max_value_length', 2048 ),
array( 'suhosin.post.max_array_index_length', 256 ),
array( 'suhosin.post.max_name_length', 512 ),
array( 'suhosin.post.max_totalname_length', 8192 ),
array( 'suhosin.post.max_vars', 4096 ),
array( 'suhosin.post.max_value_length', 1000000 ),
array( 'suhosin.request.max_array_index_length', 256 ),
array( 'suhosin.request.max_totalname_length', 8192 ),
array( 'suhosin.request.max_vars', 4096 ),
array( 'suhosin.request.max_value_length', 1000000 ),
array( 'suhosin.request.max_varname_length', 512 )
);
// Value has to be zero (protection disabled), equal or higher than x to pass
$test_zero_or_higher_than_value = array(
array( 'suhosin.executor.max_depth', 10000),
array( 'suhosin.executor.include.max_traversal', 6),
);
foreach($test_false as $test)
{
if( improvedIniGet($test) )
{
if( $test == 'suhosin.mail.protect' )
$errors[] = $test.' is required to be set to <b>0 (zero)</b> in php.ini. Your server does not meet this requirement.';
else
$errors[] = $test.' is required to be set to <b>off</b> in php.ini. Your server does not meet this requirement.';
}
}
foreach($test_values as $test)
{
if( isset($test['0']) && isset($test['1']) )
{
if( improvedIniGet($test['0']) < $test['1'] )
$errors[] = 'It is required that <b>'.$test['0'].'</b> is set to <b>'.$test['1'].'</b> or higher.';
}
}
foreach($test_zero_or_higher_than_value as $test)
{
if( improvedIniGet($test['0']) )
{
if( improvedIniGet($test['0']) < $test['1'] )
$errors[] = 'It is required that <b>'.$test['0'].'</b> is set to either 0 (zero), <b>'.$test['1'].'</b> or higher.';
}
}
}
/* -------------
MySQL Version
------------- */
if( $mysql_enable_check )
{
// Just to be sure :)
$mysql_port = (int)$mysql_port;
if( function_exists('mysqli_connect') )
{
$mysqli = @mysqli_connect($mysql_host,$mysql_username,$mysql_password,'',$mysql_port);
if(!$mysqli)
{
$errors[] = 'Unable to connect to MySQLi: '.mysqli_connect_error();
}
else
{
$client_version = mySqlVersionStringToInt( mysqli_get_client_info() );
$server_version = mySqlVersionStringToInt( mysqli_get_server_info($mysqli) );
mysqli_close($mysqli);
}
}
elseif( function_exists('mysql_connect') )
{
$mysql_host = $mysql_host.':'.$mysql_port;
$mysql = @mysql_connect($mysql_host,$mysql_username,$mysql_password);
if(!$mysql)
{
$errors[] = 'Unable to connect to MySQL: '.mysql_error();
}
else
{
$client_version = mySqlVersionStringToInt( mysql_get_client_info() );
$server_version = mySqlVersionStringToInt( mysql_get_server_info($mysql) );
mysql_close($mysql);
}
}
if( isset($server_version) && isset($client_version) )
{
if($server_version < 50100)
$errors[] = 'You are running MySQL '.mySqlVersionIntToString($server_version).'. We recommend upgrading to at least MySQL 5.1.';
if( intAbs($server_version-$client_version) >= 1000 )
$errors[] = 'Your PHP MySQL library version ('.mySqlVersionIntToString($client_version).') does not match MySQL Server version ('.mySqlVersionIntToString($server_version).').';
}
}
/* ------
Output
------ */
// Header
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>check_compatibility.php</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>';
// Body
if( isset($errors) && count($errors) )
{
// Errors
echo 'The following issues have been found, please ask your host to fix them:<br /><br />';
foreach($errors as $error)
echo $error.'<br />';
}
else
{
// Balls to you!
echo 'Congratulations, no problems have been detected.';
}
// Footer
echo '</body>
</html>';
?>