No-brainer: removing a reference to a bug which is obsolete
[Packages/TYPO3.CMS.git] / misc / phpcheck / incfile.php
1 <?php
2 // This checks for my own IP at home. You can just remove the if-statement.
3 if (1==0 || ($_SERVER['REMOTE_ADDR']!='127.0.0.1')) {
4 die('In the source distribution of TYPO3, this script is disabled by a die() function call.<br/><b>Fix:</b> Open the file misc/phpcheck/incfile.php and remove/out-comment the line that outputs this message!');
5 }
6
7 SetCookie('test_script_cookie', 'Cookie Value!', 0, '/');
8
9
10 class t3lib_div {
11 function trimExplode($delim, $string, $onlyNonEmptyValues=0) {
12 // This explodes a comma-list into an array where the values are parsed through trim();
13 $temp = explode($delim,$string);
14 $newtemp=array();
15 while(list($key,$val)=each($temp)) {
16 if (!$onlyNonEmptyValues || strcmp("",trim($val))) {
17 $newtemp[]=trim($val);
18 }
19 }
20 reset($newtemp);
21 return $newtemp;
22 }
23 function dirname($path) {
24 $p=t3lib_div::revExplode("/",$path,2);
25 return count($p)==2?$p[0]:"";
26 }
27 function revExplode($delim, $string, $count=0) {
28 $temp = explode($delim,strrev($string),$count);
29 while(list($key,$val)=each($temp)) {
30 $temp[$key]=strrev($val);
31 }
32 $temp=array_reverse($temp);
33 reset($temp);
34 return $temp;
35 }
36
37 /**
38 * Abstraction method which returns System Environment Variables regardless of server OS, CGI/MODULE version etc. Basically this is SERVER variables for most of them.
39 * This should be used instead of getEnv() and HTTP_SERVER_VARS/ENV_VARS to get reliable values for all situations.
40 *
41 * Usage: 226
42 *
43 * @param string Name of the "environment variable"/"server variable" you wish to use. Valid values are SCRIPT_NAME, SCRIPT_FILENAME, REQUEST_URI, PATH_INFO, REMOTE_ADDR, REMOTE_HOST, HTTP_REFERER, HTTP_HOST, HTTP_USER_AGENT, HTTP_ACCEPT_LANGUAGE, QUERY_STRING, TYPO3_DOCUMENT_ROOT, TYPO3_HOST_ONLY, TYPO3_HOST_ONLY, TYPO3_REQUEST_HOST, TYPO3_REQUEST_URL, TYPO3_REQUEST_SCRIPT, TYPO3_REQUEST_DIR, TYPO3_SITE_URL, _ARRAY
44 * @return string Value based on the input key, independent of server/os environment.
45 */
46 function getIndpEnv($getEnvName) {
47 global $HTTP_SERVER_VARS;
48 /*
49 Conventions:
50 output from parse_url():
51 URL: http://username:password@192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1
52 [scheme] => 'http'
53 [user] => 'username'
54 [pass] => 'password'
55 [host] => '192.168.1.4'
56 [port] => '8080'
57 [path] => '/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/'
58 [query] => 'arg1,arg2,arg3&p1=parameter1&p2[key]=value'
59 [fragment] => 'link1'
60
61 Further definition: [path_script] = '/typo3/32/temp/phpcheck/index.php'
62 [path_dir] = '/typo3/32/temp/phpcheck/'
63 [path_info] = '/arg1/arg2/arg3/'
64 [path] = [path_script/path_dir][path_info]
65
66
67 Keys supported:
68
69 URI______:
70 REQUEST_URI = [path]?[query] = /typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value
71 HTTP_HOST = [host][:[port]] = 192.168.1.4:8080
72 SCRIPT_NAME = [path_script]++ = /typo3/32/temp/phpcheck/index.php // NOTICE THAT SCRIPT_NAME will return the php-script name ALSO. [path_script] may not do that (eg. '/somedir/' may result in SCRIPT_NAME '/somedir/index.php')!
73 PATH_INFO = [path_info] = /arg1/arg2/arg3/
74 QUERY_STRING = [query] = arg1,arg2,arg3&p1=parameter1&p2[key]=value
75 HTTP_REFERER = [scheme]://[host][:[port]][path] = http://192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/?arg1,arg2,arg3&p1=parameter1&p2[key]=value
76 (Notice: NO username/password + NO fragment)
77
78 CLIENT____:
79 REMOTE_ADDR = (client IP)
80 REMOTE_HOST = (client host)
81 HTTP_USER_AGENT = (client user agent)
82 HTTP_ACCEPT_LANGUAGE = (client accept language)
83
84 SERVER____:
85 SCRIPT_FILENAME = Absolute filename of script (Differs between windows/unix). On windows 'C:\\blabla\\blabl\\' will be converted to 'C:/blabla/blabl/'
86
87 Special extras:
88 TYPO3_HOST_ONLY = [host] = 192.168.1.4
89 TYPO3_PORT = [port] = 8080 (blank if 80, taken from host value)
90 TYPO3_REQUEST_HOST = [scheme]://[host][:[port]]
91 TYPO3_REQUEST_URL = [scheme]://[host][:[port]][path]?[query] (sheme will by default be 'http' until we can detect if it's https -
92 TYPO3_REQUEST_SCRIPT = [scheme]://[host][:[port]][path_script]
93 TYPO3_REQUEST_DIR = [scheme]://[host][:[port]][path_dir]
94 TYPO3_SITE_URL = [scheme]://[host][:[port]][path_dir] of the TYPO3 website
95 TYPO3_DOCUMENT_ROOT = Absolute path of root of documents: TYPO3_DOCUMENT_ROOT.SCRIPT_NAME = SCRIPT_FILENAME (typically)
96
97 Notice: [fragment] is apparently NEVER available to the script!
98
99
100 Testing suggestions:
101 - Output all the values.
102 - In the script, make a link to the script it self, maybe add some parameters and click the link a few times so HTTP_REFERER is seen
103 - ALSO TRY the script from the ROOT of a site (like 'http://www.mytest.com/' and not 'http://www.mytest.com/test/' !!)
104
105 */
106
107 # if ($getEnvName=='HTTP_REFERER') return '';
108 switch((string)$getEnvName) {
109 case 'SCRIPT_NAME':
110 return php_sapi_name()=='cgi' ? $HTTP_SERVER_VARS['PATH_INFO'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
111 break;
112 case 'SCRIPT_FILENAME':
113 return str_replace('//','/', str_replace('\\','/', php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ? $HTTP_SERVER_VARS['PATH_TRANSLATED']:$HTTP_SERVER_VARS['SCRIPT_FILENAME']));
114 break;
115 case 'REQUEST_URI':
116 // Typical application of REQUEST_URI is return urls, forms submitting to itselt etc. Eg: returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))
117 if (!$HTTP_SERVER_VARS['REQUEST_URI']) { // This is for ISS/CGI which does not have the REQUEST_URI available.
118 return '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
119 ($HTTP_SERVER_VARS['QUERY_STRING']?'?'.$HTTP_SERVER_VARS['QUERY_STRING']:'');
120 } else return $HTTP_SERVER_VARS['REQUEST_URI'];
121 break;
122 case 'PATH_INFO':
123 // $HTTP_SERVER_VARS['PATH_INFO']!=$HTTP_SERVER_VARS['SCRIPT_NAME'] is necessary because some servers (Windows/CGI) are seen to set PATH_INFO equal to script_name
124 // Further, there must be at least one '/' in the path - else the PATH_INFO value does not make sense.
125 // IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers, then 'php_sapi_name()=='cgi'' might be a better check. Right now strcmp($HTTP_SERVER_VARS['PATH_INFO'],t3lib_div::getIndpEnv('SCRIPT_NAME')) will always return false for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO because of php_sapi_name()=='cgi' (see above)
126 // if (strcmp($HTTP_SERVER_VARS['PATH_INFO'],t3lib_div::getIndpEnv('SCRIPT_NAME')) && count(explode('/',$HTTP_SERVER_VARS['PATH_INFO']))>1) {
127 if (php_sapi_name()!='cgi') {
128 return $HTTP_SERVER_VARS['PATH_INFO'];
129 } else return '';
130 break;
131 // These are let through without modification
132 case 'REMOTE_ADDR':
133 case 'REMOTE_HOST':
134 case 'HTTP_REFERER':
135 case 'HTTP_HOST':
136 case 'HTTP_USER_AGENT':
137 case 'HTTP_ACCEPT_LANGUAGE':
138 case 'QUERY_STRING':
139 return $HTTP_SERVER_VARS[$getEnvName];
140 break;
141 case 'TYPO3_DOCUMENT_ROOT':
142 // Some CGI-versions (LA13CGI) and mod-rewrite rules on MODULE versions will deliver a 'wrong' DOCUMENT_ROOT (according to our description). Further various aliases/mod_rewrite rules can disturb this as well.
143 // Therefore the DOCUMENT_ROOT is now always calculated as the SCRIPT_FILENAME minus the end part shared with SCRIPT_NAME.
144 $SFN = t3lib_div::getIndpEnv('SCRIPT_FILENAME');
145 $SN_A = explode('/',strrev(t3lib_div::getIndpEnv('SCRIPT_NAME')));
146 $SFN_A = explode('/',strrev($SFN));
147 $acc=array();
148 while(list($kk,$vv)=each($SN_A)) {
149 if (!strcmp($SFN_A[$kk],$vv)) {
150 $acc[]=$vv;
151 } else break;
152 }
153 $commonEnd=strrev(implode('/',$acc));
154 if (strcmp($commonEnd,'')) $DR = substr($SFN,0,-(strlen($commonEnd)+1));
155 return $DR;
156 break;
157 case 'TYPO3_HOST_ONLY':
158 $p=explode(':',$HTTP_SERVER_VARS['HTTP_HOST']);
159 return $p[0];
160 break;
161 case 'TYPO3_PORT':
162 $p=explode(':',$HTTP_SERVER_VARS['HTTP_HOST']);
163 return $p[1];
164 break;
165 case 'TYPO3_REQUEST_HOST':
166 return 'http'.($HTTP_SERVER_VARS['SSL_SESSION_ID']?'s':'').'://'. // I hope this: ($HTTP_SERVER_VARS['SSL_SESSION_ID']?'s':'') - is sufficient to detect https...
167 $HTTP_SERVER_VARS['HTTP_HOST'];
168 break;
169 case 'TYPO3_REQUEST_URL':
170 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('REQUEST_URI');
171 break;
172 case 'TYPO3_REQUEST_SCRIPT':
173 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('SCRIPT_NAME');
174 break;
175 case 'TYPO3_REQUEST_DIR':
176 return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
177 break;
178 case 'TYPO3_SITE_URL':
179 if (defined('PATH_thisScript') && defined('PATH_site')) {
180 $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
181 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
182 $siteUrl = substr($url,0,-strlen($lPath));
183 if (substr($siteUrl,-1)!='/') $siteUrl.='/';
184 return $siteUrl;
185 } else return '';
186
187 break;
188 case '_ARRAY':
189 $out=array();
190 // Here, list ALL possible keys to this function for debug display.
191 $envTestVars = t3lib_div::trimExplode(',','
192 HTTP_HOST,
193 TYPO3_HOST_ONLY,
194 TYPO3_PORT,
195 PATH_INFO,
196 QUERY_STRING,
197 REQUEST_URI,
198 HTTP_REFERER,
199 TYPO3_REQUEST_HOST,
200 TYPO3_REQUEST_URL,
201 TYPO3_REQUEST_SCRIPT,
202 TYPO3_REQUEST_DIR,
203 TYPO3_SITE_URL,
204 SCRIPT_NAME,
205 TYPO3_DOCUMENT_ROOT,
206 SCRIPT_FILENAME,
207 REMOTE_ADDR,
208 REMOTE_HOST,
209 HTTP_USER_AGENT,
210 HTTP_ACCEPT_LANGUAGE',1);
211 reset($envTestVars);
212 while(list(,$v)=each($envTestVars)) {
213 $out[$v]=t3lib_div::getIndpEnv($v);
214 }
215 reset($out);
216 return $out;
217 break;
218 }
219 }
220
221 }
222
223 function view_array($array_in) {
224 // Returns HTML-code, which is a visual representation of a multidimensional array
225 // use t3lib_div::print_array() in order to print an array
226 // Returns false if $array_in is not an array
227 if (is_array($array_in)) {
228 $result='<table border=1 cellpadding=1 cellspacing=0 bgcolor=white>';
229 if (!count($array_in)) {$result.= '<tr><td><font face="Verdana,Arial" size="1"><b>'.HTMLSpecialChars("EMPTY!").'</b></font></td></tr>';}
230 while (list($key,$val)=each($array_in)) {
231 $result.= '<tr><td><font face="Verdana,Arial" size="1">'.HTMLSpecialChars($key).'</font></td><td>';
232 if (is_array($array_in[$key])) {
233 $result.=t3lib_div::view_array($array_in[$key]);
234 } else
235 $result.= '<font face="Verdana,Arial" size="1" color=red>'.nl2br(HTMLSpecialChars($val)).'<BR></font>';
236 $result.= '</td></tr>';
237 }
238 $result.= '</table>';
239 } else {
240 $result = false;
241 }
242 return $result;
243 }
244 function debug($array_in) {
245 // Prints an array
246 echo view_array($array_in);
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264 error_reporting (E_ALL ^ E_NOTICE);
265
266 define("TYPO3_OS", stristr(PHP_OS,"win")&&!stristr(PHP_OS,"darwin")?"WIN":"");
267 /*
268 define("PATH_thisScript",
269 TYPO3_OS=="WIN" ?
270 str_replace('//','/',str_replace('\\','/', $HTTP_SERVER_VARS["PATH_TRANSLATED"]?$HTTP_SERVER_VARS["PATH_TRANSLATED"]:getenv("PATH_TRANSLATED"))) :
271 (php_sapi_name()=="cgi"?(getenv("PATH_TRANSLATED")?getenv("PATH_TRANSLATED"):getenv("SCRIPT_FILENAME")):$HTTP_SERVER_VARS["PATH_TRANSLATED"])
272 );
273 */
274
275 define("PATH_thisScript",str_replace('//','/', str_replace('\\','/', php_sapi_name()=="cgi"||php_sapi_name()=="isapi" ? $HTTP_SERVER_VARS["PATH_TRANSLATED"]:$HTTP_SERVER_VARS["SCRIPT_FILENAME"])));
276 define('PATH_site', dirname(PATH_thisScript).'/');
277
278
279 if (count($_GET) || $_SERVER["HTTP_REFERER"]) {
280 # KOMPENSATED:
281 echo "<H3>t3lib_div::getIndpEnv()</H3><p>These are 'system variables' returned from t3lib_div::getIndpEnv() and should be universal for any server configuration:</p>";
282 debug(t3lib_div::getIndpEnv("_ARRAY"));
283
284 debug(array(
285 "PHP_OS"=>PHP_OS,
286 "TYPO3_OS"=>TYPO3_OS,
287 "PATH_thisScript"=>PATH_thisScript,
288 "php_sapi_name()" => php_sapi_name()
289 ));
290
291
292
293
294 ##debug(parse_url("http://admin:palindrom@192.168.1.4:8080/typo3/32/temp/phpcheck/index.php/arg1/arg2/arg3/index.php?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1"));
295
296
297 echo "<H3>Raw values</H3><p>These are the raw 'system variables' returned from getenv(), HTTP_SERVER_VARS, HTTP_ENV_VARS etc. These are displayed here so we can find the right values via this testscript to map to with t3lib_div::getIndpEnv()</p>";
298 $envTestVars = explode(",","REQUEST_URI,REMOTE_ADDR,REMOTE_HOST,PATH_INFO,SCRIPT_NAME,SCRIPT_FILENAME,HTTP_HOST,HTTP_USER_AGENT,HTTP_ACCEPT_ENCODING,HTTP_REFERER,QUERY_STRING");
299 $lines=array();
300 $lines[] = '<tr bgcolor="#eeeeee">
301 <td>Key</td>
302 <td nowrap>getenv()</td>
303 <td nowrap>HTTP_SERVER_VARS</td>
304 <td nowrap>_SERVER</td>
305 <td nowrap>HTTP_ENV_VARS</td>
306 <td nowrap>_ENV</td>
307 </tr>';
308 while(list(,$v)=each($envTestVars)) {
309 $lines[] = '<tr>
310 <td bgcolor="#eeeeee">'.htmlspecialchars($v).'</td>
311 <td nowrap>'.htmlspecialchars(getenv($v)).'&nbsp;</td>
312 <td nowrap>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"][$v]).'&nbsp;</td>
313 <td nowrap>'.htmlspecialchars($GLOBALS["_SERVER"][$v]).'&nbsp;</td>
314 <td nowrap>'.htmlspecialchars($GLOBALS["HTTP_ENV_VARS"][$v]).'&nbsp;</td>
315 <td nowrap>'.htmlspecialchars($GLOBALS["_ENV"][$v]).'&nbsp;</td>
316 </tr>';
317 }
318 echo '<table border=1 style="font-family:verdana; font-size:10px;">'.implode("",$lines).'</table>';
319
320 echo '<table border=1 style="font-family:verdana; font-size:10px;">
321 <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["DOCUMENT_ROOT"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["DOCUMENT_ROOT"]).'</td></tr>
322 <tr><td>'.htmlspecialchars('$HTTP_SERVER_VARS["PATH_TRANSLATED"]').'</td><td>'.htmlspecialchars($HTTP_SERVER_VARS["PATH_TRANSLATED"]).'</td></tr>
323 <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["REDIRECT_URL"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["REDIRECT_URL"]).'</td></tr>
324 <tr><td>'.htmlspecialchars('$GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]').'</td><td>'.htmlspecialchars($GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]).'</td></tr>
325 </table>';
326
327
328
329 echo "Cookie 'test_script_cookie': '<strong>".$HTTP_COOKIE_VARS["test_script_cookie"]."</strong>'<BR>";
330
331
332 echo '<HR><a name="link1"></a>';
333 echo '<div style="border: 1px solid black; padding: 10px 10px 10px 10px;"><h3>What to do now?</h3>
334 <p>1) Click this link above once more: <a href="index.php?arg1,arg2,arg3&p1=parameter1&p2[key]='.substr(md5(time()),0,4).'#link1">Go to this page again.</a><BR>
335 2) Then save this HTML-page and send it to kasperYYYY@typo3.com with information about 1) which webserver (Apache/ISS), 2) Unix/Windows, 3) CGI or module (ISAPI)<br>
336 2a) You might help us find any differences in your values to this <a href="reference.html" target="_blank">reference example</a> by comparing the values before you send the result (thanks).
337 <br>
338 3) If you are really advanced you try and click the link below here. With CGI-versions of servers it will most likely give an error page. If it does not, please send the output to me as well (save HTML-page and send to kasperYYYY@typo3.com). If you do this PATH_INFO test, please let me know.<br><br>
339
340 4) For the really, really advanced folks, it might be interesting to see the output if you could place this link in the root of a domain. That means the index.php script will be executed from eg. "http://www.blablabla.com/" and not "http://www.blablabla.com/kaspers_test/" - it can make a difference.<br>
341 <br>
342 <br>
343 I am operating with these categories of servers. <strong>Please identify your configuration and label your email with that "type":</strong><br><br>
344
345 <table border=1>
346 <tr bgcolor="#eeeeee">
347 <td><em>TYPE:</em></td>
348 <td><em>Description:</em></td>
349 </tr>
350 <tr>
351 <td>WA13CGI</td>
352 <td>Windows / Apache 1.3.x / CGI</td>
353 </tr>
354 <tr>
355 <td>WA2CGI</td>
356 <td>Windows / Apache 2.x / CGI</td>
357 </tr>
358 <tr>
359 <td>WA13ISAPI</td>
360 <td>Windows / Apache 1.3.x / ISAPI-module</td>
361 </tr>
362 <tr>
363 <td>WA2ISAPI</td>
364 <td>Windows / Apache 2.x / ISAPI-module</td>
365 </tr>
366 <tr>
367 <td>WISS_CGI</td>
368 <td>Windows / ISS / CGI</td>
369 </tr>
370 <tr>
371 <td>WISS_ISAPI</td>
372 <td>Windows / ISS / ISAPI-module</td>
373 </tr>
374 <tr>
375 <td>MA13MOD</td>
376 <td>Mac (Darwin) / Apache 1.3.x / Module</td>
377 </tr>
378 <tr>
379 <td>LA13CGI</td>
380 <td>Linux / Apache 1.3.x / CGI</td>
381 </tr>
382 <tr>
383 <td>LA2CGI</td>
384 <td>Linux / Apache 2.x / CGI</td>
385 </tr>
386 <tr>
387 <td>LA13MOD</td>
388 <td>Linux / Apache 1.3.x / Module</td>
389 </tr>
390 <tr>
391 <td>LA2MOD</td>
392 <td>Linux / Apache 2.x / Module</td>
393 </tr>
394 </table>
395
396
397 </p></div>';
398 echo '<a href="index.php/arg1/arg2/arg3/#link2" name="link2">Go to this page again (PATH_INFO).</a><BR>';
399
400 phpinfo();
401 } else {
402 echo '<a href="index.php?arg1,arg2,arg3&p1=parameter1&p2[key]=value#link1" name="link1">Click this link to start the test.</a><BR>';
403 }
404 ?>