ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1 <?php
2 
25 
32 {
34  private Services $http;
35  private string $img_dir;
36 
37 
38  public static function run(Services $httpState, CookieFactory $cookieFactory): void
39  {
40  $obj = new self($httpState, $cookieFactory);
41  $obj->handleRequest();
42  }
43 
44 
48  public function __construct(Services $httpState, CookieFactory $cookieFactory)
49  {
50  $this->wac = new ilWebAccessChecker($httpState, $cookieFactory);
51  $this->http = $httpState;
52  $this->img_dir = realpath(__DIR__ . '/../templates/images');
53  }
54 
55 
56  protected function handleRequest(): void
57  {
58  // Set errorreporting
60  $queries = $this->http->request()->getQueryParams();
61 
62  // Set customizing
63  if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
64  $this->wac->setDisposition($queries[ilWebAccessChecker::DISPOSITION]);
65  }
66  if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
67  $this->wac->setSendStatusCode($queries[ilWebAccessChecker::STATUS_CODE]);
68  }
69  if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
70  $this->wac->setRevalidateFolderTokens($queries[ilWebAccessChecker::REVALIDATE]);
71  }
72 
73  // Check if File can be delivered
74  try {
75  if ($this->wac->check()) {
76  $this->deliver();
77  } else {
78  $this->deny();
79  }
80  } catch (ilWACException $e) {
81  match ($e->getCode()) {
86  default => $this->handleErrors($e),
87  };
88  }
89  }
90 
94  protected function deny(): void
95  {
96  if (!$this->wac->isChecked()) {
98  }
100  }
101 
102 
103  protected function deliverDummyImage(): void
104  {
105  $ilFileDelivery = new Delivery($this->img_dir . '/access_denied.png', $this->http);
106  $ilFileDelivery->setDisposition($this->wac->getDisposition());
107  $ilFileDelivery->deliver();
108  }
109 
110 
111  protected function deliverDummyVideo(): void
112  {
113  $ilFileDelivery = new Delivery($this->img_dir . '/access_denied.mp4', $this->http);
114  $ilFileDelivery->setDisposition($this->wac->getDisposition());
115  $ilFileDelivery->stream();
116  }
117 
118  protected function handleNotFoundError(ilWACException $e): void
119  {
120  $response = $this->http
121  ->response()
122  ->withStatus(404);
123  $this->http->saveResponse($response);
124  }
125 
126  protected function handleAccessErrors(ilWACException $e): void
127  {
128  //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)
129  $response = $this->http
130  ->response()
131  ->withStatus(200);
132 
133  $this->http->saveResponse($response);
134 
135  if ($this->wac->getPathObject()->isVideo()) {
136  $this->deliverDummyVideo();
137  }
138 
139  $this->deliverDummyImage();
140 
141  $this->wac->initILIAS();
142  }
143 
144 
148  protected function handleErrors(ilWACException $e): void
149  {
150  $response = $this->http->response()
151  ->withStatus(500);
152 
156  $stream = $response->getBody();
157  $stream->write($e->getMessage());
158 
159  $this->http->saveResponse($response);
160  }
161 
162 
166  protected function deliver(): void
167  {
168  if (!$this->wac->isChecked()) {
170  }
171 
172  $path = $this->wac->getPathObject();
173  // This is currently the place where WAC handles things from the ResourceStorageService.
174  if ($path->getModuleType() === 'rs') {
175  // initialize constants
176  if (!defined('CLIENT_DATA_DIR')) {
177  $ini = new ilIniFile("./ilias.ini.php");
178  $ini->read();
179  $data_dir = rtrim($ini->readVariable("clients", "datadir"), '/');
180  $client_data_dir = $data_dir . "/" . $path->getClient();
181  } else {
182  $client_data_dir = CLIENT_DATA_DIR;
183  }
184 
185  $token_factory = new TokenFactory($client_data_dir);
186  $token = $token_factory->check($path->getFileName());
187  $path_to_file = $token->resolveStream(); // FileStream
188  } else {
189  $path_to_file = $path->getCleanURLdecodedPath();
190  }
191 
192  $real_path_to_file = realpath(__DIR__ . '/../../../../public/' . $path_to_file);
193 
194  $ilFileDelivery = new Delivery($real_path_to_file, $this->http);
195  $ilFileDelivery->setCache(true);
196  $ilFileDelivery->setDisposition($this->wac->getDisposition());
197  if ($path->isStreamable()) { // fixed 0016468
198  $ilFileDelivery->stream();
199  } else {
200  $ilFileDelivery->deliver();
201  }
202  }
203 }
$response
Definition: xapitoken.php:90
$path
Definition: ltiservices.php:30
const CLIENT_DATA_DIR
Definition: constants.php:46
static http()
Fetches the global http state from ILIAS.
$token
Definition: xapitoken.php:67
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:38
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:4