From 6351efb2456263f9811ca2ffad63a99cd9d72df1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Thu, 25 Oct 2007 07:12:47 +0000
Subject: [PATCH] Improved handling of getting its own hostname and port and so
 on... this may cause that people that have included https://foo:443 may now
 have to remove :443 from their metadata

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@54 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 56 ++++++++++++++++--------------------
 www/saml2/sp/initSSO.php     |  2 +-
 2 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index a5772df2f..9fdf2d557 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -19,20 +19,39 @@ require_once('SimpleSAML/Configuration.php');
 class SimpleSAML_Utilities {
 
 
-	public static function selfURLhost() {
+
+	public static function getSelfHost() {
 	
 		$currenthost = $_SERVER['HTTP_HOST'];
 		if(strstr($currenthost, ":")) {
 				$currenthostdecomposed = explode(":", $currenthost);
 				$currenthost = $currenthostdecomposed[0];
 		}
+		return $currenthost;
+	}
+
+
+	public static function selfURLhost() {
+	
+		$currenthost = self::getSelfHost();
 	
 		$s = empty($_SERVER["HTTPS"]) ? ''
 			: ($_SERVER["HTTPS"] == "on") ? "s"
 			: "";
 		$protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
+		
 		$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
 			: (":".$_SERVER["SERVER_PORT"]);
+		
+		
+		$portnumber = $_SERVER["SERVER_PORT"];
+		$port = ':' . $portnumber;
+		if ($protocol == 'http') {
+			if ($portnumber == '80') $port = '';
+		} elseif ($protocol == 'https') {
+			if ($portnumber == '443') $port = '';
+		}
+			
 		$querystring = '';
 		return $protocol."://" . $currenthost . $port;
 	
@@ -40,41 +59,14 @@ class SimpleSAML_Utilities {
 
 	public static function selfURLNoQuery() {
 	
-		$currenthost = $_SERVER['HTTP_HOST'];
-		if(strstr($currenthost, ":")) {
-				$currenthostdecomposed = explode(":", $currenthost);
-				$currenthost = $currenthostdecomposed[0];
-		}
-	
-		$s = empty($_SERVER["HTTPS"]) ? ''
-			: ($_SERVER["HTTPS"] == "on") ? "s"
-			: "";
-		$protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
-		$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
-			: (":".$_SERVER["SERVER_PORT"]);
-		$querystring = '';
-		return $protocol."://" . $currenthost . $port . $_SERVER['SCRIPT_NAME'];
+		$selfURLhost = self::selfURLhost();
+		return $selfURLhost . $_SERVER['SCRIPT_NAME'];
 	
 	}
 
 	public static function selfURL() {
-	
-		$currenthost = $_SERVER['HTTP_HOST'];
-		if(strstr($currenthost, ":")) {
-				$currenthostdecomposed = explode(":", $currenthost);
-				$currenthost = $currenthostdecomposed[0];
-		}
-	
-		$s = empty($_SERVER["HTTPS"]) ? ''
-			: ($_SERVER["HTTPS"] == "on") ? "s"
-			: "";
-		$protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
-		$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
-			: (":".$_SERVER["SERVER_PORT"]);
-		$querystring = '';
-		return $protocol . "://" . $currenthost . $port . $_SERVER['REQUEST_URI'];
-
-	
+		$selfURLhost = self::selfURLhost();
+		return $selfURLhost . $_SERVER['REQUEST_URI'];	
 	}
 	
 	public static function addURLparameter($url, $parameter) {
diff --git a/www/saml2/sp/initSSO.php b/www/saml2/sp/initSSO.php
index 574242de6..c2d9a6354 100644
--- a/www/saml2/sp/initSSO.php
+++ b/www/saml2/sp/initSSO.php
@@ -71,7 +71,7 @@ if (!isset($session) || !$session->isValid() ) {
 		$et->data['e'] = $exception;
 		
 		$et->show();
-
+		exit(0);
 	}
 
 } else {
-- 
GitLab