ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1 <?php
2 
24 
31 {
33  private Services $http;
34  private string $img_dir;
35 
36 
37  public static function run(Services $httpState, CookieFactory $cookieFactory): void
38  {
39  $obj = new self($httpState, $cookieFactory);
40  $obj->handleRequest();
41  }
42 
43 
47  public function __construct(Services $httpState, CookieFactory $cookieFactory)
48  {
49  $this->wac = new ilWebAccessChecker($httpState, $cookieFactory);
50  $this->http = $httpState;
51  $this->img_dir = realpath(__DIR__ . '/../templates/images');
52  }
53 
54 
55  protected function handleRequest(): void
56  {
57  // Set errorreporting
59  $queries = $this->http->request()->getQueryParams();
60 
61  // Set customizing
62  if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
63  $this->wac->setDisposition($queries[ilWebAccessChecker::DISPOSITION]);
64  }
65  if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
66  $this->wac->setSendStatusCode($queries[ilWebAccessChecker::STATUS_CODE]);
67  }
68  if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
69  $this->wac->setRevalidateFolderTokens($queries[ilWebAccessChecker::REVALIDATE]);
70  }
71 
72  // Check if File can be delivered
73  try {
74  if ($this->wac->check()) {
75  $this->deliver();
76  } else {
77  $this->deny();
78  }
79  } catch (ilWACException $e) {
80  match ($e->getCode()) {
85  default => $this->handleErrors($e),
86  };
87  }
88  }
89 
93  protected function deny(): void
94  {
95  if (!$this->wac->isChecked()) {
97  }
99  }
100 
101 
102  protected function deliverDummyImage(): void
103  {
104  $ilFileDelivery = new Delivery($this->img_dir . '/access_denied.png', $this->http);
105  $ilFileDelivery->setDisposition($this->wac->getDisposition());
106  $ilFileDelivery->deliver();
107  }
108 
109 
110  protected function deliverDummyVideo(): void
111  {
112  $ilFileDelivery = new Delivery($this->img_dir . '/access_denied.mp4', $this->http);
113  $ilFileDelivery->setDisposition($this->wac->getDisposition());
114  $ilFileDelivery->stream();
115  }
116 
117  protected function handleNotFoundError(ilWACException $e): void
118  {
119  $response = $this->http
120  ->response()
121  ->withStatus(404);
122  $this->http->saveResponse($response);
123  }
124 
125  protected function handleAccessErrors(ilWACException $e): void
126  {
127  //1.5.2017 Http code needs to be 200 because mod_xsendfile ignores the response with an 401 code. (possible leak of web path via xsendfile header)
128  $response = $this->http
129  ->response()
130  ->withStatus(200);
131 
132  $this->http->saveResponse($response);
133 
134  if ($this->wac->getPathObject()->isVideo()) {
135  $this->deliverDummyVideo();
136  }
137 
138  $this->deliverDummyImage();
139 
140  $this->wac->initILIAS();
141  }
142 
143 
147  protected function handleErrors(ilWACException $e): void
148  {
149  $response = $this->http->response()
150  ->withStatus(500);
151 
155  $stream = $response->getBody();
156  $stream->write($e->getMessage());
157 
158  $this->http->saveResponse($response);
159  }
160 
161 
165  protected function deliver(): void
166  {
167  if (!$this->wac->isChecked()) {
169  }
170 
171  $path = $this->wac->getPathObject();
172  // This is currently the place where WAC handles things from the ResourceStorageService.
173  if ($path->getModuleType() === 'rs') {
174  // initialize constants
175  if (!defined('CLIENT_DATA_DIR')) {
176  $ini = new ilIniFile("./ilias.ini.php");
177  $ini->read();
178  $data_dir = rtrim($ini->readVariable("clients", "datadir"), '/');
179  $client_data_dir = $data_dir . "/" . $path->getClient();
180  } else {
181  $client_data_dir = CLIENT_DATA_DIR;
182  }
183 
184  $token_factory = new TokenFactory($client_data_dir);
185  $token = $token_factory->check($path->getFileName());
186  $path_to_file = $token->resolveStream(); // FileStream
187  } else {
188  $path_to_file = $path->getCleanURLdecodedPath();
189  }
190 
191  $real_path_to_file = realpath(__DIR__ . '/../../../../public/' . $path_to_file);
192 
193  $ilFileDelivery = new Delivery($real_path_to_file, $this->http);
194  $ilFileDelivery->setCache(true);
195  $ilFileDelivery->setDisposition($this->wac->getDisposition());
196  if ($path->isStreamable()) { // fixed 0016468
197  $ilFileDelivery->stream();
198  } else {
199  $ilFileDelivery->deliver();
200  }
201  }
202 }
$response
Definition: xapitoken.php:93
$path
Definition: ltiservices.php:29
const CLIENT_DATA_DIR
Definition: constants.php:46
static http()
Fetches the global http state from ILIAS.
$token
Definition: xapitoken.php:70
Class ilWebAccessChecker.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class Delivery.
Definition: Delivery.php:39
Class ilWebAccessCheckerDelivery.
static run(Services $httpState, CookieFactory $cookieFactory)
static handleErrorReporting()
Set error reporting level.
__construct(Services $httpState, CookieFactory $cookieFactory)
ilWebAccessCheckerDelivery constructor.
$ini
Definition: raiseError.php:20