File: problem.php

package info (click to toggle)
php-horde 5.2.13%2Bdebian0-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,652 kB
  • sloc: php: 11,153; xml: 6,751; javascript: 5,560; sh: 92; makefile: 33; sql: 1
file content (165 lines) | stat: -rw-r--r-- 5,689 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
 * Problem reporting page.
 *
 * Copyright 1999-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author   Chuck Hagenbuch <chuck@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/lgpl LGPL-2
 * @package  Horde
 */

require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('horde', array('authentication' => 'none'));

$vars = $injector->getInstance('Horde_Variables');

$redirect_url = new Horde_Url($vars->get('return_url', Horde::url('login.php', true, array('app' => 'horde'))));

if (!$registry->showService('problem')) {
    $redirect_url->redirect();
}

$identity = $injector->getInstance('Horde_Core_Factory_Identity')->create();
$email = $identity->getValue('from_addr');
if (!$email) {
    $email = $vars->get('email', $registry->getAuth());
}
$message = $vars->message;
$name = $vars->get('name', $identity->getValue('fullname'));
$subject = $vars->subject;

switch ($vars->actionID) {
case 'send_problem_report':
    if ($subject && $message) {
        /* This is not a gettext string on purpose. */
        $remote = empty($_SERVER['REMOTE_HOST'])
            ? $_SERVER['REMOTE_ADDR']
            : $_SERVER['REMOTE_HOST'];
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $body = "This problem report was received from $remote. " .
            "The user clicked the problem report link from the following location:\n" .
            $vars->get('return_url', 'No requesting page') .
            "\nand is using the following browser:\n$user_agent\n\n" .
            str_replace("\r\n", "\n", $message);

        /* Default to a relatively reasonable email address. */
        if (!$email) {
            $email = 'horde-problem@' . $conf['problems']['maildomain'];
        }

        /* Check for attachments. */
        $attachment = null;
        if (!empty($conf['problems']['attachments'])) {
            try {
                $browser->wasFileUploaded('attachment', _("attachment"));
                $attachment = $_FILES['attachment'];
            } catch (Horde_Browser_Exception $e) {
                if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
                    $notification->push($e, 'horde.error');
                    break;
                }
            }
        }

        if (!empty($conf['problems']['tickets']) &&
            $registry->hasMethod('tickets/addTicket')) {
                $info = array_merge($conf['problems']['ticket_params'], array(
                    'summary' => $subject,
                    'comment' => $body,
                    'user_email' => $email
                ));

            try {
                $ticketId = $registry->call('tickets/addTicket', array($info));
            } catch (Horde_Exception $e) {
                $notification->push($e);
                break;
            }

            if ($attachment &&
                $registry->hasMethod('tickets/addAttachment')) {
                try {
                    $registry->call('tickets/addAttachment', array(
                        'ticket_id' => $ticketId,
                        'name' => $attachment['name'],
                        'data' => file_get_contents($attachment['tmp_name'])
                    ));
                } catch (Horde_Exception $e) {
                    $notification->push($e);
                }
            }

            $redirect_url->redirect();
        }

        /* Add user's name to the email address if provided. */
        if ($name) {
            $addr_ob = new Horde_Mail_Rfc822_Address($email);
            if (is_null($addr_ob->host)) {
                $addr_ob->host = $conf['problems']['maildomain'];
            }
            $addr_ob->personal = $name;
            $email = $addr_ob->writeAddress(true);
        }

        $mail = new Horde_Mime_Mail(array(
            'body' => $body,
            'Subject' => _("[Problem Report]") . ' ' . $subject,
            'To' => $conf['problems']['email'],
            'From' => $email
        ));
        $mail->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']);

        /* Add attachment. */
        if ($attachment) {
            $mail->addAttachment(
                $attachment['tmp_name'],
                $attachment['name'],
                $attachment['type']
            );
        }

        try {
            $mail->send($injector->getInstance('Horde_Mail'));

            /* Success. */
            Horde::log(
                sprintf("%s Message sent to %s from %s",
                    $_SERVER['REMOTE_ADDR'],
                    preg_replace('/^.*<([^>]+)>.*$/', '$1', $conf['problems']['email']),
                    preg_replace('/^.*<([^>]+)>.*$/', '$1', $email)
                ),
                'INFO'
            );

            /* Return to previous page and exit this script. */
            $redirect_url->redirect();
        } catch (Horde_Exception $e) {
            $notification->push($e);
        }
    }
    break;

case 'cancel_problem_report':
    $redirect_url->redirect();
    break;
}

$page_output->sidebar = false;
$page_output->addInlineJsVars(array(
    'HordeProblem.message_text' => _("You must describe the problem before you can send the problem report."),
    'HordeProblem.summary_text' => _("Please provide a summary of the problem.")
), true);
$page_output->addScriptFile('problem.js', 'horde');

$page_output->header(array(
    'title' => _("Problem Description")
));
$notification->notify(array('listeners' => 'status'));
require HORDE_TEMPLATES . '/problem/problem.inc';
$page_output->footer();