1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
proxy.php
См. документацию.
1
<?
2
3
namespace
Bitrix\Main\UI\ImageEditor
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Config\Option
;
7
use
Bitrix\Main\Web\Uri
;
8
use
Bitrix\Main\Web\HttpClient
;
9
14
class
Proxy
15
{
17
protected
$uri
;
18
20
protected
$allowedHosts
= [];
21
28
public
function
__construct
(
$url
,
$allowedHosts
= [])
29
{
30
$response
= static::getResponse();
31
32
if
(!static::isAuthorized())
33
{
34
$response
->setStatus(401)->flush();
35
die
(
'Unauthorized'
);
36
}
37
38
if
(is_array(
$allowedHosts
))
39
{
40
$this->allowedHosts = array_filter(
$allowedHosts
,
function
($item) {
41
return
is_string($item) && !empty($item);
42
});
43
}
44
45
$this->uri =
new
Uri
(
$url
);
46
47
if
(!$this->uri->getHost())
48
{
49
$this->uri->setHost(static::getCurrentHttpHost());
50
}
51
}
52
57
protected
static
function
getResponse
()
58
{
59
return
Application::getInstance
()->getContext()->getResponse();
60
}
61
65
protected
static
function
isAuthorized
()
66
{
67
global
$USER
;
68
return
(
$USER
->isAuthorized() &&
check_bitrix_sessid
());
69
}
70
76
protected
function
getCurrentHttpHost
()
77
{
78
static
$server =
null
;
79
80
if
($server ===
null
)
81
{
82
$server =
Application::getInstance
()->getContext()->getServer();
83
}
84
85
return
explode(
':'
, $server->getHttpHost())[0];
86
}
87
93
protected
function
getAllowedHosts
()
94
{
95
return
array_merge(
96
[$this->
getCurrentHttpHost
()],
97
$this->allowedHosts,
98
$this->
getUserAllowedHosts
()
99
);
100
}
101
106
protected
function
getUserAllowedHosts
()
107
{
108
static
$hosts =
null
;
109
110
if
($hosts ===
null
)
111
{
112
$hosts = Option::get(
'main'
,
'imageeditor_proxy_white_list'
, []);
113
if
(is_string($hosts))
114
{
115
$hosts = unserialize($hosts, [
'allowed_classes'
=>
false
]);
116
}
117
}
118
119
return
$hosts;
120
}
121
128
protected
function
isAllowedHost
(
$host
)
129
{
130
return
(
131
in_array(
$host
, $this->
getAllowedHosts
()) ||
132
(in_array(
'*'
, $this->
getAllowedHosts
()) && $this->
isEnabledForAll
())
133
);
134
}
135
136
142
protected
function
isEnabledForAll
()
143
{
144
return
static::getEnabledOption() ===
'Y'
;
145
}
146
152
protected
static
function
isEnabledForWhiteList
()
153
{
154
return
static::getEnabledOption() ===
'YWL'
;
155
}
156
162
protected
static
function
getEnabledOption
()
163
{
164
static
$option
=
null
;
165
166
if
(
$option
===
null
)
167
{
168
$option
= Option::get(
'main'
,
'imageeditor_proxy_enabled'
,
'N'
);
169
}
170
171
return
$option
;
172
}
173
181
protected
function
isEnabledForHost
(
$host
)
182
{
183
return
static::isEnabledForWhiteList() && $this->
isAllowedHost
(
$host
);
184
}
185
186
public
function
output
()
187
{
188
$remoteHost = $this->uri->getHost();
189
$currentHost = static::getCurrentHttpHost();
190
$response
= static::getResponse();
191
192
if
($this->
isEnabledForAll
() ||
193
$this->
isEnabledForHost
($remoteHost) ||
194
$remoteHost === $currentHost)
195
{
196
$client =
new
HttpClient
();
197
198
//prevents proxy to LAN
199
$client->setPrivateIp(
false
);
200
201
$contents
= $client->get($this->uri->getUri());
202
if
(
$contents
!==
false
)
203
{
204
$response
->addHeader(
'Content-Type'
, $client->getContentType());
205
$response
->flush(
$contents
);
206
return
;
207
}
208
}
209
$response
->setStatus(404)->flush();
210
}
211
}
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\Config\Option
Определения
option.php:15
Bitrix\Main\UI\ImageEditor\Proxy
Определения
proxy.php:15
Bitrix\Main\UI\ImageEditor\Proxy\isAllowedHost
isAllowedHost($host)
Определения
proxy.php:128
Bitrix\Main\UI\ImageEditor\Proxy\getUserAllowedHosts
getUserAllowedHosts()
Определения
proxy.php:106
Bitrix\Main\UI\ImageEditor\Proxy\getEnabledOption
static getEnabledOption()
Определения
proxy.php:162
Bitrix\Main\UI\ImageEditor\Proxy\getCurrentHttpHost
getCurrentHttpHost()
Определения
proxy.php:76
Bitrix\Main\UI\ImageEditor\Proxy\$allowedHosts
$allowedHosts
Определения
proxy.php:20
Bitrix\Main\UI\ImageEditor\Proxy\__construct
__construct($url, $allowedHosts=[])
Определения
proxy.php:28
Bitrix\Main\UI\ImageEditor\Proxy\output
output()
Определения
proxy.php:186
Bitrix\Main\UI\ImageEditor\Proxy\isAuthorized
static isAuthorized()
Определения
proxy.php:65
Bitrix\Main\UI\ImageEditor\Proxy\$uri
$uri
Определения
proxy.php:17
Bitrix\Main\UI\ImageEditor\Proxy\getResponse
static getResponse()
Определения
proxy.php:57
Bitrix\Main\UI\ImageEditor\Proxy\isEnabledForWhiteList
static isEnabledForWhiteList()
Определения
proxy.php:152
Bitrix\Main\UI\ImageEditor\Proxy\isEnabledForAll
isEnabledForAll()
Определения
proxy.php:142
Bitrix\Main\UI\ImageEditor\Proxy\getAllowedHosts
getAllowedHosts()
Определения
proxy.php:93
Bitrix\Main\UI\ImageEditor\Proxy\isEnabledForHost
isEnabledForHost($host)
Определения
proxy.php:181
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
Bitrix\Main\Web\Uri
Определения
uri.php:17
$contents
$contents
Определения
commerceml2.php:57
$USER
global $USER
Определения
csv_new_run.php:40
check_bitrix_sessid
check_bitrix_sessid($varname='sessid')
Определения
tools.php:4686
Bitrix\Main\UI\ImageEditor
Определения
proxy.php:3
Bitrix\Main\$host
$host
Определения
mysql_to_pgsql.php:32
die
die
Определения
quickway.php:367
$option
$option
Определения
options.php:1711
$response
$response
Определения
result.php:21
$url
$url
Определения
iframe.php:7
bitrix
modules
main
lib
ui
imageeditor
proxy.php
Создано системой
1.14.0