WAYF 18.9 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
6
Version: 1.16
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
require_once('templates.php');
require_once('functions.php');
require_once('languages.php');

21
22
23
24
25
26
27
// Set P3P headers just in case they were not set in Apache already
header('P3P: CP="NOI CUR DEVa OUR IND COM NAV PRE"');

// Set default config options
initConfigOptions();

// Read custom locales
haemmer's avatar
haemmer committed
28
29
30
31
32
if (file_exists('custom-languages.php')){
	require_once('custom-languages.php');
}

/*------------------------------------------------*/
haemmer's avatar
haemmer committed
33
// Turn on PHP error reporting
haemmer's avatar
haemmer committed
34
/*------------------------------------------------*/
35
if ($developmentMode){
haemmer's avatar
haemmer committed
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
	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
63
if($useSAML2Metadata && function_exists('xml_parser_create')){
haemmer's avatar
haemmer committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	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'])){
80
	redirectTo($_SERVER['PHP_SELF'].'/redirect/'.$_GET['origin'].'?'.$_GET['getArguments']);
haemmer's avatar
haemmer committed
81
82
83
	exit;
}

haemmer's avatar
haemmer committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*------------------------------------------------*/
// 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;
	}
	
98
	if ($enableDSReturnParamCheck){
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
		// 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
115
	}
116
117
	
	
haemmer's avatar
haemmer committed
118
119
}

haemmer's avatar
haemmer committed
120
121
122
123
124
125
126
127
128
/*------------------------------------------------*/
// Set and delete cookies
/*------------------------------------------------*/

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


// Delete permanent cookie
if (isset($_POST['clear_user_idp'])){
144
	setcookie ($redirectCookieName, '', time() - 3600, '/', $commonDomain, $cookieSecurity, $cookieSecurity);
145
	redirectTo('?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
	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
164
if (isset($_POST['user_idp']) && checkIDPAndShowErrors($_POST['user_idp'])){
haemmer's avatar
haemmer committed
165
	$IDPArray = appendValueToIdPArray($_POST['user_idp'], $IDPArray);
166
	setcookie ($SAMLDomainCookieName, getValueFromIdPArray($IDPArray) , time() + ($cookieValidity*24*3600), '/', $commonDomain, $cookieSecurity, $cookieSecurity);
haemmer's avatar
haemmer committed
167
168
169
170
171
}

// Set cookie for most recently used Service Provider
if (isset($_GET['entityID'])){
	$SPArray = appendValueToIdPArray($_GET['entityID'], array());
172
	setcookie ($SPCookieName, getValueFromIdPArray($SPArray), time() + (10*24*3600), '/', $commonDomain, $cookieSecurity, $cookieSecurity);
haemmer's avatar
haemmer committed
173
174
} else if (isset($_GET['providerId'])){
	$SPArray = appendValueToIdPArray($_GET['providerId'], array());
175
	setcookie ($SPCookieName, getValueFromIdPArray($SPArray), time() + (10*24*3600), '/', $commonDomain, $cookieSecurity, $cookieSecurity);
haemmer's avatar
haemmer committed
176
177
178
179
180
181
}


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

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

// IDP determined by redirect cookie
if (	
		isValidShibRequest()
		&& isset($_COOKIE[$redirectCookieName]) 
212
		&& checkIDP($_COOKIE[$redirectCookieName])
haemmer's avatar
haemmer committed
213
214
215
216
217
218
219
220
	){
	
	$cookieIdP = $_COOKIE[$redirectCookieName];
	
	// Handle cascaded WAYF
	if (isset($IDProviders[$cookieIdP]['Type']) && $IDProviders[$cookieIdP]['Type'] == 'wayf'){
		
		// Send user to cascaded WAYF with same request
221
		redirectTo($IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
222
223
		
	} elseif (isValidDSRequest()){
224
		redirectToSP($_GET['return'], $cookieIdP);
haemmer's avatar
haemmer committed
225
226
227
228
229
		
		// Create log entry
		logAccessEntry('DS', 'Cookie', $_GET['return'], $cookieIdP);
		
	} else {
230
		redirectTo($IDProviders[$cookieIdP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
231
232
233
234
235
236
237
238
239
240
241
		
		// 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
242
if ($useKerberos && isset($_SERVER['REMOTE_USER'])) {
haemmer's avatar
haemmer committed
243
244
245
246
	$kerberosPrincipal = $_SERVER['REMOTE_USER'];
	// Bingo - we have a winner!
	$kerberosRealm = substr($user, 1 + strlen($kerberosPrincipal) - strlen(strrchr($kerberosPrincipal, "@")));
	
247
	if ($kerberosIDP = getKerberosRealm($kerberosRealm) && checkIDP($kerberosIDP)){
haemmer's avatar
haemmer committed
248
249
250
251
252
		
		// Handle cascaded WAYF
		if (isset($IDProviders[$kerberosIDP]['Type']) && $IDProviders[$kerberosIDP]['Type'] == 'wayf'){
			
			// Send user to cascaded WAYF with same request
253
			redirectTo($IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
254
255
			
		} elseif (isValidDSRequest()){
256
			redirectToSP($_GET['return'], $kerberosIDP);
haemmer's avatar
haemmer committed
257
258
259
260
			
			// Create log entry
			logAccessEntry('DS', 'Kerberos', $_GET['return'], $kerberosIDP);
		} else {
261
			redirectTo($IDProviders[$kerberosIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
			
			// 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'];
281
			redirectTo($url);
haemmer's avatar
haemmer committed
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
			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'])
299
		&& checkIDPAndShowErrors($_GET['origin'])
haemmer's avatar
haemmer committed
300
	){
301
	redirectTo($IDProviders[$_GET['origin']]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
302
303
304
305
306
307
308
309
310
311
312
313
314
	
	// 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
315
		redirectTo($IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
316
317
318
319
		exit;
		
	} elseif ( checkPathInfo('redirect') ){
		// Set redirect cookie for this session
320
		setcookie ($redirectCookieName, $hintedPathIDP, null, '/', $commonDomain, $cookieSecurity, $cookieSecurity);
haemmer's avatar
haemmer committed
321
322
323
		
		// Determine if DS or WAYF request
		if (isValidDSRequest()){
324
			redirectToSP($_GET['return'], $hintedPathIDP);
haemmer's avatar
haemmer committed
325
326
327
328
329
			
			// Create log entry
			logAccessEntry('DS', 'Path', $_GET['return'], $hintedPathIDP);
			
		} else {
330
			redirectTo($IDProviders[$hintedPathIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
331
332
333
334
335
336
337
338
339
340
341
342
			
			// Create log entry
			logAccessEntry('WAYF', 'Path', $_GET['shire'], $hintedPathIDP);
		}
		
		exit;
	}
}

// Redirect using user selection
if (
	isset($_POST['user_idp']) 
343
	&& checkIDPAndShowErrors($_POST['user_idp'])
haemmer's avatar
haemmer committed
344
345
346
347
348
349
350
351
352
353
	&& 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
354
		redirectTo($IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
355
356
		
	} else if (isValidDSRequest()){
357
		redirectToSP($_GET['return'], $selectedIDP);
haemmer's avatar
haemmer committed
358
359
360
361
362
363
364
365
366
		
		// 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 {
367
		redirectTo($IDProviders[$selectedIDP]['SSO'].'?'.$_SERVER['QUERY_STRING']);
haemmer's avatar
haemmer committed
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
		
		// 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 = '-';
403
if ($useReverseDNSLookup){
haemmer's avatar
haemmer committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
	$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 = '-';
}

430
431
432
433
/*------------------------------------------------*/
// Sort Identity Providers
/*------------------------------------------------*/

434
if ($useSAML2Metadata){
435
436
437
438
439
	// Only automatically sort if list of Identity Provider is parsed
	// from metadata instead of being manualy managed
	sortIdentityProviders($IDProviders);
}

haemmer's avatar
haemmer committed
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
/*------------------------------------------------*/
// 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 == ''){
459
			redirectTo($_GET['return']);
haemmer's avatar
haemmer committed
460
461
462
463
464
465
			
			// Create log entry
			logAccessEntry('DS', 'Passive', $_GET['return'], '-');
			
			
		} else {
466
			redirectToSP($_GET['return'], $selectedIDP);
haemmer's avatar
haemmer committed
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
			
			// 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
496
497
498
	$message = getLocalString('arguments_missing') . '<pre>';
	$message .= '<code>'.htmlentities($invalidstring).'</code></pre></p>';
	$message .= '<p>'. getLocalString('valid_request_description');
haemmer's avatar
haemmer committed
499
500
	printError($message);
	exit;
501
} elseif(
haemmer's avatar
haemmer committed
502
503
504
505
506
507
508
509
510
		(!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
511
512
513
	$message = getLocalString('arguments_missing') . '</p><pre>';
	$message .= '<code>'.htmlentities($invalidstring).'</code></pre>';
	$message .= '<p>'. getLocalString('valid_saml2_request_description');
haemmer's avatar
haemmer committed
514
515
516
517
518
519
	printError($message);
	exit;
	
} elseif(isRequestType('snippet.html')){
	
	// Check if this feature is activated at all
520
	if (!$useEmbeddedWAYF){
haemmer's avatar
haemmer committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
		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
535
	if (!$useEmbeddedWAYF){
haemmer's avatar
haemmer committed
536
537
538
539
540
541
542
543
544
545
546
547
		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
548
	if (!$useEmbeddedWAYF){
haemmer's avatar
haemmer committed
549
550
551
552
553
554
555
		echo '// The embedded WAYF feature is deactivated in the configuration';
		exit;
	}
	
	// Set JavaScript content type
	header('Content-type: text/javascript;charset="utf-8"');
	
556
557
558
559
560
561
	// If the data protection feature is enabled, don't preselect the IdP
	if ($useEmbeddedWAYFPrivacyProtection){
		$selectedIDP = '-';
	}
	
	// If the referer check is enabled but fails, don't preselect the IdP
haemmer's avatar
haemmer committed
562
	if (
563
564
565
		   !$useEmbeddedWAYFPrivacyProtection
		&&  $useEmbeddedWAYFRefererForPrivacyProtection
		&& !isRequestRefererMatchingSPHost()
haemmer's avatar
haemmer committed
566
567
568
569
		){
		$selectedIDP = '-';
	}
	
haemmer's avatar
haemmer committed
570
571
572
573
574
575
576
577
578
579
580
581
582
	// 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
583
	if ($exportPreselectedIdP){
haemmer's avatar
haemmer committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
		$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
600
	if ($exportPreselectedIdP){
haemmer's avatar
haemmer committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
		$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
619
	if ($exportPreselectedIdP){
haemmer's avatar
haemmer committed
620
621
622
623
624
625
626
627
628
629
630
631
632
633
		$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
634
	if ($exportPreselectedIdP){
haemmer's avatar
haemmer committed
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
		$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
651
	if ($exportPreselectedIdP){
haemmer's avatar
haemmer committed
652
653
654
655
656
657
658
659
660
661
662
		$IDProviders['preselectedIDP'] = $selectedIDP;
	}
	
	echo '$IDProviders = ';
	
	// Return list of IdP array
	var_export($IDProviders);
	
	exit;
	
} elseif (
663
			(isset($_POST['user_idp']) && checkIDPAndShowErrors($_POST['user_idp']))
haemmer's avatar
haemmer committed
664
665
			|| (
				   isset($_COOKIE[$redirectCookieName]) 
666
				&& checkIDP($_COOKIE[$redirectCookieName])
haemmer's avatar
haemmer committed
667
				)
haemmer's avatar
haemmer committed
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
		){
	
	// 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;
} 

?>