Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
server.php
1
<?php
2
3
namespace
Bitrix\Main
;
4
5
use
Bitrix\Main\Type\ParameterDictionary
;
6
use
Bitrix\Main\Text\Encoding
;
7
11
class
Server
extends
ParameterDictionary
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
}
Bitrix\Main\Server
Definition
server.php:12
Bitrix\Main\Server\getServerAddr
getServerAddr()
Definition
server.php:84
Bitrix\Main\Server\getPhpSelf
getPhpSelf()
Definition
server.php:149
Bitrix\Main\Server\rewriteUri
rewriteUri($url, $queryString, $redirectStatus=null)
Definition
server.php:165
Bitrix\Main\Server\getServerPort
getServerPort()
Definition
server.php:112
Bitrix\Main\Server\getRemoteAddr
getRemoteAddr()
Definition
server.php:93
Bitrix\Main\Server\addFilter
addFilter(Type\IRequestFilter $filter)
Definition
server.php:26
Bitrix\Main\Server\getUserAgent
getUserAgent()
Definition
server.php:102
Bitrix\Main\Server\getHttpHost
getHttpHost()
Definition
server.php:64
Bitrix\Main\Server\parseAuthRequest
parseAuthRequest()
Definition
server.php:189
Bitrix\Main\Server\getScriptName
getScriptName()
Definition
server.php:160
Bitrix\Main\Server\parseDigest
static parseDigest($digest)
Definition
server.php:255
Bitrix\Main\Server\transferUri
transferUri($url, $queryString="")
Definition
server.php:173
Bitrix\Main\Server\getRequestScheme
getRequestScheme()
Definition
server.php:117
Bitrix\Main\Server\getPersonalRoot
getPersonalRoot()
Definition
server.php:50
Bitrix\Main\Server\getDocumentRoot
getDocumentRoot()
Definition
server.php:39
Bitrix\Main\Server\getRequestMethod
getRequestMethod()
Definition
server.php:138
Bitrix\Main\Server\getServerName
getServerName()
Definition
server.php:74
Bitrix\Main\Server\getRequestUri
getRequestUri()
Definition
server.php:128
Bitrix\Main\Server\__construct
__construct(array $arServer)
Definition
server.php:18
Bitrix\Main\Text\Encoding
Definition
encoding.php:8
Bitrix\Main\Type\ParameterDictionary
Definition
parameterdictionary.php:8
Bitrix\Main\Type\ParameterDictionary\setValuesNoDemand
setValuesNoDemand(array $values)
Definition
parameterdictionary.php:14
Bitrix\Main\Type\IRequestFilter
Definition
irequestfilter.php:7
Bitrix\Main\Type
Definition
collection.php:2
Bitrix\Main
modules
main
lib
server.php
Создано системой
1.10.0