1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Tool proxy.
|
|
|
19 |
*
|
|
|
20 |
* @package enrol_lti
|
|
|
21 |
* @copyright 2016 John Okely <john@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once(__DIR__ . '/../../config.php');
|
|
|
26 |
|
|
|
27 |
$toolid = null;
|
|
|
28 |
$token = null;
|
|
|
29 |
$filearguments = get_file_argument();
|
|
|
30 |
$arguments = explode('/', trim($filearguments, '/'));
|
|
|
31 |
if (count($arguments) == 2) {
|
|
|
32 |
list($toolid, $token) = $arguments;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
$toolid = optional_param('id', $toolid, PARAM_INT);
|
|
|
36 |
$token = optional_param('token', $token, PARAM_ALPHANUM);
|
|
|
37 |
|
|
|
38 |
$PAGE->set_context(context_system::instance());
|
|
|
39 |
$url = new moodle_url('/enrol/lti/tp.php');
|
|
|
40 |
$PAGE->set_url($url);
|
|
|
41 |
$PAGE->set_pagelayout('popup');
|
|
|
42 |
$PAGE->set_title(get_string('registration', 'enrol_lti'));
|
|
|
43 |
|
|
|
44 |
// Only show the proxy if the token parameter is correct.
|
|
|
45 |
// If we do not compare with a shared secret, someone could very easily
|
|
|
46 |
// guess an id for the enrolment.
|
|
|
47 |
if (!\enrol_lti\helper::verify_proxy_token($toolid, $token)) {
|
|
|
48 |
throw new \moodle_exception('incorrecttoken', 'enrol_lti');
|
|
|
49 |
}
|
|
|
50 |
$tool = \enrol_lti\helper::get_lti_tool($toolid);
|
|
|
51 |
|
|
|
52 |
if (!is_enabled_auth('lti')) {
|
|
|
53 |
throw new \moodle_exception('pluginnotenabled', 'auth', '', get_string('pluginname', 'auth_lti'));
|
|
|
54 |
exit();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
// Check if the enrolment plugin is disabled.
|
|
|
58 |
if (!enrol_is_enabled('lti')) {
|
|
|
59 |
throw new \moodle_exception('enrolisdisabled', 'enrol_lti');
|
|
|
60 |
exit();
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Check if the enrolment instance is disabled.
|
|
|
64 |
if ($tool->status != ENROL_INSTANCE_ENABLED) {
|
|
|
65 |
throw new \moodle_exception('enrolisdisabled', 'enrol_lti');
|
|
|
66 |
exit();
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
$messagetype = required_param('lti_message_type', PARAM_TEXT);
|
|
|
70 |
|
|
|
71 |
// Only accept proxy registration requests from this endpoint.
|
|
|
72 |
if ($messagetype != "ToolProxyRegistrationRequest") {
|
|
|
73 |
throw new \moodle_exception('invalidrequest', 'enrol_lti');
|
|
|
74 |
exit();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$toolprovider = new \enrol_lti\tool_provider($toolid);
|
|
|
78 |
$toolprovider->handleRequest();
|
|
|
79 |
echo $OUTPUT->header();
|
|
|
80 |
echo $OUTPUT->footer();
|