ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1 <?php
18 // declare(strict_types=1);
19 require_once('./Services/WebAccessChecker/classes/class.ilWebAccessChecker.php');
20 require_once('./Services/FileDelivery/classes/Delivery.php');
21 require_once('./Services/FileDelivery/classes/class.ilFileDelivery.php');
22 
26 
33 {
34 
38  private $ilWebAccessChecker = null;
42  private $http;
43 
44 
51  public static function run(GlobalHttpState $httpState, CookieFactory $cookieFactory)
52  {
53  $obj = new self($httpState, $cookieFactory);
54  $obj->handleRequest();
55  }
56 
57 
64  public function __construct(GlobalHttpState $httpState, CookieFactory $cookieFactory)
65  {
66  $this->ilWebAccessChecker = new ilWebAccessChecker($httpState, $cookieFactory);
67  $this->http = $httpState;
68  }
69 
70 
74  protected function handleRequest()
75  {
76  // Set errorreporting
78  $queries = $this->http->request()->getQueryParams();
79 
80  // Set customizing
81  if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
82  $this->ilWebAccessChecker->setDisposition($queries[ilWebAccessChecker::DISPOSITION]);
83  }
84  if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
85  $this->ilWebAccessChecker->setSendStatusCode($queries[ilWebAccessChecker::STATUS_CODE]);
86  }
87  if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
88  $this->ilWebAccessChecker->setRevalidateFolderTokens($queries[ilWebAccessChecker::REVALIDATE]);
89  }
90 
91  // Check if File can be delivered
92  try {
93  if ($this->ilWebAccessChecker->check()) {
94  $this->deliver();
95  } else {
96  $this->deny();
97  }
98  } catch (ilWACException $e) {
99  switch ($e->getCode()) {
101  $this->handleNotFoundError($e);
102  break;
106  $this->handleAccessErrors($e);
107  break;
111  default:
112  $this->handleErrors($e);
113  break;
114  }
115  }
116  }
117 
118 
119  protected function deny()
120  {
121  if (!$this->ilWebAccessChecker->isChecked()) {
123  }
125  }
126 
127 
128  protected function deliverDummyImage()
129  {
130  $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.png', $this->http);
131  $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
132  $ilFileDelivery->deliver();
133  }
134 
135 
136  protected function deliverDummyVideo()
137  {
138  $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.mp4', $this->http);
139  $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
140  $ilFileDelivery->stream();
141  }
142 
143  protected function handleNotFoundError(ilWACException $e) : void
144  {
145  $response = $this->http
146  ->response()
147  ->withStatus(404);
148 
149  $this->http->saveResponse($response);
150  }
151 
156  {
157 
158  //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)
159  $response = $this->http
160  ->response()
161  ->withStatus(200);
162 
163  $this->http->saveResponse($response);
164 
165  if ($this->ilWebAccessChecker->getPathObject()->isImage()) {
166  $this->deliverDummyImage();
167  }
168  if ($this->ilWebAccessChecker->getPathObject()->isVideo()) {
169  $this->deliverDummyVideo();
170  }
171 
172  $this->ilWebAccessChecker->initILIAS();
173  }
174 
175 
180  protected function handleErrors(ilWACException $e)
181  {
182  $response = $this->http->response()
183  ->withStatus(500);
184 
188  $stream = $response->getBody();
189  $stream->write($e->getMessage());
190 
191  $this->http->saveResponse($response);
192  }
193 
194 
199  protected function deliver()
200  {
201  if (!$this->ilWebAccessChecker->isChecked()) {
203  }
204 
205  $ilFileDelivery = new Delivery($this->ilWebAccessChecker->getPathObject()->getCleanURLdecodedPath(), $this->http);
206  $ilFileDelivery->setCache(true);
207  $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
208  if ($this->ilWebAccessChecker->getPathObject()->isStreamable()) { // fixed 0016468
209  $ilFileDelivery->stream();
210  } else {
211  $ilFileDelivery->deliver();
212  }
213  }
214 }
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRevalidateFolderTokens($revalidate_folder_tokens)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
Class ilWebAccessChecker.
setSendStatusCode($send_status_code)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(GlobalHttpState $httpState, CookieFactory $cookieFactory)
ilWebAccessCheckerDelivery constructor.
Class ilWebAccessCheckerDelivery.
static handleErrorReporting()
Set error reporting level.
$response
static run(GlobalHttpState $httpState, CookieFactory $cookieFactory)