Skip to content
Snippets Groups Projects
Commit 1f8b1da5 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Implementeed better error handling. Separate static function for fatal error...

Implementeed better error handling. Separate static function for fatal error in utitilies that present a error the user. This page to the user shows a error text that can be localized to several languages, the error page also shows debug text, and a way to submit errors to the administrators.



git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@232 44740490-163a-0410-bde0-09ae8108e29a
parent b5ea42a5
No related branches found
No related tags found
No related merge requests found
Showing
with 329 additions and 54 deletions
<?php
$lang = array(
'en' => array(
'title' => 'Error making single sign-on to service',
'descr' => 'You can authenticated and are ready to be sent back to the service that requested authentication, but we could not find your cached authentication request. The request is only cached for a limited amount of time. If you leaved your browser open for hours before entering your username and password, this could be one possible explaination. If this could be the case in your situation, try to go back to the service you want to access, and start a new login process. If this issue continues, please report the problem.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error creating AuthNRequest',
'descr' => 'An error occured when trying to create the authentication request.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Bad request to discovery service',
'descr' => 'The parameters sent to the discovery service were not following the specification.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Could not create authentication response',
'descr' => 'When this identity provider tried to create an authentication response, an error occured.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'LDAP Error',
'descr' => 'LDAP is the user database, and when you try to login, we need to contact an LDAP database. When we tried it this time an error occured.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error processing Logout Request',
'descr' => 'An error occured when trying to process the Logout Request.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error processing Logout Response',
'descr' => 'An error occured when trying to process the Logout Response.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error loading metadata',
'descr' => 'There is some misconfiguration of your simpleSAMLphp installation. If you are the administrator of this service, you should make sure your metadata configuration is correctly setup.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'No RelayState',
'descr' => 'The initiator of this request did not provide an RelayState parameter, that tells where to go next.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'No session found',
'descr' => 'Unfortuneately we could not get your session. This could be because your browser do not support cookies, or cookies is disabled.'
),
'no' => array(
'title' => 'Kunne ikke etablere sesjon',
'descr' => 'Desverre kunne vi ikke etablere en sesjon for deg. Dette kan skyldes at din nettleser ikke støtter cookies, eller at cookies er slått av.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error processing response from IdP',
'descr' => 'We did not accept the response sent from the Identity Provider.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Error processing request from Service Provider',
'descr' => 'This IdP received an authentication request from a service provider, but an error occured when trying to process the request.'
)
);
\ No newline at end of file
<?php
$lang = array(
'en' => array(
'title' => 'Wrong parameters provided',
'descr' => 'You must either provide a SAML Request message or a RequestID on this interface.'
)
);
\ No newline at end of file
/**
* Copy and paste this file into a page in your drupal installation, or similar CMS system.
* Make sure the Input mode in your new page is PHP Mode.
*
* Then when you click save, notice the URL of your new page. This URL should be entered in the
* config.php of your simpleSAMLphp installation.
*
*/
<p>Thanks for sending information to us from simpleSAMLphp.</p>
<?php
#$to = 'andreas.solberg@uninett.no, moria-support@uninett.no';
$to = 'andreas.solberg@uninett.no';
if (isset($_POST['action'])) {
$to = 'andreas.solberg@uninett.no';
$from = (isset($_POST['email']) ? $_POST['email'] : 'Anonymous <simplesamlphp@example.org>');
$headers = 'From: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if ($_POST['action'] == 'metadata') {
echo '<p>We have received your metadata.';
$subject = 'SAML 2.0 Metadata from '. $_POST['email'];
$message = 'Someone just used simpleSAMLphp to send metadata to Feide. Here is the metadata: ' . "\r\n\r\n------- BEGIN SAML 2.0 METADATA ----------\r\n" .
html_entity_decode(base64_decode(urldecode($_POST['metadata']))) . "\r\n------- END SAML 2.0 METADATA ----------\r\n\r\nDefault IdP: " . $_POST['defaultidp'] . "\r\nSent by simpleSAMLphp :)";
} elseif($_POST['action'] == 'error') {
echo '<p>We have received your error report.';
$subject = 'Error report from '. $_POST['email'];
$message = 'Someone just used simpleSAMLphp to send an error message to Feide. Here is the exception:
------------------
Exception message: ' . html_entity_decode(base64_decode(urldecode($_POST['exceptionmsg']))) . '
------------------
Exception stacktrace:
' . html_entity_decode(base64_decode(urldecode($_POST['exceptiontrace']))) . '
------------------
Description from user:
' . $_POST['text'] . '
TrackID [' . $_POST['trackid'] . ']
simpleSAMLphp version: ' . $_POST['version'] . '
Technical contact at server: ' . $_POST['techemail'] . '
Sent using simpleSAMLphp';
}
mail($to, $subject, $message, $headers);
}
?>
......@@ -30,11 +30,14 @@ class SimpleSAML_Logger {
* Log a message to syslog.
*/
public function log($priority, $trackid = null, $module, $submodule, $eventtype, $content, $message) {
if ($priority < $this->loglevel) return;
error_log('This entry is ' . $priority . ' and configuration says minimum ' . $this->loglevel);
error_log('LOG_ERR is ' . LOG_ERR . ' and LOGINFO is ' . LOG_INFO);
if ($priority > $this->loglevel) return;
error_log('Log2');
if ($trackid == null) {
$session = SimpleSAML_Session::getInstance(true);
$trackid = $session->getTrackID();
$trackid = 'na';
//$session = SimpleSAML_Session::getInstance(true);
//$trackid = $session->getTrackID();
}
$contentstring = '';
......
......@@ -2,6 +2,7 @@
require_once('SimpleSAML/Configuration.php');
require_once('SimpleSAML/XHTML/Template.php');
require_once('SimpleSAML/Logger.php');
/**
* Misc static functions that is used several places.in example parsing and id generation.
......@@ -268,22 +269,46 @@ class SimpleSAML_Utilities {
}
/* This function logs a error message to the error log and shows the
/**
* This function logs a error message to the error log and shows the
* message to the user. Script execution terminates afterwards.
*
* Parameters:
* $title Short title for the error message.
* $message The error message.
* @param $title Short title for the error message.
* @param $message The error message.
*/
public static function fatalError($title, $message) {
error_log($title . ': ' . $message);
public static function fatalError($trackid = 'na', $errorcode = null, Exception $e = null, $level = LOG_ERR) {
$config = SimpleSAML_Configuration::getInstance();
$t = new SimpleSAML_XHTML_Template($config, 'error.php');
$t->data['header'] = $title;
$t->data['message'] = $message;
// Get the exception message if there is any exception provided.
$emsg = (empty($e) ? 'No exception available' : $e->getMessage());
$etrace = (empty($e) ? 'No exception available' : $e->getTraceAsString());
// Log a error message
$logger = new SimpleSAML_Logger();
$logger->log($level, $trackid, $_SERVER['PHP_SELF'], '-', 'UserError', (!empty($errorcode) ? $errorcode : 'na'),
urlencode($emsg) );
$languagefile = null;
if (isset($errorcode)) $languagefile = 'error_' . $errorcode . '.php';
// Initialize a template
$t = new SimpleSAML_XHTML_Template($config, 'error.php', $languagefile);
$t->data['showerrors'] = $config->getValue('showerrors', true);
$t->data['errorreportaddress'] = $config->getValue('errorreportaddress', null);
$t->data['exceptionmsg'] = $emsg;
$t->data['exceptiontrace'] = $etrace;
$t->data['trackid'] = $trackid;
$t->data['version'] = $config->getValue('version', 'na');
$t->data['email'] = $config->getValue('technicalcontact_email', 'na');
$t->show();
exit;
}
......
<?php
require_once('SimpleSAML/Configuration.php');
require_once('SimpleSAML/Logger.php');
/**
* A minimalistic XHTML PHP based template system implemented for simpleSAMLphp.
*
......@@ -15,36 +16,42 @@ class SimpleSAML_XHTML_Template {
private $template = 'default.php';
private $language = null;
private $langtext = null;
public $data = null;
function __construct(SimpleSAML_Configuration $configuration, $template) {
function __construct(SimpleSAML_Configuration $configuration, $template, $languagefile = null) {
$this->configuration = $configuration;
$this->template = $template;
$this->data['baseurlpath'] = $this->configuration->getValue('baseurlpath');
if (!empty($languagefile)) $this->includeLanguageFile($languagefile);
}
public function setLanguage($language) {
$this->language = $language;
setcookie('language', $language);
// setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] )
// time()+60*60*24*900 expires 900 days from now.
setcookie('language', $language, time()+60*60*24*900);
}
public function getLanguage() {
// Language is set in object
if (isset($this->language)) {
return $this->language;
// Language is provided in query string
} else if (isset($_GET['language'])) {
$this->setLanguage($_GET['language']);
// Language is provided in a stored COOKIE
} else if (isset($_COOKIE['language'])) {
$this->language = $_COOKIE['language'];
// Language is not set, and we get the default language from the configuration.
} else {
return $this->configuration->getValue('language.default');
}
......@@ -71,33 +78,67 @@ class SimpleSAML_XHTML_Template {
private function includeAtLanguageBase($file) {
$data = $this->data;
$filebase = $this->configuration->getBaseDir() . $this->configuration->getValue('templatedir') . $this->getLanguage() . '/' ;
if (!file_exists($filebase . $file)) {
$filebase = $this->configuration->getBaseDir() . $this->configuration->getValue('templatedir') .
$this->configuration->getValue('language.default') . '/';
if (!file_exists($filebase . $file) ) {
$logger = new SimpleSAML_Logger();
$logger->log(LOG_ERR, null, $_SERVER['PHP_SELF'], '-', 'Template', 'CannotFindFile',
'Could not find template file [' . $this->template . '] at [' . $filename . ']');
return;
}
}
include($filebase . $file);
}
private function includeLanguageFile($file) {
$data = $this->data;
$filebase = $this->configuration->getBaseDir() . $this->configuration->getValue('dictionarydir');
if (!file_exists($filebase . $file)) {
$logger = new SimpleSAML_Logger();
$logger->log(LOG_ERR, null, $_SERVER['PHP_SELF'], '-', 'Template', 'CannotFindFile',
'Could not find template file [' . $this->template . '] at [' . $filebase . $file . ']');
return;
}
include($filebase . $file);
if (isset($lang)) {
if (array_key_exists($this->getLanguage(), $lang) ) {
foreach ($lang[$this->getLanguage()] AS $key => $text) {
$this->data[$key] = $text;
}
} elseif (array_key_exists($this->configuration->getValue('language.default', 'en'), $lang) ) {
foreach ($lang[$this->configuration->getValue('language.default')] AS $key => $text) {
$this->data[$key] = $text;
}
}
}
}
public function show() {
$data = $this->data;
$filename = $this->configuration->getBaseDir() . $this->configuration->getValue('templatedir') . $this->getLanguage() . '/' .
$this->template;
if (!file_exists($filename)) {
// echo 'Could not find template file [' . $this->template . '] at [' . $filename . ']';
// exit(0);
$filename = $this->configuration->getBaseDir() . $this->configuration->getValue('templatedir') .
$this->configuration->getValue('language.default') . '/' . $this->template;
if (!file_exists($filename)) {
echo 'Could not find template file [' . $this->template . '] at [' . $filename . ']';
$logger = new SimpleSAML_Logger();
$logger->log(LOG_ERR, null, $_SERVER['PHP_SELF'], '-', 'Template', 'CannotFindFile',
'Could not find template file [' . $this->template . '] at [' . $filename . ']');
echo 'Fatal error: Could not find template file [' . $this->template . '] at [' . $filename . ']';
exit(0);
throw new Exception('Could not find template file [' . $this->template . '] at [' . $filename . ']');
}
}
require_once($filename);
......
......@@ -13,6 +13,7 @@ require_once('xmlseclibs.php');
* An SAML 2.0 Authentication Response
*
* @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @author Olav Morken, UNINETT AS
* @package simpleSAMLphp
* @version $Id$
*/
......
<?php $this->includeAtTemplateBase('includes/header.php'); ?>
<?php
$this->data['header'] = 'simpleSAMLphp error';
$this->includeAtTemplateBase('includes/header.php');
?>
<div id="content">
<h2><?php echo (isset($this->data['title']) ? $this->data['title'] : 'simpleSAMLphp error'); ?></h2>
<p><?php echo $this->data['descr']; ?></p>
<div class="trackidtext">
If you report this error the track ID makes it possible to track your session in the logs available to the system adinistrator:
<span class="trackid"><?php echo $this->data['trackid']; ?><span>
<h2><?php if (isset($data['header'])) { echo $data['header']; } else { echo "Some error occured"; } ?></h2>
</div>
<p>
<?php echo $data['message']; ?>
</p>
<?php
/* Print out exception only if the exception is available. */
if (array_key_exists('e', $data)) {
if ($this->data['showerrors']) {
?>
<h2>Debug information</h2>
<p>The debug information below may be interesting for the administrator / help desk:</p>
<div style="border: 1px solid #eee; padding: 1em; font-size: x-small">
<p style="margin: 1px"><?php echo htmlentities($data['e']->getMessage()); ?></p>
<p style="margin: 1px"><?php echo htmlentities($this->data['exceptionmsg']); ?></p>
<div style=" padding: 1em; font-family: monospace; ">
<?php echo htmlentities($data['e']->getTraceAsString()); ?>
<?php echo htmlentities($this->data['exceptiontrace']); ?>
</div>
</div>
<?php
}
?>
<?php
/* Print out exception only if the exception is available. */
if (!empty($this->data['errorreportaddress'])) {
?>
<h2>Report errors</h2>
<form action="<?php echo $this->data['errorreportaddress']; ?>" method="post">
<p>Optionally enter your email address, for the administrators to be able contact you for further questions about your issue: </p>
<p>E-mail address: <input type="text" size="25" name="email" value="" />
<p>
<textarea style="width: 300px; height: 100px" name="text">Explain what you did to get this error...</textarea>
</p></p>
<input type="hidden" name="action" value="error" />
<input type="hidden" name="techemail" value="<?php echo $this->data['email']; ?>" />
<input type="hidden" name="version" value="<?php echo $this->data['version']; ?>" />
<input type="hidden" name="trackid" value="<?php echo $this->data['trackid']; ?>" />
<input type="hidden" name="exceptionmsg" value="<?php echo urlencode(base64_encode($this->data['exceptionmsg'])); ?>" />
<input type="hidden" name="exceptiontrace" value="<?php echo urlencode(base64_encode($this->data['exceptiontrace'])); ?>" />
<input type="submit" name="send" value="Send error report" />
</p>
</form>
<?php
}
?>
<h2 style="clear: both">How to get help</h2>
......
......@@ -15,14 +15,12 @@
<pre style="overflow: scroll; border: 1px solid #eee; padding: 2px"><?php echo $data['metadata']; ?></pre>
<?php if($data['feide']) { ?>
<?php if(array_key_exists('sendmetadatato', $this->data) { ?>
<div style="border: 1px solid #444; margin: 2em; padding: 1em; background: #eee">
<img src="http://clippings.erlang.no/ZZ076BD170.jpg" style="float: right; " />
<h2>Send your metadata to Feide</h2>
<h2>Send your metadata to <?php $this->data['federationname']; ?></h2>
<p>simpleSAMLphp has detected that you have configured Feide as your default IdP.</p>
......@@ -30,15 +28,17 @@
contact Feide to add you as a new service, you will be asked to send your metadata. Here you can easily send
the metadata to Feide by clicking the button below.</p>
<form action="http://rnd.feide.no/post-metadata/index.php" method="post">
<form action="<?php $this->data['sendmetadatato']; ?>" method="post">
<p>Feide needs to know how to get in contact with you, so you need to type in <strong>your email address</strong>:
<input type="text" size="25" name="email" value="" />
</p>
<input type="hidden" name="metadata" value="<?php echo urlencode(base64_encode($data['metadata'])); ?>" />
<input type="hidden" name="techemail" value="<?php echo $_POST['techemail']; ?>" />
<input type="hidden" name="version" value="<?php echo $_POST['version']; ?>" />
<input type="hidden" name="defaultidp" value="<?php echo htmlspecialchars($data['defaultidp']); ?>" />
<input type="submit" name="send" value="Send my metadata to Feide" />
<input type="submit" name="send" value="Send my metadata to <?php $this->data['federationname']; ?>" />
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment