Skip to content
Snippets Groups Projects
Commit 88e1dd72 authored by Olav Morken's avatar Olav Morken
Browse files

Allow for templates describing the errors to be included into the main error template.

This patch also changes the MetadataNotFound and NoState errors to use this structure.

Thanks to Andjelko Horvat for implementing this.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2773 44740490-163a-0410-bde0-09ae8108e29a
parent d0ba85be
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,14 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -50,6 +50,14 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
private $parameters; private $parameters;
/**
* Name of custom include template for the error.
*
* @var string|NULL
*/
protected $includeTemplate = NULL;
/** /**
* Constructor for this error. * Constructor for this error.
* *
...@@ -217,6 +225,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -217,6 +225,7 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
$data['module'] = $this->module; $data['module'] = $this->module;
$data['dictTitle'] = $this->dictTitle; $data['dictTitle'] = $this->dictTitle;
$data['dictDescr'] = $this->dictDescr; $data['dictDescr'] = $this->dictDescr;
$data['includeTemplate'] = $this->includeTemplate;
/* Check if there is a valid technical contact email address. */ /* Check if there is a valid technical contact email address. */
if($config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') { if($config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') {
......
...@@ -8,13 +8,6 @@ ...@@ -8,13 +8,6 @@
*/ */
class SimpleSAML_Error_MetadataNotFound extends SimpleSAML_Error_Error { class SimpleSAML_Error_MetadataNotFound extends SimpleSAML_Error_Error {
/**
* The entityID we were unable to locate.
*
* @var string
*/
private $entityId;
/** /**
* Create the error * Create the error
...@@ -24,31 +17,11 @@ class SimpleSAML_Error_MetadataNotFound extends SimpleSAML_Error_Error { ...@@ -24,31 +17,11 @@ class SimpleSAML_Error_MetadataNotFound extends SimpleSAML_Error_Error {
public function __construct($entityId) { public function __construct($entityId) {
assert('is_string($entityId)'); assert('is_string($entityId)');
$this->includeTemplate = 'core:no_metadata.tpl.php';
parent::__construct(array( parent::__construct(array(
'METADATANOTFOUND', 'METADATANOTFOUND',
'ENTITYID' => htmlspecialchars(var_export($entityId, TRUE)) '%ENTITYID%' => htmlspecialchars(var_export($entityId, TRUE))
)); ));
$this->entityId = $entityId;
}
/**
* Show the error to the user.
*
* This function does not return.
*/
public function show() {
header('HTTP/1.0 500 Internal Server Error');
$this->logError();
$globalConfig = SimpleSAML_Configuration::getInstance();
$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:no_metadata.tpl.php');
$t->data['entityId'] = $this->entityId;
$t->show();
exit();
} }
} }
...@@ -14,44 +14,8 @@ class SimpleSAML_Error_NoState extends SimpleSAML_Error_Error { ...@@ -14,44 +14,8 @@ class SimpleSAML_Error_NoState extends SimpleSAML_Error_Error {
* Create the error * Create the error
*/ */
public function __construct() { public function __construct() {
$this->includeTemplate = 'core:no_state.tpl.php';
parent::__construct('NOSTATE'); parent::__construct('NOSTATE');
} }
/**
* Show the error to the user.
*
* This function does not return.
*/
public function show() {
header('HTTP/1.0 500 Internal Server Error');
$errorData = $this->saveError();
$session = SimpleSAML_Session::getInstance();
$attributes = $session->getAttributes();
if (isset($attributes['mail'][0])) {
$email = $attributes['mail'][0];
} else {
$email = '';
}
$globalConfig = SimpleSAML_Configuration::getInstance();
$t = new SimpleSAML_XHTML_Template($globalConfig, 'core:no_state.tpl.php');
/* Enable error reporting if we have a valid technical contact email. */
if($globalConfig->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') {
/* Enable error reporting. */
$baseurl = SimpleSAML_Utilities::getBaseURL();
$t->data['errorReportAddress'] = $baseurl . 'errorreport.php';
$t->data['reportId'] = $errorData['reportId'];
$t->data['email'] = $email;
}
$t->show();
exit();
}
} }
<?php <?php
$this->data['header'] = $this->t('{core:no_metadata:header}');
$this->includeAtTemplateBase('includes/header.php');
echo('<h2>' . $this->t('{core:no_metadata:header}') . '</h2>');
echo('<p>' . $this->t('{core:no_metadata:not_found_for}') . '</p>');
echo('<code style="margin-left: 3em;">' . htmlspecialchars($this->data['entityId']) . '</code>');
echo('<p>' . $this->t('{core:no_metadata:config_problem}') . '</p>'); echo('<p>' . $this->t('{core:no_metadata:config_problem}') . '</p>');
echo('<ul>'); echo('<ul>');
...@@ -13,4 +7,3 @@ echo('<li>' . $this->t('{core:no_metadata:suggestion_user_link}') . '</li>'); ...@@ -13,4 +7,3 @@ echo('<li>' . $this->t('{core:no_metadata:suggestion_user_link}') . '</li>');
echo('<li>' . $this->t('{core:no_metadata:suggestion_developer}') . '</li>'); echo('<li>' . $this->t('{core:no_metadata:suggestion_developer}') . '</li>');
echo('</ul>'); echo('</ul>');
$this->includeAtTemplateBase('includes/footer.php');
<?php <?php
$this->data['header'] = $this->t('{core:no_state:header}');
$this->includeAtTemplateBase('includes/header.php');
echo('<h2>' . $this->t('{core:no_state:header}') . '</h2>');
echo('<p>' . $this->t('{core:no_state:description}') . '</p>');
echo('<h3>' . $this->t('{core:no_state:suggestions}') . '</h3>'); echo('<h3>' . $this->t('{core:no_state:suggestions}') . '</h3>');
echo('<ul>'); echo('<ul>');
echo('<li>' . $this->t('{core:no_state:suggestion_goback}') . '</li>'); echo('<li>' . $this->t('{core:no_state:suggestion_goback}') . '</li>');
...@@ -19,25 +13,3 @@ echo('<li>' . $this->t('{core:no_state:cause_openbrowser}') . '</li>'); ...@@ -19,25 +13,3 @@ echo('<li>' . $this->t('{core:no_state:cause_openbrowser}') . '</li>');
echo('<li>' . $this->t('{core:no_state:cause_nocookie}') . '</li>'); echo('<li>' . $this->t('{core:no_state:cause_nocookie}') . '</li>');
echo('</ul>'); echo('</ul>');
/* Add error report submit section if we have a valid technical contact. */
if (isset($this->data['errorReportAddress'])) {
echo('<h2>' . $this->t('{core:no_state:report_header}') . '</h2>');
echo('<form action="' . htmlspecialchars($this->data['errorReportAddress']) . '" method="post">');
echo('<p>' . $this->t('{core:no_state:report_text}') . '</p>');
echo('<p>' . $this->t('{errors:report_email}') . '<input type="text" size="25" name="email" value="' . htmlspecialchars($this->data['email']) . '"/></p>');
echo('<p>');
echo('<textarea style="width: 300px; height: 100px" name="text">' . $this->t('{errors:report_explain}') . '</textarea>');
echo('</p>');
echo('<p>');
echo('<input type="hidden" name="reportId" value="' . $this->data['reportId'] . '" />');
echo('<input type="submit" name="send" value="' . $this->t('{errors:report_submit}') . '" />');
echo('</p>');
echo('</form>');
}
$this->includeAtTemplateBase('includes/footer.php');
<?php <?php
$this->data['header'] = $this->t('error_header'); $this->data['header'] = $this->t($this->data['dictTitle']);
$this->data['head'] = ' $this->data['head'] = '
<meta name="robots" content="noindex, nofollow" /> <meta name="robots" content="noindex, nofollow" />
...@@ -8,11 +8,15 @@ ...@@ -8,11 +8,15 @@
$this->includeAtTemplateBase('includes/header.php'); $this->includeAtTemplateBase('includes/header.php');
?> ?>
<h2><?php echo $this->t($this->data['dictTitle']); ?></h2> <h2><?php echo $this->t($this->data['dictTitle']); ?></h2>
<?php <?php
echo htmlspecialchars($this->t($this->data['dictDescr'], $this->data['parameters'])); echo htmlspecialchars($this->t($this->data['dictDescr'], $this->data['parameters']));
/* Include optional information for error. */
if (isset($this->data['includeTemplate'])) {
$this->includeAtTemplateBase($this->data['includeTemplate']);
}
?> ?>
<div class="trackidtext"> <div class="trackidtext">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment