forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
102 lines (86 loc) · 3.44 KB
/
index.php
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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle 404 Error page
*
* This is for 404 error pages served by the webserver and then passed
* to Moodle to be rendered using the site theme.
*
* ErrorDocument 404 /error/index.php
*
* @package core
* @copyright 2020 Brendan Heywood <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../config.php'); // phpcs:ignore
// Until we have a more robust routing api in place this is a very simple
// and clean way to handle arbitrary urls without a php extension.
if ($ME === '/.well-known/change-password') {
redirect(new moodle_url('/login/change_password.php'));
}
$context = context_system::instance();
$title = get_string('pagenotexisttitle', 'error');
$PAGE->set_url('/error/index.php');
$PAGE->set_context($context);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add($title);
// This allows the webserver to dictate wether the http status should remain
// what it would have been, or force it to be a 404. Under other conditions
// it could most often be a 403, 405 or a 50x error.
$code = optional_param('code', 0, PARAM_INT);
if ($code == 404) {
header("HTTP/1.0 404 Not Found");
}
$canmessage = has_capability('moodle/site:senderrormessage', $context);
$supportuser = core_user::get_support_user();
// We can only message support if both the user has the capability
// and the support user is a real user.
if ($canmessage) {
$canmessage = core_user::is_real_user($supportuser->id);
}
$mform = new \core\form\error_feedback($CFG->wwwroot . '/error/index.php');
if ($data = $mform->get_data()) {
if (!$canmessage) {
redirect($CFG->wwwroot);
}
// Send the message and redirect.
$message = new \core\message\message();
$message->courseid = SITEID;
$message->component = 'moodle';
$message->name = 'errors';
$message->userfrom = $USER;
$message->userto = core_user::get_support_user();
$message->subject = 'Error: '. $data->referer .' -> '. $data->requested;
$message->fullmessage = $data->text;
$message->fullmessageformat = FORMAT_PLAIN;
$message->fullmessagehtml = '';
$message->smallmessage = '';
$message->contexturl = $data->requested;
message_send($message);
redirect($CFG->wwwroot, get_string('sendmessagesent', 'error', $data->requested), 5);
exit;
}
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('pagenotexist', 'error', s($ME)), 'error');
echo $OUTPUT->supportemail(['class' => 'text-center d-block mb-3 font-weight-bold']);
if ($canmessage) {
echo \html_writer::tag('h4', get_string('sendmessage', 'error'));
$mform->display();
} else {
echo $OUTPUT->continue_button($CFG->wwwroot);
}
echo $OUTPUT->footer();