diff --git a/docs/source/simplesamlphp-idp.xml b/docs/source/simplesamlphp-idp.xml index 013a348b9738ce351c34a316e484ff61d888380b..ca9575d199d98e56fc95ab19eb4be783d0edece4 100644 --- a/docs/source/simplesamlphp-idp.xml +++ b/docs/source/simplesamlphp-idp.xml @@ -7,7 +7,7 @@ <articleinfo> <date>2007-10-15</date> - <pubdate>Thu Aug 28 16:25:10 2008</pubdate> + <pubdate>Wed Oct 8 15:18:15 2008</pubdate> <author> <firstname>Andreas Ă…kre</firstname> diff --git a/lib/SimpleSAML/XHTML/EMail.php b/lib/SimpleSAML/XHTML/EMail.php new file mode 100644 index 0000000000000000000000000000000000000000..f07911bf69cb33d4a959cfc55f0e66470ba09b29 --- /dev/null +++ b/lib/SimpleSAML/XHTML/EMail.php @@ -0,0 +1,102 @@ +<?php + +/** + * A minimalistic Emailer class. Creates and sends HTML emails. + * + * @author Andreas kre Solberg, UNINETT AS. <andreas.solberg@uninett.no> + * @package simpleSAMLphp + * @version $Id$ + */ +class SimpleSAML_XHTML_EMail { + + + private $to = NULL; + private $cc = NULL; + private $body = NULL; + private $from = NULL; + private $replyto = NULL; + private $subject = NULL; + private $headers = array(); + + + /** + * Constructor + */ + function __construct($to, $subject, $from = NULL, $cc = NULL, $replyto = NULL) { + $this->to = $to; + $this->cc = $cc; + $this->from = $from; + $this->replyto = $replyto; + $this->subject = $subject; + } + + function setBody($body) { + $this->body = $body; + } + + private function getHTML($body) { + return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <title>simpleSAMLphp Email report</title> + <style type="text/css"> +pre, div.box { + margin: .4em 2em .4em 1em; + padding: 4px; + +} +pre { + background: #eee; + border: 1px solid #aaa; +} + </style> +</head> +<body> +<div class="container" style="background: #fafafa; border: 1px solid #eee; margin: 2em; padding: .6em;"> +' . $body . ' +</div> +</body> +</html>'; + } + + function send() { + if ($this->to == NULL) throw new Exception('EMail field [to] is required and not set.'); + if ($this->subject == NULL) throw new Exception('EMail field [subject] is required and not set.'); + if ($this->body == NULL) throw new Exception('EMail field [body] is required and not set.'); + + $random_hash = substr(0, 16, md5(date('r', time()))); + + if (isset($this->from)) + $this->headers[]= 'From: ' . $this->from; + if (isset($this->replyto)) + $this->headers[]= 'Reply-To: ' . $this->replyto; + + $this->headers[] = 'Content-Type: multipart/alternative; boundary="simplesamlphp-' . $random_hash . '"'; + + $message = ' +--simplesamlphp-' . $random_hash . ' +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +' . strip_tags(html_entity_decode($this->body)) . ' + +--simplesamlphp-' . $random_hash . ' +Content-Type: text/html; charset="utf-8" +Content-Transfer-Encoding: 8bit + +' . $this->getHTML($this->body) . ' + +--simplesamlphp-' . $random_hash . '-- +'; + $headers = join("\r\n", $this->headers); + + $mail_sent = @mail($this->to, $this->subject, $message, $headers); + + if (!$mail_sent) throw new Exception('Error when sending e-mail'); + } + +} + +?> \ No newline at end of file diff --git a/www/errorreport.php b/www/errorreport.php index 0874925fe87fceaf51b2e406679c1ce171be8634..eb3a1b47247d7cd35bc9826e346bd2009fe50aec 100644 --- a/www/errorreport.php +++ b/www/errorreport.php @@ -17,6 +17,8 @@ if($_SERVER['REQUEST_METHOD'] !== 'POST') { /* Format of the email. * POST fields will be added to the email in the order they appear here, and with the description * from the value in the array. + * + * DEPRECATED. Included as reference of incomming parameters. */ $mailFormat = array( 'email' => 'Email address of submitter', @@ -41,87 +43,67 @@ $ignoredFields = array( $reportId = SimpleSAML_Utilities::stringToHex(SimpleSAML_Utilities::generateRandomBytes(4)); SimpleSAML_Logger::error('Error report with id ' . $reportId . ' generated.'); -/* Build the email message. */ - -$message = ''; -/** - * Format and add a section to the email message. - * - * @param $title The title of the section. - * @param $content The content of the section. - */ -function addMessageSection($title, $content) { - global $message; - - $message .= $title . "\n"; - $message .= "===============================================================\n"; - - foreach(split("\n", $content) as $line) { - $message .= ' ' . $line . "\n"; +function getPValue($key) { + if (array_key_exists($key, $_POST)) { + return strip_tags($_POST[$key]); } - - $message .= "\n"; + return 'not set'; } -/* Add the default fields to the message. */ -foreach($mailFormat as $key => $desc) { - if(!array_key_exists($key, $_POST)) { - /* Not included in the POST message, skip. */ - continue; - } +/* Build the email message. */ - $data = $_POST[$key]; +$message = '<h1>SimpleSAMLphp Error Report</h1> - addMessageSection($desc, $data); -} +<p>Message from user:</p> +<div class="box" style="background: yellow; color: #888; border: 1px solid #999900; padding: .4em; margin: .5em">' . getPValue('text') . '</div> -/* Add any unknown fields to the message. */ -foreach($_POST as $key => $data) { +<p>Exception: <strong>' . getPValue('exceptionmsg') . '</strong></p> +<pre>' . getPValue('exceptiontrace') . '</pre> - /* Skip known fields. */ - if(array_key_exists($key, $mailFormat)) { - continue; - } +<p>URL:</p> +<pre><a href="' . getPValue('url') . '">' . getPValue('url') . '</a></pre> - /* Skip ignored fields. */ - if(in_array($key, $ignoredFields, TRUE)) { - continue; - } +<p>Directory:</p> +<pre>' . dirname(dirname(__FILE__)) . '</pre> - $title = 'Unknown field: ' . $key; - addMessageSection($title, $data); -} +<p>Track ID:</p> +<pre>' . getPValue('trackid') . '</pre> +<p>Version: <tt>' . getPValue('version') . '</tt></p> -/* Add footer to message. */ -$message .= 'Error report id: ' . $reportId . "\n"; -$message .= "You may search the logs for this id to find the location\n"; -$message .= "where this report was sent.\n"; +<p>Report ID: <tt>' . $reportId . '</tt></p> + +<hr /> +<div class="footer">This message was sent using simpleSAMLphp. Visit <a href="http://rnd.feide.no/simplesamlphp">simpleSAMLphp homepage</a>.</div> + +'; -/* We want to use UTF-8 encoding of the email message. */ -$headers = 'MIME-Version: 1.0' . "\r\n"; -$headers .= 'Content-Type: text/plain; charset="UTF-8"' . "\r\n"; /* Add the email address of the submitter as the Reply-To address. */ +$replyto = NULL; +$from = 'no-reply@simplesamlphp.org'; if(array_key_exists('email', $_POST)) { $email = $_POST['email']; $email = trim($email); /* Check that it looks like a valid email address. */ if(!preg_match('/\s/', $email) && strpos($email, '@') !== FALSE) { - $headers .= 'Reply-To: ' . $email . "\r\n"; + $replyto = $email; + $from = $email; } } /* Send the email. */ -$email = $config->getValue('technicalcontact_email', 'na@example.org'); +$toaddress = $config->getValue('technicalcontact_email', 'na@example.org'); if($email !== 'na@example.org') { - /* This should always be TRUE, as the error report button should not appear unless - * the email is set. - */ - mail($email, 'simpleSAMLphp error report', $message, $headers); + + $email = new SimpleSAML_XHTML_EMail($email, 'simpleSAMLphp error report', $from); + $email->setBody($message); + $email->send(); } + + /* Redirect the user back to this page to clear the POST request. */ SimpleSAML_Utilities::redirect(SimpleSAML_Utilities::selfURLNoQuery());