'.$serviceName.'';
} else {
$serviceName = ''.$serviceName.'';
}
// Compose strings
$promptMessage = sprintf(getLocalString('access_host'), $serviceName);
$actionURL = $_SERVER['SCRIPT_NAME'].'?'.htmlentities($_SERVER['QUERY_STRING']);
$defaultSelected = ($selectedIDP == '-') ? 'selected="selected"' : '';
$rememberSelectionChecked = (isset($_COOKIE[$redirectStateCookieName])) ? 'checked="checked"' : '' ;
include(get_template('body.php'));
}
/******************************************************************************/
// Presents the user a form to set a permanent cookie for their default IDP
function printSettings()
{
global $selectedIDP, $language, $IDProviders, $redirectCookieName;
global $customStrings;
$actionURL = $_SERVER['SCRIPT_NAME'].'?'.htmlentities($_SERVER['QUERY_STRING']);
$defaultSelected = ($selectedIDP == '-') ? 'selected="selected"' : '';
include(get_template('settings.php'));
}
/******************************************************************************/
// Prints the HTML drop down list including categories etc
function printDropDownList($IDProviders, $selectedIDP = '')
{
global $language;
$previouslyUsedIdPsHTML = getPreviouslyUsedIdPsHTML();
echo $previouslyUsedIdPsHTML;
$counter = 0;
$optgroup = '';
foreach ($IDProviders as $key => $values) {
// Get IdP Name
$IdPName = (isset($values[$language]['Name'])) ? $values[$language]['Name'] : $IdPName = $values['Name'];
// Figure out if entry is valid or a category
if (!isset($values['SSO'])) {
// Check if entry is a category
if (isset($values['Type']) && $values['Type'] == 'category') {
if (!empty($optgroup)) {
echo "\n".'';
}
// Skip adding a new category if first category is 'unknown'
// and it is the (probably) only category
if ($key == 'unknown' && empty($optgroup) && $previouslyUsedIdPsHTML == '') {
continue;
}
echo "\n".'';
}
}
/******************************************************************************/
// Prints option group of previously used organisations
function getPreviouslyUsedIdPsHTML()
{
global $IDProviders, $IDPArray, $selectedIDP, $showNumOfPreviouslyUsedIdPs;
if (!isset($IDPArray) || count($IDPArray) < 1) {
return '';
}
$content = '';
$counter = (isset($showNumOfPreviouslyUsedIdPs)) ? $showNumOfPreviouslyUsedIdPs : 3;
for ($n = count($IDPArray) - 1; $n >= 0; $n--) {
if ($counter <= 0) {
break;
}
$optionHTML = printOptionElement($IDProviders, $IDPArray[$n], $selectedIDP);
if (empty($optionHTML)) {
continue;
}
$content .= "\t".$optionHTML."\n";
$counter--;
}
// Return if no previously used IdPs exist
if (empty($content)) {
return '';
}
// Print previously used IdPs
$categoryName = getLocalString('last_used');
$content = "\n".'';
return $content;
}
/******************************************************************************/
// Print a single option element of the drop down list
function printOptionElement($IDProviders, $key, $selectedIDP)
{
global $language;
// Return if IdP does not exit
if (!isset($IDProviders[$key])) {
return '';
}
// Get values
$values = $IDProviders[$key];
// Get IdP Name
$IdPName = (isset($values[$language]['Name'])) ? $values[$language]['Name'] : $IdPName = $values['Name'];
// Set selected attribute
$selected = ($selectedIDP == $key) ? ' selected="selected"' : $selected = '';
// Add additional information as data attribute to the entry
$data = buildIdpData($values, $key);
// Add logo (which is assumed to be 16x16px) to extension string
$logo = (isset($values['Logo'])) ? 'logo="'.$values['Logo']['URL']. '"' : '' ;
return '';
}
/******************************************************************************/
// Prints the notice that tells the users their permanent IDP with an option
// to clear the permanent cookie.
function printNotice()
{
global $redirectCookieName, $IDProviders;
global $customStrings;
$actionURL = $_SERVER['SCRIPT_NAME'].'?'.htmlentities($_SERVER['QUERY_STRING']);
$hiddenUserIdPInput = '';
$permanentUserIdP = getPermanentUserIdp();
$permanentUserIdPName = '';
$permanentUserIdPLogo = '';
if ($permanentUserIdP != '') {
$hiddenUserIdPInput = '';
$permanentUserIdPName = $IDProviders[$permanentUserIdP]['Name'];
if (isset($IDProviders[$permanentUserIdP]['Logo']['URL'])) {
$permanentUserIdPLogo = $IDProviders[$permanentUserIdP]['Logo']['URL'];
}
}
include(get_template('notice.php'));
}
function getPermanentUserIdp()
{
global $redirectCookieName;
$permanentUserIdP = '';
if (
isset($_POST['user_idp'])
&& checkIDPAndShowErrors($_POST['user_idp'])
) {
$permanentUserIdP = $_POST['user_idp'];
} elseif (
isset($_COOKIE[$redirectCookieName])
&& checkIDPAndShowErrors($_COOKIE[$redirectCookieName])
) {
$permanentUserIdP = $_COOKIE[$redirectCookieName];
}
return $permanentUserIdP;
}
/******************************************************************************/
// Prints end of HTML page
function printFooter()
{
include(get_template('footer.php'));
}
/******************************************************************************/
// Prints an error message
function printError($message)
{
global $langStrings, $language, $supportContactEmail;
global $customStrings;
// Show Header
printHeader("error");
include(get_template('error.php'));
// Show footer
printFooter();
}
/******************************************************************************/
// Prints the JavaScript that renders the Embedded WAYF
function printEmbeddedWAYFScript()
{
global $langStrings, $language, $imageURL, $javascriptURL, $cssURL, $logoURL, $smallLogoURL, $federationURL;
global $selectedIDP, $IDProviders, $SAMLDomainCookieName, $redirectCookieName, $redirectStateCookieName;
global $customStrings;
global $apiURL, $developmentMode;
// Set values that are used in the java script
$loginWithString = getLocalString('login_with');
$makeSelectionString = getLocalString('make_selection', 'js');
$loggedInString = getLocalString('logged_in');
$configurationScriptUrl = preg_replace('/embedded-wayf.js/', 'embedded-wayf.js/snippet.html', 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
$utcTime = time();
$checkedBool = (isset($_COOKIE[$redirectStateCookieName]) && !empty($_COOKIE[$redirectStateCookieName])) ? 'checked="checked"' : '' ;
$rememberSelectionText = addslashes(getLocalString('remember_selection'));
$loginString = addslashes(getLocalString('login'));
$selectIdPString = addslashes(getLocalString('select_idp'));
$otherFederationString = addslashes(getLocalString('other_federation'));
$mostUsedIdPsString = addslashes(getLocalString('most_used'));
$lastUsedIdPsString = addslashes(getLocalString('last_used'));
$redirectCookie = (isset($_COOKIE[$redirectCookieName]) && !empty($_COOKIE[$redirectCookieName])) ? $_COOKIE[$redirectCookieName] : '';
// Generate list of Identity Providers
$JSONIdPArray = array();
$JSONCategoryArray = array();
foreach ($IDProviders as $key => $IDProvider) {
// Get IdP Name
if (isset($IDProvider[$language]['Name'])) {
$IdPName = addslashes($IDProvider[$language]['Name']);
} else {
$IdPName = addslashes($IDProvider['Name']);
}
// Set selected attribute
$selected = ($selectedIDP == $key) ? ' selected:"true",' : '' ;
$IdPType = isset($IDProviders[$key]['Type']) ? $IDProviders[$key]['Type'] : '';
// SSO
if (isset($IDProvider['SSO'])) {
$IdPSSO = $IDProvider['SSO'];
} else {
$IdPSSO = '';
}
// Logo URL
if (isset($IDProvider['Logo']['URL'])) {
$IdPLogoURL = $IDProvider['Logo']['URL'];
} else {
$IdPLogoURL = '';
}
// Add other information to find IdP
// $IdPData = getDomainNameFromURI($key);
// $IdPData .= composeOptionData($IDProvider);
$IdPData= buildIdpData($IDProvider, $key);
$IdPData = addslashes($IdPData);
// Skip non-IdP entries
if ($IdPType == '') {
continue;
}
// Fill category and IdP buckets
if ($IdPType == 'category') {
$JSONCategoryArray[] = <<