ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1 <?php
2 
25 
32 {
34  private Services $http;
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  }
52 
53 
54  protected function handleRequest(): void
55  {
56  // Set errorreporting
58  $queries = $this->http->request()->getQueryParams();
59 
60  // Set customizing
61  if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
62  $this->wac->setDisposition($queries[ilWebAccessChecker::DISPOSITION]);
63  }
64  if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
65  $this->wac->setSendStatusCode($queries[ilWebAccessChecker::STATUS_CODE]);
66  }
67  if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
68  $this->wac->setRevalidateFolderTokens($queries[ilWebAccessChecker::REVALIDATE]);
69  }
70 
71  // Check if File can be delivered
72  try {
73  if ($this->wac->check()) {
74  $this->deliver();
75  } else {
76  $this->deny();
77  }
78  } catch (ilWACException $e) {
79  match ($e->getCode()) {
84  default => $this->handleErrors($e),
85  };
86  }
87  }
88 
92  protected function deny(): void
93  {
94  if (!$this->wac->isChecked()) {
96  }
98  }
99 
100 
101  protected function deliverDummyImage(): void
102  {
103  $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.png', $this->http);
104  $ilFileDelivery->setDisposition($this->wac->getDisposition());
105  $ilFileDelivery->deliver();
106  }
107 
108 
109  protected function deliverDummyVideo(): void
110  {
111  $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.mp4', $this->http);
112  $ilFileDelivery->setDisposition($this->wac->getDisposition());
113  $ilFileDelivery->stream();
114  }
115 
116  protected function handleNotFoundError(ilWACException $e): void
117  {
118  $response = $this->http
119  ->response()
120  ->withStatus(404);
121 
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  $ilFileDelivery = new Delivery($path_to_file, $this->http);
192  $ilFileDelivery->setCache(true);
193  $ilFileDelivery->setDisposition($this->wac->getDisposition());
194  if ($path->isStreamable()) { // fixed 0016468
195  $ilFileDelivery->stream();
196  } else {
197  $ilFileDelivery->deliver();
198  }
199  }
200 }
$response
Definition: xapitoken.php:93
$path
Definition: ltiservices.php:32
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:38
Class ilWebAccessCheckerDelivery.
static run(Services $httpState, CookieFactory $cookieFactory)
static handleErrorReporting()
Set error reporting level.
__construct(Services $httpState, CookieFactory $cookieFactory)
ilWebAccessCheckerDelivery constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ini
Definition: raiseError.php:4