ILIAS  release_8 Revision v8.25
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1<?php
2
22
29{
31 private Services $http;
32
33
34 public static function run(Services $httpState, CookieFactory $cookieFactory): void
35 {
36 $obj = new self($httpState, $cookieFactory);
37 $obj->handleRequest();
38 }
39
40
44 public function __construct(Services $httpState, CookieFactory $cookieFactory)
45 {
46 $this->wac = new ilWebAccessChecker($httpState, $cookieFactory);
47 $this->http = $httpState;
48 }
49
50
51 protected function handleRequest(): void
52 {
53 // Set errorreporting
55 $queries = $this->http->request()->getQueryParams();
56
57 // Set customizing
58 if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
59 $this->wac->setDisposition($queries[ilWebAccessChecker::DISPOSITION]);
60 }
61 if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
62 $this->wac->setSendStatusCode($queries[ilWebAccessChecker::STATUS_CODE]);
63 }
64 if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
65 $this->wac->setRevalidateFolderTokens($queries[ilWebAccessChecker::REVALIDATE]);
66 }
67
68 // Check if File can be delivered
69 try {
70 if ($this->wac->check()) {
71 $this->deliver();
72 } else {
73 $this->deny();
74 }
75 } catch (ilWACException $e) {
76 switch ($e->getCode()) {
78 $this->handleNotFoundError($e);
79 break;
83 $this->handleAccessErrors($e);
84 break;
88 default:
89 $this->handleErrors($e);
90 break;
91 }
92
93 }
94 }
95
99 protected function deny(): void
100 {
101 if (!$this->wac->isChecked()) {
103 }
105 }
106
107
108 protected function deliverDummyImage(): void
109 {
110 $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.png', $this->http);
111 $ilFileDelivery->setDisposition($this->wac->getDisposition());
112 $ilFileDelivery->deliver();
113 }
114
115
116 protected function deliverDummyVideo(): void
117 {
118 $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.mp4', $this->http);
119 $ilFileDelivery->setDisposition($this->wac->getDisposition());
120 $ilFileDelivery->stream();
121 }
122
123 protected function handleNotFoundError(ilWACException $e): void
124 {
125 $response = $this->http
126 ->response()
127 ->withStatus(404);
128
129 $this->http->saveResponse($response);
130 }
131
132 protected function handleAccessErrors(ilWACException $e): void
133 {
134
135 //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)
136 $response = $this->http
137 ->response()
138 ->withStatus(200);
139
140 $this->http->saveResponse($response);
141
142 if ($this->wac->getPathObject()->isImage()) {
143 $this->deliverDummyImage();
144 }
145 if ($this->wac->getPathObject()->isVideo()) {
146 $this->deliverDummyVideo();
147 }
148
149 $this->wac->initILIAS();
150 }
151
152
156 protected function handleErrors(ilWACException $e): void
157 {
158 $response = $this->http->response()
159 ->withStatus(500);
160
164 $stream = $response->getBody();
165 $stream->write($e->getMessage());
166
167 $this->http->saveResponse($response);
168 }
169
170
174 protected function deliver(): void
175 {
176 if (!$this->wac->isChecked()) {
178 }
179
180 $ilFileDelivery = new Delivery($this->wac->getPathObject()->getCleanURLdecodedPath(), $this->http);
181 $ilFileDelivery->setCache(true);
182 $ilFileDelivery->setDisposition($this->wac->getDisposition());
183 if ($this->wac->getPathObject()->isStreamable()) { // fixed 0016468
184 $ilFileDelivery->stream();
185 } else {
186 $ilFileDelivery->deliver();
187 }
188 }
189}
Class Services.
Definition: Services.php:38
static handleErrorReporting()
Set error reporting level.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilWebAccessCheckerDelivery.
static run(Services $httpState, CookieFactory $cookieFactory)
__construct(Services $httpState, CookieFactory $cookieFactory)
ilWebAccessCheckerDelivery constructor.
Class ilWebAccessChecker.
static http()
Fetches the global http state from ILIAS.
$response