Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
Proxy.php
Go to the documentation of this file.
1
<?php
14
15
class
PEAR_Proxy
16
{
17
var
$config
=
null
;
18
22
var
$proxy_host
;
26
var
$proxy_port
;
30
var
$proxy_user
;
34
var
$proxy_pass
;
38
var
$proxy_schema
;
39
40
function
__construct
(
$config
=
null
)
41
{
42
$this->config =
$config
;
43
$this->
_parseProxyInfo
();
44
}
45
49
function
_parseProxyInfo
()
50
{
51
$this->proxy_host = $this->proxy_port = $this->proxy_user = $this->proxy_pass =
''
;
52
if
($this->config->get(
'http_proxy'
)&&
53
$proxy = parse_url($this->config->get(
'http_proxy'
))
54
) {
55
$this->proxy_host = isset($proxy[
'host'
]) ? $proxy[
'host'
] :
null
;
56
57
$this->proxy_port = isset($proxy[
'port'
]) ? $proxy[
'port'
] : 8080;
58
$this->proxy_user = isset($proxy[
'user'
]) ? urldecode($proxy[
'user'
]) :
null
;
59
$this->proxy_pass = isset($proxy[
'pass'
]) ? urldecode($proxy[
'pass'
]) :
null
;
60
$this->proxy_schema = (isset($proxy[
'scheme'
]) && $proxy[
'scheme'
] ==
'https'
) ?
'https'
:
'http'
;
61
}
62
}
63
67
function
_httpConnect
($fp, $host,
$port
)
68
{
69
fwrite($fp,
"CONNECT $host:$port HTTP/1.1\r\n"
);
70
fwrite($fp,
"Host: $host:$port\r\n"
);
71
if
($this->
getProxyAuth
()) {
72
fwrite($fp,
'Proxy-Authorization: Basic '
. $this->
getProxyAuth
() .
"\r\n"
);
73
}
74
fwrite($fp,
"\r\n"
);
75
76
while
($line = trim(fgets($fp, 1024))) {
77
if
(preg_match(
'|^HTTP/1.[01] ([0-9]{3}) |'
, $line, $matches)) {
78
$code = (int)$matches[1];
79
80
/* as per RFC 2817 */
81
if
($code < 200 || $code >= 300) {
82
return
PEAR::raiseError(
"Establishing a CONNECT tunnel through proxy failed with response code $code"
);
83
}
84
}
85
}
86
87
// connection was successful -- establish SSL through
88
// the tunnel
89
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
90
91
if
(defined(
'STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT'
)) {
92
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
93
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
94
}
95
96
// set the correct hostname for working hostname
97
// verification
98
stream_context_set_option($fp,
'ssl'
,
'peer_name'
, $host);
99
100
// blocking socket needed for
101
// stream_socket_enable_crypto()
102
// see
103
// <http://php.net/manual/en/function.stream-socket-enable-crypto.php>
104
stream_set_blocking ($fp,
true
);
105
$crypto_res = stream_socket_enable_crypto($fp,
true
, $crypto_method);
106
if
(!$crypto_res) {
107
return
PEAR::raiseError(
"Could not establish SSL connection through proxy: $crypto_res"
);
108
}
109
110
return
true
;
111
}
112
120
function
getProxyAuth
()
121
{
122
if
($this->
isProxyConfigured
() && $this->proxy_user !=
''
) {
123
return
base64_encode($this->proxy_user .
':'
. $this->proxy_pass);
124
}
125
return
null
;
126
}
127
128
function
getProxyUser
()
129
{
130
return
$this->proxy_user
;
131
}
132
140
function
isProxyConfigured
()
141
{
142
return
$this->proxy_host !=
''
;
143
}
144
158
function
openSocket
($host,
$port
, $secure =
false
)
159
{
160
if
($this->
isProxyConfigured
()) {
161
$fp = @fsockopen(
162
$this->proxy_host, $this->proxy_port,
163
$errno, $errstr, 15
164
);
165
166
if
(!$fp) {
167
return
PEAR::raiseError(
"Connection to the proxy failed: $errstr"
, -9276);
168
}
169
170
/* HTTPS is to be used and we have a proxy, use CONNECT verb */
171
if
($secure) {
172
$res = $this->
_httpConnect
($fp, $host,
$port
);
173
174
if
(PEAR::isError($res)) {
175
return
$res;
176
}
177
}
178
}
else
{
179
if
($secure) {
180
$host =
'ssl://'
. $host;
181
}
182
183
$fp = @fsockopen($host,
$port
, $errno, $errstr);
184
if
(!$fp) {
185
return
PEAR::raiseError(
"Connection to `$host:$port' failed: $errstr"
, $errno);
186
}
187
}
188
189
return
$fp;
190
}
191
}
$port
$port
Definition
ajax.apache.php:34
PEAR_Proxy
Definition
Proxy.php:16
PEAR_Proxy\isProxyConfigured
isProxyConfigured()
Definition
Proxy.php:140
PEAR_Proxy\getProxyUser
getProxyUser()
Definition
Proxy.php:128
PEAR_Proxy\_parseProxyInfo
_parseProxyInfo()
Definition
Proxy.php:49
PEAR_Proxy\$config
$config
Definition
Proxy.php:17
PEAR_Proxy\$proxy_port
$proxy_port
Definition
Proxy.php:26
PEAR_Proxy\$proxy_pass
$proxy_pass
Definition
Proxy.php:34
PEAR_Proxy\$proxy_schema
$proxy_schema
Definition
Proxy.php:38
PEAR_Proxy\$proxy_host
$proxy_host
Definition
Proxy.php:22
PEAR_Proxy\openSocket
openSocket($host, $port, $secure=false)
Definition
Proxy.php:158
PEAR_Proxy\_httpConnect
_httpConnect($fp, $host, $port)
Definition
Proxy.php:67
PEAR_Proxy\__construct
__construct($config=null)
Definition
Proxy.php:40
PEAR_Proxy\getProxyAuth
getProxyAuth()
Definition
Proxy.php:120
PEAR_Proxy\$proxy_user
$proxy_user
Definition
Proxy.php:30
sandbox
core
libs
php
pear
pear
PEAR
Proxy.php
Generated by
1.17.0