diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c5f230031b..581b4ce10c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2013-03-11 Kikuchi Koichiro + + * extensions/update_manager/lib/libupdate_manager_client.php, + extensions/update_manager/lib/xmlrpc/xmlrpc.inc: Added HTTP redirect + support. It fixes an issue that update manager behind http proxy + failed to communicate with update server due to the server's + "301 Moved Permanently" HTTP response. + + Merged from: branch_4.0 + 2013-03-08 Miguel de Dios * godmode/agentes/planned_downtime.list.php: added event when some diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php index 8b9b2dd1fd..6a0fccce2e 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php @@ -32,6 +32,7 @@ function um_xml_rpc_client_call ($server_host, $server_path, $server_port, $prox $client = new xmlrpc_client($server_path, $server_host, $server_port); $client->setProxy($proxy, $proxy_port, $proxy_user, $proxy_pass); + $client->setFollowLocation(true); if (defined ('XMLRPC_DEBUG')) $client->setDebug (XMLRPC_DEBUG); diff --git a/pandora_console/extensions/update_manager/lib/xmlrpc/xmlrpc.inc b/pandora_console/extensions/update_manager/lib/xmlrpc/xmlrpc.inc index 8669761c2f..49e2e2ab09 100755 --- a/pandora_console/extensions/update_manager/lib/xmlrpc/xmlrpc.inc +++ b/pandora_console/extensions/update_manager/lib/xmlrpc/xmlrpc.inc @@ -829,6 +829,9 @@ var $proxy_authtype=1; var $cookies=array(); var $extracurlopts=array(); + var $followlocation=false; + var $maxredirs=50; + var $redirs=0; /** * List of http compression methods accepted by the client for responses. @@ -877,50 +880,27 @@ // allow user to specify all params in $path if($server == '' and $port == '' and $method == '') { - $parts = parse_url($path); - $server = $parts['host']; - $path = isset($parts['path']) ? $parts['path'] : ''; - if(isset($parts['query'])) - { - $path .= '?'.$parts['query']; - } - if(isset($parts['fragment'])) - { - $path .= '#'.$parts['fragment']; - } - if(isset($parts['port'])) - { - $port = $parts['port']; - } - if(isset($parts['scheme'])) - { - $method = $parts['scheme']; - } - if(isset($parts['user'])) - { - $this->username = $parts['user']; - } - if(isset($parts['pass'])) - { - $this->password = $parts['pass']; - } - } - if($path == '' || $path[0] != '/') - { - $this->path='/'.$path; + setup_by_path($path); } else { - $this->path=$path; - } - $this->server=$server; - if($port != '') - { - $this->port=$port; - } - if($method != '') - { - $this->method=$method; + if($path == '' || $path[0] != '/') + { + $this->path='/'.$path; + } + else + { + $this->path=$path; + } + $this->server=$server; + if($port != '') + { + $this->port=$port; + } + if($method != '') + { + $this->method=$method; + } } // if ZLIB is enabled, let the client by default accept compressed responses @@ -942,6 +922,46 @@ $this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion']; } + /** + * Setup parameters by $path + * @access private + */ + function setup_by_path($path) + { + $parts = parse_url($path); + $this->server = $parts['host']; + $path = isset($parts['path']) ? $parts['path'] : ''; + if(isset($parts['query'])) + { + $path .= '?'.$parts['query']; + } + if(isset($parts['fragment'])) + { + $path .= '#'.$parts['fragment']; + } + if(isset($parts['user'])) + { + $this->username = $parts['user']; + } + if(isset($parts['pass'])) + { + $this->password = $parts['pass']; + } + if($path == '' || $path[0] != '/') + { + $path = '/' . $path; + } + $this->path=$path; + if(isset($parts['port'])) + { + $this->port = $parts['port']; + } + if(isset($parts['scheme'])) + { + $this->method = $parts['scheme']; + } + } + /** * Enables/disables the echoing to screen of the xmlrpc responses received * @param integer $debug values 0, 1 and 2 are supported (2 = echo sent msg too, before received response) @@ -1106,6 +1126,25 @@ } } + /** + * Set follow Location: header or not when server response is 301, 302 or 303. + * @param bool $follow + */ + function setFollowLocation( $follow ) + { + $this->followlocation = $follow; + } + + /** + * Set maximum number of redirection-followings allowed. By default, the limit + * is set to 50 redirections. Set this option to -1 to make it limitless. + * @param int $num + */ + function setMaxRedirs( $num ) + { + $this->maxredirs = $num; + } + /** * Directly set cURL options, for extra flexibility * It allows eg. to bind client to a specific IP interface / address @@ -1407,8 +1446,23 @@ $ipd.=fread($fp, 32768); } while(!feof($fp)); fclose($fp); - - $r =& $msg->parseResponse($ipd, false, $this->return_type); + + // Handle Redirect + if ($this->followlocation + && preg_match('/^HTTP\/[0-9.]+ 30[123] /', $ipd) + && $this->redirs < $this->maxredirs + && preg_match('/\r\nLocation:\s*([^\r\n]+)/', $ipd, $m)) { + + if ($this->maxredirs != -1) + { + $this->redirs++; + } + $this->setup_by_path($m[1]); + $r =& $this->send($msg, $timeout); + } else { + $r =& $msg->parseResponse($ipd, false, $this->return_type); + $this->redirs = 0; + } return $r; } @@ -1537,6 +1591,10 @@ // return the header too curl_setopt($curl, CURLOPT_HEADER, 1); + // redirect + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $this->followlocation); + curl_setopt($curl, CURLOPT_MAXREDIRS, $this->maxredirs); + // will only work with PHP >= 5.0 // NB: if we set an empty string, CURL will add http header indicating // ALL methods it is supporting. This is possibly a better option than @@ -3775,4 +3833,4 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha } } -?> \ No newline at end of file +?>