pageUnavailable_v3.diff

Administrator Admin, 2008-02-29 04:53

Download (15.2 KB)

View differences:

t3lib/config_default.php (working copy)
211 211
		'pageNotFound_handling' => '',			// How TYPO3 should handle requests for non-existing/accessible pages. false (default): The 'nearest' page is shown. TRUE or '1': An TYPO3 error box is displayed. Strings: page to show (reads content and outputs with correct headers), eg. 'notfound.html' or 'http://www.domain.org/errors/notfound.html'. If prefixed "REDIRECT:" it will redirect to the URL/script after the prefix (original behaviour). If prefixed with "READFILE:" then it will expect the remaining string to be a HTML file which will be read and outputted directly after having the marker "###CURRENT_URL###" substituted with REQUEST_URI and ###REASON### with reason text, for example: "READFILE:fileadmin/notfound.html". Another option is the prefix "USER_FUNCTION:" which will call a user function, eg. "USER_FUNCTION:typo3conf/pageNotFoundHandling.php:user_pageNotFound->pageNotFound" where the file must contain a class "user_pageNotFound" with a method "pageNotFound" inside with two parameters, $param and $ref
212 212
		'pageNotFound_handling_statheader' => 'HTTP/1.0 404 Not Found',			// If 'pageNotFound_handling' is enabled, this string will always be sent as header before the actual handling.
213 213
		'pageNotFoundOnCHashError' => 0,		// Boolean. If true, a page not found call is made when cHash evaluation error occurs. By default they will just disable caching but still display page output.
214
		'pageUnavailable_handling' => '',		// How TYPO3 should handle requests when pages are unavailable due to system problems. false (default): A static error message is displayed. Strings: page to show (reads content and outputs with correct headers), eg. 'unavailable.html' or 'http://www.domain.org/errors/unavailable.html'. If prefixed "REDIRECT:" it will redirect to the URL/script after the prefix (original behaviour). If prefixed with "READFILE:" then it will expect the remaining string to be a HTML file which will be read and outputted directly after having the marker "###CURRENT_URL###" substituted with REQUEST_URI and ###REASON### with reason text, for example: "READFILE:fileadmin/unavailable.html". Another option is the prefix "USER_FUNCTION:" which will call a user function, eg. "USER_FUNCTION:typo3conf/pageUnavailableHandling.php:user_pageUnavailable->pageUnavailable" where the file must contain a class "user_pageUnavailable" with a method "pageUnavailable" inside with two parameters, $param and $ref. If the client matches TYPO3_CONF_VARS[SYS][devIPmask], this setting is ignored and the page is shown as normal.
215
		'pageUnavailable_handling_statheader' => 'HTTP/1.0 503 Service Temporarily Unavailable',		// If 'pageUnavailable_handling' is enabled, this string will always be sent as header before the actual handling.
216
		'pageUnavailable_force' => 0,			// Boolean. If true, pageUnavailable_handling is used for every frontend page. If the client matches TYPO3_CONF_VARS[SYS][devIPmask], the page is shown as normal. This is useful during temporary site maintenance. 
214 217
		'userFuncClassPrefix' => 'user_',		// This prefix must be the first part of any function or class name called from TypoScript, for instance in the stdWrap function.
215 218
		'addRootLineFields' => '',				// Comma-list of fields from the 'pages'-table. These fields are added to the select query for fields in the rootline.
216 219
		'checkFeUserPid' => 1,					// Boolean. If set, the pid of fe_user logins must be sent in the form as the field 'pid' and then the user must be located in the pid. If you unset this, you should change the fe_users.username eval-flag 'uniqueInPid' to 'unique' in $TCA. This will do: $TCA['fe_users']['columns']['username']['config']['eval']= 'nospace,lower,required,unique';
typo3/sysext/cms/tslib/class.tslib_fe.php (working copy)
480 480
					</script>';
481 481
				exit;
482 482
			} elseif (!$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db))	{
483
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
484
				$this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
485
				exit;
483
				if ($this->checkPageUnavailableHandler())	{
484
					$this->pageUnavailableAndExit('Cannot connect to the current database, "'.TYPO3_db.'"');
485
				} else {
486
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
487
					$this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
488
					exit;
489
				}
486 490
			}
487 491
		} else {
488 492
			if (!TYPO3_db)	{
......
494 498
					</script>';
495 499
				exit;
496 500
			}
497
			header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
498
			$this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
499
			exit;
501
			
502
			if ($this->checkPageUnavailableHandler())	{
503
				$this->pageUnavailableAndExit('The current username, password or host was not accepted when the connection to the database was attempted to be established!');
504
			} else {
505
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
506
				$this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
507
				exit;
508
			}
500 509
		}
501 510

  
502 511

  
......
912 921
				if ($theFirstPage)	{
913 922
					$this->id = $theFirstPage['uid'];
914 923
				} else {
915
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
916
					t3lib_div::sysLog('No pages are found on the rootlevel!', 'cms', 3);
917
					$this->printError('No pages are found on the rootlevel!');
918
					exit;
924
					if ($this->checkPageUnavailableHandler())	{
925
						$this->pageUnavailableAndExit('No pages are found on the rootlevel!');
926
					} else {
927
						header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
928
						t3lib_div::sysLog('No pages are found on the rootlevel!', 'cms', 3);
929
						$this->printError('No pages are found on the rootlevel!');
930
						exit;
931
					}
919 932
				}
920 933
			}
921 934
		}
......
1025 1038
				$this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
1026 1039
			}
1027 1040
			if (!count($this->rootLine))	{
1028
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1029
				t3lib_div::sysLog('The requested page didn\'t have a proper connection to the tree-root! ('.$this->sys_page->error_getRootLine.')', 'cms', 3);
1030
				$this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
1031
				exit;
1041
				if ($this->checkPageUnavailableHandler())	{
1042
					$this->pageUnavailableAndExit('The requested page didn\'t have a proper connection to the tree-root!');
1043
				} else {
1044
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1045
					t3lib_div::sysLog('The requested page didn\'t have a proper connection to the tree-root! ('.$this->sys_page->error_getRootLine.')', 'cms', 3);
1046
					$this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
1047
					exit;
1048
				}
1032 1049
			}
1033 1050
			$this->fePreview = 1;
1034 1051
		}
......
1036 1053
			// Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
1037 1054
		if ($this->checkRootlineForIncludeSection())	{
1038 1055
			if (!count($this->rootLine))	{
1039
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1040
				t3lib_div::sysLog('The requested page was not accessible!', 'cms', 3);
1041
				$this->printError('The requested page was not accessible!');
1042
				exit;
1056
				if ($this->checkPageUnavailableHandler())	{
1057
					$this->pageUnavailableAndExit('The requested page was not accesible!');
1058
				} else {
1059
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1060
					t3lib_div::sysLog('The requested page was not accessible!', 'cms', 3);
1061
					$this->printError('The requested page was not accessible!');
1062
					exit;
1063
				}
1043 1064
			} else {
1044 1065
				$el = reset($this->rootLine);
1045 1066
				$this->id = $el['uid'];
......
1318 1339
			return $this->sys_page->getDomainStartPage(t3lib_div::getIndpEnv('HTTP_HOST'),t3lib_div::getIndpEnv('SCRIPT_NAME'),t3lib_div::getIndpEnv('REQUEST_URI'));
1319 1340
		}
1320 1341
	}
1342
	
1343
	/**
1344
	 * Page unavailable handler for use in frontend plugins from extensions.
1345
	 *
1346
	 * @param	string		Reason text
1347
	 * @param	string		HTTP header to send
1348
	 * @return	void		Function exits.
1349
	 */
1350
	function pageUnavailableAndExit($reason='', $header='')	{
1351
		$header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling_statheader'];
1352
		$this->pageUnavailableHandler($this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling'], $header, $reason);
1353
		exit;
1354
	}
1321 1355

  
1322 1356
	/**
1323 1357
	 * Page-not-found handler for use in frontend plugins from extensions.
......
1331 1365
		$this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'], $header, $reason);
1332 1366
		exit;
1333 1367
	}
1368
	
1369
	/**
1370
	 * Checks whether the pageUnavailableHandler should be used. To be used, pageUnavailable_handling must be set
1371
	 * and devIPMask must not match the current visitor's IP address.
1372
	 *
1373
	 * @return	boolean		True/false whether the pageUnavailable_handler should be used.
1374
	 */
1375
	function checkPageUnavailableHandler()	{
1376
		if($this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling'] &&
1377
		   !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $this->TYPO3_CONF_VARS['SYS']['devIPmask'])) {
1378
			$checkPageUnavailableHandler = TRUE;
1379
		} else {
1380
			$checkPageUnavailableHandler = FALSE;
1381
		}
1382
		
1383
		return $checkPageUnavailableHandler;
1384
	}
1385
	
1386
	/**
1387
	 * Page unavailable handler. Acts a wrapper for the pageErrorHandler method.
1388
	 *
1389
	 * @param	mixed		Which type of handling; If a true PHP-boolean or TRUE then a ->printError message is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1390
	 * @param	string		If set, this is passed directly to the PHP function, header()
1391
	 * @param	string		If set, error messages will also mention this as the reason for the page-not-found.
1392
	 * @return	void		(The function exits!)
1393
	 */
1394
	function pageUnavailableHandler($code, $header, $reason)	{
1395
		$this->pageErrorHandler($code, $header, $reason);
1396
	}
1397
	
1398
	/**
1399
	 * Page not found handler. Acts a wrapper for the pageErrorHandler method.
1400
	 *
1401
	 * @param	mixed		Which type of handling; If a true PHP-boolean or TRUE then a ->printError message is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1402
	 * @param	string		If set, this is passed directly to the PHP function, header()
1403
	 * @param	string		If set, error messages will also mention this as the reason for the page-not-found.
1404
	 * @return	void		(The function exits!)
1405
	 */
1406
	function pageNotFoundHandler($code, $header='', $reason='')	{
1407
		$this->pageErrorHandler($code, $header, $reason);
1408
	}
1334 1409

  
1335 1410
	/**
1336
	 * Page not found handler.
1411
	 * Generic error page handler.
1337 1412
	 * Exits.
1338 1413
	 *
1339 1414
	 * @param	mixed		Which type of handling; If a true PHP-boolean or TRUE then a ->printError message is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
......
1341 1416
	 * @param	string		If set, error messages will also mention this as the reason for the page-not-found.
1342 1417
	 * @return	void		(The function exits!)
1343 1418
	 */
1344
	function pageNotFoundHandler($code, $header='', $reason='')	{
1419
	function pageErrorHandler($code, $header='', $reason='')	{
1345 1420

  
1346 1421
			// Issue header in any case:
1347 1422
		if ($header)	{
......
1916 1991
				$this->pSetup = $this->tmpl->setup[$this->sPre.'.'];
1917 1992

  
1918 1993
				if (!is_array($this->pSetup))	{
1919
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1920
					t3lib_div::sysLog('The page is not configured! [type= '.$this->type.']['.$this->sPre.']', 'cms', 3);
1921
					$this->printError('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
1922
					exit;
1994
					if ($this->checkPageUnavailableHandler())	{
1995
						$this->pageUnavailableAndExit('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
1996
					} else {
1997
						header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1998
						t3lib_div::sysLog('The page is not configured! [type= '.$this->type.']['.$this->sPre.']', 'cms', 3);
1999
						$this->printError('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
2000
						exit;
2001
					}
1923 2002
				} else {
1924 2003
					$this->config['config']=Array();
1925 2004

  
......
1989 2068
				}
1990 2069
				$GLOBALS['TT']->pull();
1991 2070
			} else {
1992
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
1993
				t3lib_div::sysLog('No template found!', 'cms', 3);
1994
				$this->printError('No template found!');
1995
				exit;
2071
				if ($this->checkPageUnavailableHandler())	{
2072
					$this->pageUnavailableAndExit('No template found!');
2073
				} else {
2074
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
2075
					t3lib_div::sysLog('No template found!', 'cms', 3);
2076
					$this->printError('No template found!');
2077
					exit;
2078
				}
1996 2079
			}
1997 2080
		}
1998 2081

  
......
2057 2140
		if ($this->absRefPrefix_force && strcmp($this->config['config']['simulateStaticDocuments'],'PATH_INFO'))	{
2058 2141
			$redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'index.php?id='.$this->id.'&type='.$this->type;
2059 2142
			if ($this->config['config']['simulateStaticDocuments_dontRedirectPathInfoError'])	{
2060
				header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
2061
				t3lib_div::sysLog('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!', 'cms', 3);
2062
				$this->printError('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!<br /><br /><a href="'.htmlspecialchars($redirectUrl).'">Click here to get to the right page.</a>','Error: PATH_INFO not configured');
2143
				if ($this->checkPageUnavailableHandler())	{
2144
					$this->pageUnavailableAndExit('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!');
2145
				} else {
2146
					header( 'HTTP/1.0 503 Service Temporarily Unavailable' );
2147
					t3lib_div::sysLog('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!', 'cms', 3);
2148
					$this->printError('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!<br /><br /><a href="'.htmlspecialchars($redirectUrl).'">Click here to get to the right page.</a>','Error: PATH_INFO not configured');
2149
				}
2063 2150
			} else {
2064 2151
				header('Location: '.t3lib_div::locationHeaderUrl($redirectUrl));
2065 2152
			}
typo3/sysext/cms/tslib/index_ts.php (working copy)
166 166
		t3lib_div::_GP('MP'),
167 167
		t3lib_div::_GP('RDCT')
168 168
	);
169

  
170
if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] && 
171
   !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
172
	$TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
173
}
174
	
175
	
169 176
$TSFE->connectToDB();
170 177

  
171 178
	// In case of a keyword-authenticated preview, re-initialize the TSFE object: