2006-01-18-typo3-sslproxy.patch

Administrator Admin, 2006-01-18 23:45

Download (4.92 KB)

View differences:

typo3.8.1/t3lib/class.t3lib_div.php 2006-01-12 23:03:49.626885740 +0000
2663 2663
		*/
2664 2664

  
2665 2665
#		if ($getEnvName=='HTTP_REFERER')	return '';
2666

  
2667
		if (
2668
				!empty($_SERVER["HTTP_X_FORWARDED_HOST"]) &&
2669
				($_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"]) &&
2670
				!empty($GLOBALS['TYPO3_CONF_VARS']['BE']['ReverseProxyDirectory'])
2671
		) {
2672
			$sslproxy = $GLOBALS['TYPO3_CONF_VARS']['BE']['ReverseProxyDirectory'];
2673
		} else {
2674
			$sslproxy = "";
2675
		}
2676

  
2666 2677
		switch((string)$getEnvName)	{
2667 2678
			case 'SCRIPT_NAME':
2668
				return (php_sapi_name()=='cgi'||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) ? ($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) : ($_SERVER['ORIG_SCRIPT_NAME']?$_SERVER['ORIG_SCRIPT_NAME']:$_SERVER['SCRIPT_NAME']);
2679
				$retval = (php_sapi_name()=='cgi'||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) ? ($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) : ($_SERVER['ORIG_SCRIPT_NAME']?$_SERVER['ORIG_SCRIPT_NAME']:$_SERVER['SCRIPT_NAME']);
2680
				return $sslproxy . $retval;
2669 2681
			break;
2670 2682
			case 'SCRIPT_FILENAME':
2671 2683
				return 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'])));
......
2673 2685
			case 'REQUEST_URI':
2674 2686
					// Typical application of REQUEST_URI is return urls, forms submitting to itself etc. Example: returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))
2675 2687
				if (!$_SERVER['REQUEST_URI'])	{	// This is for ISS/CGI which does not have the REQUEST_URI available.
2676
					return '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
2688
					return $sslproxy . '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
2677 2689
						($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'');
2678 2690
				} else return $_SERVER['REQUEST_URI'];
2679 2691
			break;
......
2690 2702
			case 'REMOTE_ADDR':
2691 2703
			case 'REMOTE_HOST':
2692 2704
			case 'HTTP_REFERER':
2693 2705
			case 'HTTP_USER_AGENT':
2694 2706
			case 'HTTP_ACCEPT_LANGUAGE':
2695 2707
			case 'QUERY_STRING':
2696 2708
				return $_SERVER[$getEnvName];
2709
			case 'HTTP_HOST':
2710
				if (!empty ($sslproxy)) {
2711
					return $GLOBALS['TYPO3_CONF_VARS']['BE']['ReverseProxyServer'] ;
2712
				} else { 
2713
					return $_SERVER[$getEnvName];
2714
				}
2715
				break;
2697 2716
			case 'TYPO3_DOCUMENT_ROOT':
2698 2717
				// 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.
2699 2718
				// Therefore the DOCUMENT_ROOT is now always calculated as the SCRIPT_FILENAME minus the end part shared with SCRIPT_NAME.
......
2713 2732
				return $DR;
2714 2733
			break;
2715 2734
			case 'TYPO3_HOST_ONLY':
2735
				if (!empty($sslproxy)) return $GLOBALS[$TYPO3_CONF_VARS['BE']['ReverseProxyServer']];
2716 2736
				$p = explode(':',$_SERVER['HTTP_HOST']);
2717 2737
				return $p[0];
2718 2738
			break;
......
2721 2741
				return $p[1];
2722 2742
			break;
2723 2743
			case 'TYPO3_REQUEST_HOST':
2724
				return (t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://').
2725
					$_SERVER['HTTP_HOST'];
2744
				$retval = (t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://');
2745
				if (empty($sslproxy)) {
2746
					$retval .= $_SERVER['HTTP_HOST'];	
2747
				} else {
2748
					$retval .= $GLOBALS['TYPO3_CONF_VARS']['BE']['ReverseProxyServer'];
2749
				}
2750
				return $retval;
2726 2751
			break;
2727 2752
			case 'TYPO3_REQUEST_URL':
2728
				return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('REQUEST_URI');
2753
				return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').$sslproxy . t3lib_div::getIndpEnv('REQUEST_URI');
2729 2754
			break;
2730 2755
			case 'TYPO3_REQUEST_SCRIPT':
2731 2756
				return t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('SCRIPT_NAME');
......
2746 2771
				return substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
2747 2772
			break;
2748 2773
			case 'TYPO3_SSL':
2749
				return $_SERVER['SSL_SESSION_ID'] || !strcmp($_SERVER['HTTPS'],'on') ? TRUE : FALSE;
2774
				if ($sslproxy) return true;
2775
				if (!strcmp(trim($GLOBALS['TYPO3_CONF_VARS']['BE']['checkSSLProxy']),'1') && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
2776
					return true;
2777
				}
2778
				elseif (strcmp(trim($GLOBALS['TYPO3_CONF_VARS']['BE']['checkSSLProxy']),'0') && $GLOBALS['TYPO3_CONF_VARS']['BE']['checkSSLProxy']==$_SERVER['HTTP_X_FORWARDED_SERVER']) {
2779
					return true;
2780
				}
2781
				else {
2782
					return $HTTP_SERVER_VARS['SSL_SESSION_ID'] || !strcmp($HTTP_SERVER_VARS['HTTPS'],'on') ? TRUE : FALSE;
2783
				} 
2784

  
2750 2785
			break;
2751 2786
			case '_ARRAY':
2752 2787
				$out = array();