Переглянути джерело

#634 Detection of HTTPS not working with nginx (iTop always considering the current connection as being secure)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2617 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 роки тому
батько
коміт
a2d6746d60

+ 1 - 12
application/loginwebpage.class.inc.php

@@ -220,20 +220,9 @@ EOF
 		return MetaModel::GetConfig()->GetSecureConnectionRequired();
 	}
 
-	static function IsConnectionSecure()
-	{
-		$bSecured = false;
-
-		if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off'))
-		{
-			$bSecured = true;
-		}
-		return $bSecured;
-	}
-	
 	protected static function Login()
 	{
-		if (self::SecureConnectionRequired() && !self::IsConnectionSecure())
+		if (self::SecureConnectionRequired() && !utils::IsConnectionSecure())
 		{
 			// Non secured URL... request for a secure connection
 			throw new Exception('Secure connection required!');			

+ 20 - 1
application/utils.inc.php

@@ -508,7 +508,7 @@ class utils
 	{
 		// Build an absolute URL to this page on this server/port
 		$sServerName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
-		$sProtocol = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!="off")) ? 'https' : 'http';
+		$sProtocol = self::IsConnectionSecure() ? 'https' : 'http';
 		$iPort = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
 		if ($sProtocol == 'http')
 		{
@@ -572,6 +572,25 @@ class utils
 	}
 
 	/**
+	 * Helper to handle the variety of HTTP servers
+	 * See #286 (fixed in [896]), and #634 (this fix)
+	 * 	 
+	 * Though the official specs says 'a non empty string', some servers like IIS do set it to 'off' !
+	 * nginx set it to an empty string
+	 * Others might leave it unset (no array entry)	 
+	 */	 	
+	static public function IsConnectionSecure()
+	{
+		$bSecured = false;
+
+		if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off'))
+		{
+			$bSecured = true;
+		}
+		return $bSecured;
+	}
+
+	/**
 	 * Tells whether or not log off operation is supported.
 	 * Actually in only one case:
 	 * 1) iTop is using an internal authentication

+ 1 - 1
test/testlist.inc.php

@@ -2935,7 +2935,7 @@ abstract class TestSoap extends TestSoapWebService
 		$aSOAPMapping = SOAPMapping::GetMapping();
 
 		// this file is generated dynamically with location = here
-		$sWsdlUri = 'http'.(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off') ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/itop.wsdl.php';
+		$sWsdlUri = 'http'.(utils::IsConnectionSecure() ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/itop.wsdl.php';
 
 		ini_set("soap.wsdl_cache_enabled","0");
 

+ 1 - 1
webservices/itop.wsdl.php

@@ -66,7 +66,7 @@ else
 	$sRawFile = WebServicesBase::GetWSDLContents();
 }
 
-$sServerURI = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/soapserver.php';
+$sServerURI = 'http'.(utils::IsConnectionSecure() ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/soapserver.php';
 if (isset($_REQUEST['service_category']) && (!empty($_REQUEST['service_category'])))
 {
 	$sServerURI .= "?service_category=".$_REQUEST['service_category'];

+ 1 - 3
webservices/itopsoap.examples.php

@@ -24,10 +24,8 @@
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
 
-
 require_once('itopsoaptypes.class.inc.php');
-
-$sItopRoot = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/..';
+$sItopRoot = 'http'.(utils::IsConnectionSecure() ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/..';
 $sWsdlUri = $sItopRoot.'/webservices/itop.wsdl.php';
 //$sWsdlUri .= '?service_category=';
 

+ 2 - 2
webservices/soapserver.php

@@ -32,7 +32,7 @@ require_once(APPROOT.'/application/application.inc.php');
 require_once(APPROOT.'/application/startup.inc.php');
 
 // this file is generated dynamically with location = here
-$sWsdlUri = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/itop.wsdl.php';
+$sWsdlUri = 'http'.(utils::IsConnectionSecure() ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/itop.wsdl.php';
 if (isset($_REQUEST['service_category']) && (!empty($_REQUEST['service_category'])))
 {
 	$sWsdlUri .= "soapserver.php?service_category=".$_REQUEST['service_category'];
@@ -98,7 +98,7 @@ else
 		if (is_subclass_of($sPHPClass, 'WebServicesBase'))
 		{
 			$sServiceCategory = $sPHPClass;
-			$sSoapServerUri = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/soapserver.php';
+			$sSoapServerUri = 'http'.(utils::IsConnectionSecure() ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/soapserver.php';
 			$sSoapServerUri .= "?service_category=$sServiceCategory";
 			echo "<li><a href=\"$sSoapServerUri\">$sServiceCategory</a></li>\n";
 		}