-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxapiproxy.php
More file actions
executable file
·96 lines (85 loc) · 3.03 KB
/
xapiproxy.php
File metadata and controls
executable file
·96 lines (85 loc) · 3.03 KB
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
<?php
// hardcoded namespace
// attention: maybe a problem with composer v2 / psr4 autoload requires exact matching of namespace and parent folder name?
namespace XapiProxyPlugin;
// hardcoded context for better performance
// $plugin = file_exists(__DIR__."/plugin.php"); // for testing
$plugin = true;
/**
* handle preflight
*/
if (strtoupper($_SERVER["REQUEST_METHOD"]) == "OPTIONS") {
header('HTTP/1.1 204 No Content');
header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: X-Experience-API-Version,Accept,Authorization,Etag,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With');
header('Access-Control-Max-Age: 3600');
exit;
}
/**
* handle basic auth
*/
if( !empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW']) )
{
$client = $_SERVER['PHP_AUTH_USER'];
$token = $_SERVER['PHP_AUTH_PW'];
}
elseif( !empty($_SERVER['HTTP_AUTHORIZATION']) )
{
$basicAuth = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
$client = $basicAuth[0];
$token = $basicAuth[1];
}
else
{
header('HTTP/1.1 401 Authorization Required');
header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: X-Experience-API-Version,Accept,Authorization,Etag,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With');
exit;
}
/**
* handle path context
*/
if ($plugin) {
chdir("../../../../../../../");
}
else {
chdir("../../");
}
/**
* handle ILIAS Init
*/
require_once __DIR__.'/classes/XapiProxy/DataService.php';
DataService::initIlias($client);
/**
*
* required for Plugin in ILIAS 5.x
*/
if ($plugin && ((int)ILIAS_VERSION_NUMERIC < 6)) {
require_once __DIR__.'/classes/XapiProxy/vendor/autoload.php';
}
/**
* handle XapiProxy Init
*/
require_once __DIR__.'/classes/XapiProxy/XapiProxy.php';
$xapiproxy = new XapiProxy($client, $token ,$plugin);
/**
* handle Lrs Init
*/
try {
$xapiproxy->initLrs();
}
catch(\Exception $e) {
$xapiproxy->log()->error($e->getMessage());
}
require_once __DIR__.'/classes/XapiProxy/XapiProxyRequest.php';
require_once __DIR__.'/classes/XapiProxy/XapiProxyResponse.php';
$req = new XapiProxyRequest($xapiproxy);
$resp = new XapiProxyResponse($xapiproxy);
$xapiproxy->setXapiProxyRequest($req);
$xapiproxy->setXapiProxyResponse($resp);
$req->handle();
?>