ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
xapiproxy.php
Go to the documentation of this file.
1<?php
2 // hardcoded namespace
3 // attention: maybe a problem with composer v2 / psr4 autoload requires exact matching of namespace and parent folder name?
4 namespace XapiProxy;
5
6 // hardcoded context for better performance
7 // $plugin = file_exists(__DIR__."/plugin.php"); // for testing
8 $plugin = false;
9
13 if (strtoupper($_SERVER["REQUEST_METHOD"]) == "OPTIONS") {
14 header('HTTP/1.1 204 No Content');
15 header('Access-Control-Allow-Origin: '.$_SERVER["HTTP_ORIGIN"]);
16 header('Access-Control-Allow-Credentials: true');
17 header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
18 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');
19 exit;
20 }
21
25// file_put_contents("log.txt",var_export($_SERVER,true),8);
26
27 if( !empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW']) )
28 {
29 $client = $_SERVER['PHP_AUTH_USER'];
30 $token = $_SERVER['PHP_AUTH_PW'];
31 }
32 elseif( !empty($_SERVER['HTTP_AUTHORIZATION']) )
33 {
34 $basicAuth = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
35 $client = $basicAuth[0];
36 $token = $basicAuth[1];
37 }
38 else
39 {
40 header('HTTP/1.1 401 Authorization Required');
42 }
43
48 if ($plugin) {
53 //require_once __DIR__.'/classes/XapiProxy/vendor/autoload.php';
54
55 chdir("../../../../../../../");
56 }
57 else {
58 chdir("../../");
59 }
60
64 require_once __DIR__.'/classes/XapiProxy/DataService.php';
66
70 require_once __DIR__.'/classes/XapiProxy/XapiProxy.php';
71 $dic = $GLOBALS['DIC'];
72
73 $dic['xapiproxy'] = function ($c) use ($client, $token, $plugin) {
74 return new XapiProxy($client, $token ,$plugin);
75 };
76
80 try {
81 $dic['xapiproxy']->initLrs();
82 }
83 catch(\Exception $e) { // ?
84 $dic['xapiproxy']->log()->error($dic['xapiproxy']->getLogMessage($e->getMessage()));
85 }
86
87 require_once __DIR__.'/classes/XapiProxy/XapiProxyRequest.php';
88 require_once __DIR__.'/classes/XapiProxy/XapiProxyResponse.php';
91
92 $dic['xapiproxy']->setXapiProxyRequest($req);
93 $dic['xapiproxy']->setXapiProxyResponse($resp);
94
95 $req->handle();
96?>
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static initIlias($client_id)
Definition: DataService.php:7
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$dic
Definition: result.php:13
$token
Definition: xapitoken.php:57