diff --git a/modules/consent/docs/consent.md b/modules/consent/docs/consent.md index 5959a3a36b7eb4c913657d9df9c963c476fac58d..10c52015a6e16bd6d93c4e13b539b955353d8936 100644 --- a/modules/consent/docs/consent.md +++ b/modules/consent/docs/consent.md @@ -42,7 +42,7 @@ the user logs in. Example: 90 => array( - 'class' => 'class:Consent', + 'class' => 'consent:Consent', ), Using storage diff --git a/modules/consent/lib/Consent/Store/Cookie.php b/modules/consent/lib/Consent/Store/Cookie.php index ad448c799149215068942357ae4ed119ce0589af..52ea5f9520e238fb1d03f2ddf440acb7597c6d83 100644 --- a/modules/consent/lib/Consent/Store/Cookie.php +++ b/modules/consent/lib/Consent/Store/Cookie.php @@ -44,20 +44,19 @@ class Cookie extends \SimpleSAML\Module\consent\Store $cookieName = self::_getCookieName($userId, $destinationId); - $data = $userId . ':' . $attributeSet . ':' . $destinationId; + $data = $userId.':'.$attributeSet.':'.$destinationId; - \SimpleSAML\Logger::debug('Consent cookie - Get [' . $data . ']'); + \SimpleSAML\Logger::debug('Consent cookie - Get ['.$data.']'); if (!array_key_exists($cookieName, $_COOKIE)) { \SimpleSAML\Logger::debug( - 'Consent cookie - no cookie with name \'' . - $cookieName . '\'.' + 'Consent cookie - no cookie with name \''.$cookieName.'\'.' ); return false; } if (!is_string($_COOKIE[$cookieName])) { \SimpleSAML\Logger::warning( - 'Value of consent cookie wasn\'t a string. Was: ' . + 'Value of consent cookie wasn\'t a string. Was: '. var_export($_COOKIE[$cookieName], true) ); return false; @@ -99,9 +98,9 @@ class Cookie extends \SimpleSAML\Module\consent\Store assert(is_string($attributeSet)); $name = self::_getCookieName($userId, $destinationId); - $value = $userId . ':' . $attributeSet . ':' . $destinationId; + $value = $userId.':'.$attributeSet.':'.$destinationId; - \SimpleSAML\Logger::debug('Consent cookie - Set [' . $value . ']'); + \SimpleSAML\Logger::debug('Consent cookie - Set ['.$value.']'); $value = self::_sign($value); $this->_setConsentCookie($name, $value); @@ -178,7 +177,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store $tmp = explode(':', $value, 3); if (count($tmp) !== 3) { \SimpleSAML\Logger::warning( - 'Consent cookie with invalid value: ' . $value + 'Consent cookie with invalid value: '.$value ); continue; } @@ -211,7 +210,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store $secretSalt = \SimpleSAML\Utils\Config::getSecretSalt(); - return sha1($secretSalt . $data . $secretSalt) . ':' . $data; + return sha1($secretSalt.$data.$secretSalt).':'.$data; } @@ -260,7 +259,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store assert(is_string($userId)); assert(is_string($destinationId)); - return '\SimpleSAML\Module\consent:' . sha1($userId . ':' . $destinationId); + return '\SimpleSAML\Module\consent:'.sha1($userId.':'.$destinationId); } @@ -279,7 +278,7 @@ class Cookie extends \SimpleSAML\Module\consent\Store $globalConfig = \SimpleSAML\Configuration::getInstance(); $params = array( - 'lifetime' => 7776000, // (90*24*60*60) + 'lifetime' => 7776000, // (90*24*60*60) 'path' => ($globalConfig->getBasePath()), 'httponly' => true, 'secure' => \SimpleSAML\Utils\HTTP::isHTTPS(), diff --git a/modules/consent/templates/consentform.php b/modules/consent/templates/consentform.php index 957775034187df9210c232222890678eaf0a43fe..3c19503ba1a890b7f01ada26ee65a293e5f03e55 100644 --- a/modules/consent/templates/consentform.php +++ b/modules/consent/templates/consentform.php @@ -15,18 +15,19 @@ assert($this->data['sppp'] === false || is_string($this->data['sppp'])); // Parse parameters $dstName = $this->data['dstName']; +$srcName = $this->data['srcName']; $this->data['header'] = $this->t('{consent:consent:consent_header}'); -$this->data['head'] = '<link rel="stylesheet" type="text/css" href="' . - SimpleSAML\Module::getModuleURL("consent/style.css") . '" />' . "\n"; +$this->data['head'] = '<link rel="stylesheet" type="text/css" href="'. + SimpleSAML\Module::getModuleURL("consent/style.css").'" />'."\n"; $this->includeAtTemplateBase('includes/header.php'); ?> <p><?php echo $this->data['consent_accept']; ?></p> <?php -if (isSet($this->data['consent_purpose'])) { - echo '<p>' . $this->data['consent_purpose'] . '</p>'; +if (isset($this->data['consent_purpose'])) { + echo '<p>'.$this->data['consent_purpose'].'</p>'; } ?> @@ -34,8 +35,8 @@ if (isSet($this->data['consent_purpose'])) { <?php if ($this->data['usestorage']) { $checked = ($this->data['checked'] ? 'checked="checked"' : ''); - echo '<input type="checkbox" name="saveconsent" ' . $checked . - ' value="1" /> ' . $this->t('{consent:consent:remember}'); + echo '<input type="checkbox" name="saveconsent" '.$checked. + ' value="1" /> '.$this->t('{consent:consent:remember}'); } // Embed hidden fields... ?> <input type="hidden" name="StateId" value="<?php echo htmlspecialchars($this->data['stateId']); ?>" /> @@ -53,113 +54,17 @@ if ($this->data['usestorage']) { <?php if ($this->data['sppp'] !== false) { - echo "<p>" . htmlspecialchars($this->t('{consent:consent:consent_privacypolicy}')) . " "; - echo '<a target="_blank" href="' . htmlspecialchars($this->data['sppp']) . '">' . $dstName . "</a>"; + echo "<p>".htmlspecialchars($this->t('{consent:consent:consent_privacypolicy}'))." "; + echo '<a target="_blank" href="'.htmlspecialchars($this->data['sppp']).'">'.$dstName."</a>"; echo "</p>"; } -/** - * Recursive attribute array listing function - * - * @param \SimpleSAML\XHTML\Template $t Template object - * @param array $attributes Attributes to be presented - * @param string $nameParent Name of parent element - * - * @return string HTML representation of the attributes - */ -function present_attributes($t, $attributes, $nameParent) -{ - $translator = $t->getTranslator(); - - $alternate = array('odd', 'even'); - $i = 0; - $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"'; - - if (strlen($nameParent) > 0) { - $parentStr = strtolower($nameParent) . '_'; - $str = '<table class="attributes" ' . $summary . '>'; - } else { - $parentStr = ''; - $str = '<table id="table_with_attributes" class="attributes" '. $summary .'>'; - $str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') . - '</caption>'; - } - - foreach ($attributes as $name => $value) { - $nameraw = $name; - $name = $translator->getAttributeTranslation($parentStr . $nameraw); - - if (preg_match('/^child_/', $nameraw)) { - // insert child table - $parentName = preg_replace('/^child_/', '', $nameraw); - foreach ($value as $child) { - $str .= "\n" . '<tr class="odd"><td style="padding: 2em">' . - present_attributes($t, $child, $parentName) . '</td></tr>'; - } - } else { - // insert values directly - - $str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] . - '"><td><span class="attrname">' . htmlspecialchars($name) . '</span>'; - - $isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true); - if ($isHidden) { - $hiddenId = SimpleSAML\Utils\Random::generateID(); - - $str .= '<div class="attrvalue" style="display: none;" id="hidden_' . $hiddenId . '">'; - } else { - $str .= '<div class="attrvalue">'; - } - - if (sizeof($value) > 1) { - // we hawe several values - $str .= '<ul>'; - foreach ($value as $listitem) { - if ($nameraw === 'jpegPhoto') { - $str .= '<li><img src="data:image/jpeg;base64,' . - htmlspecialchars($listitem) . - '" alt="User photo" /></li>'; - } else { - $str .= '<li>' . htmlspecialchars($listitem) . '</li>'; - } - } - $str .= '</ul>'; - } elseif (isset($value[0])) { - // we hawe only one value - if ($nameraw === 'jpegPhoto') { - $str .= '<img src="data:image/jpeg;base64,' . - htmlspecialchars($value[0]) . - '" alt="User photo" />'; - } else { - $str .= htmlspecialchars($value[0]); - } - } // end of if multivalue - $str .= '</div>'; - - if ($isHidden) { - $str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">'; - $str .= '... '; - $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' . $hiddenId; - $str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">'; - $str .= $t->t('{consent:consent:show_attribute}'); - $str .= '</a>'; - $str .= '</div>'; - } - - $str .= '</td></tr>'; - } // end else: not child table - } // end foreach - $str .= isset($attributes)? '</table>':''; - return $str; -} - -echo '<h3 id="attributeheader">' . +echo '<h3 id="attributeheader">'. $this->t( '{consent:consent:consent_attributes_header}', - array( 'SPNAME' => $dstName, 'IDPNAME' => $srcName) - ) . - '</h3>'; + array('SPNAME' => $dstName, 'IDPNAME' => $srcName) + ).'</h3>'; -echo present_attributes($this, $attributes, ''); +echo $this->data['attributes_html']; $this->includeAtTemplateBase('includes/footer.php'); diff --git a/modules/consent/templates/noconsent.php b/modules/consent/templates/noconsent.php index 313ace97fd073422819342f373ba395c3ee6bec5..4ed911533ac0f512e48e5c70935fe074bbdb81d5 100644 --- a/modules/consent/templates/noconsent.php +++ b/modules/consent/templates/noconsent.php @@ -4,21 +4,21 @@ $this->data['header'] = $this->t('{consent:consent:noconsent_title}'); $this->includeAtTemplateBase('includes/header.php'); -echo '<h2>' . $this->data['header'] . '</h2>'; -echo '<p>' . $this->data['noconsent_text'] . '</p>'; +echo '<h2>'.$this->data['header'].'</h2>'; +echo '<p>'.$this->data['noconsent_text'].'</p>'; if ($this->data['resumeFrom']) { - echo('<p><a href="' . htmlspecialchars($this->data['resumeFrom']) . '">'); + echo('<p><a href="'.htmlspecialchars($this->data['resumeFrom']).'">'); echo($this->t('{consent:consent:noconsent_return}')); echo('</a></p>'); } if ($this->data['aboutService']) { - echo('<p><a href="' . htmlspecialchars($this->data['aboutService']) . '">'); + echo('<p><a href="'.htmlspecialchars($this->data['aboutService']).'">'); echo($this->t('{consent:consent:noconsent_goto_about}')); echo('</a></p>'); } -echo('<p><a href="' . htmlspecialchars($this->data['logoutLink']) . '">' . $this->data['noconsent_abort'] . '</a></p>'); +echo('<p><a href="'.htmlspecialchars($this->data['logoutLink']).'">'.$this->data['noconsent_abort'].'</a></p>'); $this->includeAtTemplateBase('includes/footer.php'); diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php index c113e10e36b1878491fcf147b8017be1464a8fc1..4b9065c84f0ad54f7e4790ee1772667c7d7d0784 100644 --- a/modules/consent/www/getconsent.php +++ b/modules/consent/www/getconsent.php @@ -57,7 +57,7 @@ if (array_key_exists('yes', $_REQUEST)) { } \SimpleSAML\Stats::log('consent:accept', $statsInfo); - if ( array_key_exists('consent:store', $state) + if (array_key_exists('consent:store', $state) && array_key_exists('saveconsent', $_REQUEST) && $_REQUEST['saveconsent'] === '1' ) { @@ -68,13 +68,12 @@ if (array_key_exists('yes', $_REQUEST)) { $attributeSet = $state['consent:store.attributeSet']; \SimpleSAML\Logger::debug( - 'Consent - saveConsent() : [' . $userId . '|' . - $targetedId . '|' . $attributeSet . ']' + 'Consent - saveConsent() : ['.$userId.'|'.$targetedId.'|'.$attributeSet.']' ); try { $store->saveConsent($userId, $targetedId, $attributeSet); } catch (\Exception $e) { - \SimpleSAML\Logger::error('Consent: Error writing to storage: ' . $e->getMessage()); + \SimpleSAML\Logger::error('Consent: Error writing to storage: '.$e->getMessage()); } } @@ -126,6 +125,38 @@ $t->data['noTarget'] = \SimpleSAML\Module::getModuleURL('consent/noconsent.php') $t->data['noData'] = array('StateId' => $id); $t->data['attributes'] = $attributes; $t->data['checked'] = $state['consent:checked']; +$t->data['stateId'] = $id; + +$srcName = htmlspecialchars(is_array($srcName) ? $t->t($srcName) : $srcName); +$dstName = htmlspecialchars(is_array($dstName) ? $t->t($dstName) : $dstName); + +$t->data['consent_attributes_header'] = $t->t( + '{consent:consent:consent_attributes_header}', + array('SPNAME' => $dstName, 'IDPNAME' => $srcName) +); + +$t->data['consent_accept'] = $t->t( + '{consent:consent:consent_accept}', + array('SPNAME' => $dstName, 'IDPNAME' => $srcName) +); + +if (array_key_exists('descr_purpose', $state['Destination'])) { + $t->data['consent_purpose'] = $t->t( + '{consent:consent:consent_purpose}', + array( + 'SPNAME' => $dstName, + 'SPDESC' => $translator->getPreferredTranslation( + \SimpleSAML\Utils\Arrays::arrayize( + $state['Destination']['descr_purpose'], + 'en' + ) + ), + ) + ); +} + +$t->data['srcName'] = $srcName; +$t->data['dstName'] = $dstName; $srcName = htmlspecialchars(is_array($srcName) ? $translator->t($srcName) : $srcName); $dstName = htmlspecialchars(is_array($dstName) ? $translator->t($dstName) : $dstName); @@ -216,40 +247,38 @@ function present_attributes($t, $attributes, $nameParent) $alternate = array('odd', 'even'); $i = 0; - $summary = 'summary="' . $translator->t('{consent:consent:table_summary}') . '"'; + $summary = 'summary="'.$t->t('{consent:consent:table_summary}').'"'; if (strlen($nameParent) > 0) { - $parentStr = strtolower($nameParent) . '_'; - $str = '<table class="attributes" ' . $summary . '>'; + $parentStr = strtolower($nameParent).'_'; + $str = '<table class="attributes" '.$summary.'>'; } else { $parentStr = ''; - $str = '<table id="table_with_attributes" class="attributes" '. $summary .'>'; - $str .= "\n" . '<caption>' . $translator->t('{consent:consent:table_caption}') . - '</caption>'; + $str = '<table id="table_with_attributes" class="attributes" '.$summary.'>'; + $str .= "\n".'<caption>'.$t->t('{consent:consent:table_caption}').'</caption>'; } foreach ($attributes as $name => $value) { $nameraw = $name; - $name = $translator->getAttributeTranslation($parentStr . $nameraw); + $name = $translator->getAttributeTranslation($parentStr.$nameraw); if (preg_match('/^child_/', $nameraw)) { // insert child table $parentName = preg_replace('/^child_/', '', $nameraw); foreach ($value as $child) { - $str .= "\n" . '<tr class="odd"><td class="td_odd">' . - present_attributes($t, $child, $parentName) . '</td></tr>'; + $str .= "\n".'<tr class="odd"><td class="td_odd">'. + present_attributes($t, $child, $parentName).'</td></tr>'; } } else { // insert values directly - $str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] . - '"><td><span class="attrname">' . htmlspecialchars($name) . '</span>'; + $str .= "\n".'<tr class="'.$alternate[($i++ % 2)]. + '"><td><span class="attrname">'.htmlspecialchars($name).'</span>'; $isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true); if ($isHidden) { $hiddenId = \SimpleSAML\Utils\Random::generateID(); - - $str .= '<div class="attrvalue hidden" id="hidden_' . $hiddenId . '">'; + $str .= '<div class="attrvalue hidden" id="hidden_'.$hiddenId.'">'; } else { $str .= '<div class="attrvalue">'; } @@ -259,20 +288,18 @@ function present_attributes($t, $attributes, $nameParent) $str .= '<ul>'; foreach ($value as $listitem) { if ($nameraw === 'jpegPhoto') { - $str .= '<li><img src="data:image/jpeg;base64,' . - htmlspecialchars($listitem) . - '" alt="User photo" /></li>'; + $str .= '<li><img src="data:image/jpeg;base64,'. + htmlspecialchars($listitem).'" alt="User photo" /></li>'; } else { - $str .= '<li>' . htmlspecialchars($listitem) . '</li>'; + $str .= '<li>'.htmlspecialchars($listitem).'</li>'; } } $str .= '</ul>'; } elseif (isset($value[0])) { // we hawe only one value if ($nameraw === 'jpegPhoto') { - $str .= '<img src="data:image/jpeg;base64,' . - htmlspecialchars($value[0]) . - '" alt="User photo" />'; + $str .= '<img src="data:image/jpeg;base64,'. + htmlspecialchars($value[0]).'" alt="User photo" />'; } else { $str .= htmlspecialchars($value[0]); } @@ -280,11 +307,11 @@ function present_attributes($t, $attributes, $nameParent) $str .= '</div>'; if ($isHidden) { - $str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">'; + $str .= '<div class="attrvalue consent_showattribute" id="visible_'.$hiddenId.'">'; $str .= '... '; - $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' . $hiddenId; - $str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">'; - $str .= $translator->t('{consent:consent:show_attribute}'); + $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_'.$hiddenId; + $str .= '\'); SimpleSAML_hide(\'visible_'.$hiddenId.'\');">'; + $str .= $t->t('{consent:consent:show_attribute}'); $str .= '</a>'; $str .= '</div>'; }