File: errorreport.php

package info (click to toggle)
simplesamlphp 1.16.3-1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,036 kB
  • sloc: php: 73,175; ansic: 875; sh: 83; perl: 82; xml: 52; makefile: 46
file content (131 lines) | stat: -rw-r--r-- 3,489 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php

require_once('_include.php');

$config = SimpleSAML_Configuration::getInstance();

// this page will redirect to itself after processing a POST request and sending the email
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    // the message has been sent. Show error report page

    $t = new SimpleSAML_XHTML_Template($config, 'errorreport.php', 'errors');
    $t->show();
    exit;
}

$reportId = (string) $_REQUEST['reportId'];
$email = (string) $_REQUEST['email'];
$text = htmlspecialchars((string) $_REQUEST['text']);

$data = null;
try {
    $session = SimpleSAML_Session::getSessionFromRequest();
    $data = $session->getData('core:errorreport', $reportId);
} catch (Exception $e) {
    SimpleSAML\Logger::error('Error loading error report data: '.var_export($e->getMessage(), true));
}

if ($data === null) {
    $data = array(
        'exceptionMsg'   => 'not set',
        'exceptionTrace' => 'not set',
        'reportId'       => $reportId,
        'trackId'        => 'not set',
        'url'            => 'not set',
        'version'        => $config->getVersion(),
        'referer'        => 'not set',
    );

    if (isset($session)) {
        $data['trackId'] = $session->getTrackID();
    }
}

foreach ($data as $k => $v) {
    $data[$k] = htmlspecialchars($v);
}

// build the email message
$message = <<<MESSAGE
<h1>SimpleSAMLphp Error Report</h1>

<p>Message from user:</p>
<div class="box" style="background: yellow; color: #888; border: 1px solid #999900; padding: .4em; margin: .5em">
    %s
</div>

<p>Exception: <strong>%s</strong></p>
<pre>%s</pre>

<p>URL:</p>
<pre><a href="%s">%s</a></pre>

<p>Host:</p>
<pre>%s</pre>

<p>Directory:</p>
<pre>%s</pre>

<p>Track ID:</p>
<pre>%s</pre>

<p>Version: <tt>%s</tt></p>

<p>Report ID: <tt>%s</tt></p>

<p>Referer: <tt>%s</tt></p>

<hr />
<div class="footer">
    This message was sent using SimpleSAMLphp. Visit the <a href="http://simplesamlphp.org/">SimpleSAMLphp homepage</a>.
</div>
MESSAGE;
$message = sprintf(
    $message,
    $text,
    $data['exceptionMsg'],
    $data['exceptionTrace'],
    $data['url'],
    $data['url'],
    htmlspecialchars(php_uname('n')),
    dirname(dirname(__FILE__)),
    $data['trackId'],
    $data['version'],
    $data['reportId'],
    $data['referer']
);

// add the email address of the submitter as the Reply-To address
$email = trim($email);

// check that it looks like a valid email address
if (!preg_match('/\s/', $email) && strpos($email, '@') !== false) {
    $replyto = $email;
} else {
    $replyto = null;
}

$from = $config->getString('sendmail_from', null);
if ($from === null || $from === '') {
    $from = ini_get('sendmail_from');
    if ($from === '' || $from === false) {
        $from = 'no-reply@example.org';
    }
}

// If no sender email was configured at least set some relevant from address
if ($from === 'no-reply@example.org' && $replyto !== null) {
    $from = $replyto;
}

// send the email
$toAddress = $config->getString('technicalcontact_email', 'na@example.org');
if ($config->getBoolean('errorreporting', true) && $toAddress !== 'na@example.org') {
    $email = new SimpleSAML_XHTML_EMail($toAddress, 'SimpleSAMLphp error report', $from);
    $email->setBody($message);
    $email->send();
    SimpleSAML\Logger::error('Report with id '.$reportId.' sent to <'.$toAddress.'>.');
}

// redirect the user back to this page to clear the POST request
\SimpleSAML\Utils\HTTP::redirectTrustedURL(\SimpleSAML\Utils\HTTP::getSelfURLNoQuery());