Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
server.php
1<?php
2
3namespace Bitrix\Main;
4
7
12{
18 public function __construct(array $arServer)
19 {
20 if (isset($arServer["DOCUMENT_ROOT"]))
21 $arServer["DOCUMENT_ROOT"] = rtrim($arServer["DOCUMENT_ROOT"], "/\\");
22
23 parent::__construct($arServer);
24 }
25
26 public function addFilter(Type\IRequestFilter $filter)
27 {
28 $filteredValues = $filter->filter($this->values);
29
30 if ($filteredValues != null)
31 $this->setValuesNoDemand($filteredValues);
32 }
33
39 public function getDocumentRoot()
40 {
41 return $this->get("DOCUMENT_ROOT");
42 }
43
50 public function getPersonalRoot()
51 {
52 $r = $this->get("BX_PERSONAL_ROOT");
53 if ($r == null || $r == "")
54 $r = "/bitrix";
55
56 return $r;
57 }
58
64 public function getHttpHost()
65 {
66 return $this->get("HTTP_HOST");
67 }
68
74 public function getServerName()
75 {
76 return $this->get("SERVER_NAME");
77 }
78
84 public function getServerAddr()
85 {
86 return $this->get("SERVER_ADDR");
87 }
88
93 public function getRemoteAddr()
94 {
95 return $this->get("REMOTE_ADDR");
96 }
97
102 public function getUserAgent()
103 {
104 return $this->get("HTTP_USER_AGENT");
105 }
106
112 public function getServerPort()
113 {
114 return $this->get("SERVER_PORT");
115 }
116
117 public function getRequestScheme()
118 {
119 return $this->get("REQUEST_SCHEME");
120 }
121
128 public function getRequestUri()
129 {
130 return $this->get("REQUEST_URI");
131 }
132
138 public function getRequestMethod()
139 {
140 return $this->get("REQUEST_METHOD");
141 }
142
149 public function getPhpSelf()
150 {
151 return $this->get("PHP_SELF");
152 }
153
160 public function getScriptName()
161 {
162 return $this->get("SCRIPT_NAME");
163 }
164
165 public function rewriteUri($url, $queryString, $redirectStatus = null)
166 {
167 $this->values["REQUEST_URI"] = $url;
168 $this->values["QUERY_STRING"] = $queryString;
169 if ($redirectStatus != null)
170 $this->values["REDIRECT_STATUS"] = $redirectStatus;
171 }
172
173 public function transferUri($url, $queryString = "")
174 {
175 $this->values["REAL_FILE_PATH"] = $url;
176 if ($queryString != "")
177 {
178 if (!isset($this->values["QUERY_STRING"]))
179 $this->values["QUERY_STRING"] = "";
180 if (isset($this->values["QUERY_STRING"]) && ($this->values["QUERY_STRING"] != ""))
181 $this->values["QUERY_STRING"] .= "&";
182 $this->values["QUERY_STRING"] .= $queryString;
183 }
184 }
185
189 public function parseAuthRequest()
190 {
191 $digest = '';
192
193 if ($this['PHP_AUTH_USER'] != '')
194 {
195 // Basic Authorization PHP module
196 return [
197 'basic' => [
198 'username' => Encoding::convertEncodingToCurrent($this['PHP_AUTH_USER']),
199 'password' => Encoding::convertEncodingToCurrent($this['PHP_AUTH_PW']),
200 ]
201 ];
202 }
203 elseif ($this['PHP_AUTH_DIGEST'] != '')
204 {
205 // Digest Authorization PHP module
206 $digest = $this['PHP_AUTH_DIGEST'];
207 }
208 else
209 {
210 if ($this['REDIRECT_REMOTE_USER'] !== null || $this['REMOTE_USER'] !== null)
211 {
212 $res = $this['REDIRECT_REMOTE_USER'] ?? $this['REMOTE_USER'];
213 if ($res != '')
214 {
215 if(preg_match('/^\x20*Basic\x20+([a-zA-Z0-9+\/=]+)\s*$/D', $res, $matches))
216 {
217 // Basic Authorization PHP FastCGI (CGI)
218 $res = trim($matches[1]);
219 $res = base64_decode($res);
220 $res = Encoding::convertEncodingToCurrent($res);
221 [$user, $pass] = explode(':', $res, 2);
222 if (mb_strpos($user, $this['HTTP_HOST']."\\") === 0)
223 {
224 $user = str_replace($this['HTTP_HOST']."\\", "", $user);
225 }
226 elseif (mb_strpos($user, $this['SERVER_NAME']."\\") === 0)
227 {
228 $user = str_replace($this['SERVER_NAME']."\\", "", $user);
229 }
230
231 return [
232 'basic' => [
233 'username' => $user,
234 'password' => $pass,
235 ]
236 ];
237 }
238 elseif (preg_match('/^\x20*Digest\x20+(.*)$/sD', $res, $matches))
239 {
240 // Digest Authorization PHP FastCGI (CGI)
241 $digest = trim($matches[1]);
242 }
243 }
244 }
245 }
246
247 if($digest <> '' && ($data = static::parseDigest($digest)))
248 {
249 return ['digest' => $data];
250 }
251
252 return false;
253 }
254
255 protected static function parseDigest($digest)
256 {
257 $data = [];
258 $parts = ['nonce' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
259 $keys = implode('|', array_keys($parts));
260
261 //from php help
262 preg_match_all('@('.$keys.')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $digest, $matches, PREG_SET_ORDER);
263
264 foreach ($matches as $m)
265 {
266 $data[$m[1]] = ($m[3] ?: $m[4]);
267 unset($parts[$m[1]]);
268 }
269
270 return ($parts? false : $data);
271 }
272}
rewriteUri($url, $queryString, $redirectStatus=null)
Definition server.php:165
addFilter(Type\IRequestFilter $filter)
Definition server.php:26
static parseDigest($digest)
Definition server.php:255
transferUri($url, $queryString="")
Definition server.php:173
__construct(array $arServer)
Definition server.php:18