Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Proxy Class Reference

Public Member Functions

 __construct ($config=null)
 _httpConnect ($fp, $host, $port)
 _parseProxyInfo ()
 getProxyAuth ()
 getProxyUser ()
 isProxyConfigured ()
 openSocket ($host, $port, $secure=false)

Data Fields

 $config = null
 $proxy_host
 $proxy_pass
 $proxy_port
 $proxy_schema
 $proxy_user

Detailed Description

Definition at line 15 of file Proxy.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $config = null)

Definition at line 40 of file Proxy.php.

41 {
42 $this->config = $config;
43 $this->_parseProxyInfo();
44 }
_parseProxyInfo()
Definition Proxy.php:49

References $config, and _parseProxyInfo().

Here is the call graph for this function:

Member Function Documentation

◆ _httpConnect()

_httpConnect ( $fp,
$host,
$port )

@access private

Definition at line 67 of file Proxy.php.

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 }
getProxyAuth()
Definition Proxy.php:120

References $port, and getProxyAuth().

Referenced by openSocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _parseProxyInfo()

_parseProxyInfo ( )

@access private

Definition at line 49 of file Proxy.php.

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 }

Referenced by __construct().

Here is the caller graph for this function:

◆ getProxyAuth()

getProxyAuth ( )

get the authorization information for the proxy, encoded to be passed in the Proxy-Authentication HTTP header.

Returns
null|string the encoded authentication information if a proxy and authentication is configured, null otherwise.

Definition at line 120 of file Proxy.php.

121 {
122 if ($this->isProxyConfigured() && $this->proxy_user != '') {
123 return base64_encode($this->proxy_user . ':' . $this->proxy_pass);
124 }
125 return null;
126 }
isProxyConfigured()
Definition Proxy.php:140

References isProxyConfigured().

Referenced by _httpConnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProxyUser()

getProxyUser ( )

Definition at line 128 of file Proxy.php.

129 {
130 return $this->proxy_user;
131 }

References $proxy_user.

◆ isProxyConfigured()

isProxyConfigured ( )

Check if we are configured to use a proxy.

Returns
boolean true if we are configured to use a proxy, false otherwise. @access public

Definition at line 140 of file Proxy.php.

141 {
142 return $this->proxy_host != '';
143 }

Referenced by getProxyAuth(), and openSocket().

Here is the caller graph for this function:

◆ openSocket()

openSocket ( $host,
$port,
$secure = false )

Open a socket to a remote server, possibly involving a HTTP proxy.

If an HTTP proxy has been configured (http_proxy PEAR_Config setting), the proxy will be used.

Parameters
string$hostthe host to connect to
string$portthe port to connect to
boolean$secureif true, establish a secure connection using TLS. @access public

Definition at line 158 of file Proxy.php.

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 }
$port
_httpConnect($fp, $host, $port)
Definition Proxy.php:67

References $port, _httpConnect(), and isProxyConfigured().

Here is the call graph for this function:

Field Documentation

◆ $config

$config = null

Definition at line 17 of file Proxy.php.

Referenced by __construct().

◆ $proxy_host

$proxy_host

@access private

Definition at line 22 of file Proxy.php.

◆ $proxy_pass

$proxy_pass

@access private

Definition at line 34 of file Proxy.php.

◆ $proxy_port

$proxy_port

@access private

Definition at line 26 of file Proxy.php.

◆ $proxy_schema

$proxy_schema

@access private

Definition at line 38 of file Proxy.php.

◆ $proxy_user

$proxy_user

@access private

Definition at line 30 of file Proxy.php.

Referenced by getProxyUser().


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Proxy.php