| 1 |
<?php |
| 2 |
/** |
| 3 |
* Reports server info useful in configuring the options $min_documentRoot, $min_symlinks, |
| 4 |
* and $min_serveOptions['minApp']['allowDirs']. |
| 5 |
* |
| 6 |
* Change to true to expose this info. |
| 7 |
*/ |
| 8 |
$enabled = false; |
| 9 |
|
| 10 |
/////////////////////// |
| 11 |
|
| 12 |
if (!$enabled) { |
| 13 |
die('Set $enabled to true to see server info.'); |
| 14 |
} |
| 15 |
|
| 16 |
function assertTrue($test, $message) |
| 17 |
{ |
| 18 |
if (!$test) { |
| 19 |
echo "Warning: $message\n"; |
| 20 |
} |
| 21 |
return (bool)$test; |
| 22 |
} |
| 23 |
|
| 24 |
header('Content-Type: text/plain'); |
| 25 |
|
| 26 |
$file = __FILE__; |
| 27 |
$tmp = sys_get_temp_dir(); |
| 28 |
|
| 29 |
echo <<<EOD |
| 30 |
Cache directory : $tmp |
| 31 |
__FILE__ : $file |
| 32 |
SCRIPT_FILENAME : {$_SERVER['SCRIPT_FILENAME']} |
| 33 |
DOCUMENT_ROOT : {$_SERVER['DOCUMENT_ROOT']} |
| 34 |
SCRIPT_NAME : {$_SERVER['SCRIPT_NAME']} |
| 35 |
REQUEST_URI : {$_SERVER['REQUEST_URI']} |
| 36 |
|
| 37 |
|
| 38 |
EOD; |
| 39 |
|
| 40 |
$noSlash = assertTrue( |
| 41 |
0 === preg_match('@[\\\\/]$@', $_SERVER['DOCUMENT_ROOT']), |
| 42 |
'DOCUMENT_ROOT ends in trailing slash' |
| 43 |
); |
| 44 |
|
| 45 |
$isRealPath = assertTrue( |
| 46 |
false !== realpath($_SERVER['DOCUMENT_ROOT']), |
| 47 |
'DOCUMENT_ROOT fails realpath()' |
| 48 |
); |
| 49 |
|
| 50 |
$containsThisFile = assertTrue( |
| 51 |
0 === strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT'])), |
| 52 |
'DOCUMENT_ROOT contains this test file' |
| 53 |
); |
| 54 |
|
| 55 |
if (! $noSlash || ! $isRealPath || ! $containsThisFile) { |
| 56 |
echo "If you cannot modify DOCUMENT_ROOT, consider setting \$min_documentRoot in config.php\n"; |
| 57 |
} |
| 58 |
|
| 59 |
assertTrue( |
| 60 |
empty($_SERVER['SUBDOMAIN_DOCUMENT_ROOT']), |
| 61 |
"\$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. You may want to set \$min_documentRoot to this in config.php" |
| 62 |
); |
| 63 |
|
| 64 |
assertTrue( |
| 65 |
realpath(__FILE__) === realpath($_SERVER['DOCUMENT_ROOT'] . '/min/server-info.php'), |
| 66 |
"/min/ is not directly inside DOCUMENT_ROOT." |
| 67 |
); |
| 68 |
|
| 69 |
// TODO: rework this |
| 70 |
/* |
| 71 |
function _test_environment_getHello($url) |
| 72 |
{ |
| 73 |
$fp = fopen($url, 'r', false, stream_context_create(array( |
| 74 |
'http' => array( |
| 75 |
'method' => "GET", |
| 76 |
'timeout' => '10', |
| 77 |
'header' => "Accept-Encoding: deflate, gzip\r\n", |
| 78 |
) |
| 79 |
))); |
| 80 |
$meta = stream_get_meta_data($fp); |
| 81 |
$encoding = ''; |
| 82 |
$length = 0; |
| 83 |
foreach ($meta['wrapper_data'] as $i => $header) { |
| 84 |
if (preg_match('@^Content-Length:\\s*(\\d+)$@i', $header, $m)) { |
| 85 |
$length = $m[1]; |
| 86 |
} elseif (preg_match('@^Content-Encoding:\\s*(\\S+)$@i', $header, $m)) { |
| 87 |
if ($m[1] !== 'identity') { |
| 88 |
$encoding = $m[1]; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
$streamContents = stream_get_contents($fp); |
| 93 |
fclose($fp); |
| 94 |
|
| 95 |
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { |
| 96 |
if ($length != 6) { |
| 97 |
echo "\nReturned content should be 6 bytes and not HTTP encoded.\n" |
| 98 |
. "Headers returned by: {$url}\n\n"; |
| 99 |
var_export($meta['wrapper_data']); |
| 100 |
echo "\n\n"; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
return array( |
| 105 |
'length' => $length |
| 106 |
,'encoding' => $encoding |
| 107 |
,'bytes' => $streamContents |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
$thisUrl = 'http://' |
| 112 |
. $_SERVER['HTTP_HOST'] // avoid redirects when SERVER_NAME doesn't match |
| 113 |
. ('80' === $_SERVER['SERVER_PORT'] ? '' : ":{$_SERVER['SERVER_PORT']}") |
| 114 |
. dirname($_SERVER['REQUEST_URI']) |
| 115 |
. '/test_environment.php'; |
| 116 |
|
| 117 |
$oc = @file_get_contents($thisUrl . '?getOutputCompression=1'); |
| 118 |
|
| 119 |
if (false === $oc || ! preg_match('/^[01]$/', $oc)) { |
| 120 |
echo "!---: environment : Local HTTP request failed. Testing cannot continue.\n"; |
| 121 |
return; |
| 122 |
} |
| 123 |
if ('1' === $oc) { |
| 124 |
echo "!---: environment : zlib.output_compression is enabled in php.ini" |
| 125 |
. " or .htaccess.\n"; |
| 126 |
} |
| 127 |
|
| 128 |
$testJs = _test_environment_getHello($thisUrl . '?hello=js'); |
| 129 |
$passed = assertTrue( |
| 130 |
$testJs['length'] == 6 |
| 131 |
,'environment : PHP/server should not auto-encode application/x-javascript output' |
| 132 |
); |
| 133 |
|
| 134 |
$testCss = _test_environment_getHello($thisUrl . '?hello=css'); |
| 135 |
$passed = $passed && assertTrue( |
| 136 |
$testCss['length'] == 6 |
| 137 |
,'environment : PHP/server should not auto-encode text/css output' |
| 138 |
); |
| 139 |
|
| 140 |
$testHtml = _test_environment_getHello($thisUrl . '?hello=html'); |
| 141 |
$passed = $passed && assertTrue( |
| 142 |
$testHtml['length'] == 6 |
| 143 |
,'environment : PHP/server should not auto-encode text/html output' |
| 144 |
); |
| 145 |
|
| 146 |
if (! $passed) { |
| 147 |
$testFake = _test_environment_getHello($thisUrl . '?hello=faketype'); |
| 148 |
if ($testFake['length'] == 6) { |
| 149 |
echo " environment : Server does not auto-encode arbitrary types. This\n" |
| 150 |
. " may indicate that the auto-encoding is caused by Apache's\n" |
| 151 |
. " AddOutputFilterByType."; |
| 152 |
} |
| 153 |
} |
| 154 |
*/ |
| 155 |
|