diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index c7ab680cc..dab021e28 100644 --- a/application/loginwebpage.class.inc.php +++ b/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!'); diff --git a/application/utils.inc.php b/application/utils.inc.php index 0a6f14739..cf8ac915f 100644 --- a/application/utils.inc.php +++ b/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') { @@ -571,6 +571,25 @@ class utils return $sAppRootUrl; } + /** + * 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: diff --git a/test/testlist.inc.php b/test/testlist.inc.php index a92f753e7..5f8466bcd 100644 --- a/test/testlist.inc.php +++ b/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"); diff --git a/webservices/itop.wsdl.php b/webservices/itop.wsdl.php index cc8943ac0..e37af4d32 100644 --- a/webservices/itop.wsdl.php +++ b/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']; diff --git a/webservices/itopsoap.examples.php b/webservices/itopsoap.examples.php index 9f4754b22..e20cd494b 100644 --- a/webservices/itopsoap.examples.php +++ b/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='; diff --git a/webservices/soapserver.php b/webservices/soapserver.php index d2c21c47e..69bc76cd6 100644 --- a/webservices/soapserver.php +++ b/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 "
  • $sServiceCategory
  • \n"; }