ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
errorreport.php
Go to the documentation of this file.
1 <?php
2 
3 require_once('_include.php');
4 
6 
7 // this page will redirect to itself after processing a POST request and sending the email
8 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
9  // the message has been sent. Show error report page
10 
11  $t = new SimpleSAML_XHTML_Template($config, 'errorreport.php', 'errors');
12  $t->show();
13  exit;
14 }
15 
16 $reportId = (string) $_REQUEST['reportId'];
17 $email = (string) $_REQUEST['email'];
18 $text = htmlspecialchars((string) $_REQUEST['text']);
19 
20 // ilias-patch: begin
21 if (!preg_match('/^[0-9a-f]{8}$/', $reportId)) {
22  throw new SimpleSAML_Error_Exception('Invalid reportID');
23 }
24 // ilias-patch: end
25 $data = null;
26 try {
28  $data = $session->getData('core:errorreport', $reportId);
29 } catch (Exception $e) {
30  SimpleSAML\Logger::error('Error loading error report data: '.var_export($e->getMessage(), true));
31 }
32 
33 if ($data === null) {
34  $data = array(
35  'exceptionMsg' => 'not set',
36  'exceptionTrace' => 'not set',
37  'reportId' => $reportId,
38  'trackId' => 'not set',
39  'url' => 'not set',
40  'version' => $config->getVersion(),
41  'referer' => 'not set',
42  );
43 
44  if (isset($session)) {
45  $data['trackId'] = $session->getTrackID();
46  }
47 }
48 
49 foreach ($data as $k => $v) {
50  $data[$k] = htmlspecialchars($v);
51 }
52 
53 // build the email message
54 $message = <<<MESSAGE
55 <h1>SimpleSAMLphp Error Report</h1>
56 
57 <p>Message from user:</p>
58 <div class="box" style="background: yellow; color: #888; border: 1px solid #999900; padding: .4em; margin: .5em">
59  %s
60 </div>
61 
62 <p>Exception: <strong>%s</strong></p>
63 <pre>%s</pre>
64 
65 <p>URL:</p>
66 <pre><a href="%s">%s</a></pre>
67 
68 <p>Host:</p>
69 <pre>%s</pre>
70 
71 <p>Directory:</p>
72 <pre>%s</pre>
73 
74 <p>Track ID:</p>
75 <pre>%s</pre>
76 
77 <p>Version: <tt>%s</tt></p>
78 
79 <p>Report ID: <tt>%s</tt></p>
80 
81 <p>Referer: <tt>%s</tt></p>
82 
83 <hr />
84 <div class="footer">
85  This message was sent using SimpleSAMLphp. Visit the <a href="http://simplesamlphp.org/">SimpleSAMLphp homepage</a>.
86 </div>
87 MESSAGE;
88 $message = sprintf(
89  $message,
90  $text,
91  $data['exceptionMsg'],
92  $data['exceptionTrace'],
93  $data['url'],
94  $data['url'],
95  htmlspecialchars(php_uname('n')),
96  dirname(dirname(__FILE__)),
97  $data['trackId'],
98  $data['version'],
99  $data['reportId'],
100  $data['referer']
101 );
102 
103 // add the email address of the submitter as the Reply-To address
104 $email = trim($email);
105 
106 // check that it looks like a valid email address
107 if (!preg_match('/\s/', $email) && strpos($email, '@') !== false) {
108  $replyto = $email;
109 } else {
110  $replyto = null;
111 }
112 
113 $from = $config->getString('sendmail_from', null);
114 if ($from === null || $from === '') {
115  $from = ini_get('sendmail_from');
116  if ($from === '' || $from === false) {
117  $from = 'no-reply@example.org';
118  }
119 }
120 
121 // If no sender email was configured at least set some relevant from address
122 if ($from === 'no-reply@example.org' && $replyto !== null) {
123  $from = $replyto;
124 }
125 
126 // send the email
127 $toAddress = $config->getString('technicalcontact_email', 'na@example.org');
128 if ($config->getBoolean('errorreporting', true) && $toAddress !== 'na@example.org') {
129  $email = new SimpleSAML_XHTML_EMail($toAddress, 'SimpleSAMLphp error report', $from);
130  $email->setBody($message);
131  $email->send();
132  SimpleSAML\Logger::error('Report with id '.$reportId.' sent to <'.$toAddress.'>.');
133 }
134 
135 // redirect the user back to this page to clear the POST request
136 \SimpleSAML\Utils\HTTP::redirectTrustedURL(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery());
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$from
$session
if(!preg_match('/^ $data[0-9a-f]{8}$/', $reportId))
Definition: errorreport.php:25
"color:#CC0000 style
Definition: example_001.php:92
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:959
user()
Definition: user.php:4
Attribute-related utility methods.
if($from===null|| $from==='') if($from==='no-reply @example.org' && $replyto !==null) $toAddress
$config
Definition: errorreport.php:5
if($_SERVER['REQUEST_METHOD'] !=='POST') $reportId
Definition: errorreport.php:16
$text
Definition: errorreport.php:18
static error($string)
Definition: Logger.php:166
catch(Exception $e) if($data===null) foreach($data as $k=> $v) $message
Definition: errorreport.php:54
exit
Definition: backend.php:16
$email
Definition: errorreport.php:17
Temporary autoloader to ensure compatibility with old, non-PSR-2 compliant classes.
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:241
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.