Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

WAYF 18.7 KB
Newer Older
haemmer's avatar
haemmer committed
1
2
3
4
5
<?php

/*
******************************************************************************
SWITCH PHP WAYF, 
6
Copyright 2009 SWITCH - Serving Swiss Universities
7
Version: 1.14.1
haemmer's avatar
haemmer committed
8
9
10
11
12
13
14
15
16
Contact:  aai@switch.ch
Web site: http://www.switch.ch/aai/wayf
******************************************************************************
*/

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

haemmer's avatar
haemmer committed
17
require_once('config.php');
haemmer's avatar
haemmer committed
18
19
20
21
22
23
24
25
26
27
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
74
75
76
77
78
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');
}

/*------------------------------------------------*/
// Turn on logging depending on development mode
/*------------------------------------------------*/
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'])){
	header('Location: '.$_SERVER['PHP_SELF'].'/redirect/'.$_GET['origin'].'?'.$_GET['getArguments']);
	exit;
}

haemmer's avatar
haemmer committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*------------------------------------------------*/
// 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;
	}
	
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	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
110
	}
111
112
	
	
haemmer's avatar
haemmer committed
113
114
}

haemmer's avatar
haemmer committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
185
/*------------------------------------------------*/
// 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'])){
		header('Location: '.$_GET['return']);
	} else {
		header('Location: '.$_SERVER['SCRIPT_NAME']);
	}
	exit;
}


// Delete permanent cookie
if (isset($_POST['clear_user_idp'])){
	setcookie ($redirectCookieName, '', time() - 3600, '/', $commonDomain, false);
	header('Location: ?'.$_SERVER['QUERY_STRING']);
	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 (
186
	isset($_POST['user_idp']) 
haemmer's avatar
haemmer committed
187
188
	&& checkIDP($_POST['user_idp'])
	){
189
190
191
192
193
194
195
196
	
	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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
}

/*------------------------------------------------*/
// 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
		header('Location: '.$IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
		
	} elseif (isValidDSRequest()){
		header('Location: '.$_GET['return'].'&'.getReturnIDParam().'='.urlencode($cookieIdP));
		
		// Create log entry
		logAccessEntry('DS', 'Cookie', $_GET['return'], $cookieIdP);
		
	} else {
		header('Location: '.$IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
		
		// 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
237
if ($useKerberos && isset($_SERVER['REMOTE_USER'])) {
haemmer's avatar
haemmer committed
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
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
424
	$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
			header('Location: '.$IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
			
		} elseif (isValidDSRequest()){
			header('Location: '.$_GET['return'].'&'.getReturnIDParam().'='.urlencode($kerberosIDP));
			
			// Create log entry
			logAccessEntry('DS', 'Kerberos', $_GET['return'], $kerberosIDP);
		} else {
			header('Location: '.$IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
			
			// 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'];
			header("Location: $url");
			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'])
	){
	header('Location: '.$IDProviders[$_GET['origin']]['SSO'].'?'.$_SERVER['QUERY_STRING']);
	
	// 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
		header('Location: '.$IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
		exit;
		
	} elseif ( checkPathInfo('redirect') ){
		// Set redirect cookie for this session
		setcookie ($redirectCookieName, $hintedPathIDP, null, '/', $commonDomain, false);
		
		// Determine if DS or WAYF request
		if (isValidDSRequest()){
			header('Location: '.$_GET['return'].'&'.getReturnIDParam().'='.urlencode($hintedPathIDP));
			
			// Create log entry
			logAccessEntry('DS', 'Path', $_GET['return'], $hintedPathIDP);
			
		} else {
			header('Location: '.$IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
			
			// 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
		header('Location: '.$IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
		
	} else if (isValidDSRequest()){
		header('Location: '.$_GET['return'].'&'.getReturnIDParam().'='.urlencode($selectedIDP));
		
		// 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 {
		header('Location: '.$IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
		
		// 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 = '-';
}

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

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

haemmer's avatar
haemmer committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
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
490
/*------------------------------------------------*/
// 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 == ''){
			header('Location: '.$_GET['return']);
			
			// Create log entry
			logAccessEntry('DS', 'Passive', $_GET['return'], '-');
			
			
		} else {
			header('Location: '.$_GET['return'].'&'.getReturnIDParam().'='.urlencode($selectedIDP));
			
			// 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');
491
	$message = getLocalString('arguments_missing') . '<pre><code>'.htmlentities($invalidstring).'</code></pre></p>
haemmer's avatar
haemmer committed
492
493
494
495
496
497
498
499
500
501
502
503
504
		<p>'. getLocalString('valid_request_description');
	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');
505
	$message = getLocalString('arguments_missing') . '<pre><code>'.htmlentities($invalidstring).'</code></pre></p>
haemmer's avatar
haemmer committed
506
507
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
550
551
552
553
554
555
556
557
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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
		<p>'. getLocalString('valid_saml2_request_description');
	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"');
	
	// 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']))
			|| (isset($_COOKIE[$redirectCookieName]) && checkIDP($_COOKIE[$redirectCookieName], false))
		){
	
	// 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;
} 

?>