ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebAccessCheckerDelivery.php
Go to the documentation of this file.
1<?php
2// declare(strict_types=1);
3
4require_once('./Services/WebAccessChecker/classes/class.ilWebAccessChecker.php');
5require_once('./Services/FileDelivery/classes/Delivery.php');
6require_once('./Services/FileDelivery/classes/class.ilFileDelivery.php');
7
11
18{
19
23 private $ilWebAccessChecker = null;
27 private $http;
28
29
36 public static function run(GlobalHttpState $httpState, CookieFactory $cookieFactory)
37 {
38 $obj = new self($httpState, $cookieFactory);
39 $obj->handleRequest();
40 }
41
42
49 public function __construct(GlobalHttpState $httpState, CookieFactory $cookieFactory)
50 {
51 $this->ilWebAccessChecker = new ilWebAccessChecker($httpState, $cookieFactory);
52 $this->http = $httpState;
53 }
54
55
59 protected function handleRequest()
60 {
61 // Set errorreporting
63 $queries = $this->http->request()->getQueryParams();
64
65 // Set customizing
66 if (isset($queries[ilWebAccessChecker::DISPOSITION])) {
68 }
69 if (isset($queries[ilWebAccessChecker::STATUS_CODE])) {
71 }
72 if (isset($queries[ilWebAccessChecker::REVALIDATE])) {
74 }
75
76 // Check if File can be delivered
77 try {
78 if ($this->ilWebAccessChecker->check()) {
79 $this->deliver();
80 } else {
81 $this->deny();
82 }
83 } catch (ilWACException $e) {
84 switch ($e->getCode()) {
88 $this->handleAccessErrors($e);
89 break;
93 default:
94 $this->handleErrors($e);
95 break;
96 }
97 }
98 }
99
100
101 protected function deny()
102 {
103 if (!$this->ilWebAccessChecker->isChecked()) {
105 }
107 }
108
109
110 protected function deliverDummyImage()
111 {
112 $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.png', $this->http);
113 $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
114 $ilFileDelivery->deliver();
115 }
116
117
118 protected function deliverDummyVideo()
119 {
120 $ilFileDelivery = new Delivery('./Services/WebAccessChecker/templates/images/access_denied.mp4', $this->http);
121 $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
122 $ilFileDelivery->stream();
123 }
124
125
129 protected function handleAccessErrors(ilWACException $e)
130 {
131
132 //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)
133 $response = $this->http
134 ->response()
135 ->withStatus(200);
136
137 $this->http->saveResponse($response);
138
139 if ($this->ilWebAccessChecker->getPathObject()->isImage()) {
140 $this->deliverDummyImage();
141 }
142 if ($this->ilWebAccessChecker->getPathObject()->isVideo()) {
143 $this->deliverDummyVideo();
144 }
145
147 }
148
149
154 protected function handleErrors(ilWACException $e)
155 {
156 $response = $this->http->response()
157 ->withStatus(500);
158
159
163 $stream = $response->getBody();
164 $stream->write($e->getMessage());
165
166 $this->http->saveResponse($response);
167 }
168
169
174 protected function deliver()
175 {
176 if (!$this->ilWebAccessChecker->isChecked()) {
178 }
179
180 $ilFileDelivery = new Delivery($this->ilWebAccessChecker->getPathObject()->getCleanURLdecodedPath(), $this->http);
181 $ilFileDelivery->setCache(true);
182 $ilFileDelivery->setDisposition($this->ilWebAccessChecker->getDisposition());
183 if ($this->ilWebAccessChecker->getPathObject()->isStreamable()) { // fixed 0016468
184 $ilFileDelivery->stream();
185 } else {
186 $ilFileDelivery->deliver();
187 }
188 }
189}
An exception for terminatinating execution or to throw for unit testing.
static handleErrorReporting()
Set error reporting level.
Class ilWACException.
Class ilWebAccessCheckerDelivery.
__construct(GlobalHttpState $httpState, CookieFactory $cookieFactory)
ilWebAccessCheckerDelivery constructor.
static run(GlobalHttpState $httpState, CookieFactory $cookieFactory)
Class ilWebAccessChecker.
setSendStatusCode($send_status_code)
setRevalidateFolderTokens($revalidate_folder_tokens)
Interface GlobalHttpState.
$stream
PHP stream implementation.
static http()
Fetches the global http state from ILIAS.
$response