WAYF 18.6 KB
Newer Older
haemmer's avatar
haemmer committed
1
<?php // Copyright (c) 2011, SWITCH - Serving Swiss Universities
haemmer's avatar
haemmer committed
2 3 4

/*
******************************************************************************
haemmer's avatar
haemmer committed
5
SWITCHwayf
haemmer's avatar
haemmer committed
6
Version: 1.15
haemmer's avatar
haemmer committed
7 8 9 10 11 12 13 14 15
Contact:  aai@switch.ch
Web site: http://www.switch.ch/aai/wayf
******************************************************************************
*/

/*------------------------------------------------*/
// Load general configuration and template file
/*------------------------------------------------*/

haemmer's avatar
haemmer committed
16
require_once('config.php');
haemmer's avatar
haemmer committed
17 18 19 20 21 22 23 24 25 26
require_once('templates.php');
require_once('functions.php');
require_once('languages.php');

// Read custom strings
if (file_exists('custom-languages.php')){
	require_once('custom-languages.php');
}

/*------------------------------------------------*/
haemmer's avatar
haemmer committed
27
// Turn on PHP error reporting
haemmer's avatar
haemmer committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
/*------------------------------------------------*/
if (isset($developmentMode) && $developmentMode){
	ini_set('error_reporting', E_ALL);
	ini_set('display_errors', 'On');
	ini_set('log_erros', 'Off');
} else {
	error_reporting(0);
}

/*------------------------------------------------*/
// Read IDP configuration file
/*------------------------------------------------*/

// Determine language
$language = determineLanguage();

// Check if IdP files differ
// If not load file
if ($IDPConfigFile == $backupIDPConfigFile){
	require_once($IDPConfigFile);
// If they do, check config file
} elseif (checkConfig($IDPConfigFile, $backupIDPConfigFile)){
	require_once($IDPConfigFile);
// Use backup file if something went wrong 
} else {
	require_once($backupIDPConfigFile);
}

// Read metadata file if configuration option is set
if(isset($useSAML2Metadata) && $useSAML2Metadata && function_exists('xml_parser_create')){
	require('readMetadata.php');
}

// Set default type
foreach ($IDProviders as $key => $values){
	if (!isset($IDProviders[$key]['Type'])){
		$IDProviders[$key]['Type'] = 'unknown';
	}
}

/*------------------------------------------------*/
// Back-wards compatibility logic
/*------------------------------------------------*/

// This is for back-wards compatibility with very old versions of the WAYF
if (isset($_GET['getArguments']) && isset($_GET['origin']) && isset($_GET['redirect'])){
74
	redirectTo($_SERVER['PHP_SELF'].'/redirect/'.$_GET['origin'].'?'.$_GET['getArguments']);
haemmer's avatar
haemmer committed
75 76 77
	exit;
}

haemmer's avatar
haemmer committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
/*------------------------------------------------*/
// Input validation
/*------------------------------------------------*/

if(isValidDSRequest()){
	// Check that return URL in DS request is a valid URL
	$returnURL = verifyAndStripReturnURL($_GET['return']);
	if(!$returnURL){
		// Show error
		$message = sprintf(getLocalString('invalid_return_url'), htmlentities($_GET['return']));
		printError($message);
		exit;
	}
	
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	if (isset($enableDSReturnParamCheck) && $enableDSReturnParamCheck){
		// Check SP
		if(!isset($SProviders[$_GET['entityID']])){
			// Show error
			$message = sprintf(getLocalString('unknown_sp'), htmlentities($_GET['entityID']));
			printError($message);
			exit;
		}
		
		// Check return URL in DS request if checks are enabled
		$returnURLOK = verifyReturnURL($_GET['entityID'], $returnURL);
		if(!$returnURLOK){
			// Show error
			$message = sprintf(getLocalString('unverified_return_url'), htmlentities($returnURL), htmlentities($_GET['entityID']));
			printError($message);
			exit;
		}
haemmer's avatar
haemmer committed
109
	}
110 111
	
	
haemmer's avatar
haemmer committed
112 113
}

haemmer's avatar
haemmer committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127
/*------------------------------------------------*/
// Set and delete cookies
/*------------------------------------------------*/

// Delete all cookies
if (isRequestType('deleteSettings')){
	$cookies = array($redirectCookieName, $redirectStateCookieName, $SAMLDomainCookieName, $SPCookieName);
	foreach ($cookies as $cookie){ 
		if (isset($_COOKIE[$cookie])){
				setcookie($cookie,'',time()-86400, '/', $commonDomain);
		}
	}
	
	if (isset($_GET['return'])){
128
		redirectTo($_GET['return']);
haemmer's avatar
haemmer committed
129
	} else {
130
		redirectTo($_SERVER['SCRIPT_NAME']);
haemmer's avatar
haemmer committed
131 132 133 134 135 136 137 138
	}
	exit;
}


// Delete permanent cookie
if (isset($_POST['clear_user_idp'])){
	setcookie ($redirectCookieName, '', time() - 3600, '/', $commonDomain, false);
139
	redirectTo('?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
	exit;
}

// Get previously accessed IdPs
if (isset($_COOKIE[$SAMLDomainCookieName])){
	$IDPArray = getIdPArrayFromValue($_COOKIE[$SAMLDomainCookieName]);
} else {
	$IDPArray = array();
}

// Get previously accessed SPs
if (isset($_COOKIE[$SPCookieName])){
	$SPArray = getIdPArrayFromValue($_COOKIE[$SPCookieName]);
} else {
	$SPArray = array();
}

// Set Cookie to remember the selection
if (isset($_POST['user_idp']) && checkIDP($_POST['user_idp'])){
	$IDPArray = appendValueToIdPArray($_POST['user_idp'], $IDPArray);
	setcookie ($SAMLDomainCookieName, getValueFromIdPArray($IDPArray) , time() + (1000*24*3600), '/', $commonDomain, false);
}

// Set cookie for most recently used Service Provider
if (isset($_GET['entityID'])){
	$SPArray = appendValueToIdPArray($_GET['entityID'], array());
	setcookie ($SPCookieName, getValueFromIdPArray($SPArray), time() + (10*24*3600), '/', $commonDomain, false);
} else if (isset($_GET['providerId'])){
	$SPArray = appendValueToIdPArray($_GET['providerId'], array());
	setcookie ($SPCookieName, getValueFromIdPArray($SPArray), time() + (10*24*3600), '/', $commonDomain, false);
}


// Set the permanent or session cookie
if (isset($_POST['permanent']) 
	&& isset($_POST['user_idp']) 
	&& checkIDP($_POST['user_idp'])){
	
	// Set permanent cookie 
	if (is_numeric($_POST['permanent'])){
		setcookie ($redirectCookieName, $_POST['user_idp'], time() + ($_POST['permanent']*24*3600), '/', $commonDomain, false);
	} else {
		setcookie ($redirectCookieName, $_POST['user_idp'], time() + (100*24*3600), '/', $commonDomain, false);
	}
} elseif (
185
	isset($_POST['user_idp']) 
haemmer's avatar
haemmer committed
186 187
	&& checkIDP($_POST['user_idp'])
	){
188 189 190 191 192 193 194 195
	
	if (isset($_POST['session'])){
		// Set redirection cookie and redirection state cookie
		setcookie ($redirectCookieName, $_POST['user_idp'], null, '/', $commonDomain, false);
		setcookie ($redirectStateCookieName, 'checked', time() + (100*24*3600), '/', $commonDomain, false);
	} else {
		setcookie ($redirectStateCookieName, 'checked', time() - 3600, '/', $commonDomain, false);
	}
haemmer's avatar
haemmer committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
}

/*------------------------------------------------*/
// Redirecting user
/*------------------------------------------------*/

// IDP determined by redirect cookie
if (	
		isValidShibRequest()
		&& isset($_COOKIE[$redirectCookieName]) 
		&& checkIDP($_COOKIE[$redirectCookieName], false)
	){
	
	$cookieIdP = $_COOKIE[$redirectCookieName];
	
	// Handle cascaded WAYF
	if (isset($IDProviders[$cookieIdP]['Type']) && $IDProviders[$cookieIdP]['Type'] == 'wayf'){
		
		// Send user to cascaded WAYF with same request
215
		redirectTo($IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
216 217
		
	} elseif (isValidDSRequest()){
218
		redirectToSP($_GET['return'], $cookieIdP);
haemmer's avatar
haemmer committed
219 220 221 222 223
		
		// Create log entry
		logAccessEntry('DS', 'Cookie', $_GET['return'], $cookieIdP);
		
	} else {
224
		redirectTo($IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
225 226 227 228 229 230 231 232 233 234 235
		
		// Create log entry
		logAccessEntry('WAYF', 'Cookie', $_GET['shire'], $cookieIdP);
		
	}
		
	exit;
} 

// Redirect using Kerberos
// Check if $REMOTE_USER has been set by mod_auth_kerb
haemmer's avatar
haemmer committed
236
if ($useKerberos && isset($_SERVER['REMOTE_USER'])) {
haemmer's avatar
haemmer committed
237 238 239 240 241 242 243 244 245 246
	$kerberosPrincipal = $_SERVER['REMOTE_USER'];
	// Bingo - we have a winner!
	$kerberosRealm = substr($user, 1 + strlen($kerberosPrincipal) - strlen(strrchr($kerberosPrincipal, "@")));
	
	if ($kerberosIDP = getKerberosRealm($kerberosRealm) && checkIDP($kerberosIDP, false)){
		
		// Handle cascaded WAYF
		if (isset($IDProviders[$kerberosIDP]['Type']) && $IDProviders[$kerberosIDP]['Type'] == 'wayf'){
			
			// Send user to cascaded WAYF with same request
247
			redirectTo($IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
248 249
			
		} elseif (isValidDSRequest()){
250
			redirectToSP($_GET['return'], $kerberosIDP);
haemmer's avatar
haemmer committed
251 252 253 254
			
			// Create log entry
			logAccessEntry('DS', 'Kerberos', $_GET['return'], $kerberosIDP);
		} else {
255
			redirectTo($IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
			
			// Create log entry
			logAccessEntry('WAYF', 'Kerberos', $_GET['shire'], $kerberosIDP);
		}
		exit;
	}
}

// Trigger Kerberos authentication
if ($useKerberos && !isset($kerberosRealm)) {
	// Check the headers for an Authorisation header.
	$headers = getallheaders();
	// If its' there...
	foreach ($headers as $name => $content) {
			if ($name == "Authorization") {
			// ... then the user agent is attempting Negotiate, so we
			// redirect to the soft link (that points back to this script)
			// which is	 protected by mod_auth_kerb.
			$url = $kerberosRedirectURL."?".$_SERVER['QUERY_STRING'];
275
			redirectTo($url);
haemmer's avatar
haemmer committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
			exit();
		}
	}
	
	// Send the User Agent a Negotiate header
	// This will provoke a User Agent that supports Negotiate into requesting this 
	// script a second time, including an 'Authorize' header. We catch this header
	// in the code above.
	header('WWW-Authenticate: Negotiate');
	// If the User Agent doesn't support Negotiate, we continue as usual.
}

// For backwards compatiblity
if (	
		isset($_GET['shire']) 
		&& isset($_GET['target'])
		&& isset($_GET['origin'])
		&& checkIDP($_GET['origin'])
	){
295
	redirectTo($IDProviders[$_GET['origin']]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
296 297 298 299 300 301 302 303 304 305 306 307 308
	
	// Create log entry
	logAccessEntry('WAYF', 'Old-Request', $_GET['shire'], $_GET['origin']);
	exit;
} 

// Redirect using resource hint
$hintedPathIDP = getIdPPathInfoHint();
if ($hintedPathIDP != '-'){
	// Handle cascaded WAYF
	if (isset($IDProviders[$hintedPathIDP]['Type']) && $IDProviders[$hintedPathIDP]['Type'] == 'wayf'){
		
		// Send user to cascaded WAYF with same request
309
		redirectTo($IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
310 311 312 313 314 315 316 317
		exit;
		
	} elseif ( checkPathInfo('redirect') ){
		// Set redirect cookie for this session
		setcookie ($redirectCookieName, $hintedPathIDP, null, '/', $commonDomain, false);
		
		// Determine if DS or WAYF request
		if (isValidDSRequest()){
318
			redirectToSP($_GET['return'], $hintedPathIDP);
haemmer's avatar
haemmer committed
319 320 321 322 323
			
			// Create log entry
			logAccessEntry('DS', 'Path', $_GET['return'], $hintedPathIDP);
			
		} else {
324
			redirectTo($IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
			
			// Create log entry
			logAccessEntry('WAYF', 'Path', $_GET['shire'], $hintedPathIDP);
		}
		
		exit;
	}
}

// Redirect using user selection
if (
	isset($_POST['user_idp']) 
	&& checkIDP($_POST['user_idp'])
	&& isValidShibRequest()
	&& !isset($_POST['permanent'])
	){
	
	$selectedIDP = $_POST['user_idp'];
	
	// Handle cascaded WAYF
	if (isset($IDProviders[$selectedIDP]['Type']) && $IDProviders[$selectedIDP]['Type'] == 'wayf'){
		
		// Send user to cascaded WAYF with same request
348
		redirectTo($IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
349 350
		
	} else if (isValidDSRequest()){
351
		redirectToSP($_GET['return'], $selectedIDP);
haemmer's avatar
haemmer committed
352 353 354 355 356 357 358 359 360
		
		// Create log entry
		if (isset($_POST['request_type']) && $_POST['request_type'] == 'embedded'){
			logAccessEntry('Embedded-DS', 'Request', $_GET['return'], $selectedIDP);
		} else {
			logAccessEntry('DS', 'Request', $_GET['return'], $selectedIDP);
		}
		
	} else {
361
		redirectTo($IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
		
		// Create log entry
		if (isset($_POST['request_type']) && $_POST['request_type'] == 'embedded'){
			logAccessEntry('Embedded-WAYF', 'Request', $_GET['shire'], $selectedIDP);
		} else {
			logAccessEntry('WAYF', 'Request', $_GET['shire'], $selectedIDP);
		}
	}
	exit;
}

/*------------------------------------------------*/
// Gather data to preselect user's IdP
/*------------------------------------------------*/

// Initialize selected IdP
$selectedIDP = '-';

// Cookie hint
$hintedCookieIdP = '-';
if (count($IDPArray) > 0){
	// Make sure one of these IdP exists
	foreach ($IDPArray as $previouslyUsedIDP){
		if (isset($IDProviders[$previouslyUsedIDP])){
			$hintedCookieIdP = $previouslyUsedIDP;
		}
	}
} 

// IP address range hint
$hintedIPIDP = '-';
$hintedIPIDP = getIPAdressHint();

// Reverse DNS lookup hint
$hintedDomainIDP = '-';
if (isset($useReverseDNSLookup) && $useReverseDNSLookup){
	$hintedDomainIDP = getDomainNameFromURIHint();
}

/*------------------------------------------------*/
// Determine preselected IdP using gathered data
/*------------------------------------------------*/

// Prioritise selected IDP in this sequence
// - Previous used IdP
// - Path info hint
// - IP address range hint 
// - Reverse DNS Lookup hint
// - No Preselection

if ($hintedCookieIdP != '-'){
	$selectedIDP = $hintedCookieIdP;
} elseif ($hintedPathIDP != '-'){
	$selectedIDP = $hintedPathIDP;
} elseif ($hintedIPIDP != '-'){
	$selectedIDP = $hintedIPIDP;
} elseif ($hintedDomainIDP != '-'){
	$selectedIDP = $hintedDomainIDP;
} else {
	$selectedIDP = '-';
}

424 425 426 427
/*------------------------------------------------*/
// Sort Identity Providers
/*------------------------------------------------*/

428
if (isset($useSAML2Metadata) && $useSAML2Metadata){
429 430 431 432 433
	// Only automatically sort if list of Identity Provider is parsed
	// from metadata instead of being manualy managed
	sortIdentityProviders($IDProviders);
}

haemmer's avatar
haemmer committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
/*------------------------------------------------*/
// Draw WAYF
/*------------------------------------------------*/

// Coming from an SP with proper GET arguments
if ( 
	isValidShibRequest() 
	&& (!isset($_POST['user_idp']) || $_POST['user_idp'] == '-')
	) {
	
	// Return directly to IdP if isPassive is set
	if (
		isValidDSRequest() 
		&& isset($_GET['isPassive'])
		&& $_GET['isPassive'] == 'true'
		){
		
		// Only return user with returnIDParam to SP if IdP could be guessed
		if ($selectedIDP == '-' || $selectedIDP == ''){
453
			redirectTo($_GET['return']);
haemmer's avatar
haemmer committed
454 455 456 457 458 459
			
			// Create log entry
			logAccessEntry('DS', 'Passive', $_GET['return'], '-');
			
			
		} else {
460
			redirectToSP($_GET['return'], $selectedIDP);
haemmer's avatar
haemmer committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
			
			// Create log entry
			logAccessEntry('DS', 'Passive', $_GET['return'], $selectedIDP);
		}
		exit;
	}
	
	// Show selection
	
	// Show Header
	printHeader();
	
	// Show drop down list
	printWAYF();
	
	// Show footer
	printFooter();
	exit;
	
} elseif(
		(!isset($_GET['shire']) && isset($_GET['target'])) 
		|| (isset($_GET['shire']) && !isset($_GET['target']))
){
	
	// Show error
	$invalidstring = urldecode($_SERVER['QUERY_STRING']);
	$invalidstring = preg_replace('/&/',"&\n",$invalidstring);
	if ($invalidstring == '')
		$invalidstring = getLocalString('no_arguments');
haemmer's avatar
haemmer committed
490 491 492
	$message = getLocalString('arguments_missing') . '<pre>';
	$message .= '<code>'.htmlentities($invalidstring).'</code></pre></p>';
	$message .= '<p>'. getLocalString('valid_request_description');
haemmer's avatar
haemmer committed
493 494 495 496 497 498 499 500 501 502 503 504
	printError($message);
	exit;
}  elseif(
		(!isset($_GET['entityID']) && isset($_GET['return'])) 
		|| (isset($_GET['entityID']) && !isset($_GET['return']))
){
	
	// Show error
	$invalidstring = urldecode($_SERVER['QUERY_STRING']);
	$invalidstring = preg_replace('/&/',"&\n",$invalidstring);
	if ($invalidstring == '')
		$invalidstring = getLocalString('no_arguments');
haemmer's avatar
haemmer committed
505 506 507
	$message = getLocalString('arguments_missing') . '</p><pre>';
	$message .= '<code>'.htmlentities($invalidstring).'</code></pre>';
	$message .= '<p>'. getLocalString('valid_saml2_request_description');
haemmer's avatar
haemmer committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
	printError($message);
	exit;
	
} elseif(isRequestType('snippet.html')){
	
	// Check if this feature is activated at all
	if (!isset($useEmbeddedWAYF) || !$useEmbeddedWAYF){
		echo '// The embedded WAYF feature is deactivated in the configuration';
		exit;
	}
	
	// Return the HTML snippet for including the Embedded WAYF
	printEmbeddedConfigurationScript();
	
	exit;

} elseif(isRequestType('snippet.txt')){
	
	header('Content-Type: text/plain');
	
	// Check if this feature is activated at all
	if (!isset($useEmbeddedWAYF) || !$useEmbeddedWAYF){
		echo '// The embedded WAYF feature is deactivated in the configuration';
		exit;
	}
	
	// Return the HTML snippet for including the Embedded WAYF
	printEmbeddedConfigurationScript();
	
	exit;

} elseif(isRequestType('embedded-wayf.js')){
	
	// Check if this feature is activated at all
	if (!isset($useEmbeddedWAYF) || !$useEmbeddedWAYF){
		echo '// The embedded WAYF feature is deactivated in the configuration';
		exit;
	}
	
	// Set JavaScript content type
	header('Content-type: text/javascript;charset="utf-8"');
	
haemmer's avatar
haemmer committed
550 551 552 553 554 555 556 557
	// Is Embedded WAYF data protection feature enabled?
	if (
		   isset($useEmbeddedWAYFPrivacyProtection) 
		&& $useEmbeddedWAYFPrivacyProtection == true
		){
		$selectedIDP = '-';
	}
	
haemmer's avatar
haemmer committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
	// Generate JavaScript code
	printEmbeddedWAYFScript();
	
	exit;
	
} elseif (isRequestType('ShibbolethDS-IDProviders.json')){
	
	// Return $IdProviders as JSON data structure
	if (!$developmentMode){
		header('Content-Type: application/json');
	}
	
	// Add guessed Identity Provider
	if (isset($exportPreselectedIdP) && $exportPreselectedIdP){
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	$ShibDSIDProviders = convertToShibDSStructure($IDProviders);
	
	// Add list of IdPs
	echo json_encode($ShibDSIDProviders);
	
	exit;
	
} elseif (isRequestType('ShibbolethDS-IDProviders.js')){
	
	// Set JavaScript content type
	header('Content-type: text/javascript;charset="utf-8"');
	
	// Add guessed Identity Provider
	if (isset($exportPreselectedIdP) && $exportPreselectedIdP){
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	$ShibDSIDProviders = convertToShibDSStructure($IDProviders);
	
	// Add list of IdPs
	echo 'var myJSONObject = '.json_encode($ShibDSIDProviders).';';
	
	exit;
	
} elseif (isRequestType('IDProviders.json')){
	
	// Return $IdProviders as JSON data structure
	if (!$developmentMode){
		header('Content-Type: application/json');
	}
	
	// Add guessed Identity Provider
	if (isset($exportPreselectedIdP) && $exportPreselectedIdP){
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	// Add list of IdPs
	echo json_encode($IDProviders);
	
	exit;
	
} elseif (isRequestType('IDProviders.txt')){
	
	// Return $IdProviders as human readable data
	header('Content-Type: text/plain');
	
	// Add guessed Identity Provider
	if (isset($exportPreselectedIdP) && $exportPreselectedIdP){
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	echo 'IDProviders = ';
	
	// Return list of IdP array
	print_r($IDProviders);
	
	exit;
	
} elseif (isRequestType('IDProviders.php')){
	
	// Return $IdProviders as PHP code
	header('Content-Type: text/plain');
	
	// Add guessed Identity Provider
	if (isset($exportPreselectedIdP) && $exportPreselectedIdP){
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	echo '$IDProviders = ';
	
	// Return list of IdP array
	var_export($IDProviders);
	
	exit;
	
} elseif (
			(isset($_POST['user_idp']) && checkIDP($_POST['user_idp']))
haemmer's avatar
haemmer committed
652 653 654 655
			|| (
				   isset($_COOKIE[$redirectCookieName]) 
				&& checkIDP($_COOKIE[$redirectCookieName], false)
				)
haemmer's avatar
haemmer committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
		){
	
	// Show confirmatin notice
	// Show Header
	printHeader();
	
	// Show drop down list
	printNotice();
	
	// Show footer
	printFooter();
	
	exit;
} else {
	
	// Show Header
	printHeader();
	
	// Show drop down list
	printSettings();
	
	// Show footer
	printFooter();
	exit;
} 

?>