fixed bug 911: setting ['BE']['lockIP'] to a value < 4 does not log out the BEuser...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from the "cms" extension)
29 * Basically put this is the "index.php" script which all requests for TYPO3 delivered pages goes to in the frontend (the website)
30 * The script configures constants, includes libraries and does a little logic here and there in order to instantiate the right classes to create the webpage.
31 * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
32 *
33 * On UNIX: You should create a symlink to this file from the directory from which you want your TYPO3 website to run (which is ../)
34 * ln -s tslib/index_ts.php index.php
35 *
36 * On Windows this file should copied to "index.php" in your website root (which is ../)
37 *
38 * $Id$
39 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
40 *
41 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
42 * @package TYPO3
43 * @subpackage tslib
44 */
45
46 // *******************************
47 // Set error reporting
48 // *******************************
49 error_reporting (E_ALL ^ E_NOTICE);
50
51
52 // ******************
53 // Constants defined
54 // ******************
55 $TYPO3_MISC['microtime_start'] = microtime();
56 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
57 define('TYPO3_MODE','FE');
58 define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
59
60 define('PATH_site', dirname(PATH_thisScript).'/');
61 define('PATH_t3lib', PATH_site.'t3lib/');
62 define('PATH_tslib', PATH_site.'tslib/');
63 define('PATH_typo3conf', PATH_site.'typo3conf/');
64 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
65
66 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
67
68 // *********************
69 // Timetracking started
70 // *********************
71 require_once(PATH_t3lib.'class.t3lib_timetrack.php');
72 $TT = new t3lib_timeTrack;
73 $TT->start();
74 $TT->push('','Script start');
75
76
77 // *********************
78 // Mandatory libraries included
79 // *********************
80 $TT->push('Include class t3lib_db, t3lib_div, t3lib_extmgm','');
81 require_once(PATH_t3lib.'class.t3lib_div.php');
82 require_once(PATH_t3lib.'class.t3lib_extmgm.php');
83 $TT->pull();
84
85
86
87 // **********************
88 // Include configuration
89 // **********************
90 $TT->push('Include config files','');
91 require(PATH_t3lib.'config_default.php');
92 if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); // the name of the TYPO3 database is stored in this constant. Here the inclusion of the config-file is verified by checking if this var is set.
93 if (!t3lib_extMgm::isLoaded('cms')) die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
94
95 require_once(PATH_t3lib.'class.t3lib_db.php');
96 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
97
98 $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
99 $TT->pull();
100
101
102 // *********************
103 // Libraries included
104 // *********************
105 $TT->push('Include Frontend libraries','');
106 require_once(PATH_tslib.'class.tslib_fe.php');
107 require_once(PATH_t3lib.'class.t3lib_page.php');
108 require_once(PATH_t3lib.'class.t3lib_userauth.php');
109 require_once(PATH_tslib.'class.tslib_feuserauth.php');
110 require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
111 require_once(PATH_t3lib.'class.t3lib_cs.php');
112 $TT->pull();
113
114
115 // *******************************
116 // Checking environment
117 // *******************************
118 if (t3lib_div::int_from_ver(phpversion())<4001000) die ('TYPO3 runs with PHP4.1.0+ only');
119
120 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) die('You cannot set the GLOBALS-array from outside the script.');
121 if (!get_magic_quotes_gpc()) {
122 $TT->push('Add slashes to GET/POST arrays','');
123 t3lib_div::addSlashesOnArray($_GET);
124 t3lib_div::addSlashesOnArray($_POST);
125 $HTTP_GET_VARS = $_GET;
126 $HTTP_POST_VARS = $_POST;
127 $TT->pull();
128 }
129
130 // ***********************************
131 // Create $TSFE object (TSFE = TypoScript Front End)
132 // Connecting to database
133 // ***********************************
134 $temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
135 $TSFE = new $temp_TSFEclassName(
136 $TYPO3_CONF_VARS,
137 t3lib_div::_GP('id'),
138 t3lib_div::_GP('type'),
139 t3lib_div::_GP('no_cache'),
140 t3lib_div::_GP('cHash'),
141 t3lib_div::_GP('jumpurl'),
142 t3lib_div::_GP('MP'),
143 t3lib_div::_GP('RDCT')
144 );
145 $TSFE->connectToDB();
146 if ($TSFE->RDCT) {$TSFE->sendRedirect();}
147
148
149 // *******************
150 // output compression
151 // *******************
152 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
153 ob_start();
154 require_once(PATH_t3lib.'class.gzip_encode.php');
155 }
156
157 // *********
158 // FE_USER
159 // *********
160 $TT->push('Front End user initialized','');
161 $TSFE->initFEuser();
162 $TT->pull();
163
164 // ****************
165 // PRE BE_USER HOOK
166 // ****************
167 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
168 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
169 $_params = array();
170 t3lib_div::callUserFunction($_funcRef, $_params , $_params);
171 }
172 }
173
174 // *********
175 // BE_USER
176 // *********
177 $BE_USER='';
178 if ($_COOKIE['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
179 $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
180 $TT->push('Back End user initialized','');
181 require_once (PATH_t3lib.'class.t3lib_befunc.php');
182 require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
183 require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
184 require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
185
186 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
187 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
188 $BE_USER->OS = TYPO3_OS;
189 $BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
190 $BE_USER->start(); // Object is initialized
191 $BE_USER->unpack_uc('');
192 if ($BE_USER->user['uid']) {
193 $BE_USER->fetchGroupData();
194 $TSFE->beUserLogin = 1;
195 }
196 if ($BE_USER->checkLockToIP() && $BE_USER->checkBackendAccessSettingsFromInitPhp()) {
197 $BE_USER->extInitFeAdmin();
198 if ($BE_USER->extAdmEnabled) {
199 require_once(t3lib_extMgm::extPath('lang').'lang.php');
200 $LANG = t3lib_div::makeInstance('language');
201 $LANG->init($BE_USER->uc['lang']);
202
203 $BE_USER->extSaveFeAdminConfig();
204 // Setting some values based on the admin panel
205 $TSFE->forceTemplateParsing = $BE_USER->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
206 $TSFE->displayEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayIcons');
207 $TSFE->displayFieldEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayFieldIcons');
208
209 if (t3lib_div::_GP('ADMCMD_editIcons')) {
210 $TSFE->displayFieldEditIcons=1;
211 $BE_USER->uc['TSFE_adminConfig']['edit_editNoPopup']=1;
212 }
213 if (t3lib_div::_GP('ADMCMD_simUser')) {
214 $BE_USER->uc['TSFE_adminConfig']['preview_simulateUserGroup']=intval(t3lib_div::_GP('ADMCMD_simUser'));
215 $BE_USER->ext_forcePreview=1;
216 }
217 if (t3lib_div::_GP('ADMCMD_simTime')) {
218 $BE_USER->uc['TSFE_adminConfig']['preview_simulateDate']=intval(t3lib_div::_GP('ADMCMD_simTime'));
219 $BE_USER->ext_forcePreview=1;
220 }
221
222 // Include classes for editing IF editing module in Admin Panel is open
223 if (($BE_USER->extAdmModuleEnabled('edit') && $BE_USER->extIsAdmMenuOpen('edit')) || $TSFE->displayEditIcons == 1) {
224 $TSFE->includeTCA();
225 if ($BE_USER->extIsEditAction()) {
226 require_once (PATH_t3lib.'class.t3lib_tcemain.php');
227 $BE_USER->extEditAction();
228 }
229 if ($BE_USER->extIsFormShown()) {
230 require_once(PATH_t3lib.'class.t3lib_tceforms.php');
231 require_once(PATH_t3lib.'class.t3lib_iconworks.php');
232 require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
233 require_once(PATH_t3lib.'class.t3lib_transferdata.php');
234 }
235 }
236
237 if ($TSFE->forceTemplateParsing || $TSFE->displayEditIcons || $TSFE->displayFieldEditIcons) { $TSFE->set_no_cache(); }
238 }
239
240 // $WEBMOUNTS = (string)($BE_USER->groupData['webmounts'])!='' ? explode(',',$BE_USER->groupData['webmounts']) : Array();
241 // $FILEMOUNTS = $BE_USER->groupData['filemounts'];
242 } else { // Unset the user initialization.
243 $BE_USER='';
244 $TSFE->beUserLogin=0;
245 }
246 $TT->pull();
247 $TYPO3_MISC['microtime_BE_USER_end'] = microtime();
248 }
249
250
251 // *****************************************
252 // Proces the ID, type and other parameters
253 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
254 // *****************************************
255 $TT->push('Process ID','');
256 $TSFE->checkAlternativeIdMethods();
257 $TSFE->clear_preview();
258 $TSFE->determineId();
259
260 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
261 if ($TSFE->beUserLogin && !$BE_USER->extPageReadAccess($TSFE->page)) {
262
263 // Remove user
264 unset($BE_USER);
265 $TSFE->beUserLogin = 0;
266
267 // Re-evaluate the page-id.
268 $TSFE->checkAlternativeIdMethods();
269 $TSFE->clear_preview();
270 $TSFE->determineId();
271 }
272 $TSFE->makeCacheHash();
273 $TT->pull();
274
275
276 // *******************************************
277 // Get compressed $TCA-Array();
278 // After this, we should now have a valid $TCA, though minimized
279 // *******************************************
280 $TSFE->getCompressedTCarray();
281
282
283 // ********************************
284 // Starts the template
285 // *******************************
286 $TT->push('Start Template','');
287 $TSFE->initTemplate();
288 $TT->pull();
289
290
291 // ********************************
292 // Get from cache
293 // *******************************
294 $TT->push('Get Page from cache','');
295 $TSFE->getFromCache();
296 $TT->pull();
297
298
299 // ******************************************************
300 // Get config if not already gotten
301 // After this, we should have a valid config-array ready
302 // ******************************************************
303 $TSFE->getConfigArray();
304
305
306 // ********************************
307 // Convert POST data to internal "renderCharset" if different from the metaCharset:
308 // *******************************
309 $TSFE->convPOSTCharset();
310
311
312 // *******************************************
313 // Setting the internal var, sys_language_uid + locale settings
314 // *******************************************
315 $TSFE->settingLanguage();
316 $TSFE->settingLocale();
317
318
319 // ********************************
320 // Check Submission of data.
321 // This is done at this point, because we need the config values
322 // *******************************
323 switch($TSFE->checkDataSubmission()) {
324 case 'email':
325 require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
326 require_once(PATH_t3lib.'class.t3lib_formmail.php');
327 $TSFE->sendFormmail();
328 break;
329 case 'fe_tce':
330 require_once(PATH_tslib.'class.tslib_fetce.php');
331 $TSFE->includeTCA();
332 $TT->push('fe_tce','');
333 $TSFE->fe_tce();
334 $TT->pull();
335 break;
336 }
337
338
339 // ********************************
340 // Check JumpUrl
341 // *******************************
342 $TSFE->checkJumpUrl();
343
344
345 // ********************************
346 // Generate page
347 // *******************************
348 $TSFE->setUrlIdToken();
349
350 $TT->push('Page generation','');
351 if ($TSFE->doXHTML_cleaning()) {require_once(PATH_t3lib.'class.t3lib_parsehtml.php');}
352 if ($TSFE->isGeneratePage()) {
353 $TSFE->generatePage_preProcessing();
354 $temp_theScript=$TSFE->generatePage_whichScript();
355
356 if ($temp_theScript) {
357 include($temp_theScript);
358 } else {
359 require_once(PATH_tslib.'class.tslib_pagegen.php');
360 include(PATH_tslib.'pagegen.php');
361 }
362 $TSFE->generatePage_postProcessing();
363 } elseif ($TSFE->isINTincScript()) {
364 require_once(PATH_tslib.'class.tslib_pagegen.php');
365 include(PATH_tslib.'pagegen.php');
366 }
367 $TT->pull();
368
369
370 // ********************************
371 // $GLOBALS['TSFE']->config['INTincScript']
372 // *******************************
373 if ($TSFE->isINTincScript()) {
374 $TT->push('Non-cached objects','');
375 $INTiS_config = $GLOBALS['TSFE']->config['INTincScript'];
376
377 // Special feature: Include libraries
378 $TT->push('Include libraries');
379 foreach($INTiS_config as $INTiS_cPart) {
380 if ($INTiS_cPart['conf']['includeLibs']) {
381 $INTiS_resourceList = t3lib_div::trimExplode(',',$INTiS_cPart['conf']['includeLibs'],1);
382 $GLOBALS['TT']->setTSlogMessage('Files for inclusion: "'.implode(', ',$INTiS_resourceList).'"');
383
384 foreach($INTiS_resourceList as $INTiS_theLib) {
385 $INTiS_incFile = $GLOBALS['TSFE']->tmpl->getFileName($INTiS_theLib);
386 if ($INTiS_incFile) {
387 require_once('./'.$INTiS_incFile);
388 } else {
389 $GLOBALS['TT']->setTSlogMessage('Include file "'.$INTiS_theLib.'" did not exist!',2);
390 }
391 }
392 }
393 }
394 $TT->pull();
395 $TSFE->INTincScript();
396 $TT->pull();
397 }
398
399 // ***************
400 // Output content
401 // ***************
402 if ($TSFE->isOutputting()) {
403 $TT->push('Print Content','');
404 $TSFE->processOutput();
405
406 // ***************************************
407 // Outputs content / Includes EXT scripts
408 // ***************************************
409 if ($TSFE->isEXTincScript()) {
410 $TT->push('External PHP-script','');
411 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
412 $EXTiS_config = $GLOBALS['TSFE']->config['EXTincScript'];
413 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$GLOBALS['TSFE']->content); // Splits content with the key.
414
415 // Special feature: Include libraries
416 reset($EXTiS_config);
417 while(list(,$EXTiS_cPart)=each($EXTiS_config)) {
418 if ($EXTiS_cPart['conf']['includeLibs']) {
419 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'],1);
420 $GLOBALS['TT']->setTSlogMessage('Files for inclusion: "'.implode(', ',$EXTiS_resourceList).'"');
421 reset($EXTiS_resourceList);
422 while(list(,$EXTiS_theLib)=each($EXTiS_resourceList)) {
423 $EXTiS_incFile=$GLOBALS['TSFE']->tmpl->getFileName($EXTiS_theLib);
424 if ($EXTiS_incFile) {
425 require_once($EXTiS_incFile);
426 } else {
427 $GLOBALS['TT']->setTSlogMessage('Include file "'.$EXTiS_theLib.'" did not exist!',2);
428 }
429 }
430 }
431 }
432
433 reset($EXTiS_splitC);
434 while(list($EXTiS_c,$EXTiS_cPart)=each($EXTiS_splitC)) {
435 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
436 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
437 if (is_array($EXTiS_config[$EXTiS_key])) {
438 $REC = $EXTiS_config[$EXTiS_key]['data'];
439 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
440 $content='';
441 include($EXTiS_config[$EXTiS_key]['file']);
442 echo $content; // The script MAY return content in $content or the script may just output the result directly!
443 }
444 echo substr($EXTiS_cPart,35);
445 } else {
446 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
447 }
448 }
449
450 $TT->pull();
451 } else {
452 echo $GLOBALS['TSFE']->content;
453 }
454 $TT->pull();
455 }
456
457
458 // ********************************
459 // Store session data for fe_users
460 // ********************************
461 $TSFE->storeSessionData();
462
463
464 // ***********
465 // Statistics
466 // ***********
467 $TYPO3_MISC['microtime_end'] = microtime();
468 $TSFE->setParseTime();
469 if ($TSFE->isOutputting() && ($TSFE->TYPO3_CONF_VARS['FE']['debug'] || $TSFE->config['config']['debug'])) {
470 echo '
471 <!-- Parsetime: '.$TSFE->scriptParseTime.' ms-->';
472 }
473 $TSFE->statistics();
474
475
476 // ***************
477 // Check JumpUrl
478 // ***************
479 $TSFE->jumpurl();
480
481
482 // *************
483 // Preview info
484 // *************
485 $TSFE->previewInfo();
486
487
488 // ******************
489 // Publishing static
490 // ******************
491 if (is_object($BE_USER)) {
492 if ($BE_USER->extAdmModuleEnabled('publish') && $BE_USER->extPublishList) {
493 include_once(PATH_tslib.'publish.php');
494 }
495 }
496
497
498 // ******************
499 // Hook for end-of-frontend
500 // ******************
501 $TSFE->hook_eofe();
502
503
504 // ********************
505 // Finish timetracking
506 // ********************
507 $TT->pull();
508
509
510 // ******************
511 // beLoginLinkIPList
512 // ******************
513 echo $GLOBALS['TSFE']->beLoginLinkIPList();
514
515
516 // *************
517 // Admin panel
518 // *************
519 if (is_object($BE_USER)
520 && $GLOBALS['TSFE']->beUserLogin
521 && $GLOBALS['TSFE']->config['config']['admPanel']
522 && $BE_USER->extAdmEnabled
523 // && $BE_USER->extPageReadAccess($GLOBALS['TSFE']->page) // This is already done, if there is a BE_USER object at this point!
524 && !$BE_USER->extAdminConfig['hide']) {
525 echo $BE_USER->extPrintFeAdminDialog();
526 }
527
528
529 // *************
530 // Debugging Output
531 // *************
532 if(@is_callable(array($error,'debugOutput'))) {
533 $error->debugOutput();
534 }
535 if (TYPO3_DLOG) t3lib_div::devLog('END of FRONTEND session','',0,array('_FLUSH'=>TRUE));
536
537
538 // *************
539 // Compressions
540 // *************
541 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
542 new gzip_encode($TYPO3_CONF_VARS['FE']['compressionLevel'], false, $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionDebugInfo']);
543 }
544
545 ?>