RE: [PEAR-DEV] Patch to go-pear : Proxy authentication
| From: | LIMBOURG Arnaud | Date: | Fri, 09 Aug 2002 07:41:38 +0000 |
| Subject: | RE: [PEAR-DEV] Patch to go-pear : Proxy authentication | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-8263@lists.php.net to get a copy of this message | ||
Here are the unified diffs.
Arnaud.
> It looks ok, but next time, please post a unified diff (diff -u).
>
> -Tal
--- Common-Original.php Thu Aug 8 15:08:19 2002 +++ Common.php Thu Aug 8 15:03:14 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.76 2002/07/04 20:28:56 mj Exp $ +// $Id: Common.php,v 1.75 2002/06/19 23:38:45 cox Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -1430,11 +1430,14 @@ } else { $config = &PEAR_Config::singleton(); } - $proxy_host = $proxy_port = null; - if ($proxy = $config->get('http_proxy')) { - $proxy = str_replace('http://', '', $proxy); - list($proxy_host, $proxy_port) = explode(':', $proxy); - if (empty($proxy_port)) { + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if ($proxy = parse_url($config->get('http_proxy'))) { + $proxy_host = $proxy['host']; + $proxy_port = $proxy['port']; + $proxy_user = $proxy['user']; + $proxy_pass = $proxy['pass']; + + if ($proxy_port == '') { $proxy_port = 8080; } if ($callback) { @@ -1444,7 +1447,7 @@ if (empty($port)) { $port = 80; } - if ($proxy_host) { + if ($proxy_host != '') { $fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr); if (!$fp) { if ($callback) { @@ -1465,9 +1468,13 @@ } $request = "GET $path HTTP/1.0\r\n"; } - $request .= "Host: $host:$port\r\n". - "User-Agent: ".PHP_VERSION."\r\n". - "\r\n"; + $request .= "Host: $host:$port\r\n" . + "User-Agent: ".PHP_VERSION."\r\n"; + if ($proxy_host != '' && $proxy_user != '') { + $request .= 'Proxy-Authorization: Basic ' . + base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n"; + } + $request .= "\r\n"; fwrite($fp, $request); $headers = array(); while (trim($line = fgets($fp, 1024))) { --- Remote-Original.php Thu Aug 8 15:11:40 2002 +++ Remote.php Thu Aug 8 15:35:57 2002 @@ -63,10 +63,21 @@ $server_host = $this->config->get('master_server'); $username = $this->config->get('username'); $password = $this->config->get('password'); + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if (sizeof($proxy = parse_url($this->config->get('http_proxy'))) > 1) { + $proxy_host = $proxy['host']; + $proxy_port = $proxy['port']; + $proxy_user = $proxy['user']; + $proxy_pass = $proxy['pass']; + + if ($proxy_port == '') { + $proxy_port = 8080; + } // if + } $eargs = array(); foreach($args as $arg) $eargs[] = $this->_encode($arg); $f = new XML_RPC_Message($method, $eargs); - $c = new XML_RPC_Client('/xmlrpc.php', $server_host, 80); + $c = new XML_RPC_Client('/xmlrpc.php', $server_host, 80, $proxy_host, $proxy_port, $proxy_user, $proxy_pass); if ($username && $password) { $c->setCredentials($username, $password); } --- RPC-Original.php Thu Aug 8 15:13:39 2002 +++ RPC.php Thu Aug 8 14:28:57 2002 @@ -371,14 +371,18 @@ var $debug=0; var $username=""; var $password=""; + var $proxy_user = ''; + var $proxy_pass = ''; - function XML_RPC_Client($path, $server, $port=80, $proxy="", $proxy_port=8080) + function XML_RPC_Client($path, $server, $port=80, $proxy = '', $proxy_port = 8080, $proxy_user = '', $proxy_pass = '') { - $this->port=$port; - $this->server=$server; - $this->path=$path; - $this->proxy = $proxy; - $this->proxy_port = $proxy_port ; + $this->port =$port; + $this->server =$server; + $this->path =$path; + $this->proxy = $proxy; + $this->proxy_port = $proxy_port; + $this->proxy_user = $proxy_user; + $this->proxy_pass = $proxy_pass; } function setDebug($in) @@ -457,8 +461,14 @@ } $op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . - "Host: ". $this->server . "\r\n" . - $credentials . + "Host: ". $this->server . "\r\n"; + + if ($this->proxy && $this->proxy_user != '') { + $op .= 'Proxy-Authorization: Basic ' . + base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; + } + + $op .= $credentials . "Content-Type: text/xml\r\nContent-Length: " . strlen($msg->payload) . "\r\n\r\n" . $msg->payload;
--- Common-Original.php Thu Aug 8 15:08:19 2002 +++ Common.php Thu Aug 8 15:03:14 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.76 2002/07/04 20:28:56 mj Exp $ +// $Id: Common.php,v 1.75 2002/06/19 23:38:45 cox Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -1430,11 +1430,14 @@ } else { $config = &PEAR_Config::singleton(); } - $proxy_host = $proxy_port = null; - if ($proxy = $config->get('http_proxy')) { - $proxy = str_replace('http://', '', $proxy); - list($proxy_host, $proxy_port) = explode(':', $proxy); - if (empty($proxy_port)) { + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if ($proxy = parse_url($config->get('http_proxy'))) { + $proxy_host = $proxy['host']; + $proxy_port = $proxy['port']; + $proxy_user = $proxy['user']; + $proxy_pass = $proxy['pass']; + + if ($proxy_port == '') { $proxy_port = 8080; } if ($callback) { @@ -1444,7 +1447,7 @@ if (empty($port)) { $port = 80; } - if ($proxy_host) { + if ($proxy_host != '') { $fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr); if (!$fp) { if ($callback) { @@ -1465,9 +1468,13 @@ } $request = "GET $path HTTP/1.0\r\n"; } - $request .= "Host: $host:$port\r\n". - "User-Agent: ".PHP_VERSION."\r\n". - "\r\n"; + $request .= "Host: $host:$port\r\n" . + "User-Agent: ".PHP_VERSION."\r\n"; + if ($proxy_host != '' && $proxy_user != '') { + $request .= 'Proxy-Authorization: Basic ' . + base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n"; + } + $request .= "\r\n"; fwrite($fp, $request); $headers = array(); while (trim($line = fgets($fp, 1024))) { --- Remote-Original.php Thu Aug 8 15:11:40 2002 +++ Remote.php Thu Aug 8 15:35:57 2002 @@ -63,10 +63,21 @@ $server_host = $this->config->get('master_server'); $username = $this->config->get('username'); $password = $this->config->get('password'); + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if (sizeof($proxy = parse_url($this->config->get('http_proxy'))) > 1) { + $proxy_host = $proxy['host']; + $proxy_port = $proxy['port']; + $proxy_user = $proxy['user']; + $proxy_pass = $proxy['pass']; + + if ($proxy_port == '') { + $proxy_port = 8080; + } // if + } $eargs = array(); foreach($args as $arg) $eargs[] = $this->_encode($arg); $f = new XML_RPC_Message($method, $eargs); - $c = new XML_RPC_Client('/xmlrpc.php', $server_host, 80); + $c = new XML_RPC_Client('/xmlrpc.php', $server_host, 80, $proxy_host, $proxy_port, $proxy_user, $proxy_pass); if ($username && $password) { $c->setCredentials($username, $password); } --- RPC-Original.php Thu Aug 8 15:13:39 2002 +++ RPC.php Thu Aug 8 14:28:57 2002 @@ -371,14 +371,18 @@ var $debug=0; var $username=""; var $password=""; + var $proxy_user = ''; + var $proxy_pass = ''; - function XML_RPC_Client($path, $server, $port=80, $proxy="", $proxy_port=8080) + function XML_RPC_Client($path, $server, $port=80, $proxy = '', $proxy_port = 8080, $proxy_user = '', $proxy_pass = '') { - $this->port=$port; - $this->server=$server; - $this->path=$path; - $this->proxy = $proxy; - $this->proxy_port = $proxy_port ; + $this->port =$port; + $this->server =$server; + $this->path =$path; + $this->proxy = $proxy; + $this->proxy_port = $proxy_port; + $this->proxy_user = $proxy_user; + $this->proxy_pass = $proxy_pass; } function setDebug($in) @@ -457,8 +461,14 @@ } $op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . - "Host: ". $this->server . "\r\n" . - $credentials . + "Host: ". $this->server . "\r\n"; + + if ($this->proxy && $this->proxy_user != '') { + $op .= 'Proxy-Authorization: Basic ' . + base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; + } + + $op .= $credentials . "Content-Type: text/xml\r\nContent-Length: " . strlen($msg->payload) . "\r\n\r\n" . $msg->payload;